refactor(schematics): make all schematics work with ng generate
This commit is contained in:
parent
84c27ba211
commit
9935beef5c
@ -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', () => {
|
||||
beforeEach(cleanup);
|
||||
|
||||
describe('root', () => {
|
||||
it('should generate', () => {
|
||||
newApp('--skip-import');
|
||||
|
||||
runSchematic('@nrwl/schematics:ngrx --module=src/app/app.module.ts --root');
|
||||
newApp('--skip-install');
|
||||
runCLI('generate ngrx app --module=src/app/app.module.ts --root --collection=@nrwl/schematics');
|
||||
|
||||
checkFilesExists(
|
||||
`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('EffectsModule.forRoot');
|
||||
});
|
||||
//
|
||||
|
||||
it('should build', () => {
|
||||
newApp();
|
||||
copyMissingPackages();
|
||||
|
||||
runSchematic('@nrwl/schematics:ngrx --module=src/app/app.module.ts --root');
|
||||
runCLI('generate ngrx app --module=src/app/app.module.ts --root --collection=@nrwl/schematics');
|
||||
|
||||
runCLI('build');
|
||||
runCLI('test --single-run');
|
||||
@ -32,8 +30,7 @@ describe('ngrx', () => {
|
||||
it('should add empty root configuration', () => {
|
||||
newApp();
|
||||
copyMissingPackages();
|
||||
|
||||
runSchematic('@nrwl/schematics:ngrx --module=src/app/app.module.ts --onlyEmptyRoot');
|
||||
runCLI('generate ngrx app --module=src/app/app.module.ts --onlyEmptyRoot --collection=@nrwl/schematics');
|
||||
|
||||
const contents = readFile('src/app/app.module.ts');
|
||||
expect(contents).toContain('StoreModule.forRoot');
|
||||
@ -45,8 +42,8 @@ describe('ngrx', () => {
|
||||
|
||||
describe('feature', () => {
|
||||
it('should generate', () => {
|
||||
newApp('--skipInstall');
|
||||
runSchematic('@nrwl/schematics:ngrx --module=src/app/app.module.ts');
|
||||
newApp('--skip-install');
|
||||
runCLI('generate ngrx app --module=src/app/app.module.ts --collection=@nrwl/schematics');
|
||||
|
||||
checkFilesExists(
|
||||
`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', () => {
|
||||
newApp('--skipInstall');
|
||||
runSchematic('@nrwl/schematics:ngrx --module=src/app/app.module.ts --onlyAddFiles');
|
||||
newApp('--skip-install');
|
||||
runCLI('generate ngrx app --module=src/app/app.module.ts --onlyAddFiles --collection=@nrwl/schematics');
|
||||
|
||||
checkFilesExists(
|
||||
`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', () => {
|
||||
newApp('--skipInstall');
|
||||
runSchematic('@nrwl/schematics:ngrx --module=src/app/app.module.ts');
|
||||
newApp('--skip-install');
|
||||
runCLI('generate ngrx app --module=src/app/app.module.ts --collection=@nrwl/schematics');
|
||||
|
||||
const contents = JSON.parse(readFile('package.json'));
|
||||
|
||||
|
||||
@ -20,24 +20,19 @@ describe('Upgrade', () => {
|
||||
|
||||
updateFile('src/app/app.component.spec.ts', ``);
|
||||
|
||||
runSchematic(
|
||||
'@nrwl/schematics:upgrade-shell ' +
|
||||
'--module=src/app/app.module.ts ' +
|
||||
'--angularJsImport=../legacy ' +
|
||||
'--angularJsCmpSelector=rootLegacyCmp ');
|
||||
runCLI(
|
||||
'generate upgrade-shell legacy --module=src/app/app.module.ts --angularJsImport=../legacy ' +
|
||||
'--angularJsCmpSelector=rootLegacyCmp --collection=@nrwl/schematics');
|
||||
|
||||
runCLI('build');
|
||||
runCLI('test --single-run');
|
||||
}, 50000);
|
||||
|
||||
it('should update package.json', () => {
|
||||
newApp('--skipInstall');
|
||||
|
||||
runSchematic(
|
||||
'@nrwl/schematics:upgrade-shell ' +
|
||||
'--module=src/app/app.module.ts ' +
|
||||
'--angularJsImport=../legacy ' +
|
||||
'--angularJsCmpSelector=rootLegacyCmp');
|
||||
newApp('--skip-install');
|
||||
runCLI(
|
||||
'generate upgrade-shell legacy --module=src/app/app.module.ts --angularJsImport=../legacy ' +
|
||||
'--angularJsCmpSelector=rootLegacyCmp --collection=@nrwl/schematics');
|
||||
|
||||
const contents = JSON.parse(readFile('package.json'));
|
||||
expect(contents.dependencies['@angular/upgrade']).toBeDefined();
|
||||
@ -46,13 +41,9 @@ describe('Upgrade', () => {
|
||||
|
||||
it('should not update package.json when --skipPackageJson', () => {
|
||||
newApp('--skipInstall');
|
||||
|
||||
runSchematic(
|
||||
'@nrwl/schematics:upgrade-shell ' +
|
||||
'--module=src/app/app.module.ts ' +
|
||||
'--angularJsImport=../legacy ' +
|
||||
'--angularJsCmpSelector=rootLegacyCmp ' +
|
||||
'--skipPackageJson');
|
||||
runCLI(
|
||||
'generate upgrade-shell legacy --module=src/app/app.module.ts --angularJsImport=../legacy ' +
|
||||
'--angularJsCmpSelector=rootLegacyCmp --skipPackageJson --collection=@nrwl/schematics');
|
||||
|
||||
const contents = JSON.parse(readFile('package.json'));
|
||||
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', () => {
|
||||
beforeEach(cleanup);
|
||||
@ -17,9 +17,8 @@ describe('Nrwl Workspace', () => {
|
||||
|
||||
describe('app', () => {
|
||||
it('should generate an app', () => {
|
||||
newApp('--collection=@nrwl/schematics');
|
||||
copyMissingPackages();
|
||||
runSchematic('@nrwl/schematics:app --name=myapp');
|
||||
newApp('--collection=@nrwl/schematics --skip-install');
|
||||
runCLI('generate app myapp --collection=@nrwl/schematics');
|
||||
|
||||
const angularCliJson = JSON.parse(readFile('.angular-cli.json'));
|
||||
expect(angularCliJson.apps[0].name).toEqual('myapp');
|
||||
@ -27,10 +26,14 @@ describe('Nrwl Workspace', () => {
|
||||
checkFilesExists(
|
||||
'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');
|
||||
});
|
||||
|
||||
it('should build app', () => {
|
||||
newApp('--collection=@nrwl/schematics');
|
||||
copyMissingPackages();
|
||||
runCLI('generate app myapp --collection=@nrwl/schematics');
|
||||
runCLI('build --aot');
|
||||
checkFilesExists('dist/apps/myapp/main.bundle.js');
|
||||
|
||||
expect(runCLI('test --single-run')).toContain('Executed 1 of 1 SUCCESS');
|
||||
});
|
||||
});
|
||||
@ -38,7 +41,7 @@ describe('Nrwl Workspace', () => {
|
||||
describe('lib', () => {
|
||||
it('should generate a lib', () => {
|
||||
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');
|
||||
});
|
||||
@ -46,8 +49,8 @@ describe('Nrwl Workspace', () => {
|
||||
it('should test a lib', () => {
|
||||
newApp('--collection=@nrwl/schematics');
|
||||
copyMissingPackages();
|
||||
runSchematic('@nrwl/schematics:app --name=myapp');
|
||||
runSchematic('@nrwl/schematics:lib --name=mylib');
|
||||
runCLI('generate app myapp --collection=@nrwl/schematics');
|
||||
runCLI('generate lib mylib --collection=@nrwl/schematics');
|
||||
|
||||
expect(runCLI('test --single-run')).toContain('Executed 2 of 2 SUCCESS');
|
||||
});
|
||||
@ -56,7 +59,7 @@ describe('Nrwl Workspace', () => {
|
||||
describe('nglib', () => {
|
||||
it('should generate an ng lib', () => {
|
||||
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');
|
||||
});
|
||||
@ -64,8 +67,8 @@ describe('Nrwl Workspace', () => {
|
||||
it('should test an ng lib', () => {
|
||||
newApp('--collection=@nrwl/schematics');
|
||||
copyMissingPackages();
|
||||
runSchematic('@nrwl/schematics:app --name=myapp');
|
||||
runSchematic('@nrwl/schematics:lib --name=mylib --ngmodule');
|
||||
runCLI('generate app myapp --collection=@nrwl/schematics');
|
||||
runCLI('generate lib mylib --collection=@nrwl/schematics --ngmodule');
|
||||
|
||||
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', () => {
|
||||
newApp('--collection=@nrwl/schematics --npmScope=nrwl');
|
||||
copyMissingPackages();
|
||||
runSchematic('@nrwl/schematics:app --name=myapp');
|
||||
runSchematic('@nrwl/schematics:lib --name=mylib --ngmodule');
|
||||
runCLI('generate app myapp --collection=@nrwl/schematics');
|
||||
runCLI('generate lib mylib --collection=@nrwl/schematics --ngmodule');
|
||||
|
||||
updateFile('apps/myapp/src/app/app.module.ts', `
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
@ -75,13 +75,7 @@ export function exists(filePath: string): boolean {
|
||||
}
|
||||
|
||||
export function copyMissingPackages(): void {
|
||||
const modulesToCopy = [
|
||||
'@ngrx',
|
||||
'jasmine-marbles',
|
||||
'@nrwl',
|
||||
'angular',
|
||||
'@angular/upgrade',
|
||||
];
|
||||
const modulesToCopy = ['@ngrx', 'jasmine-marbles', '@nrwl', 'angular', '@angular/upgrade', '@angular/cli'];
|
||||
modulesToCopy.forEach(m => copyNodeModule(projectName, m));
|
||||
}
|
||||
|
||||
|
||||
32
package.json
32
package.json
@ -21,35 +21,35 @@
|
||||
"jasmine-marbles": "0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"rxjs": "5.4.3",
|
||||
"@angular-devkit/schematics": "0.0.19",
|
||||
"@angular/core": "4.3.5",
|
||||
"@schematics/angular": "^0.0.36",
|
||||
"@angular-devkit/schematics": "^0.0.24",
|
||||
"@angular/cli": "nrwl/fix-cli-build",
|
||||
"@angular/common": "4.3.5",
|
||||
"@angular/platform-browser": "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/router": "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/router-store": "4.0.3",
|
||||
"@ngrx/store": "4.0.3",
|
||||
"@ngrx/store-devtools": "^4.0.0",
|
||||
"typescript": "2.4.2",
|
||||
"@types/node": "8.0.7",
|
||||
"@types/jasmine": "2.5.53",
|
||||
"jest": "20.0.4",
|
||||
"@schematics/angular": "0.0.30",
|
||||
"@types/node": "8.0.7",
|
||||
"angular": "1.6.6",
|
||||
"bazel-cli": "nrwl/bazel-cli-build",
|
||||
"clang-format": "^1.0.32",
|
||||
"jasmine-core": "~2.6.2",
|
||||
"jest": "20.0.4",
|
||||
"karma": "~1.7.0",
|
||||
"karma-chrome-launcher": "~2.1.1",
|
||||
"karma-jasmine": "~1.1.0",
|
||||
"karma-webpack": "2.0.4",
|
||||
"clang-format": "^1.0.32",
|
||||
"angular": "1.6.6",
|
||||
"semver": "^5.4.1"
|
||||
"rxjs": "5.4.3",
|
||||
"semver": "^5.4.1",
|
||||
"typescript": "2.4.2"
|
||||
},
|
||||
"author": "Victor Savkin",
|
||||
"license": "MIT",
|
||||
|
||||
@ -3,23 +3,6 @@
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
@ -119,7 +104,7 @@ As with the standard CLI, running `ng build` without specifying an app will buil
|
||||
|
||||
#### 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
|
||||
@ -171,7 +156,7 @@ schematics @nrwl/schematics:convert-to-workspace
|
||||
|
||||
#### 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
|
||||
@ -187,11 +172,11 @@ Also, `app.module.ts` will have `StoreModule.forRoot` and `EffectsModule.forRoot
|
||||
|
||||
#### 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
|
||||
|
||||
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
|
||||
@ -213,7 +198,7 @@ Add `--onlyAddFiles` to generate files without adding imports to the module.
|
||||
|
||||
### 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
|
||||
|
||||
@ -22,7 +22,6 @@ function updatePackageJson() {
|
||||
packageJson.dependencies['@nrwl/nx'] = nxVersion;
|
||||
packageJson.devDependencies['@nrwl/schematics'] = schematicsVersion;
|
||||
host.overwrite('package.json', JSON.stringify(packageJson, null, 2));
|
||||
|
||||
return host;
|
||||
};
|
||||
}
|
||||
@ -47,6 +46,13 @@ function updateAngularCLIJson() {
|
||||
app.tsconfig = '../../../tsconfig.app.json';
|
||||
app.testTsconfig = '../../../tsconfig.spec.json';
|
||||
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));
|
||||
|
||||
|
||||
@ -107,7 +107,7 @@ function addNgRxToPackageJson() {
|
||||
}
|
||||
|
||||
export default function(options: Schema): Rule {
|
||||
const name = path.basename(options.module, '.module.ts');
|
||||
const name = options.name;
|
||||
const moduleDir = path.dirname(options.module);
|
||||
|
||||
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 {
|
||||
name: string;
|
||||
onlyEmptyRoot: boolean;
|
||||
root: boolean;
|
||||
onlyAddFiles: boolean;
|
||||
|
||||
@ -4,10 +4,13 @@
|
||||
"title": "Add NgRx support to a module",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "Name of the directory (e.g., state)."
|
||||
},
|
||||
"module": {
|
||||
"type": "string",
|
||||
"description": "Path to anAngular module (e.g., src/app/app.module.ts).",
|
||||
"alias": "name"
|
||||
"description": "Path to an Angular module (e.g., src/app/app.module.ts)."
|
||||
},
|
||||
"onlyAddFiles": {
|
||||
"type": "boolean",
|
||||
@ -31,6 +34,7 @@
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"module"
|
||||
]
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ import {Schema} from './schema';
|
||||
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) => {
|
||||
if (!host.exists(options.module)) {
|
||||
throw new Error('Specified module does not exist');
|
||||
@ -22,8 +22,8 @@ function addImportsToModule(moduleClassName: string, angularJsModule: string, op
|
||||
|
||||
insert(host, modulePath, [
|
||||
insertImport(
|
||||
source, modulePath, `configure${toClassName(angularJsModule)}, upgradedComponents`,
|
||||
`./${toFileName(angularJsModule)}-setup`),
|
||||
source, modulePath, `configure${toClassName(options.name)}, upgradedComponents`,
|
||||
`./${toFileName(options.name)}-setup`),
|
||||
insertImport(source, modulePath, 'UpgradeModule', '@angular/upgrade/static'),
|
||||
...addImportToModule(source, modulePath, 'UpgradeModule'),
|
||||
...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) => {
|
||||
const modulePath = options.module;
|
||||
const sourceText = host.read(modulePath)!.toString('utf-8');
|
||||
@ -48,8 +48,8 @@ function addNgDoBootstrapToModule(moduleClassName: string, angularJsModule: stri
|
||||
className: moduleClassName,
|
||||
methodHeader: 'ngDoBootstrap(): void',
|
||||
body: `
|
||||
configure${toClassName(angularJsModule)}(this.upgrade.injector);
|
||||
this.upgrade.bootstrap(document.body, ['downgraded', '${angularJsModule}']);
|
||||
configure${toClassName(options.name)}(this.upgrade.injector);
|
||||
this.upgrade.bootstrap(document.body, ['downgraded', '${options.name}']);
|
||||
`
|
||||
}),
|
||||
...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) => {
|
||||
const modulePath = options.module;
|
||||
const moduleSourceText = host.read(modulePath)!.toString('utf-8');
|
||||
@ -76,10 +76,11 @@ function createFiles(moduleClassName: string, moduleFileName: string, angularJsM
|
||||
tmpl: '',
|
||||
moduleFileName,
|
||||
moduleClassName,
|
||||
angularJsModule,
|
||||
angularJsImport,
|
||||
angularJsModule: options.name,
|
||||
bootstrapComponentClassName,
|
||||
bootstrapComponentFileName,
|
||||
...names(angularJsModule)
|
||||
...names(options.name)
|
||||
}),
|
||||
move(moduleDir)
|
||||
]);
|
||||
@ -114,12 +115,11 @@ function addUpgradeToPackageJson() {
|
||||
export default function(options: Schema): Rule {
|
||||
const moduleFileName = path.basename(options.module, '.ts');
|
||||
const moduleClassName = `${toClassName(moduleFileName)}`;
|
||||
const angularJsModule = options.angularJsModule ? options.angularJsModule : path.basename(options.angularJsImport);
|
||||
const angularJsImport = options.angularJsImport ? options.angularJsImport : options.name;
|
||||
|
||||
return chain([
|
||||
createFiles(moduleClassName, moduleFileName, angularJsModule, options),
|
||||
addImportsToModule(moduleClassName, angularJsModule, options),
|
||||
addNgDoBootstrapToModule(moduleClassName, angularJsModule, options),
|
||||
createFiles(angularJsImport, moduleClassName, moduleFileName, options),
|
||||
addImportsToModule(moduleClassName, options), addNgDoBootstrapToModule(moduleClassName, options),
|
||||
options.skipPackageJson ? noop() : addUpgradeToPackageJson()
|
||||
]);
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
export interface Schema {
|
||||
angularJsImport: string;
|
||||
angularJsModule: string;
|
||||
angularJsCmpSelector: string;
|
||||
module: string;
|
||||
name: string;
|
||||
skipPackageJson: boolean;
|
||||
router: boolean;
|
||||
}
|
||||
|
||||
@ -4,19 +4,18 @@
|
||||
"title": "Add an upgrade shell to an application",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "The name of the main AngularJS module."
|
||||
},
|
||||
"module": {
|
||||
"type": "string",
|
||||
"description": "Path to the Angular module with a bootstrap component (e.g., --module=src/app/app.module.ts).",
|
||||
"alias": "name"
|
||||
"description": "Path to the Angular module with a bootstrap component (e.g., --module=src/app/app.module.ts)."
|
||||
},
|
||||
"angularJsImport": {
|
||||
"type": "string",
|
||||
"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": {
|
||||
"type": "string",
|
||||
"description": "The selector of an AngularJS component (e.g., --angularJsCmpSelector=myComponent)"
|
||||
@ -33,8 +32,7 @@
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"module",
|
||||
"angularJsImport",
|
||||
"angularJsCmpSelector"
|
||||
"name",
|
||||
"module"
|
||||
]
|
||||
}
|
||||
|
||||
@ -26,6 +26,9 @@
|
||||
}
|
||||
},
|
||||
"defaults": {
|
||||
"schematics": {
|
||||
"newProject": ["app", "lib"]
|
||||
},
|
||||
"styleExt": "<%= style %>",<% if (!minimal) { %>
|
||||
"component": {}<% } else { %>
|
||||
"component": {
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
"@nrwl/nx": "<%= nxVersion %>"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular/cli": "<%= version %>",
|
||||
"@angular/cli": "nrwl/fix-cli-build",
|
||||
"@angular/compiler-cli": "^4.2.4",
|
||||
"@nrwl/schematics": "<%= schematicsVersion %>",
|
||||
"@angular/language-service": "^4.2.4",<% if (!minimal) { %>
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
rm -rf ./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/bazel-cli ./node_modules/clis/bazel
|
||||
rm -rf ./node_modules/clis/bazel/node_modules
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user