(readDir, writeDir)
| 7 | const readdir = fs.promises.readdir; |
| 8 | |
| 9 | const 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 | |
| 42 | const loadCommand = async (filename, longName, writeFilenamePath) => { |
| 43 | const filenamePath = path.resolve(filename); |
no test coverage detected