MCPcopy Create free account
hub / github.com/taskforcesh/bullmq / loadScripts

Function loadScripts

scripts/commandTransform.js:9–40  ·  view source on GitHub ↗
(readDir, writeDir)

Source from the content-addressed store, hash-verified

7const readdir = fs.promises.readdir;
8
9const loadScripts = async (readDir, writeDir) => {
10 const normalizedDir = path.normalize(readDir);
11
12 const files = await readdir(normalizedDir);
13
14 const luaFiles = files.filter(file => path.extname(file) === '.lua');
15 const writeFilenamePath = path.normalize(writeDir);
16
17 if (!fs.existsSync(writeFilenamePath)) {
18 fs.mkdirSync(writeFilenamePath);
19 }
20
21 let indexContent = '';
22
23 if (luaFiles.length === 0) {
24 /**
25 * To prevent unclarified runtime error "updateDelayset is not a function
26 * @see https://github.com/OptimalBits/bull/issues/920
27 */
28 throw new Error('No .lua files found!');
29 }
30
31 for (let i = 0; i < luaFiles.length; i++) {
32 const completedFilename = path.join(normalizedDir, luaFiles[i]);
33 const longName = path.basename(luaFiles[i], '.lua');
34 indexContent += `export * from './${longName}';\n`;
35
36 await loadCommand(completedFilename, longName, writeFilenamePath);
37 }
38
39 await writeFile(path.join(writeFilenamePath, 'index.ts'), indexContent);
40};
41
42const loadCommand = async (filename, longName, writeFilenamePath) => {
43 const filenamePath = path.resolve(filename);

Callers 1

Calls 2

loadCommandFunction · 0.85
normalizeMethod · 0.45

Tested by

no test coverage detected