forked from jae-jae/Userscript-Plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-userscript.js
39 lines (32 loc) · 1.28 KB
/
build-userscript.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
var babel = require("babel-core");
var fs = require("fs");
var tpl = fs.readFileSync('./userscript/tpl.js').toString();
var code = babel.transformFileSync("./userscript/main.js").code;
var nano = function(template, data) {
return template.replace(/\{([\w\.]*)\}/g, function(str, key) {
let keys = key.split("."),
v = data[keys.shift()];
for (let i = 0, l = keys.length; i < l; i++) v = v[keys[i]];
return (typeof v !== "undefined" && v !== null) ? v : "";
});
};
var renderOut = function(outFile,ljs){
var ujs = nano(tpl, {
ljs: ljs,
code: code,
time: (+new Date())
});
fs.writeFile(outFile, ujs, function(err) {
if (err) {
return console.log(err);
}
return console.log('build-out:' + outFile);
});
};
var ljs = `// @require https://raw.githubusercontent.com/jae-jae/l.js/master/userjs/l.userjs.min.js
// @require https://gist.githubusercontent.com/jae-jae/35a1833079d26e6c9d9c6d5bed982353/raw/userjs-base.js`;
var ljs_GF = `// @require https://greasyfork.org/scripts/23419-l-js/code/ljs.js
// @require https://greasyfork.org/scripts/23420-userjs-base-js/code/userjs-basejs.js`;
renderOut('./dist/show-site-all-userjs.user.js',ljs);
//greasyfork version
renderOut('./dist/show-site-all-userjs.gf.user.js',ljs_GF);