forked from OptimalBits/bull
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateRawScripts.js
45 lines (39 loc) · 1.24 KB
/
generateRawScripts.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
'use strict';
const { ScriptLoader } = require('./lib/commands');
const path = require('path');
const fs = require('fs');
const { promisify } = require('util');
const writeFile = promisify(fs.writeFile);
class RawScriptLoader extends ScriptLoader {
/**
* Transpile lua scripts in one file, specifying an specific directory to be saved
* @param pathname - the path to the directory containing the scripts
* @param writeDir - the path to the directory where scripts will be saved
*/
async transpileScripts(pathname, writeDir) {
const writeFilenamePath = path.normalize(writeDir);
if (!fs.existsSync(writeFilenamePath)) {
fs.mkdirSync(writeFilenamePath);
}
const paths = new Set();
if (!paths.has(pathname)) {
paths.add(pathname);
const scripts = await this.loadScripts(pathname);
for (const command of scripts) {
const {
name,
options: { numberOfKeys, lua }
} = command;
await writeFile(
path.join(writeFilenamePath, `${name}-${numberOfKeys}.lua`),
lua
);
}
}
}
}
const scriptLoader = new RawScriptLoader();
scriptLoader.transpileScripts(
path.join(__dirname, './lib/commands'),
path.join(__dirname, './rawScripts')
);