Skip to content

Commit

Permalink
fix(@angular/cli): fix an issue with schematics
Browse files Browse the repository at this point in the history
The issue here is that the sourceDir string could be anywhere in the
path. We only care about it if its at the start.
  • Loading branch information
hansl authored and Brocco committed Sep 22, 2017
1 parent 220c3fe commit 8b09dd3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/@angular/cli/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,10 @@ export default Command.extend({
commandOptions.appRoot = parsedPath.appRoot.startsWith(root)
? parsedPath.appRoot.substr(root.length)
: parsedPath.appRoot;
commandOptions.path = parsedPath.dir
.replace(appConfig.root + path.sep, '')
.replace(separatorRegEx, '/');
commandOptions.path = parsedPath.dir.replace(separatorRegEx, '/');
if (parsedPath.dir.startsWith(root)) {
commandOptions.path = commandOptions.path.substr(root.length);
}

const cwd = this.project.root;
const schematicName = rawArgs[0];
Expand Down
24 changes: 24 additions & 0 deletions tests/e2e/tests/generate/component/component-module-2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as fs from 'fs-extra';
import {join} from 'path';
import {ng} from '../../../utils/process';
import {expectFileToMatch} from '../../../utils/fs';


export default function() {
const root = process.cwd();
const modulePath = join(root, 'src', 'app', 'app.module.ts');

fs.mkdirSync('./src/app/sub-dir');

return ng('generate', 'component', 'test-component', '--module', 'app.module.ts')
.then(() => expectFileToMatch(modulePath,
/import { TestComponentComponent } from '.\/test-component\/test-component.component'/))

.then(() => process.chdir(join(root, 'src', 'app')))
.then(() => ng('generate', 'component', 'test-component2', '--module', 'app.module.ts'))
.then(() => expectFileToMatch(modulePath,
/import { TestComponent2Component } from '.\/test-component2\/test-component2.component'/))

// Try to run the unit tests.
.then(() => ng('build'));
}

0 comments on commit 8b09dd3

Please sign in to comment.