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/cli.js CHANGED
@@ -78,6 +78,10 @@ var _src_handlers_script_common_js_CommonJsPathResolver = {};
78
78
  var _src_handlers_script_common_js_CommonJsRewriter = {};
79
79
  var _src_handlers_script_common_js_ModuleWrapper = {};
80
80
  var _src_handlers_script_common_js_templates_Templates = {};
81
+ var _src_handlers_script_copy_js_CopyJsBuilder = {};
82
+ var _src_handlers_script_copy_js_CopyJsHandler = {};
83
+ var _src_handlers_script_copy_js_CopyJsParser = {};
84
+ var _src_handlers_script_copy_js_CopyJsRewriter = {};
81
85
  var _src_handlers_script_global_js_GlobalJsBuilder = {};
82
86
  var _src_handlers_script_global_js_GlobalJsHandler = {};
83
87
  var _src_handlers_script_global_js_GlobalJsParser = {};
@@ -132,7 +136,7 @@ let assert = require('assert');
132
136
  exports.assert = assert;
133
137
  let logger = require('atma-logger');
134
138
  exports.logger = logger;
135
- let io = g.io || require('atma-io');
139
+ let io = (g.io || require('atma-io'));
136
140
  exports.io = io;
137
141
  /* Make compatible with previous atma-loaders */
138
142
  g.Class = require('atma-class');
@@ -166,8 +170,8 @@ var _src_utils_path;
166
170
 
167
171
  "use strict";
168
172
  Object.defineProperty(exports, "__esModule", { value: true });
169
- exports.path_toAbsolute = exports.path_removeQuery = exports.path_sliceQuery = exports.path_sliceHash = exports.path_combine = exports.path_toRelative = exports.path_isRelative = exports.path_resolveUrl = exports.path_normalize = exports.path_resolveCurrent = exports.path_withProtocol = exports.path_appendQuery = exports.path_getExtension = exports.path_getFile = exports.path_getDir = void 0;
170
- var isWeb = true;
173
+ exports.path_toAbsolute = exports.path_changeExtension = exports.path_removeQuery = exports.path_sliceQuery = exports.path_sliceHash = exports.path_combine = exports.path_toRelative = exports.path_isRelative = exports.path_resolveUrl = exports.path_normalize = exports.path_resolveCurrent = exports.path_withProtocol = exports.path_appendQuery = exports.path_getExtension = exports.path_getFile = exports.path_getDir = void 0;
174
+ let isWeb = true;
171
175
  function path_getDir(path) {
172
176
  return path.substring(0, path.lastIndexOf('/') + 1);
173
177
  }
