Skip to content

Commit 9042b9d

Browse files
hanslsumitarora
authored andcommitted
feat(@angular/cli): making app root configurable
1 parent 78d1c77 commit 9042b9d

File tree

7 files changed

+17
-8
lines changed

7 files changed

+17
-8
lines changed

packages/@angular/cli/blueprints/component/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ export default Blueprint.extend({
114114
resolveModulePath(options.module, this.project, this.project.root, appConfig);
115115
} else {
116116
try {
117-
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
117+
this.pathToModule =
118+
findParentModule(this.project.root, appConfig.root, this.generatePath, appConfig.appRoot);
118119
} catch (e) {
119120
if (!options.skipImport) {
120121
throw `Error locating module for declaration\n\t${e}`;

packages/@angular/cli/blueprints/directive/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export default Blueprint.extend({
6767
resolveModulePath(options.module, this.project, this.project.root, appConfig);
6868
} else {
6969
try {
70-
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
70+
this.pathToModule =
71+
findParentModule(this.project.root, appConfig.root, this.generatePath, appConfig.appRoot);
7172
} catch (e) {
7273
if (!options.skipImport) {
7374
throw `Error locating module for declaration\n\t${e}`;

packages/@angular/cli/blueprints/ng/files/angular-cli.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
},
66
"apps": [
77
{
8+
"appRoot": "app",
89
"root": "<%= sourceDir %>",
910
"outDir": "dist",
1011
"assets": [

packages/@angular/cli/blueprints/pipe/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ export default Blueprint.extend({
6161
resolveModulePath(options.module, this.project, this.project.root, appConfig);
6262
} else {
6363
try {
64-
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
64+
this.pathToModule =
65+
findParentModule(this.project.root, appConfig.root, this.generatePath, appConfig.appRoot);
6566
} catch (e) {
6667
if (!options.skipImport) {
6768
throw `Error locating module for declaration\n\t${e}`;

packages/@angular/cli/lib/config/schema.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@
3333
"type": "string",
3434
"description": "Name of the app."
3535
},
36-
"root": {
36+
"appRoot": {
3737
"type": "string",
38+
"default": "app",
3839
"description": "The root directory of the app."
40+
},
41+
"root": {
42+
"type": "string",
43+
"description": "The root src directory for the apps."
3944
},
4045
"outDir": {
4146
"type": "string",

packages/@angular/cli/utilities/dynamic-path-parser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const stringUtils = require('ember-cli-string-utils');
66
export function dynamicPathParser(project: any, entityName: string, appConfig: any) {
77
const projectRoot = project.root;
88
const sourceDir = appConfig.root;
9-
const appRoot = path.join(sourceDir, 'app');
9+
const appRoot = path.join(sourceDir, appConfig.appRoot || 'app');
1010
const cwd = process.env.PWD;
1111

1212
const rootPath = path.join(projectRoot, appRoot);

packages/@angular/cli/utilities/find-parent-module.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import * as path from 'path';
33
const SilentError = require('silent-error');
44

55
export default function findParentModule(
6-
projectRoot: string, appRoot: string, currentDir: string): string {
6+
projectRoot: string, srcRoot: string, currentDir: string, appRoot = 'app'): string {
77

8-
const sourceRoot = path.join(projectRoot, appRoot, 'app');
8+
const sourceRoot = path.join(projectRoot, srcRoot, appRoot);
99

1010
// trim currentDir
11-
currentDir = currentDir.replace(path.join(appRoot, 'app'), '');
11+
currentDir = currentDir.replace(path.join(srcRoot, appRoot), '');
1212

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

0 commit comments

Comments
 (0)