forked from fuse-box/fuse-box
/
bin.js
8786 lines (8106 loc) · 380 KB
/
bin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(FuseBox) {
FuseBox.$fuse$ = FuseBox;
FuseBox.pkg("fuse-box4-test", {}, function(___scope___) {
___scope___.file("index.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var VuePlugin_1 = require("./plugins/VuePlugin");
exports.VuePlugin = VuePlugin_1.VuePlugin;
var ImageBase64Plugin_1 = require("./plugins/images/ImageBase64Plugin");
exports.ImageBase64Plugin = ImageBase64Plugin_1.ImageBase64Plugin;
var CSSResourcePlugin_1 = require("./plugins/stylesheet/CSSResourcePlugin");
exports.CSSResourcePlugin = CSSResourcePlugin_1.CSSResourcePlugin;
var HotReloadPlugin_1 = require("./plugins/HotReloadPlugin");
exports.HotReloadPlugin = HotReloadPlugin_1.HotReloadPlugin;
var EnvPlugin_1 = require("./plugins/EnvPlugin");
exports.EnvPlugin = EnvPlugin_1.EnvPlugin;
var ConcatPlugin_1 = require("./plugins/ConcatPlugin");
exports.ConcatPlugin = ConcatPlugin_1.ConcatPlugin;
var StylusPlugin_1 = require("./plugins/stylesheet/StylusPlugin");
exports.StylusPlugin = StylusPlugin_1.StylusPlugin;
var PostCSSPlugin_1 = require("./plugins/stylesheet/PostCSSPlugin");
exports.PostCSS = PostCSSPlugin_1.PostCSS;
var TypeScriptHelpers_1 = require("./plugins/TypeScriptHelpers");
exports.TypeScriptHelpers = TypeScriptHelpers_1.TypeScriptHelpers;
var SVGPlugin_1 = require("./plugins/images/SVGPlugin");
exports.SVGPlugin = SVGPlugin_1.SVGPlugin;
var BabelPlugin_1 = require("./plugins/js-transpilers/BabelPlugin");
exports.BabelPlugin = BabelPlugin_1.BabelPlugin;
var CoffeePlugin_1 = require("./plugins/js-transpilers/CoffeePlugin");
exports.CoffeePlugin = CoffeePlugin_1.CoffeePlugin;
var LESSPlugin_1 = require("./plugins/stylesheet/LESSPlugin");
exports.LESSPlugin = LESSPlugin_1.LESSPlugin;
var CSSplugin_1 = require("./plugins/stylesheet/CSSplugin");
exports.CSSPlugin = CSSplugin_1.CSSPlugin;
var HTMLplugin_1 = require("./plugins/HTMLplugin");
exports.HTMLPlugin = HTMLplugin_1.HTMLPlugin;
var JSONplugin_1 = require("./plugins/JSONplugin");
exports.JSONPlugin = JSONplugin_1.JSONPlugin;
var BannerPlugin_1 = require("./plugins/BannerPlugin");
exports.BannerPlugin = BannerPlugin_1.BannerPlugin;
var SassPlugin_1 = require("./plugins/stylesheet/SassPlugin");
exports.SassPlugin = SassPlugin_1.SassPlugin;
var UglifyJSPlugin_1 = require("./plugins/UglifyJSPlugin");
exports.UglifyJSPlugin = UglifyJSPlugin_1.UglifyJSPlugin;
var SourceMapPlainJsPlugin_1 = require("./plugins/SourceMapPlainJsPlugin");
exports.SourceMapPlainJsPlugin = SourceMapPlainJsPlugin_1.SourceMapPlainJsPlugin;
var RawPlugin_1 = require("./plugins/RawPlugin");
exports.RawPlugin = RawPlugin_1.RawPlugin;
var WorkflowContext_1 = require("./WorkflowContext");
exports.WorkFlowContext = WorkflowContext_1.WorkFlowContext;
var PathMaster_1 = require("./PathMaster");
exports.PathMaster = PathMaster_1.PathMaster;
var Arithmetic_1 = require("./arithmetic/Arithmetic");
exports.Arithmetic = Arithmetic_1.Arithmetic;
var ModuleCollection_1 = require("./ModuleCollection");
exports.ModuleCollection = ModuleCollection_1.ModuleCollection;
var FuseBox_1 = require("./FuseBox");
exports.FuseBox = FuseBox_1.FuseBox;
});
___scope___.file("plugins/VuePlugin.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let vueCompiler;
class VuePluginClass {
constructor(opts) {
this.test = /\.vue$/;
this.opts = opts || {};
}
init(context) {
context.allowExtension(".vue");
}
transform(file) {
const context = file.context;
if (context.useCache) {
let cached = context.cache.getStaticCache(file);
if (cached) {
file.isLoaded = true;
if (cached.sourceMap) {
file.sourceMap = cached.sourceMap;
}
file.analysis.skip();
file.analysis.dependencies = cached.dependencies;
file.contents = cached.contents;
return;
}
}
file.loadContents();
if (!vueCompiler) {
vueCompiler = require("vue-template-compiler");
}
let result = vueCompiler.parseComponent(file.contents, this.opts);
if (result.template && result.template.type === "template") {
let html = result.template.content;
let jsContent = result.script.content;
const ts = require("typescript");
const jsTranspiled = ts.transpileModule(jsContent, file.context.getTypeScriptConfig());
const tsResult = `var View = require('vue/dist/vue.js');
var _p = {};
var _v = function(exports){${jsTranspiled.outputText}};
_p.template = ${JSON.stringify(html)};
let _e = {}; _v(_e); _p = Object.assign(_e.default, _p)
module.exports ={render : function(el){_p.el = el; return new View(_p)}}
`;
file.contents = tsResult;
file.analysis.parseUsingAcorn();
file.analysis.analyze();
if (context.useCache) {
context.emitJavascriptHotReload(file);
context.cache.writeStaticCache(file, file.sourceMap);
}
}
}
}
exports.VuePluginClass = VuePluginClass;;
exports.VuePlugin = (opts) => {
return new VuePluginClass(opts);
};
});
___scope___.file("plugins/images/ImageBase64Plugin.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const SVG2Base64_1 = require("../../lib/SVG2Base64");
const base64Img = require("base64-img");
class ImageBase64PluginClass {
constructor() {
this.test = /\.(gif|png|jpg|jpeg|svg)$/i;
}
init(context) {
context.allowExtension(".gif");
context.allowExtension(".png");
context.allowExtension(".jpg");
context.allowExtension(".jpeg");
context.allowExtension(".svg");
}
transform(file) {
const context = file.context;
const cached = context.cache.getStaticCache(file);
if (cached) {
file.isLoaded = true;
file.contents = cached.contents;
} else {
const ext = path.extname(file.absPath);
if (ext === ".svg") {
file.loadContents();
let content = SVG2Base64_1.SVG2Base64.get(file.contents);
file.contents = `module.exports = ${JSON.stringify(content)}`;
return;
}
file.isLoaded = true;
const data = base64Img.base64Sync(file.absPath);
file.contents = `module.exports = ${JSON.stringify(data)}`;
context.cache.writeStaticCache(file, undefined);
}
}
}
exports.ImageBase64PluginClass = ImageBase64PluginClass;;
exports.ImageBase64Plugin = () => {
return new ImageBase64PluginClass();
};
});
___scope___.file("lib/SVG2Base64.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class SVG2Base64 {
static get(content) {
content = content.replace(/"/g, "'");
content = content.replace(/\s+/g, " ");
content = content.replace(/[{}\|\\\^~\[\]`"<>#%]/g, (match) => {
return "%" + match[0].charCodeAt(0).toString(16).toUpperCase();
});
return "data:image/svg+xml;charset=utf8," + content.trim();
}
}
exports.SVG2Base64 = SVG2Base64;
});
___scope___.file("plugins/stylesheet/CSSResourcePlugin.js", function(exports, require, module, __filename, __dirname) {
/* fuse:injection: */
var Buffer = require("buffer").Buffer;
/* fuse:injection: */
var process = require("process");
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Utils_1 = require("../../Utils");
const path = require("path");
const realm_utils_1 = require("realm-utils");
const fs = require("fs");
const PostCSSResourcePlugin_1 = require("../../lib/postcss/PostCSSResourcePlugin");
const SVG2Base64_1 = require("../../lib/SVG2Base64");
const base64Img = require("base64-img");
const postcss = require("postcss");
const IMG_CACHE = {};
let resourceFolderChecked = false;
const copyFile = (source, target) => {
return new Promise((resolve, reject) => {
fs.exists(source, (exists) => {
if (!exists) {
return resolve();
}
let rd = fs.createReadStream(source);
rd.on("error", (err) => {
return reject(err);
});
let wr = fs.createWriteStream(target);
wr.on("error", (err) => {
return reject(err);
});
wr.on("close", (ex) => {
return resolve();
});
rd.pipe(wr);
});
});
};
const generateNewFileName = (str) => {
let s = str.split("node_modules");
const ext = path.extname(str);
if (s[1]) {
str = s[1];
}
let hash = 0;
let i;
let chr;
let len;
if (str.length === 0) {
return hash.toString() + ext;
}
for (i = 0, len = str.length; i < len; i++) {
chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0;
}
let fname = hash.toString() + ext;
if (fname.charAt(0) === "-") {
fname = "_" + fname.slice(1);
}
return fname;
};
class CSSResourcePluginClass {
constructor(opts) {
this.test = /\.css$/;
this.resolveFn = (p) => path.join("/css-resources", p);
opts = opts || {};
if (opts.dist) {
this.distFolder = Utils_1.ensureDir(opts.dist);
}
if (opts.inline) {
this.inlineImages = opts.inline;
}
if (realm_utils_1.utils.isFunction(opts.resolve)) {
this.resolveFn = opts.resolve;
}
}
init(context) {
context.allowExtension(".css");
}
createResouceFolder(file) {
if (resourceFolderChecked === false) {
resourceFolderChecked = true;
if (this.distFolder) {
return;
}
let outFilePath = Utils_1.ensureUserPath(file.context.outFile);
let outFileDir = path.dirname(outFilePath);
this.distFolder = Utils_1.ensureDir(path.join(outFileDir, "css-resources"));
}
}
transform(file) {
file.loadContents();
let contents = file.contents;
if (this.distFolder) {
this.createResouceFolder(file);
}
const currentFolder = file.info.absDir;
const files = {};
const tasks = [];
return postcss([PostCSSResourcePlugin_1.PostCSSResourcePlugin({
fn: (url) => {
let urlFile = path.resolve(currentFolder, url);
urlFile = urlFile.replace(/[?\#].*$/, "");
if (this.inlineImages) {
if (IMG_CACHE[urlFile]) {
return IMG_CACHE[urlFile];
}
if (!fs.existsSync(urlFile)) {
file.context.debug("CSSResourcePlugin", `Can't find file ${urlFile}`);
return;
}
const ext = path.extname(urlFile);
let fontsExtensions = {
'.woff': 'application/font-woff',
'.woff2': 'application/font-woff2',
'.eot': 'application/vnd.ms-fontobject',
'.ttf': 'application/x-font-ttf',
'.otf': 'font/opentype'
};
if (fontsExtensions[ext]) {
let content = new Buffer(fs.readFileSync(urlFile)).toString('base64');
return `data:${fontsExtensions[ext]};charset=utf-8;base64,${content}`;
}
if (ext === ".svg") {
let content = SVG2Base64_1.SVG2Base64.get(fs.readFileSync(urlFile).toString());
IMG_CACHE[urlFile] = content;
return content;
}
let result = base64Img.base64Sync(urlFile);
IMG_CACHE[urlFile] = result;
return result;
}
if (this.distFolder) {
let newFileName = generateNewFileName(urlFile);
if (!files[urlFile]) {
let newPath = path.join(this.distFolder, newFileName);
tasks.push(copyFile(urlFile, newPath));
files[urlFile] = true;
}
return this.resolveFn(newFileName);
}
},
})]).process(contents).then(result => {
file.contents = result.css;
return Promise.all(tasks);
});
}
}
exports.CSSResourcePluginClass = CSSResourcePluginClass;
exports.CSSResourcePlugin = (options) => {
return new CSSResourcePluginClass(options);
};
});
___scope___.file("Utils.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const fs = require("fs");
const appRoot = require("app-root-path");
const mkdirp = require("mkdirp");
const MBLACKLIST = [
"freelist",
"sys"
];
exports.Concat = require("concat-with-sourcemaps");
function contains(array, obj) {
return array && array.indexOf(obj) > -1;
}
exports.contains = contains;
function replaceAliasRequireStatement(requireStatement, aliasName, aliasReplacement) {
requireStatement = requireStatement.replace(aliasName, aliasReplacement);
requireStatement = path.normalize(requireStatement);
return requireStatement;
}
exports.replaceAliasRequireStatement = replaceAliasRequireStatement;
function write(fileName, contents) {
return new Promise((resolve, reject) => {
fs.writeFile(fileName, contents, (e) => {
if (e) {
return reject(e);
}
return resolve();
});
});
}
exports.write = write;
function camelCase(str) {
let DEFAULT_REGEX = /[-_]+(.)?/g;
function toUpper(match, group1) {
return group1 ? group1.toUpperCase() : "";
}
return str.replace(DEFAULT_REGEX, toUpper);
}
exports.camelCase = camelCase;
function parseQuery(qstr) {
let query = new Map();
let a = qstr.split("&");
for (let i = 0; i < a.length; i++) {
let b = a[i].split("=");
query.set(decodeURIComponent(b[0]), decodeURIComponent(b[1] || ""));
}
return query;
}
exports.parseQuery = parseQuery;
function ensureUserPath(userPath) {
if (!path.isAbsolute(userPath)) {
userPath = path.join(appRoot.path, userPath);
}
userPath = path.normalize(userPath);
let dir = path.dirname(userPath);
mkdirp.sync(dir);
return userPath;
}
exports.ensureUserPath = ensureUserPath;
function ensureDir(userPath) {
if (!path.isAbsolute(userPath)) {
userPath = path.join(appRoot.path, userPath);
}
userPath = path.normalize(userPath);
mkdirp.sync(userPath);
return userPath;
}
exports.ensureDir = ensureDir;
function removeFolder(userPath) {
if (fs.existsSync(userPath)) {
fs.readdirSync(userPath).forEach(function(file, index) {
var curPath = path.join(userPath, file);
if (fs.lstatSync(curPath).isDirectory()) {
removeFolder(curPath);
} else {
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(userPath);
}
}
exports.removeFolder = removeFolder;
function replaceExt(npath, ext) {
if (typeof npath !== "string") {
return npath;
}
if (npath.length === 0) {
return npath;
}
if (/\.[a-z0-9]+$/i.test(npath)) {
return npath.replace(/\.[a-z0-9]+$/i, ext);
} else {
return npath + ext;
}
}
exports.replaceExt = replaceExt;
function ensurePublicExtension(url) {
let ext = path.extname(url);
if (ext === ".ts") {
url = replaceExt(url, ".js");
}
if (ext === ".tsx") {
url = replaceExt(url, ".jsx");
}
return url;
}
exports.ensurePublicExtension = ensurePublicExtension;
function getBuiltInNodeModules() {
const process = global.process;
return Object.keys(process.binding("natives")).filter(m => {
return !/^_|^internal|\//.test(m) && MBLACKLIST.indexOf(m) === -1;
});
}
exports.getBuiltInNodeModules = getBuiltInNodeModules;
function findFileBackwards(target, limitPath) {
let [found, reachedLimit] = [false, false];
let filename = path.basename(target);
let current = path.dirname(target);
let iterations = 0;
const maxIterations = 10;
while (found === false && reachedLimit === false) {
let targetFilePath = path.join(current, filename);
if (fs.existsSync(targetFilePath)) {
return targetFilePath;
}
if (limitPath === current) {
reachedLimit = true;
}
current = path.join(current, "..");
iterations++;
if (iterations > maxIterations) {
reachedLimit = true;
}
}
}
exports.findFileBackwards = findFileBackwards;
});
___scope___.file("lib/postcss/PostCSSResourcePlugin.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const postcss = require("postcss");
const extractValue = (input) => {
const first = input.charCodeAt(0);
const last = input.charCodeAt(input.length - 1);
if (first === 39 || first === 34) {
input = input.slice(1);
}
if (last === 39 || last === 34) {
input = input.slice(0, -1);
}
if (/data:/.test(input)) {
return;
}
return input;
};
exports.PostCSSResourcePlugin = postcss.plugin("css-resource", function(opts) {
opts = opts || {};
return (css, result) => {
css.walkDecls(declaration => {
if (declaration.prop) {
if (declaration.prop.indexOf("background") === 0 || declaration.prop.indexOf("src") === 0) {
let re = /url\((.*?)\)/g;
let match;
while (match = re.exec(declaration.value)) {
const value = match[1];
const url = extractValue(value);
if (typeof opts.fn === "function" && url) {
const result = opts.fn(url);
if (typeof result === "string") {
declaration.value = declaration.value.replace(match[0], `url("${result}")`);
}
}
}
}
}
});
};
});
});
___scope___.file("plugins/HotReloadPlugin.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class HotReloadPluginClass {
constructor(opts = {}) {
this.dependencies = ["fusebox-hot-reload"];
this.port = "";
this.uri = "";
if (opts.port) {
this.port = opts.port;
}
if (opts.uri) {
this.uri = opts.uri;
}
}
init() {}
bundleEnd(context) {
context.source.addContent(`FuseBox.import("fusebox-hot-reload").connect(${this.port}, ${JSON.stringify(this.uri)})`);
}
}
exports.HotReloadPluginClass = HotReloadPluginClass;;
exports.HotReloadPlugin = (opts) => {
return new HotReloadPluginClass(opts);
};
});
___scope___.file("plugins/EnvPlugin.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class EnvPluginClass {
constructor(env) {
this.env = env;
}
bundleStart(context) {
context.source.addContent(`var __process_env__ = ${JSON.stringify(this.env)};`);
}
}
exports.EnvPluginClass = EnvPluginClass;
exports.EnvPlugin = (banner) => {
return new EnvPluginClass(banner);
};
});
___scope___.file("plugins/ConcatPlugin.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class ConcatPluginClass {
constructor(opts = {}) {
this.delimiter = "\n";
this.test = /\.txt$/;
if ("ext" in opts) {
this.ext = opts.ext;
}
if ("name" in opts) {
this.bundleName = opts.name;
}
if ("delimiter" in opts) {
this.delimiter = opts.delimiter;
}
}
init(context) {
if (this.ext) {
context.allowExtension(this.ext);
}
}
transform(file) {
file.loadContents();
let context = file.context;
let fileGroup = context.getFileGroup(this.bundleName);
if (!fileGroup) {
fileGroup = context.createFileGroup(this.bundleName, file.collection, this);
}
fileGroup.addSubFile(file);
file.alternativeContent = `module.exports = require("./${this.bundleName}")`;
}
transformGroup(group) {
let contents = [];
group.subFiles.forEach(file => {
contents.push(file.contents);
});
let text = contents.join(this.delimiter);
group.contents = `module.exports = ${JSON.stringify(text)}`;
}
}
exports.ConcatPluginClass = ConcatPluginClass;;
exports.ConcatPlugin = (opts) => {
return new ConcatPluginClass(opts);
};
});
___scope___.file("plugins/stylesheet/StylusPlugin.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let stylus;
class StylusPluginClass {
constructor(options) {
this.test = /\.styl$/;
this.options = options || {};
}
init(context) {
context.allowExtension('.styl');
}
transform(file) {
const context = file.context;
const options = Object.assign({}, this.options);
const sourceMapDef = {
comment: false,
sourceRoot: file.info.absDir
};
file.loadContents();
if (!stylus)
stylus = require('stylus');
options.filename = file.info.fuseBoxPath;
if ('sourceMapConfig' in context) {
options.sourcemap = Object.assign({}, sourceMapDef, this.options.sourcemap || {});
}
return new Promise((res, rej) => {
const renderer = stylus(file.contents, options);
return renderer.render((err, css) => {
if (err)
return rej(err);
if (renderer.sourcemap) {
file.sourceMap = JSON.stringify(renderer.sourcemap);
}
file.contents = css;
return res(css);
});
});
}
}
exports.StylusPluginClass = StylusPluginClass;
exports.StylusPlugin = (options) => {
return new StylusPluginClass(options);
};
});
___scope___.file("plugins/stylesheet/PostCSSPlugin.js", function(exports, require, module, __filename, __dirname) {
/* fuse:injection: */
var process = require("process");
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let postcss;
class PostCSSPluginClass {
constructor(processors, opts) {
this.processors = processors;
this.opts = opts;
this.test = /\.css$/;
this.dependencies = [];
this.opts = this.opts || {};
this.processors = this.processors || [];
}
init(context) {
context.allowExtension(".css");
}
transform(file) {
file.loadContents();
if (!postcss) {
postcss = require("postcss");
}
return postcss(this.processors)
.process(file.contents, this.opts)
.then(result => {
file.contents = result.css;
return result.css;
});
}
}
exports.PostCSSPluginClass = PostCSSPluginClass;
exports.PostCSS = (processors, opts) => {
return new PostCSSPluginClass(processors, opts);
};
});
___scope___.file("plugins/TypeScriptHelpers.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Config_1 = require("./../Config");
const fs = require("fs");
const path = require("path");
class TypeScriptHelpersClass {
constructor(opts) {
this.test = /(\.js|\.ts)$/;
this.registeredHelpers = new Map();
opts = opts || {};
let folder = path.join(Config_1.Config.FUSEBOX_MODULES, "fuse-typescript-helpers");
let files = fs.readdirSync(folder);
files.forEach(fileName => {
let contents = fs.readFileSync(path.join(folder, fileName)).toString();
let name = fileName.replace(/\.js/, "");
this.registeredHelpers.set(name, contents);
});
}
init(context) {
context.setItem("ts_helpers", new Set());
}
bundleEnd(context) {
let helpers = context.getItem("ts_helpers");
helpers.forEach(name => {
let contents = this.registeredHelpers.get(name);
context.source.addContent(contents);
});
}
transform(file) {
let patchDecorate = false;
if (file.collection.name !== file.context.defaultPackageName) {
return;
}
let helpers = file.context.getItem("ts_helpers");
this.registeredHelpers.forEach((cont, name) => {
let regexp = new RegExp(name, "gm");
if (regexp.test(file.contents)) {
if (name === "__decorate") {
patchDecorate = true;
}
if (!helpers.has(name)) {
helpers.add(name);
}
}
});
if (patchDecorate) {
file.addHeaderContent("var __decorate = __fsbx_decorate(arguments)");
}
}
}
exports.TypeScriptHelpersClass = TypeScriptHelpersClass;
exports.TypeScriptHelpers = () => {
return new TypeScriptHelpersClass({});
};
});
___scope___.file("Config.js", function(exports, require, module, __filename, __dirname) {
/* fuse:injection: */
var process = require("process");
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const appRoot = require("app-root-path");
const path = require("path");
const PROJECT_ROOT = process.env.FUSEBOX_DIST_ROOT || path.join(__dirname, "../../");
class Configuration {
constructor() {
this.NODE_MODULES_DIR = process.env.PROJECT_NODE_MODULES || path.join(appRoot.path, "node_modules");
this.FUSEBOX_MODULES = path.join(PROJECT_ROOT, "modules");
this.TEMP_FOLDER = path.join(appRoot.path, ".fusebox");
this.PROJECT_FOLDER = appRoot.path;
this.FUSEBOX_VERSION = process.env.FUSEBOX_VERSION || require(path.join(PROJECT_ROOT, "package.json")).version;
}
}
exports.Configuration = Configuration;
exports.Config = new Configuration();
});
___scope___.file("plugins/images/SVGPlugin.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class SVGSimplePlugin {
constructor() {
this.test = /\.svg$/;
}
init(context) {
context.allowExtension(".svg");
}
transform(file) {
file.loadContents();
let content = file.contents;
content = content.replace(/"/g, "'");
content = content.replace(/\s+/g, " ");
content = content.replace(/[{}\|\\\^~\[\]`"<>#%]/g, (match) => {
return "%" + match[0].charCodeAt(0).toString(16).toUpperCase();
});
let data = "data:image/svg+xml;charset=utf8," + content.trim();
file.contents = `module.exports = ${JSON.stringify(data)}`;
}
}
exports.SVGSimplePlugin = SVGSimplePlugin;;
exports.SVGPlugin = () => {
return new SVGSimplePlugin();
};
});
___scope___.file("plugins/js-transpilers/BabelPlugin.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require("path");
const appRoot = require("app-root-path");
let babelCore;
class BabelPluginClass {
constructor(opts) {
this.test = /\.(j|t)s(x)?$/;
this.limit2project = true;
this.config = {};
this.configPrinted = false;
let babelRcConfig;
let babelRcPath = path.join(appRoot.path, `.babelrc`);
if (fs.existsSync(babelRcPath)) {
babelRcConfig = fs.readFileSync(babelRcPath).toString();
if (babelRcConfig)
babelRcConfig = JSON.parse(babelRcConfig);
}
opts = opts || {};
this.config = opts.config ? opts.config : babelRcConfig;
if (opts.test !== undefined) {
this.test = opts.test;
}
if (opts.limit2project !== undefined) {
this.limit2project = opts.limit2project;
}
}
init(context) {
this.context = context;
context.allowExtension(".jsx");
}
transform(file, ast) {
if (!babelCore) {
babelCore = require("babel-core");
}
if (this.configPrinted === false) {
file.context.debug("BabelPlugin", `\n\tConfiguration: ${JSON.stringify(this.config)}`);
this.configPrinted = true;
}
if (this.context.useCache) {
let cached = this.context.cache.getStaticCache(file);
if (cached) {
if (cached.sourceMap) {
file.sourceMap = cached.sourceMap;
}
file.analysis.skip();
file.analysis.dependencies = cached.dependencies;
file.contents = cached.contents;
return;
}
}
if (this.limit2project === false || file.collection.name === file.context.defaultPackageName) {
let result = babelCore.transform(file.contents, this.config);
if (result.ast) {
file.analysis.loadAst(result.ast);
file.analysis.analyze();
file.contents = result.code;
if (result.map) {
let sm = result.map;
sm.file = file.info.fuseBoxPath;
sm.sources = [file.info.fuseBoxPath];
file.sourceMap = JSON.stringify(sm);
}
if (this.context.useCache) {
this.context.emitJavascriptHotReload(file);
this.context.cache.writeStaticCache(file, file.sourceMap);
}
}
}
}
}
exports.BabelPluginClass = BabelPluginClass;;
exports.BabelPlugin = (opts) => {
return new BabelPluginClass(opts);
};
});
___scope___.file("plugins/js-transpilers/CoffeePlugin.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let coffee;
class CoffeePluginClass {
constructor(options) {
this.test = /\.coffee$/;
this.options = Object.assign({}, {
bare: true,
sourceMap: false,
sourceRoot: "",
literate: false,
filename: false,
sourceFiles: false,
generatedFile: false
}, options);
}
init(context) {
context.allowExtension('.coffee');
}
transform(file) {
file.loadContents();
if (!coffee) {
coffee = require('coffee-script');
}
return new Promise((res, rej) => {
try {
let options = Object.assign({}, this.options, {
filename: file.absPath
});
file.contents = coffee.compile(file.contents, options);
res(file.contents);
} catch (err) {
rej(err);
}
});
}
}
exports.CoffeePluginClass = CoffeePluginClass;
exports.CoffeePlugin = (options = {}) => {
return new CoffeePluginClass(options);
};
});
___scope___.file("plugins/stylesheet/LESSPlugin.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let less;
class LESSPluginClass {
constructor(options) {
this.test = /\.less$/;
this.options = options || {};
}
init(context) {
context.allowExtension(".less");
}
transform(file) {
const context = file.context;
const options = Object.assign({}, this.options);
file.loadContents();
const sourceMapDef = {
sourceMapBasepath: '.',
sourceMapRootpath: file.info.absDir
};
if (!less) {
less = require("less");
}
options.filename = file.info.fuseBoxPath;
if ('sourceMapConfig' in context) {
options.sourceMap = Object.assign({}, sourceMapDef, options.sourceMap || {});
}
return less.render(file.contents, options).then(output => {
if (output.map) {
file.sourceMap = output.map;
}
file.contents = output.css;
});
}
}
exports.LESSPluginClass = LESSPluginClass;
exports.LESSPlugin = (opts) => {
return new LESSPluginClass(opts);
};
});
___scope___.file("plugins/stylesheet/CSSplugin.js", function(exports, require, module, __filename, __dirname) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const path = require("path");
const Config_1 = require("./../../Config");
const realm_utils_1 = require("realm-utils");
const CSSPluginDeprecated_1 = require("./CSSPluginDeprecated");
const Utils_1 = require("../../Utils");
class CSSPluginClass {