UNPKG

107 kBJavaScriptView Raw
1
2// source ./RootModule.js
3(function(){
4
5 var _src_Directory = {};
6var _src_Env = {};
7var _src_ExportsGlob = {};
8var _src_ExportsSetts = {};
9var _src_File = {};
10var _src_FileFactory = {};
11var _src_FileHookRegistration = {};
12var _src_FileHooks = {};
13var _src_Watcher = {};
14var _src_global = {};
15var _src_middleware_json = {};
16var _src_transport_custom = {};
17var _src_transport_dir_transport = {};
18var _src_transport_file_transport = {};
19var _src_transport_filesystem_fs_dir = {};
20var _src_transport_filesystem_fs_file = {};
21var _src_transport_filesystem_transport = {};
22var _src_util_arr = {};
23var _src_util_cli = {};
24var _src_util_filesystem_util = {};
25var _src_util_glob = {};
26var _src_util_logger = {};
27var _src_util_obj = {};
28var _src_util_path = {};
29var _src_util_rgx = {};
30var _src_util_stack = {};
31var _src_util_uri = {};
32
33// source ./ModuleSimplified.js
34var _src_global;
35(function () {
36 var exports = {};
37 var module = { exports: exports };
38 "use strict";
39Object.defineProperty(exports, "__esModule", { value: true });
40var Class = require("atma-class");
41exports.Class = Class;
42var g = global;
43exports.global = g;
44var logger = g.logger || require('atma-logger');
45exports.logger = logger;
46var io = {};
47exports.io = io;
48;
49
50 function isObject(x) {
51 return x != null && typeof x === 'object' && x.constructor === Object;
52 }
53 if (isObject(_src_global) && isObject(module.exports)) {
54 Object.assign(_src_global, module.exports);
55 return;
56 }
57 _src_global = module.exports;
58}());
59// end:source ./ModuleSimplified.js
60
61
62// source ./ModuleSimplified.js
63var _src_Env;
64(function () {
65 var exports = {};
66 var module = { exports: exports };
67 "use strict";
68Object.defineProperty(exports, "__esModule", { value: true });
69var atma_utils_1 = require("atma-utils");
70var global_1 = _src_global;
71var os = require("os");
72var mainFile = new atma_utils_1.class_Uri(normalizePath(process.mainModule.filename));
73var platform = process.platform;
74var cwd = toDir(process.cwd());
75exports.Env = {
76 settings: {},
77 cwd: cwd,
78 applicationDir: new atma_utils_1.class_Uri(mainFile.toDir()),
79 currentDir: new atma_utils_1.class_Uri(cwd),
80 tmpDir: new atma_utils_1.class_Uri("file:///" + os.tmpdir + "/"),
81 newLine: os.EOL,
82 getTmpPath: function (filename) {
83 return exports.Env
84 .tmpDir
85 .combine(Date.now() + "-" + ((Math.random() * 10000) | 0) + "-" + filename)
86 .toString();
87 },
88 get appdataDir() {
89 var path;
90 switch (platform) {
91 case 'win32':
92 case 'win64':
93 path = process.env.APPDATA || process.env.HOME;
94 break;
95 case 'darwin':
96 path = process.env.HOME;
97 break;
98 default:
99 path = process.env.HOME;
100 break;
101 }
102 if (path == null) {
103 global_1.logger.error('<io.env> Unknown AppData Dir');
104 Object.defineProperty(this, 'appdataDir', {
105 value: this.applicationDir
106 });
107 return this.applicationDir;
108 }
109 path = new atma_utils_1.class_Uri(toDir(path));
110 if (platform === 'darwin')
111 path = path.combine('Library/Application Support/');
112 path = path.combine('.' + mainFile.file + '/');
113 Object.defineProperty(this, 'appdataDir', {
114 value: path
115 });
116 return path;
117 }
118};
119function toDir(path) {
120 return atma_utils_1.class_Uri.combine(normalizePath(path), '/');
121}
122function normalizePath(path) {
123 return path.replace(/\\/g, '/');
124}
125;
126
127 function isObject(x) {
128 return x != null && typeof x === 'object' && x.constructor === Object;
129 }
130 if (isObject(_src_Env) && isObject(module.exports)) {
131 Object.assign(_src_Env, module.exports);
132 return;
133 }
134 _src_Env = module.exports;
135}());
136// end:source ./ModuleSimplified.js
137
138
139// source ./ModuleSimplified.js
140var _src_Watcher;
141(function () {
142 var exports = {};
143 var module = { exports: exports };
144 "use strict";
145var __extends = (this && this.__extends) || (function () {
146 var extendStatics = function (d, b) {
147 extendStatics = Object.setPrototypeOf ||
148 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
149 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
150 return extendStatics(d, b);
151 };
152 return function (d, b) {
153 extendStatics(d, b);
154 function __() { this.constructor = d; }
155 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
156 };
157})();
158var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
159 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
160 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
161 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
162 return c > 3 && r && Object.defineProperty(target, key, r), r;
163};
164Object.defineProperty(exports, "__esModule", { value: true });
165var __fs = require("fs");
166var global_1 = _src_global;
167var event_CHANGE = 'change';
168var WATCHERS = {};
169exports.Watcher = {
170 watch: function (path, callback) {
171 if (WATCHERS[path]) {
172 WATCHERS[path].on(event_CHANGE, callback);
173 return;
174 }
175 if (__fs.existsSync(path) === false) {
176 global_1.logger.error('<watcher> File not exists', path);
177 return;
178 }
179 WATCHERS[path] = new FileWatcher(path);
180 WATCHERS[path].on(event_CHANGE, callback);
181 },
182 unwatch: function (path, callback) {
183 var watcher = WATCHERS[path];
184 if (watcher == null) {
185 global_1.logger.warn('<watcher> No exists', path);
186 return;
187 }
188 if (callback != null) {
189 watcher.off(event_CHANGE, callback);
190 if (watcher._listeners.length !== 0) {
191 return;
192 }
193 }
194 watcher.close();
195 delete WATCHERS[path];
196 }
197};
198var FileWatcher = /** @class */ (function (_super) {
199 __extends(FileWatcher, _super);
200 function FileWatcher(path) {
201 var _this = _super.call(this) || this;
202 _this.path = path;
203 _this.fswatcher = __fs.watch(path, _this.changed);
204 return _this;
205 }
206 FileWatcher.prototype.changed = function () {
207 if (this.timeout) {
208 clearTimeout(this.timeout);
209 }
210 this.timeout = setTimeout(this.reportChange, 100);
211 };
212 FileWatcher.prototype.reportChange = function () {
213 this.trigger(event_CHANGE, this.path);
214 };
215 FileWatcher.prototype.close = function () {
216 this.fswatcher.close();
217 this.off(event_CHANGE);
218 };
219 __decorate([
220 global_1.Class.deco.self
221 ], FileWatcher.prototype, "changed", null);
222 __decorate([
223 global_1.Class.deco.self
224 ], FileWatcher.prototype, "reportChange", null);
225 return FileWatcher;
226}(global_1.Class.EventEmitter));
227;
228;
229
230 function isObject(x) {
231 return x != null && typeof x === 'object' && x.constructor === Object;
232 }
233 if (isObject(_src_Watcher) && isObject(module.exports)) {
234 Object.assign(_src_Watcher, module.exports);
235 return;
236 }
237 _src_Watcher = module.exports;
238}());
239// end:source ./ModuleSimplified.js
240
241
242// source ./ModuleSimplified.js
243var _src_util_glob;
244(function () {
245 var exports = {};
246 var module = { exports: exports };
247 "use strict";
248var __extends = (this && this.__extends) || (function () {
249 var extendStatics = function (d, b) {
250 extendStatics = Object.setPrototypeOf ||
251 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
252 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
253 return extendStatics(d, b);
254 };
255 return function (d, b) {
256 extendStatics(d, b);
257 function __() { this.constructor = d; }
258 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
259 };
260})();
261Object.defineProperty(exports, "__esModule", { value: true });
262var global_1 = _src_global;
263function glob_getCalculatedPath(path, glob) {
264 var star = glob.indexOf('*'), slash = glob.lastIndexOf('/', star), strict = slash === -1 ? null : glob.substring(0, slash);
265 if (!slash)
266 return path;
267 var index = path.toLowerCase().indexOf(strict.toLowerCase());
268 if (index === -1) {
269 global_1.logger.warn('[substring not found]', path, strict);
270 return path;
271 }
272 return path.substring(index + strict.length);
273}
274exports.glob_getCalculatedPath = glob_getCalculatedPath;
275;
276function glob_matchPath(pattern /*String*/, path /*String*/) {
277 if (path[0] === '/')
278 path = path.substring(1);
279 if (pattern[0] === '/')
280 pattern = pattern.substring(1);
281 return glob_toRegExp(pattern).test(path);
282}
283exports.glob_matchPath = glob_matchPath;
284;
285function glob_parsePatterns(mix, out) {
286 if (mix == null)
287 return null;
288 if (out == null)
289 out = [];
290 if (Array.isArray(mix)) {
291 mix.forEach(function (x) {
292 glob_parsePatterns(x, out);
293 });
294 return out;
295 }
296 if (mix instanceof RegExp) {
297 out.push(mix);
298 return out;
299 }
300 if (typeof mix === 'string') {
301 var pattern = mix;
302 if (pattern[0] === '/') {
303 pattern = pattern.substring(1);
304 }
305 var _a = glob_parseDirs(pattern), depth = _a[0], rootCount = _a[1], root = _a[2];
306 var regexp = glob_toRegExp(pattern);
307 regexp.depth = depth;
308 regexp.rootCount = rootCount;
309 regexp.root = root;
310 out.push(regexp);
311 return out;
312 }
313 global_1.logger.error('<glob> Unsupported pattern', mix);
314 return out;
315}
316exports.glob_parsePatterns = glob_parsePatterns;
317;
318function glob_parseDirs(pattern) {
319 if (pattern[0] === '/')
320 pattern = pattern.substring(1);
321 var depth = 0, dirs = pattern.split('/');
322 depth = pattern.indexOf('**') !== -1
323 ? Infinity
324 : dirs.length;
325 // remove file
326 dirs.pop();
327 for (var i = 0; i < dirs.length; i++) {
328 if (dirs[i].indexOf('*') === -1)
329 continue;
330 dirs.splice(i);
331 }
332 return [depth, dirs.length, dirs.join('/').toLowerCase()];
333}
334exports.glob_parseDirs = glob_parseDirs;
335;
336function glob_toRegExp(glob) {
337 var specialChars = "\\^$*+?.()|{}[]", stream = '', i = -1, length = glob.length;
338 glob = glob.replace(/(\*\*\/){2,}/g, '**/');
339 while (++i < length) {
340 var c = glob[i];
341 switch (c) {
342 case '?':
343 stream += '.';
344 break;
345 case '*':
346 if (glob[i + 1] === '*') {
347 if (i === 0 && /[\\\/]/.test(glob[i + 2])) {
348 stream += '.+';
349 i += 2;
350 }
351 stream += '.+';
352 i++;
353 break;
354 }
355 stream += '[^/]+';
356 break;
357 case '{':
358 var close = glob.indexOf('}', i);
359 if (~close) {
360 stream += '(' + glob.substring(i + 1, close).replace(/,/g, '|') + ')';
361 i = close;
362 break;
363 }
364 stream += c;
365 break;
366 case '[':
367 var close = glob.indexOf(']', i);
368 if (~close) {
369 stream = glob.substring(i, close);
370 i = close;
371 break;
372 }
373 stream += c;
374 break;
375 default:
376 if (~specialChars.indexOf(c)) {
377 stream += '\\';
378 }
379 stream += c;
380 break;
381 }
382 }
383 stream = '^' + stream + '$';
384 return new GlobRegExp(stream, 'i');
385}
386exports.glob_toRegExp = glob_toRegExp;
387;
388/**
389 * [as dir] '/dev/*.js' -> '/dev/'
390 */
391function glob_getStrictPath(path) {
392 var index = path.indexOf('*');
393 if (index === -1) {
394 global_1.logger.error('glob.js [path is not a glob pattern]', path);
395 return null;
396 }
397 return path.substring(0, path.lastIndexOf('/', index) + 1);
398}
399exports.glob_getStrictPath = glob_getStrictPath;
400;
401/**
402 * 'c:/dev/*.js' -> '*.js'
403 */
404function glob_getRelativePath(path) {
405 var index = path.indexOf('*');
406 if (index === -1) {
407 global_1.logger.error('glob.js [path is not a glob pattern]', path);
408 return null;
409 }
410 return path.substring(path.lastIndexOf('/', index) + 1);
411}
412exports.glob_getRelativePath = glob_getRelativePath;
413;
414var GlobRegExp = /** @class */ (function (_super) {
415 __extends(GlobRegExp, _super);
416 function GlobRegExp() {
417 return _super !== null && _super.apply(this, arguments) || this;
418 }
419 return GlobRegExp;
420}(RegExp));
421exports.GlobRegExp = GlobRegExp;
422;
423
424 function isObject(x) {
425 return x != null && typeof x === 'object' && x.constructor === Object;
426 }
427 if (isObject(_src_util_glob) && isObject(module.exports)) {
428 Object.assign(_src_util_glob, module.exports);
429 return;
430 }
431 _src_util_glob = module.exports;
432}());
433// end:source ./ModuleSimplified.js
434
435
436// source ./ModuleSimplified.js
437var _src_util_path;
438(function () {
439 var exports = {};
440 var module = { exports: exports };
441 "use strict";
442Object.defineProperty(exports, "__esModule", { value: true });
443var global_1 = _src_global;
444var atma_utils_1 = require("atma-utils");
445function path_getProtocol(path) {
446 var i = path.indexOf(':');
447 if (i === -1 || path[i + 1] !== '/' || path[i + 2] !== '/') {
448 return null;
449 }
450 return path.substring(0, i);
451}
452exports.path_getProtocol = path_getProtocol;
453function path_getUri(path, base) {
454 if (typeof path !== 'string') {
455 path = path.toString();
456 }
457 path = path_normalize(path);
458 if (path[0] === '/') {
459 path = path.substring(1);
460 }
461 var uri = new atma_utils_1.class_Uri(path);
462 if (uri.isRelative() === false) {
463 return uri;
464 }
465 if (base) {
466 return new atma_utils_1.class_Uri(base).combine(uri);
467 }
468 if (global_1.io.env) {
469 return global_1.io.env.currentDir.combine(uri);
470 }
471 return new atma_utils_1.class_Uri('file://' + process.cwd() + '/')
472 .combine(uri);
473}
474exports.path_getUri = path_getUri;
475function path_combine(_1, _2) {
476 if (!_1)
477 return _2;
478 if (!_2)
479 return _1;
480 if (_2[0] === '/')
481 _2 = _2.substring(1);
482 if (_1[_1.length - 1] === '/')
483 return _1 + _2;
484 return _1 + '/' + _2;
485}
486exports.path_combine = path_combine;
487function path_getDir(url) {
488 if (!url)
489 return '/';
490 var index = url.lastIndexOf('/');
491 return index === -1
492 ? ''
493 : url.substring(index + 1, -index);
494}
495exports.path_getDir = path_getDir;
496function path_isSubDir(basepath, path) {
497 var basedir = path_getDir(basepath), dir = path_getDir(path);
498 return dir
499 .toLowerCase()
500 .indexOf(basedir.toLowerCase()) === 0;
501}
502exports.path_isSubDir = path_isSubDir;
503function path_resolveUri(url, parentLocation, base) {
504 if (url[0] === '/') {
505 parentLocation = base;
506 url = url.substring(1);
507 }
508 var uri = new atma_utils_1.class_Uri(url);
509 return uri.isRelative()
510 ? (new atma_utils_1.class_Uri(parentLocation)).combine(uri)
511 : uri;
512}
513exports.path_resolveUri = path_resolveUri;
514function path_resolveAppUri(url, parentPath) {
515 if (url[0] === '/')
516 return url;
517 if (url.substring(0, 2) === './')
518 url = url.substring(2);
519 if (!parentPath || url.substring(0, 4) === 'file')
520 return '/';
521 var index = parentPath.lastIndexOf('/');
522 return (index === -1
523 ? '/'
524 : (parentPath.substring(index + 1, -index)))
525 + url;
526}
527exports.path_resolveAppUri = path_resolveAppUri;
528function path_ensureTrailingSlash(path) {
529 if (path[path.length - 1] === '/')
530 return path;
531 return path + '/';
532}
533exports.path_ensureTrailingSlash = path_ensureTrailingSlash;
534;
535function path_normalize(str) {
536 str = str
537 .replace(/\\/g, '/')
538 .replace(/^\.\//, '');
539 var double = /\/{2,}/g;
540 var protocolMatched = false;
541 do {
542 var match = double.exec(str);
543 if (match == null) {
544 break;
545 }
546 if (match.index === 0) {
547 continue;
548 }
549 if (str[match.index - 1] === ':') {
550 if (protocolMatched === false) {
551 protocolMatched = true;
552 continue;
553 }
554 // otherwise remove extra slashes e.g. file://c://foo/bar.jpg
555 }
556 str = str.substring(0, match.index) + '/' + str.substring(match.index + match[0].length);
557 } while (true);
558 return str;
559}
560;
561
562 function isObject(x) {
563 return x != null && typeof x === 'object' && x.constructor === Object;
564 }
565 if (isObject(_src_util_path) && isObject(module.exports)) {
566 Object.assign(_src_util_path, module.exports);
567 return;
568 }
569 _src_util_path = module.exports;
570}());
571// end:source ./ModuleSimplified.js
572
573
574// source ./ModuleSimplified.js
575var _src_transport_custom;
576(function () {
577 var exports = {};
578 var module = { exports: exports };
579 "use strict";
580Object.defineProperty(exports, "__esModule", { value: true });
581exports.Repository = {};
582var CustomTransport = /** @class */ (function () {
583 function CustomTransport() {
584 }
585 CustomTransport.register = function (protocol, transport) {
586 exports.Repository[protocol] = transport;
587 };
588 CustomTransport.get = function (protocol) {
589 return exports.Repository[protocol];
590 };
591 CustomTransport.all = function () {
592 return exports.Repository;
593 };
594 CustomTransport.set = function (repository) {
595 for (var key in repository) {
596 exports.Repository[key] = repository[key];
597 }
598 };
599 return CustomTransport;
600}());
601exports.CustomTransport = CustomTransport;
602;
603
604 function isObject(x) {
605 return x != null && typeof x === 'object' && x.constructor === Object;
606 }
607 if (isObject(_src_transport_custom) && isObject(module.exports)) {
608 Object.assign(_src_transport_custom, module.exports);
609 return;
610 }
611 _src_transport_custom = module.exports;
612}());
613// end:source ./ModuleSimplified.js
614
615
616// source ./ModuleSimplified.js
617var _src_util_obj;
618(function () {
619 var exports = {};
620 var module = { exports: exports };
621 "use strict";
622Object.defineProperty(exports, "__esModule", { value: true });
623function obj_extend(target, source) {
624 if (target == null)
625 target = {};
626 if (source == null)
627 return target;
628 for (var key in source) {
629 target[key] = source[key];
630 }
631 return target;
632}
633exports.obj_extend = obj_extend;
634;
635
636 function isObject(x) {
637 return x != null && typeof x === 'object' && x.constructor === Object;
638 }
639 if (isObject(_src_util_obj) && isObject(module.exports)) {
640 Object.assign(_src_util_obj, module.exports);
641 return;
642 }
643 _src_util_obj = module.exports;
644}());
645// end:source ./ModuleSimplified.js
646
647
648// source ./ModuleSimplified.js
649var _src_util_filesystem_util;
650(function () {
651 var exports = {};
652 var module = { exports: exports };
653 "use strict";
654Object.defineProperty(exports, "__esModule", { value: true });
655var __fs = require("fs");
656function fs_isDirectory(path) {
657 try {
658 return __fs
659 .statSync(path)
660 .isDirectory();
661 }
662 catch (e) {
663 return false;
664 }
665}
666exports.fs_isDirectory = fs_isDirectory;
667function fs_getStat(path) {
668 try {
669 return __fs.statSync(path);
670 }
671 catch (e) {
672 return null;
673 }
674}
675exports.fs_getStat = fs_getStat;
676;
677
678 function isObject(x) {
679 return x != null && typeof x === 'object' && x.constructor === Object;
680 }
681 if (isObject(_src_util_filesystem_util) && isObject(module.exports)) {
682 Object.assign(_src_util_filesystem_util, module.exports);
683 return;
684 }
685 _src_util_filesystem_util = module.exports;
686}());
687// end:source ./ModuleSimplified.js
688
689
690// source ./ModuleSimplified.js
691var _src_transport_filesystem_fs_dir;
692(function () {
693 var exports = {};
694 var module = { exports: exports };
695 "use strict";
696Object.defineProperty(exports, "__esModule", { value: true });
697var global_1 = _src_global;
698var __fs = require("fs");
699var obj_1 = _src_util_obj;
700var filesystem_util_1 = _src_util_filesystem_util;
701var path_1 = _src_util_path;
702exports.DirectoryFsTransport = {
703 ensure: function (path) {
704 return dir_ensure(path);
705 },
706 ensureAsync: function (path, cb) {
707 return dir_ensureAsync(path, cb);
708 },
709 ceateSymlink: function (source, target) {
710 dir_symlink(source, target);
711 },
712 exists: function (path) {
713 return dir_exists(path);
714 },
715 existsAsync: function (path, cb) {
716 dir_existsAsync(path, cb);
717 },
718 readFiles: function (path, patterns, excludes, data) {
719 return dir_files(path, patterns, excludes, data);
720 },
721 readFilesAsync: function (path, patternsOrCb, excludesOrCb, dataOrCb, Cb) {
722 dir_filesAsync(path, patternsOrCb, excludesOrCb, dataOrCb, Cb);
723 },
724 remove: function (path) {
725 return dir_remove(path);
726 },
727 removeAsync: function (path, cb) {
728 dir_removeAsync(path, cb);
729 },
730 rename: function (oldPath, newPath) {
731 __fs.renameSync(oldPath, newPath);
732 },
733 renameAsync: function (oldPath, newPath, cb) {
734 __fs.rename(oldPath, newPath, cb);
735 }
736};
737function dir_ensure(path) {
738 if (path[path.length - 1] === '/')
739 path = path.substring(0, path.length - 1);
740 if (__fs.existsSync(path) === false) {
741 var sub = path.substring(0, path.lastIndexOf('/')), error;
742 if (isRoot(sub) === false)
743 error = dir_ensure(sub);
744 if (error)
745 return error.toString();
746 try {
747 __fs.mkdirSync(path);
748 }
749 catch (e) {
750 return e.toString();
751 }
752 }
753 if (!filesystem_util_1.fs_isDirectory(path))
754 return 'Target exists, but is not a directory:' + path;
755}
756function dir_ensureAsync(path, cb) {
757 path = path.replace(/\/*$/, '');
758 dir_existsAsync(path, function (error, exists) {
759 if (exists)
760 return cb();
761 var sub = path.substring(0, path.lastIndexOf('/'));
762 if (isRoot(sub) === false) {
763 dir_ensureAsync(sub, mkdir);
764 }
765 else {
766 mkdir();
767 }
768 });
769 function mkdir() {
770 __fs.mkdir(path, function (error) {
771 if (error) {
772 if (error.code === 'EEXIST')
773 error = null;
774 else if (error.errno === 47 || error.errno === -4707)
775 error = null;
776 }
777 cb(error);
778 });
779 }
780}
781function dir_exists(path) {
782 return filesystem_util_1.fs_isDirectory(path);
783}
784function dir_existsAsync(path, cb) {
785 __fs.stat(path, function (error, stat) {
786 cb(error, stat && stat.isDirectory());
787 });
788}
789function dir_files(path, patterns, excludes, data) {
790 return dir_walk(path, '', obj_1.obj_extend(data, {
791 depth: 0,
792 maxdepth: rgxs_getDepth(patterns),
793 patterns: patterns,
794 excludes: excludes
795 }));
796}
797function dir_filesAsync(path) {
798 var args = []; /* [?patterns, ?excludes, ?data], cb */
799 for (var _i = 1 /* [?patterns, ?excludes, ?data], cb */; _i < arguments.length /* [?patterns, ?excludes, ?data], cb */; _i++ /* [?patterns, ?excludes, ?data], cb */) {
800 args[_i - 1] = arguments[_i]; /* [?patterns, ?excludes, ?data], cb */
801 }
802 var cb = args.pop();
803 while (cb == null && args.length > 0) {
804 cb = args.pop();
805 }
806 var patterns = args.shift(), excludes = args.shift(), data = args.shift();
807 dir_walkAsync(path, '', 0, obj_1.obj_extend(data, {
808 maxdepth: rgxs_getDepth(patterns),
809 patterns: patterns,
810 excludes: excludes
811 }), [], cb);
812}
813function dir_symlink(source, target) {
814 try {
815 __fs.symlinkSync(source, target, 'junction');
816 }
817 catch (error) {
818 global_1.logger.error('symlink: bold<%s>', error);
819 }
820}
821function dir_remove(path) {
822 if (dir_exists(path) === false)
823 return true;
824 try {
825 dir_removeRecursive(path);
826 return true;
827 }
828 catch (err) {
829 return false;
830 }
831}
832function dir_removeAsync(path, cb) {
833 dir_removeRecursiveAsync(path, cb);
834}
835//> private
836function dir_removeRecursive(path) {
837 var subentries = __fs.readdirSync(path), imax = subentries.length, i = -1, filename, entry, stats;
838 while (++i < imax) {
839 filename = subentries[i];
840 if ('.' === filename || '..' === filename)
841 continue;
842 entry = path + '/' + filename;
843 stats = __fs.lstatSync(entry);
844 if (stats.isDirectory()) {
845 dir_removeRecursive(entry);
846 continue;
847 }
848 __fs.unlinkSync(entry);
849 }
850 __fs.rmdirSync(path);
851}
852function dir_removeRecursiveAsync(path, cb) {
853 __fs.readdir(path, function (error, files) {
854 if (error) {
855 cb(error);
856 return;
857 }
858 var imax = files.length, i = -1;
859 if (imax === 0) {
860 onSubCompleted();
861 return;
862 }
863 var next = cb_listeners(imax, onSubCompleted), fsname;
864 while (++i < imax) {
865 fsname = files[i];
866 if ('.' === fsname || '..' === fsname) {
867 next();
868 continue;
869 }
870 processSubEntry(path_1.path_combine(path, fsname), next);
871 }
872 });
873 function processSubEntry(path, cb) {
874 __fs.lstat(path, function (error, stat) {
875 if (error) {
876 cb(error);
877 return;
878 }
879 if (stat.isDirectory()) {
880 dir_removeRecursiveAsync(path, cb);
881 return;
882 }
883 __fs.unlink(path, cb);
884 });
885 }
886 function onSubCompleted() {
887 __fs.rmdir(path, cb);
888 }
889}
890function dir_walk(dir, root, data) {
891 var results = [], files;
892 try {
893 files = __fs.readdirSync(dir);
894 }
895 catch (error) {
896 console.error('<dir walk>', error);
897 return results;
898 }
899 if (root == null)
900 root = '';
901 if (data == null) {
902 data = {
903 depth: 0,
904 maxdepth: Infinity,
905 directories: false,
906 symlinks: false
907 };
908 }
909 var currentDepth = data.depth, patterns = data.patterns, excludes = data.excludes;
910 data.depth++;
911 for (var i = 0, x, imax = files.length; i < imax; i++) {
912 x = files[i];
913 var stats = lstat_(path_1.path_combine(dir, x)), path = path_1.path_combine(root, x), match = true;
914 if (stats == null)
915 continue;
916 if (stats.isDirectory()) {
917 if (stats.isSymbolicLink())
918 continue;
919 if (data.directories) {
920 results.push(path_1.path_combine(dir, x) + '/');
921 }
922 if (data.depth >= data.maxdepth)
923 continue;
924 var dirroot = path_1.path_combine(root, x);
925 if (patterns) {
926 var dirCanBeMatched = false;
927 for (var j = 0, jmax = patterns.length; j < jmax; j++) {
928 var patternRootCount = patterns[j].rootCount - currentDepth, patternRoot = patterns[j].root;
929 if (!patternRootCount || currentDepth > patternRootCount) {
930 dirCanBeMatched = true;
931 break;
932 }
933 if (patternRoot.indexOf(dirroot) === 0) {
934 dirCanBeMatched = true;
935 break;
936 }
937 global_1.logger(90).warn('<glob> not matched %s | %s', dirroot, patternRoot);
938 }
939 if (dirCanBeMatched === false)
940 continue;
941 }
942 global_1.logger(90).warn('<glob> match sub-', dirroot);
943 results = results.concat(dir_walk(path_1.path_combine(dir, x), dirroot, data));
944 continue;
945 }
946 if (patterns) {
947 match = false;
948 for (var j = 0, jmax = patterns.length; j < jmax; j++) {
949 if (patterns[j].test(path)) {
950 match = true;
951 break;
952 }
953 }
954 }
955 if (match && excludes) {
956 for (var j = 0, jmax = excludes.length; j < jmax; j++) {
957 if (excludes[j].test(path)) {
958 match = false;
959 break;
960 }
961 }
962 }
963 if (match)
964 results.push(path);
965 }
966 data.depth = currentDepth;
967 return results;
968}
969/*
970 * - dir: String directory to get the filelist from
971 * - root: String current subdirectory
972 * - depth: Number current subdirectory depth
973 * - data: Object { maxdepth, patterns, excludes, directories }
974 * - result: Array current filelist
975 */
976function dir_walkAsync(dir, root, depth, data, results, cb) {
977 var currentDepth = depth, maxdepth = data.maxdepth, patterns = data.patterns, excludes = data.excludes;
978 depth++;
979 __fs.readdir(dir, function (error, files) {
980 if (error)
981 return cb(error, results);
982 if (files.length === 0)
983 return cb(null, results);
984 var i = -1, imax = files.length;
985 var listener = listeners(imax);
986 while (++i < imax) {
987 process(files[i], listener);
988 }
989 });
990 function listeners(count) {
991 var err;
992 return function (error) {
993 err = err || error;
994 if (--count === 0)
995 cb(err, results);
996 };
997 }
998 function process(fsname, cb) {
999 var path = path_1.path_combine(dir, fsname);
1000 __fs.lstat(path, function (error, stat) {
1001 if (error)
1002 return cb();
1003 if (stat.isDirectory())
1004 return processDirectory(fsname, stat, cb);
1005 processFile(fsname, results);
1006 cb();
1007 });
1008 }
1009 function processDirectory(name, stat, cb) {
1010 if (stat.isSymbolicLink())
1011 return cb();
1012 if (data.directories)
1013 results.push(path_1.path_combine(root, name) + '/');
1014 if (depth >= maxdepth)
1015 return cb();
1016 var dirroot = path_1.path_combine(root, name);
1017 if (patterns) {
1018 var i = -1, imax = patterns.length;
1019 while (++i < imax) {
1020 var patternRootCount = patterns[i].rootCount - currentDepth, patternRoot = patterns[i].root;
1021 if (!patternRootCount || currentDepth > patternRootCount)
1022 break;
1023 if (patternRoot.indexOf(dirroot) === 0)
1024 break;
1025 }
1026 if (i >= imax) {
1027 // directory can not be matched
1028 return cb();
1029 }
1030 }
1031 dir_walkAsync(path_1.path_combine(dir, name), dirroot, depth, data, results, cb);
1032 }
1033 function processFile(fsname, results) {
1034 var path = path_1.path_combine(root, fsname);
1035 if (patterns && matchPath(path, patterns) === false)
1036 return;
1037 if (excludes && matchPath(path, excludes) === true)
1038 return;
1039 results.push(path);
1040 }
1041} //< walkAsync
1042function isRoot(path) {
1043 if (path === '' || path === '/')
1044 return true;
1045 return /^[A-Z]:\/?$/i.test(path);
1046}
1047function matchPath(path, rgxs) {
1048 var i = -1, imax = rgxs.length;
1049 while (++i < imax) {
1050 if (rgxs[i].test(path))
1051 return true;
1052 }
1053 return false;
1054}
1055function rgxs_getDepth(rgxs) {
1056 if (rgxs == null)
1057 return Infinity;
1058 var maxdepth = 0, imax = rgxs.length, i = -1;
1059 while (++i < imax) {
1060 if (maxdepth < rgxs[i].depth)
1061 maxdepth = rgxs[i].depth;
1062 }
1063 return maxdepth || Infinity;
1064}
1065function cb_listeners(count, cb) {
1066 var err;
1067 return function (error) {
1068 err = err || error;
1069 if (--count < 1)
1070 cb(err);
1071 };
1072}
1073function lstat_(path) {
1074 try {
1075 return __fs.lstatSync(path);
1076 }
1077 catch (e) {
1078 return null;
1079 }
1080}
1081;
1082
1083 function isObject(x) {
1084 return x != null && typeof x === 'object' && x.constructor === Object;
1085 }
1086 if (isObject(_src_transport_filesystem_fs_dir) && isObject(module.exports)) {
1087 Object.assign(_src_transport_filesystem_fs_dir, module.exports);
1088 return;
1089 }
1090 _src_transport_filesystem_fs_dir = module.exports;
1091}());
1092// end:source ./ModuleSimplified.js
1093
1094
1095// source ./ModuleSimplified.js
1096var _src_util_logger;
1097(function () {
1098 var exports = {};
1099 var module = { exports: exports };
1100 "use strict";
1101var __spreadArrays = (this && this.__spreadArrays) || function () {
1102 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
1103 for (var r = Array(s), k = 0, i = 0; i < il; i++)
1104 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
1105 r[k] = a[j];
1106 return r;
1107};
1108Object.defineProperty(exports, "__esModule", { value: true });
1109var global_1 = _src_global;
1110function log_error() {
1111 var args = [];
1112 for (var _i = 0; _i < arguments.length; _i++) {
1113 args[_i] = arguments[_i];
1114 }
1115 log.apply(void 0, __spreadArrays([NAME.red], args));
1116}
1117exports.log_error = log_error;
1118;
1119function log_info() {
1120 var args = [];
1121 for (var _i = 0; _i < arguments.length; _i++) {
1122 args[_i] = arguments[_i];
1123 }
1124 log.apply(void 0, __spreadArrays([NAME.cyan], args));
1125}
1126exports.log_info = log_info;
1127;
1128//= private
1129var NAME = '[atma-io]';
1130function log(title) {
1131 var args = [];
1132 for (var _i = 1; _i < arguments.length; _i++) {
1133 args[_i - 1] = arguments[_i];
1134 }
1135 args.unshift(title);
1136 global_1.logger.log.apply(global_1.logger, args);
1137}
1138;
1139
1140 function isObject(x) {
1141 return x != null && typeof x === 'object' && x.constructor === Object;
1142 }
1143 if (isObject(_src_util_logger) && isObject(module.exports)) {
1144 Object.assign(_src_util_logger, module.exports);
1145 return;
1146 }
1147 _src_util_logger = module.exports;
1148}());
1149// end:source ./ModuleSimplified.js
1150
1151
1152// source ./ModuleSimplified.js
1153var _src_transport_filesystem_fs_file;
1154(function () {
1155 var exports = {};
1156 var module = { exports: exports };
1157 "use strict";
1158Object.defineProperty(exports, "__esModule", { value: true });
1159var __fs = require("fs");
1160var fs_dir_1 = _src_transport_filesystem_fs_dir;
1161var logger_1 = _src_util_logger;
1162var global_1 = _src_global;
1163var path_1 = _src_util_path;
1164exports.FileFsTransport = {
1165 save: function (path, content, options) {
1166 var error = fs_dir_1.DirectoryFsTransport.ensure(path_1.path_getDir(path));
1167 if (error) {
1168 logger_1.log_error('file_save', path);
1169 return;
1170 }
1171 try {
1172 __fs.writeFileSync(path, content, options);
1173 }
1174 catch (error) {
1175 logger_1.log_error('file_save', error.toString());
1176 }
1177 },
1178 saveAsync: function (path, content, options, cb) {
1179 fs_dir_1.DirectoryFsTransport.ensureAsync(path_1.path_getDir(path), function (error) {
1180 if (error)
1181 return cb(error);
1182 __fs.writeFile(path, content, options || writeOpts, cb);
1183 });
1184 },
1185 copy: function (from, to) {
1186 if (__fs.existsSync(from) === false) {
1187 logger_1.log_error('file_copy 404', from);
1188 return;
1189 }
1190 var error = fs_dir_1.DirectoryFsTransport.ensure(path_1.path_getDir(to));
1191 if (error) {
1192 logger_1.log_error('file_copy Target error', to);
1193 return;
1194 }
1195 try {
1196 copySync(from, to);
1197 }
1198 catch (error) {
1199 logger_1.log_error('file_copy', error.toString());
1200 }
1201 },
1202 copyAsync: function (from, to, cb) {
1203 exports.FileFsTransport.existsAsync(from, prepairFn);
1204 function prepairFn(error, exists) {
1205 if (exists !== true)
1206 return cb({ code: 404, message: from + " not exists." });
1207 fs_dir_1.DirectoryFsTransport.ensureAsync(path_1.path_getDir(to), copyFn);
1208 }
1209 function copyFn(error) {
1210 if (error) {
1211 cb(error);
1212 return;
1213 }
1214 var readstream = __fs
1215 .createReadStream(from)
1216 .on('error', function (err) {
1217 global_1.logger.log('readstream error', from, err);
1218 cb && cb(err);
1219 cb = null;
1220 });
1221 var writestream = __fs
1222 .createWriteStream(to)
1223 .on('error', function (err) {
1224 global_1.logger.log('writestream error', to, err);
1225 cb && cb(err);
1226 cb = null;
1227 })
1228 .on('close', function () {
1229 cb && cb(null);
1230 cb = null;
1231 });
1232 readstream.pipe(writestream);
1233 }
1234 },
1235 exists: function (path) {
1236 return __fs.existsSync(path) && __fs.statSync(path).isFile();
1237 },
1238 existsAsync: function (path, cb) {
1239 __fs.stat(path, function (error, stat) {
1240 if (Errno.isNotFound(error)) {
1241 cb(null, false);
1242 return;
1243 }
1244 var exists = stat && stat.isFile();
1245 cb(error, exists);
1246 });
1247 },
1248 read: function (path, encoding) {
1249 try {
1250 return __fs.readFileSync(path, encoding);
1251 }
1252 catch (error) {
1253 logger_1.log_error('file_read', error.toString());
1254 }
1255 return '';
1256 },
1257 readAsync: function (path, encoding, cb) {
1258 __fs.readFile(path, { encoding: encoding }, cb);
1259 },
1260 remove: function (path) {
1261 if (exports.FileFsTransport.exists(path) === false)
1262 return true;
1263 try {
1264 __fs.unlinkSync(path);
1265 }
1266 catch (error) {
1267 logger_1.log_error('file_remove', error.toString());
1268 return false;
1269 }
1270 return true;
1271 },
1272 removeAsync: function (path, cb) {
1273 __fs.unlink(path, function (error) {
1274 if (Errno.isNotFound(error)) {
1275 error = null;
1276 }
1277 cb(error);
1278 });
1279 },
1280 rename: function (path, filename) {
1281 if (exports.FileFsTransport.exists(path) === false) {
1282 logger_1.log_error('file_rename 404', path);
1283 return false;
1284 }
1285 try {
1286 __fs.renameSync(path, getDir(path) + filename);
1287 }
1288 catch (error) {
1289 logger_1.log_error('file_rename', error.toString());
1290 return false;
1291 }
1292 return true;
1293 },
1294 renameAsync: function (path, filename, cb) {
1295 __fs.rename(path, getDir(path) + filename, function (error) {
1296 cb(error, error == null);
1297 });
1298 }
1299};
1300//= private
1301var writeOpts = {
1302 encoding: 'utf8'
1303};
1304function getDir(path) {
1305 return path.substring(0, path.lastIndexOf('/') + 1);
1306}
1307function copySync(from, to) {
1308 var BUF_LENGTH = 64 * 1024, buff = new Buffer(BUF_LENGTH), bytesRead = 1, fdr = __fs.openSync(from, 'r'), fdw = __fs.openSync(to, 'w'), pos = 0;
1309 while (bytesRead > 0) {
1310 bytesRead = __fs.readSync(fdr, buff, 0, BUF_LENGTH, pos);
1311 __fs.writeSync(fdw, buff, 0, bytesRead);
1312 pos += bytesRead;
1313 }
1314 __fs.closeSync(fdr);
1315 return __fs.closeSync(fdw);
1316}
1317var Errno;
1318(function (Errno) {
1319 function isNotFound(error) {
1320 if (error != null &&
1321 (error.errno === 34 ||
1322 error.errno === -4058 ||
1323 error.code === 'ENOENT')) {
1324 return true;
1325 }
1326 return false;
1327 }
1328 Errno.isNotFound = isNotFound;
1329})(Errno || (Errno = {}));
1330;
1331
1332 function isObject(x) {
1333 return x != null && typeof x === 'object' && x.constructor === Object;
1334 }
1335 if (isObject(_src_transport_filesystem_fs_file) && isObject(module.exports)) {
1336 Object.assign(_src_transport_filesystem_fs_file, module.exports);
1337 return;
1338 }
1339 _src_transport_filesystem_fs_file = module.exports;
1340}());
1341// end:source ./ModuleSimplified.js
1342
1343
1344// source ./ModuleSimplified.js
1345var _src_transport_filesystem_transport;
1346(function () {
1347 var exports = {};
1348 var module = { exports: exports };
1349 "use strict";
1350Object.defineProperty(exports, "__esModule", { value: true });
1351var fs_file_1 = _src_transport_filesystem_fs_file;
1352var fs_dir_1 = _src_transport_filesystem_fs_dir;
1353exports.FsTransport = {
1354 File: fs_file_1.FileFsTransport,
1355 Directory: fs_dir_1.DirectoryFsTransport
1356};
1357;
1358
1359 function isObject(x) {
1360 return x != null && typeof x === 'object' && x.constructor === Object;
1361 }
1362 if (isObject(_src_transport_filesystem_transport) && isObject(module.exports)) {
1363 Object.assign(_src_transport_filesystem_transport, module.exports);
1364 return;
1365 }
1366 _src_transport_filesystem_transport = module.exports;
1367}());
1368// end:source ./ModuleSimplified.js
1369
1370
1371// source ./ModuleSimplified.js
1372var _src_transport_dir_transport;
1373(function () {
1374 var exports = {};
1375 var module = { exports: exports };
1376 "use strict";
1377Object.defineProperty(exports, "__esModule", { value: true });
1378var path_1 = _src_util_path;
1379var custom_1 = _src_transport_custom;
1380var transport_1 = _src_transport_filesystem_transport;
1381function dir_ensure(path) {
1382 var transport = getDirectoryTransportForPath(path);
1383 return transport.ensure(path);
1384}
1385exports.dir_ensure = dir_ensure;
1386function dir_ensureAsync(path, cb) {
1387 var transport = getDirectoryTransportForPath(path);
1388 transport.ensureAsync(path, cb);
1389}
1390exports.dir_ensureAsync = dir_ensureAsync;
1391function dir_exists(path) {
1392 var transport = getDirectoryTransportForPath(path);
1393 return transport.exists(path);
1394}
1395exports.dir_exists = dir_exists;
1396function dir_existsAsync(path, cb) {
1397 var transport = getDirectoryTransportForPath(path);
1398 transport.existsAsync(path, cb);
1399}
1400exports.dir_existsAsync = dir_existsAsync;
1401function dir_files(path, patterns, excludes, data) {
1402 var transport = getDirectoryTransportForPath(path);
1403 return transport.readFiles(path, patterns, excludes, data);
1404}
1405exports.dir_files = dir_files;
1406function dir_filesAsync(path, patternsOrCb, excludesOrCb, dataOrCb, Cb) {
1407 var transport = getDirectoryTransportForPath(path);
1408 return transport.readFilesAsync(path, patternsOrCb, excludesOrCb, dataOrCb, Cb);
1409}
1410exports.dir_filesAsync = dir_filesAsync;
1411function dir_symlink(source, target) {
1412 var transport = getDirectoryTransportForPath(source);
1413 transport.ceateSymlink(source, target);
1414}
1415exports.dir_symlink = dir_symlink;
1416function dir_remove(path) {
1417 var transport = getDirectoryTransportForPath(path);
1418 return transport.remove(path);
1419}
1420exports.dir_remove = dir_remove;
1421function dir_removeAsync(path, cb) {
1422 var transport = getDirectoryTransportForPath(path);
1423 return transport.removeAsync(path, cb);
1424}
1425exports.dir_removeAsync = dir_removeAsync;
1426function dir_rename(oldPath, newPath) {
1427 var transport = getDirectoryTransportForPath(oldPath);
1428 return transport.rename(oldPath, newPath);
1429}
1430exports.dir_rename = dir_rename;
1431function dir_renameAsync(oldPath, newPath, cb) {
1432 var transport = getDirectoryTransportForPath(oldPath);
1433 return transport.renameAsync(oldPath, newPath, cb);
1434}
1435exports.dir_renameAsync = dir_renameAsync;
1436//> private
1437function getDirectoryTransportForPath(path) {
1438 var protocol = path_1.path_getProtocol(path);
1439 if (protocol == null || protocol === 'file') {
1440 return transport_1.FsTransport.Directory;
1441 }
1442 var transport = custom_1.CustomTransport.get(protocol);
1443 if (transport == null) {
1444 throw new Error("Transport '" + protocol + "' is not supported or not installed");
1445 }
1446 return transport.Directory;
1447}
1448;
1449
1450 function isObject(x) {
1451 return x != null && typeof x === 'object' && x.constructor === Object;
1452 }
1453 if (isObject(_src_transport_dir_transport) && isObject(module.exports)) {
1454 Object.assign(_src_transport_dir_transport, module.exports);
1455 return;
1456 }
1457 _src_transport_dir_transport = module.exports;
1458}());
1459// end:source ./ModuleSimplified.js
1460
1461
1462// source ./ModuleSimplified.js
1463var _src_transport_file_transport;
1464(function () {
1465 var exports = {};
1466 var module = { exports: exports };
1467 "use strict";
1468Object.defineProperty(exports, "__esModule", { value: true });
1469var custom_1 = _src_transport_custom;
1470var transport_1 = _src_transport_filesystem_transport;
1471var path_1 = _src_util_path;
1472function file_save(path, content, options) {
1473 var transport = getFileTransportForPath(path);
1474 transport.save(path, content, options);
1475}
1476exports.file_save = file_save;
1477;
1478function file_saveAsync(path, content, options, cb) {
1479 var transport = getFileTransportForPath(path);
1480 transport.saveAsync(path, content, options, cb);
1481}
1482exports.file_saveAsync = file_saveAsync;
1483;
1484function file_copy(from, to) {
1485 var fromTransport = getFileTransportForPath(from);
1486 var toTransport = getFileTransportForPath(to);
1487 if (fromTransport === toTransport) {
1488 fromTransport.copy(from, to);
1489 return;
1490 }
1491 var data = fromTransport.read(from);
1492 toTransport.save(to, data);
1493}
1494exports.file_copy = file_copy;
1495;
1496function file_copyAsync(from, to, cb) {
1497 var fromTransport = getFileTransportForPath(from);
1498 var toTransport = getFileTransportForPath(to);
1499 if (fromTransport === toTransport) {
1500 fromTransport.copyAsync(from, to, cb);
1501 return;
1502 }
1503 fromTransport.readAsync(from, null, function (err, data) {
1504 if (err) {
1505 cb(err);
1506 return;
1507 }
1508 toTransport.saveAsync(to, data, null, cb);
1509 });
1510}
1511exports.file_copyAsync = file_copyAsync;
1512;
1513function file_exists(path) {
1514 var transport = getFileTransportForPath(path);
1515 return transport.exists(path);
1516}
1517exports.file_exists = file_exists;
1518;
1519function file_existsAsync(path, cb) {
1520 var transport = getFileTransportForPath(path);
1521 return transport.existsAsync(path, cb);
1522}
1523exports.file_existsAsync = file_existsAsync;
1524;
1525function file_read(path, encoding) {
1526 var transport = getFileTransportForPath(path);
1527 return transport.read(path, encoding);
1528}
1529exports.file_read = file_read;
1530;
1531function file_readAsync(path, encoding, cb) {
1532 var transport = getFileTransportForPath(path);
1533 transport.readAsync(path, encoding, cb);
1534}
1535exports.file_readAsync = file_readAsync;
1536;
1537function file_remove(path) {
1538 var transport = getFileTransportForPath(path);
1539 return transport.remove(path);
1540}
1541exports.file_remove = file_remove;
1542;
1543function file_removeAsync(path, cb) {
1544 var transport = getFileTransportForPath(path);
1545 transport.removeAsync(path, cb);
1546}
1547exports.file_removeAsync = file_removeAsync;
1548;
1549function file_rename(path, filename) {
1550 var transport = getFileTransportForPath(path);
1551 return transport.rename(path, filename);
1552}
1553exports.file_rename = file_rename;
1554;
1555function file_renameAsync(path, filename, cb) {
1556 var transport = getFileTransportForPath(path);
1557 transport.renameAsync(path, filename, cb);
1558}
1559exports.file_renameAsync = file_renameAsync;
1560;
1561function getFileTransportForPath(path) {
1562 var protocol = path_1.path_getProtocol(path);
1563 if (protocol == null || protocol === 'file') {
1564 return transport_1.FsTransport.File;
1565 }
1566 var transport = custom_1.CustomTransport.get(protocol);
1567 if (transport == null) {
1568 throw new Error("Transport '" + protocol + "' is not supported or not installed for path '" + path + "'");
1569 }
1570 return transport.File;
1571}
1572;
1573
1574 function isObject(x) {
1575 return x != null && typeof x === 'object' && x.constructor === Object;
1576 }
1577 if (isObject(_src_transport_file_transport) && isObject(module.exports)) {
1578 Object.assign(_src_transport_file_transport, module.exports);
1579 return;
1580 }
1581 _src_transport_file_transport = module.exports;
1582}());
1583// end:source ./ModuleSimplified.js
1584
1585
1586// source ./ModuleSimplified.js
1587var _src_FileFactory;
1588(function () {
1589 var exports = {};
1590 var module = { exports: exports };
1591 "use strict";
1592Object.defineProperty(exports, "__esModule", { value: true });
1593var atma_utils_1 = require("atma-utils");
1594var FileFactory = /** @class */ (function () {
1595 function FileFactory() {
1596 this.handlers = [];
1597 }
1598 FileFactory.prototype.registerHandler = function (regexp, handler) {
1599 normalizeHandler(handler);
1600 this.handlers.push({
1601 handler: handler,
1602 regexp: regexp
1603 });
1604 };
1605 FileFactory.prototype.unregisterHandler = function (regexp, handler) {
1606 var str = regexp.toString(), imax = this.handlers.length, i = -1, x;
1607 while (++i < imax) {
1608 x = this.handlers[i];
1609 if (x.regexp.toString() !== str)
1610 continue;
1611 if (handler === void 0) {
1612 this.handlers.splice(i, 1);
1613 i--;
1614 imax--;
1615 continue;
1616 }
1617 if (handler === x) {
1618 this.handlers.splice(i, 1);
1619 return;
1620 }
1621 }
1622 };
1623 FileFactory.prototype.resolveHandler = function (uri) {
1624 var str = uri.toString(), handler = resolveHandler(this.handlers, str);
1625 return handler
1626 ? handler.handler
1627 : null;
1628 };
1629 return FileFactory;
1630}());
1631exports.FileFactory = FileFactory;
1632;
1633function resolveHandler(handlers, str) {
1634 var imax = handlers.length, i = -1, handler;
1635 while (++i < imax) {
1636 handler = handlers[i];
1637 if (matchRegexp(handler.regexp, str))
1638 return handler;
1639 }
1640 return null;
1641}
1642function matchRegexp(mix, str) {
1643 if (Array.isArray(mix)) {
1644 return mix.some(function (x) {
1645 return matchRegexp(x, str);
1646 });
1647 }
1648 // regexp
1649 mix.lastIndex = 0;
1650 return mix.test(str);
1651}
1652function normalizeHandler(Handler) {
1653 var Proto = typeof Handler === 'function' ? Handler.prototype : Handler;
1654 for (var key in Proto) {
1655 var val = Proto[key];
1656 if (typeof val !== 'function') {
1657 continue;
1658 }
1659 if (key.indexOf('Async') !== -1) {
1660 continue;
1661 }
1662 var keyAsync = key + 'Async';
1663 if (Proto[keyAsync] != null) {
1664 continue;
1665 }
1666 Proto[keyAsync] = createAsyncDelegate(val, key);
1667 }
1668 function createAsyncDelegate(syncFn, key) {
1669 return function () {
1670 var args = [];
1671 for (var _i = 0; _i < arguments.length; _i++) {
1672 args[_i] = arguments[_i];
1673 }
1674 var dfr = new atma_utils_1.class_Dfr;
1675 try {
1676 var r = syncFn.apply(this, args);
1677 return dfr.resolve(r);
1678 }
1679 catch (e) {
1680 return dfr.reject(e);
1681 }
1682 };
1683 }
1684}
1685;
1686
1687 function isObject(x) {
1688 return x != null && typeof x === 'object' && x.constructor === Object;
1689 }
1690 if (isObject(_src_FileFactory) && isObject(module.exports)) {
1691 Object.assign(_src_FileFactory, module.exports);
1692 return;
1693 }
1694 _src_FileFactory = module.exports;
1695}());
1696// end:source ./ModuleSimplified.js
1697
1698
1699// source ./ModuleSimplified.js
1700var _src_util_arr;
1701(function () {
1702 var exports = {};
1703 var module = { exports: exports };
1704 "use strict";
1705Object.defineProperty(exports, "__esModule", { value: true });
1706function arr_eachOrSingle(mix, fn) {
1707 if (arr_isArray(mix) === false) {
1708 fn(mix);
1709 return mix;
1710 }
1711 return arr_each(mix, fn);
1712}
1713exports.arr_eachOrSingle = arr_eachOrSingle;
1714;
1715function arr_any(arr, matcher) {
1716 if (arr_isArray(arr) === false)
1717 return false;
1718 var imax = arr.length, i = -1;
1719 while (++i < imax) {
1720 if (matcher(arr[i], i))
1721 return true;
1722 }
1723 return false;
1724}
1725exports.arr_any = arr_any;
1726;
1727function arr_each(arr, fn) {
1728 if (arr == null)
1729 return arr;
1730 var imax = arr.length, i = -1;
1731 while (++i < imax && fn(arr[i], i) !== false)
1732 ;
1733 return arr;
1734}
1735exports.arr_each = arr_each;
1736;
1737function arr_find(arr, fn) {
1738 if (arr == null)
1739 return arr;
1740 var imax = arr.length, i = -1;
1741 while (++i < imax) {
1742 if (fn(arr[i], i))
1743 return arr[i];
1744 }
1745 return null;
1746}
1747exports.arr_find = arr_find;
1748;
1749function arr_isArray(x) {
1750 return Array.isArray(x);
1751}
1752exports.arr_isArray = arr_isArray;
1753;
1754;
1755
1756 function isObject(x) {
1757 return x != null && typeof x === 'object' && x.constructor === Object;
1758 }
1759 if (isObject(_src_util_arr) && isObject(module.exports)) {
1760 Object.assign(_src_util_arr, module.exports);
1761 return;
1762 }
1763 _src_util_arr = module.exports;
1764}());
1765// end:source ./ModuleSimplified.js
1766
1767
1768// source ./ModuleSimplified.js
1769var _src_util_rgx;
1770(function () {
1771 var exports = {};
1772 var module = { exports: exports };
1773 "use strict";
1774Object.defineProperty(exports, "__esModule", { value: true });
1775function rgx_prepairString(str) {
1776 return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
1777}
1778exports.rgx_prepairString = rgx_prepairString;
1779;
1780;
1781
1782 function isObject(x) {
1783 return x != null && typeof x === 'object' && x.constructor === Object;
1784 }
1785 if (isObject(_src_util_rgx) && isObject(module.exports)) {
1786 Object.assign(_src_util_rgx, module.exports);
1787 return;
1788 }
1789 _src_util_rgx = module.exports;
1790}());
1791// end:source ./ModuleSimplified.js
1792
1793
1794// source ./ModuleSimplified.js
1795var _src_FileHookRegistration;
1796(function () {
1797 var exports = {};
1798 var module = { exports: exports };
1799 "use strict";
1800Object.defineProperty(exports, "__esModule", { value: true });
1801var File_1 = _src_File;
1802var arr_1 = _src_util_arr;
1803var global_1 = _src_global;
1804var rgx_1 = _src_util_rgx;
1805exports.FileHookRegistration = {
1806 registerMiddlewares: function (extensions, shouldCleanPrevious, settings) {
1807 if (shouldCleanPrevious === void 0) { shouldCleanPrevious = false; }
1808 if (settings === void 0) { settings = null; }
1809 var hook = File_1.File.getHookHandler();
1810 for (var ext in extensions) {
1811 var handlers = extensions[ext];
1812 if (arr_1.arr_isArray(handlers) === false) {
1813 global_1.logger.warn('Middleware list for %s is not an array', ext);
1814 continue;
1815 }
1816 if (shouldCleanPrevious) {
1817 unregisterHook(hook, ext);
1818 }
1819 arr_1.arr_each(handlers, Registration.registerHookDelegate(hook, ext, settings));
1820 }
1821 },
1822 ensureMiddleware: function (name, method) {
1823 return ensureMiddleware(name, method);
1824 }
1825};
1826var Registration;
1827(function (Registration) {
1828 function registerHookDelegate(hook, extension, appSettings) {
1829 return function (handlerDefinition) {
1830 registerHook(hook, extension, handlerDefinition, appSettings);
1831 };
1832 }
1833 Registration.registerHookDelegate = registerHookDelegate;
1834 function registerHook(hook, extension, handlerDefinition, appSettings) {
1835 if (typeof handlerDefinition === 'string') {
1836 registerHookByStr(hook, extension, handlerDefinition, appSettings);
1837 return;
1838 }
1839 if (Array.isArray(handlerDefinition)) {
1840 var midd = handlerDefinition[0], funcName = handlerDefinition[1];
1841 setMidd(hook, midd, extension, null, funcName, appSettings);
1842 return;
1843 }
1844 throw Error('Invalid handler Definition in registerHook');
1845 }
1846 ;
1847 function registerHookByStr(hook, extension, handlerDefinition, appSettings) {
1848 var parts = /^(.+?)(:(read|write))?$/.exec(handlerDefinition), handlerName = parts[1], funcName = parts[3], middleware = ensureMiddleware(handlerName, funcName);
1849 setMidd(hook, middleware, extension, handlerName, funcName, appSettings);
1850 }
1851 function setMidd(hook, middleware, extension, handlerName, funcName, appSettings) {
1852 if (middleware == null) {
1853 return;
1854 }
1855 if (appSettings != null && handlerName != null && typeof middleware !== 'string') {
1856 var options = appSettings[handlerName];
1857 if (options && middleware.setOptions) {
1858 middleware.setOptions(options);
1859 }
1860 }
1861 if (typeof middleware !== 'string' && middleware.setIo) {
1862 middleware.setIo(global_1.io);
1863 }
1864 var rgx = getRegexp(extension);
1865 hook.register(rgx, funcName, middleware);
1866 }
1867})(Registration || (Registration = {}));
1868;
1869function unregisterHook(hook, extension) {
1870 var rgx = getRegexp(extension);
1871 hook.unregisterByRegexp(rgx);
1872}
1873function ensureMiddleware(name, funcName) {
1874 var middleware = File_1.File.middleware[name];
1875 if (middleware == null) {
1876 try {
1877 var x = require(name);
1878 if (x && x.register) {
1879 x.register(global_1.io);
1880 }
1881 middleware = File_1.File.middleware[name];
1882 if (middleware == null) {
1883 middleware = x;
1884 }
1885 }
1886 catch (error) { }
1887 }
1888 if (middleware == null) {
1889 global_1.logger.error('Middleware is not installed', name);
1890 return null;
1891 }
1892 if (typeof middleware === 'object') {
1893 if (middleware.name == null) {
1894 middleware.name = name;
1895 }
1896 if (funcName != null && middleware[funcName] == null && middleware[funcName + 'Async'] == null) {
1897 global_1.logger.error('Middleware not defined for action', funcName, name);
1898 return null;
1899 }
1900 }
1901 return middleware;
1902}
1903function getRegexp(misc) {
1904 if (misc[0] === '/') {
1905 var str = misc.substring(1);
1906 var end = str.lastIndexOf('/');
1907 var flags = str.substring(end + 1);
1908 str = str.substring(0, end);
1909 return new RegExp(str, flags);
1910 }
1911 var ext = rgx_1.rgx_prepairString(misc);
1912 var rgx = '\\.' + ext + '($|\\?|#)';
1913 return new RegExp(rgx);
1914}
1915;
1916
1917 function isObject(x) {
1918 return x != null && typeof x === 'object' && x.constructor === Object;
1919 }
1920 if (isObject(_src_FileHookRegistration) && isObject(module.exports)) {
1921 Object.assign(_src_FileHookRegistration, module.exports);
1922 return;
1923 }
1924 _src_FileHookRegistration = module.exports;
1925}());
1926// end:source ./ModuleSimplified.js
1927
1928
1929// source ./ModuleSimplified.js
1930var _src_FileHooks;
1931(function () {
1932 var exports = {};
1933 var module = { exports: exports };
1934 "use strict";
1935Object.defineProperty(exports, "__esModule", { value: true });
1936var File_1 = _src_File;
1937var global_1 = _src_global;
1938var FileHookRegistration_1 = _src_FileHookRegistration;
1939var HookRunner = /** @class */ (function () {
1940 function HookRunner(regexp, method, handler, zIndex) {
1941 this.regexp = regexp;
1942 this.method = method;
1943 this.handler = handler;
1944 this.zIndex = zIndex;
1945 }
1946 HookRunner.prototype.run = function (method, file, config) {
1947 if (this.canHandle(file.uri.toString(), method) === false) {
1948 return;
1949 }
1950 if (typeof this.handler !== 'function') {
1951 if (this.handler[method])
1952 this.handler[method](file, config);
1953 return;
1954 }
1955 this.handler(file, config);
1956 };
1957 HookRunner.prototype.runAsync = function (method, file, config, done) {
1958 if (method !== this.method) {
1959 done();
1960 return;
1961 }
1962 if (this.regexp.test(file.uri.toString()) === false) {
1963 done();
1964 return;
1965 }
1966 var handler = this.handler;
1967 if (typeof handler !== 'function') {
1968 if (handler[method + 'Async']) {
1969 handler[method + 'Async'](file, config, done);
1970 return;
1971 }
1972 if (handler[method]) {
1973 try {
1974 handler[method](file, config);
1975 }
1976 catch (error) {
1977 done(error);
1978 return;
1979 }
1980 }
1981 done();
1982 return;
1983 }
1984 handler(file, config);
1985 done();
1986 };
1987 HookRunner.prototype.canHandle = function (path, method) {
1988 if (method != null && method !== this.method) {
1989 return false;
1990 }
1991 return this.regexp.test(path);
1992 };
1993 return HookRunner;
1994}());
1995exports.HookRunner = HookRunner;
1996;
1997var FileHooks = /** @class */ (function () {
1998 function FileHooks() {
1999 this.hooks = [];
2000 }
2001 FileHooks.prototype.register = function (mix, method, handler, zIndex) {
2002 var regexp;
2003 if (mix instanceof RegExp) {
2004 regexp = mix;
2005 }
2006 else {
2007 regexp = mix.regexp;
2008 method = mix.method;
2009 handler = mix.handler;
2010 zIndex = mix.zIndex;
2011 }
2012 if (typeof handler === 'string') {
2013 var hook = FileHookRegistration_1.FileHookRegistration.ensureMiddleware(handler, method);
2014 if (hook == null) {
2015 return this;
2016 }
2017 handler = hook;
2018 }
2019 if (this.contains(method, handler, regexp) === false) {
2020 this.hooks.push(new HookRunner(regexp, method, handler, zIndex || 0));
2021 }
2022 return this;
2023 };
2024 FileHooks.prototype.contains = function (method, handler, regexp) {
2025 var str = regexp && regexp.toString() || null;
2026 var imax = this.hooks.length;
2027 var i = -1;
2028 while (++i < imax) {
2029 var hook = this.hooks[i];
2030 if (hook.method !== method) {
2031 continue;
2032 }
2033 if (hook.handler !== handler) {
2034 continue;
2035 }
2036 if (str != null && str !== hook.regexp.toString()) {
2037 continue;
2038 }
2039 return true;
2040 }
2041 return false;
2042 };
2043 FileHooks.prototype.unregister = function (method, handler) {
2044 if (typeof handler === 'string') {
2045 handler = File_1.File.middleware[handler];
2046 }
2047 this.hooks = this.hooks.filter(function (x) {
2048 return !(x.method === method && x.handler === handler);
2049 });
2050 };
2051 FileHooks.prototype.unregisterByRegexp = function (regexp) {
2052 var str = regexp.toString();
2053 var imax = this.hooks.length;
2054 var i = -1;
2055 while (++i < imax) {
2056 var hook = this.hooks[i];
2057 if (hook.regexp.toString() === str) {
2058 this.hooks.splice(i, 1);
2059 i--;
2060 imax--;
2061 }
2062 }
2063 };
2064 FileHooks.prototype.trigger = function (method, file, config) {
2065 this
2066 .getHooksForPath(file.uri.toString(), method)
2067 .forEach(function (x) {
2068 x.run(method, file, config);
2069 });
2070 };
2071 FileHooks.prototype.triggerAsync = function (method, file, config, cb) {
2072 var path = file.uri.toString(), hooks = this.getHooksForPath(path, method);
2073 new AsyncHooks(hooks).process(method, file, config, cb);
2074 };
2075 FileHooks.prototype.clear = function () {
2076 this.hooks = [];
2077 return this;
2078 };
2079 FileHooks.prototype.getHooksForPath = function (path, method) {
2080 return this
2081 .hooks
2082 .filter(function (x) { return x.canHandle(path, method); })
2083 .sort(function (a, b) {
2084 var az = a.zIndex, bz = b.zIndex;
2085 if (az === bz)
2086 return 0;
2087 return a.zIndex < b.zIndex
2088 ? 1
2089 : -1;
2090 });
2091 };
2092 return FileHooks;
2093}());
2094exports.FileHooks = FileHooks;
2095;
2096var AsyncHooks = global_1.Class.Collection(HookRunner, {
2097 Base: global_1.Class.Serializable,
2098 index: -1,
2099 cb: null,
2100 method: null,
2101 file: null,
2102 config: null,
2103 process: function (method, file, config, cb) {
2104 this.index = -1;
2105 this.cb = cb;
2106 this.method = method;
2107 this.file = file;
2108 this.config = config;
2109 this.next();
2110 },
2111 Self: {
2112 next: function (error) {
2113 if (error) {
2114 this.cb(error);
2115 return;
2116 }
2117 if (++this.index >= this.length) {
2118 this.cb();
2119 return;
2120 }
2121 var hook = this[this.index];
2122 //@FIX prevent same hook to be run twice
2123 if (typeof hook.handler !== 'function') {
2124 var name = hook.handler.name;
2125 if (name) {
2126 for (var i = this.index - 1; i > -1; i--) {
2127 if (name === this[i].handler.name) {
2128 this.next();
2129 return;
2130 }
2131 }
2132 }
2133 }
2134 hook.runAsync(this.method, this.file, this.config, this.next);
2135 }
2136 }
2137});
2138;
2139
2140 function isObject(x) {
2141 return x != null && typeof x === 'object' && x.constructor === Object;
2142 }
2143 if (isObject(_src_FileHooks) && isObject(module.exports)) {
2144 Object.assign(_src_FileHooks, module.exports);
2145 return;
2146 }
2147 _src_FileHooks = module.exports;
2148}());
2149// end:source ./ModuleSimplified.js
2150
2151
2152// source ./ModuleSimplified.js
2153var _src_middleware_json;
2154(function () {
2155 var exports = {};
2156 var module = { exports: exports };
2157 "use strict";
2158Object.defineProperty(exports, "__esModule", { value: true });
2159var global_1 = _src_global;
2160var Env_1 = _src_Env;
2161exports.JsonMiddleware = {
2162 read: function (file) {
2163 if (typeof file.content !== 'string') {
2164 return;
2165 }
2166 try {
2167 file.content = JSON.parse(file.content);
2168 }
2169 catch (error) {
2170 global_1.logger.error("<json:parser> " + file.uri.toString() + " " + error);
2171 }
2172 },
2173 write: function (file, config) {
2174 if (file.content == null || typeof file.content !== 'object') {
2175 return;
2176 }
2177 try {
2178 var indent = config && config.minify
2179 ? null
2180 : 2;
2181 file.content = JSON
2182 .stringify(file.content, null, indent)
2183 .replace(/\n/g, Env_1.Env.newLine);
2184 }
2185 catch (error) {
2186 global_1.logger.error("<json:stringify> " + file.uri.toString() + " " + error);
2187 }
2188 }
2189};
2190;
2191
2192 function isObject(x) {
2193 return x != null && typeof x === 'object' && x.constructor === Object;
2194 }
2195 if (isObject(_src_middleware_json) && isObject(module.exports)) {
2196 Object.assign(_src_middleware_json, module.exports);
2197 return;
2198 }
2199 _src_middleware_json = module.exports;
2200}());
2201// end:source ./ModuleSimplified.js
2202
2203
2204// source ./ModuleSimplified.js
2205var _src_util_uri;
2206(function () {
2207 var exports = {};
2208 var module = { exports: exports };
2209 "use strict";
2210Object.defineProperty(exports, "__esModule", { value: true });
2211var path_1 = _src_util_path;
2212function uri_getFile(uri, base) {
2213 if (base == null) {
2214 return uri.file;
2215 }
2216 var baseUri = path_1.path_getUri(base);
2217 var pathStr = uri.toLocalFile();
2218 var baseStr = baseUri.toLocalFile();
2219 if (pathStr.includes(baseStr) === false) {
2220 throw new Error(base + " is not the base path for " + pathStr);
2221 }
2222 var rel = uri.toRelativeString(baseUri);
2223 return rel;
2224}
2225exports.uri_getFile = uri_getFile;
2226;
2227
2228 function isObject(x) {
2229 return x != null && typeof x === 'object' && x.constructor === Object;
2230 }
2231 if (isObject(_src_util_uri) && isObject(module.exports)) {
2232 Object.assign(_src_util_uri, module.exports);
2233 return;
2234 }
2235 _src_util_uri = module.exports;
2236}());
2237// end:source ./ModuleSimplified.js
2238
2239
2240// source ./ModuleSimplified.js
2241var _src_File;
2242(function () {
2243 var exports = {};
2244 var module = { exports: exports };
2245 "use strict";
2246Object.defineProperty(exports, "__esModule", { value: true });
2247var atma_utils_1 = require("atma-utils");
2248var path_1 = _src_util_path;
2249var file_transport_1 = _src_transport_file_transport;
2250var global_1 = _src_global;
2251var logger_1 = _src_util_logger;
2252var filesystem_util_1 = _src_util_filesystem_util;
2253var Env_1 = _src_Env;
2254var Watcher_1 = _src_Watcher;
2255var FileFactory_1 = _src_FileFactory;
2256var FileHooks_1 = _src_FileHooks;
2257var FileHookRegistration_1 = _src_FileHookRegistration;
2258var custom_1 = _src_transport_custom;
2259var json_1 = _src_middleware_json;
2260var global_2 = _src_global;
2261var uri_1 = _src_util_uri;
2262var _cache = {}, _cacheEnabled = true, _hooks, _factory;
2263var File = /** @class */ (function () {
2264 function File(path, opts) {
2265 this.uri = path_1.path_getUri(path);
2266 path = uri_toPath(this.uri);
2267 if (isFromCache(path, opts)) {
2268 return _cache[path];
2269 }
2270 if (this.__proto__ === File.prototype) {
2271 var factory = opts && opts.factory || _factory;
2272 var Handler = factory && factory.resolveHandler(this.uri);
2273 if (Handler != null)
2274 return new Handler(this.uri, opts);
2275 }
2276 return isCacheEnabled(opts) === false
2277 ? (this)
2278 : (_cache[path] = this);
2279 }
2280 File.prototype.read = function (mix) {
2281 if (this.content != null)
2282 return this.content;
2283 var setts = getSetts(mix), path = uri_toPath(this.uri);
2284 this.content = file_transport_1.file_read(path, setts.encoding);
2285 processHooks('read', this, setts, mix);
2286 return this.content;
2287 };
2288 File.read = function (path, mix) {
2289 return new File(path).read(mix);
2290 };
2291 File.prototype.readAsync = function (mix) {
2292 return dfr_factory(this, function (dfr, file, path) {
2293 if (file.content != null) {
2294 dfr.resolve(file.content, file);
2295 return;
2296 }
2297 var setts = getSetts(mix);
2298 file_transport_1.file_readAsync(path, setts.encoding, onReadComplete);
2299 function onReadComplete(error, content) {
2300 if (error)
2301 return dfr.reject(error);
2302 file.content = content;
2303 processHooks('read', file, setts, mix, onHookComplete);
2304 }
2305 function onHookComplete(error) {
2306 if (error)
2307 return dfr.reject(error);
2308 dfr.resolve(file.content, file);
2309 }
2310 }, function onError(file, path) {
2311 if (isFromCache(path)) {
2312 delete _cache[path];
2313 }
2314 });
2315 };
2316 File.readAsync = function (path, mix) {
2317 return new File(path, mix).readAsync(mix);
2318 };
2319 File.prototype.write = function (content, mix) {
2320 if (content != null) {
2321 this.content = content;
2322 }
2323 if (this.content == null) {
2324 global_1.logger.error('io.file.write: Content is empty');
2325 return this;
2326 }
2327 var path = uri_toPath(this.uri), setts = getSetts(mix);
2328 processHooks('write', this, setts, mix);
2329 file_transport_1.file_save(path, this.content, setts);
2330 // Clear Content sothat next `read` call reads content and processes the middlewares, as processHooks may serialize content
2331 // Consider not to clear content, but to flag the file as serialized, so that next `read` call runs middlewares once again
2332 this.content = null;
2333 return this;
2334 };
2335 File.write = function (path, content, mix) {
2336 return new File(path, mix).write(content, mix);
2337 };
2338 File.prototype.writeAsync = function (content, mix) {
2339 return dfr_factory(this, function (dfr, file, path) {
2340 file.content = content = (content || file.content);
2341 if (content == null) {
2342 dfr.reject(Error('Content is undefined'));
2343 return;
2344 }
2345 var setts = getSetts(mix);
2346 processHooks('write', file, setts, mix, onHookComplete);
2347 function onHookComplete() {
2348 var content = file.content;
2349 file.content = null;
2350 file_transport_1.file_saveAsync(path, content, setts, dfr_pipeDelegate(dfr));
2351 }
2352 });
2353 };
2354 File.writeAsync = function (path, content, mix) {
2355 return new File(path).writeAsync(content, mix);
2356 };
2357 File.prototype.copyTo = function (target, opts) {
2358 var _a, _b;
2359 var from = uri_toPath(this.uri);
2360 var targetUri = path_1.path_getUri(target);
2361 var targetPath = targetUri.file
2362 ? uri_toPath(targetUri)
2363 : uri_toPath(targetUri.combine(uri_1.uri_getFile(this.uri, (_a = opts) === null || _a === void 0 ? void 0 : _a.baseSource)));
2364 if (((_b = opts) === null || _b === void 0 ? void 0 : _b.silent) !== true) {
2365 var _from = from
2366 .substr(-25)
2367 .replace(/([^\/]+)$/, 'green<bold<$1>>').color, _to = targetPath
2368 .substr(-25)
2369 .replace(/([^\/]+)$/, 'green<bold<$1>>').color;
2370 logger_1.log_info('copy:', _from, _to);
2371 }
2372 file_transport_1.file_copy(from, targetPath);
2373 return this;
2374 };
2375 File.copyTo = function (path, target, opts) {
2376 return new File(path).copyTo(target, opts);
2377 };
2378 File.prototype.copyToAsync = function (target, opts) {
2379 return dfr_factory(this, function (dfr, file, path) {
2380 var _a;
2381 var targetUri = path_1.path_getUri(target);
2382 var targetPath = targetUri.file
2383 ? uri_toPath(targetUri)
2384 : uri_toPath(targetUri.combine(uri_1.uri_getFile(this.uri, (_a = opts) === null || _a === void 0 ? void 0 : _a.baseSource)));
2385 file_transport_1.file_copyAsync(path, targetPath, dfr_pipeDelegate(dfr));
2386 });
2387 };
2388 File.copyToAsync = function (path, target, opts) {
2389 return new File(path).copyToAsync(target);
2390 };
2391 File.prototype.exists = function () {
2392 return file_transport_1.file_exists(uri_toPath(this.uri));
2393 };
2394 File.exists = function (path) {
2395 return new File(path).exists();
2396 };
2397 File.prototype.existsAsync = function () {
2398 return dfr_factory(this, function (dfr, file, path) {
2399 file_transport_1.file_existsAsync(path, dfr_pipeDelegate(dfr));
2400 });
2401 };
2402 File.existsAsync = function (path) {
2403 return new File(path).existsAsync();
2404 };
2405 File.prototype.rename = function (fileName) {
2406 return file_transport_1.file_rename(uri_toPath(this.uri), fileName);
2407 };
2408 File.rename = function (path, fileName) {
2409 return new File(path).rename(fileName);
2410 };
2411 File.prototype.renameAsync = function (filename) {
2412 return dfr_factory(this, function (dfr, file, path) {
2413 file_transport_1.file_renameAsync(path, filename, dfr_pipeDelegate(dfr));
2414 });
2415 };
2416 File.renameAsync = function (path, fileName) {
2417 return new File(path).renameAsync(fileName);
2418 };
2419 File.prototype.remove = function () {
2420 return file_transport_1.file_remove(uri_toPath(this.uri));
2421 };
2422 File.remove = function (path) {
2423 return new File(path).remove();
2424 };
2425 File.prototype.removeAsync = function () {
2426 return dfr_factory(this, function (dfr, file, path) {
2427 file_transport_1.file_removeAsync(path, dfr_pipeDelegate(dfr));
2428 });
2429 };
2430 File.removeAsync = function (path) {
2431 return new File(path).removeAsync();
2432 };
2433 File.prototype.replace = function (a, b, setts) {
2434 var content = this.read(setts);
2435 if (typeof content !== 'string') {
2436 content = content.toString();
2437 }
2438 content = content.replace(a, b);
2439 this.write(content);
2440 return content;
2441 };
2442 File.replace = function (path, a, b, setts) {
2443 return new File(path).replace(a, b, setts);
2444 };
2445 File.prototype.replaceAsync = function (a, b, setts) {
2446 return dfr_factory(this, function (dfr, file) {
2447 file
2448 .readAsync(setts)
2449 .fail(dfr.rejectDelegate())
2450 .done(function (content) {
2451 content = content.replace(a, b);
2452 file
2453 .writeAsync(content)
2454 .fail(dfr.rejectDelegate())
2455 .done(function () {
2456 dfr.resolve(null, content);
2457 });
2458 });
2459 });
2460 };
2461 File.replaceAsync = function (path, a, b, setts) {
2462 return new File(path).replaceAsync(a, b, setts);
2463 };
2464 File.prototype.watch = function (callback) {
2465 Watcher_1.Watcher.watch(uri_toPath(this.uri), callback);
2466 };
2467 File.watch = function (path, callback) {
2468 new File(path).watch(callback);
2469 };
2470 File.prototype.unwatch = function (callback) {
2471 // - callback: if undefined remove all listeners
2472 Watcher_1.Watcher.unwatch(uri_toPath(this.uri), callback);
2473 };
2474 File.unwatch = function (path, callback) {
2475 new File(path).unwatch(callback);
2476 };
2477 File.prototype.stats = function () {
2478 return filesystem_util_1.fs_getStat(uri_toPath(this.uri));
2479 };
2480 File.stats = function (path) {
2481 return new File(path).stats();
2482 };
2483 File.clearCache = function (mix) {
2484 if (_cacheEnabled === false) {
2485 return;
2486 }
2487 if (arguments.length === 0) {
2488 _cache = {};
2489 return;
2490 }
2491 if (mix == null)
2492 return;
2493 var path;
2494 if (typeof mix === 'string') {
2495 path = uri_toPath(path_1.path_getUri(mix));
2496 if (_cache.hasOwnProperty(path) === false && mix.charCodeAt(0) === 47) {
2497 path = atma_utils_1.class_Uri.combine(Env_1.Env.cwd, mix);
2498 }
2499 }
2500 else if (mix.uri) {
2501 path = uri_toPath(mix.uri);
2502 }
2503 else if (mix.toLocalFile) {
2504 path = uri_toPath(mix);
2505 }
2506 if (_cache.hasOwnProperty(path) === false) {
2507 global_1.logger.log('io.File - not in cache -', path);
2508 return;
2509 }
2510 delete _cache[path];
2511 };
2512 File.disableCache = function () {
2513 _cache = {};
2514 _cacheEnabled = false;
2515 };
2516 File.enableCache = function () {
2517 _cacheEnabled = true;
2518 };
2519 File.registerFactory = function (factory) {
2520 _factory = factory;
2521 };
2522 File.getFactory = function () {
2523 return _factory;
2524 };
2525 File.registerHookHandler = function (hook) {
2526 _hooks = hook;
2527 };
2528 File.getHookHandler = function () {
2529 return _hooks;
2530 };
2531 File.registerTransport = function (protocol, transport) {
2532 custom_1.CustomTransport.register(protocol, transport);
2533 };
2534 File.getTransports = function () {
2535 return custom_1.CustomTransport.all();
2536 };
2537 File.setTransports = function (repository) {
2538 custom_1.CustomTransport.set(repository);
2539 };
2540 Object.defineProperty(File, "Factory", {
2541 get: function () {
2542 return _factory;
2543 },
2544 enumerable: true,
2545 configurable: true
2546 });
2547 Object.defineProperty(File, "Middleware", {
2548 get: function () {
2549 return _hooks;
2550 },
2551 enumerable: true,
2552 configurable: true
2553 });
2554 File.processHooks = function (method, file, config, onComplete) {
2555 processHooks(method, file, null, config, onComplete);
2556 };
2557 File.registerExtensions = function (extensions, shouldCleanPrevious, settings) {
2558 if (shouldCleanPrevious === void 0) { shouldCleanPrevious = false; }
2559 if (settings === void 0) { settings = null; }
2560 FileHookRegistration_1.FileHookRegistration.registerMiddlewares(extensions, shouldCleanPrevious, settings);
2561 };
2562 File.setMiddlewares = function (extensions, settings) {
2563 if (settings === void 0) { settings = null; }
2564 FileHookRegistration_1.FileHookRegistration.registerMiddlewares(extensions, true, settings);
2565 };
2566 File.middleware = {};
2567 return File;
2568}());
2569exports.File = File;
2570;
2571function dfr_factory(file, fn, onError) {
2572 var dfr = new global_1.Class.Deferred;
2573 var path = uri_toPath(file.uri);
2574 if (onError != null) {
2575 dfr.fail(function () {
2576 onError(file, path);
2577 });
2578 }
2579 fn(dfr, file, path);
2580 return dfr;
2581}
2582function dfr_pipeDelegate(dfr) {
2583 return function (error) {
2584 var args = [];
2585 for (var _i = 1; _i < arguments.length; _i++) {
2586 args[_i - 1] = arguments[_i];
2587 }
2588 if (error) {
2589 dfr.reject(error);
2590 return;
2591 }
2592 dfr.resolve.apply(dfr, args);
2593 };
2594}
2595function uri_toPath(uri) {
2596 if (uri.protocol == null || uri.protocol === 'file') {
2597 return uri.toLocalFile();
2598 }
2599 return uri.toString();
2600}
2601function getSetts(mix, defaults) {
2602 var setts = defaults || {
2603 encoding: 'utf8',
2604 skipHooks: false,
2605 hooks: null,
2606 };
2607 if (mix == null)
2608 return setts;
2609 switch (typeof mix) {
2610 case 'string':
2611 setts.encoding = mix;
2612 break;
2613 case 'object':
2614 Object.assign(setts, mix);
2615 break;
2616 }
2617 if (setts.encoding === 'buffer')
2618 setts.encoding = null;
2619 return setts;
2620}
2621function processHooks(method, file, setts, config, cb) {
2622 var hooks = _hooks;
2623 if (setts != null) {
2624 hooks = setts.hooks || hooks;
2625 if (hooks == null || setts.skipHooks === true) {
2626 cb && cb();
2627 return;
2628 }
2629 }
2630 if (cb) {
2631 hooks.triggerAsync(method, file, config, cb);
2632 return;
2633 }
2634 hooks.trigger(method, file, config);
2635}
2636function isFromCache(path, opts) {
2637 if (_cacheEnabled === false) {
2638 return false;
2639 }
2640 if (opts != null && opts.cached === false) {
2641 return false;
2642 }
2643 return _cache.hasOwnProperty(path) && _cache[path] != null;
2644}
2645function isCacheEnabled(opts) {
2646 if (_cacheEnabled === false) {
2647 return false;
2648 }
2649 if (opts != null && opts.cached === false) {
2650 return false;
2651 }
2652 return true;
2653}
2654/** REGISTER */
2655if (global_2.global.io && global_2.global.io.File && typeof global_2.global.io.File.getFactory === 'function') {
2656 var globalFile = global_2.global.io.File;
2657 File.registerFactory(globalFile.getFactory());
2658 File.registerHookHandler(globalFile.getHookHandler());
2659 File.middleware = globalFile.middleware;
2660 if (globalFile.getTransports) {
2661 File.setTransports(globalFile.getTransports());
2662 }
2663}
2664else {
2665 var factory = new FileFactory_1.FileFactory();
2666 var hooks = new FileHooks_1.FileHooks();
2667 File.registerFactory(factory);
2668 File.registerHookHandler(hooks);
2669 hooks.register(/\.json$/, 'read', json_1.JsonMiddleware);
2670 hooks.register(/\.json$/, 'write', json_1.JsonMiddleware);
2671}
2672;
2673
2674 function isObject(x) {
2675 return x != null && typeof x === 'object' && x.constructor === Object;
2676 }
2677 if (isObject(_src_File) && isObject(module.exports)) {
2678 Object.assign(_src_File, module.exports);
2679 return;
2680 }
2681 _src_File = module.exports;
2682}());
2683// end:source ./ModuleSimplified.js
2684
2685
2686// source ./ModuleSimplified.js
2687var _src_util_cli;
2688(function () {
2689 var exports = {};
2690 var module = { exports: exports };
2691 "use strict";
2692var __extends = (this && this.__extends) || (function () {
2693 var extendStatics = function (d, b) {
2694 extendStatics = Object.setPrototypeOf ||
2695 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
2696 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
2697 return extendStatics(d, b);
2698 };
2699 return function (d, b) {
2700 extendStatics(d, b);
2701 function __() { this.constructor = d; }
2702 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
2703 };
2704})();
2705var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2706 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2707 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2708 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2709 return c > 3 && r && Object.defineProperty(target, key, r), r;
2710};
2711Object.defineProperty(exports, "__esModule", { value: true });
2712var global_1 = _src_global;
2713function cli_prompt(str, callback) {
2714 Factory.create(new PromptAction(str, callback));
2715}
2716exports.cli_prompt = cli_prompt;
2717;
2718function cli_confirm(str, callback) {
2719 Factory.create(new ConfirmAction(str + ' (y): ', callback));
2720}
2721exports.cli_confirm = cli_confirm;
2722;
2723//= private
2724var rl, factory_;
2725function initialize() {
2726 var readline = require('readline');
2727 rl = readline.createInterface({
2728 input: process.stdin,
2729 output: process.stdout
2730 });
2731}
2732var Factory = /** @class */ (function () {
2733 function Factory() {
2734 this.collection = [];
2735 this.busy = false;
2736 }
2737 Factory.create = function (prompt) {
2738 if (rl == null) {
2739 initialize();
2740 factory_ = new Factory;
2741 }
2742 factory_.collection.push(prompt);
2743 factory_.process();
2744 };
2745 Factory.prototype.process = function () {
2746 if (this.busy)
2747 return;
2748 if (this.collection.length === 0)
2749 return;
2750 this.busy = true;
2751 this
2752 .collection
2753 .shift()
2754 .process()
2755 .always(this.next);
2756 };
2757 Factory.prototype.next = function () {
2758 this.busy = false;
2759 this.process();
2760 };
2761 __decorate([
2762 global_1.Class.deco.self
2763 ], Factory.prototype, "process", null);
2764 __decorate([
2765 global_1.Class.deco.self
2766 ], Factory.prototype, "next", null);
2767 return Factory;
2768}());
2769var PromptAction = /** @class */ (function (_super) {
2770 __extends(PromptAction, _super);
2771 function PromptAction(text, callback) {
2772 if (text === void 0) { text = '>'; }
2773 var _this = _super.call(this) || this;
2774 _this.text = text;
2775 _this.callback = callback;
2776 return _this;
2777 }
2778 PromptAction.prototype.process = function () {
2779 rl.resume();
2780 process.stdout.write('\n');
2781 rl.question(this.text, this.onInput.bind(this));
2782 return this;
2783 };
2784 PromptAction.prototype.onInput = function (answer) {
2785 rl.pause();
2786 this.callback && this.callback(answer);
2787 this.resolve(answer);
2788 };
2789 return PromptAction;
2790}(global_1.Class.Deferred));
2791var ConfirmAction = /** @class */ (function (_super) {
2792 __extends(ConfirmAction, _super);
2793 function ConfirmAction(text, callback) {
2794 var _this = _super.call(this, text, callback) || this;
2795 var original = _this.callback;
2796 _this.callback = function (answer) {
2797 original(/^y|yes$/ig.test(answer));
2798 };
2799 return _this;
2800 }
2801 ;
2802 ConfirmAction.prototype.onInput = function (answer) {
2803 if (!answer) {
2804 this.process();
2805 return;
2806 }
2807 _super.prototype.onInput.call(this, answer);
2808 };
2809 return ConfirmAction;
2810}(PromptAction));
2811;
2812
2813 function isObject(x) {
2814 return x != null && typeof x === 'object' && x.constructor === Object;
2815 }
2816 if (isObject(_src_util_cli) && isObject(module.exports)) {
2817 Object.assign(_src_util_cli, module.exports);
2818 return;
2819 }
2820 _src_util_cli = module.exports;
2821}());
2822// end:source ./ModuleSimplified.js
2823
2824
2825// source ./ModuleSimplified.js
2826var _src_util_stack;
2827(function () {
2828 var exports = {};
2829 var module = { exports: exports };
2830 "use strict";
2831Object.defineProperty(exports, "__esModule", { value: true });
2832var stackEntry = {
2833 path: null,
2834 file: null,
2835 line: null
2836};
2837var currentFile;
2838function parseStackEntry(line) {
2839 if (line[line.length - 1] === ")")
2840 line = line.substr(line.indexOf("(") + 1, line.lastIndexOf(")") - 1);
2841 var match = /^(.+):(\d+):(\d)/.exec(line);
2842 if (match == null)
2843 return null;
2844 var path = (stackEntry.path = match[1]);
2845 stackEntry.file = path.substring(path.search(/[\/\\][^\/\\]+$/) + 1);
2846 stackEntry.line = match[2];
2847 if (currentFile == null)
2848 currentFile = stackEntry.file;
2849 return stackEntry;
2850}
2851function stack_formatCaller(format) {
2852 if (format === void 0) { format = 'P:L'; }
2853 var stack = new Error().stack.split("\n").splice(1);
2854 var imax = stack.length, i = -1, entry;
2855 while (++i < imax) {
2856 entry = parseStackEntry(stack[i]);
2857 if (entry == null || currentFile == null)
2858 continue;
2859 if (entry.file !== currentFile)
2860 break;
2861 }
2862 if (entry == null || i === imax)
2863 return "";
2864 return format
2865 .replace("P", entry.path)
2866 .replace("F", entry.file)
2867 .replace("L", entry.line);
2868}
2869exports.stack_formatCaller = stack_formatCaller;
2870;
2871
2872 function isObject(x) {
2873 return x != null && typeof x === 'object' && x.constructor === Object;
2874 }
2875 if (isObject(_src_util_stack) && isObject(module.exports)) {
2876 Object.assign(_src_util_stack, module.exports);
2877 return;
2878 }
2879 _src_util_stack = module.exports;
2880}());
2881// end:source ./ModuleSimplified.js
2882
2883
2884// source ./ModuleSimplified.js
2885var _src_Directory;
2886(function () {
2887 var exports = {};
2888 var module = { exports: exports };
2889 "use strict";
2890var __spreadArrays = (this && this.__spreadArrays) || function () {
2891 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
2892 for (var r = Array(s), k = 0, i = 0; i < il; i++)
2893 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
2894 r[k] = a[j];
2895 return r;
2896};
2897Object.defineProperty(exports, "__esModule", { value: true });
2898var global_1 = _src_global;
2899var atma_utils_1 = require("atma-utils");
2900var dir_transport_1 = _src_transport_dir_transport;
2901var glob_1 = _src_util_glob;
2902var File_1 = _src_File;
2903var path_1 = _src_util_path;
2904var cli_1 = _src_util_cli;
2905var Watcher_1 = _src_Watcher;
2906var stack_1 = _src_util_stack;
2907var Env_1 = _src_Env;
2908var Directory = /** @class */ (function () {
2909 function Directory(directory) {
2910 if (directory instanceof Directory)
2911 return directory;
2912 if (directory == null || directory === '/') {
2913 this.uri = Env_1.Env.currentDir;
2914 return;
2915 }
2916 if (typeof directory === 'string' && directory[directory.length - 1] !== '/') {
2917 global_1.logger
2918 .warn('@ directory path should end with slash. Adding...', directory);
2919 if (/\.\w+$/.test(directory) === false)
2920 directory = directory + '/';
2921 }
2922 this.uri = path_1.path_getUri(directory);
2923 delete this.uri.file;
2924 }
2925 Directory.prototype.exists = function () {
2926 return dir_transport_1.dir_exists(uri_toDirectory(this.uri));
2927 };
2928 Directory.exists = function (path) {
2929 return new Directory(path).exists();
2930 };
2931 Directory.prototype.existsAsync = function () {
2932 return dfr_factory(this, function (dfr, dir, path) {
2933 dir_transport_1.dir_existsAsync(path, dfr_pipeDelegate(dfr));
2934 });
2935 };
2936 Directory.existsAsync = function (path) {
2937 return new Directory(path).existsAsync();
2938 };
2939 Directory.prototype.ensure = function () {
2940 dir_transport_1.dir_ensure(uri_toDirectory(this.uri));
2941 return this;
2942 };
2943 Directory.ensure = function (path) {
2944 return new Directory(path).ensure();
2945 };
2946 Directory.prototype.ensureAsync = function () {
2947 return dfr_factory(this, function (dfr, dir, path) {
2948 dir_transport_1.dir_ensureAsync(path, dfr_pipeDelegate(dfr, dir));
2949 });
2950 };
2951 Directory.ensureAsync = function (path) {
2952 return new Directory(path).ensureAsync();
2953 };
2954 Directory.prototype.readFiles = function (pattern, exclude) {
2955 var _this = this;
2956 var patterns = glob_1.glob_parsePatterns(pattern), excludes = glob_1.glob_parsePatterns(exclude);
2957 var arr = this.files = dir_transport_1.dir_files(uri_toDirectory(this.uri), patterns, excludes)
2958 .map(function (path) {
2959 return new File_1.File(_this.uri.combine(path));
2960 });
2961 /** Obsolete (Backward compatible: Directory was returned) */
2962 Object.defineProperty(arr, 'files', {
2963 get: function () {
2964 console.log('Warn: obsolete. io.Directory::readFiles returns now the array of files');
2965 stack_1.stack_formatCaller();
2966 return arr;
2967 }
2968 });
2969 return arr;
2970 };
2971 Directory.readFiles = function (path, pattern, exclude) {
2972 return new Directory(path).readFiles(pattern, exclude);
2973 };
2974 Directory.prototype.read = function (pattern, exclude) {
2975 var _this = this;
2976 var patterns = glob_1.glob_parsePatterns(pattern), excludes = glob_1.glob_parsePatterns(exclude);
2977 return dir_transport_1.dir_files(uri_toDirectory(this.uri), patterns, excludes, { directories: true })
2978 .map(function (x) {
2979 var path = _this.uri.combine(x);
2980 if (x[x.length - 1] === '/') {
2981 return new Directory(path);
2982 }
2983 return new File_1.File(path);
2984 });
2985 };
2986 Directory.read = function (path, pattern, exclude) {
2987 return new Directory(path).read(pattern, exclude);
2988 };
2989 Directory.prototype.readFilesAsync = function (pattern, exclude) {
2990 var patterns = glob_1.glob_parsePatterns(pattern), excludes = glob_1.glob_parsePatterns(exclude);
2991 return dfr_factory(this, function (dfr, dir, path) {
2992 dir_transport_1.dir_filesAsync(path, patterns, exclude, function (error, files) {
2993 if (error) {
2994 dfr.reject(error);
2995 return;
2996 }
2997 dir.files = files.map(function (x) {
2998 var uri = new atma_utils_1.class_Uri(x);
2999 if (uri.isRelative()) {
3000 uri = dir.uri.combine(x);
3001 }
3002 return new File_1.File(uri);
3003 });
3004 dfr.resolve(dir.files);
3005 });
3006 });
3007 };
3008 Directory.readFilesAsync = function (path, pattern, exclude) {
3009 return new Directory(path).readFilesAsync(pattern, exclude);
3010 };
3011 Directory.prototype.readAsync = function (pattern, exclude) {
3012 var patterns = glob_1.glob_parsePatterns(pattern), excludes = glob_1.glob_parsePatterns(exclude);
3013 return dfr_factory(this, function (dfr, dir, path) {
3014 dir_transport_1.dir_filesAsync(path, patterns, exclude, { directories: true }, function (error, files) {
3015 if (error) {
3016 dfr.reject(error);
3017 return;
3018 }
3019 var arr = files.map(function (x) {
3020 var path = dir.uri.combine(x);
3021 if (x[x.length - 1] === '/')
3022 return new Directory(path);
3023 return new File_1.File(path);
3024 });
3025 dfr.resolve(arr, dir);
3026 });
3027 });
3028 };
3029 Directory.readAsync = function (path, pattern, exclude) {
3030 return new Directory(path).readAsync(pattern, exclude);
3031 };
3032 /*
3033 * Is sync, except if is not verbose, and target file exists
3034 *
3035 * options {Object} { verbose: Boolean} Confirm target file rewrite
3036 */
3037 Directory.prototype.copyTo = function (target, options) {
3038 if (options === void 0) { options = { verbose: false }; }
3039 var dfr = new global_1.Class.Deferred;
3040 if (Array.isArray(this.files) === false) {
3041 this.readFiles();
3042 }
3043 var uri = this.uri, targetUri = path_1.path_getUri(target), files = this.files, imax = files.length, i = -1;
3044 function next() {
3045 if (++i >= imax) {
3046 dfr.resolve();
3047 return;
3048 }
3049 var file = files[i], relPath = file.uri.toRelativeString(uri), to;
3050 to = targetUri.combine(relPath);
3051 if (options.verbose !== true && File_1.File.exists(to)) {
3052 var message = "File already exists: " + relPath + ". Replace? ";
3053 cli_1.cli_prompt(message, function (confirm) {
3054 if (confirm)
3055 file.copyTo(to);
3056 next();
3057 });
3058 return;
3059 }
3060 file.copyTo(to);
3061 next();
3062 }
3063 next();
3064 return dfr;
3065 };
3066 Directory.copyTo = function (path, target, options) {
3067 if (options === void 0) { options = { verbose: false }; }
3068 return new Directory(path).copyTo(target, options);
3069 };
3070 /*
3071 * options {Object} {
3072 * verbose: Boolean
3073 * } Confirm target file rewrite
3074 */
3075 Directory.prototype.copyToAsync = function (target, options) {
3076 if (options === void 0) { options = { verbose: false }; }
3077 var dfr = new global_1.Class.Deferred;
3078 if (Array.isArray(this.files) === false) {
3079 var dir = this;
3080 this
3081 .readFilesAsync()
3082 .done(function () {
3083 dir
3084 .copyToAsync(target, options)
3085 .done(dfr.resolveDelegate())
3086 .fail(dfr.rejectDelegate());
3087 })
3088 .fail(dfr.rejectDelegate());
3089 return dfr;
3090 }
3091 var uri = this.uri, targetUri = path_1.path_getUri(target), files = this.files, imax = files.length, i = -1;
3092 var awaiter = new global_1.Class.Await;
3093 while (++i < imax) {
3094 copy(i, awaiter.delegate(null));
3095 }
3096 awaiter
3097 .done(dfr.resolveDelegate())
3098 .fail(dfr.rejectDelegate());
3099 function copy(i, done) {
3100 var file = files[i], relPath = file.uri.toRelativeString(uri), to;
3101 to = targetUri.combine(relPath);
3102 if (options.verbose !== true && File_1.File.exists(to)) {
3103 var message = "File already exists: " + relPath + ". Replace? ";
3104 cli_1.cli_prompt(message, function (confirm) {
3105 if (confirm !== true)
3106 return;
3107 file
3108 .copyToAsync(to)
3109 .done(onComplete)
3110 .fail(done);
3111 });
3112 return;
3113 }
3114 file
3115 .copyToAsync(to)
3116 .done(onComplete)
3117 .fail(done);
3118 function onComplete() {
3119 done();
3120 }
3121 }
3122 return dfr;
3123 };
3124 Directory.copyToAsync = function (path, target, options) {
3125 if (options === void 0) { options = { verbose: false }; }
3126 return new Directory(path).copyToAsync(target, options);
3127 };
3128 Directory.prototype.getName = function () {
3129 return /([^\/]+)\/?$/.exec(this.uri.path)[1];
3130 };
3131 Directory.prototype.rename = function (name) {
3132 if (!name) {
3133 global_1.logger.error('<dir:rename> New Name is not defined');
3134 return;
3135 }
3136 var oldpath = this.uri.toLocalFile(), newpath = oldpath.replace(/[^\/]+\/?$/g, name);
3137 global_1.logger.log('<dir:rename>', oldpath, newpath);
3138 dir_transport_1.dir_rename(oldpath, newpath);
3139 };
3140 Directory.rename = function (path, name) {
3141 new Directory(path).rename(name);
3142 };
3143 Directory.prototype.renameAsync = function (name) {
3144 return dfr_factory(this, function (dfr, dir, path) {
3145 if (!name) {
3146 dfr.reject('Name is undefined');
3147 return;
3148 }
3149 var newpath = path.replace(/[^\/]+\/?$/g, name);
3150 dir_transport_1.dir_renameAsync(path, newpath, dfr_pipeDelegate(dfr));
3151 });
3152 };
3153 Directory.renameAsync = function (path, name) {
3154 return new Directory(path).renameAsync(name);
3155 };
3156 Directory.prototype.remove = function () {
3157 dir_transport_1.dir_remove(uri_toDirectory(this.uri));
3158 };
3159 Directory.remove = function (path) {
3160 new Directory(path).remove();
3161 };
3162 Directory.prototype.removeAsync = function () {
3163 return dfr_factory(this, function (dfr, dir, path) {
3164 dir_transport_1.dir_removeAsync(path, dfr_pipeDelegate(dfr));
3165 });
3166 };
3167 Directory.removeAsync = function (path) {
3168 return new Directory(path).removeAsync();
3169 };
3170 Directory.prototype.watch = function (callback) {
3171 Watcher_1.Watcher.watch(this.uri.toLocalFile(), callback);
3172 };
3173 Directory.watch = function (path, callback) {
3174 new Directory(path).watch(callback);
3175 };
3176 Directory.prototype.unwatch = function (callback) {
3177 Watcher_1.Watcher.unwatch(this.uri.toLocalFile(), callback);
3178 };
3179 Directory.unwatch = function (path, callback) {
3180 new Directory(path).unwatch(callback);
3181 };
3182 Directory.symlink = dir_transport_1.dir_symlink;
3183 return Directory;
3184}());
3185exports.Directory = Directory;
3186;
3187function dfr_factory(dir, fn) {
3188 var dfr = new global_1.Class.Deferred;
3189 fn(dfr, dir, uri_toDirectory(dir.uri));
3190 return dfr;
3191}
3192function dfr_pipeDelegate(dfr) {
3193 var argsBefore = [];
3194 for (var _i = 1; _i < arguments.length; _i++) {
3195 argsBefore[_i - 1] = arguments[_i];
3196 }
3197 return function (error) {
3198 var args = [];
3199 for (var _i = 1; _i < arguments.length; _i++) {
3200 args[_i - 1] = arguments[_i];
3201 }
3202 if (error) {
3203 dfr.reject(error);
3204 return;
3205 }
3206 dfr.resolve.apply(dfr, __spreadArrays(argsBefore, args));
3207 };
3208}
3209function uri_toDirectory(uri) {
3210 var fs = uri.protocol == null || uri.protocol === 'file';
3211 var path = fs
3212 ? uri.toLocalDir()
3213 : null;
3214 if (fs === false) {
3215 uri = new atma_utils_1.class_Uri(uri);
3216 uri.file = null;
3217 path = uri.toString();
3218 }
3219 return path;
3220}
3221;
3222
3223 function isObject(x) {
3224 return x != null && typeof x === 'object' && x.constructor === Object;
3225 }
3226 if (isObject(_src_Directory) && isObject(module.exports)) {
3227 Object.assign(_src_Directory, module.exports);
3228 return;
3229 }
3230 _src_Directory = module.exports;
3231}());
3232// end:source ./ModuleSimplified.js
3233
3234
3235// source ./ModuleSimplified.js
3236var _src_ExportsGlob;
3237(function () {
3238 var exports = {};
3239 var module = { exports: exports };
3240 "use strict";
3241Object.defineProperty(exports, "__esModule", { value: true });
3242var glob_1 = _src_util_glob;
3243var Directory_1 = _src_Directory;
3244exports.Glob = {
3245 matchPath: glob_1.glob_matchPath,
3246 readFiles: function (path) {
3247 var strict = glob_1.glob_getStrictPath(path), rel = glob_1.glob_getRelativePath(path);
3248 return new Directory_1.Directory(strict).readFiles(rel);
3249 },
3250 read: function (path) {
3251 var strict = glob_1.glob_getStrictPath(path), rel = glob_1.glob_getRelativePath(path);
3252 return new Directory_1.Directory(strict).read(rel);
3253 },
3254 readAsync: function (path, cb) {
3255 var strict = glob_1.glob_getStrictPath(path), rel = glob_1.glob_getRelativePath(path);
3256 return new Directory_1.Directory(strict)
3257 .readAsync(rel)
3258 .done(function (arr, dir) {
3259 cb(null, arr, dir);
3260 })
3261 .fail(function (err) {
3262 cb(err);
3263 });
3264 }
3265};
3266;
3267
3268 function isObject(x) {
3269 return x != null && typeof x === 'object' && x.constructor === Object;
3270 }
3271 if (isObject(_src_ExportsGlob) && isObject(module.exports)) {
3272 Object.assign(_src_ExportsGlob, module.exports);
3273 return;
3274 }
3275 _src_ExportsGlob = module.exports;
3276}());
3277// end:source ./ModuleSimplified.js
3278
3279
3280// source ./ModuleSimplified.js
3281var _src_ExportsSetts;
3282(function () {
3283 var exports = {};
3284 var module = { exports: exports };
3285 "use strict";
3286Object.defineProperty(exports, "__esModule", { value: true });
3287var File_1 = _src_File;
3288function setSettings(settings) {
3289 if (settings.extensions) {
3290 File_1.File.registerExtensions(settings.extensions, /* shouldCleanPrevious */ true);
3291 }
3292}
3293exports.setSettings = setSettings;
3294;
3295;
3296
3297 function isObject(x) {
3298 return x != null && typeof x === 'object' && x.constructor === Object;
3299 }
3300 if (isObject(_src_ExportsSetts) && isObject(module.exports)) {
3301 Object.assign(_src_ExportsSetts, module.exports);
3302 return;
3303 }
3304 _src_ExportsSetts = module.exports;
3305}());
3306// end:source ./ModuleSimplified.js
3307
3308"use strict";
3309var global_1 = _src_global;
3310var Env_1 = _src_Env;
3311var Watcher_1 = _src_Watcher;
3312var ExportsGlob_1 = _src_ExportsGlob;
3313var File_1 = _src_File;
3314var Directory_1 = _src_Directory;
3315var ExportsSetts_1 = _src_ExportsSetts;
3316var atma_utils_1 = require("atma-utils");
3317global_1.io.env = Env_1.Env;
3318global_1.io.watcher = Watcher_1.Watcher;
3319global_1.io.glob = ExportsGlob_1.Glob;
3320global_1.io.File = File_1.File;
3321global_1.io.Uri = atma_utils_1.class_Uri;
3322global_1.io.Directory = Directory_1.Directory;
3323global_1.io.settings = ExportsSetts_1.setSettings;
3324if (global_1.global.io == null) {
3325 global_1.global.io = global_1.io;
3326}
3327module.exports = global_1.io;
3328
3329
3330}());
3331// end:source ./RootModule.js