super-productivity/packages/plugin-dev/scripts/build-all.js
Johannes Millan b6bb62006a chore: update dependencies and clean up build configuration
- Remove references to non-existent plugins from build-all.js
- Update package-lock.json files after dependency installation
- Include latest compiled assets for procrastination-buster plugin
2025-06-24 21:04:37 +02:00

203 lines
5.8 KiB
JavaScript
Executable file

#!/usr/bin/env node
const { exec } = require('child_process');
const { promisify } = require('util');
const fs = require('fs');
const path = require('path');
const execAsync = promisify(exec);
// Colors for console output
const colors = {
reset: '\x1b[0m',
bright: '\x1b[1m',
green: '\x1b[32m',
yellow: '\x1b[33m',
red: '\x1b[31m',
cyan: '\x1b[36m',
};
function log(message, color = '') {
console.log(`${color}${message}${colors.reset}`);
}
// Plugin configurations
const plugins = [
{
name: 'procrastination-buster',
path: 'procrastination-buster',
needsInstall: true,
buildCommand: async (pluginPath) => {
await execAsync(`cd ${pluginPath} && npm run build && npm run package`);
return 'Built and packaged';
},
},
// Migrated built-in plugins
{
name: 'api-test-plugin',
path: 'api-test-plugin',
copyToAssets: true,
buildCommand: async (pluginPath) => {
// Copy to assets directory
const targetDir = path.join(__dirname, '../../../src/assets/api-test-plugin');
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
const files = ['manifest.json', 'plugin.js', 'index.html'];
for (const file of files) {
const src = path.join(pluginPath, file);
const dest = path.join(targetDir, file);
if (fs.existsSync(src)) {
fs.copyFileSync(src, dest);
}
}
return 'Copied to assets';
},
},
{
name: 'sync-md-plugin',
path: 'sync-md-plugin',
copyToAssets: true,
buildCommand: async (pluginPath) => {
// Copy to assets directory
const targetDir = path.join(__dirname, '../../../src/assets/sync-md-plugin');
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
const files = [
'manifest.json',
'plugin.js',
'index.html',
'iframe-script.js',
'sync-md-icon.svg',
];
for (const file of files) {
const src = path.join(pluginPath, file);
const dest = path.join(targetDir, file);
if (fs.existsSync(src)) {
fs.copyFileSync(src, dest);
}
}
return 'Copied to assets';
},
},
{
name: 'yesterday-tasks-plugin',
path: 'yesterday-tasks-plugin',
copyToAssets: true,
buildCommand: async (pluginPath) => {
// Copy to assets directory
const targetDir = path.join(
__dirname,
'../../../src/assets/yesterday-tasks-plugin',
);
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
}
const files = ['manifest.json', 'plugin.js', 'index.html', 'icon.svg'];
for (const file of files) {
const src = path.join(pluginPath, file);
const dest = path.join(targetDir, file);
if (fs.existsSync(src)) {
fs.copyFileSync(src, dest);
}
}
return 'Copied to assets';
},
},
];
async function buildPlugin(plugin) {
const startTime = Date.now();
log(`\n📦 Building ${plugin.name}...`, colors.cyan);
try {
// Check if plugin directory exists
if (!fs.existsSync(plugin.path)) {
throw new Error(`Plugin directory not found: ${plugin.path}`);
}
// Install dependencies if needed
if (plugin.needsInstall) {
const packageJsonPath = path.join(plugin.path, 'package.json');
const nodeModulesPath = path.join(plugin.path, 'node_modules');
if (fs.existsSync(packageJsonPath) && !fs.existsSync(nodeModulesPath)) {
log(` Installing dependencies...`, colors.yellow);
await execAsync(`cd ${plugin.path} && npm install`);
}
}
// Run build command
log(` Building...`, colors.yellow);
const result = await plugin.buildCommand(plugin.path);
const duration = ((Date.now() - startTime) / 1000).toFixed(1);
log(`${plugin.name} - ${result} (${duration}s)`, colors.green);
return { plugin: plugin.name, success: true, duration };
} catch (error) {
const duration = ((Date.now() - startTime) / 1000).toFixed(1);
log(`${plugin.name} - Build failed: ${error.message} (${duration}s)`, colors.red);
return { plugin: plugin.name, success: false, error: error.message, duration };
}
}
async function buildAll() {
log('\n🚀 Building all plugins...', colors.bright);
const startTime = Date.now();
// Build plugins in parallel
const results = await Promise.all(plugins.map(buildPlugin));
// Summary
const totalDuration = ((Date.now() - startTime) / 1000).toFixed(1);
const successful = results.filter((r) => r.success).length;
const failed = results.filter((r) => !r.success).length;
log('\n📊 Build Summary:', colors.bright);
log(` Total plugins: ${plugins.length}`);
log(` Successful: ${successful}`, colors.green);
if (failed > 0) {
log(` Failed: ${failed}`, colors.red);
}
log(` Total time: ${totalDuration}s`);
// List outputs
log('\n📁 Build outputs:', colors.bright);
// Check for minimal plugin zip
if (fs.existsSync('minimal-plugin.zip')) {
log(` • minimal-plugin.zip`);
}
// Check for other plugin outputs
for (const plugin of plugins.slice(1)) {
const distPath = path.join(plugin.path, 'dist');
if (fs.existsSync(distPath)) {
const pluginZip = path.join(distPath, 'plugin.zip');
if (fs.existsSync(pluginZip)) {
const stats = fs.statSync(pluginZip);
const size = (stats.size / 1024).toFixed(1);
log(`${plugin.path}/dist/plugin.zip (${size} KB)`);
} else {
log(`${plugin.path}/dist/`);
}
}
}
if (failed > 0) {
process.exit(1);
}
}
// Run if called directly
if (require.main === module) {
buildAll().catch((error) => {
log(`\n❌ Build failed: ${error.message}`, colors.red);
process.exit(1);
});
}
module.exports = { buildAll };