1+ import { Command , Option , CommandScope } from '../models/command' ;
12import { CliConfig } from '../models/config' ;
23import { BuildOptions } from '../models/build-options' ;
34import { Version } from '../upgrade/version' ;
@@ -6,7 +7,6 @@ import { getAppFromConfig } from '../utilities/app-utils';
67import { join } from 'path' ;
78import { RenderUniversalTaskOptions } from '../tasks/render-universal' ;
89
9- const Command = require ( '../ember-cli/lib/models/command' ) ;
1010const SilentError = require ( 'silent-error' ) ;
1111
1212const config = CliConfig . fromProject ( ) || CliConfig . fromGlobal ( ) ;
@@ -16,12 +16,13 @@ const buildConfigDefaults = config.getPaths('defaults.build', [
1616] ) ;
1717
1818// defaults for BuildOptions
19- export const baseBuildCommandOptions : any = [
19+ export const baseBuildCommandOptions : Option [ ] = [
2020 {
2121 name : 'target' ,
2222 type : String ,
2323 default : 'development' ,
24- aliases : [ 't' , { 'dev' : 'development' } , { 'prod' : 'production' } ] ,
24+ // TODO: re-add support for `--prod`
25+ aliases : [ 't' ] ,
2526 description : 'Defines the build target.'
2627 } ,
2728 {
@@ -213,29 +214,33 @@ export interface BuildTaskOptions extends BuildOptions {
213214 statsJson ?: boolean ;
214215}
215216
216- const BuildCommand = Command . extend ( {
217- name : 'build' ,
218- description : 'Builds your app and places it into the output path (dist/ by default).' ,
219- aliases : [ 'b' ] ,
220-
221- availableOptions : baseBuildCommandOptions . concat ( [
217+ export default class BuildCommand extends Command {
218+ public readonly name = 'build' ;
219+ public readonly description =
220+ 'Builds your app and places it into the output path (dist/ by default).' ;
221+ public static aliases = [ 'b' ] ;
222+ public scope = CommandScope . inProject ;
223+ public arguments : string [ ] ;
224+ public options = baseBuildCommandOptions . concat ( [
222225 {
223226 name : 'stats-json' ,
224227 type : Boolean ,
225228 default : false ,
226229 description : oneLine `Generates a \`stats.json\` file which can be analyzed using tools
227230 such as: \`webpack-bundle-analyzer\` or https://webpack.github.io/analyse.`
228231 }
229- ] ) ,
232+ ] ) ;
230233
231- run : function ( commandOptions : BuildTaskOptions ) {
232- // Check Angular and TypeScript versions.
234+ public validate ( _options : BuildTaskOptions ) {
233235 Version . assertAngularVersionIs2_3_1OrHigher ( this . project . root ) ;
234236 Version . assertTypescriptVersion ( this . project . root ) ;
237+ return true ;
238+ }
235239
240+ public async run ( options : BuildTaskOptions ) {
236241 // Add trailing slash if missing to prevent https://github.com/angular/angular-cli/issues/7295
237- if ( commandOptions . deployUrl && commandOptions . deployUrl . substr ( - 1 ) !== '/' ) {
238- commandOptions . deployUrl += '/' ;
242+ if ( options . deployUrl && options . deployUrl . substr ( - 1 ) !== '/' ) {
243+ options . deployUrl += '/' ;
239244 }
240245
241246 const BuildTask = require ( '../tasks/build' ) . default ;
@@ -245,11 +250,11 @@ const BuildCommand = Command.extend({
245250 ui : this . ui ,
246251 } ) ;
247252
248- const clientApp = getAppFromConfig ( commandOptions . app ) ;
253+ const clientApp = getAppFromConfig ( options . app ) ;
249254
250- const doAppShell = commandOptions . target === 'production' &&
251- ( commandOptions . aot === undefined || commandOptions . aot === true ) &&
252- ! commandOptions . skipAppShell ;
255+ const doAppShell = options . target === 'production' &&
256+ ( options . aot === undefined || options . aot === true ) &&
257+ ! options . skipAppShell ;
253258
254259 let serverApp : any = null ;
255260 if ( clientApp . appShell && doAppShell ) {
@@ -259,40 +264,30 @@ const BuildCommand = Command.extend({
259264 }
260265 }
261266
262- const buildPromise = buildTask . run ( commandOptions ) ;
263-
267+ const buildTaskResult = await buildTask . run ( options ) ;
264268 if ( ! clientApp . appShell || ! doAppShell ) {
265- return buildPromise ;
269+ return buildTaskResult ;
266270 }
267271
268- return buildPromise
269- . then ( ( ) => {
272+ const serverOptions = {
273+ ...options ,
274+ app : clientApp . appShell . app
275+ } ;
276+ await buildTask . run ( serverOptions ) ;
270277
271- const serverOptions = {
272- ...commandOptions ,
273- app : clientApp . appShell . app
274- } ;
275- return buildTask . run ( serverOptions ) ;
276- } )
277- . then ( ( ) => {
278- const RenderUniversalTask = require ( '../tasks/render-universal' ) . default ;
278+ const RenderUniversalTask = require ( '../tasks/render-universal' ) . default ;
279279
280- const renderUniversalTask = new RenderUniversalTask ( {
281- project : this . project ,
282- ui : this . ui ,
283- } ) ;
284- const renderUniversalOptions : RenderUniversalTaskOptions = {
285- inputIndexPath : join ( this . project . root , clientApp . outDir , clientApp . index ) ,
286- route : clientApp . appShell . route ,
287- serverOutDir : join ( this . project . root , serverApp . outDir ) ,
288- outputIndexPath : join ( this . project . root , clientApp . outDir , clientApp . index )
289- } ;
280+ const renderUniversalTask = new RenderUniversalTask ( {
281+ project : this . project ,
282+ ui : this . ui ,
283+ } ) ;
284+ const renderUniversalOptions : RenderUniversalTaskOptions = {
285+ inputIndexPath : join ( this . project . root , clientApp . outDir , clientApp . index ) ,
286+ route : clientApp . appShell . route ,
287+ serverOutDir : join ( this . project . root , serverApp . outDir ) ,
288+ outputIndexPath : join ( this . project . root , clientApp . outDir , clientApp . index )
289+ } ;
290290
291- return renderUniversalTask . run ( renderUniversalOptions ) ;
292- } ) ;
291+ return await renderUniversalTask . run ( renderUniversalOptions ) ;
293292 }
294- } ) ;
295-
296-
297- BuildCommand . overrideCore = true ;
298- export default BuildCommand ;
293+ }
0 commit comments