File size: 7,195 Bytes
857cdcf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | #!/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');
|