-
-
Notifications
You must be signed in to change notification settings - Fork 303
/
make.mjs
319 lines (217 loc) · 5.65 KB
/
make.mjs
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import path from 'path';
import process from 'process';
import url from 'url';
import { console } from './base/source/node/console.mjs';
import { build as build_base, clean as clean_base } from './base/make.mjs';
import { build as build_browser, clean as clean_browser, pack as pack_browser } from './browser/make.mjs';
import { build as build_covert, clean as clean_covert } from './covert/make.mjs';
import { build as build_stealth, clean as clean_stealth, pack as pack_stealth } from './stealth/make.mjs';
const FILE = url.fileURLToPath(import.meta.url);
const ROOT = path.dirname(path.resolve(FILE, '.'));
const isComparison = (line, chunk) => {
let offset = line.indexOf(chunk + '(');
if (offset !== -1) {
let is_true = line.indexOf('=== true', offset) !== -1;
let is_false = line.indexOf('=== false', offset) !== -1;
// let is_return = line.substr(offset - 7, 6) === 'return';
let is_ternary = line.indexOf('?', offset) !== -1 && line.indexOf(':', offset) !== -1;
if (is_true === true || is_false === true) {
return true;
} else if (is_ternary === true) {
return true;
}
}
return false;
};
const clean = async () => {
console.log('');
console.log('clean()');
console.log('');
let results = [
await clean_base(),
await clean_browser(),
await clean_covert(),
await clean_stealth()
];
if (results.includes(false) === false) {
return true;
}
return false;
};
const build = async () => {
console.log('');
console.log('build()');
console.log('');
let results = [
await build_base(),
await build_browser(),
await build_covert(),
await build_stealth()
];
if (results.includes(false) === false) {
return true;
}
return false;
};
const REQUIRED_COMPARE = [
'isArray',
'isBoolean',
'isBuffer',
'isDate',
'isEmitter',
'isFunction',
'isMap',
'isNumber',
'isObject',
'isRegExp',
'isSet',
'isString',
'DATETIME.isDate',
'DATETIME.isDATETIME',
'DATETIME.isTime',
'HOSTS.isHost',
'HOSTS.isHOSTS',
'IP.isIP',
'UA.isUA',
'URL.isURL',
'Number.isNaN',
'isNaN'
];
const OPTIONAL_COMPARE = [
'.includes',
'.startsWith',
'.endsWith',
'.test'
];
const lint_file = (file) => {
let lines = file.buffer.split('\n');
let result = true;
lines.forEach((line, l) => {
REQUIRED_COMPARE.forEach((chunk) => {
if (line.includes(chunk + '(') === true) {
if (isComparison(line, chunk) === false) {
console.error(' > ' + file.name + '#L' + (l + 1) + ':' + line.trim());
result = false;
}
}
});
OPTIONAL_COMPARE.forEach((chunk) => {
if (line.includes(chunk + '(') === true) {
if (isComparison(line, chunk) === false) {
console.warn(' > ' + file.name + '#L' + (l + 1) + ':' + line.trim());
result = false;
}
}
});
});
return result;
};
const lint = async () => {
console.log('');
console.log('lint()');
console.log('');
let ignored = [];
let Filesystem = await import(ROOT + '/covert/source/Filesystem.mjs').then((mod) => mod['Filesystem']).catch(() => {
console.error('Please execute "make.mjs build" first.');
process.exit(1);
});
let FILESYSTEM = new Filesystem();
FILESYSTEM.read(ROOT + '/browser/.gitignore').split('\n').forEach((line) => {
if (line.startsWith('/') === true) {
if (line.endsWith('.mjs') === true) {
ignored.push('/browser' + line);
} else if (line.endsWith('*') === true) {
ignored.push('/browser' + line.substr(0, line.length - 1));
} else {
ignored.push('/browser' + line);
}
}
});
let files = [
...FILESYSTEM.scan(ROOT + '/base/source', true),
...FILESYSTEM.scan(ROOT + '/browser/design', true),
...FILESYSTEM.scan(ROOT + '/browser/source', true),
...FILESYSTEM.scan(ROOT + '/covert/source', true),
...FILESYSTEM.scan(ROOT + '/stealth/source', true)
].map((file) => {
return file.substr(ROOT.length);
}).filter((file) => {
return file.endsWith('.mjs');
}).filter((file) => {
let check = ignored.find((i) => {
return file.startsWith(i) === true;
}) !== undefined;
if (check === true) {
return false;
}
return true;
}).map((file) => ({
name: file,
buffer: FILESYSTEM.read(ROOT + file)
}));
let results = files.map((file) => {
return lint_file(file);
});
if (results.includes(false) === false) {
return true;
}
return false;
};
const pack = async (target) => {
console.log('');
console.log('pack()');
console.log('');
let results = [
await pack_browser(target),
await pack_stealth(target)
];
if (results.includes(false) === false) {
return true;
}
return false;
};
(async (args) => {
if (args.includes(FILE) === true) {
let results = [];
if (args.includes('clean')) {
results.push(await clean());
}
if (args.includes('build')) {
results.push(await build());
}
if (args.includes('lint')) {
results.push(await lint());
}
if (args.includes('pack')) {
let folder = args.find((v) => v.includes('/') && v !== FILE) || null;
if (folder !== null) {
let sandbox = null;
try {
sandbox = path.resolve(ROOT, folder);
} catch (err) {
sandbox = null;
}
if (sandbox !== null) {
results.push(await pack(sandbox));
} else {
console.error('Invalid parameter "' + folder + '". Please use a correct path.');
results.push(false);
}
} else {
results.push(await pack());
}
}
if (results.length === 0) {
results.push(await clean());
results.push(await build());
results.push(await lint());
// XXX: Don't pack by default
// results.push(await pack());
}
if (results.includes(false) === false) {
process.exit(0);
} else {
process.exit(1);
}
}
})(process.argv.slice(1));