mirror of
https://github.com/HeyPuter/puter.git
synced 2026-09-22 05:06:10 +00:00
feat: add support for extensions
This commit is contained in:
@@ -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;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user