Skip to content

Commit

Permalink
feat(@angular/cli): adding the --app command option (angular#4754)
Browse files Browse the repository at this point in the history
  • Loading branch information
sumitarora authored and Zhicheng Wang committed Mar 16, 2017
1 parent e9e9efc commit fb37dbe
Show file tree
Hide file tree
Showing 29 changed files with 213 additions and 72 deletions.
11 changes: 10 additions & 1 deletion packages/@angular/cli/blueprints/class/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {getAppFromConfig} from '../../utilities/app-utils';

const stringUtils = require('ember-cli-string-utils');
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
const Blueprint = require('../../ember-cli/lib/models/blueprint');
Expand All @@ -11,11 +13,18 @@ export default Blueprint.extend({
name: 'spec',
type: Boolean,
description: 'Specifies if a spec file is generated.'
},
{
name: 'app',
type: String,
aliases: ['a'],
description: 'Specifies app name to use.'
}
],

normalizeEntityName: function (entityName: string) {
const parsedPath = dynamicPathParser(this.project, entityName.split('.')[0]);
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
const parsedPath = dynamicPathParser(this.project, entityName.split('.')[0], appConfig);

this.dynamicPath = parsedPath;
return parsedPath.name;
Expand Down
26 changes: 16 additions & 10 deletions packages/@angular/cli/blueprints/component/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NodeHost } from '../../lib/ast-tools';
import {getAppFromConfig} from '../../utilities/app-utils';

import * as fs from 'fs';
import * as path from 'path';
Expand Down Expand Up @@ -71,22 +72,30 @@ export default Blueprint.extend({
type: Boolean,
default: false,
description: 'Specifies if declaring module exports the component.'
},
{
name: 'app',
type: String,
aliases: ['a'],
description: 'Specifies app name to use.'
}
],

beforeInstall: function (options: any) {
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
if (options.module) {
// Resolve path to module
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
const parsedPath = dynamicPathParser(this.project, modulePath);
const parsedPath = dynamicPathParser(this.project, modulePath, appConfig);
this.pathToModule = path.join(this.project.root, parsedPath.dir, parsedPath.base);

if (!fs.existsSync(this.pathToModule)) {
throw 'Module specified does not exist';
}
} else {
try {
this.pathToModule = findParentModule(this.project, this.dynamicPath.dir);
this.pathToModule = findParentModule(
this.project.root, appConfig.root, this.dynamicPath.dir);
} catch (e) {
if (!options.skipImport) {
throw `Error locating module for declaration\n\t${e}`;
Expand All @@ -96,16 +105,12 @@ export default Blueprint.extend({
},

normalizeEntityName: function (entityName: string) {
const parsedPath = dynamicPathParser(this.project, entityName);
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);

this.dynamicPath = parsedPath;

let defaultPrefix = '';
if (this.project.ngConfig &&
this.project.ngConfig.apps[0] &&
this.project.ngConfig.apps[0].prefix) {
defaultPrefix = this.project.ngConfig.apps[0].prefix;
}
const defaultPrefix = (appConfig && appConfig.prefix) || '';

let prefix = (this.options.prefix === 'false' || this.options.prefix === '')
? '' : (this.options.prefix || defaultPrefix);
Expand Down Expand Up @@ -191,7 +196,8 @@ export default Blueprint.extend({
if (!options.locals.flat) {
dir += path.sep + options.dasherizedModuleName;
}
const srcDir = this.project.ngConfig.apps[0].root;
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
const srcDir = appConfig.root;
this.appDir = dir.substr(dir.indexOf(srcDir) + srcDir.length);
this.generatePath = dir;
return dir;
Expand Down
23 changes: 14 additions & 9 deletions packages/@angular/cli/blueprints/directive/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {NodeHost} from '../../lib/ast-tools';
import {getAppFromConfig} from '../../utilities/app-utils';

const path = require('path');
const fs = require('fs');
Expand Down Expand Up @@ -46,22 +47,30 @@ export default Blueprint.extend({
type: Boolean,
default: false,
description: 'Specifies if declaring module exports the component.'
},
{
name: 'app',
type: String,
aliases: ['a'],
description: 'Specifies app name to use.'
}
],

beforeInstall: function(options: any) {
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
if (options.module) {
// Resolve path to module
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
const parsedPath = dynamicPathParser(this.project, modulePath);
const parsedPath = dynamicPathParser(this.project, modulePath, appConfig);
this.pathToModule = path.join(this.project.root, parsedPath.dir, parsedPath.base);

if (!fs.existsSync(this.pathToModule)) {
throw ' ';
}
} else {
try {
this.pathToModule = findParentModule(this.project, this.dynamicPath.dir);
this.pathToModule = findParentModule
(this.project.root, appConfig.root, this.dynamicPath.dir);
} catch (e) {
if (!options.skipImport) {
throw `Error locating module for declaration\n\t${e}`;
Expand All @@ -71,16 +80,12 @@ export default Blueprint.extend({
},

normalizeEntityName: function (entityName: string) {
const parsedPath = dynamicPathParser(this.project, entityName);
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);

this.dynamicPath = parsedPath;

let defaultPrefix = '';
if (this.project.ngConfig &&
this.project.ngConfig.apps[0] &&
this.project.ngConfig.apps[0].prefix) {
defaultPrefix = this.project.ngConfig.apps[0].prefix;
}
const defaultPrefix = (appConfig && appConfig.prefix) || '';

let prefix = (this.options.prefix === 'false' || this.options.prefix === '')
? '' : (this.options.prefix || defaultPrefix);
Expand Down
14 changes: 13 additions & 1 deletion packages/@angular/cli/blueprints/enum/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import {getAppFromConfig} from '../../utilities/app-utils';

const stringUtils = require('ember-cli-string-utils');
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
const Blueprint = require('../../ember-cli/lib/models/blueprint');

export default Blueprint.extend({
description: '',

availableOptions: [
{
name: 'app',
type: String,
aliases: ['a'],
description: 'Specifies app name to use.'
}
],

normalizeEntityName: function (entityName: string) {
const parsedPath = dynamicPathParser(this.project, entityName);
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);

this.dynamicPath = parsedPath;
return parsedPath.name;
Expand Down
7 changes: 5 additions & 2 deletions packages/@angular/cli/blueprints/guard/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {NodeHost} from '../../lib/ast-tools';
import { oneLine } from 'common-tags';
import {getAppFromConfig} from '../../utilities/app-utils';

const path = require('path');
const fs = require('fs');
Expand All @@ -20,10 +21,11 @@ export default Blueprint.extend({
],

beforeInstall: function(options: any) {
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
if (options.module) {
// Resolve path to module
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
const parsedPath = dynamicPathParser(this.project, modulePath);
const parsedPath = dynamicPathParser(this.project, modulePath, appConfig);
this.pathToModule = path.join(this.project.root, parsedPath.dir, parsedPath.base);

if (!fs.existsSync(this.pathToModule)) {
Expand All @@ -33,7 +35,8 @@ export default Blueprint.extend({
},

normalizeEntityName: function (entityName: string) {
const parsedPath = dynamicPathParser(this.project, entityName);
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);

this.dynamicPath = parsedPath;
return parsedPath.name;
Expand Down
14 changes: 13 additions & 1 deletion packages/@angular/cli/blueprints/interface/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {getAppFromConfig} from '../../utilities/app-utils';

const stringUtils = require('ember-cli-string-utils');
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
const Blueprint = require('../../ember-cli/lib/models/blueprint');
Expand All @@ -9,8 +11,18 @@ export default Blueprint.extend({
'<interface-type>'
],

availableOptions: [
{
name: 'app',
type: String,
aliases: ['a'],
description: 'Specifies app name to use.'
}
],

normalizeEntityName: function (entityName: string) {
const parsedPath = dynamicPathParser(this.project, entityName);
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);

this.dynamicPath = parsedPath;
return parsedPath.name;
Expand Down
11 changes: 10 additions & 1 deletion packages/@angular/cli/blueprints/module/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {getAppFromConfig} from '../../utilities/app-utils';

const path = require('path');
const Blueprint = require('../../ember-cli/lib/models/blueprint');
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
Expand All @@ -22,12 +24,19 @@ export default Blueprint.extend({
type: Boolean,
default: false,
description: 'Specifies if a routing module file should be generated.'
},
{
name: 'app',
type: String,
aliases: ['a'],
description: 'Specifies app name to use.'
}
],

normalizeEntityName: function (entityName: string) {
this.entityName = entityName;
const parsedPath = dynamicPathParser(this.project, entityName);
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);

this.dynamicPath = parsedPath;
return parsedPath.name;
Expand Down
16 changes: 13 additions & 3 deletions packages/@angular/cli/blueprints/pipe/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {NodeHost} from '../../lib/ast-tools';
import {getAppFromConfig} from '../../utilities/app-utils';

const path = require('path');
const fs = require('fs');
Expand Down Expand Up @@ -41,22 +42,30 @@ export default Blueprint.extend({
type: Boolean,
default: false,
description: 'Specifies if declaring module exports the pipe.'
},
{
name: 'app',
type: String,
aliases: ['a'],
description: 'Specifies app name to use.'
}
],

beforeInstall: function(options: any) {
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
if (options.module) {
// Resolve path to module
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
const parsedPath = dynamicPathParser(this.project, modulePath);
const parsedPath = dynamicPathParser(this.project, modulePath, appConfig);
this.pathToModule = path.join(this.project.root, parsedPath.dir, parsedPath.base);

if (!fs.existsSync(this.pathToModule)) {
throw 'Module specified does not exist';
}
} else {
try {
this.pathToModule = findParentModule(this.project, this.dynamicPath.dir);
this.pathToModule = findParentModule
(this.project.root, appConfig.root, this.dynamicPath.dir);
} catch (e) {
if (!options.skipImport) {
throw `Error locating module for declaration\n\t${e}`;
Expand All @@ -66,7 +75,8 @@ export default Blueprint.extend({
},

normalizeEntityName: function (entityName: string) {
const parsedPath = dynamicPathParser(this.project, entityName);
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);

this.dynamicPath = parsedPath;
return parsedPath.name;
Expand Down
13 changes: 11 additions & 2 deletions packages/@angular/cli/blueprints/service/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {NodeHost} from '../../lib/ast-tools';
import { oneLine } from 'common-tags';
import {getAppFromConfig} from '../../utilities/app-utils';

const path = require('path');
const fs = require('fs');
Expand Down Expand Up @@ -28,14 +29,21 @@ export default Blueprint.extend({
name: 'module',
type: String, aliases: ['m'],
description: 'Allows specification of the declaring module.'
},
{
name: 'app',
type: String,
aliases: ['a'],
description: 'Specifies app name to use.'
}
],

beforeInstall: function(options: any) {
if (options.module) {
// Resolve path to module
const modulePath = options.module.endsWith('.ts') ? options.module : `${options.module}.ts`;
const parsedPath = dynamicPathParser(this.project, modulePath);
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
const parsedPath = dynamicPathParser(this.project, modulePath, appConfig);
this.pathToModule = path.join(this.project.root, parsedPath.dir, parsedPath.base);

if (!fs.existsSync(this.pathToModule)) {
Expand All @@ -45,7 +53,8 @@ export default Blueprint.extend({
},

normalizeEntityName: function (entityName: string) {
const parsedPath = dynamicPathParser(this.project, entityName);
const appConfig = getAppFromConfig(this.project.ngConfig.apps, this.options.app);
const parsedPath = dynamicPathParser(this.project, entityName, appConfig);

this.dynamicPath = parsedPath;
return parsedPath.name;
Expand Down
6 changes: 6 additions & 0 deletions packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export const baseBuildCommandOptions: any = [
type: Number,
default: pollDefault,
description: 'enable and define the file watching poll time period (milliseconds)'
},
{
name: 'app',
type: String,
aliases: ['a'],
description: 'Specifies app name to use.'
}
];

Expand Down
9 changes: 8 additions & 1 deletion packages/@angular/cli/commands/eject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ const Command = require('../ember-cli/lib/models/command');
// defaults for BuildOptions
export const baseEjectCommandOptions: any = [
...baseBuildCommandOptions,
{ name: 'force', 'type': Boolean }
{ name: 'force', 'type': Boolean },
{
name: 'app',
type: String,
aliases: ['a'],
description: 'Specifies app name to use.'
}
];

export interface EjectTaskOptions extends BuildOptions {
force?: boolean;
app?: string;
}


Expand Down
2 changes: 1 addition & 1 deletion packages/@angular/cli/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const baseServeCommandOptions: any = overrideOptions(
description: 'Enable hot module replacement',
}
]), [
{ name: 'watch', default: true },
{ name: 'watch', default: true }
]
);

Expand Down
Loading

0 comments on commit fb37dbe

Please sign in to comment.