UNPKG

zz-shopify-components

Version:

Reusable Shopify components for theme projects

44 lines (36 loc) 1.25 kB
#!/usr/bin/env node const fs = require('fs'); const path = require('path'); const semver = require('semver'); const { execSync } = require('child_process'); const packageJsonPath = path.resolve(__dirname, '../package.json'); const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); // 获取命令参数 const releaseType = process.argv[2]; // 'patch' | 'minor' | 'major' | 'beta' const isBeta = releaseType === 'beta'; const currentVersion = pkg.version; // 生成新版本号 let newVersion; if (isBeta) { newVersion = semver.inc(currentVersion, 'prerelease', 'beta'); } else { newVersion = semver.inc(currentVersion, releaseType); } if (!newVersion) { console.error('❌ 无效的发布类型: ' + releaseType); process.exit(1); } // 更新 package.json pkg.version = newVersion; fs.writeFileSync(packageJsonPath, JSON.stringify(pkg, null, 2), 'utf-8'); console.log(`📦 更新版本: ${currentVersion}${newVersion}`); // 发布到 npm try { const tag = isBeta ? '--tag beta' : ''; console.log(`🚀 发布中: npm publish ${tag}`); execSync(`npm publish ${tag}`, { stdio: 'inherit' }); console.log('✅ 发布成功!'); } catch (err) { console.error('❌ 发布失败', err.message); process.exit(1); }