|
1 |
| -import { Command, Option, CommandScope } from '../models/command'; |
2 |
| -import { BuildOptions } from '../models/build-options'; |
| 1 | +import { ArchitectCommand } from '../models/architect-command'; |
| 2 | +import { Option, CommandScope } from '../models/command'; |
| 3 | +// import { BuildOptions } from '../models/build-options'; |
3 | 4 | import { Version } from '../upgrade/version';
|
4 |
| -import { getAppFromConfig } from '../utilities/app-utils'; |
5 |
| -import { join } from 'path'; |
6 |
| -import { RenderUniversalTaskOptions } from '../tasks/render-universal'; |
| 5 | +// import { getAppFromConfig } from '../utilities/app-utils'; |
| 6 | +// import { join } from 'path'; |
| 7 | +// import { RenderUniversalTaskOptions } from '../tasks/render-universal'; |
| 8 | +// import { run as runArchitect } from '../utilities/architect'; |
7 | 9 |
|
8 |
| -const SilentError = require('silent-error'); |
| 10 | +// const SilentError = require('silent-error'); |
9 | 11 |
|
10 |
| -export interface BuildTaskOptions extends BuildOptions { |
11 |
| - statsJson?: boolean; |
| 12 | +export interface RunOptions { |
| 13 | + app?: string; |
| 14 | + prod: boolean; |
12 | 15 | }
|
13 | 16 |
|
14 |
| -export default class BuildCommand extends Command { |
| 17 | +export default class BuildCommand extends ArchitectCommand { |
15 | 18 | public readonly name = 'build';
|
| 19 | + public readonly target = 'browser'; |
16 | 20 | public readonly description =
|
17 | 21 | 'Builds your app and places it into the output path (dist/ by default).';
|
18 | 22 | public static aliases = ['b'];
|
19 | 23 | public scope = CommandScope.inProject;
|
20 | 24 | public arguments: string[];
|
21 |
| - public options: Option[] = []; |
| 25 | + public options: Option[] = [this.prodOption]; |
22 | 26 |
|
23 |
| - public validate(_options: BuildTaskOptions) { |
| 27 | + public validate(_options: RunOptions) { |
24 | 28 | Version.assertAngularVersionIs2_3_1OrHigher(this.project.root);
|
25 | 29 | Version.assertTypescriptVersion(this.project.root);
|
26 | 30 | return true;
|
27 | 31 | }
|
28 | 32 |
|
29 |
| - public async run(options: BuildTaskOptions) { |
30 |
| - // Add trailing slash if missing to prevent https://github.com/angular/angular-cli/issues/7295 |
31 |
| - if (options.deployUrl && options.deployUrl.substr(-1) !== '/') { |
32 |
| - options.deployUrl += '/'; |
| 33 | + public async run(options: RunOptions) { |
| 34 | + let configuration; |
| 35 | + if (options.prod) { |
| 36 | + configuration = 'production'; |
33 | 37 | }
|
| 38 | + const overrides = {...options}; |
| 39 | + delete overrides.app; |
| 40 | + delete overrides.prod; |
| 41 | + return this.runArchitect({ |
| 42 | + app: options.app, |
| 43 | + configuration, |
| 44 | + overrides |
| 45 | + }); |
| 46 | + // Add trailing slash if missing to prevent https://github.com/angular/angular-cli/issues/7295 |
| 47 | + // if (options.deployUrl && options.deployUrl.substr(-1) !== '/') { |
| 48 | + // options.deployUrl += '/'; |
| 49 | + // } |
34 | 50 |
|
35 |
| - const BuildTask = require('../tasks/build').default; |
| 51 | + // const BuildTask = require('../tasks/build').default; |
36 | 52 |
|
37 |
| - const buildTask = new BuildTask({ |
38 |
| - project: this.project, |
39 |
| - ui: this.ui, |
40 |
| - }); |
| 53 | + // const buildTask = new BuildTask({ |
| 54 | + // project: this.project, |
| 55 | + // ui: this.ui, |
| 56 | + // }); |
41 | 57 |
|
42 |
| - const clientApp = getAppFromConfig(options.app); |
| 58 | + // const clientApp = getAppFromConfig(options.app); |
43 | 59 |
|
44 |
| - const doAppShell = options.target === 'production' && |
45 |
| - (options.aot === undefined || options.aot === true) && |
46 |
| - !options.skipAppShell; |
| 60 | + // const doAppShell = options.target === 'production' && |
| 61 | + // (options.aot === undefined || options.aot === true) && |
| 62 | + // !options.skipAppShell; |
47 | 63 |
|
48 |
| - let serverApp: any = null; |
49 |
| - if (clientApp.appShell && doAppShell) { |
50 |
| - serverApp = getAppFromConfig(clientApp.appShell.app); |
51 |
| - if (serverApp.platform !== 'server') { |
52 |
| - throw new SilentError(`Shell app's platform is not "server"`); |
53 |
| - } |
54 |
| - } |
| 64 | + // let serverApp: any = null; |
| 65 | + // if (clientApp.appShell && doAppShell) { |
| 66 | + // serverApp = getAppFromConfig(clientApp.appShell.app); |
| 67 | + // if (serverApp.platform !== 'server') { |
| 68 | + // throw new SilentError(`Shell app's platform is not "server"`); |
| 69 | + // } |
| 70 | + // } |
55 | 71 |
|
56 |
| - const buildTaskResult = await buildTask.run(options); |
57 |
| - if (!clientApp.appShell || !doAppShell) { |
58 |
| - return buildTaskResult; |
59 |
| - } |
| 72 | + // // const buildTaskResult = await buildTask.run(options); |
| 73 | + // const buildTaskResult = await this.runArchitect({project: options.project}); |
| 74 | + // if (!clientApp.appShell || !doAppShell) { |
| 75 | + // return buildTaskResult; |
| 76 | + // } |
60 | 77 |
|
61 |
| - const serverOptions = { |
62 |
| - ...options, |
63 |
| - app: clientApp.appShell.app |
64 |
| - }; |
65 |
| - await buildTask.run(serverOptions); |
| 78 | + // const serverOptions = { |
| 79 | + // ...options, |
| 80 | + // app: clientApp.appShell.app |
| 81 | + // }; |
| 82 | + // await buildTask.run(serverOptions); |
66 | 83 |
|
67 |
| - const RenderUniversalTask = require('../tasks/render-universal').default; |
| 84 | + // const RenderUniversalTask = require('../tasks/render-universal').default; |
68 | 85 |
|
69 |
| - const renderUniversalTask = new RenderUniversalTask({ |
70 |
| - project: this.project, |
71 |
| - ui: this.ui, |
72 |
| - }); |
73 |
| - const renderUniversalOptions: RenderUniversalTaskOptions = { |
74 |
| - inputIndexPath: join(this.project.root, clientApp.outDir, clientApp.index), |
75 |
| - route: clientApp.appShell.route, |
76 |
| - serverOutDir: join(this.project.root, serverApp.outDir), |
77 |
| - outputIndexPath: join(this.project.root, clientApp.outDir, clientApp.index) |
78 |
| - }; |
| 86 | + // const renderUniversalTask = new RenderUniversalTask({ |
| 87 | + // project: this.project, |
| 88 | + // ui: this.ui, |
| 89 | + // }); |
| 90 | + // const renderUniversalOptions: RenderUniversalTaskOptions = { |
| 91 | + // inputIndexPath: join(this.project.root, clientApp.outDir, clientApp.index), |
| 92 | + // route: clientApp.appShell.route, |
| 93 | + // serverOutDir: join(this.project.root, serverApp.outDir), |
| 94 | + // outputIndexPath: join(this.project.root, clientApp.outDir, clientApp.index) |
| 95 | + // }; |
79 | 96 |
|
80 |
| - return await renderUniversalTask.run(renderUniversalOptions); |
| 97 | + // return await renderUniversalTask.run(renderUniversalOptions); |
81 | 98 | }
|
82 | 99 | }
|
0 commit comments