cleanup(schematics): cleanup

This commit is contained in:
vsavkin 2017-09-14 11:46:54 -04:00
parent 8c62e8451f
commit f570d7ab29
11 changed files with 126 additions and 42 deletions

View File

@ -24,7 +24,7 @@ describe('Upgrade', () => {
'@nrwl/schematics:upgrade-shell ' +
'--module=src/app/app.module.ts ' +
'--angularJsImport=../legacy ' +
'--angularJsCmpSelector=rootLegacyCmp');
'--angularJsCmpSelector=rootLegacyCmp ');
runCLI('build');
runCLI('test --single-run');

View File

@ -25,11 +25,11 @@ describe('Nrwl Workspace', () => {
expect(angularCliJson.apps[0].name).toEqual('myapp');
checkFilesExists(
'proj/apps/myapp/src/main.ts', 'proj2/apps/myapp/src/app/app.module.ts',
'proj/apps/myapp/src/app/app.component.ts', 'proj2/apps/myapp/e2e/app.po.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');
runCLI('build --aot');
checkFilesExists('proj/dist/apps/myapp/main.bundle.js');
checkFilesExists('dist/apps/myapp/main.bundle.js');
expect(runCLI('test --single-run')).toContain('Executed 1 of 1 SUCCESS');
});

View File

@ -28,7 +28,8 @@
"@angular/platform-browser-dynamic": "4.3.5",
"@angular/router": "4.3.5",
"@angular/upgrade": "4.3.5",
"@angular/cli": "1.4.0-rc.2",
"@angular/compiler-cli": "4.3.5",
"@angular/cli": "nrwl/fix-cli-build",
"@ngrx/store": "4.0.3",
"@ngrx/router-store": "4.0.3",
"@ngrx/effects": "4.0.3",

View File

@ -1 +1,2 @@
export {DataPersistence} from './src/data-persistence';
export {NxModule} from './src/nx.module';

View File

@ -12,6 +12,7 @@ import {_throw} from 'rxjs/observable/throw';
import {Subject} from 'rxjs/Subject';
import {DataPersistence} from '../index';
import {NxModule} from '../src/nx.module';
import {readAll} from '../testing';
// interfaces
@ -76,9 +77,8 @@ describe('DataPersistence', () => {
declarations: [RootCmp, TodoComponent],
imports: [
StoreModule.forRoot({todos: todosReducer, user: userReducer}), StoreRouterConnectingModule,
RouterTestingModule.withRoutes([{path: 'todo/:id', component: TodoComponent}])
],
providers: [DataPersistence]
RouterTestingModule.withRoutes([{path: 'todo/:id', component: TodoComponent}]), NxModule.forRoot()
]
});
});

View File

