chahuadev
Update README
857cdcf
#!/usr/bin/env node
/**
* Chahuadev Framework - Distribution Package Builder
* Copies built outputs to packages/@chahuadev distribution folders
*
* Structure:
* - packages/@chahuadev/framework-win32-x64/
* - packages/@chahuadev/framework-win32-ia32/
* - packages/@chahuadev/chahuadev-framework-linux/
*/
const fs = require('fs-extra');
const path = require('path');
const { execSync } = require('child_process');
const VERSION = '1.0.0';
const PROJECT_ROOT = __dirname;
const DIST_DIR = path.join(PROJECT_ROOT, 'dist', `Chahuadev Framework-${VERSION}`);
const PACKAGES_DIR = path.join(PROJECT_ROOT, 'packages', '@chahuadev');
console.log('\n╔════════════════════════════════════════════════════════════╗');
console.log('║ Chahuadev Framework - Distribution Package Builder ║');
console.log('╚════════════════════════════════════════════════════════════╝\n');
// Verify dist folder exists
if (!fs.existsSync(DIST_DIR)) {
console.error('❌ dist/ folder not found!');
console.error(` Run: npm run build:all`);
process.exit(1);
}
console.log('[1/5] Scanning build outputs...\n');
// Define distribution packages
const distributions = {
'framework-win32-x64': {
type: 'Windows 64-bit',
target: path.join(PACKAGES_DIR, 'framework-win32-x64'),
files: [
{ match: /Portable.*\.exe$/, desc: 'Portable EXE (Recommended)', priority: 1 },
{ match: /-win-x64\.exe$/, desc: 'EXE Installer', priority: 2 },
{ match: /-win-x64\.msi$/, desc: 'MSI Installer', priority: 3 }
]
},
'framework-win32-ia32': {
type: 'Windows 32-bit',
target: path.join(PACKAGES_DIR, 'framework-win32-ia32'),
files: [
{ match: /Portable.*\.exe$/, desc: 'Portable EXE (Recommended)', priority: 1 },
{ match: /-win-ia32\.exe$/, desc: 'EXE Installer', priority: 2 },
{ match: /-win-ia32\.msi$/, desc: 'MSI Installer', priority: 3 }
]
},
'framework-linux-x64': {
type: 'Linux 64-bit',
target: path.join(PACKAGES_DIR, 'framework-linux-x64'),
files: [
{ match: /\.AppImage$/, desc: 'AppImage', priority: 1 }
]
}
};
// Find files in dist
function findFiles(pattern) {
const files = fs.readdirSync(DIST_DIR);
return files.filter(f => pattern.test(f)).map(f => path.join(DIST_DIR, f));
}
// Copy files to distribution packages
let totalCopied = 0;
Object.entries(distributions).forEach(([pkgName, config], index) => {
const stepNum = index + 2;
console.log(`[${stepNum}/5] Processing ${config.type}...`);
// Create target directory
fs.ensureDirSync(config.target);
// Copy files
let copiedCount = 0;
config.files.forEach(({ match, desc }) => {
const foundFiles = findFiles(match);
if (foundFiles.length === 0) {
console.log(` ⚠️ No ${desc} found`);
return;
}
foundFiles.forEach(file => {
const filename = path.basename(file);
const size = (fs.statSync(file).size / (1024 * 1024)).toFixed(2);
// Create subdirectory for binaries
const binDir = path.join(config.target, 'bin');
fs.ensureDirSync(binDir);
const targetPath = path.join(binDir, filename);
fs.copyFileSync(file, targetPath);
console.log(` ✓ ${filename} (${size} MB)`);
copiedCount++;
totalCopied++;
});
});
if (copiedCount === 0) {
console.log(` ℹ️ No files copied for ${config.type}`);
}
console.log('');
});
// Step 5: Create package.json for each distribution
console.log('[5/5] Creating package manifests...\n');
const templatePackageJson = {
name: '',
version: VERSION,
description: 'Chahuadev Framework - Ready-to-use Distribution',
main: 'bin/index.js',
homepage: 'https://github.com/chahuadev/chahuadev-framework',
repository: {
type: 'git',
url: 'https://github.com/chahuadev/chahuadev-framework'
},
license: 'MIT',
author: 'Chahua Development Thailand'
};
const packageConfigs = {
'framework-win32-x64': {
...templatePackageJson,
name: '@chahuadev/framework-win32-x64',
description: 'Chahuadev Framework - Windows 64-bit Ready-to-use Distribution',
os: ['win32'],
cpu: ['x64'],
files: ['bin/']
},
'framework-win32-ia32': {
...templatePackageJson,
name: '@chahuadev/framework-win32-ia32',
description: 'Chahuadev Framework - Windows 32-bit Ready-to-use Distribution',
os: ['win32'],
cpu: ['ia32'],
files: ['bin/']
},
'framework-linux-x64': {
...templatePackageJson,
name: '@chahuadev/framework-linux-x64',
description: 'Chahuadev Framework - Linux 64-bit Ready-to-use Distribution',
os: ['linux'],
cpu: ['x64'],
files: ['bin/']
}
};
Object.entries(packageConfigs).forEach(([pkgName, config]) => {
const pkgJsonPath = path.join(PACKAGES_DIR, pkgName, 'package.json');
fs.ensureDirSync(path.dirname(pkgJsonPath));
fs.writeJsonSync(pkgJsonPath, config, { spaces: 2 });
console.log(` ✓ ${pkgName}/package.json`);
});
// Summary
console.log('\n╔════════════════════════════════════════════════════════════╗');
if (totalCopied > 0) {
console.log('║ ✅ Distribution Updated Successfully! ║');
} else {
console.log('║ ⚠️ No files were copied ║');
}
console.log('╚════════════════════════════════════════════════════════════╝\n');
console.log('📦 Distribution Structure:\n');
console.log('packages/@chahuadev/');
console.log('├── framework-win32-x64/');
console.log('│ ├── bin/');
console.log('│ │ ├── *.exe');
console.log('│ │ └── *.msi');
console.log('│ └── package.json');
console.log('├── framework-win32-ia32/');
console.log('│ ├── bin/');
console.log('│ │ ├── *.exe');
console.log('│ │ └── *.msi');
console.log('│ └── package.json');
console.log('└── chahuadev-framework-linux/');
console.log(' ├── bin/');
console.log(' │ └── *.AppImage');
console.log(' └── package.json');
console.log('');
console.log('Next steps:');
console.log(' 1. Update version numbers in ROOT package.json');
console.log(' 2. Run: npm publish from each package folder');
console.log(' 3. Or: npm run npm:publish to publish all\n');