|
1 | | -import prompts from 'prompts' |
2 | | -import semver from 'semver' |
3 | | -import colors from 'picocolors' |
4 | | -import { |
5 | | - args, |
6 | | - getPackageInfo, |
7 | | - getVersionChoices, |
8 | | - isDryRun, |
9 | | - logRecentCommits, |
10 | | - packages, |
11 | | - run, |
12 | | - runIfNotDry, |
13 | | - step, |
14 | | - updateVersion, |
15 | | -} from './releaseUtils' |
16 | | - |
17 | | -async function main(): Promise<void> { |
18 | | - let targetVersion: string | undefined |
19 | | - |
20 | | - const { pkg }: { pkg: string } = await prompts({ |
21 | | - type: 'select', |
22 | | - name: 'pkg', |
23 | | - message: 'Select package', |
24 | | - choices: packages.map((i) => ({ value: i, title: i })), |
25 | | - }) |
26 | | - |
27 | | - if (!pkg) return |
28 | | - |
29 | | - await logRecentCommits(pkg) |
30 | | - |
31 | | - const { currentVersion, pkgName, pkgPath, pkgDir } = getPackageInfo(pkg) |
32 | | - |
33 | | - if (!targetVersion) { |
34 | | - const { release }: { release: string } = await prompts({ |
35 | | - type: 'select', |
36 | | - name: 'release', |
37 | | - message: 'Select release type', |
38 | | - choices: getVersionChoices(currentVersion), |
39 | | - }) |
40 | | - |
41 | | - if (release === 'custom') { |
42 | | - const res: { version: string } = await prompts({ |
43 | | - type: 'text', |
44 | | - name: 'version', |
45 | | - message: 'Input custom version', |
46 | | - initial: currentVersion, |
47 | | - }) |
48 | | - targetVersion = res.version |
49 | | - } else { |
50 | | - targetVersion = release |
51 | | - } |
52 | | - } |
53 | | - |
54 | | - if (!semver.valid(targetVersion)) { |
55 | | - throw new Error(`invalid target version: ${targetVersion}`) |
56 | | - } |
57 | | - |
58 | | - const tag = `${pkgName}@${targetVersion}` |
59 | | - |
60 | | - if (targetVersion.includes('beta') && !args.tag) { |
61 | | - args.tag = 'beta' |
62 | | - } |
63 | | - if (targetVersion.includes('alpha') && !args.tag) { |
64 | | - args.tag = 'alpha' |
65 | | - } |
66 | | - |
67 | | - const { yes }: { yes: boolean } = await prompts({ |
68 | | - type: 'confirm', |
69 | | - name: 'yes', |
70 | | - message: `Releasing ${colors.yellow(tag)} Confirm?`, |
71 | | - }) |
72 | | - |
73 | | - if (!yes) { |
74 | | - return |
75 | | - } |
76 | | - |
77 | | - step('\nUpdating package version...') |
78 | | - updateVersion(pkgPath, targetVersion) |
79 | | - |
80 | | - step('\nGenerating changelog...') |
81 | | - await run( |
82 | | - 'npx', |
83 | | - [ |
84 | | - 'conventional-changelog', |
85 | | - '-p', |
86 | | - 'angular', |
87 | | - '-i', |
88 | | - 'CHANGELOG.md', |
89 | | - '-s', |
90 | | - '--commit-path', |
91 | | - '.', |
92 | | - '--lerna-package', |
93 | | - pkgName, |
94 | | - ], |
95 | | - { cwd: pkgDir }, |
96 | | - ) |
97 | | - |
98 | | - const { stdout } = await run('git', ['diff'], { stdio: 'pipe' }) |
99 | | - if (stdout) { |
100 | | - step('\nCommitting changes...') |
101 | | - await runIfNotDry('git', ['add', '-A']) |
102 | | - await runIfNotDry('git', ['commit', '-m', `release: ${tag}`]) |
103 | | - await runIfNotDry('git', ['tag', tag]) |
104 | | - } else { |
105 | | - console.log('No changes to commit.') |
106 | | - return |
107 | | - } |
108 | | - |
109 | | - step('\nPushing to GitHub...') |
110 | | - await runIfNotDry('git', ['push', 'origin', `refs/tags/${tag}`]) |
111 | | - await runIfNotDry('git', ['push']) |
112 | | - |
113 | | - if (isDryRun) { |
114 | | - console.log(`\nDry run finished - run git diff to see package changes.`) |
115 | | - } else { |
116 | | - console.log( |
117 | | - colors.green( |
118 | | - '\nPushed, publishing should starts shortly on CI.\nhttps://github.com/vitejs/vite-plugin-react/actions/workflows/publish.yml', |
119 | | - ), |
| 1 | +import { release } from '@vitejs/release-scripts' |
| 2 | +import { logRecentCommits, run } from './releaseUtils' |
| 3 | + |
| 4 | +release({ |
| 5 | + repo: 'vite-plugin-react', |
| 6 | + packages: ['plugin-react'], |
| 7 | + toTag: (pkg, version) => `${pkg}@${version}`, |
| 8 | + logChangelog: async (pkgName) => { |
| 9 | + await logRecentCommits(pkgName) |
| 10 | + }, |
| 11 | + generateChangelog: async (pkgName) => { |
| 12 | + await run( |
| 13 | + 'npx', |
| 14 | + [ |
| 15 | + 'conventional-changelog', |
| 16 | + '-p', |
| 17 | + 'angular', |
| 18 | + '-i', |
| 19 | + 'CHANGELOG.md', |
| 20 | + '-s', |
| 21 | + '--commit-path', |
| 22 | + '.', |
| 23 | + '--lerna-package', |
| 24 | + pkgName, |
| 25 | + ], |
| 26 | + { cwd: `packages/${pkgName}` }, |
120 | 27 | ) |
121 | | - } |
122 | | - |
123 | | - console.log() |
124 | | -} |
125 | | - |
126 | | -main().catch((err) => { |
127 | | - console.error(err) |
128 | | - process.exit(1) |
| 28 | + }, |
129 | 29 | }) |
0 commit comments