app-bundler 0.1.16 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bundler.js +646 -171
- package/lib/cli.js +646 -171
- package/package.json +6 -5
- package/tsconfig.json +5 -0
package/lib/cli.js
CHANGED
|
@@ -78,6 +78,10 @@ var _src_handlers_script_common_js_CommonJsPathResolver = {};
|
|
|
78
78
|
var _src_handlers_script_common_js_CommonJsRewriter = {};
|
|
79
79
|
var _src_handlers_script_common_js_ModuleWrapper = {};
|
|
80
80
|
var _src_handlers_script_common_js_templates_Templates = {};
|
|
81
|
+
var _src_handlers_script_copy_js_CopyJsBuilder = {};
|
|
82
|
+
var _src_handlers_script_copy_js_CopyJsHandler = {};
|
|
83
|
+
var _src_handlers_script_copy_js_CopyJsParser = {};
|
|
84
|
+
var _src_handlers_script_copy_js_CopyJsRewriter = {};
|
|
81
85
|
var _src_handlers_script_global_js_GlobalJsBuilder = {};
|
|
82
86
|
var _src_handlers_script_global_js_GlobalJsHandler = {};
|
|
83
87
|
var _src_handlers_script_global_js_GlobalJsParser = {};
|
|
@@ -132,7 +136,7 @@ let assert = require('assert');
|
|
|
132
136
|
exports.assert = assert;
|
|
133
137
|
let logger = require('atma-logger');
|
|
134
138
|
exports.logger = logger;
|
|
135
|
-
let io = g.io || require('atma-io');
|
|
139
|
+
let io = (g.io || require('atma-io'));
|
|
136
140
|
exports.io = io;
|
|
137
141
|
/* Make compatible with previous atma-loaders */
|
|
138
142
|
g.Class = require('atma-class');
|
|
@@ -166,8 +170,8 @@ var _src_utils_path;
|
|
|
166
170
|
|
|
167
171
|
"use strict";
|
|
168
172
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
169
|
-
exports.path_toAbsolute = exports.path_removeQuery = exports.path_sliceQuery = exports.path_sliceHash = exports.path_combine = exports.path_toRelative = exports.path_isRelative = exports.path_resolveUrl = exports.path_normalize = exports.path_resolveCurrent = exports.path_withProtocol = exports.path_appendQuery = exports.path_getExtension = exports.path_getFile = exports.path_getDir = void 0;
|
|
170
|
-
|
|
173
|
+
exports.path_toAbsolute = exports.path_changeExtension = exports.path_removeQuery = exports.path_sliceQuery = exports.path_sliceHash = exports.path_combine = exports.path_toRelative = exports.path_isRelative = exports.path_resolveUrl = exports.path_normalize = exports.path_resolveCurrent = exports.path_withProtocol = exports.path_appendQuery = exports.path_getExtension = exports.path_getFile = exports.path_getDir = void 0;
|
|
174
|
+
let isWeb = true;
|
|
171
175
|
function path_getDir(path) {
|
|
172
176
|
return path.substring(0, path.lastIndexOf('/') + 1);
|
|
173
177
|
}
|
|
@@ -187,17 +191,17 @@ function path_getFile(path) {
|
|
|
187
191
|
exports.path_getFile = path_getFile;
|
|
188
192
|
;
|
|
189
193
|
function path_getExtension(path) {
|
|
190
|
-
|
|
194
|
+
let query = path.indexOf('?');
|
|
191
195
|
if (query !== -1) {
|
|
192
196
|
path = path.substring(0, query);
|
|
193
197
|
}
|
|
194
|
-
|
|
198
|
+
let match = rgx_EXT.exec(path);
|
|
195
199
|
return match == null ? '' : match[1];
|
|
196
200
|
}
|
|
197
201
|
exports.path_getExtension = path_getExtension;
|
|
198
202
|
;
|
|
199
203
|
function path_appendQuery(path, key, val) {
|
|
200
|
-
|
|
204
|
+
let conjunctor = path.indexOf('?') === -1 ? '?' : '&';
|
|
201
205
|
return path + conjunctor + key + '=' + val;
|
|
202
206
|
}
|
|
203
207
|
exports.path_appendQuery = path_appendQuery;
|
|
@@ -207,7 +211,7 @@ function path_withProtocol(path) {
|
|
|
207
211
|
}
|
|
208
212
|
exports.path_withProtocol = path_withProtocol;
|
|
209
213
|
;
|
|
210
|
-
|
|
214
|
+
let current_;
|
|
211
215
|
function path_resolveCurrent() {
|
|
212
216
|
if (current_ != null)
|
|
213
217
|
return current_;
|
|
@@ -216,7 +220,7 @@ function path_resolveCurrent() {
|
|
|
216
220
|
exports.path_resolveCurrent = path_resolveCurrent;
|
|
217
221
|
;
|
|
218
222
|
function path_normalize(path) {
|
|
219
|
-
|
|
223
|
+
let path_ = path
|
|
220
224
|
.replace(/\\/g, '/')
|
|
221
225
|
// remove double slashes, but not near protocol
|
|
222
226
|
.replace(/([^:\/])\/{2,}/g, '$1/')
|
|
@@ -233,7 +237,7 @@ function path_normalize(path) {
|
|
|
233
237
|
exports.path_normalize = path_normalize;
|
|
234
238
|
;
|
|
235
239
|
function path_resolveUrl(path, base) {
|
|
236
|
-
|
|
240
|
+
let url = path_normalize(path);
|
|
237
241
|
if (path_isRelative(url)) {
|
|
238
242
|
return path_normalize(path_combine(base || path_resolveCurrent(), url));
|
|
239
243
|
}
|
|
@@ -264,9 +268,9 @@ function path_toRelative(path, anchor, base) {
|
|
|
264
268
|
return path_.substring(absolute_.length);
|
|
265
269
|
}
|
|
266
270
|
else {
|
|
267
|
-
|
|
271
|
+
let sub = '../';
|
|
268
272
|
while (true) {
|
|
269
|
-
|
|
273
|
+
let folder = absolute_.replace(/[^\/]+\/?$/, '');
|
|
270
274
|
if (folder === '' || folder === absolute_) {
|
|
271
275
|
break;
|
|
272
276
|
}
|
|
@@ -282,7 +286,9 @@ function path_toRelative(path, anchor, base) {
|
|
|
282
286
|
exports.path_toRelative = path_toRelative;
|
|
283
287
|
;
|
|
284
288
|
function path_combine(...args) {
|
|
285
|
-
|
|
289
|
+
let out = '';
|
|
290
|
+
let imax = args.length;
|
|
291
|
+
let i = -1, x;
|
|
286
292
|
while (++i < imax) {
|
|
287
293
|
x = args[i];
|
|
288
294
|
if (!x)
|
|
@@ -305,38 +311,54 @@ function path_combine(...args) {
|
|
|
305
311
|
exports.path_combine = path_combine;
|
|
306
312
|
;
|
|
307
313
|
function path_sliceHash(url) {
|
|
308
|
-
if (url == null)
|
|
314
|
+
if (url == null) {
|
|
309
315
|
return null;
|
|
310
|
-
|
|
311
|
-
|
|
316
|
+
}
|
|
317
|
+
let i = url.indexOf('#');
|
|
318
|
+
if (i === -1) {
|
|
312
319
|
return null;
|
|
320
|
+
}
|
|
313
321
|
return url.substring(i);
|
|
314
322
|
}
|
|
315
323
|
exports.path_sliceHash = path_sliceHash;
|
|
316
324
|
;
|
|
317
325
|
function path_sliceQuery(url) {
|
|
318
|
-
if (url == null)
|
|
326
|
+
if (url == null) {
|
|
319
327
|
return null;
|
|
320
|
-
|
|
321
|
-
|
|
328
|
+
}
|
|
329
|
+
let i = url.indexOf('?');
|
|
330
|
+
if (i === -1) {
|
|
322
331
|
return null;
|
|
332
|
+
}
|
|
323
333
|
return url.substring(i);
|
|
324
334
|
}
|
|
325
335
|
exports.path_sliceQuery = path_sliceQuery;
|
|
326
336
|
;
|
|
327
337
|
function path_removeQuery(url) {
|
|
328
|
-
if (url == null)
|
|
338
|
+
if (url == null) {
|
|
329
339
|
return null;
|
|
330
|
-
|
|
331
|
-
|
|
340
|
+
}
|
|
341
|
+
let i = url.indexOf('#');
|
|
342
|
+
if (i !== -1) {
|
|
332
343
|
url = url.substring(0, i);
|
|
333
|
-
|
|
334
|
-
|
|
344
|
+
}
|
|
345
|
+
i = url.indexOf('?');
|
|
346
|
+
if (i !== -1) {
|
|
335
347
|
url = url.substring(0, i);
|
|
348
|
+
}
|
|
336
349
|
return url;
|
|
337
350
|
}
|
|
338
351
|
exports.path_removeQuery = path_removeQuery;
|
|
339
352
|
;
|
|
353
|
+
function path_changeExtension(path, ext) {
|
|
354
|
+
let str = ext ? '.' + ext : '';
|
|
355
|
+
let i = path.indexOf('.');
|
|
356
|
+
if (i === -1) {
|
|
357
|
+
return path + str;
|
|
358
|
+
}
|
|
359
|
+
return path.substring(0, i) + str;
|
|
360
|
+
}
|
|
361
|
+
exports.path_changeExtension = path_changeExtension;
|
|
340
362
|
function path_toAbsolute(path, parentLocation, rootLocation) {
|
|
341
363
|
path = path_normalize(path);
|
|
342
364
|
if (path_isRelative(path) === false) {
|
|
@@ -355,11 +377,11 @@ function path_toAbsolute(path, parentLocation, rootLocation) {
|
|
|
355
377
|
}
|
|
356
378
|
exports.path_toAbsolute = path_toAbsolute;
|
|
357
379
|
;
|
|
358
|
-
|
|
380
|
+
let _cwd;
|
|
359
381
|
function cwd() {
|
|
360
382
|
return _cwd || (_cwd = path_normalize(process.cwd()));
|
|
361
383
|
}
|
|
362
|
-
|
|
384
|
+
let rgx_PROTOCOL = /^(file|https?):/i, rgx_SUB_DIR = /[^\/\.]+\/\.\.\//, rgx_FILENAME = /\/[^\/]+\.\w+(\?.*)?(#.*)?$/, rgx_EXT = /\.(\w+)$/, rgx_win32Drive = /(^\/?\w{1}:)(\/|$)/;
|
|
363
385
|
function path_win32Normalize(path) {
|
|
364
386
|
path = path_normalize(path);
|
|
365
387
|
if (path.substring(0, 5) === 'file:')
|
|
@@ -367,7 +389,7 @@ function path_win32Normalize(path) {
|
|
|
367
389
|
return 'file://' + path;
|
|
368
390
|
}
|
|
369
391
|
function path_collapse(url_) {
|
|
370
|
-
|
|
392
|
+
let url = url_;
|
|
371
393
|
while (rgx_SUB_DIR.test(url)) {
|
|
372
394
|
url = url.replace(rgx_SUB_DIR, '');
|
|
373
395
|
}
|
|
@@ -1138,11 +1160,11 @@ class Include {
|
|
|
1138
1160
|
}
|
|
1139
1161
|
}
|
|
1140
1162
|
include(type, mix) {
|
|
1141
|
-
var
|
|
1142
|
-
if (typeof
|
|
1143
|
-
|
|
1163
|
+
var pkg = mix;
|
|
1164
|
+
if (typeof pkg === 'string' && arguments.length > 2) {
|
|
1165
|
+
pkg = Array.prototype.slice.call(arguments, 1);
|
|
1144
1166
|
}
|
|
1145
|
-
Routes.each(type,
|
|
1167
|
+
Routes.each(type, pkg, (namespace, route) => {
|
|
1146
1168
|
let item = new Include();
|
|
1147
1169
|
item.type = type;
|
|
1148
1170
|
item.url = atma_utils_1.class_Uri.combine(this.base, route.path);
|
|
@@ -1207,7 +1229,7 @@ exports.Include = Include;
|
|
|
1207
1229
|
Include.groupByType = res_1.res_groupByType;
|
|
1208
1230
|
Include.PathResolver = PathResolver;
|
|
1209
1231
|
;
|
|
1210
|
-
['js', 'css', 'load', 'lazy', 'mask'].forEach(type => {
|
|
1232
|
+
['js', 'css', 'load', 'lazy', 'mask', 'data'].forEach(type => {
|
|
1211
1233
|
Include.prototype[type] = function () {
|
|
1212
1234
|
var mix = arguments.length > 1 ? Array.from(arguments) : arguments[0];
|
|
1213
1235
|
return this.include(type, mix);
|
|
@@ -1387,6 +1409,7 @@ const HandlersUtils_1 = _src_class_HandlersUtils;
|
|
|
1387
1409
|
const npm_1 = _src_utils_npm;
|
|
1388
1410
|
class Resource {
|
|
1389
1411
|
constructor(includeData, parent, solution) {
|
|
1412
|
+
var _a;
|
|
1390
1413
|
this.parent = parent;
|
|
1391
1414
|
this.solution = solution;
|
|
1392
1415
|
this.resources = [];
|
|
@@ -1409,6 +1432,8 @@ class Resource {
|
|
|
1409
1432
|
this.inPages = null;
|
|
1410
1433
|
this.isCyclic = false;
|
|
1411
1434
|
this.isMapped = false;
|
|
1435
|
+
// when the path is like "/foo/bar/**.ts"
|
|
1436
|
+
this.isGlob = false;
|
|
1412
1437
|
this.meta = null;
|
|
1413
1438
|
this.aliases = [];
|
|
1414
1439
|
if (arguments.length === 0)
|
|
@@ -1435,6 +1460,7 @@ class Resource {
|
|
|
1435
1460
|
this.asModules = [];
|
|
1436
1461
|
this.inPages = [];
|
|
1437
1462
|
this.source = null;
|
|
1463
|
+
this.isGlob = /\*+\.\w+$/.test(includeData.url);
|
|
1438
1464
|
if (includeData.bundle) {
|
|
1439
1465
|
this.bundle = includeData.bundle;
|
|
1440
1466
|
}
|
|
@@ -1459,8 +1485,19 @@ class Resource {
|
|
|
1459
1485
|
if (includeData.url == null) {
|
|
1460
1486
|
return;
|
|
1461
1487
|
}
|
|
1462
|
-
|
|
1463
|
-
|
|
1488
|
+
let mappings = (_a = solution === null || solution === void 0 ? void 0 : solution.opts.mappings) !== null && _a !== void 0 ? _a : {};
|
|
1489
|
+
if (mappings[includeData.url] != null) {
|
|
1490
|
+
includeData.url = mappings[includeData.url];
|
|
1491
|
+
}
|
|
1492
|
+
else {
|
|
1493
|
+
// Map resource by regex, for example the filename to another filename
|
|
1494
|
+
for (let key in mappings) {
|
|
1495
|
+
let rgx = new RegExp(key);
|
|
1496
|
+
if (rgx.test(includeData.url)) {
|
|
1497
|
+
includeData.url = includeData.url.replace(rgx, mappings[key]);
|
|
1498
|
+
break;
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1464
1501
|
}
|
|
1465
1502
|
let url;
|
|
1466
1503
|
let pathResolver = HandlersUtils_1.HandlersUtils.findPathResolver(solution.handlers, includeData);
|
|
@@ -1476,7 +1513,11 @@ class Resource {
|
|
|
1476
1513
|
}
|
|
1477
1514
|
if (Include_1.Include.PathResolver.isNpm(includeData.url)) {
|
|
1478
1515
|
this.aliases.push(includeData.url);
|
|
1479
|
-
|
|
1516
|
+
let byNpmResolver = npm_1.Npm.resolveAppUrl(includeData.url, parent && parent.location, solution.opts.base);
|
|
1517
|
+
if (byNpmResolver != null) {
|
|
1518
|
+
// otherwise "url" could be previously resolved with pathResolver.resolve
|
|
1519
|
+
url = byNpmResolver;
|
|
1520
|
+
}
|
|
1480
1521
|
if (url == null) {
|
|
1481
1522
|
// Fix. `resolveAppUrl` returns undefined on native nodejs modules
|
|
1482
1523
|
url = includeData.url;
|
|
@@ -1534,6 +1575,8 @@ class Resource {
|
|
|
1534
1575
|
res.source = this.source;
|
|
1535
1576
|
res.isCyclic = this.isCyclic;
|
|
1536
1577
|
res.aliases = this.aliases;
|
|
1578
|
+
res.isGlob = this.isGlob;
|
|
1579
|
+
res.dependencies = this.dependencies;
|
|
1537
1580
|
return res;
|
|
1538
1581
|
}
|
|
1539
1582
|
toTarget(solution, settings) {
|
|
@@ -1546,6 +1589,7 @@ class Resource {
|
|
|
1546
1589
|
resource.inPages = this.inPages;
|
|
1547
1590
|
resource.bundle = this.bundle;
|
|
1548
1591
|
resource.aliases = this.aliases;
|
|
1592
|
+
resource.isGlob = this.isGlob;
|
|
1549
1593
|
if (solution.opts.version && ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.type) !== 'load') {
|
|
1550
1594
|
resource.url += '?v=' + solution.opts.version;
|
|
1551
1595
|
}
|
|
@@ -1630,7 +1674,7 @@ class Resource {
|
|
|
1630
1674
|
if (modules.length === 1) {
|
|
1631
1675
|
return modules[0];
|
|
1632
1676
|
}
|
|
1633
|
-
let arr = ['global', 'commonjs', 'amd', 'includejs', 'import'];
|
|
1677
|
+
let arr = ['global', 'commonjs', 'amd', 'includejs', 'import', 'esm'];
|
|
1634
1678
|
let name = arr.find(name => modules.indexOf(name) !== -1);
|
|
1635
1679
|
if (name == null) {
|
|
1636
1680
|
name = modules[0];
|
|
@@ -2331,6 +2375,18 @@ exports.FileActions = {
|
|
|
2331
2375
|
}
|
|
2332
2376
|
return global_1.io.File.readAsync(path, opts);
|
|
2333
2377
|
},
|
|
2378
|
+
async readDirectory(path, opts) {
|
|
2379
|
+
let i = path.indexOf('*');
|
|
2380
|
+
let patternI = path.lastIndexOf('/', i);
|
|
2381
|
+
if (patternI === -1) {
|
|
2382
|
+
throw new Error(`Invalid glob pattern: ${path}`);
|
|
2383
|
+
}
|
|
2384
|
+
let pattern = path.substring(patternI + 1);
|
|
2385
|
+
let directory = path.substring(0, patternI + 1);
|
|
2386
|
+
let files = await global_1.io.Directory.readFiles(directory, pattern);
|
|
2387
|
+
let paths = files.map(x => x.uri.toString());
|
|
2388
|
+
return paths;
|
|
2389
|
+
},
|
|
2334
2390
|
writeFile(path, content, opts) {
|
|
2335
2391
|
return global_1.io.File.writeAsync(path, content, opts);
|
|
2336
2392
|
},
|
|
@@ -2406,7 +2462,7 @@ class Configuration {
|
|
|
2406
2462
|
}
|
|
2407
2463
|
}
|
|
2408
2464
|
defineMany(options) {
|
|
2409
|
-
for (
|
|
2465
|
+
for (let key in options) {
|
|
2410
2466
|
this.define(key, options[key]);
|
|
2411
2467
|
}
|
|
2412
2468
|
}
|
|
@@ -2590,7 +2646,9 @@ class SolutionOpts extends SolutionOptsBase {
|
|
|
2590
2646
|
'scss': { type: 'css' },
|
|
2591
2647
|
'sass': { type: 'css' },
|
|
2592
2648
|
'html': { type: 'html' },
|
|
2593
|
-
|
|
2649
|
+
// will be embedded as data into the build
|
|
2650
|
+
'json': { type: 'js' },
|
|
2651
|
+
'yml': { type: 'js' },
|
|
2594
2652
|
'jpg': { type: 'asset' },
|
|
2595
2653
|
'png': { type: 'asset' },
|
|
2596
2654
|
'mp4': { type: 'asset' },
|
|
@@ -2954,13 +3012,17 @@ class OutputResources {
|
|
|
2954
3012
|
this.resources = [];
|
|
2955
3013
|
this.pagesInput = {};
|
|
2956
3014
|
}
|
|
2957
|
-
|
|
3015
|
+
prepare(resources) {
|
|
2958
3016
|
this.resources = [];
|
|
2959
3017
|
this.pagesInput = {};
|
|
2960
3018
|
this.items = [];
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
3019
|
+
let root = resources.pop();
|
|
3020
|
+
let isGlob = root.isGlob;
|
|
3021
|
+
if (isGlob !== true) {
|
|
3022
|
+
this.rootOutput = root.toTarget(this.solution);
|
|
3023
|
+
this.rootOutput.content = root.content;
|
|
3024
|
+
}
|
|
3025
|
+
this.rootInput = root;
|
|
2964
3026
|
this.pagesInput = (0, res_1.res_groupByPageAndBundles)(resources, this.solution.opts);
|
|
2965
3027
|
Object.keys(this.pagesInput).forEach(page => {
|
|
2966
3028
|
Object.keys(this.pagesInput[page]).forEach(bundle => {
|
|
@@ -2973,20 +3035,22 @@ class OutputResources {
|
|
|
2973
3035
|
bundle,
|
|
2974
3036
|
type,
|
|
2975
3037
|
solution: this.solution,
|
|
2976
|
-
resources: arr
|
|
3038
|
+
resources: arr,
|
|
3039
|
+
isGlob: isGlob,
|
|
2977
3040
|
});
|
|
2978
3041
|
this.items.push(item);
|
|
2979
3042
|
});
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
3043
|
+
// @TODO: Do we need empty output item?
|
|
3044
|
+
// if (byType['js'] == null) {
|
|
3045
|
+
// let item = new OutputItem({
|
|
3046
|
+
// page,
|
|
3047
|
+
// bundle,
|
|
3048
|
+
// type: 'js',
|
|
3049
|
+
// solution: this.solution,
|
|
3050
|
+
// resources: []
|
|
3051
|
+
// });
|
|
3052
|
+
// this.items.push(item);
|
|
3053
|
+
// }
|
|
2990
3054
|
});
|
|
2991
3055
|
});
|
|
2992
3056
|
}
|
|
@@ -2994,7 +3058,7 @@ class OutputResources {
|
|
|
2994
3058
|
return this.items.filter(x => x.page === page).map(x => x.resource);
|
|
2995
3059
|
}
|
|
2996
3060
|
getAll() {
|
|
2997
|
-
|
|
3061
|
+
let all = this
|
|
2998
3062
|
.items
|
|
2999
3063
|
.map(x => x.resource)
|
|
3000
3064
|
.filter(x => x.embed !== true)
|
|
@@ -3007,19 +3071,27 @@ class OutputResources {
|
|
|
3007
3071
|
}
|
|
3008
3072
|
exports.OutputResources = OutputResources;
|
|
3009
3073
|
class OutputItem {
|
|
3010
|
-
constructor(
|
|
3074
|
+
constructor(params) {
|
|
3075
|
+
let { page, bundle, type, solution, resources, isGlob } = params;
|
|
3011
3076
|
this.page = page;
|
|
3012
3077
|
this.bundle = bundle;
|
|
3013
3078
|
this.type = type;
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3079
|
+
this.resource = params.resource;
|
|
3080
|
+
this.resources = resources !== null && resources !== void 0 ? resources : [];
|
|
3081
|
+
if (this.resource == null) {
|
|
3082
|
+
let ext = solution.opts.getExtForType(type);
|
|
3083
|
+
let sfx = '';
|
|
3084
|
+
if (isGlob === true) {
|
|
3085
|
+
sfx = '_*';
|
|
3086
|
+
}
|
|
3087
|
+
let filename = `${page}_${bundle}${sfx}.${ext}`;
|
|
3088
|
+
let resource = new Resource_1.Resource({
|
|
3089
|
+
type: type,
|
|
3090
|
+
url: filename,
|
|
3091
|
+
bundle: bundle
|
|
3092
|
+
}, null, solution);
|
|
3093
|
+
this.resource = resource.toTarget(solution);
|
|
3094
|
+
}
|
|
3023
3095
|
}
|
|
3024
3096
|
}
|
|
3025
3097
|
exports.OutputItem = OutputItem;
|
|
@@ -3057,7 +3129,7 @@ exports.BaseHandler = void 0;
|
|
|
3057
3129
|
class BaseHandler {
|
|
3058
3130
|
constructor(solution) {
|
|
3059
3131
|
this.solution = solution;
|
|
3060
|
-
|
|
3132
|
+
let { Parser, Rewriter, Builder, PathResolver } = this.constructor;
|
|
3061
3133
|
this.parser = new Parser(solution, this);
|
|
3062
3134
|
this.rewriter = new Rewriter(solution, this);
|
|
3063
3135
|
this.builder = new Builder(solution, this);
|
|
@@ -3387,6 +3459,12 @@ class BaseParser {
|
|
|
3387
3459
|
assert(solution instanceof Solution_1.Solution, 'Solution expected for Parser');
|
|
3388
3460
|
assert(handler instanceof BaseHandler_1.BaseHandler, 'BaseHandler expected for the Parser');
|
|
3389
3461
|
}
|
|
3462
|
+
/** Usually we transpile on `atma-io` level. But in some cases the bundle may need to adjust the content.
|
|
3463
|
+
* For example the .json or .yml files should be serialized to export the content
|
|
3464
|
+
*/
|
|
3465
|
+
transpile(content, resource) {
|
|
3466
|
+
return Promise.resolve({ content });
|
|
3467
|
+
}
|
|
3390
3468
|
getDependencies(content, ownerResource) {
|
|
3391
3469
|
throw new Error('Not implemented');
|
|
3392
3470
|
}
|
|
@@ -3887,7 +3965,7 @@ class MaskParser extends BaseParser_1.BaseParser {
|
|
|
3887
3965
|
// @NextIteration base will be handled in mask.Module.resolvePath
|
|
3888
3966
|
// var base = mask.Module.cfg('base');
|
|
3889
3967
|
// if (base) {
|
|
3890
|
-
//
|
|
3968
|
+
// path = path_combine(base, path);
|
|
3891
3969
|
// }
|
|
3892
3970
|
}
|
|
3893
3971
|
return [this._createDependency(path, type, page)];
|
|
@@ -4012,12 +4090,15 @@ exports.AstUtil = void 0;
|
|
|
4012
4090
|
const UglifyJS = require("uglify-js");
|
|
4013
4091
|
let nope = function () {
|
|
4014
4092
|
return true;
|
|
4015
|
-
}
|
|
4093
|
+
};
|
|
4094
|
+
let variableOverrides = null;
|
|
4095
|
+
function walk(node, fn) {
|
|
4016
4096
|
var walker = new UglifyJS.TreeWalker(function (node, descend) {
|
|
4017
4097
|
return fn.call(this, node, descend);
|
|
4018
4098
|
});
|
|
4019
4099
|
node.walk(walker);
|
|
4020
|
-
}
|
|
4100
|
+
}
|
|
4101
|
+
function findNode(node, fn, options = { scopeOnly: false }) {
|
|
4021
4102
|
var result, intop = true;
|
|
4022
4103
|
walk(node, function (node) {
|
|
4023
4104
|
if (options.scopeOnly && !intop) {
|
|
@@ -4034,11 +4115,13 @@ let nope = function () {
|
|
|
4034
4115
|
return null;
|
|
4035
4116
|
});
|
|
4036
4117
|
return result;
|
|
4037
|
-
}
|
|
4118
|
+
}
|
|
4119
|
+
function each(node, selector, fn) {
|
|
4038
4120
|
walk(node, function (node) {
|
|
4039
4121
|
return selector(node) ? fn.call(this, node, selector) : null;
|
|
4040
4122
|
});
|
|
4041
|
-
}
|
|
4123
|
+
}
|
|
4124
|
+
function getVariableValue(scope, varName) {
|
|
4042
4125
|
if (variableOverrides && varName in variableOverrides) {
|
|
4043
4126
|
return variableOverrides[varName];
|
|
4044
4127
|
}
|
|
@@ -4062,7 +4145,8 @@ let nope = function () {
|
|
|
4062
4145
|
return evaluateNode(varDef.right, scope);
|
|
4063
4146
|
}
|
|
4064
4147
|
return null;
|
|
4065
|
-
}
|
|
4148
|
+
}
|
|
4149
|
+
function evaluateNode(node, scope) {
|
|
4066
4150
|
if (scope == null) {
|
|
4067
4151
|
console.warn('Evaluate Node: Scope is undefined', node);
|
|
4068
4152
|
}
|
|
@@ -4112,7 +4196,8 @@ let nope = function () {
|
|
|
4112
4196
|
//
|
|
4113
4197
|
//console.warn('[includes parser]: Dynamic Expression', type, file, ':', info.line);
|
|
4114
4198
|
return null;
|
|
4115
|
-
}
|
|
4199
|
+
}
|
|
4200
|
+
function getArguments(args, scope) {
|
|
4116
4201
|
if (scope == null) {
|
|
4117
4202
|
console.warn('getArguments: scope is undefined', args);
|
|
4118
4203
|
}
|
|
@@ -4121,7 +4206,8 @@ let nope = function () {
|
|
|
4121
4206
|
return evaluateNode(x, scope);
|
|
4122
4207
|
});
|
|
4123
4208
|
return cleanArgs(args);
|
|
4124
|
-
}
|
|
4209
|
+
}
|
|
4210
|
+
function cleanArgs(args) {
|
|
4125
4211
|
for (var i = 0, x, length = args.length; i < length; i++) {
|
|
4126
4212
|
x = args[i];
|
|
4127
4213
|
if (x == null) {
|
|
@@ -4159,7 +4245,8 @@ let nope = function () {
|
|
|
4159
4245
|
}
|
|
4160
4246
|
}
|
|
4161
4247
|
return args;
|
|
4162
|
-
}
|
|
4248
|
+
}
|
|
4249
|
+
function getPropertyChain(node, stack) {
|
|
4163
4250
|
if ((node instanceof UglifyJS.AST_SymbolRef) == false) {
|
|
4164
4251
|
console.warn('Current node is not a sumbol referencing');
|
|
4165
4252
|
}
|
|
@@ -4173,10 +4260,12 @@ let nope = function () {
|
|
|
4173
4260
|
break;
|
|
4174
4261
|
}
|
|
4175
4262
|
return chain;
|
|
4176
|
-
}
|
|
4263
|
+
}
|
|
4264
|
+
function transform(node, fn) {
|
|
4177
4265
|
var transform = new UglifyJS.TreeTransformer(fn);
|
|
4178
4266
|
node.transform(transform);
|
|
4179
|
-
}
|
|
4267
|
+
}
|
|
4268
|
+
;
|
|
4180
4269
|
exports.AstUtil = {
|
|
4181
4270
|
findNode: findNode,
|
|
4182
4271
|
each: each,
|
|
@@ -4451,6 +4540,13 @@ const Include_1 = _src_class_Include;
|
|
|
4451
4540
|
const BaseParser_1 = _src_handlers_base_BaseParser;
|
|
4452
4541
|
const atma_utils_1 = require("atma-utils");
|
|
4453
4542
|
class CommonJsParser extends BaseParser_1.BaseParser {
|
|
4543
|
+
async transpile(content, resource) {
|
|
4544
|
+
if (/\.(yml|json)([^\w]|$)/.test(resource.filename)) {
|
|
4545
|
+
let str = typeof content !== 'string' ? JSON.stringify(content, null, ' ') : content;
|
|
4546
|
+
str = `module.exports = ${str};`;
|
|
4547
|
+
return { content: str };
|
|
4548
|
+
}
|
|
4549
|
+
}
|
|
4454
4550
|
getDependencies(ast, ownerResource) {
|
|
4455
4551
|
let info = {
|
|
4456
4552
|
dependencies: []
|
|
@@ -5575,8 +5671,18 @@ const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
|
|
|
5575
5671
|
class AmdJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
|
|
5576
5672
|
buildRoot(resource, dependencies) {
|
|
5577
5673
|
}
|
|
5578
|
-
|
|
5579
|
-
return
|
|
5674
|
+
wrapModule(resource, outputItem) {
|
|
5675
|
+
return resource.content;
|
|
5676
|
+
}
|
|
5677
|
+
accepts(resource) {
|
|
5678
|
+
if (resource.type !== 'js') {
|
|
5679
|
+
return false;
|
|
5680
|
+
}
|
|
5681
|
+
let module = resource.getModule();
|
|
5682
|
+
if (module === 'root' && resource.solution.opts.package.module === 'amd') {
|
|
5683
|
+
module = 'amd';
|
|
5684
|
+
}
|
|
5685
|
+
return module === 'amd';
|
|
5580
5686
|
}
|
|
5581
5687
|
}
|
|
5582
5688
|
exports.AmdJsBuilder = AmdJsBuilder;
|
|
@@ -5661,12 +5767,12 @@ class ResourcePropMapping {
|
|
|
5661
5767
|
this.resB = resB;
|
|
5662
5768
|
}
|
|
5663
5769
|
map(resource) {
|
|
5664
|
-
|
|
5665
|
-
for (
|
|
5666
|
-
|
|
5770
|
+
let match = true;
|
|
5771
|
+
for (let key in this.resA) {
|
|
5772
|
+
let val = this.resA[key];
|
|
5667
5773
|
if (val == null)
|
|
5668
5774
|
continue;
|
|
5669
|
-
|
|
5775
|
+
let currentVal = resource[key];
|
|
5670
5776
|
if (typeof val === 'function') {
|
|
5671
5777
|
match = val(currentVal);
|
|
5672
5778
|
}
|
|
@@ -5676,13 +5782,14 @@ class ResourcePropMapping {
|
|
|
5676
5782
|
if (typeof val === 'string' || typeof val === 'number') {
|
|
5677
5783
|
match = val === currentVal;
|
|
5678
5784
|
}
|
|
5679
|
-
if (match == false)
|
|
5785
|
+
if (match == false) {
|
|
5680
5786
|
return resource;
|
|
5787
|
+
}
|
|
5681
5788
|
}
|
|
5682
|
-
|
|
5683
|
-
for (
|
|
5684
|
-
|
|
5685
|
-
|
|
5789
|
+
let clone = resource.clone();
|
|
5790
|
+
for (let key in this.resB) {
|
|
5791
|
+
let val = this.resB[key];
|
|
5792
|
+
let currentVal = resource[key];
|
|
5686
5793
|
if (typeof val === 'function') {
|
|
5687
5794
|
clone[key] = val(currentVal, resource);
|
|
5688
5795
|
continue;
|
|
@@ -5740,7 +5847,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5740
5847
|
}
|
|
5741
5848
|
}
|
|
5742
5849
|
getDependencies(ast, ownerResource) {
|
|
5743
|
-
|
|
5850
|
+
let info = {
|
|
5744
5851
|
type: null,
|
|
5745
5852
|
url: null,
|
|
5746
5853
|
dependencies: [],
|
|
@@ -5757,7 +5864,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5757
5864
|
function isIncludeSymbolRef(node) {
|
|
5758
5865
|
return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name == 'include';
|
|
5759
5866
|
}
|
|
5760
|
-
|
|
5867
|
+
let scope = AstUtil_1.AstUtil.findNode(node, isIncludeSymbolRef).scope || ast;
|
|
5761
5868
|
this._process(info, node, scope);
|
|
5762
5869
|
return true;
|
|
5763
5870
|
});
|
|
@@ -5767,7 +5874,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5767
5874
|
return new atma_utils_1.class_Dfr().resolve(info);
|
|
5768
5875
|
}
|
|
5769
5876
|
_process(info, node, scope) {
|
|
5770
|
-
|
|
5877
|
+
let arr = [];
|
|
5771
5878
|
function isIncludeMethodCall(node) {
|
|
5772
5879
|
return AstUtil_1.AstUtil.is.type(node, 'AST_Call') && node.start.value == 'include';
|
|
5773
5880
|
}
|
|
@@ -5782,7 +5889,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5782
5889
|
case 'routes':
|
|
5783
5890
|
case 'setBase':
|
|
5784
5891
|
case 'cfg':
|
|
5785
|
-
|
|
5892
|
+
let pckg = {
|
|
5786
5893
|
type: node.expression.property,
|
|
5787
5894
|
args: AstUtil_1.AstUtil.getArguments(node.args, scope),
|
|
5788
5895
|
};
|
|
@@ -5814,7 +5921,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5814
5921
|
break;
|
|
5815
5922
|
}
|
|
5816
5923
|
});
|
|
5817
|
-
|
|
5924
|
+
let include = new Include_1.Include();
|
|
5818
5925
|
arr.forEach(function (x) {
|
|
5819
5926
|
include[x.type].apply(include, x.args);
|
|
5820
5927
|
});
|
|
@@ -5824,28 +5931,28 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5824
5931
|
if (AstUtil_1.AstUtil.is.type(CallbackNode, 'AST_Function') == false) {
|
|
5825
5932
|
return;
|
|
5826
5933
|
}
|
|
5827
|
-
|
|
5934
|
+
let meta = info.meta.includejs, args = CallbackNode.argnames, responseObjectName = args.length > 0
|
|
5828
5935
|
? args[args.length - 1].name
|
|
5829
5936
|
: null;
|
|
5830
5937
|
if (responseObjectName) {
|
|
5831
5938
|
meta.hasResponseObject = true;
|
|
5832
|
-
|
|
5939
|
+
let names = this._getPropertyAccessors(responseObjectName, CallbackNode);
|
|
5833
5940
|
if (names) {
|
|
5834
5941
|
meta.responseAccessors = (meta.responseAccessors || []).concat(names);
|
|
5835
5942
|
}
|
|
5836
5943
|
}
|
|
5837
5944
|
}
|
|
5838
5945
|
/**
|
|
5839
|
-
*
|
|
5946
|
+
* resolve %name%.propertyAccessor
|
|
5840
5947
|
*/
|
|
5841
5948
|
_getPropertyAccessors(name, Fn) {
|
|
5842
|
-
|
|
5949
|
+
let references = [];
|
|
5843
5950
|
Fn.body.forEach(function (x) {
|
|
5844
5951
|
function isSymbolName(node) {
|
|
5845
5952
|
return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name === name;
|
|
5846
5953
|
}
|
|
5847
5954
|
AstUtil_1.AstUtil.each(x, isSymbolName, function (node) {
|
|
5848
|
-
|
|
5955
|
+
let chain = AstUtil_1.AstUtil.getPropertyChain(node, this.stack);
|
|
5849
5956
|
if (chain) {
|
|
5850
5957
|
references.push(chain);
|
|
5851
5958
|
}
|
|
@@ -5854,16 +5961,16 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5854
5961
|
return references;
|
|
5855
5962
|
}
|
|
5856
5963
|
/**
|
|
5857
|
-
*
|
|
5964
|
+
* aim to find all **.exports = X
|
|
5858
5965
|
*/
|
|
5859
5966
|
_getPropertySetter(name, Fn) {
|
|
5860
|
-
|
|
5967
|
+
let result = null;
|
|
5861
5968
|
Fn.body.forEach(function (x) {
|
|
5862
5969
|
function isPropertyName(node) {
|
|
5863
5970
|
AstUtil_1.AstUtil.is.type(node, 'AST_Assign') && node.left.property === name;
|
|
5864
5971
|
}
|
|
5865
5972
|
AstUtil_1.AstUtil.each(x, isPropertyName, function (node) {
|
|
5866
|
-
|
|
5973
|
+
let arr = ['include', 'module', 'exports'];
|
|
5867
5974
|
if (arr.indexOf(node.start.value) > -1) {
|
|
5868
5975
|
result = node;
|
|
5869
5976
|
}
|
|
@@ -5874,12 +5981,12 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
|
|
|
5874
5981
|
}
|
|
5875
5982
|
exports.IncludeJsParser = IncludeJsParser;
|
|
5876
5983
|
;
|
|
5877
|
-
|
|
5984
|
+
let IncludeJsMappings = [
|
|
5878
5985
|
new ResourcePropMapping_1.ResourcePropMapping({
|
|
5879
5986
|
asModules: (arr) => arr.indexOf('mask') > -1
|
|
5880
5987
|
}, {
|
|
5881
5988
|
asModules: (arr) => {
|
|
5882
|
-
|
|
5989
|
+
let i = arr.indexOf('mask');
|
|
5883
5990
|
arr[i] = 'includejs';
|
|
5884
5991
|
return arr;
|
|
5885
5992
|
}
|
|
@@ -5888,7 +5995,7 @@ var IncludeJsMappings = [
|
|
|
5888
5995
|
asModules: (arr) => arr.indexOf('amd') > -1
|
|
5889
5996
|
}, {
|
|
5890
5997
|
asModules: (arr) => {
|
|
5891
|
-
|
|
5998
|
+
let i = arr.indexOf('amd');
|
|
5892
5999
|
arr[i] = 'includejs';
|
|
5893
6000
|
return arr;
|
|
5894
6001
|
}
|
|
@@ -6908,6 +7015,16 @@ class ImportJsParser extends BaseParser_1.BaseParser {
|
|
|
6908
7015
|
/** @TODO: set to false and handle ast in ScriptParser */
|
|
6909
7016
|
this.asText = true;
|
|
6910
7017
|
}
|
|
7018
|
+
async transpile(content, resource) {
|
|
7019
|
+
if (/\.(yml|json)([^\w]|$)/.test(resource.filename)) {
|
|
7020
|
+
let str = typeof content !== 'string' ? JSON.stringify(content, null, ' ') : content;
|
|
7021
|
+
str = [
|
|
7022
|
+
`const data = ${str};`,
|
|
7023
|
+
`export default data;`
|
|
7024
|
+
].join('\n');
|
|
7025
|
+
return { content: str };
|
|
7026
|
+
}
|
|
7027
|
+
}
|
|
6911
7028
|
getDependencies(content, ownerResource) {
|
|
6912
7029
|
if (Parser_1.Parser.supports(content) === false) {
|
|
6913
7030
|
return null;
|
|
@@ -7559,6 +7676,10 @@ class ScriptParser extends BaseParser_1.BaseParser {
|
|
|
7559
7676
|
new ImportJsHandler_1.ImportJsHandler.Parser(this.solution, this.handler),
|
|
7560
7677
|
];
|
|
7561
7678
|
}
|
|
7679
|
+
transpile(content, resource) {
|
|
7680
|
+
let [common] = this.parsers;
|
|
7681
|
+
return common.transpile(content, resource);
|
|
7682
|
+
}
|
|
7562
7683
|
getDependencies(content, ownerResource) {
|
|
7563
7684
|
if (!content) {
|
|
7564
7685
|
throw new Error(`Content is undefined for ${ownerResource.filename}`);
|
|
@@ -7592,7 +7713,8 @@ class ScriptParser extends BaseParser_1.BaseParser {
|
|
|
7592
7713
|
dfrs.unshift(...asTextDfrs);
|
|
7593
7714
|
return (0, async_1.async_whenAll)(dfrs).then(results => {
|
|
7594
7715
|
let arr = (0, arr_1.arr_flattern)(results);
|
|
7595
|
-
|
|
7716
|
+
let merged = ResourceInfo_1.ResourceInfo.merge(...arr);
|
|
7717
|
+
return merged;
|
|
7596
7718
|
});
|
|
7597
7719
|
}
|
|
7598
7720
|
accepts(type) {
|
|
@@ -8090,6 +8212,297 @@ MaskJsHandler.PathResolver = null;
|
|
|
8090
8212
|
// end:source ./ModuleSimplified.js
|
|
8091
8213
|
|
|
8092
8214
|
|
|
8215
|
+
// source ./ModuleSimplified.js
|
|
8216
|
+
var _src_handlers_script_copy_js_CopyJsParser;
|
|
8217
|
+
(function () {
|
|
8218
|
+
// ensure AMD is not active for the model, so that any UMD exports as commonjs
|
|
8219
|
+
var define = null;
|
|
8220
|
+
var exports = _src_handlers_script_copy_js_CopyJsParser != null ? _src_handlers_script_copy_js_CopyJsParser : {};
|
|
8221
|
+
var module = { exports: exports };
|
|
8222
|
+
|
|
8223
|
+
"use strict";
|
|
8224
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8225
|
+
exports.CopyJsParser = void 0;
|
|
8226
|
+
const BaseParser_1 = _src_handlers_base_BaseParser;
|
|
8227
|
+
class CopyJsParser extends BaseParser_1.BaseParser {
|
|
8228
|
+
getDependencies(ast, ownerResource) {
|
|
8229
|
+
return null;
|
|
8230
|
+
}
|
|
8231
|
+
}
|
|
8232
|
+
exports.CopyJsParser = CopyJsParser;
|
|
8233
|
+
;
|
|
8234
|
+
//# sourceMappingURL=CopyJsParser.js.map
|
|
8235
|
+
//# sourceMappingURL=CopyJsParser.ts.map;
|
|
8236
|
+
|
|
8237
|
+
function __isObj(x) {
|
|
8238
|
+
return x != null && typeof x === 'object' && x.constructor === Object;
|
|
8239
|
+
}
|
|
8240
|
+
if (_src_handlers_script_copy_js_CopyJsParser === module.exports) {
|
|
8241
|
+
// do nothing if
|
|
8242
|
+
} else if (__isObj(_src_handlers_script_copy_js_CopyJsParser) && __isObj(module.exports)) {
|
|
8243
|
+
Object.assign(_src_handlers_script_copy_js_CopyJsParser, module.exports);
|
|
8244
|
+
} else {
|
|
8245
|
+
_src_handlers_script_copy_js_CopyJsParser = module.exports;
|
|
8246
|
+
}
|
|
8247
|
+
|
|
8248
|
+
;
|
|
8249
|
+
}());
|
|
8250
|
+
|
|
8251
|
+
// end:source ./ModuleSimplified.js
|
|
8252
|
+
|
|
8253
|
+
|
|
8254
|
+
// source ./ModuleSimplified.js
|
|
8255
|
+
var _src_handlers_script_copy_js_CopyJsRewriter;
|
|
8256
|
+
(function () {
|
|
8257
|
+
// ensure AMD is not active for the model, so that any UMD exports as commonjs
|
|
8258
|
+
var define = null;
|
|
8259
|
+
var exports = _src_handlers_script_copy_js_CopyJsRewriter != null ? _src_handlers_script_copy_js_CopyJsRewriter : {};
|
|
8260
|
+
var module = { exports: exports };
|
|
8261
|
+
|
|
8262
|
+
"use strict";
|
|
8263
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8264
|
+
exports.CopyJsRewriter = void 0;
|
|
8265
|
+
const BaseRewriter_1 = _src_handlers_base_BaseRewriter;
|
|
8266
|
+
class CopyJsRewriter extends BaseRewriter_1.BaseRewriter {
|
|
8267
|
+
rewritePartial(content, ownerResource) {
|
|
8268
|
+
}
|
|
8269
|
+
rewriteResource(resource) {
|
|
8270
|
+
}
|
|
8271
|
+
accepts(type) {
|
|
8272
|
+
return type === 'mask';
|
|
8273
|
+
}
|
|
8274
|
+
}
|
|
8275
|
+
exports.CopyJsRewriter = CopyJsRewriter;
|
|
8276
|
+
;
|
|
8277
|
+
//# sourceMappingURL=CopyJsRewriter.js.map
|
|
8278
|
+
//# sourceMappingURL=CopyJsRewriter.ts.map;
|
|
8279
|
+
|
|
8280
|
+
function __isObj(x) {
|
|
8281
|
+
return x != null && typeof x === 'object' && x.constructor === Object;
|
|
8282
|
+
}
|
|
8283
|
+
if (_src_handlers_script_copy_js_CopyJsRewriter === module.exports) {
|
|
8284
|
+
// do nothing if
|
|
8285
|
+
} else if (__isObj(_src_handlers_script_copy_js_CopyJsRewriter) && __isObj(module.exports)) {
|
|
8286
|
+
Object.assign(_src_handlers_script_copy_js_CopyJsRewriter, module.exports);
|
|
8287
|
+
} else {
|
|
8288
|
+
_src_handlers_script_copy_js_CopyJsRewriter = module.exports;
|
|
8289
|
+
}
|
|
8290
|
+
|
|
8291
|
+
;
|
|
8292
|
+
}());
|
|
8293
|
+
|
|
8294
|
+
// end:source ./ModuleSimplified.js
|
|
8295
|
+
|
|
8296
|
+
|
|
8297
|
+
// source ./ModuleSimplified.js
|
|
8298
|
+
var _src_handlers_script_copy_js_CopyJsBuilder;
|
|
8299
|
+
(function () {
|
|
8300
|
+
// ensure AMD is not active for the model, so that any UMD exports as commonjs
|
|
8301
|
+
var define = null;
|
|
8302
|
+
var exports = _src_handlers_script_copy_js_CopyJsBuilder != null ? _src_handlers_script_copy_js_CopyJsBuilder : {};
|
|
8303
|
+
var module = { exports: exports };
|
|
8304
|
+
|
|
8305
|
+
"use strict";
|
|
8306
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8307
|
+
exports.CopyJsBuilder = void 0;
|
|
8308
|
+
const alot_1 = require("alot");
|
|
8309
|
+
const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
|
|
8310
|
+
const OutputResources_1 = _src_class_OutputResources;
|
|
8311
|
+
const atma_utils_1 = require("atma-utils");
|
|
8312
|
+
const path_1 = _src_utils_path;
|
|
8313
|
+
const Configuration_1 = _src_config_Configuration;
|
|
8314
|
+
/**
|
|
8315
|
+
* Primary purpose of this builder is to copy source files to the output folder.
|
|
8316
|
+
* Atma IO middlewares are used to compile/transpile the files.
|
|
8317
|
+
*
|
|
8318
|
+
* For now the accent is made for Typescript files.
|
|
8319
|
+
*/
|
|
8320
|
+
class CopyJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
|
|
8321
|
+
wrapModule(resource, outputItem) {
|
|
8322
|
+
let { content, dependencies } = resource;
|
|
8323
|
+
let offset = 0;
|
|
8324
|
+
dependencies && dependencies.filter(x => x.pos != null && (0, path_1.path_isRelative)(x.url)).forEach(dep => {
|
|
8325
|
+
let resUrl = new atma_utils_1.class_Uri(resource.url);
|
|
8326
|
+
let resDep = new atma_utils_1.class_Uri(dep.url);
|
|
8327
|
+
let url = resUrl.combine(resDep).toLocalFile();
|
|
8328
|
+
let start = dep.pos + offset + 1;
|
|
8329
|
+
let c = content[start - 1];
|
|
8330
|
+
let end = content.indexOf(c, start);
|
|
8331
|
+
let oldLength = end - start;
|
|
8332
|
+
let newLength = url.length;
|
|
8333
|
+
content = content.substring(0, start) + url + content.substring(end);
|
|
8334
|
+
offset += newLength - oldLength;
|
|
8335
|
+
});
|
|
8336
|
+
return content;
|
|
8337
|
+
}
|
|
8338
|
+
async buildRoot(root, outputDependencies) {
|
|
8339
|
+
let outputResources = this.solution.outputResources;
|
|
8340
|
+
outputResources.items = await (0, alot_1.default)(outputResources.items)
|
|
8341
|
+
.mapManyAsync(async (item) => {
|
|
8342
|
+
if (item.resource.isGlob !== true) {
|
|
8343
|
+
return [item];
|
|
8344
|
+
}
|
|
8345
|
+
// Normal output
|
|
8346
|
+
let copyItems = await (0, alot_1.default)(item.resources)
|
|
8347
|
+
.mapMany(resource => {
|
|
8348
|
+
return this.createOutputItems(item, resource);
|
|
8349
|
+
})
|
|
8350
|
+
.toArrayAsync();
|
|
8351
|
+
return copyItems;
|
|
8352
|
+
}).toArrayAsync();
|
|
8353
|
+
}
|
|
8354
|
+
getRootContent(root, outputDependencies) {
|
|
8355
|
+
return root.content;
|
|
8356
|
+
}
|
|
8357
|
+
accepts(resource) {
|
|
8358
|
+
if (resource.type !== 'js') {
|
|
8359
|
+
return false;
|
|
8360
|
+
}
|
|
8361
|
+
return resource.isGlob === true;
|
|
8362
|
+
}
|
|
8363
|
+
async createOutputItems(parent, resource) {
|
|
8364
|
+
var _a;
|
|
8365
|
+
let solution = this.solution;
|
|
8366
|
+
let rewriteToRelativeUrls = {};
|
|
8367
|
+
if (((_a = resource.dependencies) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
8368
|
+
let appBase = this.solution.opts.base;
|
|
8369
|
+
(0, alot_1.default)(resource.dependencies)
|
|
8370
|
+
.forEach(dep => {
|
|
8371
|
+
if (dep.resource == null) {
|
|
8372
|
+
return;
|
|
8373
|
+
}
|
|
8374
|
+
if (dep.resource.filename.startsWith(appBase) === false) {
|
|
8375
|
+
// is project dependency
|
|
8376
|
+
return;
|
|
8377
|
+
}
|
|
8378
|
+
let relativePath = (0, path_1.path_toRelative)(dep.resource.filename, resource.filename);
|
|
8379
|
+
if (relativePath == null || /(..\/)*?\/?node_modules/.test(relativePath)) {
|
|
8380
|
+
return;
|
|
8381
|
+
}
|
|
8382
|
+
relativePath = (0, path_1.path_changeExtension)(relativePath, null);
|
|
8383
|
+
relativePath = relativePath.startsWith('.')
|
|
8384
|
+
? relativePath
|
|
8385
|
+
: './' + relativePath;
|
|
8386
|
+
rewriteToRelativeUrls[dep.url] = relativePath;
|
|
8387
|
+
})
|
|
8388
|
+
.toArray();
|
|
8389
|
+
resource.content = rewriteUrls(resource.content, rewriteToRelativeUrls);
|
|
8390
|
+
}
|
|
8391
|
+
let result = [
|
|
8392
|
+
createOutputItem(cloneWithExtension(resource, 'js'))
|
|
8393
|
+
];
|
|
8394
|
+
let extra = [{
|
|
8395
|
+
ext: 'ts.map',
|
|
8396
|
+
output: 'js.map',
|
|
8397
|
+
}, {
|
|
8398
|
+
ext: 'd.ts',
|
|
8399
|
+
output: 'd.ts',
|
|
8400
|
+
}];
|
|
8401
|
+
let readFile = Configuration_1.Configuration.Instance.get('readFile');
|
|
8402
|
+
await (0, alot_1.default)(extra).forEachAsync(async (x) => {
|
|
8403
|
+
let cloned = cloneWithExtension(resource, x.ext);
|
|
8404
|
+
cloned.content = await readFile(cloned.filename);
|
|
8405
|
+
cloned.content = rewriteUrls(cloned.content, rewriteToRelativeUrls);
|
|
8406
|
+
result.push(createOutputItem(cloneWithExtension(cloned, x.output)));
|
|
8407
|
+
if (x.ext === 'ts.map' && cloned.content != null) {
|
|
8408
|
+
let outputItem = result[result.length - 1];
|
|
8409
|
+
let source = resource.filename;
|
|
8410
|
+
let target = outputItem.resource.filename;
|
|
8411
|
+
let rel = (0, path_1.path_toRelative)(source, target);
|
|
8412
|
+
outputItem.resource.content = outputItem.resource.content.replace(/"sources":\["[^"]+"\]/, `"sources":["${rel}"]`);
|
|
8413
|
+
}
|
|
8414
|
+
}).toArrayAsync({ threads: 1 });
|
|
8415
|
+
function createOutputItem(resource) {
|
|
8416
|
+
return new OutputResources_1.OutputItem({
|
|
8417
|
+
page: parent.page,
|
|
8418
|
+
bundle: parent.bundle,
|
|
8419
|
+
type: parent.type,
|
|
8420
|
+
solution: solution,
|
|
8421
|
+
resources: [resource],
|
|
8422
|
+
isGlob: false,
|
|
8423
|
+
resource: resource.toTarget(solution)
|
|
8424
|
+
});
|
|
8425
|
+
}
|
|
8426
|
+
function cloneWithExtension(resource, ext) {
|
|
8427
|
+
let cloned = resource.clone();
|
|
8428
|
+
cloned.filename = (0, path_1.path_changeExtension)(cloned.filename, ext);
|
|
8429
|
+
cloned.url = (0, path_1.path_changeExtension)(cloned.url, ext);
|
|
8430
|
+
return cloned;
|
|
8431
|
+
}
|
|
8432
|
+
function rewriteUrls(content, rewriteToRelativeUrls) {
|
|
8433
|
+
for (let key in rewriteToRelativeUrls) {
|
|
8434
|
+
content = content.replaceAll(key, rewriteToRelativeUrls[key]);
|
|
8435
|
+
}
|
|
8436
|
+
return content;
|
|
8437
|
+
}
|
|
8438
|
+
return result;
|
|
8439
|
+
}
|
|
8440
|
+
}
|
|
8441
|
+
exports.CopyJsBuilder = CopyJsBuilder;
|
|
8442
|
+
;
|
|
8443
|
+
//# sourceMappingURL=CopyJsBuilder.js.map
|
|
8444
|
+
//# sourceMappingURL=CopyJsBuilder.ts.map;
|
|
8445
|
+
|
|
8446
|
+
function __isObj(x) {
|
|
8447
|
+
return x != null && typeof x === 'object' && x.constructor === Object;
|
|
8448
|
+
}
|
|
8449
|
+
if (_src_handlers_script_copy_js_CopyJsBuilder === module.exports) {
|
|
8450
|
+
// do nothing if
|
|
8451
|
+
} else if (__isObj(_src_handlers_script_copy_js_CopyJsBuilder) && __isObj(module.exports)) {
|
|
8452
|
+
Object.assign(_src_handlers_script_copy_js_CopyJsBuilder, module.exports);
|
|
8453
|
+
} else {
|
|
8454
|
+
_src_handlers_script_copy_js_CopyJsBuilder = module.exports;
|
|
8455
|
+
}
|
|
8456
|
+
|
|
8457
|
+
;
|
|
8458
|
+
}());
|
|
8459
|
+
|
|
8460
|
+
// end:source ./ModuleSimplified.js
|
|
8461
|
+
|
|
8462
|
+
|
|
8463
|
+
// source ./ModuleSimplified.js
|
|
8464
|
+
var _src_handlers_script_copy_js_CopyJsHandler;
|
|
8465
|
+
(function () {
|
|
8466
|
+
// ensure AMD is not active for the model, so that any UMD exports as commonjs
|
|
8467
|
+
var define = null;
|
|
8468
|
+
var exports = _src_handlers_script_copy_js_CopyJsHandler != null ? _src_handlers_script_copy_js_CopyJsHandler : {};
|
|
8469
|
+
var module = { exports: exports };
|
|
8470
|
+
|
|
8471
|
+
"use strict";
|
|
8472
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8473
|
+
exports.CopyJsHandler = void 0;
|
|
8474
|
+
const BaseHandler_1 = _src_handlers_base_BaseHandler;
|
|
8475
|
+
const CopyJsParser_1 = _src_handlers_script_copy_js_CopyJsParser;
|
|
8476
|
+
const CopyJsRewriter_1 = _src_handlers_script_copy_js_CopyJsRewriter;
|
|
8477
|
+
const CopyJsBuilder_1 = _src_handlers_script_copy_js_CopyJsBuilder;
|
|
8478
|
+
class CopyJsHandler extends BaseHandler_1.BaseHandler {
|
|
8479
|
+
}
|
|
8480
|
+
exports.CopyJsHandler = CopyJsHandler;
|
|
8481
|
+
CopyJsHandler.Parser = CopyJsParser_1.CopyJsParser;
|
|
8482
|
+
CopyJsHandler.Rewriter = CopyJsRewriter_1.CopyJsRewriter;
|
|
8483
|
+
CopyJsHandler.Builder = CopyJsBuilder_1.CopyJsBuilder;
|
|
8484
|
+
CopyJsHandler.PathResolver = null;
|
|
8485
|
+
;
|
|
8486
|
+
//# sourceMappingURL=CopyJsHandler.js.map
|
|
8487
|
+
//# sourceMappingURL=CopyJsHandler.ts.map;
|
|
8488
|
+
|
|
8489
|
+
function __isObj(x) {
|
|
8490
|
+
return x != null && typeof x === 'object' && x.constructor === Object;
|
|
8491
|
+
}
|
|
8492
|
+
if (_src_handlers_script_copy_js_CopyJsHandler === module.exports) {
|
|
8493
|
+
// do nothing if
|
|
8494
|
+
} else if (__isObj(_src_handlers_script_copy_js_CopyJsHandler) && __isObj(module.exports)) {
|
|
8495
|
+
Object.assign(_src_handlers_script_copy_js_CopyJsHandler, module.exports);
|
|
8496
|
+
} else {
|
|
8497
|
+
_src_handlers_script_copy_js_CopyJsHandler = module.exports;
|
|
8498
|
+
}
|
|
8499
|
+
|
|
8500
|
+
;
|
|
8501
|
+
}());
|
|
8502
|
+
|
|
8503
|
+
// end:source ./ModuleSimplified.js
|
|
8504
|
+
|
|
8505
|
+
|
|
8093
8506
|
// source ./ModuleSimplified.js
|
|
8094
8507
|
var _src_handlers_script_ScriptBuilder;
|
|
8095
8508
|
(function () {
|
|
@@ -8108,10 +8521,12 @@ const AmdJsHandler_1 = _src_handlers_script_amd_js_AmdJsHandler;
|
|
|
8108
8521
|
const IncludeJsHandler_1 = _src_handlers_script_include_js_IncludeJsHandler;
|
|
8109
8522
|
const MaskJsHandler_1 = _src_handlers_script_mask_js_MaskJsHandler;
|
|
8110
8523
|
const ImportJsHandler_1 = _src_handlers_script_import_js_ImportJsHandler;
|
|
8524
|
+
const CopyJsHandler_1 = _src_handlers_script_copy_js_CopyJsHandler;
|
|
8111
8525
|
class ScriptBuilder extends BaseBuilder_1.BaseBuilder {
|
|
8112
8526
|
constructor() {
|
|
8113
8527
|
super(...arguments);
|
|
8114
8528
|
this.builders = [
|
|
8529
|
+
new CopyJsHandler_1.CopyJsHandler.Builder(this.solution, this.handler),
|
|
8115
8530
|
new GlobalJsHandler_1.GlobalJsHandler.Builder(this.solution, this.handler),
|
|
8116
8531
|
new CommonJsHandler_1.CommonJsHandler.Builder(this.solution, this.handler),
|
|
8117
8532
|
new AmdJsHandler_1.AmdJsHandler.Builder(this.solution, this.handler),
|
|
@@ -8132,8 +8547,9 @@ class ScriptBuilder extends BaseBuilder_1.BaseBuilder {
|
|
|
8132
8547
|
else {
|
|
8133
8548
|
const out = resArr.map(res => {
|
|
8134
8549
|
let builder = this.builders.find(x => x.accepts(res));
|
|
8135
|
-
if (builder == null)
|
|
8550
|
+
if (builder == null) {
|
|
8136
8551
|
throw new Error('Module Builder not found for ' + res.url);
|
|
8552
|
+
}
|
|
8137
8553
|
return builder.wrapModule(res, outputItem, otherOutputItems);
|
|
8138
8554
|
});
|
|
8139
8555
|
code = out.join('\n');
|
|
@@ -10937,26 +11353,37 @@ exports.Parser = {
|
|
|
10937
11353
|
getDependencies(resource, solution) {
|
|
10938
11354
|
assert(resource != null, 'Resource is empty');
|
|
10939
11355
|
assert(solution instanceof Solution_1.Solution, 'Solution is not passed');
|
|
10940
|
-
|
|
11356
|
+
let dfr = new atma_utils_1.class_Dfr;
|
|
10941
11357
|
getDependenciesInternal(resource, solution)
|
|
10942
|
-
.
|
|
10943
|
-
.fail(error => dfr.reject(error));
|
|
11358
|
+
.then(_runMiddlewares, error => dfr.reject(error));
|
|
10944
11359
|
function _runMiddlewares(deps) {
|
|
10945
11360
|
getDependenciesExternal(deps, resource, solution)
|
|
10946
11361
|
.then((deps) => mapDeps(deps, solution))
|
|
10947
11362
|
.then((deps) => filterDynamicDeps(deps, solution))
|
|
10948
|
-
.
|
|
10949
|
-
.fail(error => dfr.reject(error));
|
|
11363
|
+
.then(deps => dfr.resolve(deps), error => dfr.reject(error));
|
|
10950
11364
|
}
|
|
10951
11365
|
return dfr;
|
|
10952
11366
|
}
|
|
10953
11367
|
};
|
|
10954
11368
|
function getDependenciesInternal(resource, solution) {
|
|
10955
11369
|
assert(typeof resource.url === 'string', 'Path is expected');
|
|
10956
|
-
|
|
10957
|
-
|
|
11370
|
+
if (resource.isGlob) {
|
|
11371
|
+
let paths = resource.content;
|
|
11372
|
+
let resInfos = paths.map(path => {
|
|
11373
|
+
return {
|
|
11374
|
+
type: resource.type,
|
|
11375
|
+
url: path,
|
|
11376
|
+
module: resource.module,
|
|
11377
|
+
page: resource.page
|
|
11378
|
+
};
|
|
11379
|
+
});
|
|
11380
|
+
let result = { dependencies: resInfos };
|
|
11381
|
+
return (0, async_1.async_resolve)(result);
|
|
11382
|
+
}
|
|
11383
|
+
let ext = (0, path_1.path_getExtension)(resource.url);
|
|
11384
|
+
let handler = solution.handlers.find(x => x.parser.accepts(resource.type) || x.parser.accepts(ext));
|
|
10958
11385
|
if (handler == null) {
|
|
10959
|
-
console.warn('GetDependenciesInternal: Skip
|
|
11386
|
+
console.warn('GetDependenciesInternal: Skip unknown resource type', resource.type);
|
|
10960
11387
|
return (0, async_1.async_resolve)({ dependencies: [] });
|
|
10961
11388
|
}
|
|
10962
11389
|
return handler.parser.getDependencies(resource.content, resource);
|
|
@@ -10971,7 +11398,7 @@ function filterDynamicDeps(info, solution) {
|
|
|
10971
11398
|
return info;
|
|
10972
11399
|
}
|
|
10973
11400
|
function isDynamicDependency(dep, solution) {
|
|
10974
|
-
|
|
11401
|
+
let arr = solution.opts.dynamicDependencies;
|
|
10975
11402
|
return arr.length !== 0 && arr.some(rgx => rgx.test(dep.url));
|
|
10976
11403
|
}
|
|
10977
11404
|
function mapDeps(info, solution) {
|
|
@@ -11155,7 +11582,8 @@ var ResourceLoader;
|
|
|
11155
11582
|
this.solution = solution;
|
|
11156
11583
|
this.promise = new atma_utils_1.class_Dfr;
|
|
11157
11584
|
}
|
|
11158
|
-
process() {
|
|
11585
|
+
async process() {
|
|
11586
|
+
var _a, _b;
|
|
11159
11587
|
this
|
|
11160
11588
|
.solution
|
|
11161
11589
|
.reporter
|
|
@@ -11173,25 +11601,42 @@ var ResourceLoader;
|
|
|
11173
11601
|
this.processChildren();
|
|
11174
11602
|
return;
|
|
11175
11603
|
}
|
|
11176
|
-
|
|
11177
|
-
|
|
11178
|
-
|
|
11604
|
+
try {
|
|
11605
|
+
let start = Date.now();
|
|
11606
|
+
let reader = this.resource.isGlob
|
|
11607
|
+
? Configuration_1.Configuration.Instance.get('readDirectory')
|
|
11608
|
+
: Configuration_1.Configuration.Instance.get('readFile');
|
|
11609
|
+
let content = await reader(this.resource.filename, this.opts);
|
|
11610
|
+
let handler = this.solution.handlers.find(x => x.parser.accepts(this.resource.type));
|
|
11611
|
+
if (((_a = handler === null || handler === void 0 ? void 0 : handler.parser) === null || _a === void 0 ? void 0 : _a.transpile) != null) {
|
|
11612
|
+
let result = await handler.parser.transpile(content, this.resource);
|
|
11613
|
+
content = (_b = result === null || result === void 0 ? void 0 : result.content) !== null && _b !== void 0 ? _b : content;
|
|
11614
|
+
}
|
|
11179
11615
|
let end = Date.now();
|
|
11180
|
-
this.solution.reporter.print((0, color_1.color)(` cyan<${end - start}> ms
|
|
11616
|
+
this.solution.reporter.print((0, color_1.color)(` cyan<${end - start}> ms`));
|
|
11181
11617
|
this.resource.content = content;
|
|
11618
|
+
if (this.resource.type === 'data') {
|
|
11619
|
+
this.solution.reporter.print('\n');
|
|
11620
|
+
this.promise.resolve(this);
|
|
11621
|
+
return;
|
|
11622
|
+
}
|
|
11182
11623
|
this.processChildren();
|
|
11183
|
-
}
|
|
11624
|
+
}
|
|
11625
|
+
catch (error) {
|
|
11184
11626
|
this.promise.reject(error);
|
|
11185
|
-
}
|
|
11627
|
+
}
|
|
11186
11628
|
}
|
|
11187
11629
|
processChildren() {
|
|
11188
11630
|
if (this.shouldSkipChildren()) {
|
|
11631
|
+
this.solution.reporter.print(` (skip deps)`);
|
|
11189
11632
|
this.promise.resolve(this);
|
|
11190
11633
|
return;
|
|
11191
11634
|
}
|
|
11192
11635
|
Parser_1.Parser
|
|
11193
11636
|
.getDependencies(this.resource, this.solution)
|
|
11194
11637
|
.then(result => {
|
|
11638
|
+
var _a;
|
|
11639
|
+
this.solution.reporter.print((0, color_1.color)(` cyan<${(_a = result.dependencies) === null || _a === void 0 ? void 0 : _a.length}> dep\n`));
|
|
11195
11640
|
this.loadChildren(result).catch(err => {
|
|
11196
11641
|
this.promise.reject(err);
|
|
11197
11642
|
});
|
|
@@ -11375,23 +11820,34 @@ var _src_utils_tree;
|
|
|
11375
11820
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11376
11821
|
exports.tree_async = void 0;
|
|
11377
11822
|
const res_1 = _src_utils_res;
|
|
11378
|
-
|
|
11823
|
+
const atma_utils_1 = require("atma-utils");
|
|
11824
|
+
function tree_async(workerInfo) {
|
|
11825
|
+
let start = Date.now();
|
|
11826
|
+
let dfr;
|
|
11827
|
+
try {
|
|
11828
|
+
dfr = workerInfo.action();
|
|
11829
|
+
}
|
|
11830
|
+
catch (error) {
|
|
11831
|
+
console.error(error);
|
|
11832
|
+
return atma_utils_1.class_Dfr.reject(error);
|
|
11833
|
+
}
|
|
11834
|
+
let reporter = workerInfo.reporter;
|
|
11835
|
+
dfr.then(resources => {
|
|
11836
|
+
let end = Date.now();
|
|
11837
|
+
let seconds = ((end - start) / 1000).toFixed(2);
|
|
11838
|
+
let treeInfo = (0, res_1.res_getTreeInfo)(resources);
|
|
11839
|
+
reporter
|
|
11840
|
+
.info(workerInfo.message(treeInfo, seconds));
|
|
11841
|
+
reporter
|
|
11842
|
+
.info(treeInfo.treeString);
|
|
11843
|
+
}, err => {
|
|
11844
|
+
console.error(err);
|
|
11845
|
+
throw err;
|
|
11846
|
+
});
|
|
11847
|
+
return dfr;
|
|
11848
|
+
}
|
|
11379
11849
|
exports.tree_async = tree_async;
|
|
11380
|
-
|
|
11381
|
-
exports.tree_async = tree_async = function (workerInfo) {
|
|
11382
|
-
let start = Date.now(), dfr = workerInfo.action(), reporter = workerInfo.reporter;
|
|
11383
|
-
dfr.done(resources => {
|
|
11384
|
-
let end = Date.now();
|
|
11385
|
-
let seconds = ((end - start) / 1000).toFixed(2);
|
|
11386
|
-
let treeInfo = (0, res_1.res_getTreeInfo)(resources);
|
|
11387
|
-
reporter
|
|
11388
|
-
.info(workerInfo.message(treeInfo, seconds));
|
|
11389
|
-
reporter
|
|
11390
|
-
.info(treeInfo.treeString);
|
|
11391
|
-
});
|
|
11392
|
-
return dfr;
|
|
11393
|
-
};
|
|
11394
|
-
}());
|
|
11850
|
+
;
|
|
11395
11851
|
//# sourceMappingURL=tree.js.map
|
|
11396
11852
|
//# sourceMappingURL=tree.ts.map;
|
|
11397
11853
|
|
|
@@ -11426,14 +11882,14 @@ exports.Builder = void 0;
|
|
|
11426
11882
|
const Middlewares_1 = _src_class_Middlewares;
|
|
11427
11883
|
const path_1 = _src_utils_path;
|
|
11428
11884
|
const async_1 = _src_utils_async;
|
|
11429
|
-
const
|
|
11885
|
+
const alot_1 = require("alot");
|
|
11430
11886
|
exports.Builder = {
|
|
11431
11887
|
build(resources, solution) {
|
|
11432
11888
|
return Middlewares_1._middlewares
|
|
11433
11889
|
.run('buildResources', resources, solution)
|
|
11434
11890
|
.then(arr => {
|
|
11435
|
-
resources = arr
|
|
11436
|
-
solution.outputResources.
|
|
11891
|
+
resources = arr !== null && arr !== void 0 ? arr : resources;
|
|
11892
|
+
solution.outputResources.prepare(resources);
|
|
11437
11893
|
return Middlewares_1._middlewares
|
|
11438
11894
|
.run('rewriteDependencies', resources, solution)
|
|
11439
11895
|
.then(() => rewriteDependenciesInternal(resources))
|
|
@@ -11443,9 +11899,9 @@ exports.Builder = {
|
|
|
11443
11899
|
.then(() => solution.outputResources.getAll());
|
|
11444
11900
|
});
|
|
11445
11901
|
function rewriteDependenciesInternal(resources) {
|
|
11446
|
-
|
|
11447
|
-
|
|
11448
|
-
|
|
11902
|
+
let promises = resources.map(resource => {
|
|
11903
|
+
let ext = (0, path_1.path_getExtension)(resource.url);
|
|
11904
|
+
let handler = solution.handlers.find(x => x.rewriter.accepts(ext));
|
|
11449
11905
|
if (handler == null) {
|
|
11450
11906
|
handler = solution.handlers.find(x => x.rewriter.accepts(resource.type));
|
|
11451
11907
|
}
|
|
@@ -11454,12 +11910,14 @@ exports.Builder = {
|
|
|
11454
11910
|
}
|
|
11455
11911
|
return handler.rewriter.rewriteResource(resource);
|
|
11456
11912
|
});
|
|
11457
|
-
return (0, async_1.async_whenAll)(
|
|
11913
|
+
return (0, async_1.async_whenAll)(promises);
|
|
11458
11914
|
}
|
|
11459
11915
|
function rewriteRoot() {
|
|
11460
11916
|
return (0, async_1.async_run)(() => {
|
|
11461
|
-
|
|
11462
|
-
|
|
11917
|
+
let input = solution.outputResources.rootInput;
|
|
11918
|
+
let output = solution.outputResources.rootOutput;
|
|
11919
|
+
let ext = (0, path_1.path_getExtension)(input.url);
|
|
11920
|
+
let handler = solution.handlers.find(x => x.rewriter.accepts(input.type) || x.rewriter.accepts(ext));
|
|
11463
11921
|
if (handler == null || handler.rewriter.rewriteRoot == null) {
|
|
11464
11922
|
//throw new Error(`RootRewriter is not found for a resource ${input.url} and type ${input.type}`);
|
|
11465
11923
|
return;
|
|
@@ -11468,9 +11926,9 @@ exports.Builder = {
|
|
|
11468
11926
|
});
|
|
11469
11927
|
}
|
|
11470
11928
|
function buildOutputItems() {
|
|
11471
|
-
|
|
11472
|
-
return
|
|
11473
|
-
|
|
11929
|
+
let items = solution.outputResources.items;
|
|
11930
|
+
return (0, alot_1.default)(items).mapAsync(item => {
|
|
11931
|
+
let otherOutputItems = items.filter(x => {
|
|
11474
11932
|
if (x === item)
|
|
11475
11933
|
return false;
|
|
11476
11934
|
if (x.page != item.page)
|
|
@@ -11491,8 +11949,8 @@ exports.Builder = {
|
|
|
11491
11949
|
if (outputItem.resource.content) {
|
|
11492
11950
|
return;
|
|
11493
11951
|
}
|
|
11494
|
-
|
|
11495
|
-
|
|
11952
|
+
let ext = (0, path_1.path_getExtension)(outputItem.resource.url);
|
|
11953
|
+
let handler = solution.handlers.find(x => x.builder.accepts(outputItem.type));
|
|
11496
11954
|
if (handler == null) {
|
|
11497
11955
|
handler = solution.handlers.find(x => x.builder.accepts(ext));
|
|
11498
11956
|
}
|
|
@@ -11502,10 +11960,11 @@ exports.Builder = {
|
|
|
11502
11960
|
return handler.builder.createModule(outputItem, otherOutputItems);
|
|
11503
11961
|
}
|
|
11504
11962
|
function buildRoot() {
|
|
11505
|
-
var
|
|
11506
|
-
|
|
11507
|
-
|
|
11508
|
-
|
|
11963
|
+
var _a;
|
|
11964
|
+
let main = (_a = solution.outputResources.rootOutput) !== null && _a !== void 0 ? _a : solution.outputResources.rootInput;
|
|
11965
|
+
let dependencies = solution.outputResources.getForPage(solution.opts.mainPage);
|
|
11966
|
+
let ext = (0, path_1.path_getExtension)(main.url);
|
|
11967
|
+
let handler = solution.handlers.find(x => x.builder.accepts(main.type) || x.builder.accepts(ext));
|
|
11509
11968
|
if (handler == null || handler.builder.buildRoot == null) {
|
|
11510
11969
|
throw new Error(`RootBuilder is not found for a resource ${main.url} and type ${main.type}`);
|
|
11511
11970
|
}
|
|
@@ -11559,11 +12018,6 @@ const tree_1 = _src_utils_tree;
|
|
|
11559
12018
|
const Builder_1 = _src_builder_Builder;
|
|
11560
12019
|
const color_1 = _src_utils_color;
|
|
11561
12020
|
class Bundler extends atma_utils_1.class_EventEmitter {
|
|
11562
|
-
constructor(path, opts) {
|
|
11563
|
-
super();
|
|
11564
|
-
global.__$bundler = this;
|
|
11565
|
-
this.solution = new Solution_1.Solution(path, opts);
|
|
11566
|
-
}
|
|
11567
12021
|
static clearCache() {
|
|
11568
12022
|
Loader_1.Loader.clearCache();
|
|
11569
12023
|
if (global_1.io.File.middleware) {
|
|
@@ -11579,8 +12033,15 @@ class Bundler extends atma_utils_1.class_EventEmitter {
|
|
|
11579
12033
|
static get Config() {
|
|
11580
12034
|
return Configuration_1.Configuration.Instance;
|
|
11581
12035
|
}
|
|
12036
|
+
constructor(path, opts) {
|
|
12037
|
+
super();
|
|
12038
|
+
global.__$bundler = this;
|
|
12039
|
+
this.solution = new Solution_1.Solution(path, opts);
|
|
12040
|
+
}
|
|
11582
12041
|
getResourceTree(opts) {
|
|
11583
|
-
|
|
12042
|
+
let solution = this.solution;
|
|
12043
|
+
let type = solution.opts.type;
|
|
12044
|
+
let path = solution.path;
|
|
11584
12045
|
return Loader_1.Loader
|
|
11585
12046
|
.load(type, path, opts, solution)
|
|
11586
12047
|
.then(x => x.toJSON());
|
|
@@ -11589,7 +12050,9 @@ class Bundler extends atma_utils_1.class_EventEmitter {
|
|
|
11589
12050
|
return new Bundler(path, opts).getResourceTree();
|
|
11590
12051
|
}
|
|
11591
12052
|
getResources(opts) {
|
|
11592
|
-
|
|
12053
|
+
let solution = this.solution;
|
|
12054
|
+
let type = solution.opts.type;
|
|
12055
|
+
let path = solution.path;
|
|
11593
12056
|
return Loader_1.Loader.load(type, path, opts, solution).then(resource => {
|
|
11594
12057
|
return (0, res_1.res_flattern)(resource, solution.opts.dependencies).map(x => x);
|
|
11595
12058
|
});
|
|
@@ -11598,16 +12061,28 @@ class Bundler extends atma_utils_1.class_EventEmitter {
|
|
|
11598
12061
|
return new Bundler(path, opts).getResources();
|
|
11599
12062
|
}
|
|
11600
12063
|
build(opts) {
|
|
11601
|
-
|
|
12064
|
+
let solution = this.solution;
|
|
12065
|
+
let type = solution.opts.type;
|
|
12066
|
+
let path = solution.path;
|
|
12067
|
+
let shouldRebuild = false;
|
|
12068
|
+
let isBuilding = false;
|
|
12069
|
+
let isRebuilding = false;
|
|
12070
|
+
let rootResource = null;
|
|
12071
|
+
let self = this;
|
|
11602
12072
|
function build(resource) {
|
|
11603
12073
|
isBuilding = true;
|
|
11604
|
-
|
|
12074
|
+
let resources = (0, res_1.res_flattern)(resource, solution.opts.dependencies);
|
|
11605
12075
|
return (0, tree_1.tree_async)({
|
|
11606
|
-
resources,
|
|
11607
12076
|
reporter: solution.reporter,
|
|
11608
|
-
action: () =>
|
|
11609
|
-
|
|
11610
|
-
|
|
12077
|
+
action: () => {
|
|
12078
|
+
return Builder_1.Builder.build(resources, solution);
|
|
12079
|
+
},
|
|
12080
|
+
message: (treeInfo, seconds) => {
|
|
12081
|
+
return (0, color_1.color)(`Created bold<yellow<${treeInfo.count}>> files in bold<yellow<${seconds}>> sec.`);
|
|
12082
|
+
}
|
|
12083
|
+
})
|
|
12084
|
+
.done(buildComplete)
|
|
12085
|
+
.fail(buildFailed);
|
|
11611
12086
|
}
|
|
11612
12087
|
function buildComplete(resources) {
|
|
11613
12088
|
isBuilding = false;
|
|
@@ -11667,8 +12142,8 @@ class Bundler extends atma_utils_1.class_EventEmitter {
|
|
|
11667
12142
|
return new Bundler(path, opts).build(opts);
|
|
11668
12143
|
}
|
|
11669
12144
|
static process(path, opts) {
|
|
11670
|
-
|
|
11671
|
-
|
|
12145
|
+
let bundler = new Bundler(path, opts);
|
|
12146
|
+
let solution = bundler.solution;
|
|
11672
12147
|
function builderComplete(resources) {
|
|
11673
12148
|
resources.forEach(res => {
|
|
11674
12149
|
global_1.io.File.write(res.filename, res.content);
|
|
@@ -11699,8 +12174,8 @@ class Bundler extends atma_utils_1.class_EventEmitter {
|
|
|
11699
12174
|
getDependencies(content, opts = { type: 'js' }) {
|
|
11700
12175
|
if (typeof opts === 'string')
|
|
11701
12176
|
opts = { type: opts };
|
|
11702
|
-
|
|
11703
|
-
|
|
12177
|
+
let solution = new Solution_1.Solution('', opts);
|
|
12178
|
+
let resource = new Resource_1.Resource({ type: opts.type, content: content }, null, solution);
|
|
11704
12179
|
return Parser_1.Parser.getDependencies(resource, solution);
|
|
11705
12180
|
}
|
|
11706
12181
|
};
|