Skip to content

Commit

Permalink
fix(schematics): copy the cli file when running the workspace schematic
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Jan 9, 2018
1 parent fe7032d commit ddd8de3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
19 changes: 17 additions & 2 deletions e2e/schematics/workspace.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { checkFilesExist, cleanup, runNgNew, readFile, runCLI, runSchematic, updateFile } from '../utils';
import {
checkFilesExist,
cleanup,
runNgNew,
readFile,
runCLI,
runSchematic,
updateFile,
runCommand,
copyMissingPackages,
fileExists
} from '../utils';
import { angularCliSchema } from '../../packages/schematics/src/collection/utility/lib-versions';

describe('Nrwl Convert to Nx Workspace', () => {
beforeEach(cleanup);

it('should generate a workspace', () => {
runNgNew('--skip-install');
runNgNew();
copyMissingPackages();

// update package.json
const packageJson = JSON.parse(readFile('package.json'));
Expand Down Expand Up @@ -39,6 +51,7 @@ describe('Nrwl Convert to Nx Workspace', () => {
const updatedPackageJson = JSON.parse(readFile('package.json'));
expect(updatedPackageJson.description).toEqual('some description');
expect(updatedPackageJson.devDependencies['@nrwl/schematics']).toBeDefined();
expect(updatedPackageJson.dependencies['@angular/cli']).toEqual('file:.angular_cli.tgz');
expect(updatedPackageJson.dependencies['@nrwl/nx']).toBeDefined();
expect(updatedPackageJson.dependencies['@ngrx/store']).toBeDefined();
expect(updatedPackageJson.dependencies['@ngrx/effects']).toBeDefined();
Expand All @@ -63,6 +76,8 @@ describe('Nrwl Convert to Nx Workspace', () => {
a: ['b'],
'@proj/*': ['libs/*']
});

expect(fileExists('./tmp/proj/.angular_cli.tgz')).toEqual(true);
});

it('should generate a workspace and not change dependencies or devDependencies if they already exist', () => {
Expand Down
2 changes: 1 addition & 1 deletion e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function newProject(): string {
return execSync('cp -r ./tmp/proj_backup ./tmp/proj').toString();
}

function copyMissingPackages(): void {
export function copyMissingPackages(): void {
const modulesToCopy = ['@ngrx', 'jasmine-marbles', '@nrwl', 'angular', '@angular/upgrade', '@angular/cli'];
modulesToCopy.forEach(m => copyNodeModule(projectName, m));
}
Expand Down
31 changes: 30 additions & 1 deletion packages/schematics/src/collection/workspace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,34 @@ function moveFiles(options: Schema) {
};
}

function copyAngularCliTgz() {
return (host: Tree) => {
copyFile(
path.join(
'node_modules',
'@nrwl',
'schematics',
'src',
'collection',
'application',
'files',
'__directory__',
'.angular_cli.tgz'
),
'.'
);
return host;
};
}

function copyFile(file: string, target: string) {
const f = path.basename(file);
const source = fs.createReadStream(file);
const dest = fs.createWriteStream(path.resolve(target, f));
source.pipe(dest);
source.on('error', e => console.error(e));
}

function dedup(array: any[]): any[] {
const res = [];

Expand Down Expand Up @@ -281,6 +309,7 @@ export default function(schema: Schema): Rule {
updateAngularCLIJson(options),
updateTsConfigsJson(options),
updateProtractorConf(),
updateTsLintJson(options)
updateTsLintJson(options),
copyAngularCliTgz()
]);
}

0 comments on commit ddd8de3

Please sign in to comment.