1 | "use strict";
|
2 |
|
3 |
|
4 | function __export(m) {
|
5 | for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
6 | }
|
7 | Object.defineProperty(exports, "__esModule", { value: true });
|
8 | if (process.argv.indexOf('--no-color') === -1) {
|
9 | process.argv.push('--color');
|
10 | }
|
11 | const path = require("path");
|
12 | const GulpTask_1 = require("./tasks/GulpTask");
|
13 | const GulpProxy_1 = require("./GulpProxy");
|
14 | const CleanTask_1 = require("./tasks/CleanTask");
|
15 | const CleanFlagTask_1 = require("./tasks/CleanFlagTask");
|
16 | const CopyStaticAssetsTask_1 = require("./tasks/copyStaticAssets/CopyStaticAssetsTask");
|
17 | const State_1 = require("./State");
|
18 | const logging_1 = require("./logging");
|
19 | const logging_2 = require("./logging");
|
20 | const config_1 = require("./config");
|
21 | const notifier = require("node-notifier");
|
22 | const JestTask_1 = require("./tasks/JestTask");
|
23 | var logging_3 = require("./logging");
|
24 | exports.addSuppression = logging_3.addSuppression;
|
25 | exports.coverageData = logging_3.coverageData;
|
26 | exports.functionalTestRun = logging_3.functionalTestRun;
|
27 | exports.getErrors = logging_3.getErrors;
|
28 | exports.getWarnings = logging_3.getWarnings;
|
29 | exports.TestResultState = logging_3.TestResultState;
|
30 | exports.warn = logging_3.warn;
|
31 | exports.verbose = logging_3.verbose;
|
32 | exports.error = logging_3.error;
|
33 | exports.fileError = logging_3.fileError;
|
34 | exports.fileLog = logging_3.fileLog;
|
35 | exports.fileWarning = logging_3.fileWarning;
|
36 | exports.reset = logging_3.reset;
|
37 | exports.log = logging_3.log;
|
38 | exports.logSummary = logging_3.logSummary;
|
39 | var GCBTerminalProvider_1 = require("./utilities/GCBTerminalProvider");
|
40 | exports.GCBTerminalProvider = GCBTerminalProvider_1.GCBTerminalProvider;
|
41 | __export(require("./tasks/CopyTask"));
|
42 | __export(require("./tasks/GenerateShrinkwrapTask"));
|
43 | __export(require("./tasks/GulpTask"));
|
44 | __export(require("./tasks/CleanTask"));
|
45 | __export(require("./tasks/CleanFlagTask"));
|
46 | __export(require("./tasks/ValidateShrinkwrapTask"));
|
47 | __export(require("./tasks/copyStaticAssets/CopyStaticAssetsTask"));
|
48 | __export(require("./tasks/JestTask"));
|
49 | const _taskMap = {};
|
50 | const _uniqueTasks = [];
|
51 | const packageFolder = State_1.builtPackage.directories && State_1.builtPackage.directories.packagePath
|
52 | ? State_1.builtPackage.directories.packagePath
|
53 | : '';
|
54 | let _buildConfig = {
|
55 | maxBuildTimeMs: 0,
|
56 |
|
57 |
|
58 |
|
59 | gulp: undefined,
|
60 | rootPath: undefined,
|
61 | packageFolder,
|
62 | srcFolder: 'src',
|
63 | distFolder: path.join(packageFolder, 'dist'),
|
64 | libAMDFolder: undefined,
|
65 | libESNextFolder: undefined,
|
66 | libFolder: path.join(packageFolder, 'lib'),
|
67 | tempFolder: 'temp',
|
68 | properties: {},
|
69 | relogIssues: config_1.getFlagValue('relogIssues', true),
|
70 | showToast: config_1.getFlagValue('showToast', true),
|
71 | buildSuccessIconPath: path.resolve(__dirname, 'pass.png'),
|
72 | buildErrorIconPath: path.resolve(__dirname, 'fail.png'),
|
73 | verbose: config_1.getFlagValue('verbose', false),
|
74 | production: config_1.getFlagValue('production', false),
|
75 | args: State_1.args,
|
76 | shouldWarningsFailBuild: false
|
77 | };
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | function setConfig(config) {
|
85 |
|
86 | const objectAssign = require('object-assign');
|
87 | _buildConfig = objectAssign({}, _buildConfig, config);
|
88 | }
|
89 | exports.setConfig = setConfig;
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | function mergeConfig(config) {
|
97 |
|
98 | const merge = require('lodash.merge');
|
99 | _buildConfig = merge({}, _buildConfig, config);
|
100 | }
|
101 | exports.mergeConfig = mergeConfig;
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | function replaceConfig(config) {
|
109 | _buildConfig = config;
|
110 | }
|
111 | exports.replaceConfig = replaceConfig;
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | function getConfig() {
|
118 | return _buildConfig;
|
119 | }
|
120 | exports.getConfig = getConfig;
|
121 |
|
122 | exports.cleanFlag = new CleanFlagTask_1.CleanFlagTask();
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | function task(taskName, taskExecutable) {
|
131 | taskExecutable = serial(exports.cleanFlag, taskExecutable);
|
132 | _taskMap[taskName] = taskExecutable;
|
133 | _trackTask(taskExecutable);
|
134 | return taskExecutable;
|
135 | }
|
136 | exports.task = task;
|
137 |
|
138 | class CustomTask extends GulpTask_1.GulpTask {
|
139 | constructor(name, fn) {
|
140 | super(name);
|
141 | this._fn = fn.bind(this);
|
142 | }
|
143 | executeTask(gulp, completeCallback) {
|
144 | return this._fn(gulp, getConfig(), completeCallback);
|
145 | }
|
146 | }
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 | function subTask(taskName, fn) {
|
157 | const customTask = new CustomTask(taskName, fn);
|
158 | return customTask;
|
159 | }
|
160 | exports.subTask = subTask;
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 | function watch(watchMatch, taskExecutable) {
|
170 | _trackTask(taskExecutable);
|
171 | let isWatchRunning = false;
|
172 | let shouldRerunWatch = false;
|
173 | let lastError = undefined;
|
174 | const successMessage = 'Build succeeded';
|
175 | const failureMessage = 'Build failed';
|
176 | return {
|
177 | execute: (buildConfig) => {
|
178 | return new Promise(() => {
|
179 | function _runWatch() {
|
180 | if (isWatchRunning) {
|
181 | shouldRerunWatch = true;
|
182 | return Promise.resolve();
|
183 | }
|
184 | else {
|
185 | isWatchRunning = true;
|
186 | return _executeTask(taskExecutable, buildConfig)
|
187 | .then(() => {
|
188 | if (lastError) {
|
189 | lastError = undefined;
|
190 | if (buildConfig.showToast) {
|
191 | notifier.notify({
|
192 | title: successMessage,
|
193 | message: State_1.builtPackage ? State_1.builtPackage.name : '',
|
194 | icon: buildConfig.buildSuccessIconPath
|
195 | });
|
196 | }
|
197 | else {
|
198 | logging_1.log(successMessage);
|
199 | }
|
200 | }
|
201 | return _finalizeWatch();
|
202 | })
|
203 | .catch((error) => {
|
204 | if (!lastError || lastError !== error) {
|
205 | lastError = error;
|
206 | if (buildConfig.showToast) {
|
207 | notifier.notify({
|
208 | title: failureMessage,
|
209 | message: error.toString(),
|
210 | icon: buildConfig.buildErrorIconPath
|
211 | });
|
212 | }
|
213 | else {
|
214 | logging_1.log(failureMessage);
|
215 | }
|
216 | }
|
217 | return _finalizeWatch();
|
218 | });
|
219 | }
|
220 | }
|
221 | function _finalizeWatch() {
|
222 | isWatchRunning = false;
|
223 | if (shouldRerunWatch) {
|
224 | shouldRerunWatch = false;
|
225 | return _runWatch();
|
226 | }
|
227 | return Promise.resolve();
|
228 | }
|
229 | logging_2.setWatchMode();
|
230 | buildConfig.gulp.watch(watchMatch, _runWatch);
|
231 | _runWatch().catch(console.error);
|
232 | });
|
233 | }
|
234 | };
|
235 | }
|
236 | exports.watch = watch;
|
237 |
|
238 |
|
239 |
|
240 |
|
241 | function serial(...tasks) {
|
242 | const flatTasks = _flatten(tasks).filter((taskExecutable) => {
|
243 |
|
244 | return taskExecutable !== null && taskExecutable !== undefined;
|
245 | });
|
246 | for (const flatTask of flatTasks) {
|
247 | _trackTask(flatTask);
|
248 | }
|
249 | return {
|
250 | execute: (buildConfig) => {
|
251 | let output = Promise.resolve();
|
252 | for (const taskExecutable of flatTasks) {
|
253 | output = output.then(() => _executeTask(taskExecutable, buildConfig));
|
254 | }
|
255 | return output;
|
256 | }
|
257 | };
|
258 | }
|
259 | exports.serial = serial;
|
260 |
|
261 |
|
262 |
|
263 |
|
264 | function parallel(...tasks) {
|
265 | const flatTasks = _flatten(tasks).filter((taskExecutable) => {
|
266 |
|
267 | return taskExecutable !== null && taskExecutable !== undefined;
|
268 | });
|
269 | for (const flatTask of flatTasks) {
|
270 | _trackTask(flatTask);
|
271 | }
|
272 | return {
|
273 |
|
274 | execute: (buildConfig) => {
|
275 | return new Promise((resolve, reject) => {
|
276 | const promises = [];
|
277 | for (const taskExecutable of flatTasks) {
|
278 | promises.push(_executeTask(taskExecutable, buildConfig));
|
279 | }
|
280 |
|
281 | Promise.all(promises).then(resolve, reject);
|
282 | });
|
283 | }
|
284 | };
|
285 | }
|
286 | exports.parallel = parallel;
|
287 |
|
288 |
|
289 |
|
290 |
|
291 | function initialize(gulp) {
|
292 | _buildConfig.rootPath = process.cwd();
|
293 | _buildConfig.gulp = new GulpProxy_1.GulpProxy(gulp);
|
294 | _buildConfig.uniqueTasks = _uniqueTasks;
|
295 | _buildConfig.jestEnabled = JestTask_1._isJestEnabled(_buildConfig.rootPath);
|
296 | _handleCommandLineArguments();
|
297 | for (const uniqueTask of _buildConfig.uniqueTasks) {
|
298 | if (uniqueTask.onRegister) {
|
299 | uniqueTask.onRegister();
|
300 | }
|
301 | }
|
302 | logging_2.initialize(gulp, getConfig(), undefined, undefined);
|
303 | Object.keys(_taskMap).forEach((taskName) => _registerTask(gulp, taskName, _taskMap[taskName]));
|
304 | logging_2.markTaskCreationTime();
|
305 | }
|
306 | exports.initialize = initialize;
|
307 |
|
308 |
|
309 |
|
310 | function _registerTask(gulp, taskName, taskExecutable) {
|
311 | gulp.task(taskName, (cb) => {
|
312 | const maxBuildTimeMs = taskExecutable.maxBuildTimeMs === undefined
|
313 | ? _buildConfig.maxBuildTimeMs
|
314 | : taskExecutable.maxBuildTimeMs;
|
315 | const timer = maxBuildTimeMs === 0
|
316 | ? undefined
|
317 | : setTimeout(() => {
|
318 | logging_1.error(`Build ran for ${maxBuildTimeMs} milliseconds without completing. Cancelling build with error.`);
|
319 | cb(new Error('Timeout'));
|
320 | }, maxBuildTimeMs);
|
321 | _executeTask(taskExecutable, _buildConfig).then(() => {
|
322 | if (timer) {
|
323 | clearTimeout(timer);
|
324 | }
|
325 | cb();
|
326 | }, (error) => {
|
327 | if (timer) {
|
328 | clearTimeout(timer);
|
329 | }
|
330 | cb(logging_2.generateGulpError(error));
|
331 | });
|
332 | });
|
333 | }
|
334 |
|
335 |
|
336 |
|
337 | function _executeTask(taskExecutable, buildConfig) {
|
338 |
|
339 | if (taskExecutable && !taskExecutable.execute) {
|
340 |
|
341 | if (taskExecutable.default) {
|
342 |
|
343 | taskExecutable = taskExecutable.default;
|
344 | }
|
345 | }
|
346 |
|
347 | if (!taskExecutable || !taskExecutable.execute) {
|
348 | return Promise.reject(new Error(`A task was scheduled, but the task was null. This probably means the task wasn't imported correctly.`));
|
349 | }
|
350 | if (taskExecutable.isEnabled === undefined || taskExecutable.isEnabled(buildConfig)) {
|
351 | const startTime = process.hrtime();
|
352 | if (buildConfig.onTaskStart && taskExecutable.name) {
|
353 | buildConfig.onTaskStart(taskExecutable.name);
|
354 | }
|
355 | const taskPromise = taskExecutable.execute(buildConfig).then(() => {
|
356 | if (buildConfig.onTaskEnd && taskExecutable.name) {
|
357 | buildConfig.onTaskEnd(taskExecutable.name, process.hrtime(startTime));
|
358 | }
|
359 | }, (error) => {
|
360 | if (buildConfig.onTaskEnd && taskExecutable.name) {
|
361 | buildConfig.onTaskEnd(taskExecutable.name, process.hrtime(startTime), error);
|
362 | }
|
363 | return Promise.reject(error);
|
364 | });
|
365 | return taskPromise;
|
366 | }
|
367 |
|
368 | return Promise.resolve();
|
369 | }
|
370 | function _trackTask(taskExecutable) {
|
371 | if (_uniqueTasks.indexOf(taskExecutable) < 0) {
|
372 | _uniqueTasks.push(taskExecutable);
|
373 | }
|
374 | }
|
375 |
|
376 |
|
377 |
|
378 | function _flatten(oArr) {
|
379 | const output = [];
|
380 | function traverse(arr) {
|
381 | for (let i = 0; i < arr.length; ++i) {
|
382 | if (Array.isArray(arr[i])) {
|
383 | traverse(arr[i]);
|
384 | }
|
385 | else {
|
386 | output.push(arr[i]);
|
387 | }
|
388 | }
|
389 | }
|
390 | traverse(oArr);
|
391 | return output;
|
392 | }
|
393 | function _handleCommandLineArguments() {
|
394 | _handleTasksListArguments();
|
395 | }
|
396 | function _handleTasksListArguments() {
|
397 |
|
398 | if (State_1.args['tasks'] || State_1.args['tasks-simple'] || State_1.args['T']) {
|
399 | global['dontWatchExit'] = true;
|
400 | }
|
401 | if (State_1.args['h']) {
|
402 |
|
403 | global['dontWatchExit'] = true;
|
404 | }
|
405 |
|
406 | }
|
407 |
|
408 | exports.clean = new CleanTask_1.CleanTask();
|
409 |
|
410 | exports.copyStaticAssets = new CopyStaticAssetsTask_1.CopyStaticAssetsTask();
|
411 |
|
412 | exports.jest = new JestTask_1.JestTask();
|
413 |
|
414 | task('clean', exports.clean);
|
415 |
|
\ | No newline at end of file |