Skip to content

Commit 037194b

Browse files
committed
fix(@angular/cli): Update schemeatic task & update deps
1 parent bd08f5b commit 037194b

File tree

6 files changed

+21
-94
lines changed

6 files changed

+21
-94
lines changed

package-lock.json

+12-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
"homepage": "https://github.com/angular/angular-cli",
4242
"dependencies": {
4343
"@angular-devkit/build-optimizer": "0.0.13",
44-
"@angular-devkit/schematics": "0.0.15",
45-
"@schematics/angular": "0.0.21",
44+
"@angular-devkit/schematics": "0.0.17",
45+
"@schematics/angular": "0.0.26",
4646
"autoprefixer": "^6.5.3",
4747
"chalk": "^2.0.1",
4848
"circular-dependency-plugin": "^3.0.0",

packages/@angular/cli/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
"homepage": "https://github.com/angular/angular-cli",
2929
"dependencies": {
3030
"@angular-devkit/build-optimizer": "0.0.13",
31-
"@angular-devkit/schematics": "0.0.15",
31+
"@angular-devkit/schematics": "0.0.16",
3232
"@ngtools/json-schema": "1.1.0",
3333
"@ngtools/webpack": "1.7.0-beta.0",
34-
"@schematics/angular": "0.0.21",
34+
"@schematics/angular": "0.0.26",
3535
"autoprefixer": "^6.5.3",
3636
"chalk": "^2.0.1",
3737
"circular-dependency-plugin": "^3.0.0",

packages/@angular/cli/tasks/schematic-run.ts

+2-75
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ import { green, red, yellow } from 'chalk';
1313
import { CliConfig } from '../models/config';
1414
import 'rxjs/add/operator/concatMap';
1515
import 'rxjs/add/operator/map';
16-
import * as fs from 'fs';
1716
import { getCollection, getSchematic } from '../utilities/schematics';
1817
import { getAppFromConfig } from '../utilities/app-utils';
1918

20-
const SilentError = require('silent-error');
2119

2220
const Task = require('../ember-cli/lib/models/task');
2321

@@ -49,27 +47,14 @@ export default Task.extend({
4947

5048
let modifiedFiles: string[] = [];
5149

52-
let appDir = workingDir;
5350
let appConfig;
5451
try {
5552
appConfig = getAppFromConfig(taskOptions.app);
5653
} catch (err) {}
5754

5855
const projectRoot = !!this.project ? this.project.root : workingDir;
5956

60-
if (appConfig) {
61-
const sourceRoot = path.join(projectRoot, appConfig.root);
62-
const appRoot = path.join(sourceRoot, 'app');
63-
if (workingDir.indexOf(appRoot) === 0) {
64-
appDir = workingDir;
65-
} else if (workingDir.indexOf(sourceRoot) === 0) {
66-
appDir = path.join(sourceRoot, 'app');
67-
} else {
68-
appDir = path.join(projectRoot, appConfig.root, 'app');
69-
}
70-
}
71-
72-
const preppedOptions = prepOptions(schematic, appDir, taskOptions, projectRoot);
57+
const preppedOptions = prepOptions(schematic, taskOptions);
7358
const opts = { ...taskOptions, ...preppedOptions };
7459

7560
const host = Observable.of(new FileSystemTree(new FileSystemHost(workingDir)));
@@ -163,8 +148,7 @@ export default Task.extend({
163148
}
164149
});
165150

166-
function prepOptions(schematic: Schematic<{}, {}>, workingDirectory: string,
167-
options: SchematicOptions, projectRoot: string): SchematicOptions {
151+
function prepOptions(schematic: Schematic<{}, {}>, options: SchematicOptions): SchematicOptions {
168152

169153
const properties = (<any>schematic.description).schemaJson.properties;
170154
const keys = Object.keys(properties);
@@ -174,11 +158,6 @@ function prepOptions(schematic: Schematic<{}, {}>, workingDirectory: string,
174158
? '' : options.prefix;
175159
}
176160

177-
const filepathKeys = keys
178-
.filter(key => {
179-
const prop = properties[key];
180-
return prop.type === 'string' && prop.subtype === 'filepath';
181-
});
182161
let preppedOptions = {
183162
...options,
184163
...readDefaults(schematic.description.name, keys, options)
@@ -187,32 +166,6 @@ function prepOptions(schematic: Schematic<{}, {}>, workingDirectory: string,
187166
...preppedOptions,
188167
...normalizeOptions(schematic.description.name, keys, options)
189168
};
190-
preppedOptions = {
191-
...preppedOptions,
192-
...prepFilepaths(filepathKeys, options, workingDirectory, projectRoot)
193-
};
194-
195-
if (preppedOptions.module) {
196-
if (!preppedOptions.module.endsWith('.module.ts')) {
197-
let newModuleValue = preppedOptions.module;
198-
const fullPath = path.join(projectRoot, preppedOptions.module);
199-
if (fs.existsSync(fullPath) && fs.lstatSync(fullPath).isDirectory()) {
200-
const files = fs.readdirSync(path.join(projectRoot, preppedOptions.module));
201-
const moduleFiles = files.filter(f => f.endsWith('.module.ts'));
202-
if (moduleFiles.length === 1) {
203-
newModuleValue = path.join(preppedOptions.module, moduleFiles[0]);
204-
}
205-
} else if (preppedOptions.module.endsWith('.module')) {
206-
newModuleValue = `${newModuleValue}.ts`;
207-
} else {
208-
newModuleValue = `${newModuleValue}.module.ts`;
209-
}
210-
preppedOptions = {
211-
...preppedOptions,
212-
module: newModuleValue
213-
};
214-
}
215-
}
216169

217170
return preppedOptions;
218171
}
@@ -253,29 +206,3 @@ function readDefault(schematicName: String, key: string) {
253206
const jsonPath = `defaults.${schematicName}.${key}`;
254207
return CliConfig.getValue(jsonPath);
255208
}
256-
257-
function prepFilepaths(keys: string[],
258-
options: SchematicOptions,
259-
workingDirectory: string,
260-
projectRoot: string): any {
261-
return keys
262-
.reduce((acc: any, key) => {
263-
acc[key] = prepFilepath(options[key], workingDirectory, projectRoot);
264-
return acc;
265-
}, {});
266-
}
267-
268-
function prepFilepath(value: string, workingDirectory: string, projectRoot: string): string {
269-
if (!value) {
270-
return undefined;
271-
}
272-
const modulePath = path.resolve(workingDirectory, value);
273-
274-
// ensure it starts with projectRoot
275-
if (!modulePath.startsWith(projectRoot)) {
276-
throw new SilentError('invalid module path');
277-
}
278-
279-
return modulePath.substr(projectRoot.length);
280-
}
281-

tests/e2e/tests/build/aot/aot-decorators.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {ng} from '../../../utils/process';
2-
import {appendToFile, expectFileToMatch, prependToFile, replaceInFile} from '../../../utils/fs';
2+
import { appendToFile, expectFileToMatch, prependToFile, replaceInFile } from '../../../utils/fs';
33
import {expectToFail} from '../../../utils/utils';
44

55
export default function() {

tests/e2e/tests/generate/component/component-path-case.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ export default function() {
1010
const componentDir = join(rootDir, 'test-component');
1111
const componentTwoDir = join(rootDir, 'test-component-two');
1212

13-
return ng('generate', 'component', `${upperDirs}/test-component`)
13+
return ng('generate', 'component', join(upperDirs, 'test-component'))
1414
.then(() => expectFileToExist(componentDir))
1515
.then(() => expectFileToExist(join(componentDir, 'test-component.component.ts')))
1616
.then(() => expectFileToExist(join(componentDir, 'test-component.component.spec.ts')))
1717
.then(() => expectFileToExist(join(componentDir, 'test-component.component.html')))
1818
.then(() => expectFileToExist(join(componentDir, 'test-component.component.css')))
19-
.then(() => ng('generate', 'component', `${upperDirs}/Test-Component-Two`))
19+
.then(() => ng('generate', 'component', join(upperDirs, 'Test-Component-Two')))
2020
.then(() => expectFileToExist(join(componentTwoDir, 'test-component-two.component.ts')))
2121
.then(() => expectFileToExist(join(componentTwoDir, 'test-component-two.component.spec.ts')))
2222
.then(() => expectFileToExist(join(componentTwoDir, 'test-component-two.component.html')))

0 commit comments

Comments
 (0)