forked from ImYanXiao/Elaina-MultiDevice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
34 lines (31 loc) · 1.1 KB
/
test.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
import fs from 'fs';
import path, { dirname } from 'path';
import assert from 'assert';
import syntaxError from 'syntax-error';
import { fileURLToPath } from 'url';
import { createRequire } from 'module';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const require = createRequire(__dirname);
const folders = ['.', ...Object.keys(require(path.join(__dirname, './package.json')).directories)];
const files = [];
folders.forEach(folder => {
try {
const jsFiles = fs.readdirSync(folder).filter(v => v.endsWith('.js')).map(file => path.resolve(folder, file));
files.push(...jsFiles);
} catch (err) {
console.error(`Error reading folder ${folder}:`, err);
}
});
files.forEach(file => {
if (file !== __filename) {
console.error('Checking', file);
const error = syntaxError(fs.readFileSync(file, 'utf8'), file, {
sourceType: 'module',
allowReturnOutsideFunction: true,
allowAwaitOutsideFunction: true
});
assert.ifError(error);
console.log('Done ☑️', file);
}
});