|
1 |
| -const { join } = require('path'); |
2 | 1 | const execa = require('execa');
|
3 |
| -const fs = require('fs'); |
4 |
| -const { execSync } = require('child_process'); |
5 |
| - |
6 |
| -function objectMap(obj, fn) { |
7 |
| - return Object.fromEntries( |
8 |
| - Object.entries(obj) |
9 |
| - .map(([k, v]) => fn(k, v)) |
10 |
| - .filter(notNullish), |
11 |
| - ); |
12 |
| -} |
| 2 | +const path = require('path'); |
| 3 | +const bumpPrompt = require('@jsdevtools/version-bump-prompt'); |
13 | 4 |
|
14 |
| -execSync('npx bumpp package.json packages/*/package.json', { |
15 |
| - stdio: 'inherit', |
16 |
| -}); |
| 5 | +const bin = (name) => path.resolve(__dirname, '../node_modules/.bin/' + name); |
| 6 | +const run = (bin, args, opts = {}) => { |
| 7 | + return execa(bin, args, { stdio: 'inherit', ...opts }); |
| 8 | +}; |
| 9 | +const step = (msg) => { |
| 10 | + console.log(chalk.cyan(msg)); |
| 11 | +}; |
| 12 | + |
| 13 | +async function main() { |
| 14 | + // run tests before release |
| 15 | + step('\nRunning tests...'); |
17 | 16 |
|
18 |
| -const templates = [ |
19 |
| - 'packages/create-app/template', |
20 |
| - 'packages/create-theme/template', |
21 |
| -]; |
22 |
| - |
23 |
| -const { version } = await fs.readJSON('package.json'); |
24 |
| - |
25 |
| -for (const template of templates) { |
26 |
| - const path = join(template, 'package.json'); |
27 |
| - const pkg = await fs.readJSON(path); |
28 |
| - const deps = ['dependencies', 'devDependencies']; |
29 |
| - for (const name of deps) { |
30 |
| - if (!pkg[name]) continue; |
31 |
| - pkg[name] = objectMap(pkg[name], (k, v) => { |
32 |
| - if (k.startsWith('@slidev/') && !k.startsWith('@slidev/theme')) |
33 |
| - return [k, `^${version}`]; |
34 |
| - return [k, v]; |
35 |
| - }); |
| 17 | + // build all packages with types |
| 18 | + step('\nBuilding all packages...'); |
| 19 | + await build(); |
| 20 | + |
| 21 | + // build all packages with types |
| 22 | + step('\nSelect bumpVersion...'); |
| 23 | + const selectVersion = await bumpVersion(); |
| 24 | + if (selectVersion) { |
| 25 | + console.log(selectVersion); |
| 26 | + // build all packages with types |
| 27 | + step('\npublishing...'); |
| 28 | + // await publish(); |
36 | 29 | }
|
37 |
| - await fs.writeJSON(path, pkg, { spaces: 2 }); |
38 | 30 | }
|
39 | 31 |
|
40 |
| -await $`git add .`; |
41 |
| -await $`git commit -m "chore: release v${version}"`; |
42 |
| -await $`git tag v${version}`; |
43 |
| -await $`git push`; |
44 |
| -await $`git push origin --tags`; |
| 32 | +async function build() { |
| 33 | + await run('pnpm', ['build']); |
| 34 | +} |
| 35 | + |
| 36 | +async function bumpVersion() { |
| 37 | + return await bumpPrompt({ |
| 38 | + commit: 'chore(publish): release v', |
| 39 | + push: true, |
| 40 | + tag: true, |
| 41 | + }); |
| 42 | +} |
| 43 | + |
| 44 | +async function publish() { |
| 45 | + await run('pnpm', ['publish']); |
| 46 | +} |
| 47 | + |
| 48 | +main().catch((err) => { |
| 49 | + console.error(err); |
| 50 | +}); |
0 commit comments