-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
154 lines (142 loc) · 5.07 KB
/
gulpfile.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
try {
require("./dist/src/compiler/gulpfile");
} catch (error) {
console.error(error);
}
const gulp = require("gulp");
const fs = require("fs");
const path = require("path");
const siteConfig = require("./config.json");
const spawn = require("cross-spawn");
const slash = require("slash");
const http = require("https"); // or 'https' for https:// URLs
const download = function (url, dest) {
const file = fs.createWriteStream(dest);
const request = http.get(url, function (response) {
response.pipe(file);
});
return request;
};
const webConfig = {
google: {
key: siteConfig.google.key,
recaptcha: {
key: siteConfig.google.recaptcha.key,
},
analystics: {
id: siteConfig.google.analystics.id,
},
},
};
/**
* fs.readdirSync recursive
* @param {string} dir
* @param {(err:NodeJS.ErrnoException|null, results:string[])} done
*/
var walk = function (dir, done) {
var results = [];
fs.readdir(dir, function (err, list) {
if (err) return done(err);
var i = 0;
(function next() {
var file = list[i++];
if (!file) return done(null, results);
file = path.resolve(dir, file);
fs.stat(file, function (err, stat) {
if (stat && stat.isDirectory()) {
walk(file, function (err, res) {
results = results.concat(res);
next();
});
} else {
results.push(file);
next();
}
});
})();
});
};
gulp.task("config", function (done) {
fs.writeFileSync(path.join(__dirname, "/libs/js/_conf.ts"), "const siteConfig = " + JSON.stringify(webConfig));
fs.writeFileSync(
path.join(__dirname, "libs/src/compiler/config.ts"),
"export const config = " + JSON.stringify(siteConfig)
);
download(
"https://raw.githubusercontent.com/microsoft/TypeScript/master/lib/lib.dom.d.ts",
"./libs/js/lib.dom.d.ts"
);
let interf = "";
let modes = [];
let modeArrays = [];
fs.readdirSync("./node_modules/codemirror/mode", { encoding: "utf-8" }).map(function (dir, i, arr) {
modes.push(`'${dir}'`);
modeArrays.push(`'${dir}'[]`);
});
let themes = [];
fs.readdirSync("./node_modules/codemirror/theme").map(function (file, i, arr) {
themes.push(`'${file.replace(/\.css$/, "")}'`);
});
let codename = [];
let codenames = [];
walk("./node_modules/codemirror/addon", function (err, result) {
if (!err) {
let newResult = {};
result.map(function (file) {
let repl = file.replace(path.join(__dirname, "node_modules/codemirror/addon"), "");
repl = slash(repl);
repl = repl.replace(/\//g, "-");
let id = "CodeMirror" + repl.replace(/\.(js|css)$/g, "");
if (!newResult.hasOwnProperty(id)) {
newResult[id] = {};
codename.push(`'${id}'`);
codenames.push(`'${id}'[]`);
}
if (repl.includes(".css")) {
newResult[id].css = slash(file.replace(__dirname, ""));
} else {
newResult[id].js = slash(file.replace(__dirname, ""));
}
});
setTimeout(() => {
//interf += `declare const CodeMirrorAddon = ${JSON.stringify(newResult, null, 4)};\n`;
fs.writeFileSync(
"./libs/js/Codemirror-var.ts",
`const CodeMirrorAddon = ${JSON.stringify(newResult, null, 4)};\n`
);
}, 1000);
}
});
setTimeout(() => {
interf += `interface CodeMirrorConfig {
addon : ${codename.join(" | ")};
theme : ${themes.join(" | ")};
mode : ${modes.join(" | ")};
modes : ${modeArrays.join(" | ")};
modeAll : ${modes.join(" | ")} | ${modeArrays.join(" | ")};
addons : ${codenames.join(" | ")};
addonAll : ${codename.join(" | ")} | ${codenames.join(" | ")};
}\n`;
fs.writeFileSync(path.join(__dirname, "libs/js/Codemirror.d.ts"), interf);
done();
}, 2000);
});
gulp.task("compile", function (done) {
["tsconfig.formsaver.json", "tsconfig.precompiler.json", "tsconfig.compiler.json", "tsconfig.build.json"].map(
function (config, index, arr) {
const child = spawn("tsc", ["-p", config]);
child.addListener("error", console.error);
child.addListener("message", console.info);
child.stdout.on("data", function (data) {
console.log("stdout: " + data);
});
child.stderr.on("data", function (data) {
console.log("stderr: " + data);
});
child.stdin.on("data", function (data) {
console.log("stdin: " + data);
});
if (index == arr.length - 1) done();
}
);
});