62 lines
2.0 KiB
JavaScript
Executable File
62 lines
2.0 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/**
|
|
* IWA (Installer for Web Applications) Build Script
|
|
* Generates Chrome extension manifest and required files for deployment.
|
|
*
|
|
* Usage: npm run build:iwa
|
|
*/
|
|
|
|
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
|
|
import { join, dirname } from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __dirname = join(
|
|
dirname(fileURLToPath(import.meta.url)),
|
|
'.'
|
|
);
|
|
|
|
// Read existing manifest for reference
|
|
const distManifestPath = join(__dirname, 'dist', 'manifest.json');
|
|
try {
|
|
const distManifest = JSON.parse(readFileSync(distManifestPath, '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'
|
|
}))
|
|
};
|
|
|
|
// Write IWA manifest
|
|
const iwaDir = join(__dirname, 'public', 'iwa');
|
|
if (!existsSync(iwaDir)) {
|
|
mkdirSync(iwaDir, { recursive: true });
|
|
}
|
|
|
|
writeFileSync(join(iwaDir, 'manifest.json'), JSON.stringify(iwaManifest, null, 2));
|
|
|
|
console.log('✅ IWA manifest generated at:', join(iwaDir, 'manifest.json'));
|
|
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');
|
|
|
|
} catch (error) {
|
|
console.error('❌ Build failed:', error.message);
|
|
process.exit(1);
|
|
}
|