refactor(schematics): make all schematics work with ng generate
This commit is contained in:
parent
84c27ba211
commit
9935beef5c
@ -15,7 +15,7 @@ describe('Nrwl Convert to Nx Workspace', () => {
|
|||||||
|
|
||||||
// update tsconfig.json
|
// update tsconfig.json
|
||||||
const tsconfigJson = JSON.parse(readFile('tsconfig.json'));
|
const tsconfigJson = JSON.parse(readFile('tsconfig.json'));
|
||||||
tsconfigJson.compilerOptions.paths = { 'a': ['b'] };
|
tsconfigJson.compilerOptions.paths = {'a': ['b']};
|
||||||
updateFile('tsconfig.json', JSON.stringify(tsconfigJson, null, 2));
|
updateFile('tsconfig.json', JSON.stringify(tsconfigJson, null, 2));
|
||||||
|
|
||||||
// update angular-cli.json
|
// update angular-cli.json
|
||||||
@ -48,7 +48,7 @@ describe('Nrwl Convert to Nx Workspace', () => {
|
|||||||
|
|
||||||
// check if tsconfig.json get merged
|
// check if tsconfig.json get merged
|
||||||
const updatedTsConfig = JSON.parse(readFile('tsconfig.json'));
|
const updatedTsConfig = JSON.parse(readFile('tsconfig.json'));
|
||||||
expect(updatedTsConfig.compilerOptions.paths).toEqual({ 'a': ['b'], '@proj/*': ['libs/*'] });
|
expect(updatedTsConfig.compilerOptions.paths).toEqual({'a': ['b'], '@proj/*': ['libs/*']});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
import {checkFilesExists, cleanup, copyMissingPackages, newApp, readFile, runCLI, runCommand, runSchematic, updateFile} from '../utils';
|
import {checkFilesExists, cleanup, copyMissingPackages, newApp, readFile, runCLI} from '../utils';
|
||||||
|
|
||||||
describe('ngrx', () => {
|
describe('ngrx', () => {
|
||||||
beforeEach(cleanup);
|
beforeEach(cleanup);
|
||||||
|
|
||||||
describe('root', () => {
|
describe('root', () => {
|
||||||
it('should generate', () => {
|
it('should generate', () => {
|
||||||
newApp('--skip-import');
|
newApp('--skip-install');
|
||||||
|
runCLI('generate ngrx app --module=src/app/app.module.ts --root --collection=@nrwl/schematics');
|
||||||
runSchematic('@nrwl/schematics:ngrx --module=src/app/app.module.ts --root');
|
|
||||||
|
|
||||||
checkFilesExists(
|
checkFilesExists(
|
||||||
`src/app/+state/app.actions.ts`, `src/app/+state/app.effects.ts`, `src/app/+state/app.effects.spec.ts`,
|
`src/app/+state/app.actions.ts`, `src/app/+state/app.effects.ts`, `src/app/+state/app.effects.spec.ts`,
|
||||||
@ -18,12 +17,11 @@ describe('ngrx', () => {
|
|||||||
expect(contents).toContain('StoreModule.forRoot');
|
expect(contents).toContain('StoreModule.forRoot');
|
||||||
expect(contents).toContain('EffectsModule.forRoot');
|
expect(contents).toContain('EffectsModule.forRoot');
|
||||||
});
|
});
|
||||||
//
|
|
||||||
it('should build', () => {
|
it('should build', () => {
|
||||||
newApp();
|
newApp();
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
|
runCLI('generate ngrx app --module=src/app/app.module.ts --root --collection=@nrwl/schematics');
|
||||||
runSchematic('@nrwl/schematics:ngrx --module=src/app/app.module.ts --root');
|
|
||||||
|
|
||||||
runCLI('build');
|
runCLI('build');
|
||||||
runCLI('test --single-run');
|
runCLI('test --single-run');
|
||||||
@ -32,8 +30,7 @@ describe('ngrx', () => {
|
|||||||
it('should add empty root configuration', () => {
|
it('should add empty root configuration', () => {
|
||||||
newApp();
|
newApp();
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
|
runCLI('generate ngrx app --module=src/app/app.module.ts --onlyEmptyRoot --collection=@nrwl/schematics');
|
||||||
runSchematic('@nrwl/schematics:ngrx --module=src/app/app.module.ts --onlyEmptyRoot');
|
|
||||||
|
|
||||||
const contents = readFile('src/app/app.module.ts');
|
const contents = readFile('src/app/app.module.ts');
|
||||||
expect(contents).toContain('StoreModule.forRoot');
|
expect(contents).toContain('StoreModule.forRoot');
|
||||||
@ -45,8 +42,8 @@ describe('ngrx', () => {
|
|||||||
|
|
||||||
describe('feature', () => {
|
describe('feature', () => {
|
||||||
it('should generate', () => {
|
it('should generate', () => {
|
||||||
newApp('--skipInstall');
|
newApp('--skip-install');
|
||||||
runSchematic('@nrwl/schematics:ngrx --module=src/app/app.module.ts');
|
runCLI('generate ngrx app --module=src/app/app.module.ts --collection=@nrwl/schematics');
|
||||||
|
|
||||||
checkFilesExists(
|
checkFilesExists(
|
||||||
`src/app/+state/app.actions.ts`, `src/app/+state/app.effects.ts`, `src/app/+state/app.effects.spec.ts`,
|
`src/app/+state/app.actions.ts`, `src/app/+state/app.effects.ts`, `src/app/+state/app.effects.spec.ts`,
|
||||||
@ -60,8 +57,8 @@ describe('ngrx', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should generate files without importing them', () => {
|
it('should generate files without importing them', () => {
|
||||||
newApp('--skipInstall');
|
newApp('--skip-install');
|
||||||
runSchematic('@nrwl/schematics:ngrx --module=src/app/app.module.ts --onlyAddFiles');
|
runCLI('generate ngrx app --module=src/app/app.module.ts --onlyAddFiles --collection=@nrwl/schematics');
|
||||||
|
|
||||||
checkFilesExists(
|
checkFilesExists(
|
||||||
`src/app/+state/app.actions.ts`, `src/app/+state/app.effects.ts`, `src/app/+state/app.effects.spec.ts`,
|
`src/app/+state/app.actions.ts`, `src/app/+state/app.effects.ts`, `src/app/+state/app.effects.spec.ts`,
|
||||||
@ -74,8 +71,8 @@ describe('ngrx', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should update package.json', () => {
|
it('should update package.json', () => {
|
||||||
newApp('--skipInstall');
|
newApp('--skip-install');
|
||||||
runSchematic('@nrwl/schematics:ngrx --module=src/app/app.module.ts');
|
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'));
|
||||||
|
|
||||||
|
|||||||
@ -20,24 +20,19 @@ describe('Upgrade', () => {
|
|||||||
|
|
||||||
updateFile('src/app/app.component.spec.ts', ``);
|
updateFile('src/app/app.component.spec.ts', ``);
|
||||||
|
|
||||||
runSchematic(
|
runCLI(
|
||||||
'@nrwl/schematics:upgrade-shell ' +
|
'generate upgrade-shell legacy --module=src/app/app.module.ts --angularJsImport=../legacy ' +
|
||||||
'--module=src/app/app.module.ts ' +
|
'--angularJsCmpSelector=rootLegacyCmp --collection=@nrwl/schematics');
|
||||||
'--angularJsImport=../legacy ' +
|
|
||||||
'--angularJsCmpSelector=rootLegacyCmp ');
|
|
||||||
|
|
||||||
runCLI('build');
|
runCLI('build');
|
||||||
runCLI('test --single-run');
|
runCLI('test --single-run');
|
||||||
}, 50000);
|
}, 50000);
|
||||||
|
|
||||||
it('should update package.json', () => {
|
it('should update package.json', () => {
|
||||||
newApp('--skipInstall');
|
newApp('--skip-install');
|
||||||
|
runCLI(
|
||||||
runSchematic(
|
'generate upgrade-shell legacy --module=src/app/app.module.ts --angularJsImport=../legacy ' +
|
||||||
'@nrwl/schematics:upgrade-shell ' +
|
'--angularJsCmpSelector=rootLegacyCmp --collection=@nrwl/schematics');
|
||||||
'--module=src/app/app.module.ts ' +
|
|
||||||
'--angularJsImport=../legacy ' +
|
|
||||||
'--angularJsCmpSelector=rootLegacyCmp');
|
|
||||||
|
|
||||||
const contents = JSON.parse(readFile('package.json'));
|
const contents = JSON.parse(readFile('package.json'));
|
||||||
expect(contents.dependencies['@angular/upgrade']).toBeDefined();
|
expect(contents.dependencies['@angular/upgrade']).toBeDefined();
|
||||||
@ -46,13 +41,9 @@ describe('Upgrade', () => {
|
|||||||
|
|
||||||
it('should not update package.json when --skipPackageJson', () => {
|
it('should not update package.json when --skipPackageJson', () => {
|
||||||
newApp('--skipInstall');
|
newApp('--skipInstall');
|
||||||
|
runCLI(
|
||||||
runSchematic(
|
'generate upgrade-shell legacy --module=src/app/app.module.ts --angularJsImport=../legacy ' +
|
||||||
'@nrwl/schematics:upgrade-shell ' +
|
'--angularJsCmpSelector=rootLegacyCmp --skipPackageJson --collection=@nrwl/schematics');
|
||||||
'--module=src/app/app.module.ts ' +
|
|
||||||
'--angularJsImport=../legacy ' +
|
|
||||||
'--angularJsCmpSelector=rootLegacyCmp ' +
|
|
||||||
'--skipPackageJson');
|
|
||||||
|
|
||||||
const contents = JSON.parse(readFile('package.json'));
|
const contents = JSON.parse(readFile('package.json'));
|
||||||
expect(contents.dependencies['@angular/upgrade']).not.toBeDefined();
|
expect(contents.dependencies['@angular/upgrade']).not.toBeDefined();
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import {checkFilesExists, cleanup, copyMissingPackages, newApp, readFile, runCLI, runSchematic, updateFile} from '../utils';
|
import {checkFilesExists, cleanup, copyMissingPackages, newApp, readFile, runCLI, updateFile} from '../utils';
|
||||||
|
|
||||||
describe('Nrwl Workspace', () => {
|
describe('Nrwl Workspace', () => {
|
||||||
beforeEach(cleanup);
|
beforeEach(cleanup);
|
||||||
@ -17,9 +17,8 @@ describe('Nrwl Workspace', () => {
|
|||||||
|
|
||||||
describe('app', () => {
|
describe('app', () => {
|
||||||
it('should generate an app', () => {
|
it('should generate an app', () => {
|
||||||
newApp('--collection=@nrwl/schematics');
|
newApp('--collection=@nrwl/schematics --skip-install');
|
||||||
copyMissingPackages();
|
runCLI('generate app myapp --collection=@nrwl/schematics');
|
||||||
runSchematic('@nrwl/schematics:app --name=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');
|
||||||
@ -27,10 +26,14 @@ describe('Nrwl Workspace', () => {
|
|||||||
checkFilesExists(
|
checkFilesExists(
|
||||||
'apps/myapp/src/main.ts', 'apps/myapp/src/app/app.module.ts', 'apps/myapp/src/app/app.component.ts',
|
'apps/myapp/src/main.ts', 'apps/myapp/src/app/app.module.ts', 'apps/myapp/src/app/app.component.ts',
|
||||||
'apps/myapp/e2e/app.po.ts');
|
'apps/myapp/e2e/app.po.ts');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should build app', () => {
|
||||||
|
newApp('--collection=@nrwl/schematics');
|
||||||
|
copyMissingPackages();
|
||||||
|
runCLI('generate app myapp --collection=@nrwl/schematics');
|
||||||
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');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -38,7 +41,7 @@ describe('Nrwl Workspace', () => {
|
|||||||
describe('lib', () => {
|
describe('lib', () => {
|
||||||
it('should generate a lib', () => {
|
it('should generate a lib', () => {
|
||||||
newApp('--collection=@nrwl/schematics --skip-install');
|
newApp('--collection=@nrwl/schematics --skip-install');
|
||||||
runSchematic('@nrwl/schematics:lib --name=mylib');
|
runCLI('generate lib mylib --collection=@nrwl/schematics');
|
||||||
|
|
||||||
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');
|
||||||
});
|
});
|
||||||
@ -46,8 +49,8 @@ describe('Nrwl Workspace', () => {
|
|||||||
it('should test a lib', () => {
|
it('should test a lib', () => {
|
||||||
newApp('--collection=@nrwl/schematics');
|
newApp('--collection=@nrwl/schematics');
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
runSchematic('@nrwl/schematics:app --name=myapp');
|
runCLI('generate app myapp --collection=@nrwl/schematics');
|
||||||
runSchematic('@nrwl/schematics:lib --name=mylib');
|
runCLI('generate lib mylib --collection=@nrwl/schematics');
|
||||||
|
|
||||||
expect(runCLI('test --single-run')).toContain('Executed 2 of 2 SUCCESS');
|
expect(runCLI('test --single-run')).toContain('Executed 2 of 2 SUCCESS');
|
||||||
});
|
});
|
||||||
@ -56,7 +59,7 @@ 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');
|
newApp('--collection=@nrwl/schematics --skip-install');
|
||||||
runSchematic('@nrwl/schematics:lib --name=mylib --ngmodule');
|
runCLI('generate lib mylib --collection=@nrwl/schematics --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');
|
||||||
});
|
});
|
||||||
@ -64,8 +67,8 @@ describe('Nrwl Workspace', () => {
|
|||||||
it('should test an ng lib', () => {
|
it('should test an ng lib', () => {
|
||||||
newApp('--collection=@nrwl/schematics');
|
newApp('--collection=@nrwl/schematics');
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
runSchematic('@nrwl/schematics:app --name=myapp');
|
runCLI('generate app myapp --collection=@nrwl/schematics');
|
||||||
runSchematic('@nrwl/schematics:lib --name=mylib --ngmodule');
|
runCLI('generate lib mylib --collection=@nrwl/schematics --ngmodule');
|
||||||
|
|
||||||
expect(runCLI('test --single-run')).toContain('Executed 2 of 2 SUCCESS');
|
expect(runCLI('test --single-run')).toContain('Executed 2 of 2 SUCCESS');
|
||||||
});
|
});
|
||||||
@ -73,8 +76,8 @@ describe('Nrwl Workspace', () => {
|
|||||||
it('should resolve dependencies on the lib', () => {
|
it('should resolve dependencies on the lib', () => {
|
||||||
newApp('--collection=@nrwl/schematics --npmScope=nrwl');
|
newApp('--collection=@nrwl/schematics --npmScope=nrwl');
|
||||||
copyMissingPackages();
|
copyMissingPackages();
|
||||||
runSchematic('@nrwl/schematics:app --name=myapp');
|
runCLI('generate app myapp --collection=@nrwl/schematics');
|
||||||
runSchematic('@nrwl/schematics:lib --name=mylib --ngmodule');
|
runCLI('generate lib mylib --collection=@nrwl/schematics --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';
|
||||||
|
|||||||
@ -75,13 +75,7 @@ export function exists(filePath: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function copyMissingPackages(): void {
|
export function copyMissingPackages(): void {
|
||||||
const modulesToCopy = [
|
const modulesToCopy = ['@ngrx', 'jasmine-marbles', '@nrwl', 'angular', '@angular/upgrade', '@angular/cli'];
|
||||||
'@ngrx',
|
|
||||||
'jasmine-marbles',
|
|
||||||
'@nrwl',
|
|
||||||
'angular',
|
|
||||||
'@angular/upgrade',
|
|
||||||
];
|
|
||||||
modulesToCopy.forEach(m => copyNodeModule(projectName, m));
|
modulesToCopy.forEach(m => copyNodeModule(projectName, m));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
36
package.json
36
package.json
@ -17,43 +17,43 @@
|
|||||||
"publish_npm": "./scripts/publish.sh",
|
"publish_npm": "./scripts/publish.sh",
|
||||||
"postinstall": "./scripts/copy-clis.sh"
|
"postinstall": "./scripts/copy-clis.sh"
|
||||||
},
|
},
|
||||||
"dependencies" :{
|
"dependencies": {
|
||||||
"jasmine-marbles": "0.1.0"
|
"jasmine-marbles": "0.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"rxjs": "5.4.3",
|
"@schematics/angular": "^0.0.36",
|
||||||
"@angular-devkit/schematics": "0.0.19",
|
"@angular-devkit/schematics": "^0.0.24",
|
||||||
"@angular/core": "4.3.5",
|
"@angular/cli": "nrwl/fix-cli-build",
|
||||||
"@angular/common": "4.3.5",
|
"@angular/common": "4.3.5",
|
||||||
"@angular/platform-browser": "4.3.5",
|
|
||||||
"@angular/compiler": "4.3.5",
|
"@angular/compiler": "4.3.5",
|
||||||
|
"@angular/compiler-cli": "4.3.5",
|
||||||
|
"@angular/core": "4.3.5",
|
||||||
|
"@angular/platform-browser": "4.3.5",
|
||||||
"@angular/platform-browser-dynamic": "4.3.5",
|
"@angular/platform-browser-dynamic": "4.3.5",
|
||||||
"@angular/router": "4.3.5",
|
"@angular/router": "4.3.5",
|
||||||
"@angular/upgrade": "4.3.5",
|
"@angular/upgrade": "4.3.5",
|
||||||
"@angular/compiler-cli": "4.3.5",
|
|
||||||
"@angular/cli": "nrwl/fix-cli-build",
|
|
||||||
"bazel-cli": "nrwl/bazel-cli-build",
|
|
||||||
"@ngrx/store": "4.0.3",
|
|
||||||
"@ngrx/router-store": "4.0.3",
|
|
||||||
"@ngrx/effects": "4.0.3",
|
"@ngrx/effects": "4.0.3",
|
||||||
|
"@ngrx/router-store": "4.0.3",
|
||||||
|
"@ngrx/store": "4.0.3",
|
||||||
"@ngrx/store-devtools": "^4.0.0",
|
"@ngrx/store-devtools": "^4.0.0",
|
||||||
"typescript": "2.4.2",
|
|
||||||
"@types/node": "8.0.7",
|
|
||||||
"@types/jasmine": "2.5.53",
|
"@types/jasmine": "2.5.53",
|
||||||
"jest": "20.0.4",
|
"@types/node": "8.0.7",
|
||||||
"@schematics/angular": "0.0.30",
|
"angular": "1.6.6",
|
||||||
|
"bazel-cli": "nrwl/bazel-cli-build",
|
||||||
|
"clang-format": "^1.0.32",
|
||||||
"jasmine-core": "~2.6.2",
|
"jasmine-core": "~2.6.2",
|
||||||
|
"jest": "20.0.4",
|
||||||
"karma": "~1.7.0",
|
"karma": "~1.7.0",
|
||||||
"karma-chrome-launcher": "~2.1.1",
|
"karma-chrome-launcher": "~2.1.1",
|
||||||
"karma-jasmine": "~1.1.0",
|
"karma-jasmine": "~1.1.0",
|
||||||
"karma-webpack": "2.0.4",
|
"karma-webpack": "2.0.4",
|
||||||
"clang-format": "^1.0.32",
|
"rxjs": "5.4.3",
|
||||||
"angular": "1.6.6",
|
"semver": "^5.4.1",
|
||||||
"semver": "^5.4.1"
|
"typescript": "2.4.2"
|
||||||
},
|
},
|
||||||
"author": "Victor Savkin",
|
"author": "Victor Savkin",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"jest" : {
|
"jest": {
|
||||||
"modulePathIgnorePatterns": [
|
"modulePathIgnorePatterns": [
|
||||||
"tmp",
|
"tmp",
|
||||||
"files"
|
"files"
|
||||||
|
|||||||
@ -3,23 +3,6 @@
|
|||||||
Nx (Nrwl Extensions for Angular) is a set of libraries and schematics for the Angular framework.
|
Nx (Nrwl Extensions for Angular) is a set of libraries and schematics for the Angular framework.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Installing
|
|
||||||
|
|
||||||
Add the following dependencies to your project's `package.json` and run `npm install`:
|
|
||||||
|
|
||||||
```
|
|
||||||
{
|
|
||||||
dependencies: {
|
|
||||||
"@nrwl/schematics": "https://github.com/nrwl/schematics-build"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Schematics
|
|
||||||
|
|
||||||
### Installing Nrwl/Schematics
|
### Installing Nrwl/Schematics
|
||||||
|
|
||||||
To be able to do `ng new proj --collection=@nrwl/schematics`, the `@nrwl/schematics` must be available in the current context. There are multiple ways to achieve this.
|
To be able to do `ng new proj --collection=@nrwl/schematics`, the `@nrwl/schematics` must be available in the current context. There are multiple ways to achieve this.
|
||||||
@ -70,6 +53,8 @@ rm -rf context
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Nrwl Workspace
|
### Nrwl Workspace
|
||||||
|
|
||||||
The default layout generated by the CLI is good for small applications, but does not work that well for large enterprise apps, where many teams works on many apps composed of many shared libraries.
|
The default layout generated by the CLI is good for small applications, but does not work that well for large enterprise apps, where many teams works on many apps composed of many shared libraries.
|
||||||
@ -100,7 +85,7 @@ It's similar to the standard CLI projects with a few changes:
|
|||||||
|
|
||||||
#### Create an App
|
#### Create an App
|
||||||
|
|
||||||
Run `schematics @nrwl/schematics:app --name=myapp`, and you will see the following files created:
|
Run `ng generate app myapp --collection=@nrwl/schematics`, and you will see the following files created:
|
||||||
|
|
||||||
```
|
```
|
||||||
apps/myapp/src/main.ts
|
apps/myapp/src/main.ts
|
||||||
@ -119,7 +104,7 @@ As with the standard CLI, running `ng build` without specifying an app will buil
|
|||||||
|
|
||||||
#### Create a Lib
|
#### Create a Lib
|
||||||
|
|
||||||
Run `schematics @nrwl/schematics:lib --name=mylib`, and you will see the following files created:
|
Run `ng generate lib mylib --collection=@nrwl/schematics`, and you will see the following files created:
|
||||||
|
|
||||||
```
|
```
|
||||||
libs/mylib/src/mylib.ts
|
libs/mylib/src/mylib.ts
|
||||||
@ -171,7 +156,7 @@ schematics @nrwl/schematics:convert-to-workspace
|
|||||||
|
|
||||||
#### Root
|
#### Root
|
||||||
|
|
||||||
Run `schematics @nrwl/schematics:ngrx --module=src/app/app.module.ts --root`, and you will see the following files created:
|
Run `ng generate ngrx app --module=src/app/app.module.ts --root --collection=@nrwl/schematics`, and you will see the following files created:
|
||||||
|
|
||||||
```
|
```
|
||||||
/src/app/+state/app.actions.ts
|
/src/app/+state/app.actions.ts
|
||||||
@ -187,11 +172,11 @@ Also, `app.module.ts` will have `StoreModule.forRoot` and `EffectsModule.forRoot
|
|||||||
|
|
||||||
#### onlyEmptyRoot
|
#### onlyEmptyRoot
|
||||||
|
|
||||||
Run `schematics @nrwl/schematics:ngrx --module=src/app/app.module.ts --onlyEmptyRoot` 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 --collection=@nrwl/schematics` to only add the `StoreModule.forRoot` and `EffectsModule.forRoot` calls without generating any new files.
|
||||||
|
|
||||||
#### Feature
|
#### Feature
|
||||||
|
|
||||||
Run `schematics @nrwl/schematics:ngrx --module=src/app/mymodule/mymodule.module.ts `, and you will see the following files created:
|
Run `ng generate ngrx app --module=src/app/mymodule/mymodule.module.ts --collection=@nrwl/schematics`, and you will see the following files created:
|
||||||
|
|
||||||
```
|
```
|
||||||
/src/app/mymodule/+state/app.actions.ts
|
/src/app/mymodule/+state/app.actions.ts
|
||||||
@ -213,7 +198,7 @@ Add `--onlyAddFiles` to generate files without adding imports to the module.
|
|||||||
|
|
||||||
### upgrade-shell
|
### upgrade-shell
|
||||||
|
|
||||||
Run `schematics @nrwl/schematics:upgrade-shell --module=src/app/app.module.ts --angularJsImport=legacy --angularJsCmpSelector=rootLegacyCmp` and you will see the following files created:
|
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:
|
||||||
|
|
||||||
```
|
```
|
||||||
/src/app/legacy-setup.ts
|
/src/app/legacy-setup.ts
|
||||||
|
|||||||
@ -22,7 +22,6 @@ function updatePackageJson() {
|
|||||||
packageJson.dependencies['@nrwl/nx'] = nxVersion;
|
packageJson.dependencies['@nrwl/nx'] = nxVersion;
|
||||||
packageJson.devDependencies['@nrwl/schematics'] = schematicsVersion;
|
packageJson.devDependencies['@nrwl/schematics'] = schematicsVersion;
|
||||||
host.overwrite('package.json', JSON.stringify(packageJson, null, 2));
|
host.overwrite('package.json', JSON.stringify(packageJson, null, 2));
|
||||||
|
|
||||||
return host;
|
return host;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -47,6 +46,13 @@ function updateAngularCLIJson() {
|
|||||||
app.tsconfig = '../../../tsconfig.app.json';
|
app.tsconfig = '../../../tsconfig.app.json';
|
||||||
app.testTsconfig = '../../../tsconfig.spec.json';
|
app.testTsconfig = '../../../tsconfig.spec.json';
|
||||||
app.scripts = app.scripts.map((p) => path.join('../../', p));
|
app.scripts = app.scripts.map((p) => path.join('../../', p));
|
||||||
|
if (!app.defaults) {
|
||||||
|
app.defaults = {};
|
||||||
|
}
|
||||||
|
if (!app.defaults.schematics) {
|
||||||
|
app.defaults.schematics = {};
|
||||||
|
}
|
||||||
|
app.defaults.schematics['newProject'] = ['app', 'lib'];
|
||||||
|
|
||||||
host.overwrite('.angular-cli.json', JSON.stringify(angularCliJson, null, 2));
|
host.overwrite('.angular-cli.json', JSON.stringify(angularCliJson, null, 2));
|
||||||
|
|
||||||
@ -96,7 +102,7 @@ function updateProtractorConf() {
|
|||||||
const angularCliJson = JSON.parse(host.read('.angular-cli.json')!.toString('utf-8'));
|
const angularCliJson = JSON.parse(host.read('.angular-cli.json')!.toString('utf-8'));
|
||||||
|
|
||||||
protractorConf.replace(`'./e2e/**/*.e2e-spec.ts'`, `'.apps/${angularCliJson.project.name}/e2e/**/*.e2e-spec.ts'`)
|
protractorConf.replace(`'./e2e/**/*.e2e-spec.ts'`, `'.apps/${angularCliJson.project.name}/e2e/**/*.e2e-spec.ts'`)
|
||||||
.replace(`'e2e/tsconfig.e2e.json'`, `'./tsconfig.e2e.json'`);
|
.replace(`'e2e/tsconfig.e2e.json'`, `'./tsconfig.e2e.json'`);
|
||||||
|
|
||||||
host.overwrite('protractor.conf.js', JSON.stringify(protractorConf, null, 2));
|
host.overwrite('protractor.conf.js', JSON.stringify(protractorConf, null, 2));
|
||||||
|
|
||||||
|
|||||||
@ -107,7 +107,7 @@ function addNgRxToPackageJson() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function(options: Schema): Rule {
|
export default function(options: Schema): Rule {
|
||||||
const name = path.basename(options.module, '.module.ts');
|
const name = options.name;
|
||||||
const moduleDir = path.dirname(options.module);
|
const moduleDir = path.dirname(options.module);
|
||||||
|
|
||||||
if (options.onlyEmptyRoot) {
|
if (options.onlyEmptyRoot) {
|
||||||
|
|||||||
1
packages/schematics/src/ngrx/schema.d.ts
vendored
1
packages/schematics/src/ngrx/schema.d.ts
vendored
@ -1,4 +1,5 @@
|
|||||||
export interface Schema {
|
export interface Schema {
|
||||||
|
name: string;
|
||||||
onlyEmptyRoot: boolean;
|
onlyEmptyRoot: boolean;
|
||||||
root: boolean;
|
root: boolean;
|
||||||
onlyAddFiles: boolean;
|
onlyAddFiles: boolean;
|
||||||
|
|||||||
@ -4,10 +4,13 @@
|
|||||||
"title": "Add NgRx support to a module",
|
"title": "Add NgRx support to a module",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Name of the directory (e.g., state)."
|
||||||
|
},
|
||||||
"module": {
|
"module": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Path to anAngular module (e.g., src/app/app.module.ts).",
|
"description": "Path to an Angular module (e.g., src/app/app.module.ts)."
|
||||||
"alias": "name"
|
|
||||||
},
|
},
|
||||||
"onlyAddFiles": {
|
"onlyAddFiles": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
@ -31,6 +34,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
"name",
|
||||||
"module"
|
"module"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import {Schema} from './schema';
|
|||||||
import {angularJsVersion} from '../utility/lib-versions';
|
import {angularJsVersion} from '../utility/lib-versions';
|
||||||
|
|
||||||
|
|
||||||
function addImportsToModule(moduleClassName: string, angularJsModule: string, options: Schema): Rule {
|
function addImportsToModule(moduleClassName: string, options: Schema): Rule {
|
||||||
return (host: Tree) => {
|
return (host: Tree) => {
|
||||||
if (!host.exists(options.module)) {
|
if (!host.exists(options.module)) {
|
||||||
throw new Error('Specified module does not exist');
|
throw new Error('Specified module does not exist');
|
||||||
@ -22,8 +22,8 @@ function addImportsToModule(moduleClassName: string, angularJsModule: string, op
|
|||||||
|
|
||||||
insert(host, modulePath, [
|
insert(host, modulePath, [
|
||||||
insertImport(
|
insertImport(
|
||||||
source, modulePath, `configure${toClassName(angularJsModule)}, upgradedComponents`,
|
source, modulePath, `configure${toClassName(options.name)}, upgradedComponents`,
|
||||||
`./${toFileName(angularJsModule)}-setup`),
|
`./${toFileName(options.name)}-setup`),
|
||||||
insertImport(source, modulePath, 'UpgradeModule', '@angular/upgrade/static'),
|
insertImport(source, modulePath, 'UpgradeModule', '@angular/upgrade/static'),
|
||||||
...addImportToModule(source, modulePath, 'UpgradeModule'),
|
...addImportToModule(source, modulePath, 'UpgradeModule'),
|
||||||
...addDeclarationToModule(source, modulePath, '...upgradedComponents'),
|
...addDeclarationToModule(source, modulePath, '...upgradedComponents'),
|
||||||
@ -35,7 +35,7 @@ function addImportsToModule(moduleClassName: string, angularJsModule: string, op
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function addNgDoBootstrapToModule(moduleClassName: string, angularJsModule: string, options: Schema): Rule {
|
function addNgDoBootstrapToModule(moduleClassName: string, options: Schema): Rule {
|
||||||
return (host: Tree) => {
|
return (host: Tree) => {
|
||||||
const modulePath = options.module;
|
const modulePath = options.module;
|
||||||
const sourceText = host.read(modulePath)!.toString('utf-8');
|
const sourceText = host.read(modulePath)!.toString('utf-8');
|
||||||
@ -48,8 +48,8 @@ function addNgDoBootstrapToModule(moduleClassName: string, angularJsModule: stri
|
|||||||
className: moduleClassName,
|
className: moduleClassName,
|
||||||
methodHeader: 'ngDoBootstrap(): void',
|
methodHeader: 'ngDoBootstrap(): void',
|
||||||
body: `
|
body: `
|
||||||
configure${toClassName(angularJsModule)}(this.upgrade.injector);
|
configure${toClassName(options.name)}(this.upgrade.injector);
|
||||||
this.upgrade.bootstrap(document.body, ['downgraded', '${angularJsModule}']);
|
this.upgrade.bootstrap(document.body, ['downgraded', '${options.name}']);
|
||||||
`
|
`
|
||||||
}),
|
}),
|
||||||
...removeFromNgModule(source, modulePath, 'bootstrap')
|
...removeFromNgModule(source, modulePath, 'bootstrap')
|
||||||
@ -59,7 +59,7 @@ this.upgrade.bootstrap(document.body, ['downgraded', '${angularJsModule}']);
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function createFiles(moduleClassName: string, moduleFileName: string, angularJsModule: string, options: Schema): Rule {
|
function createFiles(angularJsImport: string, moduleClassName: string, moduleFileName: string, options: Schema): Rule {
|
||||||
return (host: Tree, context: SchematicContext) => {
|
return (host: Tree, context: SchematicContext) => {
|
||||||
const modulePath = options.module;
|
const modulePath = options.module;
|
||||||
const moduleSourceText = host.read(modulePath)!.toString('utf-8');
|
const moduleSourceText = host.read(modulePath)!.toString('utf-8');
|
||||||
@ -76,10 +76,11 @@ function createFiles(moduleClassName: string, moduleFileName: string, angularJsM
|
|||||||
tmpl: '',
|
tmpl: '',
|
||||||
moduleFileName,
|
moduleFileName,
|
||||||
moduleClassName,
|
moduleClassName,
|
||||||
angularJsModule,
|
angularJsImport,
|
||||||
|
angularJsModule: options.name,
|
||||||
bootstrapComponentClassName,
|
bootstrapComponentClassName,
|
||||||
bootstrapComponentFileName,
|
bootstrapComponentFileName,
|
||||||
...names(angularJsModule)
|
...names(options.name)
|
||||||
}),
|
}),
|
||||||
move(moduleDir)
|
move(moduleDir)
|
||||||
]);
|
]);
|
||||||
@ -114,12 +115,11 @@ function addUpgradeToPackageJson() {
|
|||||||
export default function(options: Schema): Rule {
|
export default function(options: Schema): Rule {
|
||||||
const moduleFileName = path.basename(options.module, '.ts');
|
const moduleFileName = path.basename(options.module, '.ts');
|
||||||
const moduleClassName = `${toClassName(moduleFileName)}`;
|
const moduleClassName = `${toClassName(moduleFileName)}`;
|
||||||
const angularJsModule = options.angularJsModule ? options.angularJsModule : path.basename(options.angularJsImport);
|
const angularJsImport = options.angularJsImport ? options.angularJsImport : options.name;
|
||||||
|
|
||||||
return chain([
|
return chain([
|
||||||
createFiles(moduleClassName, moduleFileName, angularJsModule, options),
|
createFiles(angularJsImport, moduleClassName, moduleFileName, options),
|
||||||
addImportsToModule(moduleClassName, angularJsModule, options),
|
addImportsToModule(moduleClassName, options), addNgDoBootstrapToModule(moduleClassName, options),
|
||||||
addNgDoBootstrapToModule(moduleClassName, angularJsModule, options),
|
|
||||||
options.skipPackageJson ? noop() : addUpgradeToPackageJson()
|
options.skipPackageJson ? noop() : addUpgradeToPackageJson()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
export interface Schema {
|
export interface Schema {
|
||||||
angularJsImport: string;
|
angularJsImport: string;
|
||||||
angularJsModule: string;
|
|
||||||
angularJsCmpSelector: string;
|
angularJsCmpSelector: string;
|
||||||
module: string;
|
module: string;
|
||||||
|
name: string;
|
||||||
skipPackageJson: boolean;
|
skipPackageJson: boolean;
|
||||||
router: boolean;
|
router: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,19 +4,18 @@
|
|||||||
"title": "Add an upgrade shell to an application",
|
"title": "Add an upgrade shell to an application",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "The name of the main AngularJS module."
|
||||||
|
},
|
||||||
"module": {
|
"module": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Path to the Angular module with a bootstrap component (e.g., --module=src/app/app.module.ts).",
|
"description": "Path to the Angular module with a bootstrap component (e.g., --module=src/app/app.module.ts)."
|
||||||
"alias": "name"
|
|
||||||
},
|
},
|
||||||
"angularJsImport": {
|
"angularJsImport": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Import expression of the AngularJS application (e.g., --angularJsImport=some_node_module/my_app)."
|
"description": "Import expression of the AngularJS application (e.g., --angularJsImport=some_node_module/my_app)."
|
||||||
},
|
},
|
||||||
"angularJsModule": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The name of the main AngularJS module (e.g., --angularJsModule=myAppModule). If not specified, the last segment of angularJsImport will be used."
|
|
||||||
},
|
|
||||||
"angularJsCmpSelector": {
|
"angularJsCmpSelector": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The selector of an AngularJS component (e.g., --angularJsCmpSelector=myComponent)"
|
"description": "The selector of an AngularJS component (e.g., --angularJsCmpSelector=myComponent)"
|
||||||
@ -33,8 +32,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"module",
|
"name",
|
||||||
"angularJsImport",
|
"module"
|
||||||
"angularJsCmpSelector"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"defaults": {
|
"defaults": {
|
||||||
|
"schematics": {
|
||||||
|
"newProject": ["app", "lib"]
|
||||||
|
},
|
||||||
"styleExt": "<%= style %>",<% if (!minimal) { %>
|
"styleExt": "<%= style %>",<% if (!minimal) { %>
|
||||||
"component": {}<% } else { %>
|
"component": {}<% } else { %>
|
||||||
"component": {
|
"component": {
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
"@nrwl/nx": "<%= nxVersion %>"
|
"@nrwl/nx": "<%= nxVersion %>"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@angular/cli": "<%= version %>",
|
"@angular/cli": "nrwl/fix-cli-build",
|
||||||
"@angular/compiler-cli": "^4.2.4",
|
"@angular/compiler-cli": "^4.2.4",
|
||||||
"@nrwl/schematics": "<%= schematicsVersion %>",
|
"@nrwl/schematics": "<%= schematicsVersion %>",
|
||||||
"@angular/language-service": "^4.2.4",<% if (!minimal) { %>
|
"@angular/language-service": "^4.2.4",<% if (!minimal) { %>
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
rm -rf ./node_modules/clis
|
rm -rf ./node_modules/clis
|
||||||
mkdir ./node_modules/clis
|
mkdir ./node_modules/clis
|
||||||
|
rm -rf ./node_modules/@angular/cli/node_modules
|
||||||
|
rm -rf ./node_modules/bazel-cli/node_modules
|
||||||
cp -rf ./node_modules/@angular/cli ./node_modules/clis/standard
|
cp -rf ./node_modules/@angular/cli ./node_modules/clis/standard
|
||||||
cp -rf ./node_modules/bazel-cli ./node_modules/clis/bazel
|
cp -rf ./node_modules/bazel-cli ./node_modules/clis/bazel
|
||||||
rm -rf ./node_modules/clis/bazel/node_modules
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user