Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(schematics): rename template files to avoid compilation #1586

Merged
merged 11 commits into from
Feb 28, 2019
7 changes: 5 additions & 2 deletions modules/effects/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
SchematicsException,
Tree,
apply,
applyTemplates,
branchAndMerge,
chain,
filter,
Expand Down Expand Up @@ -121,8 +122,10 @@ export default function(options: RootEffectOptions): Rule {
options.path = parsedPath.path;

const templateSource = apply(url('./files'), [
options.spec ? noop() : filter(path => !path.endsWith('__spec.ts')),
template({
options.spec
? noop()
: filter(path => !path.endsWith('.spec.ts.template')),
applyTemplates({
...stringUtils,
'if-flat': (s: string) =>
stringUtils.group(
Expand Down
16 changes: 10 additions & 6 deletions modules/schematics/src/action/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { strings } from '@angular-devkit/core';
santoshyadavdev marked this conversation as resolved.
Show resolved Hide resolved
import {
Rule,
SchematicsException,
apply,
applyTemplates,
branchAndMerge,
chain,
filter,
Expand Down Expand Up @@ -29,17 +31,19 @@ export default function(options: ActionOptions): Rule {
options.path = parsedPath.path;

const templateSource = apply(url('./files'), [
options.spec ? noop() : filter(path => !path.endsWith('__spec.ts')),
template({
options.spec
? noop()
: filter(path => !path.endsWith('.spec.ts.template')),
applyTemplates({
...stringUtils,
'if-flat': (s: string) =>
stringUtils.group(
options.flat ? '' : s,
options.group ? 'actions' : ''
),
...stringUtils,
...(options as object),
dot: () => '.',
} as any),
...options,
dot: '.',
santoshyadavdev marked this conversation as resolved.
Show resolved Hide resolved
}),
move(parsedPath.path),
]);

Expand Down
9 changes: 6 additions & 3 deletions modules/schematics/src/container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
chain,
externalSchematic,
apply,
applyTemplates,
url,
noop,
filter,
Expand Down Expand Up @@ -136,12 +137,14 @@ export default function(options: ContainerOptions): Rule {
);

const templateSource = apply(url('./files'), [
options.spec ? noop() : filter(path => !path.endsWith('__spec.ts')),
template({
options.spec
? noop()
: filter(path => !path.endsWith('__spec.ts.template')),
applyTemplates({
'if-flat': (s: string) => (options.flat ? '' : s),
...stringUtils,
...(options as object),
dot: () => '.',
dot: '.',
} as any),
move(parsedPath.path),
]);
Expand Down
9 changes: 6 additions & 3 deletions modules/schematics/src/effect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
SchematicsException,
Tree,
apply,
applyTemplates,
branchAndMerge,
chain,
filter,
Expand Down Expand Up @@ -105,16 +106,18 @@ export default function(options: EffectOptions): Rule {
options.path = parsedPath.path;

const templateSource = apply(url('./files'), [
options.spec ? noop() : filter(path => !path.endsWith('__spec.ts')),
template({
options.spec
? noop()
: filter(path => !path.endsWith('.spec.ts.template')),
applyTemplates({
...stringUtils,
'if-flat': (s: string) =>
stringUtils.group(
options.flat ? '' : s,
options.group ? 'effects' : ''
),
...(options as object),
dot: () => '.',
dot: '.',
} as any),
move(parsedPath.path),
]);
Expand Down
9 changes: 6 additions & 3 deletions modules/schematics/src/entity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Rule,
SchematicsException,
apply,
applyTemplates,
branchAndMerge,
chain,
filter,
Expand Down Expand Up @@ -36,8 +37,10 @@ export default function(options: EntityOptions): Rule {
}

const templateSource = apply(url('./files'), [
options.spec ? noop() : filter(path => !path.endsWith('__spec.ts')),
template({
options.spec
? noop()
: filter(path => !path.endsWith('.spec.ts.template')),
applyTemplates({
...stringUtils,
'if-flat': (s: string) => (options.flat ? '' : s),
'group-actions': (name: string) =>
Expand All @@ -47,7 +50,7 @@ export default function(options: EntityOptions): Rule {
'group-reducers': (s: string) =>
stringUtils.group(s, options.group ? 'reducers' : ''),
...(options as object),
dot: () => '.',
dot: '.',
} as any),
move(parsedPath.path),
]);
Expand Down
9 changes: 6 additions & 3 deletions modules/schematics/src/reducer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
SchematicsException,
Tree,
apply,
applyTemplates,
branchAndMerge,
chain,
filter,
Expand Down Expand Up @@ -37,16 +38,18 @@ export default function(options: ReducerOptions): Rule {
options.path = parsedPath.path;

const templateSource = apply(url('./files'), [
options.spec ? noop() : filter(path => !path.endsWith('__spec.ts')),
template({
options.spec
? noop()
: filter(path => !path.endsWith('.spec.ts.template')),
applyTemplates({
...stringUtils,
'if-flat': (s: string) =>
stringUtils.group(
options.flat ? '' : s,
options.group ? 'reducers' : ''
),
...(options as object),
dot: () => '.',
dot: '.',
} as any),
move(parsedPath.path),
]);
Expand Down
5 changes: 3 additions & 2 deletions modules/schematics/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
SchematicsException,
Tree,
apply,
applyTemplates,
branchAndMerge,
chain,
mergeWith,
Expand Down Expand Up @@ -156,12 +157,12 @@ export default function(options: StoreOptions): Rule {
}

const templateSource = apply(url('./files'), [
template({
applyTemplates({
...stringUtils,
...(options as object),
isLib: isLib(host, options),
environmentsPath,
} as any),
}),
move(parsedPath.path),
]);

Expand Down
6 changes: 4 additions & 2 deletions modules/store/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('Store ng-add Schematic', () => {
};

const projectPath = getTestProjectPath();

let appTree: UnitTestTree;

beforeEach(() => {
Expand All @@ -33,6 +32,7 @@ describe('Store ng-add Schematic', () => {
const options = { ...defaultOptions };

const tree = schematicRunner.runSchematic('ng-add', options, appTree);

const packageJson = JSON.parse(tree.readContent('/package.json'));

expect(packageJson.dependencies['@ngrx/store']).toBeDefined();
Expand Down Expand Up @@ -105,11 +105,11 @@ describe('Store ng-add Schematic', () => {

it('should support a default root state interface name', () => {
const options = { ...defaultOptions, name: 'State' };

const tree = schematicRunner.runSchematic('ng-add', options, appTree);
const content = tree.readContent(
`${projectPath}/src/app/reducers/index.ts`
);

expect(content).toMatch(/export interface State {/);
});

Expand All @@ -121,9 +121,11 @@ describe('Store ng-add Schematic', () => {
};

const tree = schematicRunner.runSchematic('ng-add', options, appTree);

const content = tree.readContent(
`${projectPath}/src/app/reducers/index.ts`
);

expect(content).toMatch(/export interface AppState {/);
});
});
10 changes: 6 additions & 4 deletions modules/store/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { strings } from '@angular-devkit/core';
santoshyadavdev marked this conversation as resolved.
Show resolved Hide resolved
import {
Rule,
SchematicContext,
SchematicsException,
Tree,
apply,
applyTemplates,
branchAndMerge,
chain,
mergeWith,
Expand Down Expand Up @@ -121,11 +123,11 @@ export default function(options: RootStoreOptions): Rule {
}

const templateSource = apply(url('./files'), [
template({
...stringUtils,
...(options as object),
applyTemplates({
...strings,
...options,
environmentsPath,
} as any),
}),
move(parsedPath.path),
]);

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.10.0",
"@angular-devkit/core": "^7.3.3",
santoshyadavdev marked this conversation as resolved.
Show resolved Hide resolved
"@angular-devkit/schematics": "^7.3.3",
santoshyadavdev marked this conversation as resolved.
Show resolved Hide resolved
"@bazel/bazel": "^0.19.1",
"@cypress/webpack-preprocessor": "^4.0.3",
"@octokit/rest": "^15.17.0",
Expand Down
29 changes: 29 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,32 @@
rxjs "6.3.3"
source-map "0.7.3"

"@angular-devkit/core@7.3.3":
santoshyadavdev marked this conversation as resolved.
Show resolved Hide resolved
version "7.3.3"
resolved "https://registry.yarnpkg.com/@angular-devkit/core/-/core-7.3.3.tgz#cd6d5a8eca25ef07b6394bc2b08133d90d08d39f"
integrity sha512-fosULDtMoDWrOyUzTmBkJccOy7zodo02kENyKai7vOv9EWfv9jytkVdNc+jl0ys9OE2QadvSYBo49jhnZxFXfQ==
dependencies:
ajv "6.9.1"
chokidar "2.0.4"
fast-json-stable-stringify "2.0.0"
rxjs "6.3.3"
source-map "0.7.3"

"@angular-devkit/schematics@7.0.1":
version "7.0.1"
resolved "https://registry.yarnpkg.com/@angular-devkit/schematics/-/schematics-7.0.1.tgz#ccd7c5349c08aaf6224a28881bfeeacaf0ee0307"
dependencies:
"@angular-devkit/core" "7.0.1"
rxjs "6.3.3"

"@angular-devkit/schematics@^7.3.3":
version "7.3.3"
resolved "https://registry.yarnpkg.com/@angular-devkit/schematics/-/schematics-7.3.3.tgz#80e9dc3197a3181f32edfb5c07e7ac016eace7d3"
integrity sha512-SdDq9eKwceb6WLwci1fywtZ/kARR5CYyzi5dZIR1lOxrz00682uUBqH/X39mKdqc6eVqR7rtPceqNm6nQpOIMg==
dependencies:
"@angular-devkit/core" "7.3.3"
rxjs "6.3.3"

"@angular/animations@^7.0.1":
version "7.0.1"
resolved "https://registry.yarnpkg.com/@angular/animations/-/animations-7.0.1.tgz#2df561c0959e156985297e69b7c30614537b4ffe"
Expand Down Expand Up @@ -1350,6 +1369,16 @@ ajv@6.5.3:
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

ajv@6.9.1:
version "6.9.1"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.9.1.tgz#a4d3683d74abc5670e75f0b16520f70a20ea8dc1"
integrity sha512-XDN92U311aINL77ieWHmqCcNlwjoP5cHXDxIxbf2MaPYuCXOHS7gHH8jktxeK5omgd52XbSTX6a4Piwd1pQmzA==
dependencies:
fast-deep-equal "^2.0.1"
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

ajv@^5.0.0, ajv@^5.1.0, ajv@^5.3.0:
version "5.5.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.5.2.tgz#73b5eeca3fab653e3d3f9422b341ad42205dc965"
Expand Down