|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +const fs = require('fs'); |
| 4 | +const path = require('path'); |
| 5 | +const { execSync } = require('child_process'); |
| 6 | + |
| 7 | +const pkgPath = path.join(process.cwd(), 'package.json'); |
| 8 | + |
| 9 | +if (!fs.existsSync(pkgPath)) { |
| 10 | + console.error('❌ No package.json found in current directory.'); |
| 11 | + process.exit(1); |
| 12 | +} |
| 13 | + |
| 14 | +const original = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); |
| 15 | +const publishMeta = original['x-publish'] || {}; |
| 16 | + |
| 17 | +const publishName = publishMeta.publishName || 'libpg-query'; |
| 18 | +const distTag = process.env.TAG || publishMeta.distTag || 'latest'; |
| 19 | + |
| 20 | +if (!original.name || !original.version) { |
| 21 | + console.error('❌ package.json must include name and version'); |
| 22 | + process.exit(1); |
| 23 | +} |
| 24 | + |
| 25 | +const modified = { ...original, name: publishName }; |
| 26 | + |
| 27 | +try { |
| 28 | + console.log(`📦 Publishing ${publishName}@${original.version} with tag '${distTag}'...`); |
| 29 | + fs.writeFileSync(pkgPath, JSON.stringify(modified, null, 2)); |
| 30 | + execSync(`pnpm publish --tag ${distTag}`, { stdio: 'inherit' }); |
| 31 | + console.log('✅ Publish complete.'); |
| 32 | +} catch (err) { |
| 33 | + console.error('❌ Publish failed:', err.message); |
| 34 | +} finally { |
| 35 | + fs.writeFileSync(pkgPath, JSON.stringify(original, null, 2)); |
| 36 | + console.log('🔄 Restored original package.json'); |
| 37 | +} |
0 commit comments