Skip to content

Commit 40458c5

Browse files
committed
chore(workflow): add release script
1 parent c7227b9 commit 40458c5

File tree

3 files changed

+109
-106
lines changed

3 files changed

+109
-106
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@babel/plugin-transform-regenerator": "^7.12.1",
5959
"@babel/preset-env": "^7.12.7",
6060
"@babel/preset-typescript": "^7.12.7",
61+
"@jsdevtools/version-bump-prompt": "^6.1.0",
6162
"@ls-lint/ls-lint": "^1.9.2",
6263
"@microsoft/api-extractor": "^7.12.0",
6364
"@rollup/plugin-commonjs": "^13.0.0",

pnpm-lock.yaml

+64-68
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/release.js

+44-38
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,50 @@
1-
const { join } = require('path');
21
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');
134

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...');
1716

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();
3629
}
37-
await fs.writeJSON(path, pkg, { spaces: 2 });
3830
}
3931

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

Comments
 (0)