feat: add support for extensions

This commit is contained in:
jelveh
2024-10-29 18:37:32 -07:00
parent 14f477a633
commit b018571a86
3 changed files with 31 additions and 22 deletions
+28 -1
View File
@@ -1,6 +1,32 @@
const path = require('path');
const fs = require('fs');
const EmitPlugin = require('./EmitPlugin.cjs');
module.exports = async (options = {}) => {
// Directory containing extension files
const extensionsDir = path.join(__dirname, '../src/extensions');
// Read and process extension entries from the extensions directory
const entries = fs.readdirSync(extensionsDir, { withFileTypes: true })
.map(entry => {
// Case 1: Direct JavaScript files in extensions directory
if (entry.isFile() && entry.name.endsWith('.js')) {
return `./src/extensions/${entry.name}`;
}
// Case 2: Extension directories with index.js files
if (entry.isDirectory()) {
const indexPath = path.join(extensionsDir, entry.name, 'index.js');
// Check if directory contains an index.js file
if (fs.existsSync(indexPath)) {
return `./src/extensions/${entry.name}/index.js`;
}
}
// Skip entries that don't match either case
return null;
})
// Remove null entries from the array
.filter(entry => entry !== null);
const config = {};
config.entry = [
'./src/init_sync.js',
@@ -12,6 +38,7 @@ module.exports = async (options = {}) => {
'./src/i18n/i18n.js',
'./src/keyboard.js',
'./src/index.js',
...entries,
];
config.output = {
path: path.resolve(__dirname, '../dist'),
@@ -24,4 +51,4 @@ module.exports = async (options = {}) => {
}),
];
return config;
};
};