forked from taskforcesh/bullmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateRawScripts.ts
44 lines (38 loc) · 1.27 KB
/
generateRawScripts.ts
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
import { ScriptLoader } from './src/commands/index';
import * as path from 'path';
import * as fs from 'fs';
import { promisify } from 'util';
const writeFile = promisify(fs.writeFile);
export 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: string, writeDir: string): Promise<void> {
const writeFilenamePath = path.normalize(writeDir);
if (!fs.existsSync(writeFilenamePath)) {
fs.mkdirSync(writeFilenamePath);
}
const paths = new Set<string>();
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, './src/commands'),
path.join(__dirname, './rawScripts'),
);