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

58 lines
1.5 KiB
JavaScript
Raw Normal View History

const utils = require('../utils');
const glob = require('glob');
const rootDir = utils.rootDir();
async function processDirectory(dir) {
2021-09-04 15:36:52 +02:00
const tsFiles = glob.sync('{**/*.ts,**/*.tsx}', {
cwd: dir,
}).filter(f => f !== 'index.ts');
2023-07-01 13:56:34 +02:00
tsFiles.sort();
const fileContent = [];
for (const tsFile of tsFiles) {
2021-09-04 16:15:25 +02:00
const f = utils.getFilename(tsFile);
fileContent.push(`import * as ${f} from './${f}';`);
}
fileContent.push('');
fileContent.push('const index:any[] = [');
for (const tsFile of tsFiles) {
2021-09-04 16:15:25 +02:00
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`);
},
};