|
1 | 1 | /*jshint node: true*/
|
2 | 2 | 'use strict';
|
3 | 3 |
|
4 |
| -const fs = require('fs-extra'); |
5 |
| -const merge = require('../utils/merge'); |
6 |
| - |
7 |
| -const skyPagesConfigUtil = require('../config/sky-pages/sky-pages.config'); |
8 |
| -const generator = require('../lib/sky-pages-module-generator'); |
9 |
| -const assetsProcessor = require('../lib/assets-processor'); |
10 |
| -const pluginFileProcessor = require('../lib/plugin-file-processor'); |
11 |
| -const localeAssetsProcessor = require('../lib/locale-assets-processor'); |
12 |
| - |
13 |
| -const server = require('./utils/server'); |
14 |
| -const browser = require('./utils/browser'); |
15 |
| -const runCompiler = require('./utils/run-compiler'); |
16 |
| -const tsLinter = require('./utils/ts-linter'); |
17 |
| - |
18 |
| -function writeTSConfig() { |
19 |
| - var config = { |
20 |
| - 'compilerOptions': { |
21 |
| - 'target': 'es5', |
22 |
| - 'module': 'es2015', |
23 |
| - 'moduleResolution': 'node', |
24 |
| - 'emitDecoratorMetadata': true, |
25 |
| - 'experimentalDecorators': true, |
26 |
| - 'sourceMap': true, |
27 |
| - 'noEmitHelpers': true, |
28 |
| - 'noImplicitAny': true, |
29 |
| - 'rootDir': '.', |
30 |
| - 'inlineSources': true, |
31 |
| - 'declaration': true, |
32 |
| - 'skipLibCheck': true, |
33 |
| - 'lib': [ |
34 |
| - 'es2015', |
35 |
| - 'dom' |
36 |
| - ], |
37 |
| - 'types': [ |
38 |
| - 'jasmine', |
39 |
| - 'node' |
40 |
| - ] |
41 |
| - }, |
42 |
| - 'files': [ |
43 |
| - './app/app.module.ts' |
44 |
| - ], |
45 |
| - 'exclude': [ |
46 |
| - 'node_modules', |
47 |
| - skyPagesConfigUtil.outPath('node_modules'), |
48 |
| - '**/*.spec.ts' |
49 |
| - ], |
50 |
| - 'compileOnSave': false, |
51 |
| - 'buildOnSave': false, |
52 |
| - 'angularCompilerOptions': { |
53 |
| - 'debug': true, |
54 |
| - 'genDir': './ngfactory', |
55 |
| - 'skipMetadataEmit': true |
56 |
| - } |
57 |
| - }; |
58 |
| - |
59 |
| - fs.writeJSONSync(skyPagesConfigUtil.spaPathTempSrc('tsconfig.json'), config); |
60 |
| -} |
61 |
| - |
62 |
| -function stageAot(skyPagesConfig, assetsBaseUrl, assetsRel) { |
63 |
| - let skyPagesConfigOverrides = { |
64 |
| - runtime: { |
65 |
| - spaPathAlias: '../..', |
66 |
| - skyPagesOutAlias: '../..', |
67 |
| - // These files won't be copied to the temp folder because the consuming project will |
68 |
| - // be referencing it by its Node package name. Make sure this code also references its |
69 |
| - // Node package name rather than a local path; otherwise TypeScript will treat them as |
70 |
| - // different types and Angular will throw an error when trying to inject an instance |
71 |
| - // of a class (such as SkyAuthHttp) by its type. |
72 |
| - runtimeAlias: '@blackbaud/skyux-builder/runtime', |
73 |
| - useTemplateUrl: true |
74 |
| - } |
75 |
| - }; |
76 |
| - |
77 |
| - if (skyPagesConfig && skyPagesConfig.skyux && skyPagesConfig.skyux.importPath) { |
78 |
| - skyPagesConfigOverrides.runtime.skyuxPathAlias = '../../' + skyPagesConfig.skyux.importPath; |
79 |
| - } |
80 |
| - |
81 |
| - const spaPathTempSrc = skyPagesConfigUtil.spaPathTempSrc(); |
82 |
| - |
83 |
| - fs.ensureDirSync(spaPathTempSrc); |
84 |
| - fs.emptyDirSync(spaPathTempSrc); |
85 |
| - |
86 |
| - merge(skyPagesConfig, skyPagesConfigOverrides); |
87 |
| - let skyPagesModuleSource = generator.getSource(skyPagesConfig); |
88 |
| - |
89 |
| - // The Webpack loader that processes referenced asset files will have run and emitted |
90 |
| - // the appropriate files, but the AoT compiler will not pick up changes to the contents |
91 |
| - // of the sky-pages.module.ts file. Process the file again to do the replacements |
92 |
| - // before writing the file to disk. |
93 |
| - skyPagesModuleSource = assetsProcessor.processAssets( |
94 |
| - skyPagesModuleSource, |
95 |
| - assetsProcessor.getAssetsUrl(skyPagesConfig, assetsBaseUrl, assetsRel) |
96 |
| - ); |
97 |
| - |
98 |
| - fs.copySync( |
99 |
| - skyPagesConfigUtil.outPath('src'), |
100 |
| - spaPathTempSrc |
101 |
| - ); |
102 |
| - |
103 |
| - fs.copySync( |
104 |
| - skyPagesConfigUtil.spaPath('src'), |
105 |
| - spaPathTempSrc |
106 |
| - ); |
107 |
| - |
108 |
| - fs.writeFileSync( |
109 |
| - skyPagesConfigUtil.spaPathTempSrc('app', 'sky-pages.module.ts'), |
110 |
| - skyPagesModuleSource, |
111 |
| - { |
112 |
| - encoding: 'utf8' |
113 |
| - } |
114 |
| - ); |
115 |
| - |
116 |
| - pluginFileProcessor.processFiles(skyPagesConfig); |
117 |
| - writeTSConfig(); |
118 |
| -} |
119 |
| - |
120 |
| -function cleanupAot() { |
121 |
| - fs.removeSync(skyPagesConfigUtil.spaPathTemp()); |
122 |
| -} |
123 |
| - |
124 |
| -function buildServe(argv, skyPagesConfig, webpack, isAot) { |
125 |
| - const base = skyPagesConfigUtil.getAppBase(skyPagesConfig); |
126 |
| - return server |
127 |
| - .start(base) |
128 |
| - .then(port => { |
129 |
| - argv.assets = argv.assets || `https://localhost:${port}`; |
130 |
| - return buildCompiler(argv, skyPagesConfig, webpack, isAot) |
131 |
| - .then(stats => { |
132 |
| - browser(argv, skyPagesConfig, stats, port); |
133 |
| - return stats; |
134 |
| - }); |
135 |
| - }); |
136 |
| -} |
137 |
| - |
138 |
| -function buildCompiler(argv, skyPagesConfig, webpack, isAot) { |
139 |
| - const assetsBaseUrl = argv.assets || ''; |
140 |
| - const assetsRel = argv.assetsrel; |
141 |
| - |
142 |
| - let buildConfig; |
143 |
| - |
144 |
| - if (isAot) { |
145 |
| - stageAot(skyPagesConfig, assetsBaseUrl, assetsRel); |
146 |
| - buildConfig = require('../config/webpack/build-aot.webpack.config'); |
147 |
| - } else { |
148 |
| - buildConfig = require('../config/webpack/build.webpack.config'); |
149 |
| - } |
150 |
| - |
151 |
| - const config = buildConfig.getWebpackConfig(skyPagesConfig, argv); |
152 |
| - assetsProcessor.setSkyAssetsLoaderUrl(config, skyPagesConfig, assetsBaseUrl, assetsRel); |
153 |
| - |
154 |
| - return runCompiler(webpack, config, isAot) |
155 |
| - .then(stats => { |
156 |
| - if (isAot) { |
157 |
| - cleanupAot(); |
158 |
| - } |
159 |
| - |
160 |
| - return stats; |
161 |
| - }); |
162 |
| -} |
| 4 | +const logger = require('@blackbaud/skyux-logger'); |
| 5 | +const runBuild = require('./utils/run-build'); |
163 | 6 |
|
164 | 7 | /**
|
165 | 8 | * Executes the build command.
|
166 | 9 | * @name build
|
167 | 10 | * @param {*} skyPagesConfig
|
168 | 11 | * @param {*} webpack
|
169 | 12 | * @param {*} isAot
|
| 13 | + * @param {*} cancelProcessExit |
170 | 14 | */
|
171 | 15 | function build(argv, skyPagesConfig, webpack) {
|
172 |
| - |
173 |
| - const lintResult = tsLinter.lintSync(); |
174 |
| - const isAot = skyPagesConfig && |
175 |
| - skyPagesConfig.skyux && |
176 |
| - skyPagesConfig.skyux.compileMode === 'aot'; |
177 |
| - |
178 |
| - if (lintResult.exitCode > 0) { |
179 |
| - process.exit(lintResult.exitCode); |
180 |
| - } else { |
181 |
| - localeAssetsProcessor.prepareLocaleFiles(); |
182 |
| - const name = argv.serve ? buildServe : buildCompiler; |
183 |
| - return name(argv, skyPagesConfig, webpack, isAot); |
184 |
| - } |
| 16 | + return runBuild(argv, skyPagesConfig, webpack) |
| 17 | + .then(() => { |
| 18 | + logger.info('Build successfully completed.'); |
| 19 | + }) |
| 20 | + .catch(err => { |
| 21 | + logger.error(err); |
| 22 | + process.exit(1); |
| 23 | + }); |
185 | 24 | }
|
186 | 25 |
|
187 | 26 | module.exports = build;
|
0 commit comments