@ -13,14 +13,14 @@ import {switchMap} from 'rxjs/operator/switchMap';
import {withLatestFrom} from 'rxjs/operator/withLatestFrom';
/**
* See DataPersistence.pessimisticUpdate for more information.
* See {@link DataPersistence.pessimisticUpdate} for more information.
*/
export interface PessimisticUpdateOpts {
run(a: Action, state?: any): Observable<Action>|Action|void;
onError(a: Action, e: any): Observable<any>|any;
}
/**
* See DataPersistence.pessimisticUpdate for more information.
* See {@link DataPersistence.pessimisticUpdate} for more information.
*/
export interface OptimisticUpdateOpts {
run(a: Action, state?: any): Observable<any>|any;
@ -28,7 +28,7 @@ export interface OptimisticUpdateOpts {
}
/**
* See DataPersistence.navigation for more information.
* See {@link DataPersistence.navigation} for more information.
*/
export interface FetchOpts {
run(a: Action, state?: any): Observable<Action>|Action|void;
@ -36,7 +36,7 @@ export interface FetchOpts {
}
/**
* See DataPersistence.navigation for more information.
* See {@link DataPersistence.navigation} for more information.
*/
export interface HandleNavigationOpts {
run(a: ActivatedRouteSnapshot, state?: any): Observable<Action>|Action|void;
@ -44,10 +44,7 @@ export interface HandleNavigationOpts {
}
/**
* Provides convenience methods for implementing common NgRx/Router workflows
*
* * `navigation` handles fetching data when handling router navigation.
* * `pessimisticUpdate` handles updating the server before or after the client has been updated.
* @whatItDoes Provides convenience methods for implementing common operations of talking to the backend.
*/
@Injectable()
export class DataPersistence<T> {
@ -55,11 +52,16 @@ export class DataPersistence<T> {
/**
*
* Handles pessimistic updates (updating the server first).
* @whatItDoes Handles pessimistic updates (updating the server first).
*
* Example:
* It provides the action and the current state. It runs all updates in order by using `concatMap` to prevent race
* conditions.
*
* ```
* * `run` callback must return an action or an observable with an action.
* * `onError` is called when a server update was not successful.
* ## Example:
*
* ```typescript
* @Injectable()
* class TodoEffects {
* @Effect() updateTodo = this.s.pessimisticUpdate('UPDATE_TODO', {
@ -83,7 +85,6 @@ export class DataPersistence<T> {
* constructor(private s: DataPersistence<TodosState>, private backend: Backend) {}
* }
* ```
*
*/
pessimisticUpdate(actionType: string, opts: PessimisticUpdateOpts): Observable<any> {
const nav = this.actions.ofType(actionType);
@ -93,11 +94,18 @@ export class DataPersistence<T> {
/**
*
* Handles optimistic updates (updating the client first).
* @whatItDoes Handles optimistic updates (updating the client first).
*
* Example:
* It provides the action and the current state. It runs all updates in order by using `concatMap` to prevent race
* conditions.
*
* ```
* * `run` callback must return an action or an observable with an action.
* * `undoAction` is called server update was not successful. It must return an action or an observable with an action
* to undo the changes in the client state.
*
* ## Example:
*
* ```typescript
* @Injectable()
* class TodoEffects {
* @Effect() updateTodo = this.s.optimisticUpdate('UPDATE_TODO', {
@ -127,11 +135,16 @@ export class DataPersistence<T> {
/**
*
* Handles data fetching.
* @whatItDoes Handles data fetching.
*
* Example:
* It provides the action and the current state. It only runs the last fetch by using `switchMap`.
*
* ```
* * `run` callback must return an action or an observable with an action.
* * `onError` is called when a server request was not successful.
*
* ## Example:
*
* ```typescript
* @Injectable()
* class TodoEffects {
* @Effect() loadTodo = this.s.fetch('GET_TODOS', {
@ -160,12 +173,18 @@ export class DataPersistence<T> {
}
/**
* Handles ROUTER_NAVIGATION event.
* @whatItDoes Handles data fetching as part of router navigation.
*
* This is useful for loading extra data needed for a router navigation.
* It checks if an activated router state contains the passed in component type, and, if it does, runs the `run`
* callback. It provides the activated snapshot associated with the component and the current state. It only runs the
* last request by using `switchMap`.
*
* Example:
* ```
* * `run` callback must return an action or an observable with an action.
* * `onError` is called when a server request was not successful.
*
* ## Example:
*
* ```typescript
* @Injectable()
* class TodoEffects {
* @Effect() loadTodo = this.s.navigation(TodoComponent, {

View File

@ -0,0 +1,12 @@
import {ModuleWithProviders, NgModule} from '@angular/core';
import {DataPersistence} from './data-persistence';
/**
* @whatItDoes Provides services simplifying enterprise Angular development.
*/
@NgModule({})
export class NxModule {
static forRoot(): ModuleWithProviders {
return {ngModule: NxModule, providers: [DataPersistence]};
}
}

View File

@ -1,19 +1,35 @@
import {apply, branchAndMerge, chain, externalSchematic, mergeWith, move, Rule, template, Tree, url} from '@angular-devkit/schematics';
import {Schema} from './schema';
import * as stringUtils from '@schematics/angular/strings';
import {insert, toFileName} from '@nrwl/schematics';
import {addImportToModule, insert, toFileName} from '@nrwl/schematics';
import * as path from 'path';
import * as ts from 'typescript';
import {addBootstrapToModule, addImportToModule} from '@schematics/angular/utility/ast-utils';
import {addBootstrapToModule} from '@schematics/angular/utility/ast-utils';
import {insertImport} from '@schematics/angular/utility/route-utils';
function addBootstrap(path: string): Rule {
return (host: Tree) => {
const modulePath = `${path}/app/app.module.ts`;
const moduleSource = host.read(modulePath)!.toString('utf-8');
const sourceFile = ts.createSourceFile(modulePath, moduleSource, ts.ScriptTarget.Latest, true);
const importChanges = addImportToModule(sourceFile, modulePath, 'BrowserModule', '@angular/platform-browser');
const bootstrapChanges = addBootstrapToModule(sourceFile, modulePath, 'AppComponent', './app.component');
insert(host, modulePath, [...importChanges, ...bootstrapChanges]);
insert(host, modulePath, [
insertImport(sourceFile, modulePath, 'BrowserModule', '@angular/platform-browser'),
...addImportToModule(sourceFile, modulePath, 'BrowserModule'),
...addBootstrapToModule(sourceFile, modulePath, 'AppComponent', './app.component')
]);
return host;
};
}
function addNxModule(path: string): Rule {
return (host: Tree) => {
const modulePath = `${path}/app/app.module.ts`;
const moduleSource = host.read(modulePath)!.toString('utf-8');
const sourceFile = ts.createSourceFile(modulePath, moduleSource, ts.ScriptTarget.Latest, true);
insert(host, modulePath, [
insertImport(sourceFile, modulePath, 'NxModule', '@nrwl/nx'),
...addImportToModule(sourceFile, modulePath, 'NxModule.forRoot()'),
]);
return host;
};
}
@ -80,6 +96,6 @@ export default function(options: Schema): Rule {
viewEncapsulation: options.viewEncapsulation,
changeDetection: options.changeDetection
}),
addBootstrap(fullPath), addAppToAngularCliJson(options)
addBootstrap(fullPath), addNxModule(fullPath), addAppToAngularCliJson(options)
]);
}

View File

@ -1,5 +1,5 @@
#!/bin/bash
rm -rf build
tsc
ngc
rsync -a --exclude=*.ts packages/ build/packages

View File

@ -23,5 +23,9 @@
"tmp",
"node_modules",
"packages/schematics/src/*/files/**/*"
]
],
"angularCompilerOptions": {
"strictMetadataEmit": true,
"skipTemplateCodegen": true
}
}

