app-bundler 0.1.17 → 0.2.2

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
  }
@@ -1408,6 +1430,8 @@ class Resource {
1408
1430
  this.inPages = null;
1409
1431
  this.isCyclic = false;
1410
1432
  this.isMapped = false;
1433
+ // when the path is like "/foo/bar/**.ts"
1434
+ this.isGlob = false;
1411
1435
  this.meta = null;
1412
1436
  this.aliases = [];
1413
1437
  if (arguments.length === 0)
@@ -1434,6 +1458,7 @@ class Resource {
1434
1458
  this.asModules = [];
1435
1459
  this.inPages = [];
1436
1460
  this.source = null;
1461
+ this.isGlob = /\*+\.\w+$/.test(includeData.url);
1437
1462
  if (includeData.bundle) {
1438
1463
  this.bundle = includeData.bundle;
1439
1464
  }
@@ -1486,7 +1511,11 @@ class Resource {
1486
1511
  }
1487
1512
  if (Include_1.Include.PathResolver.isNpm(includeData.url)) {
1488
1513
  this.aliases.push(includeData.url);
1489
- 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
+ }
1490
1519
  if (url == null) {
1491
1520
  // Fix. `resolveAppUrl` returns undefined on native nodejs modules
1492
1521
  url = includeData.url;
@@ -1544,6 +1573,8 @@ class Resource {
1544
1573
  res.source = this.source;
1545
1574
  res.isCyclic = this.isCyclic;
1546
1575
  res.aliases = this.aliases;
1576
+ res.isGlob = this.isGlob;
1577
+ res.dependencies = this.dependencies;
1547
1578
  return res;
1548
1579
  }
1549
1580
  toTarget(solution, settings) {
@@ -1556,6 +1587,7 @@ class Resource {
1556
1587
  resource.inPages = this.inPages;
1557
1588
  resource.bundle = this.bundle;
1558
1589
  resource.aliases = this.aliases;
1590
+ resource.isGlob = this.isGlob;
1559
1591
  if (solution.opts.version && ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.type) !== 'load') {
1560
1592
  resource.url += '?v=' + solution.opts.version;
1561
1593
  }
@@ -1640,7 +1672,7 @@ class Resource {
1640
1672
  if (modules.length === 1) {
1641
1673
  return modules[0];
1642
1674
  }
1643
- let arr = ['global', 'commonjs', 'amd', 'includejs', 'import'];
1675
+ let arr = ['global', 'commonjs', 'amd', 'includejs', 'import', 'esm'];
1644
1676
  let name = arr.find(name => modules.indexOf(name) !== -1);
1645
1677
  if (name == null) {
1646
1678
  name = modules[0];
@@ -2341,6 +2373,18 @@ exports.FileActions = {
2341
2373
  }
2342
2374
  return global_1.io.File.readAsync(path, opts);
2343
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
+ },
2344
2388
  writeFile(path, content, opts) {
2345
2389
  return global_1.io.File.writeAsync(path, content, opts);
2346
2390
  },
@@ -2416,7 +2460,7 @@ class Configuration {
2416
2460
  }
2417
2461
  }
2418
2462
  defineMany(options) {
2419
- for (var key in options) {
2463
+ for (let key in options) {
2420
2464
  this.define(key, options[key]);
2421
2465
  }
2422
2466
  }
@@ -2571,6 +2615,7 @@ class SolutionOpts extends SolutionOptsBase {
2571
2615
  mainPage: 'main',
2572
2616
  mainBundle: '',
2573
2617
  mainContent: null,
2618
+ ignore: null,
2574
2619
  outputBase: '',
2575
2620
  outputAppBase: '/',
2576
2621
  output: '',
@@ -2966,13 +3011,17 @@ class OutputResources {
2966
3011
  this.resources = [];
2967
3012
  this.pagesInput = {};
2968
3013
  }
2969
- prepair(resources) {
3014
+ prepare(resources) {
2970
3015
  this.resources = [];
2971
3016
  this.pagesInput = {};
2972
3017
  this.items = [];
2973
- this.rootInput = resources.pop();
2974
- this.rootOutput = this.rootInput.toTarget(this.solution);
2975
- this.rootOutput.content = this.rootInput.content;
3018
+ let root = resources.pop();
3019
+ let isGlob = root.isGlob;
3020
+ if (isGlob !== true) {
3021
+ this.rootOutput = root.toTarget(this.solution);
3022
+ this.rootOutput.content = root.content;
3023
+ }
3024
+ this.rootInput = root;
2976
3025
  this.pagesInput = (0, res_1.res_groupByPageAndBundles)(resources, this.solution.opts);
2977
3026
  Object.keys(this.pagesInput).forEach(page => {
2978
3027
  Object.keys(this.pagesInput[page]).forEach(bundle => {
@@ -2985,20 +3034,22 @@ class OutputResources {
2985
3034
  bundle,
2986
3035
  type,
2987
3036
  solution: this.solution,
2988
- resources: arr
3037
+ resources: arr,
3038
+ isGlob: isGlob,
2989
3039
  });
2990
3040
  this.items.push(item);
2991
3041
  });
2992
- if (byType['js'] == null) {
2993
- let item = new OutputItem({
2994
- page,
2995
- bundle,
2996
- type: 'js',
2997
- solution: this.solution,
2998
- resources: []
2999
- });
3000
- this.items.push(item);
3001
- }
3042
+ // @TODO: Do we need empty output item?
3043
+ // if (byType['js'] == null) {
3044
+ // let item = new OutputItem({
3045
+ // page,
3046
+ // bundle,
3047
+ // type: 'js',
3048
+ // solution: this.solution,
3049
+ // resources: []
3050
+ // });
3051
+ // this.items.push(item);
3052
+ // }
3002
3053
  });
3003
3054
  });
3004
3055
  }
@@ -3006,7 +3057,7 @@ class OutputResources {
3006
3057
  return this.items.filter(x => x.page === page).map(x => x.resource);
3007
3058
  }
3008
3059
  getAll() {
3009
- var all = this
3060
+ let all = this
3010
3061
  .items
3011
3062
  .map(x => x.resource)
3012
3063
  .filter(x => x.embed !== true)
@@ -3019,19 +3070,27 @@ class OutputResources {
3019
3070
  }
3020
3071
  exports.OutputResources = OutputResources;
3021
3072
  class OutputItem {
3022
- constructor({ page, bundle, type, solution, resources }) {
3073
+ constructor(params) {
3074
+ let { page, bundle, type, solution, resources, isGlob } = params;
3023
3075
  this.page = page;
3024
3076
  this.bundle = bundle;
3025
3077
  this.type = type;
3026
- var ext = solution.opts.getExtForType(type);
3027
- var filename = `${page}_${bundle}.${ext}`;
3028
- var resource = new Resource_1.Resource({
3029
- type: type,
3030
- url: filename,
3031
- bundle: bundle
3032
- }, null, solution);
3033
- this.resource = resource.toTarget(solution);
3034
- this.resources = resources || [];
3078
+ this.resource = params.resource;
3079
+ this.resources = resources !== null && resources !== void 0 ? resources : [];
3080
+ if (this.resource == null) {
3081
+ let ext = solution.opts.getExtForType(type);
3082
+ let sfx = '';
3083
+ if (isGlob === true) {
3084
+ sfx = '_*';
3085
+ }
3086
+ let filename = `${page}_${bundle}${sfx}.${ext}`;
3087
+ let resource = new Resource_1.Resource({
3088
+ type: type,
3089
+ url: filename,
3090
+ bundle: bundle
3091
+ }, null, solution);
3092
+ this.resource = resource.toTarget(solution);
3093
+ }
3035
3094
  }
3036
3095
  }
3037
3096
  exports.OutputItem = OutputItem;
@@ -3905,7 +3964,7 @@ class MaskParser extends BaseParser_1.BaseParser {
3905
3964
  // @NextIteration base will be handled in mask.Module.resolvePath
3906
3965
  // var base = mask.Module.cfg('base');
3907
3966
  // if (base) {
3908
- // path = path_combine(base, path);
3967
+ // path = path_combine(base, path);
3909
3968
  // }
3910
3969
  }
3911
3970
  return [this._createDependency(path, type, page)];
@@ -5611,8 +5670,18 @@ const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
5611
5670
  class AmdJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
5612
5671
  buildRoot(resource, dependencies) {
5613
5672
  }
5614
- accepts(type) {
5615
- return false;
5673
+ wrapModule(resource, outputItem) {
5674
+ return resource.content;
5675
+ }
5676
+ accepts(resource) {
5677
+ if (resource.type !== 'js') {
5678
+ return false;
5679
+ }
5680
+ let module = resource.getModule();
5681
+ if (module === 'root' && resource.solution.opts.package.module === 'amd') {
5682
+ module = 'amd';
5683
+ }
5684
+ return module === 'amd';
5616
5685
  }
5617
5686
  }
5618
5687
  exports.AmdJsBuilder = AmdJsBuilder;
@@ -5697,12 +5766,12 @@ class ResourcePropMapping {
5697
5766
  this.resB = resB;
5698
5767
  }
5699
5768
  map(resource) {
5700
- var match = true;
5701
- for (var key in this.resA) {
5702
- var val = this.resA[key];
5769
+ let match = true;
5770
+ for (let key in this.resA) {
5771
+ let val = this.resA[key];
5703
5772
  if (val == null)
5704
5773
  continue;
5705
- var currentVal = resource[key];
5774
+ let currentVal = resource[key];
5706
5775
  if (typeof val === 'function') {
5707
5776
  match = val(currentVal);
5708
5777
  }
@@ -5712,13 +5781,14 @@ class ResourcePropMapping {
5712
5781
  if (typeof val === 'string' || typeof val === 'number') {
5713
5782
  match = val === currentVal;
5714
5783
  }
5715
- if (match == false)
5784
+ if (match == false) {
5716
5785
  return resource;
5786
+ }
5717
5787
  }
5718
- var clone = resource.clone();
5719
- for (var key in this.resB) {
5720
- var val = this.resB[key];
5721
- var currentVal = resource[key];
5788
+ let clone = resource.clone();
5789
+ for (let key in this.resB) {
5790
+ let val = this.resB[key];
5791
+ let currentVal = resource[key];
5722
5792
  if (typeof val === 'function') {
5723
5793
  clone[key] = val(currentVal, resource);
5724
5794
  continue;
@@ -5776,7 +5846,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5776
5846
  }
5777
5847
  }
5778
5848
  getDependencies(ast, ownerResource) {
5779
- var info = {
5849
+ let info = {
5780
5850
  type: null,
5781
5851
  url: null,
5782
5852
  dependencies: [],
@@ -5793,7 +5863,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5793
5863
  function isIncludeSymbolRef(node) {
5794
5864
  return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name == 'include';
5795
5865
  }
5796
- var scope = AstUtil_1.AstUtil.findNode(node, isIncludeSymbolRef).scope || ast;
5866
+ let scope = AstUtil_1.AstUtil.findNode(node, isIncludeSymbolRef).scope || ast;
5797
5867
  this._process(info, node, scope);
5798
5868
  return true;
5799
5869
  });
@@ -5803,7 +5873,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5803
5873
  return new atma_utils_1.class_Dfr().resolve(info);
5804
5874
  }
5805
5875
  _process(info, node, scope) {
5806
- var arr = [];
5876
+ let arr = [];
5807
5877
  function isIncludeMethodCall(node) {
5808
5878
  return AstUtil_1.AstUtil.is.type(node, 'AST_Call') && node.start.value == 'include';
5809
5879
  }
@@ -5818,7 +5888,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5818
5888
  case 'routes':
5819
5889
  case 'setBase':
5820
5890
  case 'cfg':
5821
- var pckg = {
5891
+ let pckg = {
5822
5892
  type: node.expression.property,
5823
5893
  args: AstUtil_1.AstUtil.getArguments(node.args, scope),
5824
5894
  };
@@ -5850,7 +5920,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5850
5920
  break;
5851
5921
  }
5852
5922
  });
5853
- var include = new Include_1.Include();
5923
+ let include = new Include_1.Include();
5854
5924
  arr.forEach(function (x) {
5855
5925
  include[x.type].apply(include, x.args);
5856
5926
  });
@@ -5860,28 +5930,28 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5860
5930
  if (AstUtil_1.AstUtil.is.type(CallbackNode, 'AST_Function') == false) {
5861
5931
  return;
5862
5932
  }
5863
- var meta = info.meta.includejs, args = CallbackNode.argnames, responseObjectName = args.length > 0
5933
+ let meta = info.meta.includejs, args = CallbackNode.argnames, responseObjectName = args.length > 0
5864
5934
  ? args[args.length - 1].name
5865
5935
  : null;
5866
5936
  if (responseObjectName) {
5867
5937
  meta.hasResponseObject = true;
5868
- var names = this._getPropertyAccessors(responseObjectName, CallbackNode);
5938
+ let names = this._getPropertyAccessors(responseObjectName, CallbackNode);
5869
5939
  if (names) {
5870
5940
  meta.responseAccessors = (meta.responseAccessors || []).concat(names);
5871
5941
  }
5872
5942
  }
5873
5943
  }
5874
5944
  /**
5875
- * resolve %name%.propertyAccessor
5945
+ * resolve %name%.propertyAccessor
5876
5946
  */
5877
5947
  _getPropertyAccessors(name, Fn) {
5878
- var references = [];
5948
+ let references = [];
5879
5949
  Fn.body.forEach(function (x) {
5880
5950
  function isSymbolName(node) {
5881
5951
  return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name === name;
5882
5952
  }
5883
5953
  AstUtil_1.AstUtil.each(x, isSymbolName, function (node) {
5884
- var chain = AstUtil_1.AstUtil.getPropertyChain(node, this.stack);
5954
+ let chain = AstUtil_1.AstUtil.getPropertyChain(node, this.stack);
5885
5955
  if (chain) {
5886
5956
  references.push(chain);
5887
5957
  }
@@ -5890,16 +5960,16 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5890
5960
  return references;
5891
5961
  }
5892
5962
  /**
5893
- * aim to find all **.exports = X
5963
+ * aim to find all **.exports = X
5894
5964
  */
5895
5965
  _getPropertySetter(name, Fn) {
5896
- var result = null;
5966
+ let result = null;
5897
5967
  Fn.body.forEach(function (x) {
5898
5968
  function isPropertyName(node) {
5899
5969
  AstUtil_1.AstUtil.is.type(node, 'AST_Assign') && node.left.property === name;
5900
5970
  }
5901
5971
  AstUtil_1.AstUtil.each(x, isPropertyName, function (node) {
5902
- var arr = ['include', 'module', 'exports'];
5972
+ let arr = ['include', 'module', 'exports'];
5903
5973
  if (arr.indexOf(node.start.value) > -1) {
5904
5974
  result = node;
5905
5975
  }
@@ -5910,12 +5980,12 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5910
5980
  }
5911
5981
  exports.IncludeJsParser = IncludeJsParser;
5912
5982
  ;
5913
- var IncludeJsMappings = [
5983
+ let IncludeJsMappings = [
5914
5984
  new ResourcePropMapping_1.ResourcePropMapping({
5915
5985
  asModules: (arr) => arr.indexOf('mask') > -1
5916
5986
  }, {
5917
5987
  asModules: (arr) => {
5918
- var i = arr.indexOf('mask');
5988
+ let i = arr.indexOf('mask');
5919
5989
  arr[i] = 'includejs';
5920
5990
  return arr;
5921
5991
  }
@@ -5924,7 +5994,7 @@ var IncludeJsMappings = [
5924
5994
  asModules: (arr) => arr.indexOf('amd') > -1
5925
5995
  }, {
5926
5996
  asModules: (arr) => {
5927
- var i = arr.indexOf('amd');
5997
+ let i = arr.indexOf('amd');
5928
5998
  arr[i] = 'includejs';
5929
5999
  return arr;
5930
6000
  }
@@ -7642,7 +7712,8 @@ class ScriptParser extends BaseParser_1.BaseParser {
7642
7712
  dfrs.unshift(...asTextDfrs);
7643
7713
  return (0, async_1.async_whenAll)(dfrs).then(results => {
7644
7714
  let arr = (0, arr_1.arr_flattern)(results);
7645
- return ResourceInfo_1.ResourceInfo.merge(...arr);
7715
+ let merged = ResourceInfo_1.ResourceInfo.merge(...arr);
7716
+ return merged;
7646
7717
  });
7647
7718
  }
7648
7719
  accepts(type) {
@@ -8140,6 +8211,297 @@ MaskJsHandler.PathResolver = null;
8140
8211
  // end:source ./ModuleSimplified.js
8141
8212
 
8142
8213
 
8214
+ // source ./ModuleSimplified.js
8215
+ var _src_handlers_script_copy_js_CopyJsParser;
8216
+ (function () {
8217
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
8218
+ var define = null;
8219
+ var exports = _src_handlers_script_copy_js_CopyJsParser != null ? _src_handlers_script_copy_js_CopyJsParser : {};
8220
+ var module = { exports: exports };
8221
+
8222
+ "use strict";
8223
+ Object.defineProperty(exports, "__esModule", { value: true });
8224
+ exports.CopyJsParser = void 0;
8225
+ const BaseParser_1 = _src_handlers_base_BaseParser;
8226
+ class CopyJsParser extends BaseParser_1.BaseParser {
8227
+ getDependencies(ast, ownerResource) {
8228
+ return null;
8229
+ }
8230
+ }
8231
+ exports.CopyJsParser = CopyJsParser;
8232
+ ;
8233
+ //# sourceMappingURL=CopyJsParser.js.map
8234
+ //# sourceMappingURL=CopyJsParser.ts.map;
8235
+
8236
+ function __isObj(x) {
8237
+ return x != null && typeof x === 'object' && x.constructor === Object;
8238
+ }
8239
+ if (_src_handlers_script_copy_js_CopyJsParser === module.exports) {
8240
+ // do nothing if
8241
+ } else if (__isObj(_src_handlers_script_copy_js_CopyJsParser) && __isObj(module.exports)) {
8242
+ Object.assign(_src_handlers_script_copy_js_CopyJsParser, module.exports);
8243
+ } else {
8244
+ _src_handlers_script_copy_js_CopyJsParser = module.exports;
8245
+ }
8246
+
8247
+ ;
8248
+ }());
8249
+
8250
+ // end:source ./ModuleSimplified.js
8251
+
8252
+
8253
+ // source ./ModuleSimplified.js
8254
+ var _src_handlers_script_copy_js_CopyJsRewriter;
8255
+ (function () {
8256
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
8257
+ var define = null;
8258
+ var exports = _src_handlers_script_copy_js_CopyJsRewriter != null ? _src_handlers_script_copy_js_CopyJsRewriter : {};
8259
+ var module = { exports: exports };
8260
+
8261
+ "use strict";
8262
+ Object.defineProperty(exports, "__esModule", { value: true });
8263
+ exports.CopyJsRewriter = void 0;
8264
+ const BaseRewriter_1 = _src_handlers_base_BaseRewriter;
8265
+ class CopyJsRewriter extends BaseRewriter_1.BaseRewriter {
8266
+ rewritePartial(content, ownerResource) {
8267
+ }
8268
+ rewriteResource(resource) {
8269
+ }
8270
+ accepts(type) {
8271
+ return type === 'mask';
8272
+ }
8273
+ }
8274
+ exports.CopyJsRewriter = CopyJsRewriter;
8275
+ ;
8276
+ //# sourceMappingURL=CopyJsRewriter.js.map
8277
+ //# sourceMappingURL=CopyJsRewriter.ts.map;
8278
+
8279
+ function __isObj(x) {
8280
+ return x != null && typeof x === 'object' && x.constructor === Object;
8281
+ }
8282
+ if (_src_handlers_script_copy_js_CopyJsRewriter === module.exports) {
8283
+ // do nothing if
8284
+ } else if (__isObj(_src_handlers_script_copy_js_CopyJsRewriter) && __isObj(module.exports)) {
8285
+ Object.assign(_src_handlers_script_copy_js_CopyJsRewriter, module.exports);
8286
+ } else {
8287
+ _src_handlers_script_copy_js_CopyJsRewriter = module.exports;
8288
+ }
8289
+
8290
+ ;
8291
+ }());
8292
+
8293
+ // end:source ./ModuleSimplified.js
8294
+
8295
+
8296
+ // source ./ModuleSimplified.js
8297
+ var _src_handlers_script_copy_js_CopyJsBuilder;
8298
+ (function () {
8299
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
8300
+ var define = null;
8301
+ var exports = _src_handlers_script_copy_js_CopyJsBuilder != null ? _src_handlers_script_copy_js_CopyJsBuilder : {};
8302
+ var module = { exports: exports };
8303
+
8304
+ "use strict";
8305
+ Object.defineProperty(exports, "__esModule", { value: true });
8306
+ exports.CopyJsBuilder = void 0;
8307
+ const alot_1 = require("alot");
8308
+ const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
8309
+ const OutputResources_1 = _src_class_OutputResources;
8310
+ const atma_utils_1 = require("atma-utils");
8311
+ const path_1 = _src_utils_path;
8312
+ const Configuration_1 = _src_config_Configuration;
8313
+ /**
8314
+ * Primary purpose of this builder is to copy source files to the output folder.
8315
+ * Atma IO middlewares are used to compile/transpile the files.
8316
+ *
8317
+ * For now the accent is made for Typescript files.
8318
+ */
8319
+ class CopyJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
8320
+ wrapModule(resource, outputItem) {
8321
+ let { content, dependencies } = resource;
8322
+ let offset = 0;
8323
+ dependencies && dependencies.filter(x => x.pos != null && (0, path_1.path_isRelative)(x.url)).forEach(dep => {
8324
+ let resUrl = new atma_utils_1.class_Uri(resource.url);
8325
+ let resDep = new atma_utils_1.class_Uri(dep.url);
8326
+ let url = resUrl.combine(resDep).toLocalFile();
8327
+ let start = dep.pos + offset + 1;
8328
+ let c = content[start - 1];
8329
+ let end = content.indexOf(c, start);
8330
+ let oldLength = end - start;
8331
+ let newLength = url.length;
8332
+ content = content.substring(0, start) + url + content.substring(end);
8333
+ offset += newLength - oldLength;
8334
+ });
8335
+ return content;
8336
+ }
8337
+ async buildRoot(root, outputDependencies) {
8338
+ let outputResources = this.solution.outputResources;
8339
+ outputResources.items = await (0, alot_1.default)(outputResources.items)
8340
+ .mapManyAsync(async (item) => {
8341
+ if (item.resource.isGlob !== true) {
8342
+ return [item];
8343
+ }
8344
+ // Normal output
8345
+ let copyItems = await (0, alot_1.default)(item.resources)
8346
+ .mapMany(resource => {
8347
+ return this.createOutputItems(item, resource);
8348
+ })
8349
+ .toArrayAsync();
8350
+ return copyItems;
8351
+ }).toArrayAsync();
8352
+ }
8353
+ getRootContent(root, outputDependencies) {
8354
+ return root.content;
8355
+ }
8356
+ accepts(resource) {
8357
+ if (resource.type !== 'js') {
8358
+ return false;
8359
+ }
8360
+ return resource.isGlob === true;
8361
+ }
8362
+ async createOutputItems(parent, resource) {
8363
+ var _a;
8364
+ let solution = this.solution;
8365
+ let rewriteToRelativeUrls = {};
8366
+ if (((_a = resource.dependencies) === null || _a === void 0 ? void 0 : _a.length) > 0) {
8367
+ let appBase = this.solution.opts.base;
8368
+ (0, alot_1.default)(resource.dependencies)
8369
+ .forEach(dep => {
8370
+ if (dep.resource == null) {
8371
+ return;
8372
+ }
8373
+ if (dep.resource.filename.startsWith(appBase) === false) {
8374
+ // is project dependency
8375
+ return;
8376
+ }
8377
+ let relativePath = (0, path_1.path_toRelative)(dep.resource.filename, resource.filename);
8378
+ if (relativePath == null || /(..\/)*?\/?node_modules/.test(relativePath)) {
8379
+ return;
8380
+ }
8381
+ relativePath = (0, path_1.path_changeExtension)(relativePath, null);
8382
+ relativePath = relativePath.startsWith('.')
8383
+ ? relativePath
8384
+ : './' + relativePath;
8385
+ rewriteToRelativeUrls[dep.url] = relativePath;
8386
+ })
8387
+ .toArray();
8388
+ resource.content = rewriteUrls(resource.content, rewriteToRelativeUrls);
8389
+ }
8390
+ let result = [
8391
+ createOutputItem(cloneWithExtension(resource, 'js'))
8392
+ ];
8393
+ let extra = [{
8394
+ ext: 'ts.map',
8395
+ output: 'js.map',
8396
+ }, {
8397
+ ext: 'd.ts',
8398
+ output: 'd.ts',
8399
+ }];
8400
+ let readFile = Configuration_1.Configuration.Instance.get('readFile');
8401
+ await (0, alot_1.default)(extra).forEachAsync(async (x) => {
8402
+ let cloned = cloneWithExtension(resource, x.ext);
8403
+ cloned.content = await readFile(cloned.filename);
8404
+ cloned.content = rewriteUrls(cloned.content, rewriteToRelativeUrls);
8405
+ result.push(createOutputItem(cloneWithExtension(cloned, x.output)));
8406
+ if (x.ext === 'ts.map' && cloned.content != null) {
8407
+ let outputItem = result[result.length - 1];
8408
+ let source = resource.filename;
8409
+ let target = outputItem.resource.filename;
8410
+ let rel = (0, path_1.path_toRelative)(source, target);
8411
+ outputItem.resource.content = outputItem.resource.content.replace(/"sources":\["[^"]+"\]/, `"sources":["${rel}"]`);
8412
+ }
8413
+ }).toArrayAsync({ threads: 1 });
8414
+ function createOutputItem(resource) {
8415
+ return new OutputResources_1.OutputItem({
8416
+ page: parent.page,
8417
+ bundle: parent.bundle,
8418
+ type: parent.type,
8419
+ solution: solution,
8420
+ resources: [resource],
8421
+ isGlob: false,
8422
+ resource: resource.toTarget(solution)
8423
+ });
8424
+ }
8425
+ function cloneWithExtension(resource, ext) {
8426
+ let cloned = resource.clone();
8427
+ cloned.filename = (0, path_1.path_changeExtension)(cloned.filename, ext);
8428
+ cloned.url = (0, path_1.path_changeExtension)(cloned.url, ext);
8429
+ return cloned;
8430
+ }
8431
+ function rewriteUrls(content, rewriteToRelativeUrls) {
8432
+ for (let key in rewriteToRelativeUrls) {
8433
+ content = content.replaceAll(key, rewriteToRelativeUrls[key]);
8434
+ }
8435
+ return content;
8436
+ }
8437
+ return result;
8438
+ }
8439
+ }
8440
+ exports.CopyJsBuilder = CopyJsBuilder;
8441
+ ;
8442
+ //# sourceMappingURL=CopyJsBuilder.js.map
8443
+ //# sourceMappingURL=CopyJsBuilder.ts.map;
8444
+
8445
+ function __isObj(x) {
8446
+ return x != null && typeof x === 'object' && x.constructor === Object;
8447
+ }
8448
+ if (_src_handlers_script_copy_js_CopyJsBuilder === module.exports) {
8449
+ // do nothing if
8450
+ } else if (__isObj(_src_handlers_script_copy_js_CopyJsBuilder) && __isObj(module.exports)) {
8451
+ Object.assign(_src_handlers_script_copy_js_CopyJsBuilder, module.exports);
8452
+ } else {
8453
+ _src_handlers_script_copy_js_CopyJsBuilder = module.exports;
8454
+ }
8455
+
8456
+ ;
8457
+ }());
8458
+
8459
+ // end:source ./ModuleSimplified.js
8460
+
8461
+
8462
+ // source ./ModuleSimplified.js
8463
+ var _src_handlers_script_copy_js_CopyJsHandler;
8464
+ (function () {
8465
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
8466
+ var define = null;
8467
+ var exports = _src_handlers_script_copy_js_CopyJsHandler != null ? _src_handlers_script_copy_js_CopyJsHandler : {};
8468
+ var module = { exports: exports };
8469
+
8470
+ "use strict";
8471
+ Object.defineProperty(exports, "__esModule", { value: true });
8472
+ exports.CopyJsHandler = void 0;
8473
+ const BaseHandler_1 = _src_handlers_base_BaseHandler;
8474
+ const CopyJsParser_1 = _src_handlers_script_copy_js_CopyJsParser;
8475
+ const CopyJsRewriter_1 = _src_handlers_script_copy_js_CopyJsRewriter;
8476
+ const CopyJsBuilder_1 = _src_handlers_script_copy_js_CopyJsBuilder;
8477
+ class CopyJsHandler extends BaseHandler_1.BaseHandler {
8478
+ }
8479
+ exports.CopyJsHandler = CopyJsHandler;
8480
+ CopyJsHandler.Parser = CopyJsParser_1.CopyJsParser;
8481
+ CopyJsHandler.Rewriter = CopyJsRewriter_1.CopyJsRewriter;
8482
+ CopyJsHandler.Builder = CopyJsBuilder_1.CopyJsBuilder;
8483
+ CopyJsHandler.PathResolver = null;
8484
+ ;
8485
+ //# sourceMappingURL=CopyJsHandler.js.map
8486
+ //# sourceMappingURL=CopyJsHandler.ts.map;
8487
+
8488
+ function __isObj(x) {
8489
+ return x != null && typeof x === 'object' && x.constructor === Object;
8490
+ }
8491
+ if (_src_handlers_script_copy_js_CopyJsHandler === module.exports) {
8492
+ // do nothing if
8493
+ } else if (__isObj(_src_handlers_script_copy_js_CopyJsHandler) && __isObj(module.exports)) {
8494
+ Object.assign(_src_handlers_script_copy_js_CopyJsHandler, module.exports);
8495
+ } else {
8496
+ _src_handlers_script_copy_js_CopyJsHandler = module.exports;
8497
+ }
8498
+
8499
+ ;
8500
+ }());
8501
+
8502
+ // end:source ./ModuleSimplified.js
8503
+
8504
+
8143
8505
  // source ./ModuleSimplified.js
8144
8506
  var _src_handlers_script_ScriptBuilder;
8145
8507
  (function () {
@@ -8158,10 +8520,12 @@ const AmdJsHandler_1 = _src_handlers_script_amd_js_AmdJsHandler;
8158
8520
  const IncludeJsHandler_1 = _src_handlers_script_include_js_IncludeJsHandler;
8159
8521
  const MaskJsHandler_1 = _src_handlers_script_mask_js_MaskJsHandler;
8160
8522
  const ImportJsHandler_1 = _src_handlers_script_import_js_ImportJsHandler;
8523
+ const CopyJsHandler_1 = _src_handlers_script_copy_js_CopyJsHandler;
8161
8524
  class ScriptBuilder extends BaseBuilder_1.BaseBuilder {
8162
8525
  constructor() {
8163
8526
  super(...arguments);
8164
8527
  this.builders = [
8528
+ new CopyJsHandler_1.CopyJsHandler.Builder(this.solution, this.handler),
8165
8529
  new GlobalJsHandler_1.GlobalJsHandler.Builder(this.solution, this.handler),
8166
8530
  new CommonJsHandler_1.CommonJsHandler.Builder(this.solution, this.handler),
8167
8531
  new AmdJsHandler_1.AmdJsHandler.Builder(this.solution, this.handler),
@@ -8182,8 +8546,9 @@ class ScriptBuilder extends BaseBuilder_1.BaseBuilder {
8182
8546
  else {
8183
8547
  const out = resArr.map(res => {
8184
8548
  let builder = this.builders.find(x => x.accepts(res));
8185
- if (builder == null)
8549
+ if (builder == null) {
8186
8550
  throw new Error('Module Builder not found for ' + res.url);
8551
+ }
8187
8552
  return builder.wrapModule(res, outputItem, otherOutputItems);
8188
8553
  });
8189
8554
  code = out.join('\n');
@@ -11001,6 +11366,19 @@ exports.Parser = {
11001
11366
  };
11002
11367
  function getDependenciesInternal(resource, solution) {
11003
11368
  assert(typeof resource.url === 'string', 'Path is expected');
11369
+ if (resource.isGlob) {
11370
+ let paths = resource.content;
11371
+ let resInfos = paths.map(path => {
11372
+ return {
11373
+ type: resource.type,
11374
+ url: path,
11375
+ module: resource.module,
11376
+ page: resource.page
11377
+ };
11378
+ });
11379
+ let result = { dependencies: resInfos };
11380
+ return (0, async_1.async_resolve)(result);
11381
+ }
11004
11382
  let ext = (0, path_1.path_getExtension)(resource.url);
11005
11383
  let handler = solution.handlers.find(x => x.parser.accepts(resource.type) || x.parser.accepts(ext));
11006
11384
  if (handler == null) {
@@ -11224,17 +11602,26 @@ var ResourceLoader;
11224
11602
  }
11225
11603
  try {
11226
11604
  let start = Date.now();
11227
- let reader = Configuration_1.Configuration.Instance.get('readFile');
11605
+ let reader = this.resource.isGlob
11606
+ ? Configuration_1.Configuration.Instance.get('readDirectory')
11607
+ : Configuration_1.Configuration.Instance.get('readFile');
11228
11608
  let content = await reader(this.resource.filename, this.opts);
11609
+ if (this.resource.isGlob && Array.isArray(content) && this.solution.opts.ignore) {
11610
+ let rgxArr = this.solution.opts.ignore.map(path => new RegExp(path, 'i'));
11611
+ content = content.filter(path => {
11612
+ return rgxArr.some(rgx => rgx.test(path)) === false;
11613
+ });
11614
+ }
11229
11615
  let handler = this.solution.handlers.find(x => x.parser.accepts(this.resource.type));
11230
- if (((_a = handler === null || handler === void 0 ? void 0 : handler.parser) === null || _a === void 0 ? void 0 : _a.transpile) !== null) {
11616
+ if (((_a = handler === null || handler === void 0 ? void 0 : handler.parser) === null || _a === void 0 ? void 0 : _a.transpile) != null) {
11231
11617
  let result = await handler.parser.transpile(content, this.resource);
11232
11618
  content = (_b = result === null || result === void 0 ? void 0 : result.content) !== null && _b !== void 0 ? _b : content;
11233
11619
  }
11234
11620
  let end = Date.now();
11235
- this.solution.reporter.print((0, color_1.color)(` cyan<${end - start}> ms \n`));
11621
+ this.solution.reporter.print((0, color_1.color)(` cyan<${end - start}> ms`));
11236
11622
  this.resource.content = content;
11237
- if (this.resource.type === 'data' || this.resource.type === 'load') {
11623
+ if (this.resource.type === 'data') {
11624
+ this.solution.reporter.print('\n');
11238
11625
  this.promise.resolve(this);
11239
11626
  return;
11240
11627
  }
@@ -11246,12 +11633,15 @@ var ResourceLoader;
11246
11633
  }
11247
11634
  processChildren() {
11248
11635
  if (this.shouldSkipChildren()) {
11636
+ this.solution.reporter.print(` (skip deps)`);
11249
11637
  this.promise.resolve(this);
11250
11638
  return;
11251
11639
  }
11252
11640
  Parser_1.Parser
11253
11641
  .getDependencies(this.resource, this.solution)
11254
11642
  .then(result => {
11643
+ var _a;
11644
+ this.solution.reporter.print((0, color_1.color)(` cyan<${(_a = result.dependencies) === null || _a === void 0 ? void 0 : _a.length}> dep\n`));
11255
11645
  this.loadChildren(result).catch(err => {
11256
11646
  this.promise.reject(err);
11257
11647
  });
@@ -11497,14 +11887,14 @@ exports.Builder = void 0;
11497
11887
  const Middlewares_1 = _src_class_Middlewares;
11498
11888
  const path_1 = _src_utils_path;
11499
11889
  const async_1 = _src_utils_async;
11500
- const alot = require("alot");
11890
+ const alot_1 = require("alot");
11501
11891
  exports.Builder = {
11502
11892
  build(resources, solution) {
11503
11893
  return Middlewares_1._middlewares
11504
11894
  .run('buildResources', resources, solution)
11505
11895
  .then(arr => {
11506
- resources = arr || resources;
11507
- solution.outputResources.prepair(resources);
11896
+ resources = arr !== null && arr !== void 0 ? arr : resources;
11897
+ solution.outputResources.prepare(resources);
11508
11898
  return Middlewares_1._middlewares
11509
11899
  .run('rewriteDependencies', resources, solution)
11510
11900
  .then(() => rewriteDependenciesInternal(resources))
@@ -11514,9 +11904,9 @@ exports.Builder = {
11514
11904
  .then(() => solution.outputResources.getAll());
11515
11905
  });
11516
11906
  function rewriteDependenciesInternal(resources) {
11517
- var dfrs = resources.map(resource => {
11518
- var ext = (0, path_1.path_getExtension)(resource.url);
11519
- var handler = solution.handlers.find(x => x.rewriter.accepts(ext));
11907
+ let promises = resources.map(resource => {
11908
+ let ext = (0, path_1.path_getExtension)(resource.url);
11909
+ let handler = solution.handlers.find(x => x.rewriter.accepts(ext));
11520
11910
  if (handler == null) {
11521
11911
  handler = solution.handlers.find(x => x.rewriter.accepts(resource.type));
11522
11912
  }
@@ -11525,12 +11915,14 @@ exports.Builder = {
11525
11915
  }
11526
11916
  return handler.rewriter.rewriteResource(resource);
11527
11917
  });
11528
- return (0, async_1.async_whenAll)(dfrs);
11918
+ return (0, async_1.async_whenAll)(promises);
11529
11919
  }
11530
11920
  function rewriteRoot() {
11531
11921
  return (0, async_1.async_run)(() => {
11532
- var input = solution.outputResources.rootInput, output = solution.outputResources.rootOutput, ext = (0, path_1.path_getExtension)(input.url);
11533
- var handler = solution.handlers.find(x => x.rewriter.accepts(input.type) || x.rewriter.accepts(ext));
11922
+ let input = solution.outputResources.rootInput;
11923
+ let output = solution.outputResources.rootOutput;
11924
+ let ext = (0, path_1.path_getExtension)(input.url);
11925
+ let handler = solution.handlers.find(x => x.rewriter.accepts(input.type) || x.rewriter.accepts(ext));
11534
11926
  if (handler == null || handler.rewriter.rewriteRoot == null) {
11535
11927
  //throw new Error(`RootRewriter is not found for a resource ${input.url} and type ${input.type}`);
11536
11928
  return;
@@ -11539,9 +11931,9 @@ exports.Builder = {
11539
11931
  });
11540
11932
  }
11541
11933
  function buildOutputItems() {
11542
- var items = solution.outputResources.items;
11543
- return alot(items).mapAsync(item => {
11544
- var otherOutputItems = items.filter(x => {
11934
+ let items = solution.outputResources.items;
11935
+ return (0, alot_1.default)(items).mapAsync(item => {
11936
+ let otherOutputItems = items.filter(x => {
11545
11937
  if (x === item)
11546
11938
  return false;
11547
11939
  if (x.page != item.page)
@@ -11562,8 +11954,8 @@ exports.Builder = {
11562
11954
  if (outputItem.resource.content) {
11563
11955
  return;
11564
11956
  }
11565
- var ext = (0, path_1.path_getExtension)(outputItem.resource.url);
11566
- var handler = solution.handlers.find(x => x.builder.accepts(outputItem.type));
11957
+ let ext = (0, path_1.path_getExtension)(outputItem.resource.url);
11958
+ let handler = solution.handlers.find(x => x.builder.accepts(outputItem.type));
11567
11959
  if (handler == null) {
11568
11960
  handler = solution.handlers.find(x => x.builder.accepts(ext));
11569
11961
  }
@@ -11573,10 +11965,11 @@ exports.Builder = {
11573
11965
  return handler.builder.createModule(outputItem, otherOutputItems);
11574
11966
  }
11575
11967
  function buildRoot() {
11576
- var main = solution.outputResources.rootOutput;
11577
- var dependencies = solution.outputResources.getForPage(solution.opts.mainPage);
11578
- var ext = (0, path_1.path_getExtension)(main.url);
11579
- var handler = solution.handlers.find(x => x.builder.accepts(main.type) || x.builder.accepts(ext));
11968
+ var _a;
11969
+ let main = (_a = solution.outputResources.rootOutput) !== null && _a !== void 0 ? _a : solution.outputResources.rootInput;
11970
+ let dependencies = solution.outputResources.getForPage(solution.opts.mainPage);
11971
+ let ext = (0, path_1.path_getExtension)(main.url);
11972
+ let handler = solution.handlers.find(x => x.builder.accepts(main.type) || x.builder.accepts(ext));
11580
11973
  if (handler == null || handler.builder.buildRoot == null) {
11581
11974
  throw new Error(`RootBuilder is not found for a resource ${main.url} and type ${main.type}`);
11582
11975
  }
@@ -11630,11 +12023,6 @@ const tree_1 = _src_utils_tree;
11630
12023
  const Builder_1 = _src_builder_Builder;
11631
12024
  const color_1 = _src_utils_color;
11632
12025
  class Bundler extends atma_utils_1.class_EventEmitter {
11633
- constructor(path, opts) {
11634
- super();
11635
- global.__$bundler = this;
11636
- this.solution = new Solution_1.Solution(path, opts);
11637
- }
11638
12026
  static clearCache() {
11639
12027
  Loader_1.Loader.clearCache();
11640
12028
  if (global_1.io.File.middleware) {
@@ -11650,8 +12038,15 @@ class Bundler extends atma_utils_1.class_EventEmitter {
11650
12038
  static get Config() {
11651
12039
  return Configuration_1.Configuration.Instance;
11652
12040
  }
12041
+ constructor(path, opts) {
12042
+ super();
12043
+ global.__$bundler = this;
12044
+ this.solution = new Solution_1.Solution(path, opts);
12045
+ }
11653
12046
  getResourceTree(opts) {
11654
- var solution = this.solution, type = solution.opts.type, path = solution.path;
12047
+ let solution = this.solution;
12048
+ let type = solution.opts.type;
12049
+ let path = solution.path;
11655
12050
  return Loader_1.Loader
11656
12051
  .load(type, path, opts, solution)
11657
12052
  .then(x => x.toJSON());
@@ -11660,7 +12055,9 @@ class Bundler extends atma_utils_1.class_EventEmitter {
11660
12055
  return new Bundler(path, opts).getResourceTree();
11661
12056
  }
11662
12057
  getResources(opts) {
11663
- var solution = this.solution, type = solution.opts.type, path = solution.path;
12058
+ let solution = this.solution;
12059
+ let type = solution.opts.type;
12060
+ let path = solution.path;
11664
12061
  return Loader_1.Loader.load(type, path, opts, solution).then(resource => {
11665
12062
  return (0, res_1.res_flattern)(resource, solution.opts.dependencies).map(x => x);
11666
12063
  });
@@ -11669,16 +12066,28 @@ class Bundler extends atma_utils_1.class_EventEmitter {
11669
12066
  return new Bundler(path, opts).getResources();
11670
12067
  }
11671
12068
  build(opts) {
11672
- var solution = this.solution, type = solution.opts.type, path = solution.path, shouldRebuild = false, isBuilding = false, isRebuilding = false, rootResource = null, self = this;
12069
+ let solution = this.solution;
12070
+ let type = solution.opts.type;
12071
+ let path = solution.path;
12072
+ let shouldRebuild = false;
12073
+ let isBuilding = false;
12074
+ let isRebuilding = false;
12075
+ let rootResource = null;
12076
+ let self = this;
11673
12077
  function build(resource) {
11674
12078
  isBuilding = true;
11675
- var resources = (0, res_1.res_flattern)(resource, solution.opts.dependencies);
12079
+ let resources = (0, res_1.res_flattern)(resource, solution.opts.dependencies);
11676
12080
  return (0, tree_1.tree_async)({
11677
- resources,
11678
12081
  reporter: solution.reporter,
11679
- action: () => Builder_1.Builder.build(resources, solution),
11680
- message: (treeInfo, seconds) => (0, color_1.color)(`Created bold<yellow<${treeInfo.count}>> files in bold<yellow<${seconds}>> sec.`)
11681
- }).done(buildComplete).fail(buildFailed);
12082
+ action: () => {
12083
+ return Builder_1.Builder.build(resources, solution);
12084
+ },
12085
+ message: (treeInfo, seconds) => {
12086
+ return (0, color_1.color)(`Created bold<yellow<${treeInfo.count}>> files in bold<yellow<${seconds}>> sec.`);
12087
+ }
12088
+ })
12089
+ .done(buildComplete)
12090
+ .fail(buildFailed);
11682
12091
  }
11683
12092
  function buildComplete(resources) {
11684
12093
  isBuilding = false;
@@ -11738,8 +12147,8 @@ class Bundler extends atma_utils_1.class_EventEmitter {
11738
12147
  return new Bundler(path, opts).build(opts);
11739
12148
  }
11740
12149
  static process(path, opts) {
11741
- var bundler = new Bundler(path, opts);
11742
- var solution = bundler.solution;
12150
+ let bundler = new Bundler(path, opts);
12151
+ let solution = bundler.solution;
11743
12152
  function builderComplete(resources) {
11744
12153
  resources.forEach(res => {
11745
12154
  global_1.io.File.write(res.filename, res.content);
@@ -11770,8 +12179,8 @@ class Bundler extends atma_utils_1.class_EventEmitter {
11770
12179
  getDependencies(content, opts = { type: 'js' }) {
11771
12180
  if (typeof opts === 'string')
11772
12181
  opts = { type: opts };
11773
- var solution = new Solution_1.Solution('', opts);
11774
- var resource = new Resource_1.Resource({ type: opts.type, content: content }, null, solution);
12182
+ let solution = new Solution_1.Solution('', opts);
12183
+ let resource = new Resource_1.Resource({ type: opts.type, content: content }, null, solution);
11775
12184
  return Parser_1.Parser.getDependencies(resource, solution);
11776
12185
  }
11777
12186
  };