feat(schematics): add all libs as apps to angularcli.json to support code generation
This commit is contained in:
parent
9935beef5c
commit
e2c8ef7a36
@ -1,11 +1,11 @@
|
|||||||
import {checkFilesExists, cleanup, copyMissingPackages, newBazelApp, readFile, runCLI, runSchematic} from '../utils';
|
import {checkFilesExists, cleanup, copyMissingPackages, ngNewBazel, readFile, runCLI, runSchematic} from '../utils';
|
||||||
|
|
||||||
describe('application', () => {
|
describe('application', () => {
|
||||||
beforeEach(cleanup);
|
beforeEach(cleanup);
|
||||||
|
|
||||||
describe('generate', () => {
|
describe('generate', () => {
|
||||||
it('should work', () => {
|
it('should work', () => {
|
||||||
newBazelApp('--collection=@nrwl/bazel --skip-install');
|
ngNewBazel('--collection=@nrwl/bazel --skip-install');
|
||||||
runSchematic('@nrwl/bazel:app --name=myApp');
|
runSchematic('@nrwl/bazel:app --name=myApp');
|
||||||
|
|
||||||
checkFilesExists(
|
checkFilesExists(
|
||||||
@ -35,7 +35,7 @@ describe('application', () => {
|
|||||||
|
|
||||||
describe('build', () => {
|
describe('build', () => {
|
||||||
it('should work', () => {
|
it('should work', () => {
|
||||||
newBazelApp('--collection=@nrwl/bazel');
|
ngNewBazel('--collection=@nrwl/bazel');
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
runSchematic('@nrwl/bazel:app --name=myApp');
|
runSchematic('@nrwl/bazel:app --name=myApp');
|
||||||
expect(runCLI('build')).toContain('main.bundle.js');
|
expect(runCLI('build')).toContain('main.bundle.js');
|
||||||
@ -44,7 +44,7 @@ describe('application', () => {
|
|||||||
|
|
||||||
describe('test', () => {
|
describe('test', () => {
|
||||||
it('should work', () => {
|
it('should work', () => {
|
||||||
newBazelApp('--collection=@nrwl/bazel');
|
ngNewBazel('--collection=@nrwl/bazel');
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
runSchematic('@nrwl/bazel:app --name=myApp');
|
runSchematic('@nrwl/bazel:app --name=myApp');
|
||||||
expect(runCLI('test --single-run')).toContain('Executed 1 of 1 SUCCESS');
|
expect(runCLI('test --single-run')).toContain('Executed 1 of 1 SUCCESS');
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import {checkFilesExists, cleanup, copyMissingPackages, newBazelApp, readFile, runCLI, runSchematic} from '../utils';
|
import {checkFilesExists, cleanup, copyMissingPackages, ngNewBazel, readFile, runCLI, runSchematic} from '../utils';
|
||||||
|
|
||||||
describe('library', () => {
|
describe('library', () => {
|
||||||
beforeEach(cleanup);
|
beforeEach(cleanup);
|
||||||
|
|
||||||
describe('generate', () => {
|
describe('generate', () => {
|
||||||
it('should work', () => {
|
it('should work', () => {
|
||||||
newBazelApp('--collection=@nrwl/bazel --skip-install');
|
ngNewBazel('--collection=@nrwl/bazel --skip-install');
|
||||||
runSchematic('@nrwl/bazel:lib --name=myLib');
|
runSchematic('@nrwl/bazel:lib --name=myLib');
|
||||||
|
|
||||||
checkFilesExists(
|
checkFilesExists(
|
||||||
@ -20,7 +20,7 @@ describe('library', () => {
|
|||||||
|
|
||||||
describe('build', () => {
|
describe('build', () => {
|
||||||
it('should work', () => {
|
it('should work', () => {
|
||||||
newBazelApp('--collection=@nrwl/bazel');
|
ngNewBazel('--collection=@nrwl/bazel');
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
runSchematic('@nrwl/bazel:lib --name=lib');
|
runSchematic('@nrwl/bazel:lib --name=lib');
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import {checkFilesExists, cleanup, copyMissingPackages, newApp, newBazelApp, readFile, runCLI, runCommand, runSchematic, updateFile} from '../utils';
|
import {checkFilesExists, cleanup, copyMissingPackages, ngNew, ngNewBazel, readFile, runCLI, runCommand, runSchematic, updateFile} from '../utils';
|
||||||
|
|
||||||
describe('angular library', () => {
|
describe('angular library', () => {
|
||||||
beforeEach(cleanup);
|
beforeEach(cleanup);
|
||||||
|
|
||||||
describe('generate', () => {
|
describe('generate', () => {
|
||||||
it('creates a new angularlibrary in a workspace', () => {
|
it('creates a new angularlibrary in a workspace', () => {
|
||||||
newBazelApp('--collection=@nrwl/bazel --skip-install');
|
ngNewBazel('--collection=@nrwl/bazel --skip-install');
|
||||||
runSchematic('@nrwl/bazel:nglib --name=myLib');
|
runSchematic('@nrwl/bazel:nglib --name=myLib');
|
||||||
|
|
||||||
checkFilesExists(
|
checkFilesExists(
|
||||||
@ -20,7 +20,7 @@ describe('angular library', () => {
|
|||||||
|
|
||||||
describe('build', () => {
|
describe('build', () => {
|
||||||
it('should work', () => {
|
it('should work', () => {
|
||||||
newBazelApp('--collection=@nrwl/bazel');
|
ngNewBazel('--collection=@nrwl/bazel');
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
runSchematic('@nrwl/bazel:nglib --name=myLib');
|
runSchematic('@nrwl/bazel:nglib --name=myLib');
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ describe('angular library', () => {
|
|||||||
|
|
||||||
describe('test', () => {
|
describe('test', () => {
|
||||||
it('should work', () => {
|
it('should work', () => {
|
||||||
newBazelApp('--collection=@nrwl/bazel');
|
ngNewBazel('--collection=@nrwl/bazel');
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
runSchematic('@nrwl/bazel:nglib --name=myLib');
|
runSchematic('@nrwl/bazel:nglib --name=myLib');
|
||||||
expect(runCLI('test --single-run')).toContain('Executed 0 of 0');
|
expect(runCLI('test --single-run')).toContain('Executed 0 of 0');
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import {checkFilesExists, cleanup, copyMissingPackages, newApp, newBazelApp, readFile, runCLI, runCommand, runSchematic, updateFile} from '../utils';
|
import {checkFilesExists, cleanup, copyMissingPackages, ngNew, ngNewBazel, readFile, runCLI, runCommand, runSchematic, updateFile} from '../utils';
|
||||||
|
|
||||||
describe('workspace', () => {
|
describe('workspace', () => {
|
||||||
beforeEach(cleanup);
|
beforeEach(cleanup);
|
||||||
|
|
||||||
it('creates a new workspace for developing angular applications', () => {
|
it('creates a new workspace for developing angular applications', () => {
|
||||||
newBazelApp('--collection=@nrwl/bazel --skip-install');
|
ngNewBazel('--collection=@nrwl/bazel --skip-install');
|
||||||
checkFilesExists(`tsconfig.json`, `WORKSPACE`, `BUILD.bazel`);
|
checkFilesExists(`tsconfig.json`, `WORKSPACE`, `BUILD.bazel`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import {checkFilesExists, cleanup, newApp, readFile, runCLI, runSchematic, updateFile} from '../utils';
|
import {checkFilesExists, cleanup, ngNew, readFile, runCLI, runSchematic, updateFile} from '../utils';
|
||||||
|
|
||||||
describe('Nrwl Convert to Nx Workspace', () => {
|
describe('Nrwl Convert to Nx Workspace', () => {
|
||||||
beforeEach(cleanup);
|
beforeEach(cleanup);
|
||||||
|
|
||||||
it('should generate a workspace', () => {
|
it('should generate a workspace', () => {
|
||||||
newApp('--skip-install --npmScope=nrwl');
|
ngNew('--skip-install --npmScope=nrwl');
|
||||||
|
|
||||||
// update package.json
|
// update package.json
|
||||||
const packageJson = JSON.parse(readFile('package.json'));
|
const packageJson = JSON.parse(readFile('package.json'));
|
||||||
@ -53,7 +53,7 @@ describe('Nrwl Convert to Nx Workspace', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should build and test', () => {
|
it('should build and test', () => {
|
||||||
newApp();
|
ngNew();
|
||||||
runSchematic('@nrwl/schematics:convert-to-workspace --npmScope=nrwl');
|
runSchematic('@nrwl/schematics:convert-to-workspace --npmScope=nrwl');
|
||||||
runSchematic('@nrwl/schematics:lib --name=mylib --ngmodule');
|
runSchematic('@nrwl/schematics:lib --name=mylib --ngmodule');
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
import {checkFilesExists, cleanup, copyMissingPackages, newApp, readFile, runCLI} from '../utils';
|
import {checkFilesExists, cleanup, copyMissingPackages, ngNew, readFile, runCLI} from '../utils';
|
||||||
|
|
||||||
describe('ngrx', () => {
|
describe('ngrx', () => {
|
||||||
beforeEach(cleanup);
|
beforeEach(cleanup);
|
||||||
|
|
||||||
describe('root', () => {
|
describe('root', () => {
|
||||||
it('should generate', () => {
|
it('should generate', () => {
|
||||||
newApp('--skip-install');
|
ngNew('--skip-install');
|
||||||
runCLI('generate ngrx app --module=src/app/app.module.ts --root --collection=@nrwl/schematics');
|
runCLI('generate ngrx app --module=src/app/app.module.ts --root --collection=@nrwl/schematics');
|
||||||
|
|
||||||
checkFilesExists(
|
checkFilesExists(
|
||||||
@ -19,7 +19,7 @@ describe('ngrx', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should build', () => {
|
it('should build', () => {
|
||||||
newApp();
|
ngNew();
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
runCLI('generate ngrx app --module=src/app/app.module.ts --root --collection=@nrwl/schematics');
|
runCLI('generate ngrx app --module=src/app/app.module.ts --root --collection=@nrwl/schematics');
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ describe('ngrx', () => {
|
|||||||
}, 50000);
|
}, 50000);
|
||||||
|
|
||||||
it('should add empty root configuration', () => {
|
it('should add empty root configuration', () => {
|
||||||
newApp();
|
ngNew();
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
runCLI('generate ngrx app --module=src/app/app.module.ts --onlyEmptyRoot --collection=@nrwl/schematics');
|
runCLI('generate ngrx app --module=src/app/app.module.ts --onlyEmptyRoot --collection=@nrwl/schematics');
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ describe('ngrx', () => {
|
|||||||
|
|
||||||
describe('feature', () => {
|
describe('feature', () => {
|
||||||
it('should generate', () => {
|
it('should generate', () => {
|
||||||
newApp('--skip-install');
|
ngNew('--skip-install');
|
||||||
runCLI('generate ngrx app --module=src/app/app.module.ts --collection=@nrwl/schematics');
|
runCLI('generate ngrx app --module=src/app/app.module.ts --collection=@nrwl/schematics');
|
||||||
|
|
||||||
checkFilesExists(
|
checkFilesExists(
|
||||||
@ -57,7 +57,7 @@ describe('ngrx', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should generate files without importing them', () => {
|
it('should generate files without importing them', () => {
|
||||||
newApp('--skip-install');
|
ngNew('--skip-install');
|
||||||
runCLI('generate ngrx app --module=src/app/app.module.ts --onlyAddFiles --collection=@nrwl/schematics');
|
runCLI('generate ngrx app --module=src/app/app.module.ts --onlyAddFiles --collection=@nrwl/schematics');
|
||||||
|
|
||||||
checkFilesExists(
|
checkFilesExists(
|
||||||
@ -71,7 +71,7 @@ describe('ngrx', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should update package.json', () => {
|
it('should update package.json', () => {
|
||||||
newApp('--skip-install');
|
ngNew('--skip-install');
|
||||||
runCLI('generate ngrx app --module=src/app/app.module.ts --collection=@nrwl/schematics');
|
runCLI('generate ngrx app --module=src/app/app.module.ts --collection=@nrwl/schematics');
|
||||||
|
|
||||||
const contents = JSON.parse(readFile('package.json'));
|
const contents = JSON.parse(readFile('package.json'));
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import {cleanup, copyMissingPackages, newApp, readFile, runCLI, runSchematic, updateFile} from '../utils';
|
import {cleanup, copyMissingPackages, ngNew, readFile, runCLI, runSchematic, updateFile} from '../utils';
|
||||||
|
|
||||||
describe('Upgrade', () => {
|
describe('Upgrade', () => {
|
||||||
beforeEach(cleanup);
|
beforeEach(cleanup);
|
||||||
|
|
||||||
it('should generate an upgrade shell', () => {
|
it('should generate an upgrade shell', () => {
|
||||||
newApp();
|
ngNew();
|
||||||
|
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
updateFile('src/legacy.js', `
|
updateFile('src/legacy.js', `
|
||||||
@ -29,7 +29,7 @@ describe('Upgrade', () => {
|
|||||||
}, 50000);
|
}, 50000);
|
||||||
|
|
||||||
it('should update package.json', () => {
|
it('should update package.json', () => {
|
||||||
newApp('--skip-install');
|
ngNew('--skip-install');
|
||||||
runCLI(
|
runCLI(
|
||||||
'generate upgrade-shell legacy --module=src/app/app.module.ts --angularJsImport=../legacy ' +
|
'generate upgrade-shell legacy --module=src/app/app.module.ts --angularJsImport=../legacy ' +
|
||||||
'--angularJsCmpSelector=rootLegacyCmp --collection=@nrwl/schematics');
|
'--angularJsCmpSelector=rootLegacyCmp --collection=@nrwl/schematics');
|
||||||
@ -40,7 +40,7 @@ describe('Upgrade', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not update package.json when --skipPackageJson', () => {
|
it('should not update package.json when --skipPackageJson', () => {
|
||||||
newApp('--skipInstall');
|
ngNew('--skipInstall');
|
||||||
runCLI(
|
runCLI(
|
||||||
'generate upgrade-shell legacy --module=src/app/app.module.ts --angularJsImport=../legacy ' +
|
'generate upgrade-shell legacy --module=src/app/app.module.ts --angularJsImport=../legacy ' +
|
||||||
'--angularJsCmpSelector=rootLegacyCmp --skipPackageJson --collection=@nrwl/schematics');
|
'--angularJsCmpSelector=rootLegacyCmp --skipPackageJson --collection=@nrwl/schematics');
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import {checkFilesExists, cleanup, copyMissingPackages, newApp, readFile, runCLI, updateFile} from '../utils';
|
import {checkFilesExists, cleanup, copyMissingPackages, newApp, newLib, ngNew, readFile, runCLI, updateFile} from '../utils';
|
||||||
|
|
||||||
describe('Nrwl Workspace', () => {
|
describe('Nrwl Workspace', () => {
|
||||||
beforeEach(cleanup);
|
beforeEach(cleanup);
|
||||||
|
|
||||||
it('should generate an empty workspace', () => {
|
it('should generate an empty workspace', () => {
|
||||||
newApp('--collection=@nrwl/schematics --skip-install');
|
ngNew('--collection=@nrwl/schematics --skip-install');
|
||||||
|
|
||||||
const angularCliJson = JSON.parse(readFile('.angular-cli.json'));
|
const angularCliJson = JSON.parse(readFile('.angular-cli.json'));
|
||||||
expect(angularCliJson.apps).toEqual([]);
|
expect(angularCliJson.apps).toEqual([]);
|
||||||
@ -17,8 +17,8 @@ describe('Nrwl Workspace', () => {
|
|||||||
|
|
||||||
describe('app', () => {
|
describe('app', () => {
|
||||||
it('should generate an app', () => {
|
it('should generate an app', () => {
|
||||||
newApp('--collection=@nrwl/schematics --skip-install');
|
ngNew('--collection=@nrwl/schematics --skip-install');
|
||||||
runCLI('generate app myapp --collection=@nrwl/schematics');
|
newApp('myapp');
|
||||||
|
|
||||||
const angularCliJson = JSON.parse(readFile('.angular-cli.json'));
|
const angularCliJson = JSON.parse(readFile('.angular-cli.json'));
|
||||||
expect(angularCliJson.apps[0].name).toEqual('myapp');
|
expect(angularCliJson.apps[0].name).toEqual('myapp');
|
||||||
@ -29,9 +29,9 @@ describe('Nrwl Workspace', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should build app', () => {
|
it('should build app', () => {
|
||||||
newApp('--collection=@nrwl/schematics');
|
ngNew('--collection=@nrwl/schematics');
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
runCLI('generate app myapp --collection=@nrwl/schematics');
|
newApp('myapp');
|
||||||
runCLI('build --aot');
|
runCLI('build --aot');
|
||||||
checkFilesExists('dist/apps/myapp/main.bundle.js');
|
checkFilesExists('dist/apps/myapp/main.bundle.js');
|
||||||
expect(runCLI('test --single-run')).toContain('Executed 1 of 1 SUCCESS');
|
expect(runCLI('test --single-run')).toContain('Executed 1 of 1 SUCCESS');
|
||||||
@ -40,17 +40,20 @@ describe('Nrwl Workspace', () => {
|
|||||||
|
|
||||||
describe('lib', () => {
|
describe('lib', () => {
|
||||||
it('should generate a lib', () => {
|
it('should generate a lib', () => {
|
||||||
newApp('--collection=@nrwl/schematics --skip-install');
|
ngNew('--collection=@nrwl/schematics --skip-install');
|
||||||
runCLI('generate lib mylib --collection=@nrwl/schematics');
|
newLib('mylib');
|
||||||
|
|
||||||
|
const angularCliJson = JSON.parse(readFile('.angular-cli.json'));
|
||||||
|
expect(angularCliJson.apps[0].name).toEqual('mylib');
|
||||||
|
|
||||||
checkFilesExists('libs/mylib/src/mylib.ts', 'libs/mylib/src/mylib.spec.ts', 'libs/mylib/index.ts');
|
checkFilesExists('libs/mylib/src/mylib.ts', 'libs/mylib/src/mylib.spec.ts', 'libs/mylib/index.ts');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should test a lib', () => {
|
it('should test a lib', () => {
|
||||||
newApp('--collection=@nrwl/schematics');
|
ngNew('--collection=@nrwl/schematics');
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
runCLI('generate app myapp --collection=@nrwl/schematics');
|
newApp('myapp');
|
||||||
runCLI('generate lib mylib --collection=@nrwl/schematics');
|
newLib('generate lib mylib');
|
||||||
|
|
||||||
expect(runCLI('test --single-run')).toContain('Executed 2 of 2 SUCCESS');
|
expect(runCLI('test --single-run')).toContain('Executed 2 of 2 SUCCESS');
|
||||||
});
|
});
|
||||||
@ -58,26 +61,26 @@ describe('Nrwl Workspace', () => {
|
|||||||
|
|
||||||
describe('nglib', () => {
|
describe('nglib', () => {
|
||||||
it('should generate an ng lib', () => {
|
it('should generate an ng lib', () => {
|
||||||
newApp('--collection=@nrwl/schematics --skip-install');
|
ngNew('--collection=@nrwl/schematics --skip-install');
|
||||||
runCLI('generate lib mylib --collection=@nrwl/schematics --ngmodule');
|
newLib('mylib --ngmodule');
|
||||||
|
|
||||||
checkFilesExists('libs/mylib/src/mylib.module.ts', 'libs/mylib/src/mylib.module.spec.ts', 'libs/mylib/index.ts');
|
checkFilesExists('libs/mylib/src/mylib.module.ts', 'libs/mylib/src/mylib.module.spec.ts', 'libs/mylib/index.ts');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should test an ng lib', () => {
|
it('should test an ng lib', () => {
|
||||||
newApp('--collection=@nrwl/schematics');
|
ngNew('--collection=@nrwl/schematics');
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
runCLI('generate app myapp --collection=@nrwl/schematics');
|
newApp('myapp');
|
||||||
runCLI('generate lib mylib --collection=@nrwl/schematics --ngmodule');
|
newLib('mylib --ngmodule');
|
||||||
|
|
||||||
expect(runCLI('test --single-run')).toContain('Executed 2 of 2 SUCCESS');
|
expect(runCLI('test --single-run')).toContain('Executed 2 of 2 SUCCESS');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should resolve dependencies on the lib', () => {
|
it('should resolve dependencies on the lib', () => {
|
||||||
newApp('--collection=@nrwl/schematics --npmScope=nrwl');
|
ngNew('--collection=@nrwl/schematics --npmScope=nrwl');
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
runCLI('generate app myapp --collection=@nrwl/schematics');
|
newApp('myapp');
|
||||||
runCLI('generate lib mylib --collection=@nrwl/schematics --ngmodule');
|
newLib('mylib --ngmodule');
|
||||||
|
|
||||||
updateFile('apps/myapp/src/app/app.module.ts', `
|
updateFile('apps/myapp/src/app/app.module.ts', `
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
|
|||||||
20
e2e/utils.ts
20
e2e/utils.ts
@ -4,12 +4,12 @@ import * as path from 'path';
|
|||||||
|
|
||||||
const projectName: string = 'proj';
|
const projectName: string = 'proj';
|
||||||
|
|
||||||
export function newApp(command?: string): string {
|
export function ngNew(command?: string): string {
|
||||||
return execSync(`../node_modules/.bin/ng new proj ${command}`, {cwd: `./tmp`}).toString();
|
return execSync(`../node_modules/.bin/ng new proj ${command}`, {cwd: `./tmp`}).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function newBazelApp(command?: string): string {
|
export function ngNewBazel(command?: string): string {
|
||||||
const res = newApp(command);
|
const res = ngNew(command);
|
||||||
const cliPath = path.join('tmp', projectName, 'node_modules', '@angular', 'cli');
|
const cliPath = path.join('tmp', projectName, 'node_modules', '@angular', 'cli');
|
||||||
execSync(`rm -rf ${cliPath}`);
|
execSync(`rm -rf ${cliPath}`);
|
||||||
execSync(`cp -r node_modules/clis/bazel ${cliPath}`);
|
execSync(`cp -r node_modules/clis/bazel ${cliPath}`);
|
||||||
@ -20,6 +20,20 @@ export function runCLI(command?: string): string {
|
|||||||
return execSync(`../../node_modules/.bin/ng ${command}`, {cwd: `./tmp/${projectName}`}).toString();
|
return execSync(`../../node_modules/.bin/ng ${command}`, {cwd: `./tmp/${projectName}`}).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// switch to ng generate, once CLI is fixed
|
||||||
|
export function newApp(name: string): string {
|
||||||
|
return runCLI(`generate app ${name}`)
|
||||||
|
// return execSync(`../../node_modules/.bin/schematics @nrwl/schematics:app --name=${name}
|
||||||
|
// --collection=@nrwl/schematics`, { cwd: `./tmp/${projectName}` }).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// switch to ng generate, once CLI is fixed
|
||||||
|
export function newLib(name: string): string {
|
||||||
|
return runCLI(`generate lib ${name}`)
|
||||||
|
// return execSync(`../../node_modules/.bin/schematics @nrwl/schematics:lib --name=${name}
|
||||||
|
// --collection=@nrwl/schematics`, { cwd: `./tmp/${projectName}` }).toString();
|
||||||
|
}
|
||||||
|
|
||||||
export function runSchematic(command: string): string {
|
export function runSchematic(command: string): string {
|
||||||
return execSync(`../../node_modules/.bin/schematics ${command}`, {cwd: `./tmp/${projectName}`}).toString();
|
return execSync(`../../node_modules/.bin/schematics ${command}`, {cwd: `./tmp/${projectName}`}).toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -85,7 +85,7 @@ It's similar to the standard CLI projects with a few changes:
|
|||||||
|
|
||||||
#### Create an App
|
#### Create an App
|
||||||
|
|
||||||
Run `ng generate app myapp --collection=@nrwl/schematics`, and you will see the following files created:
|
Run `ng generate app myapp`, and you will see the following files created:
|
||||||
|
|
||||||
```
|
```
|
||||||
apps/myapp/src/main.ts
|
apps/myapp/src/main.ts
|
||||||
@ -104,7 +104,7 @@ As with the standard CLI, running `ng build` without specifying an app will buil
|
|||||||
|
|
||||||
#### Create a Lib
|
#### Create a Lib
|
||||||
|
|
||||||
Run `ng generate lib mylib --collection=@nrwl/schematics`, and you will see the following files created:
|
Run `ng generate lib mylib`, and you will see the following files created:
|
||||||
|
|
||||||
```
|
```
|
||||||
libs/mylib/src/mylib.ts
|
libs/mylib/src/mylib.ts
|
||||||
@ -156,7 +156,7 @@ schematics @nrwl/schematics:convert-to-workspace
|
|||||||
|
|
||||||
#### Root
|
#### Root
|
||||||
|
|
||||||
Run `ng generate ngrx app --module=src/app/app.module.ts --root --collection=@nrwl/schematics`, and you will see the following files created:
|
Run `ng generate ngrx app --module=src/app/app.module.ts --root`, and you will see the following files created:
|
||||||
|
|
||||||
```
|
```
|
||||||
/src/app/+state/app.actions.ts
|
/src/app/+state/app.actions.ts
|
||||||
@ -172,11 +172,11 @@ Also, `app.module.ts` will have `StoreModule.forRoot` and `EffectsModule.forRoot
|
|||||||
|
|
||||||
#### onlyEmptyRoot
|
#### onlyEmptyRoot
|
||||||
|
|
||||||
Run `ng generate ngrx app --module=src/app/app.module.ts --onlyEmptyRoot --collection=@nrwl/schematics` to only add the `StoreModule.forRoot` and `EffectsModule.forRoot` calls without generating any new files.
|
Run `ng generate ngrx app --module=src/app/app.module.ts --onlyEmptyRoot` to only add the `StoreModule.forRoot` and `EffectsModule.forRoot` calls without generating any new files.
|
||||||
|
|
||||||
#### Feature
|
#### Feature
|
||||||
|
|
||||||
Run `ng generate ngrx app --module=src/app/mymodule/mymodule.module.ts --collection=@nrwl/schematics`, and you will see the following files created:
|
Run `ng generate ngrx app --module=src/app/mymodule/mymodule.module.ts`, and you will see the following files created:
|
||||||
|
|
||||||
```
|
```
|
||||||
/src/app/mymodule/+state/app.actions.ts
|
/src/app/mymodule/+state/app.actions.ts
|
||||||
@ -198,7 +198,7 @@ Add `--onlyAddFiles` to generate files without adding imports to the module.
|
|||||||
|
|
||||||
### upgrade-shell
|
### upgrade-shell
|
||||||
|
|
||||||
Run `ng generate upgrade-shell legacy --module=src/app/app.module.ts --angularJsCmpSelector=rootLegacyCmp --collection=@nrwl/schematics` and you will see the following files created:
|
Run `ng generate upgrade-shell legacy --module=src/app/app.module.ts --angularJsCmpSelector=rootLegacyCmp` and you will see the following files created:
|
||||||
|
|
||||||
```
|
```
|
||||||
/src/app/legacy-setup.ts
|
/src/app/legacy-setup.ts
|
||||||
|
|||||||
@ -3,6 +3,30 @@ import {Schema} from './schema';
|
|||||||
import {names, toFileName} from '@nrwl/schematics';
|
import {names, toFileName} from '@nrwl/schematics';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
|
function addLibToAngularCliJson(options: Schema): Rule {
|
||||||
|
return (host: Tree) => {
|
||||||
|
const appConfig = {
|
||||||
|
'name': options.name,
|
||||||
|
'root': path.join('libs', options.name, options.sourceDir),
|
||||||
|
'test': '../../../test.js'
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!host.exists('.angular-cli.json')) {
|
||||||
|
throw new Error('Missing .angular-cli.json');
|
||||||
|
}
|
||||||
|
|
||||||
|
const sourceText = host.read('.angular-cli.json')!.toString('utf-8');
|
||||||
|
const json = JSON.parse(sourceText);
|
||||||
|
if (!json['apps']) {
|
||||||
|
json['apps'] = [];
|
||||||
|
}
|
||||||
|
json['apps'].push(appConfig);
|
||||||
|
|
||||||
|
host.overwrite('.angular-cli.json', JSON.stringify(json, null, 2));
|
||||||
|
return host;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export default function(options: Schema): Rule {
|
export default function(options: Schema): Rule {
|
||||||
const fullPath = path.join('libs', toFileName(options.name), options.sourceDir);
|
const fullPath = path.join('libs', toFileName(options.name), options.sourceDir);
|
||||||
|
|
||||||
@ -10,5 +34,5 @@ export default function(options: Schema): Rule {
|
|||||||
url(options.ngmodule ? './ngfiles' : './files'),
|
url(options.ngmodule ? './ngfiles' : './files'),
|
||||||
[template({...names(options.name), dot: '.', tmpl: '', ...options as object})]);
|
[template({...names(options.name), dot: '.', tmpl: '', ...options as object})]);
|
||||||
|
|
||||||
return chain([branchAndMerge(chain([mergeWith(templateSource)]))]);
|
return chain([branchAndMerge(chain([mergeWith(templateSource)])), addLibToAngularCliJson(options)]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
},
|
},
|
||||||
"defaults": {
|
"defaults": {
|
||||||
"schematics": {
|
"schematics": {
|
||||||
|
"collection": "@nrwl/schematics",
|
||||||
"newProject": ["app", "lib"]
|
"newProject": ["app", "lib"]
|
||||||
},
|
},
|
||||||
"styleExt": "<%= style %>",<% if (!minimal) { %>
|
"styleExt": "<%= style %>",<% if (!minimal) { %>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user