11import { cyan , yellow } from 'chalk' ;
2+ const stringUtils = require ( 'ember-cli-string-utils' ) ;
23import { oneLine } from 'common-tags' ;
34import { CliConfig } from '../models/config' ;
45
@@ -10,11 +11,14 @@ import {
1011} from '../utilities/schematics' ;
1112import { DynamicPathOptions , dynamicPathParser } from '../utilities/dynamic-path-parser' ;
1213import { getAppFromConfig } from '../utilities/app-utils' ;
14+ import * as path from 'path' ;
1315import { SchematicAvailableOptions } from '../tasks/schematic-get-options' ;
1416
1517const Command = require ( '../ember-cli/lib/models/command' ) ;
1618const SilentError = require ( 'silent-error' ) ;
1719
20+ const separatorRegEx = / [ \/ \\ ] / g;
21+
1822
1923export default Command . extend ( {
2024 name : 'generate' ,
@@ -73,15 +77,16 @@ export default Command.extend({
7377
7478 beforeRun : function ( rawArgs : string [ ] ) {
7579
76- const isHelp = [ '--help' , '-h' ] . indexOf ( rawArgs [ 0 ] ) != - 1 ;
80+ const isHelp = [ '--help' , '-h' ] . includes ( rawArgs [ 0 ] ) ;
7781 if ( isHelp ) {
7882 return ;
7983 }
8084
8185 const schematicName = rawArgs [ 0 ] ;
8286 if ( ! schematicName ) {
8387 return Promise . reject ( new SilentError ( oneLine `
84- The "ng generate" command requires a schematic name to be specified.
88+ The "ng generate" command requires a
89+ schematic name to be specified.
8590 For more details, use "ng help".
8691 ` ) ) ;
8792 }
@@ -122,6 +127,7 @@ export default Command.extend({
122127 }
123128
124129 const entityName = rawArgs [ 1 ] ;
130+ commandOptions . name = stringUtils . dasherize ( entityName . split ( separatorRegEx ) . pop ( ) ) ;
125131
126132 const appConfig = getAppFromConfig ( commandOptions . app ) ;
127133 const dynamicPathOptions : DynamicPathOptions = {
@@ -131,16 +137,34 @@ export default Command.extend({
131137 dryRun : commandOptions . dryRun
132138 } ;
133139 const parsedPath = dynamicPathParser ( dynamicPathOptions ) ;
134-
135- // Do not pass the schematics name itself, that's not useful.
136- commandOptions . _ = rawArgs . slice ( 1 ) ;
137- commandOptions . _angularCliConfig = ( CliConfig . fromProject ( ) || CliConfig . fromGlobal ( ) ) . config ;
138- commandOptions . _angularCliAppConfig = appConfig ;
139- commandOptions . _angularCliParsedPath = parsedPath ;
140+ commandOptions . sourceDir = appConfig . root ;
141+ const root = appConfig . root + path . sep ;
142+ commandOptions . appRoot = parsedPath . appRoot === appConfig . root ? '' :
143+ parsedPath . appRoot . startsWith ( root )
144+ ? parsedPath . appRoot . substr ( root . length )
145+ : parsedPath . appRoot ;
146+
147+ commandOptions . path = parsedPath . dir . replace ( separatorRegEx , '/' ) ;
148+ commandOptions . path = parsedPath . dir === appConfig . root ? '' :
149+ parsedPath . dir . startsWith ( root )
150+ ? commandOptions . path . substr ( root . length )
151+ : commandOptions . path ;
140152
141153 const cwd = this . project . root ;
142154 const schematicName = rawArgs [ 0 ] ;
143155
156+ if ( [ 'component' , 'c' , 'directive' , 'd' ] . indexOf ( schematicName ) !== - 1 ) {
157+ if ( commandOptions . prefix === undefined ) {
158+ commandOptions . prefix = appConfig . prefix ;
159+ }
160+
161+ if ( schematicName === 'component' || schematicName === 'c' ) {
162+ if ( commandOptions . styleext === undefined ) {
163+ commandOptions . styleext = CliConfig . getValue ( 'defaults.styleExt' ) ;
164+ }
165+ }
166+ }
167+
144168 const SchematicRunTask = require ( '../tasks/schematic-run' ) . default ;
145169 const schematicRunTask = new SchematicRunTask ( {
146170 ui : this . ui ,
@@ -149,6 +173,10 @@ export default Command.extend({
149173 const collectionName = commandOptions . collection ||
150174 CliConfig . getValue ( 'defaults.schematics.collection' ) ;
151175
176+ if ( collectionName === '@schematics/angular' && schematicName === 'interface' && rawArgs [ 2 ] ) {
177+ commandOptions . type = rawArgs [ 2 ] ;
178+ }
179+
152180 return schematicRunTask . run ( {
153181 taskOptions : commandOptions ,
154182 workingDir : cwd ,
0 commit comments