1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/packages/tools/gulp/tasks/buildCommandIndex.js

58 lines
1.5 KiB
JavaScript

const utils = require('../utils');
const glob = require('glob');
const rootDir = utils.rootDir();
async function processDirectory(dir) {
const tsFiles = glob.sync('{**/*.ts,**/*.tsx}', {
cwd: dir,
}).filter(f => f !== 'index.ts');
tsFiles.sort();
const fileContent = [];
for (const tsFile of tsFiles) {
const f = utils.getFilename(tsFile);
fileContent.push(`import * as ${f} from './${f}';`);
}
fileContent.push('');
fileContent.push('const index:any[] = [');
for (const tsFile of tsFiles) {
const f = utils.getFilename(tsFile);
fileContent.push(`\t${f},`);
}
fileContent.push('];');
fileContent.push('');
fileContent.push('export default index;');
const destFile = `${dir}/index.ts`;
console.info(`Generating ${destFile}...`);
await utils.insertContentIntoFile(
destFile,
'// AUTO-GENERATED using `gulp buildCommandIndex`',
fileContent.join('\n'),
true,
);
}
module.exports = {
src: '',
fn: async function() {
await processDirectory(`${rootDir}/packages/app-desktop/commands`);
await processDirectory(`${rootDir}/packages/app-desktop/gui/MainScreen/commands`);
await processDirectory(`${rootDir}/packages/app-desktop/gui/NoteEditor/commands`);
await processDirectory(`${rootDir}/packages/app-desktop/gui/NoteList/commands`);
await processDirectory(`${rootDir}/packages/app-desktop/gui/NoteListControls/commands`);
await processDirectory(`${rootDir}/packages/app-desktop/gui/Sidebar/commands`);
await processDirectory(`${rootDir}/packages/lib/commands`);
},
};