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