|
| 1 | +const { readdirSync, statSync, writeFileSync } = require('fs'); |
| 2 | +const { join } = require('path'); |
| 3 | + |
| 4 | +function isNonEmptyFolder(folderPath) { |
| 5 | + const items = readdirSync(folderPath); |
| 6 | + // Check if there are any items in the folder |
| 7 | + return items.some((item) => { |
| 8 | + const fullPath = join(folderPath, item); |
| 9 | + // Check if the item is a file or a non-empty directory |
| 10 | + const stats = statSync(fullPath); |
| 11 | + if (stats.isDirectory()) { |
| 12 | + return isNonEmptyFolder(fullPath); // Recursively check subfolders |
| 13 | + } |
| 14 | + return true; // It's a file |
| 15 | + }); |
| 16 | +} |
| 17 | + |
| 18 | +// Function to get all non-empty folders |
| 19 | +function getNonEmptyFolders(rootFolder) { |
| 20 | + const result = []; |
| 21 | + const items = readdirSync(rootFolder); |
| 22 | + |
| 23 | + items.forEach((item) => { |
| 24 | + const fullPath = join(rootFolder, item); |
| 25 | + const stats = statSync(fullPath); |
| 26 | + if (stats.isDirectory() && isNonEmptyFolder(fullPath)) { |
| 27 | + result.push(item); |
| 28 | + } |
| 29 | + }); |
| 30 | + |
| 31 | + return result; |
| 32 | +} |
| 33 | +const abc = [ |
| 34 | + 'a', |
| 35 | + 'b', |
| 36 | + 'c', |
| 37 | + 'd', |
| 38 | + 'e', |
| 39 | + 'f', |
| 40 | + 'g', |
| 41 | + 'h', |
| 42 | + 'i', |
| 43 | + 'j', |
| 44 | + 'k', |
| 45 | + 'l', |
| 46 | + 'm', |
| 47 | + 'n', |
| 48 | + 'o', |
| 49 | + 'p', |
| 50 | + 'q', |
| 51 | + 'r', |
| 52 | + 's', |
| 53 | + 't', |
| 54 | + 'u', |
| 55 | + 'v', |
| 56 | + 'w', |
| 57 | + 'x', |
| 58 | + 'y', |
| 59 | + 'z', |
| 60 | +]; |
| 61 | +const list = getNonEmptyFolders('./libraries/plugins/src/list'); |
| 62 | +const fileContent = `${list |
| 63 | + .map((p, index) => { |
| 64 | + return `import Module${abc[ |
| 65 | + index |
| 66 | + ].toUpperCase()} from '@gitroom/plugins/list/${p}/backend/module';`; |
| 67 | + }) |
| 68 | + .join('\n')} |
| 69 | +
|
| 70 | +export default [${list |
| 71 | + .map((p, index) => { |
| 72 | + return `Module${abc[index].toUpperCase()}`; |
| 73 | + }) |
| 74 | + .join(', ')}]; |
| 75 | +`; |
| 76 | + |
| 77 | +writeFileSync('./libraries/plugins/src/plugins.ts', fileContent); |
0 commit comments