-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (29 loc) · 1.04 KB
/
index.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
const fs = require('fs');
const path = require('path');
const transpiler = require('transpiler');
const scriptDir = path.resolve(__dirname, 'scripts');
function loadScripts() {
let scripts = {};
fs.readdirSync(scriptDir).forEach((filename) => {
const file = path.resolve(scriptDir, filename);
const stat = fs.statSync(file);
if (stat && stat.isDirectory()) {
fs.readdirSync(file).forEach((scriptname) => {
const script = `${filename}.${scriptname.split('.')[0]}`;
const filepath = path.resolve(file, scriptname);
const original = fs.readFileSync(filepath);
scripts[script] = {path: filepath, original, transpiled: transpiler.transpileScript(original).transpiled};
});
} else {
if (filename[0] !== '.') {
const script = filename.split('.')[0];
const original = fs.readFileSync(file);
scripts[script] = {path: file, original, transpiled: transpiler.transpileScript(original).transpiled};
}
}
});
return scripts;
}
module.exports = {
loadScripts
};