|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/** |
| 4 | + * Build script that creates a versioned .tgz package in the builds/ folder |
| 5 | + * Usage: node scripts/build-local.mjs [version-suffix] |
| 6 | + * |
| 7 | + * Examples: |
| 8 | + * node scripts/build-local.mjs -> builds/nozbe-watermelondb-v0.28.1-0.tgz |
| 9 | + * node scripts/build-local.mjs dev -> builds/nozbe-watermelondb-v0.28.1-0-dev.tgz |
| 10 | + * node scripts/build-local.mjs feature-x -> builds/nozbe-watermelondb-v0.28.1-0-feature-x.tgz |
| 11 | + */ |
| 12 | + |
| 13 | +import { execa } from 'execa' |
| 14 | +import fs from 'fs-extra' |
| 15 | +import path from 'path' |
| 16 | +import { fileURLToPath } from 'url' |
| 17 | + |
| 18 | +import pkg from './pkg.cjs' |
| 19 | + |
| 20 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)) |
| 21 | +const rootDir = path.resolve(__dirname, '..') |
| 22 | +const distPath = path.join(rootDir, 'dist') |
| 23 | +const buildsPath = path.join(rootDir, 'builds') |
| 24 | + |
| 25 | +const suffix = process.argv[2] || '' |
| 26 | +const versionTag = suffix ? `v${pkg.version}-${suffix}` : `v${pkg.version}` |
| 27 | +const tgzName = `nozbe-watermelondb-${versionTag}.tgz` |
| 28 | +const tgzPath = path.join(buildsPath, tgzName) |
| 29 | + |
| 30 | +async function main() { |
| 31 | + console.log(`Building WatermelonDB v${pkg.version}...`) |
| 32 | + |
| 33 | + // Run the standard build |
| 34 | + await execa('yarn', ['build'], { |
| 35 | + cwd: rootDir, |
| 36 | + stdio: 'inherit', |
| 37 | + env: { ...process.env, NODE_ENV: 'production' } |
| 38 | + }) |
| 39 | + |
| 40 | + // Ensure builds directory exists |
| 41 | + await fs.ensureDir(buildsPath) |
| 42 | + |
| 43 | + // Pack the dist folder into a tgz |
| 44 | + console.log(`\nPacking to ${tgzName}...`) |
| 45 | + await execa('yarn', ['pack', '--filename', tgzPath], { |
| 46 | + cwd: distPath, |
| 47 | + stdio: 'inherit' |
| 48 | + }) |
| 49 | + |
| 50 | + console.log(`\n✅ Build complete: builds/${tgzName}`) |
| 51 | + console.log(`\nTo use in another project, add to package.json:`) |
| 52 | + console.log(` "@nozbe/watermelondb": "file:${tgzPath}"`) |
| 53 | +} |
| 54 | + |
| 55 | +main().catch((err) => { |
| 56 | + console.error('Build failed:', err) |
| 57 | + process.exit(1) |
| 58 | +}) |
0 commit comments