forked from vitejs/vite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
releaseUtils.ts
70 lines (65 loc) · 2 KB
/
releaseUtils.ts
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
import fs from 'node:fs/promises'
import path from 'node:path'
import colors from 'picocolors'
import type { Options as ExecaOptions, ResultPromise } from 'execa'
import { execa } from 'execa'
export function run<EO extends ExecaOptions>(
bin: string,
args: string[],
opts?: EO,
): ResultPromise<
EO & (keyof EO extends 'stdio' ? object : { stdio: 'inherit' })
> {
return execa(bin, args, { stdio: 'inherit', ...opts }) as any
}
export async function getLatestTag(pkgName: string): Promise<string> {
const pkgJson = JSON.parse(
await fs.readFile(`packages/${pkgName}/package.json`, 'utf-8'),
)
const version = pkgJson.version
return pkgName === 'vite' ? `v${version}` : `${pkgName}@${version}`
}
export async function logRecentCommits(pkgName: string): Promise<void> {
const tag = await getLatestTag(pkgName)
if (!tag) return
const sha = await run('git', ['rev-list', '-n', '1', tag], {
stdio: 'pipe',
}).then((res) => res.stdout.trim())
console.log(
colors.bold(
`\n${colors.blue(`i`)} Commits of ${colors.green(
pkgName,
)} since ${colors.green(tag)} ${colors.gray(`(${sha.slice(0, 5)})`)}`,
),
)
await run(
'git',
[
'--no-pager',
'log',
`${sha}..HEAD`,
'--oneline',
'--',
`packages/${pkgName}`,
],
{ stdio: 'inherit' },
)
console.log()
}
export async function updateTemplateVersions(): Promise<void> {
const vitePkgJson = JSON.parse(
await fs.readFile('packages/vite/package.json', 'utf-8'),
)
const viteVersion = vitePkgJson.version
if (/beta|alpha|rc/.test(viteVersion)) return
const dir = 'packages/create-vite'
const templates = (await fs.readdir(dir)).filter((dir) =>
dir.startsWith('template-'),
)
for (const template of templates) {
const pkgPath = path.join(dir, template, `package.json`)
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8'))
pkg.devDependencies.vite = `^` + viteVersion
await fs.writeFile(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
}
}