-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_back.mts
More file actions
99 lines (80 loc) · 2.21 KB
/
build_back.mts
File metadata and controls
99 lines (80 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import path from 'node:path';
import process from 'node:process';
import { readPackage } from 'read-pkg';
import { $ } from 'execa';
import semver from 'semver';
import enquirer from 'enquirer';
import { writePackage } from 'write-package';
import consola from 'consola';
import readYamlFile from 'read-yaml-file';
import { findPackages } from 'find-packages';
const $$ = $({
stdout: process.stdout,
stderr: process.stderr,
});
const stdout = await $`git rev-parse --short HEAD`;
const hash = stdout.stdout?.trim();
if (!hash) {
throw new Error('No git hash');
}
const packageJson = await readPackage();
const versionType = [
'major',
'minor',
'patch',
'premajor',
'preminor',
'prepatch',
'prerelease',
] as const;
const choices = versionType.map((type) => {
const value = semver.inc(packageJson.version, type, 'canary')!;
return {
name: value,
message: type,
hint: value,
value: value,
};
});
const { v } = await enquirer.prompt<{ v: string }>({
type: 'select',
name: 'v',
message: `What type of release? Current version: ${packageJson.version}`,
choices: choices,
});
const { isSure } = await enquirer.prompt<{ isSure: boolean }>({
type: 'confirm',
initial: false,
name: 'isSure',
message: `Are you sure to release? [ ${v} ]`,
});
if (isSure) {
const tag = /^\d+\.\d+\.\d+$/.test(v) ? "latest" : "canary";
console.log(v,tag);
packageJson.version = v;
packageJson._id = v;
packageJson.private = true;
await writePackage(path.join(process.cwd(), 'package.json'), packageJson);
const yaml = await readYamlFile.default<{ packages: string[] }>(
path.join(process.cwd(), 'pnpm-workspace.yaml')
);
const packages = await findPackages(process.cwd(), {
patterns: yaml.packages,
});
for (const item of packages) {
const packageJson = await readPackage({ cwd: item.dir });
if (!packageJson.private) {
packageJson.version = v;
packageJson._id = v;
packageJson.publishConfig = {
access: 'public',
tag,
};
await writePackage(path.join(item.dir, 'package.json'), packageJson);
}
}
await $$`git add .`;
await $$`git commit -m ${v}`;
await $$`git tag v${v}`;
consola.success(`tag v${v} created`);
}