Skip to content

Commit f34777f

Browse files
committed
feat(@angular/cli): making app root configurable
1 parent fb96871 commit f34777f

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
@@ -112,7 +112,8 @@ export default Blueprint.extend({
112112
resolveModulePath(options.module, this.project, this.project.root, appConfig);
113113
} else {
114114
try {
115-
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
115+
this.pathToModule =
116+
findParentModule(this.project.root, appConfig.root, this.generatePath, appConfig.appRoot);
116117
} catch (e) {
117118
if (!options.skipImport) {
118119
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
@@ -65,7 +65,8 @@ export default Blueprint.extend({
6565
resolveModulePath(options.module, this.project, this.project.root, appConfig);
6666
} else {
6767
try {
68-
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
68+
this.pathToModule =
69+
findParentModule(this.project.root, appConfig.root, this.generatePath, appConfig.appRoot);
6970
} catch (e) {
7071
if (!options.skipImport) {
7172
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
@@ -60,7 +60,8 @@ export default Blueprint.extend({
6060
resolveModulePath(options.module, this.project, this.project.root, appConfig);
6161
} else {
6262
try {
63-
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
63+
this.pathToModule =
64+
findParentModule(this.project.root, appConfig.root, this.generatePath, appConfig.appRoot);
6465
} catch (e) {
6566
if (!options.skipImport) {
6667
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)