forked from jslint-org/jslint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.ci.sh
291 lines (290 loc) · 9.21 KB
/
.ci.sh
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
shCiArtifactUploadCustom() {(set -e
# this function will custom-upload build-artifacts to branch-gh-pages
# .cache - restore
if [ -d .cache ]
then
cp -a .cache/* .
# js-hack - */
fi
# save jslint.cjs
mv .jslint.cjs jslint.cjs
cp jslint.mjs jslint.js
git add -f jslint.cjs jslint.js
# seo - inline css-assets and invalidate cached-assets
node --input-type=module -e '
import moduleFs from "fs";
(async function () {
let cacheKey = Math.random().toString(36).slice(-4);
let fileDict = {};
await Promise.all([
"index.html"
].map(async function (file) {
try {
fileDict[file] = await moduleFs.promises.readFile(file, "utf8");
} catch (ignore) {
process.exit();
}
}));
// invalidate cached-assets
fileDict["index.html"] = fileDict["index.html"].replace((
/\b(?:href|src)=".+?\.(?:css|js|mjs)\b/g
), function (match0) {
return `${match0}?cc=${cacheKey}`;
});
// write file
Object.entries(fileDict).map(function ([
file, data
]) {
moduleFs.promises.writeFile(file, data);
});
}());
' "$@" # '
# screenshot quickstart
node --input-type=module -e '
import moduleFs from "fs";
import moduleChildProcess from "child_process";
(async function () {
let screenshotCurl;
screenshotCurl = await moduleFs.promises.stat("jslint.mjs");
screenshotCurl = String(`
echo "\
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 250k 100 250k 0 0 250k 0 0:00:01 --:--:-- 0:00:01 250k\
"
`).trim().replace((
/250/g
), Math.floor(screenshotCurl.size / 1024));
// parallel-task - run-and-screenshot example-shell-commands in README.md
await Promise.all(Array.from(String(
await moduleFs.promises.readFile("README.md", "utf8")
).matchAll(
/\n```shell <!-- shRunWithScreenshotTxt (.*?) -->\n([\S\s]*?\n)```\n/g
)).map(async function ([
ignore, file, script0
]) {
let script = script0;
// modify script - jslint install
script = script.replace(
"curl -L https://www.jslint.com/jslint.mjs > jslint.mjs",
screenshotCurl
);
// modify script - cd node-sqlite3
script = script.replace((
/\n\ncd node-sqlite3-\w*?\n/g
), (
" 2>/dev/null || true\n"
+ "$&\n"
+ "git checkout 60a022c511a37788e652c271af23174566a80c30\n"
));
// limit stdout to 100 lines
script = script.trimRight() + " 2>&1 | head -n 100\n";
// printf script
script = (
"(set -e\n"
+ "printf \u0027"
+ script0.trim().replace((
/[%\\]/gm
), "$&$&").replace((
/\u0027/g
), "\u0027\"\u0027\"\u0027").replace((
/^/gm
), "> ")
+ "\n\n\n\u0027\n"
+ script
+ ")\n"
);
await moduleFs.promises.writeFile(file + ".sh", script);
await new Promise(function (resolve) {
moduleChildProcess.spawn(
"sh",
[
"jslint_ci.sh", "shRunWithScreenshotTxt", file,
"sh", file + ".sh"
],
{
stdio: [
"ignore", 1, 2
]
}
).on("exit", resolve);
});
}));
}());
' "$@" # '
# screenshot asset_image_logo
shImageLogoCreate &
# screenshot html
node --input-type=module -e '
import moduleChildProcess from "child_process";
(async function () {
await Promise.all([
(
"https://"
+ process.env.UPSTREAM_OWNER
+ ".github.io/"
+ process.env.UPSTREAM_REPO
+ "/branch-beta/index.html"
),
".artifact/apidoc.html",
".artifact/coverage_sqlite3_js/index.html",
".artifact/coverage_sqlite3_js/lib/sqlite3.js.html",
".artifact/coverage_sqlite3_sh/index.html",
".artifact/coverage_sqlite3_sh/lib/sqlite3.js.html",
".artifact/jslint_report_hello.html"
].map(async function (url) {
await new Promise(function (resolve) {
moduleChildProcess.spawn(
"sh",
[
"jslint_ci.sh", "shBrowserScreenshot", url
],
{
stdio: [
"ignore", 1, 2
]
}
).on("exit", resolve);
});
}));
}());
' "$@" # '
# remove bloated json-coverage-files
rm .artifact/coverage/*.json
rm .artifact/coverage_sqlite3_*/*.json
# js-hack - */
# .cache - save
if [ ! -d .cache ]
then
mkdir .cache
cp -a node-sqlite3-* .cache
fi
)}
shCiBaseCustom() {(set -e
# this function will run base-ci
# update version in README.md, jslint.mjs, package.json from CHANGELOG.md
if [ "$(git branch --show-current)" = alpha ]
then
node --input-type=module -e '
import jslint from "./jslint.mjs";
import moduleFs from "fs";
(async function () {
let fileDict = {};
let fileModified;
let packageDescription;
let versionBeta;
let versionMaster;
await Promise.all([
"CHANGELOG.md",
"README.md",
"index.html",
"jslint.mjs",
"jslint_ci.sh",
"package.json"
].map(async function (file) {
fileDict[file] = await moduleFs.promises.readFile(file, "utf8");
}));
packageDescription = fileDict["package.json"].match(
/"description": "(.*?)"/
)[1];
Array.from(fileDict["CHANGELOG.md"].matchAll(
/\n\n# (v\d\d\d\d\.\d\d?\.\d\d?(.*?)?)\n/g
)).slice(0, 2).forEach(function ([
ignore, version, isBeta
]) {
versionBeta = versionBeta || version;
versionMaster = versionMaster || (!isBeta && version);
});
await Promise.all([
{
file: "README.md",
src: fileDict["README.md"].replace((
/\bv\d\d\d\d\.\d\d?\.\d\d?\b/m
), versionMaster).replace((
/\n# .*/
), "\n# " + packageDescription)
}, {
file: "index.html",
src: fileDict["index.html"].replace((
/\n<style\sclass="JSLINT_REPORT_STYLE">\n[\S\s]*?\n<\/style>\n/
), function () {
return fileDict["jslint.mjs"].match(
/\n<style\sclass="JSLINT_REPORT_STYLE">\n[\S\s]*?\n<\/style>\n/
)[0];
})
}, {
file: "jslint.mjs",
// inline css-assets
src: fileDict["jslint.mjs"].replace((
/^let jslint_edition = ".*?";$/m
), `let jslint_edition = "${versionBeta}";`)
}, {
file: "jslint_ci.sh",
// update coverage-code
src: fileDict["jslint_ci.sh"].replace((
/(\nshRunWithCoverage[\S\s]*?\nlet moduleUrl;\n)[\S\s]*?\nv8CoverageReportCreate\(/m
), function (ignore, match1) {
return (
match1
+ [
jslint.assertOrThrow,
jslint.fsWriteFileWithParents,
jslint.htmlEscape,
jslint.moduleFsInit,
jslint.v8CoverageListMerge,
jslint.v8CoverageReportCreate
// reduce size of string/argument passed to nodejs
// by removing comments
].join("\n").replace((
/\n\/\/.*/g
), "").replace((
/\n\n\n/g
// CL-xxx reduce size of string/argument passed to nodejs
// by using 2-space-indent
), "\n").replace((
/ /g
), " ")
+ "\nv8CoverageReportCreate("
);
})
}, {
file: "package.json",
src: fileDict["package.json"].replace((
/("version": )".*?"/
), "$1" + JSON.stringify(versionBeta.slice(1)))
}
].map(async function ({
file,
src
}) {
let src0 = fileDict[file];
if (src !== src0) {
console.error(`update file ${file}`);
fileModified = file;
await moduleFs.promises.writeFile(file, src);
}
}));
if (fileModified) {
// throw new Error("modified file " + fileModified);
return;
}
}());
' "$@" # '
fi
# create .jslint.cjs
cat jslint.mjs | sed \
-e "s|^// module.exports = |module.exports = |" \
-e "s|^export default Object.freeze(|// &|" \
-e "s|^jslint_import_meta_url = |// &|" \
> .jslint.cjs
# run test with coverage-report
# coverage-hack - test jslint's invalid-file handling-behavior
mkdir -p .test-dir.js
# test jslint's cli handling-behavior
printf "node .jslint.cjs .\n"
node .jslint.cjs .
printf "node jslint.mjs .\n"
node jslint.mjs .
printf "node test.mjs\n"
npm run test
)}