Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/@angular/cli/blueprints/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ export default Blueprint.extend({
resolveModulePath(options.module, this.project, this.project.root, appConfig);
} else {
try {
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
this.pathToModule =
findParentModule(this.project.root, appConfig.root, this.generatePath, appConfig.appRoot);
} catch (e) {
if (!options.skipImport) {
throw `Error locating module for declaration\n\t${e}`;
Expand Down
3 changes: 2 additions & 1 deletion packages/@angular/cli/blueprints/directive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export default Blueprint.extend({
resolveModulePath(options.module, this.project, this.project.root, appConfig);
} else {
try {
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
this.pathToModule =
findParentModule(this.project.root, appConfig.root, this.generatePath, appConfig.appRoot);
} catch (e) {
if (!options.skipImport) {
throw `Error locating module for declaration\n\t${e}`;
Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/blueprints/ng/files/angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
},
"apps": [
{
"appRoot": "app",
"root": "<%= sourceDir %>",
"outDir": "dist",
"assets": [
Expand Down
3 changes: 2 additions & 1 deletion packages/@angular/cli/blueprints/pipe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export default Blueprint.extend({
resolveModulePath(options.module, this.project, this.project.root, appConfig);
} else {
try {
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
this.pathToModule =
findParentModule(this.project.root, appConfig.root, this.generatePath, appConfig.appRoot);
} catch (e) {
if (!options.skipImport) {
throw `Error locating module for declaration\n\t${e}`;
Expand Down
7 changes: 6 additions & 1 deletion packages/@angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@
"type": "string",
"description": "Name of the app."
},
"root": {
"appRoot": {
"type": "string",
"default": "app",
"description": "The root directory of the app."
},
"root": {
"type": "string",
"description": "The root src directory for the apps."
},
"outDir": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion packages/@angular/cli/utilities/dynamic-path-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface DynamicPathOptions {
export function dynamicPathParser(options: DynamicPathOptions) {
const projectRoot = options.project.root;
const sourceDir = options.appConfig.root;
const appRoot = path.join(sourceDir, 'app');
const appRoot = path.join(sourceDir, options.appConfig.appRoot || 'app');
const cwd = process.env.PWD;

const rootPath = path.join(projectRoot, appRoot);
Expand Down
6 changes: 3 additions & 3 deletions packages/@angular/cli/utilities/find-parent-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import * as path from 'path';
const SilentError = require('silent-error');

export default function findParentModule(
projectRoot: string, appRoot: string, currentDir: string): string {
projectRoot: string, srcRoot: string, currentDir: string, appRoot = 'app'): string {

const sourceRoot = path.join(projectRoot, appRoot, 'app');
const sourceRoot = path.join(projectRoot, srcRoot, appRoot);

// trim currentDir
currentDir = currentDir.replace(path.join(appRoot, 'app'), '');
currentDir = currentDir.replace(path.join(srcRoot, appRoot), '');

let pathToCheck = path.join(sourceRoot, currentDir);

Expand Down
26 changes: 26 additions & 0 deletions tests/e2e/tests/commands/set/set-approot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {ng} from '../../../utils/process';
import {rename} from '../../../utils/fs';

export default function() {
return Promise.resolve()
.then(() => ng('get', 'apps.0.appRoot'))
.then(({ stdout }) => {
if (!stdout.match(/app/)) {
throw new Error(`Expected "app", received "${JSON.stringify(stdout)}".`);
}
})
.then(() => ng('set', 'apps.0.appRoot' , 'app1'))
.then(() => ng('get', 'apps.0.appRoot'))
.then(({ stdout }) => {
if (!stdout.match(/app1/)) {
throw new Error(`Expected "app1", received "${JSON.stringify(stdout)}".`);
}
})
.then(() => rename('./src/app', './src/app1'))
.then(() => ng('g', 'c', 'hello', '-d'))
.then(({ stdout }) => {
if (!stdout.match(/app1/)) {
throw new Error(`Expected "app", received "${JSON.stringify(stdout)}".`);
}
});
}
11 changes: 11 additions & 0 deletions tests/e2e/utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ export function createDir(path: string) {
_recursiveMkDir(path);
}

export function rename(from: string, to: string) {
return new Promise((resolve, reject) => {
fs.rename(from, to, (error) => {
if (error) {
reject(error);
} else {
resolve();
}
});
});
}

function _recursiveMkDir(path: string) {
if (fs.existsSync(path)) {
Expand Down