forked from kuitos/kuitos.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.js
67 lines (48 loc) · 1.6 KB
/
deploy.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
/**
* @author Kuitos
* @homepage https://github.com/kuitos/
* @since 2015-11-03
*/
var fs = require('fs');
var path = require('path');
var indexHtml = fs.readFileSync(path.resolve(__dirname, "./src/index.html"), "utf-8");
var assets = require('./build/assets.json');
var interpolator = {
js: {
regex : /<!--\s*build:js\s*-->/,
inlineTag: 'script',
outerTag : '<script src="{{js}}"></script>'
},
css: {
regex : /<!--\s*build:css\s*-->/,
inlineTag: 'style',
outerTag : '<link rel="stylesheet" href="{{css}}">'
}
};
var isInlineAssets = process.argv.some(function (argv) {
return argv === '--inline-source';
});
['script', 'link', 'style'].forEach(tag => {
indexHtml = indexHtml.replace(new RegExp(`<${tag}.*>.*</${tag}>`, 'g'), '');
});
if (isInlineAssets) {
Object.keys(interpolator).forEach(type => {
var sourcePath = assets.app[type],
info;
if (sourcePath) {
info = interpolator[type];
indexHtml = indexHtml.replace(info.regex, `<${info.inlineTag}>` + fs.readFileSync(path.resolve(__dirname,
`.${assets.app[type]}`), 'utf-8') + `</${info.inlineTag}>`);
}
});
} else {
Object.keys(interpolator).forEach(type => {
var sourcePath = assets.app[type],
info;
if (sourcePath) {
info = interpolator[type];
indexHtml = indexHtml.replace(info.regex, info.outerTag.replace(`{{${type}}}`, assets.app[type]));
}
});
}
fs.writeFile(path.resolve(__dirname, './index.html'), indexHtml, 'utf-8');