View File

@ -23,9 +23,9 @@
minimist "^1.2.0"
rxjs "^5.4.2"
"@angular/cli@1.4.0-rc.2":
"@angular/cli@nrwl/fix-cli-build":
version "1.4.0-rc.2"
resolved "https://registry.yarnpkg.com/@angular/cli/-/cli-1.4.0-rc.2.tgz#0859aa8a622dfb529484a356f18ff27e7f18a8b8"
resolved "https://codeload.github.com/nrwl/fix-cli-build/tar.gz/a8366071746a531bd286450228045e2dc14dd3ee"
dependencies:
"@angular-devkit/build-optimizer" "~0.0.15"
"@angular-devkit/schematics" "~0.0.18"
@ -74,7 +74,7 @@
style-loader "^0.13.1"
stylus "^0.54.5"
stylus-loader "^3.0.1"
typescript ">=2.0.0 <2.5.0"
typescript ">=2.0.0 <2.6.0"
url-loader "^0.5.7"
webpack "~3.5.5"
webpack-concat-plugin "1.4.0"
@ -91,6 +91,14 @@
dependencies:
tslib "^1.7.1"
"@angular/compiler-cli@4.3.5":
version "4.3.5"
resolved "https://registry.yarnpkg.com/@angular/compiler-cli/-/compiler-cli-4.3.5.tgz#24e99b36c0909363ff8247bf331a8b89eaedfe63"
dependencies:
"@angular/tsc-wrapped" "4.3.5"
minimist "^1.2.0"
reflect-metadata "^0.1.2"
"@angular/compiler@4.3.5":
version "4.3.5"
resolved "https://registry.yarnpkg.com/@angular/compiler/-/compiler-4.3.5.tgz#50d3c986657beff1fef4f6dd9a3fa58e24abd548"
@ -121,6 +129,12 @@
dependencies:
tslib "^1.7.1"
"@angular/tsc-wrapped@4.3.5":
version "4.3.5"
resolved "https://registry.yarnpkg.com/@angular/tsc-wrapped/-/tsc-wrapped-4.3.5.tgz#95fdaa813cfc57262fc7ef5fea726d628aefabac"
dependencies:
tsickle "^0.21.0"
"@angular/upgrade@4.3.5":
version "4.3.5"
resolved "https://registry.yarnpkg.com/@angular/upgrade/-/upgrade-4.3.5.tgz#e5e0bf967f8c13db6de6265807eaffdad2420b04"
@ -4585,6 +4599,10 @@ reduce-function-call@^1.0.1:
dependencies:
balanced-match "^0.4.2"
reflect-metadata@^0.1.2:
version "0.1.10"
resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.10.tgz#b4f83704416acad89988c9b15635d47e03b9344a"
regenerate@^1.2.1:
version "1.3.2"
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.2.tgz#d1941c67bad437e1be76433add5b385f95b19260"
@ -5346,6 +5364,15 @@ trim-right@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
tsickle@^0.21.0:
version "0.21.6"
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.21.6.tgz#53b01b979c5c13fdb13afb3fb958177e5991588d"
dependencies:
minimist "^1.2.0"
mkdirp "^0.5.1"
source-map "^0.5.6"
source-map-support "^0.4.2"
tslib@^1.7.1:
version "1.7.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.7.1.tgz#bc8004164691923a79fe8378bbeb3da2017538ec"
@ -5377,10 +5404,14 @@ type-is@~1.6.15:
media-typer "0.3.0"
mime-types "~2.1.15"
typescript@2.4.2, "typescript@>=2.0.0 <2.5.0", typescript@^2.3.3:
typescript@2.4.2, typescript@^2.3.3:
version "2.4.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.2.tgz#f8395f85d459276067c988aa41837a8f82870844"
"typescript@>=2.0.0 <2.6.0":
version "2.5.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.5.2.tgz#038a95f7d9bbb420b1bf35ba31d4c5c1dd3ffe34"
uglify-js@3.0.x:
version "3.0.27"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.0.27.tgz#a97db8c8ba6b9dba4e2f88d86aa9548fa6320034"