2026-10-20 20:17:01 -04:00
|
|
|
#!/usr/bin/env node
|
2026-10-22 08:08:33 -04:00
|
|
|
|
2026-10-20 20:17:01 -04:00
|
|
|
/**
|
2026-10-21 21:14:59 -04:00
|
|
|
* IWA (Installer for Web Applications) Build Script
|
|
|
|
|
* Generates Chrome extension manifest and required files for deployment.
|
|
|
|
|
*
|
|
|
|
|
* Usage: npm run build:iwa
|
|
|
|
|
*
|
|
|
|
|
* Prerequisites:
|
|
|
|
|
* - Private key for signing must be available at path in IWA_PRIVATE_KEY_PATH
|
|
|
|
|
* - .wbn file must exist (generated by wbn tool or vite plugin)
|
2026-10-20 20:17:01 -04:00
|
|
|
*/
|
|
|
|
|
|
2026-10-21 21:14:59 -04:00
|
|
|
import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync } from 'fs';
|
2026-10-22 08:08:33 -04:00
|
|
|
import { execSync } from 'child_process';
|
2026-10-21 21:14:59 -04:00
|
|
|
import { join, dirname } from 'path';
|
|
|
|
|
import { fileURLToPath } from 'url';
|
|
|
|
|
import dotenv from 'dotenv';
|
2026-10-20 20:17:01 -04:00
|
|
|
|
2026-10-21 21:14:59 -04:00
|
|
|
dotenv.config();
|
2026-10-20 20:17:01 -04:00
|
|
|
|
2026-10-21 21:14:59 -04:00
|
|
|
const __dirname = join(
|
|
|
|
|
dirname(fileURLToPath(import.meta.url)),
|
|
|
|
|
'.'
|
|
|
|
|
);
|
2026-10-22 08:08:33 -04:00
|
|
|
|
2026-10-21 21:14:59 -04:00
|
|
|
try {
|
|
|
|
|
if (!existsSync(join(__dirname, 'dist', 'manifest.json'))) {
|
|
|
|
|
throw new Error('dist/manifest.json not found. Please run npm run build first.');
|
2026-10-20 20:17:01 -04:00
|
|
|
}
|
2026-10-22 08:08:33 -04:00
|
|
|
|
2026-10-21 21:14:59 -04:00
|
|
|
const distManifest = JSON.parse(readFileSync(join(__dirname, 'dist', 'manifest.json'), 'utf-8'));
|
|
|
|
|
|
|
|
|
|
// Generate IWA manifest with Chrome-specific fields
|
|
|
|
|
const iwaManifest = {
|
|
|
|
|
name: distManifest.name,
|
|
|
|
|
short_name: distManifest.short_name,
|
|
|
|
|
description: distManifest.description,
|
|
|
|
|
version: distManifest.version || '1.0.0',
|
|
|
|
|
start_url: '../index.html',
|
|
|
|
|
display: distManifest.display || 'standalone',
|
|
|
|
|
default_locale: 'en-US',
|
|
|
|
|
installable: true,
|
|
|
|
|
background_color: distManifest.background_color,
|
|
|
|
|
theme_color: distManifest.theme_color,
|
|
|
|
|
icons: distManifest.icons.map(icon => ({
|
|
|
|
|
src: icon.src,
|
|
|
|
|
sizes: icon.sizes,
|
|
|
|
|
type: icon.type,
|
|
|
|
|
purpose: 'any maskable'
|
|
|
|
|
})),
|
|
|
|
|
permissions: [
|
|
|
|
|
"*",
|
|
|
|
|
"tabs",
|
|
|
|
|
"storage"
|
|
|
|
|
],
|
|
|
|
|
host_permissions: [
|
|
|
|
|
"https://*/*",
|
|
|
|
|
"http://*/*"
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Write IWA manifest
|
|
|
|
|
const iwaDir = join(__dirname, 'public', 'iwa');
|
|
|
|
|
if (!existsSync(iwaDir)) {
|
|
|
|
|
mkdirSync(iwaDir, { recursive: true });
|
2026-10-22 08:08:33 -04:00
|
|
|
}
|
|
|
|
|
|
2026-10-21 21:14:59 -04:00
|
|
|
writeFileSync(join(iwaDir, 'manifest.json'), JSON.stringify(iwaManifest, null, 2));
|
|
|
|
|
console.log('✅ IWA manifest generated at:', join(iwaDir, 'manifest.json'));
|
2026-10-22 08:08:33 -04:00
|
|
|
|
2026-10-21 21:14:59 -04:00
|
|
|
// Check if we have the wbn-sign binary available globally
|
|
|
|
|
const distDir = join(__dirname, 'dist');
|
|
|
|
|
const files = readdirSync(distDir);
|
|
|
|
|
const wbnFile = files.find(f => f.endsWith('.wbn'));
|
2026-10-22 08:08:33 -04:00
|
|
|
|
2026-10-21 21:14:59 -04:00
|
|
|
let outputSwbn;
|
|
|
|
|
|
|
|
|
|
if (wbnFile) {
|
|
|
|
|
// Existing .wbn file - sign it
|
|
|
|
|
console.log('📦 Signing existing web bundle...');
|
|
|
|
|
outputSwbn = join(iwaDir, 'signed.swbn');
|
|
|
|
|
|
|
|
|
|
const wbnSignBinary = '/home/unfunny/.config/nvm/versions/node/v26.12.0/bin/wbn-sign';
|
|
|
|
|
if (existsSync(privateKeyPath)) {
|
|
|
|
|
try {
|
|
|
|
|
execSync(`node ${wbnSignBinary} sign ${join(distDir, wbnFile)} ${privateKeyPath} -o ${outputSwbn}`, { stdio: 'inherit' });
|
|
|
|
|
console.log('✅ IWA signed bundle generated at:', outputSwbn);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log('⚠️ Could not sign bundle');
|
|
|
|
|
}
|
2026-10-22 08:08:33 -04:00
|
|
|
} else {
|
2026-10-21 21:14:59 -04:00
|
|
|
console.log('⚠️ Private key not found, skipping signing step');
|
2026-10-22 08:08:33 -04:00
|
|
|
}
|
2026-10-21 21:14:59 -04:00
|
|
|
|
|
|
|
|
console.log('');
|
|
|
|
|
console.log('📦 Deployment instructions:');
|
|
|
|
|
console.log(' 1. Copy /public/iwa to your package directory (e.g., /usr/local/share/applications/iwa/)');
|
|
|
|
|
console.log(' 2. The manifest references index.html which loads from the main dist/index.html');
|
|
|
|
|
console.log(' 3. Chrome will detect this and offer installation via the Chrome Store');
|
|
|
|
|
} else {
|
|
|
|
|
// No .wbn file - skip signing, just use index.html for IWA deployment
|
|
|
|
|
console.log('');
|
|
|
|
|
console.log('📦 Deployment instructions:');
|
|
|
|
|
console.log(' Copy /public/iwa to your Chrome profile or use with --load-extension flag');
|
|
|
|
|
console.log(' The unpacked extension will work locally without signing.');
|
2026-10-22 08:08:33 -04:00
|
|
|
}
|
|
|
|
|
|
2026-10-21 21:14:59 -04:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error('❌ Build failed:', error.message);
|
|
|
|
|
process.exit(1);
|
2026-10-22 08:08:33 -04:00
|
|
|
}
|