1
+ import { Command , Option , CommandScope } from '../models/command' ;
1
2
import { CliConfig } from '../models/config' ;
2
3
import { BuildOptions } from '../models/build-options' ;
3
4
import { Version } from '../upgrade/version' ;
@@ -6,7 +7,6 @@ import { getAppFromConfig } from '../utilities/app-utils';
6
7
import { join } from 'path' ;
7
8
import { RenderUniversalTaskOptions } from '../tasks/render-universal' ;
8
9
9
- const Command = require ( '../ember-cli/lib/models/command' ) ;
10
10
const SilentError = require ( 'silent-error' ) ;
11
11
12
12
const config = CliConfig . fromProject ( ) || CliConfig . fromGlobal ( ) ;
@@ -16,12 +16,13 @@ const buildConfigDefaults = config.getPaths('defaults.build', [
16
16
] ) ;
17
17
18
18
// defaults for BuildOptions
19
- export const baseBuildCommandOptions : any = [
19
+ export const baseBuildCommandOptions : Option [ ] = [
20
20
{
21
21
name : 'target' ,
22
22
type : String ,
23
23
default : 'development' ,
24
- aliases : [ 't' , { 'dev' : 'development' } , { 'prod' : 'production' } ] ,
24
+ // TODO: re-add support for `--prod`
25
+ aliases : [ 't' ] ,
25
26
description : 'Defines the build target.'
26
27
} ,
27
28
{
@@ -213,29 +214,33 @@ export interface BuildTaskOptions extends BuildOptions {
213
214
statsJson ?: boolean ;
214
215
}
215
216
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 ( [
222
225
{
223
226
name : 'stats-json' ,
224
227
type : Boolean ,
225
228
default : false ,
226
229
description : oneLine `Generates a \`stats.json\` file which can be analyzed using tools
227
230
such as: \`webpack-bundle-analyzer\` or https://webpack.github.io/analyse.`
228
231
}
229
- ] ) ,
232
+ ] ) ;
230
233
231
- run : function ( commandOptions : BuildTaskOptions ) {
232
- // Check Angular and TypeScript versions.
234
+ public validate ( _options : BuildTaskOptions ) {
233
235
Version . assertAngularVersionIs2_3_1OrHigher ( this . project . root ) ;
234
236
Version . assertTypescriptVersion ( this . project . root ) ;
237
+ return true ;
238
+ }
235
239
240
+ public async run ( options : BuildTaskOptions ) {
236
241
// 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 += '/' ;
239
244
}
240
245
241
246
const BuildTask = require ( '../tasks/build' ) . default ;
@@ -245,11 +250,11 @@ const BuildCommand = Command.extend({
245
250
ui : this . ui ,
246
251
} ) ;
247
252
248
- const clientApp = getAppFromConfig ( commandOptions . app ) ;
253
+ const clientApp = getAppFromConfig ( options . app ) ;
249
254
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 ;
253
258
254
259
let serverApp : any = null ;
255
260
if ( clientApp . appShell && doAppShell ) {
@@ -259,40 +264,30 @@ const BuildCommand = Command.extend({
259
264
}
260
265
}
261
266
262
- const buildPromise = buildTask . run ( commandOptions ) ;
263
-
267
+ const buildTaskResult = await buildTask . run ( options ) ;
264
268
if ( ! clientApp . appShell || ! doAppShell ) {
265
- return buildPromise ;
269
+ return buildTaskResult ;
266
270
}
267
271
268
- return buildPromise
269
- . then ( ( ) => {
272
+ const serverOptions = {
273
+ ...options ,
274
+ app : clientApp . appShell . app
275
+ } ;
276
+ await buildTask . run ( serverOptions ) ;
270
277
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 ;
279
279
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
+ } ;
290
290
291
- return renderUniversalTask . run ( renderUniversalOptions ) ;
292
- } ) ;
291
+ return await renderUniversalTask . run ( renderUniversalOptions ) ;
293
292
}
294
- } ) ;
295
-
296
-
297
- BuildCommand . overrideCore = true ;
298
- export default BuildCommand ;
293
+ }
0 commit comments