-
Notifications
You must be signed in to change notification settings - Fork 14
/
html-builder.js
93 lines (75 loc) · 2.3 KB
/
html-builder.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
// Credits:
// Guy Bedford https://github.com/guybedford
var Vulcan = System._nodeRequire('vulcanize');
var Promise = global.Promise || System._nodeRequire('es6-promise').Promise;
// it's bad to do this in general, as code is now heavily environment specific
var fs = System._nodeRequire('fs');
var isWin = process.platform.match(/^win/);
function fromFileURL(address) {
address = address.replace(/^file:(\/+)?/i, '');
if (isWin) {
address = address.replace(/\//g, '\\');
} else {
address = '/' + address;
}
return address;
}
function extend(a, b) {
for (var p in b) {
if (b.hasOwnProperty(p)) {
a[p] = b[p];
}
}
return a;
}
/* function errCallback(err) {
setTimeout(function () {
throw err;
});
} */
module.exports = function bundle(loads, opts) {
var loader = this;
var options = {
excludes: [],
inlineScripts: true,
inlineCss: true,
implicitStrip: true,
stripComments: false
};
if (loader.vulvanizeHTML) {
extend(options, loader.vulvanizeHTML);
}
var vulcan = new Vulcan(options);
/* var minimize = new Minimize({
empty: false, // KEEP empty attributes
cdata: true, // KEEP CDATA from scripts
comments: false, // KEEP comments
ssi: false, // KEEP Server Side Includes
conditionals: true, // KEEP conditional internet explorer comments
spare: false, // KEEP redundant attributes
quotes: false, // KEEP arbitrary quotes
loose: false // KEEP one whitespace
}); */
// var rootURL = loader.rootURL || fromFileURL(loader.baseURL);
var outFile = opts.outFile.replace(/\.js$/, '.html');
var output = loads.map(function (load) {
return '<link rel="import" href="' + fromFileURL(load.address) + '">';
}).join('\n');
var stubDefines = loads.map(function (load) {
return "System\.register('" + load.name + "', [], false, function() {});";
}).join('\n');
return new Promise(function (resolve, reject) {
fs.writeFileSync(outFile, output);
console.log(' Vulcanizing ', outFile);
vulcan.process(outFile, function (error, output) {
if (error) {
return reject(error);
}
// minimize.parse(output, function(error, output) {
// if (error) { return reject(error); }
fs.writeFileSync(outFile, output);
resolve(stubDefines);
// });
});
});
};