@@ -187,17 +191,17 @@ function path_getFile(path) {
187
191
  exports.path_getFile = path_getFile;
188
192
  ;
189
193
  function path_getExtension(path) {
190
- var query = path.indexOf('?');
194
+ let query = path.indexOf('?');
191
195
  if (query !== -1) {
192
196
  path = path.substring(0, query);
193
197
  }
194
- var match = rgx_EXT.exec(path);
198
+ let match = rgx_EXT.exec(path);
195
199
  return match == null ? '' : match[1];
196
200
  }
197
201
  exports.path_getExtension = path_getExtension;
198
202
  ;
199
203
  function path_appendQuery(path, key, val) {
200
- var conjunctor = path.indexOf('?') === -1 ? '?' : '&';
204
+ let conjunctor = path.indexOf('?') === -1 ? '?' : '&';
201
205
  return path + conjunctor + key + '=' + val;
202
206
  }
203
207
  exports.path_appendQuery = path_appendQuery;
@@ -207,7 +211,7 @@ function path_withProtocol(path) {
207
211
  }
208
212
  exports.path_withProtocol = path_withProtocol;
209
213
  ;
210
- var current_;
214
+ let current_;
211
215
  function path_resolveCurrent() {
212
216
  if (current_ != null)
213
217
  return current_;
@@ -216,7 +220,7 @@ function path_resolveCurrent() {
216
220
  exports.path_resolveCurrent = path_resolveCurrent;
217
221
  ;
218
222
  function path_normalize(path) {
219
- var path_ = path
223
+ let path_ = path
220
224
  .replace(/\\/g, '/')
221
225
  // remove double slashes, but not near protocol
222
226
  .replace(/([^:\/])\/{2,}/g, '$1/')
@@ -233,7 +237,7 @@ function path_normalize(path) {
233
237
  exports.path_normalize = path_normalize;
234
238
  ;
235
239
  function path_resolveUrl(path, base) {
236
- var url = path_normalize(path);
240
+ let url = path_normalize(path);
237
241
  if (path_isRelative(url)) {
238
242
  return path_normalize(path_combine(base || path_resolveCurrent(), url));
239
243
  }
@@ -264,9 +268,9 @@ function path_toRelative(path, anchor, base) {
264
268
  return path_.substring(absolute_.length);
265
269
  }
266
270
  else {
267
- var sub = '../';
271
+ let sub = '../';
268
272
  while (true) {
269
- var folder = absolute_.replace(/[^\/]+\/?$/, '');
273
+ let folder = absolute_.replace(/[^\/]+\/?$/, '');
270
274
  if (folder === '' || folder === absolute_) {
271
275
  break;
272
276
  }
@@ -282,7 +286,9 @@ function path_toRelative(path, anchor, base) {
282
286
  exports.path_toRelative = path_toRelative;
283
287
  ;
284
288
  function path_combine(...args) {
285
- var out = '', imax = args.length, i = -1, x;
289
+ let out = '';
290
+ let imax = args.length;
291
+ let i = -1, x;
286
292
  while (++i < imax) {
287
293
  x = args[i];
288
294
  if (!x)
@@ -305,38 +311,54 @@ function path_combine(...args) {
305
311
  exports.path_combine = path_combine;
306
312
  ;
307
313
  function path_sliceHash(url) {
308
- if (url == null)
314
+ if (url == null) {
309
315
  return null;
310
- var i = url.indexOf('#');
311
- if (i === -1)
316
+ }
317
+ let i = url.indexOf('#');
318
+ if (i === -1) {
312
319
  return null;
320
+ }
313
321
  return url.substring(i);
314
322
  }
315
323
  exports.path_sliceHash = path_sliceHash;
316
324
  ;
317
325
  function path_sliceQuery(url) {
318
- if (url == null)
326
+ if (url == null) {
319
327
  return null;
320
- var i = url.indexOf('?');
321
- if (i === -1)
328
+ }
329
+ let i = url.indexOf('?');
330
+ if (i === -1) {
322
331
  return null;
332
+ }
323
333
  return url.substring(i);
324
334
  }
325
335
  exports.path_sliceQuery = path_sliceQuery;
326
336
  ;
327
337
  function path_removeQuery(url) {
328
- if (url == null)
338
+ if (url == null) {
329
339
  return null;
330
- var i = url.indexOf('#');
331
- if (i !== -1)
340
+ }
341
+ let i = url.indexOf('#');
342
+ if (i !== -1) {
332
343
  url = url.substring(0, i);
333
- var i = url.indexOf('?');
334
- if (i !== -1)
344
+ }
345
+ i = url.indexOf('?');
346
+ if (i !== -1) {
335
347
  url = url.substring(0, i);
348
+ }
336
349
  return url;
337
350
  }
338
351
  exports.path_removeQuery = path_removeQuery;
339
352
  ;
353
+ function path_changeExtension(path, ext) {
354
+ let str = ext ? '.' + ext : '';
355
+ let i = path.indexOf('.');
356
+ if (i === -1) {
357
+ return path + str;
358
+ }
359
+ return path.substring(0, i) + str;
360
+ }
361
+ exports.path_changeExtension = path_changeExtension;
340
362
  function path_toAbsolute(path, parentLocation, rootLocation) {
341
363
  path = path_normalize(path);
342
364
  if (path_isRelative(path) === false) {
@@ -355,11 +377,11 @@ function path_toAbsolute(path, parentLocation, rootLocation) {
355
377
  }
356
378
  exports.path_toAbsolute = path_toAbsolute;
357
379
  ;
358
- var _cwd;
380
+ let _cwd;
359
381
  function cwd() {
360
382
  return _cwd || (_cwd = path_normalize(process.cwd()));
361
383
  }
362
- var rgx_PROTOCOL = /^(file|https?):/i, rgx_SUB_DIR = /[^\/\.]+\/\.\.\//, rgx_FILENAME = /\/[^\/]+\.\w+(\?.*)?(#.*)?$/, rgx_EXT = /\.(\w+)$/, rgx_win32Drive = /(^\/?\w{1}:)(\/|$)/;
384
+ let rgx_PROTOCOL = /^(file|https?):/i, rgx_SUB_DIR = /[^\/\.]+\/\.\.\//, rgx_FILENAME = /\/[^\/]+\.\w+(\?.*)?(#.*)?$/, rgx_EXT = /\.(\w+)$/, rgx_win32Drive = /(^\/?\w{1}:)(\/|$)/;
363
385
  function path_win32Normalize(path) {
364
386
  path = path_normalize(path);
365
387
  if (path.substring(0, 5) === 'file:')
@@ -367,7 +389,7 @@ function path_win32Normalize(path) {
367
389
  return 'file://' + path;
368
390
  }
369
391
  function path_collapse(url_) {
370
- var url = url_;
392
+ let url = url_;
371
393
  while (rgx_SUB_DIR.test(url)) {
372
394
  url = url.replace(rgx_SUB_DIR, '');
373
395
  }
@@ -1410,6 +1432,8 @@ class Resource {
1410
1432
  this.inPages = null;
1411
1433
  this.isCyclic = false;
1412
1434
  this.isMapped = false;
1435
+ // when the path is like "/foo/bar/**.ts"
1436
+ this.isGlob = false;
1413
1437
  this.meta = null;
1414
1438
  this.aliases = [];
1415
1439
  if (arguments.length === 0)
@@ -1436,6 +1460,7 @@ class Resource {
1436
1460
  this.asModules = [];
1437
1461
  this.inPages = [];
1438
1462
  this.source = null;
1463
+ this.isGlob = /\*+\.\w+$/.test(includeData.url);
1439
1464
  if (includeData.bundle) {
1440
1465
  this.bundle = includeData.bundle;
1441
1466
  }
@@ -1488,7 +1513,11 @@ class Resource {
1488
1513
  }
1489
1514
  if (Include_1.Include.PathResolver.isNpm(includeData.url)) {
1490
1515
  this.aliases.push(includeData.url);
1491
- url = npm_1.Npm.resolveAppUrl(includeData.url, parent && parent.location, solution.opts.base);
1516
+ let byNpmResolver = npm_1.Npm.resolveAppUrl(includeData.url, parent && parent.location, solution.opts.base);
1517
+ if (byNpmResolver != null) {
1518
+ // otherwise "url" could be previously resolved with pathResolver.resolve
1519
+ url = byNpmResolver;
1520
+ }
1492
1521
  if (url == null) {
1493
1522
  // Fix. `resolveAppUrl` returns undefined on native nodejs modules
1494
1523
  url = includeData.url;
@@ -1546,6 +1575,8 @@ class Resource {
1546
1575
  res.source = this.source;
1547
1576
  res.isCyclic = this.isCyclic;
1548
1577
  res.aliases = this.aliases;
1578
+ res.isGlob = this.isGlob;
1579
+ res.dependencies = this.dependencies;
1549
1580
  return res;
1550
1581
  }
1551
1582
  toTarget(solution, settings) {
@@ -1558,6 +1589,7 @@ class Resource {
1558
1589
  resource.inPages = this.inPages;
1559
1590
  resource.bundle = this.bundle;
1560
1591
  resource.aliases = this.aliases;
1592
+ resource.isGlob = this.isGlob;
1561
1593
  if (solution.opts.version && ((_a = this.parent) === null || _a === void 0 ? void 0 : _a.type) !== 'load') {
1562
1594
  resource.url += '?v=' + solution.opts.version;
1563
1595
  }
@@ -1642,7 +1674,7 @@ class Resource {
1642
1674
  if (modules.length === 1) {
1643
1675
  return modules[0];
1644
1676
  }
1645
- let arr = ['global', 'commonjs', 'amd', 'includejs', 'import'];
1677
+ let arr = ['global', 'commonjs', 'amd', 'includejs', 'import', 'esm'];
1646
1678
  let name = arr.find(name => modules.indexOf(name) !== -1);
1647
1679
  if (name == null) {
1648
1680
  name = modules[0];
@@ -2343,6 +2375,18 @@ exports.FileActions = {
2343
2375
  }
2344
2376
  return global_1.io.File.readAsync(path, opts);
2345
2377
  },
2378
+ async readDirectory(path, opts) {
2379
+ let i = path.indexOf('*');
2380
+ let patternI = path.lastIndexOf('/', i);
2381
+ if (patternI === -1) {
2382
+ throw new Error(`Invalid glob pattern: ${path}`);
2383
+ }
2384
+ let pattern = path.substring(patternI + 1);
2385
+ let directory = path.substring(0, patternI + 1);
2386
+ let files = await global_1.io.Directory.readFiles(directory, pattern);
2387
+ let paths = files.map(x => x.uri.toString());
2388
+ return paths;
2389
+ },
2346
2390
  writeFile(path, content, opts) {
2347
2391
  return global_1.io.File.writeAsync(path, content, opts);
2348
2392
  },
@@ -2418,7 +2462,7 @@ class Configuration {
2418
2462
  }
2419
2463
  }
2420
2464
  defineMany(options) {
2421
- for (var key in options) {
2465
+ for (let key in options) {
2422
2466
  this.define(key, options[key]);
2423
2467
  }
2424
2468
  }
@@ -2573,6 +2617,7 @@ class SolutionOpts extends SolutionOptsBase {
2573
2617
  mainPage: 'main',
2574
2618
  mainBundle: '',
2575
2619
  mainContent: null,
2620
+ ignore: null,
2576
2621
  outputBase: '',
2577
2622
  outputAppBase: '/',
2578
2623
  output: '',
@@ -2968,13 +3013,17 @@ class OutputResources {
2968
3013
  this.resources = [];
2969
3014
  this.pagesInput = {};
2970
3015
  }
2971
- prepair(resources) {
3016
+ prepare(resources) {
2972
3017
  this.resources = [];
2973
3018
  this.pagesInput = {};
2974
3019
  this.items = [];
2975
- this.rootInput = resources.pop();
2976
- this.rootOutput = this.rootInput.toTarget(this.solution);
2977
- this.rootOutput.content = this.rootInput.content;
3020
+ let root = resources.pop();
3021
+ let isGlob = root.isGlob;
3022
+ if (isGlob !== true) {
3023
+ this.rootOutput = root.toTarget(this.solution);
3024
+ this.rootOutput.content = root.content;
3025
+ }
3026
+ this.rootInput = root;
2978
3027
  this.pagesInput = (0, res_1.res_groupByPageAndBundles)(resources, this.solution.opts);
2979
3028
  Object.keys(this.pagesInput).forEach(page => {
2980
3029
  Object.keys(this.pagesInput[page]).forEach(bundle => {
@@ -2987,20 +3036,22 @@ class OutputResources {
2987
3036
  bundle,
2988
3037
  type,
2989
3038
  solution: this.solution,
2990
- resources: arr
3039
+ resources: arr,
3040
+ isGlob: isGlob,
2991
3041
  });
2992
3042
  this.items.push(item);
2993
3043
  });
2994
- if (byType['js'] == null) {
2995
- let item = new OutputItem({
2996
- page,
2997
- bundle,
2998
- type: 'js',
2999
- solution: this.solution,
3000
- resources: []
3001
- });
3002
- this.items.push(item);
3003
- }
3044
+ // @TODO: Do we need empty output item?
3045
+ // if (byType['js'] == null) {
3046
+ // let item = new OutputItem({
3047
+ // page,
3048
+ // bundle,
3049
+ // type: 'js',
3050
+ // solution: this.solution,
3051
+ // resources: []
3052
+ // });
3053
+ // this.items.push(item);
3054
+ // }
3004
3055
  });
3005
3056
  });
3006
3057
  }
@@ -3008,7 +3059,7 @@ class OutputResources {
3008
3059
  return this.items.filter(x => x.page === page).map(x => x.resource);
3009
3060
  }
3010
3061
  getAll() {
3011
- var all = this
3062
+ let all = this
3012
3063
  .items
3013
3064
  .map(x => x.resource)
3014
3065
  .filter(x => x.embed !== true)
@@ -3021,19 +3072,27 @@ class OutputResources {
3021
3072
  }
3022
3073
  exports.OutputResources = OutputResources;
3023
3074
  class OutputItem {
3024
- constructor({ page, bundle, type, solution, resources }) {
3075
+ constructor(params) {
3076
+ let { page, bundle, type, solution, resources, isGlob } = params;
3025
3077
  this.page = page;
3026
3078
  this.bundle = bundle;
3027
3079
  this.type = type;
3028
- var ext = solution.opts.getExtForType(type);
3029
- var filename = `${page}_${bundle}.${ext}`;
3030
- var resource = new Resource_1.Resource({
3031
- type: type,
3032
- url: filename,
3033
- bundle: bundle
3034
- }, null, solution);
3035
- this.resource = resource.toTarget(solution);
3036
- this.resources = resources || [];
3080
+ this.resource = params.resource;
3081
+ this.resources = resources !== null && resources !== void 0 ? resources : [];
3082
+ if (this.resource == null) {
3083
+ let ext = solution.opts.getExtForType(type);
3084
+ let sfx = '';
3085
+ if (isGlob === true) {
3086
+ sfx = '_*';
3087
+ }
3088
+ let filename = `${page}_${bundle}${sfx}.${ext}`;
3089
+ let resource = new Resource_1.Resource({
3090
+ type: type,
3091
+ url: filename,
3092
+ bundle: bundle
3093
+ }, null, solution);
3094
+ this.resource = resource.toTarget(solution);
3095
+ }
3037
3096
  }
3038
3097
  }
3039
3098
  exports.OutputItem = OutputItem;
@@ -3907,7 +3966,7 @@ class MaskParser extends BaseParser_1.BaseParser {
3907
3966
  // @NextIteration base will be handled in mask.Module.resolvePath
3908
3967
  // var base = mask.Module.cfg('base');
3909
3968
  // if (base) {
3910
- // path = path_combine(base, path);
3969
+ // path = path_combine(base, path);
3911
3970
  // }
3912
3971
  }
3913
3972
  return [this._createDependency(path, type, page)];
@@ -5613,8 +5672,18 @@ const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
5613
5672
  class AmdJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
5614
5673
  buildRoot(resource, dependencies) {
5615
5674
  }
5616
- accepts(type) {
5617
- return false;
5675
+ wrapModule(resource, outputItem) {
5676
+ return resource.content;
5677
+ }
5678
+ accepts(resource) {
5679
+ if (resource.type !== 'js') {
5680
+ return false;
5681
+ }
5682
+ let module = resource.getModule();
5683
+ if (module === 'root' && resource.solution.opts.package.module === 'amd') {
5684
+ module = 'amd';
5685
+ }
5686
+ return module === 'amd';
5618
5687
  }
5619
5688
  }
5620
5689
  exports.AmdJsBuilder = AmdJsBuilder;
@@ -5699,12 +5768,12 @@ class ResourcePropMapping {
5699
5768
  this.resB = resB;
5700
5769
  }
5701
5770
  map(resource) {
5702
- var match = true;
5703
- for (var key in this.resA) {
5704
- var val = this.resA[key];
5771
+ let match = true;
5772
+ for (let key in this.resA) {
5773
+ let val = this.resA[key];
5705
5774
  if (val == null)
5706
5775
  continue;
5707
- var currentVal = resource[key];
5776
+ let currentVal = resource[key];
5708
5777
  if (typeof val === 'function') {
5709
5778
  match = val(currentVal);
5710
5779
  }
@@ -5714,13 +5783,14 @@ class ResourcePropMapping {
5714
5783
  if (typeof val === 'string' || typeof val === 'number') {
5715
5784
  match = val === currentVal;
5716
5785
  }
5717
- if (match == false)
5786
+ if (match == false) {
5718
5787
  return resource;
5788
+ }
5719
5789
  }
5720
- var clone = resource.clone();
5721
- for (var key in this.resB) {
5722
- var val = this.resB[key];
5723
- var currentVal = resource[key];
5790
+ let clone = resource.clone();
5791
+ for (let key in this.resB) {
5792
+ let val = this.resB[key];
5793
+ let currentVal = resource[key];
5724
5794
  if (typeof val === 'function') {
5725
5795
  clone[key] = val(currentVal, resource);
5726
5796
  continue;
@@ -5778,7 +5848,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5778
5848
  }
5779
5849
  }
5780
5850
  getDependencies(ast, ownerResource) {
5781
- var info = {
5851
+ let info = {
5782
5852
  type: null,
5783
5853
  url: null,
5784
5854
  dependencies: [],
@@ -5795,7 +5865,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5795
5865
  function isIncludeSymbolRef(node) {
5796
5866
  return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name == 'include';
5797
5867
  }
5798
- var scope = AstUtil_1.AstUtil.findNode(node, isIncludeSymbolRef).scope || ast;
5868
+ let scope = AstUtil_1.AstUtil.findNode(node, isIncludeSymbolRef).scope || ast;
5799
5869
  this._process(info, node, scope);
5800
5870
  return true;
5801
5871
  });
@@ -5805,7 +5875,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5805
5875
  return new atma_utils_1.class_Dfr().resolve(info);
5806
5876
  }
5807
5877
  _process(info, node, scope) {
5808
- var arr = [];
5878
+ let arr = [];
5809
5879
  function isIncludeMethodCall(node) {
5810
5880
  return AstUtil_1.AstUtil.is.type(node, 'AST_Call') && node.start.value == 'include';
5811
5881
  }
@@ -5820,7 +5890,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5820
5890
  case 'routes':
5821
5891
  case 'setBase':
5822
5892
  case 'cfg':
5823
- var pckg = {
5893
+ let pckg = {
5824
5894
  type: node.expression.property,
5825
5895
  args: AstUtil_1.AstUtil.getArguments(node.args, scope),
5826
5896
  };
@@ -5852,7 +5922,7 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5852
5922
  break;
5853
5923
  }
5854
5924
  });
5855
- var include = new Include_1.Include();
5925
+ let include = new Include_1.Include();
5856
5926
  arr.forEach(function (x) {
5857
5927
  include[x.type].apply(include, x.args);
5858
5928
  });
@@ -5862,28 +5932,28 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5862
5932
  if (AstUtil_1.AstUtil.is.type(CallbackNode, 'AST_Function') == false) {
5863
5933
  return;
5864
5934
  }
5865
- var meta = info.meta.includejs, args = CallbackNode.argnames, responseObjectName = args.length > 0
5935
+ let meta = info.meta.includejs, args = CallbackNode.argnames, responseObjectName = args.length > 0
5866
5936
  ? args[args.length - 1].name
5867
5937
  : null;
5868
5938
  if (responseObjectName) {
5869
5939
  meta.hasResponseObject = true;
5870
- var names = this._getPropertyAccessors(responseObjectName, CallbackNode);
5940
+ let names = this._getPropertyAccessors(responseObjectName, CallbackNode);
5871
5941
  if (names) {
5872
5942
  meta.responseAccessors = (meta.responseAccessors || []).concat(names);
5873
5943
  }
5874
5944
  }
5875
5945
  }
5876
5946
  /**
5877
- * resolve %name%.propertyAccessor
5947
+ * resolve %name%.propertyAccessor
5878
5948
  */
5879
5949
  _getPropertyAccessors(name, Fn) {
5880
- var references = [];
5950
+ let references = [];
5881
5951
  Fn.body.forEach(function (x) {
5882
5952
  function isSymbolName(node) {
5883
5953
  return AstUtil_1.AstUtil.is.type(node, 'AST_SymbolRef') && node.name === name;
5884
5954
  }
5885
5955
  AstUtil_1.AstUtil.each(x, isSymbolName, function (node) {
5886
- var chain = AstUtil_1.AstUtil.getPropertyChain(node, this.stack);
5956
+ let chain = AstUtil_1.AstUtil.getPropertyChain(node, this.stack);
5887
5957
  if (chain) {
5888
5958
  references.push(chain);
5889
5959
  }
@@ -5892,16 +5962,16 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5892
5962
  return references;
5893
5963
  }
5894
5964
  /**
5895
- * aim to find all **.exports = X
5965
+ * aim to find all **.exports = X
5896
5966
  */
5897
5967
  _getPropertySetter(name, Fn) {
5898
- var result = null;
5968
+ let result = null;
5899
5969
  Fn.body.forEach(function (x) {
5900
5970
  function isPropertyName(node) {
5901
5971
  AstUtil_1.AstUtil.is.type(node, 'AST_Assign') && node.left.property === name;
5902
5972
  }
5903
5973
  AstUtil_1.AstUtil.each(x, isPropertyName, function (node) {
5904
- var arr = ['include', 'module', 'exports'];
5974
+ let arr = ['include', 'module', 'exports'];
5905
5975
  if (arr.indexOf(node.start.value) > -1) {
5906
5976
  result = node;
5907
5977
  }
@@ -5912,12 +5982,12 @@ class IncludeJsParser extends BaseParser_1.BaseParser {
5912
5982
  }
5913
5983
  exports.IncludeJsParser = IncludeJsParser;
5914
5984
  ;
5915
- var IncludeJsMappings = [
5985
+ let IncludeJsMappings = [
5916
5986
  new ResourcePropMapping_1.ResourcePropMapping({
5917
5987
  asModules: (arr) => arr.indexOf('mask') > -1
5918
5988
  }, {
5919
5989
  asModules: (arr) => {
5920
- var i = arr.indexOf('mask');
5990
+ let i = arr.indexOf('mask');
5921
5991
  arr[i] = 'includejs';
5922
5992
  return arr;
5923
5993
  }
@@ -5926,7 +5996,7 @@ var IncludeJsMappings = [
5926
5996
  asModules: (arr) => arr.indexOf('amd') > -1
5927
5997
  }, {
5928
5998
  asModules: (arr) => {
5929
- var i = arr.indexOf('amd');
5999
+ let i = arr.indexOf('amd');
5930
6000
  arr[i] = 'includejs';
5931
6001
  return arr;
5932
6002
  }
@@ -7644,7 +7714,8 @@ class ScriptParser extends BaseParser_1.BaseParser {
7644
7714
  dfrs.unshift(...asTextDfrs);
7645
7715
  return (0, async_1.async_whenAll)(dfrs).then(results => {
7646
7716
  let arr = (0, arr_1.arr_flattern)(results);
7647
- return ResourceInfo_1.ResourceInfo.merge(...arr);
7717
+ let merged = ResourceInfo_1.ResourceInfo.merge(...arr);
7718
+ return merged;
7648
7719
  });
7649
7720
  }
7650
7721
  accepts(type) {
@@ -8142,6 +8213,297 @@ MaskJsHandler.PathResolver = null;
8142
8213
  // end:source ./ModuleSimplified.js
8143
8214
 
8144
8215
 
8216
+ // source ./ModuleSimplified.js
8217
+ var _src_handlers_script_copy_js_CopyJsParser;
8218
+ (function () {
8219
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
8220
+ var define = null;
8221
+ var exports = _src_handlers_script_copy_js_CopyJsParser != null ? _src_handlers_script_copy_js_CopyJsParser : {};
8222
+ var module = { exports: exports };
8223
+
8224
+ "use strict";
8225
+ Object.defineProperty(exports, "__esModule", { value: true });
8226
+ exports.CopyJsParser = void 0;
8227
+ const BaseParser_1 = _src_handlers_base_BaseParser;
8228
+ class CopyJsParser extends BaseParser_1.BaseParser {
8229
+ getDependencies(ast, ownerResource) {
8230
+ return null;
8231
+ }
8232
+ }
8233
+ exports.CopyJsParser = CopyJsParser;
8234
+ ;
8235
+ //# sourceMappingURL=CopyJsParser.js.map
8236
+ //# sourceMappingURL=CopyJsParser.ts.map;
8237
+
8238
+ function __isObj(x) {
8239
+ return x != null && typeof x === 'object' && x.constructor === Object;
8240
+ }
8241
+ if (_src_handlers_script_copy_js_CopyJsParser === module.exports) {
8242
+ // do nothing if
8243
+ } else if (__isObj(_src_handlers_script_copy_js_CopyJsParser) && __isObj(module.exports)) {
8244
+ Object.assign(_src_handlers_script_copy_js_CopyJsParser, module.exports);
8245
+ } else {
8246
+ _src_handlers_script_copy_js_CopyJsParser = module.exports;
8247
+ }
8248
+
8249
+ ;
8250
+ }());
8251
+
8252
+ // end:source ./ModuleSimplified.js
8253
+
8254
+
8255
+ // source ./ModuleSimplified.js
8256
+ var _src_handlers_script_copy_js_CopyJsRewriter;
8257
+ (function () {
8258
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
8259
+ var define = null;
8260
+ var exports = _src_handlers_script_copy_js_CopyJsRewriter != null ? _src_handlers_script_copy_js_CopyJsRewriter : {};
8261
+ var module = { exports: exports };
8262
+
8263
+ "use strict";
8264
+ Object.defineProperty(exports, "__esModule", { value: true });
8265
+ exports.CopyJsRewriter = void 0;
8266
+ const BaseRewriter_1 = _src_handlers_base_BaseRewriter;
8267
+ class CopyJsRewriter extends BaseRewriter_1.BaseRewriter {
8268
+ rewritePartial(content, ownerResource) {
8269
+ }
8270
+ rewriteResource(resource) {
8271
+ }
8272
+ accepts(type) {
8273
+ return type === 'mask';
8274
+ }
8275
+ }
8276
+ exports.CopyJsRewriter = CopyJsRewriter;
8277
+ ;
8278
+ //# sourceMappingURL=CopyJsRewriter.js.map
8279
+ //# sourceMappingURL=CopyJsRewriter.ts.map;
8280
+
8281
+ function __isObj(x) {
8282
+ return x != null && typeof x === 'object' && x.constructor === Object;
8283
+ }
8284
+ if (_src_handlers_script_copy_js_CopyJsRewriter === module.exports) {
8285
+ // do nothing if
8286
+ } else if (__isObj(_src_handlers_script_copy_js_CopyJsRewriter) && __isObj(module.exports)) {
8287
+ Object.assign(_src_handlers_script_copy_js_CopyJsRewriter, module.exports);
8288
+ } else {
8289
+ _src_handlers_script_copy_js_CopyJsRewriter = module.exports;
8290
+ }
8291
+
8292
+ ;
8293
+ }());
8294
+
8295
+ // end:source ./ModuleSimplified.js
8296
+
8297
+
8298
+ // source ./ModuleSimplified.js
8299
+ var _src_handlers_script_copy_js_CopyJsBuilder;
8300
+ (function () {
8301
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
8302
+ var define = null;
8303
+ var exports = _src_handlers_script_copy_js_CopyJsBuilder != null ? _src_handlers_script_copy_js_CopyJsBuilder : {};
8304
+ var module = { exports: exports };
8305
+
8306
+ "use strict";
8307
+ Object.defineProperty(exports, "__esModule", { value: true });
8308
+ exports.CopyJsBuilder = void 0;
8309
+ const alot_1 = require("alot");
8310
+ const BaseScriptBuilder_1 = _src_handlers_script_base_BaseScriptBuilder;
8311
+ const OutputResources_1 = _src_class_OutputResources;
8312
+ const atma_utils_1 = require("atma-utils");
8313
+ const path_1 = _src_utils_path;
8314
+ const Configuration_1 = _src_config_Configuration;
8315
+ /**
8316
+ * Primary purpose of this builder is to copy source files to the output folder.
8317
+ * Atma IO middlewares are used to compile/transpile the files.
8318
+ *
8319
+ * For now the accent is made for Typescript files.
8320
+ */
8321
+ class CopyJsBuilder extends BaseScriptBuilder_1.BaseScriptBuilder {
8322
+ wrapModule(resource, outputItem) {
8323
+ let { content, dependencies } = resource;
8324
+ let offset = 0;
8325
+ dependencies && dependencies.filter(x => x.pos != null && (0, path_1.path_isRelative)(x.url)).forEach(dep => {
8326
+ let resUrl = new atma_utils_1.class_Uri(resource.url);
8327
+ let resDep = new atma_utils_1.class_Uri(dep.url);
8328
+ let url = resUrl.combine(resDep).toLocalFile();
8329
+ let start = dep.pos + offset + 1;
8330
+ let c = content[start - 1];
8331
+ let end = content.indexOf(c, start);
8332
+ let oldLength = end - start;
8333
+ let newLength = url.length;
8334
+ content = content.substring(0, start) + url + content.substring(end);
8335
+ offset += newLength - oldLength;
8336
+ });
8337
+ return content;
8338
+ }
8339
+ async buildRoot(root, outputDependencies) {
8340
+ let outputResources = this.solution.outputResources;
8341
+ outputResources.items = await (0, alot_1.default)(outputResources.items)
8342
+ .mapManyAsync(async (item) => {
8343
+ if (item.resource.isGlob !== true) {
8344
+ return [item];
8345
+ }
8346
+ // Normal output
8347
+ let copyItems = await (0, alot_1.default)(item.resources)
8348
+ .mapMany(resource => {
8349
+ return this.createOutputItems(item, resource);
8350
+ })
8351
+ .toArrayAsync();
8352
+ return copyItems;
8353
+ }).toArrayAsync();
8354
+ }
8355
+ getRootContent(root, outputDependencies) {
8356
+ return root.content;
8357
+ }
8358
+ accepts(resource) {
8359
+ if (resource.type !== 'js') {
8360
+ return false;
8361
+ }
8362
+ return resource.isGlob === true;
8363
+ }
8364
+ async createOutputItems(parent, resource) {
8365
+ var _a;
8366
+ let solution = this.solution;
8367
+ let rewriteToRelativeUrls = {};
8368
+ if (((_a = resource.dependencies) === null || _a === void 0 ? void 0 : _a.length) > 0) {
8369
+ let appBase = this.solution.opts.base;
8370
+ (0, alot_1.default)(resource.dependencies)
8371
+ .forEach(dep => {
8372
+ if (dep.resource == null) {
8373
+ return;
8374
+ }
8375
+ if (dep.resource.filename.startsWith(appBase) === false) {
8376
+ // is project dependency
8377
+ return;
8378
+ }
8379
+ let relativePath = (0, path_1.path_toRelative)(dep.resource.filename, resource.filename);
8380
+ if (relativePath == null || /(..\/)*?\/?node_modules/.test(relativePath)) {
8381
+ return;
8382
+ }
8383
+ relativePath = (0, path_1.path_changeExtension)(relativePath, null);
8384
+ relativePath = relativePath.startsWith('.')
8385
+ ? relativePath
8386
+ : './' + relativePath;
8387
+ rewriteToRelativeUrls[dep.url] = relativePath;
8388
+ })
8389
+ .toArray();
8390
+ resource.content = rewriteUrls(resource.content, rewriteToRelativeUrls);
8391
+ }
8392
+ let result = [
8393
+ createOutputItem(cloneWithExtension(resource, 'js'))
8394
+ ];
8395
+ let extra = [{
8396
+ ext: 'ts.map',
8397
+ output: 'js.map',
8398
+ }, {
8399
+ ext: 'd.ts',
8400
+ output: 'd.ts',
8401
+ }];
8402
+ let readFile = Configuration_1.Configuration.Instance.get('readFile');
8403
+ await (0, alot_1.default)(extra).forEachAsync(async (x) => {
8404
+ let cloned = cloneWithExtension(resource, x.ext);
8405
+ cloned.content = await readFile(cloned.filename);
8406
+ cloned.content = rewriteUrls(cloned.content, rewriteToRelativeUrls);
8407
+ result.push(createOutputItem(cloneWithExtension(cloned, x.output)));
8408
+ if (x.ext === 'ts.map' && cloned.content != null) {
8409
+ let outputItem = result[result.length - 1];
8410
+ let source = resource.filename;
8411
+ let target = outputItem.resource.filename;
8412
+ let rel = (0, path_1.path_toRelative)(source, target);
8413
+ outputItem.resource.content = outputItem.resource.content.replace(/"sources":\["[^"]+"\]/, `"sources":["${rel}"]`);
8414
+ }
8415
+ }).toArrayAsync({ threads: 1 });
8416
+ function createOutputItem(resource) {
8417
+ return new OutputResources_1.OutputItem({
8418
+ page: parent.page,
8419
+ bundle: parent.bundle,
8420
+ type: parent.type,
8421
+ solution: solution,
8422
+ resources: [resource],
8423
+ isGlob: false,
8424
+ resource: resource.toTarget(solution)
8425
+ });
8426
+ }
8427
+ function cloneWithExtension(resource, ext) {
8428
+ let cloned = resource.clone();
8429
+ cloned.filename = (0, path_1.path_changeExtension)(cloned.filename, ext);
8430
+ cloned.url = (0, path_1.path_changeExtension)(cloned.url, ext);
8431
+ return cloned;
8432
+ }
8433
+ function rewriteUrls(content, rewriteToRelativeUrls) {
8434
+ for (let key in rewriteToRelativeUrls) {
8435
+ content = content.replaceAll(key, rewriteToRelativeUrls[key]);
8436
+ }
8437
+ return content;
8438
+ }
8439
+ return result;
8440
+ }
8441
+ }
8442
+ exports.CopyJsBuilder = CopyJsBuilder;
8443
+ ;
8444
+ //# sourceMappingURL=CopyJsBuilder.js.map
8445
+ //# sourceMappingURL=CopyJsBuilder.ts.map;
8446
+
8447
+ function __isObj(x) {
8448
+ return x != null && typeof x === 'object' && x.constructor === Object;
8449
+ }
8450
+ if (_src_handlers_script_copy_js_CopyJsBuilder === module.exports) {
8451
+ // do nothing if
8452
+ } else if (__isObj(_src_handlers_script_copy_js_CopyJsBuilder) && __isObj(module.exports)) {
8453
+ Object.assign(_src_handlers_script_copy_js_CopyJsBuilder, module.exports);
8454
+ } else {
8455
+ _src_handlers_script_copy_js_CopyJsBuilder = module.exports;
8456
+ }
8457
+
8458
+ ;
8459
+ }());
8460
+
8461
+ // end:source ./ModuleSimplified.js
8462
+
8463
+
8464
+ // source ./ModuleSimplified.js
8465
+ var _src_handlers_script_copy_js_CopyJsHandler;
8466
+ (function () {
8467
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
8468
+ var define = null;
8469
+ var exports = _src_handlers_script_copy_js_CopyJsHandler != null ? _src_handlers_script_copy_js_CopyJsHandler : {};
8470
+ var module = { exports: exports };
8471
+
8472
+ "use strict";
8473
+ Object.defineProperty(exports, "__esModule", { value: true });
8474
+ exports.CopyJsHandler = void 0;
8475
+ const BaseHandler_1 = _src_handlers_base_BaseHandler;
8476
+ const CopyJsParser_1 = _src_handlers_script_copy_js_CopyJsParser;
8477
+ const CopyJsRewriter_1 = _src_handlers_script_copy_js_CopyJsRewriter;
8478
+ const CopyJsBuilder_1 = _src_handlers_script_copy_js_CopyJsBuilder;
8479
+ class CopyJsHandler extends BaseHandler_1.BaseHandler {
8480
+ }
8481
+ exports.CopyJsHandler = CopyJsHandler;
8482
+ CopyJsHandler.Parser = CopyJsParser_1.CopyJsParser;
8483
+ CopyJsHandler.Rewriter = CopyJsRewriter_1.CopyJsRewriter;
8484
+ CopyJsHandler.Builder = CopyJsBuilder_1.CopyJsBuilder;
8485
+ CopyJsHandler.PathResolver = null;
8486
+ ;
8487
+ //# sourceMappingURL=CopyJsHandler.js.map
8488
+ //# sourceMappingURL=CopyJsHandler.ts.map;
8489
+
8490
+ function __isObj(x) {
8491
+ return x != null && typeof x === 'object' && x.constructor === Object;
8492
+ }
8493
+ if (_src_handlers_script_copy_js_CopyJsHandler === module.exports) {
8494
+ // do nothing if
8495
+ } else if (__isObj(_src_handlers_script_copy_js_CopyJsHandler) && __isObj(module.exports)) {
8496
+ Object.assign(_src_handlers_script_copy_js_CopyJsHandler, module.exports);
8497
+ } else {
8498
+ _src_handlers_script_copy_js_CopyJsHandler = module.exports;
8499
+ }
8500
+
8501
+ ;
8502
+ }());
8503
+
8504
+ // end:source ./ModuleSimplified.js
8505
+
8506
+
8145
8507
  // source ./ModuleSimplified.js
8146
8508
  var _src_handlers_script_ScriptBuilder;
8147
8509
  (function () {
@@ -8160,10 +8522,12 @@ const AmdJsHandler_1 = _src_handlers_script_amd_js_AmdJsHandler;
8160
8522
  const IncludeJsHandler_1 = _src_handlers_script_include_js_IncludeJsHandler;
8161
8523
  const MaskJsHandler_1 = _src_handlers_script_mask_js_MaskJsHandler;
8162
8524
  const ImportJsHandler_1 = _src_handlers_script_import_js_ImportJsHandler;
8525
+ const CopyJsHandler_1 = _src_handlers_script_copy_js_CopyJsHandler;
8163
8526
  class ScriptBuilder extends BaseBuilder_1.BaseBuilder {
8164
8527
  constructor() {
8165
8528
  super(...arguments);
8166
8529
  this.builders = [
8530
+ new CopyJsHandler_1.CopyJsHandler.Builder(this.solution, this.handler),
8167
8531
  new GlobalJsHandler_1.GlobalJsHandler.Builder(this.solution, this.handler),
8168
8532
  new CommonJsHandler_1.CommonJsHandler.Builder(this.solution, this.handler),
8169
8533
  new AmdJsHandler_1.AmdJsHandler.Builder(this.solution, this.handler),
@@ -8184,8 +8548,9 @@ class ScriptBuilder extends BaseBuilder_1.BaseBuilder {
8184
8548
  else {
8185
8549
  const out = resArr.map(res => {
8186
8550
  let builder = this.builders.find(x => x.accepts(res));
8187
- if (builder == null)
8551
+ if (builder == null) {
8188
8552
  throw new Error('Module Builder not found for ' + res.url);
8553
+ }
8189
8554
  return builder.wrapModule(res, outputItem, otherOutputItems);
8190
8555
  });
8191
8556
  code = out.join('\n');
@@ -11003,6 +11368,19 @@ exports.Parser = {
11003
11368
  };
11004
11369
  function getDependenciesInternal(resource, solution) {
11005
11370
  assert(typeof resource.url === 'string', 'Path is expected');
11371
+ if (resource.isGlob) {
11372
+ let paths = resource.content;
11373
+ let resInfos = paths.map(path => {
11374
+ return {
11375
+ type: resource.type,
11376
+ url: path,
11377
+ module: resource.module,
11378
+ page: resource.page
11379
+ };
11380
+ });
11381
+ let result = { dependencies: resInfos };
11382
+ return (0, async_1.async_resolve)(result);
11383
+ }
11006
11384
  let ext = (0, path_1.path_getExtension)(resource.url);
11007
11385
  let handler = solution.handlers.find(x => x.parser.accepts(resource.type) || x.parser.accepts(ext));
11008
11386
  if (handler == null) {
@@ -11226,17 +11604,26 @@ var ResourceLoader;
11226
11604
  }
11227
11605
  try {
11228
11606
  let start = Date.now();
11229
- let reader = Configuration_1.Configuration.Instance.get('readFile');
11607
+ let reader = this.resource.isGlob
11608
+ ? Configuration_1.Configuration.Instance.get('readDirectory')
11609
+ : Configuration_1.Configuration.Instance.get('readFile');
11230
11610
  let content = await reader(this.resource.filename, this.opts);
11611
+ if (this.resource.isGlob && Array.isArray(content) && this.solution.opts.ignore) {
11612
+ let rgxArr = this.solution.opts.ignore.map(path => new RegExp(path, 'i'));
11613
+ content = content.filter(path => {
11614
+ return rgxArr.some(rgx => rgx.test(path)) === false;
11615
+ });
11616
+ }
11231
11617
  let handler = this.solution.handlers.find(x => x.parser.accepts(this.resource.type));
11232
- if (((_a = handler === null || handler === void 0 ? void 0 : handler.parser) === null || _a === void 0 ? void 0 : _a.transpile) !== null) {
11618
+ if (((_a = handler === null || handler === void 0 ? void 0 : handler.parser) === null || _a === void 0 ? void 0 : _a.transpile) != null) {
11233
11619
  let result = await handler.parser.transpile(content, this.resource);
11234
11620
  content = (_b = result === null || result === void 0 ? void 0 : result.content) !== null && _b !== void 0 ? _b : content;
11235
11621
  }
11236
11622
  let end = Date.now();
11237
- this.solution.reporter.print((0, color_1.color)(` cyan<${end - start}> ms \n`));
11623
+ this.solution.reporter.print((0, color_1.color)(` cyan<${end - start}> ms`));
11238
11624
  this.resource.content = content;
11239
- if (this.resource.type === 'data' || this.resource.type === 'load') {
11625
+ if (this.resource.type === 'data') {
11626
+ this.solution.reporter.print('\n');
11240
11627
  this.promise.resolve(this);
11241
11628
  return;
11242
11629
  }
@@ -11248,12 +11635,15 @@ var ResourceLoader;
11248
11635
  }
11249
11636
  processChildren() {
11250
11637
  if (this.shouldSkipChildren()) {
11638
+ this.solution.reporter.print(` (skip deps)`);
11251
11639
  this.promise.resolve(this);
11252
11640
  return;
11253
11641
  }
11254
11642
  Parser_1.Parser
11255
11643
  .getDependencies(this.resource, this.solution)
11256
11644
  .then(result => {
11645
+ var _a;
11646
+ this.solution.reporter.print((0, color_1.color)(` cyan<${(_a = result.dependencies) === null || _a === void 0 ? void 0 : _a.length}> dep\n`));
11257
11647
  this.loadChildren(result).catch(err => {
11258
11648
  this.promise.reject(err);
11259
11649
  });
@@ -11499,14 +11889,14 @@ exports.Builder = void 0;
11499
11889
  const Middlewares_1 = _src_class_Middlewares;
11500
11890
  const path_1 = _src_utils_path;
11501
11891
  const async_1 = _src_utils_async;
11502
- const alot = require("alot");
11892
+ const alot_1 = require("alot");
11503
11893
  exports.Builder = {
11504
11894
  build(resources, solution) {
11505
11895
  return Middlewares_1._middlewares
11506
11896
  .run('buildResources', resources, solution)
11507
11897
  .then(arr => {
11508
- resources = arr || resources;
11509
- solution.outputResources.prepair(resources);
11898
+ resources = arr !== null && arr !== void 0 ? arr : resources;
11899
+ solution.outputResources.prepare(resources);
11510
11900
  return Middlewares_1._middlewares
11511
11901
  .run('rewriteDependencies', resources, solution)
11512
11902
  .then(() => rewriteDependenciesInternal(resources))
@@ -11516,9 +11906,9 @@ exports.Builder = {
11516
11906
  .then(() => solution.outputResources.getAll());
11517
11907
  });
11518
11908
  function rewriteDependenciesInternal(resources) {
11519
- var dfrs = resources.map(resource => {
11520
- var ext = (0, path_1.path_getExtension)(resource.url);
11521
- var handler = solution.handlers.find(x => x.rewriter.accepts(ext));
11909
+ let promises = resources.map(resource => {
11910
+ let ext = (0, path_1.path_getExtension)(resource.url);
11911
+ let handler = solution.handlers.find(x => x.rewriter.accepts(ext));
11522
11912
  if (handler == null) {
11523
11913
  handler = solution.handlers.find(x => x.rewriter.accepts(resource.type));
11524
11914
  }
@@ -11527,12 +11917,14 @@ exports.Builder = {
11527
11917
  }
11528
11918
  return handler.rewriter.rewriteResource(resource);
11529
11919
  });
11530
- return (0, async_1.async_whenAll)(dfrs);
11920
+ return (0, async_1.async_whenAll)(promises);
11531
11921
  }
11532
11922
  function rewriteRoot() {
11533
11923
  return (0, async_1.async_run)(() => {
11534
- var input = solution.outputResources.rootInput, output = solution.outputResources.rootOutput, ext = (0, path_1.path_getExtension)(input.url);
11535
- var handler = solution.handlers.find(x => x.rewriter.accepts(input.type) || x.rewriter.accepts(ext));
11924
+ let input = solution.outputResources.rootInput;
11925
+ let output = solution.outputResources.rootOutput;
11926
+ let ext = (0, path_1.path_getExtension)(input.url);
11927
+ let handler = solution.handlers.find(x => x.rewriter.accepts(input.type) || x.rewriter.accepts(ext));
11536
11928
  if (handler == null || handler.rewriter.rewriteRoot == null) {
11537
11929
  //throw new Error(`RootRewriter is not found for a resource ${input.url} and type ${input.type}`);
11538
11930
  return;
@@ -11541,9 +11933,9 @@ exports.Builder = {
11541
11933
  });
11542
11934
  }
11543
11935
  function buildOutputItems() {
11544
- var items = solution.outputResources.items;
11545
- return alot(items).mapAsync(item => {
11546
- var otherOutputItems = items.filter(x => {
11936
+ let items = solution.outputResources.items;
11937
+ return (0, alot_1.default)(items).mapAsync(item => {
11938
+ let otherOutputItems = items.filter(x => {
11547
11939
  if (x === item)
11548
11940
  return false;
11549
11941
  if (x.page != item.page)
@@ -11564,8 +11956,8 @@ exports.Builder = {
11564
11956
  if (outputItem.resource.content) {
11565
11957
  return;
11566
11958
  }
11567
- var ext = (0, path_1.path_getExtension)(outputItem.resource.url);
11568
- var handler = solution.handlers.find(x => x.builder.accepts(outputItem.type));
11959
+ let ext = (0, path_1.path_getExtension)(outputItem.resource.url);
11960
+ let handler = solution.handlers.find(x => x.builder.accepts(outputItem.type));
11569
11961
  if (handler == null) {
11570
11962
  handler = solution.handlers.find(x => x.builder.accepts(ext));
11571
11963
  }
@@ -11575,10 +11967,11 @@ exports.Builder = {
11575
11967
  return handler.builder.createModule(outputItem, otherOutputItems);
11576
11968
  }
11577
11969
  function buildRoot() {
11578
- var main = solution.outputResources.rootOutput;
11579
- var dependencies = solution.outputResources.getForPage(solution.opts.mainPage);
11580
- var ext = (0, path_1.path_getExtension)(main.url);
11581
- var handler = solution.handlers.find(x => x.builder.accepts(main.type) || x.builder.accepts(ext));
11970
+ var _a;
11971
+ let main = (_a = solution.outputResources.rootOutput) !== null && _a !== void 0 ? _a : solution.outputResources.rootInput;
11972
+ let dependencies = solution.outputResources.getForPage(solution.opts.mainPage);
11973
+ let ext = (0, path_1.path_getExtension)(main.url);
11974
+ let handler = solution.handlers.find(x => x.builder.accepts(main.type) || x.builder.accepts(ext));
11582
11975
  if (handler == null || handler.builder.buildRoot == null) {
11583
11976
  throw new Error(`RootBuilder is not found for a resource ${main.url} and type ${main.type}`);
11584
11977
  }
@@ -11632,11 +12025,6 @@ const tree_1 = _src_utils_tree;
11632
12025
  const Builder_1 = _src_builder_Builder;
11633
12026
  const color_1 = _src_utils_color;
11634
12027
  class Bundler extends atma_utils_1.class_EventEmitter {
11635
- constructor(path, opts) {
11636
- super();
11637
- global.__$bundler = this;
11638
- this.solution = new Solution_1.Solution(path, opts);
11639
- }
11640
12028
  static clearCache() {
11641
12029
  Loader_1.Loader.clearCache();
11642
12030
  if (global_1.io.File.middleware) {
@@ -11652,8 +12040,15 @@ class Bundler extends atma_utils_1.class_EventEmitter {
11652
12040
  static get Config() {
11653
12041
  return Configuration_1.Configuration.Instance;
11654
12042
  }
12043
+ constructor(path, opts) {
12044
+ super();
12045
+ global.__$bundler = this;
12046
+ this.solution = new Solution_1.Solution(path, opts);
12047
+ }
11655
12048
  getResourceTree(opts) {
11656
- var solution = this.solution, type = solution.opts.type, path = solution.path;
12049
+ let solution = this.solution;
12050
+ let type = solution.opts.type;
12051
+ let path = solution.path;
11657
12052
  return Loader_1.Loader
11658
12053
  .load(type, path, opts, solution)
11659
12054
  .then(x => x.toJSON());
@@ -11662,7 +12057,9 @@ class Bundler extends atma_utils_1.class_EventEmitter {
11662
12057
  return new Bundler(path, opts).getResourceTree();
11663
12058
  }
11664
12059
  getResources(opts) {
11665
- var solution = this.solution, type = solution.opts.type, path = solution.path;
12060
+ let solution = this.solution;
12061
+ let type = solution.opts.type;
12062
+ let path = solution.path;
11666
12063
  return Loader_1.Loader.load(type, path, opts, solution).then(resource => {
11667
12064
  return (0, res_1.res_flattern)(resource, solution.opts.dependencies).map(x => x);
11668
12065
  });
@@ -11671,16 +12068,28 @@ class Bundler extends atma_utils_1.class_EventEmitter {
11671
12068
  return new Bundler(path, opts).getResources();
11672
12069
  }
11673
12070
  build(opts) {
11674
- var solution = this.solution, type = solution.opts.type, path = solution.path, shouldRebuild = false, isBuilding = false, isRebuilding = false, rootResource = null, self = this;
12071
+ let solution = this.solution;
12072
+ let type = solution.opts.type;
12073
+ let path = solution.path;
12074
+ let shouldRebuild = false;
12075
+ let isBuilding = false;
12076
+ let isRebuilding = false;
12077
+ let rootResource = null;
12078
+ let self = this;
11675
12079
  function build(resource) {
11676
12080
  isBuilding = true;
11677
- var resources = (0, res_1.res_flattern)(resource, solution.opts.dependencies);
12081
+ let resources = (0, res_1.res_flattern)(resource, solution.opts.dependencies);
11678
12082
  return (0, tree_1.tree_async)({
11679
- resources,
11680
12083
  reporter: solution.reporter,
11681
- action: () => Builder_1.Builder.build(resources, solution),
11682
- message: (treeInfo, seconds) => (0, color_1.color)(`Created bold<yellow<${treeInfo.count}>> files in bold<yellow<${seconds}>> sec.`)
11683
- }).done(buildComplete).fail(buildFailed);
12084
+ action: () => {
12085
+ return Builder_1.Builder.build(resources, solution);
12086
+ },
12087
+ message: (treeInfo, seconds) => {
12088
+ return (0, color_1.color)(`Created bold<yellow<${treeInfo.count}>> files in bold<yellow<${seconds}>> sec.`);
12089
+ }
12090
+ })
12091
+ .done(buildComplete)
12092
+ .fail(buildFailed);
11684
12093
  }
11685
12094
  function buildComplete(resources) {
11686
12095
  isBuilding = false;
@@ -11740,8 +12149,8 @@ class Bundler extends atma_utils_1.class_EventEmitter {
11740
12149
  return new Bundler(path, opts).build(opts);
11741
12150
  }
11742
12151
  static process(path, opts) {
11743
- var bundler = new Bundler(path, opts);
11744
- var solution = bundler.solution;
12152
+ let bundler = new Bundler(path, opts);
12153
+ let solution = bundler.solution;
11745
12154
  function builderComplete(resources) {
11746
12155
  resources.forEach(res => {
11747
12156
  global_1.io.File.write(res.filename, res.content);
@@ -11772,8 +12181,8 @@ class Bundler extends atma_utils_1.class_EventEmitter {
11772
12181
  getDependencies(content, opts = { type: 'js' }) {
11773
12182
  if (typeof opts === 'string')
11774
12183
  opts = { type: opts };
11775
- var solution = new Solution_1.Solution('', opts);
11776
- var resource = new Resource_1.Resource({ type: opts.type, content: content }, null, solution);
12184
+ let solution = new Solution_1.Solution('', opts);
12185
+ let resource = new Resource_1.Resource({ type: opts.type, content: content }, null, solution);
11777
12186
  return Parser_1.Parser.getDependencies(resource, solution);
11778
12187
  }
11779
12188
  };