| #!/usr/bin/env node |
|
|
| import fs from 'fs'; |
| import path from 'path'; |
| import { execSync } from 'child_process'; |
|
|
| |
| const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8')); |
| const version = packageJson.version; |
|
|
| console.log(`π¦ Building dist folder for version ${version}...`); |
|
|
| |
| try { |
| execSync('npm run build', { stdio: 'inherit' }); |
| console.log('β
Build completed successfully'); |
| } catch (error) { |
| console.error('β Build failed:', error.message); |
| process.exit(1); |
| } |
|
|
| |
| import { createWriteStream, existsSync } from 'fs'; |
| import { pipeline } from 'stream'; |
| import { promisify } from 'util'; |
| import archiver from 'archiver'; |
|
|
| const distDir = path.resolve('./dist'); |
| const zipPath = path.resolve(`./dist-${version}.zip`); |
|
|
| |
| if (!existsSync(distDir)) { |
| console.error('β dist directory does not exist. Please run build first.'); |
| process.exit(1); |
| } |
|
|
| |
| const output = createWriteStream(zipPath); |
| const archive = archiver('zip', { |
| zlib: { level: 9 } |
| }); |
|
|
| |
| output.on('close', () => { |
| console.log(`β
Successfully created ${zipPath}. Total bytes: ${archive.pointer()}`); |
| }); |
|
|
| |
| archive.on('error', (err) => { |
| console.error('β Error creating zip:', err); |
| process.exit(1); |
| }); |
|
|
| |
| archive.pipe(output); |
|
|
| |
| archive.directory(distDir, false); |
|
|
| |
| archive.finalize(); |
|
|
| output.on('close', () => { |
| console.log(`β
Successfully created ${zipPath}. Total bytes: ${archive.pointer()}`); |
| }); |
|
|