Skip to content

Commit

Permalink
ci: update release script
Browse files Browse the repository at this point in the history
  • Loading branch information
YunYouJun committed Oct 4, 2023
1 parent 3673613 commit 910166e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/valaxy/node/rss.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { dirname, resolve } from 'node:path'
import { readFile } from 'node:fs/promises'
import { cyan, dim } from 'kolorist'

import fg from 'fast-glob'
Expand Down Expand Up @@ -63,7 +64,7 @@ export async function build(options: ResolvedValaxyOptions) {

const posts: Item[] = []
for await (const i of files) {
const raw = fs.readFileSync(i, 'utf-8')
const raw = await readFile(i, 'utf-8')

const { data, content, excerpt } = matter(raw, { excerpt_separator: EXCERPT_SEPARATOR })

Expand Down
13 changes: 8 additions & 5 deletions scripts/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@ async function main() {

console.log()
consola.info('Updating packages version...')
updateVersion('package.json', targetVersion)
packages.forEach((name) => {
updateVersion(`packages/${name}/package.json`, targetVersion)
})
await updateVersion('package.json', targetVersion)

await Promise.all(
packages.map(name =>
updateVersion(`packages/${name}/package.json`, targetVersion),
),
)

console.log()
consola.info('Updating template version...')
updateTemplateVersions(targetVersion)
await updateTemplateVersions(targetVersion)

if (!isDryRun) {
console.log()
Expand Down
14 changes: 7 additions & 7 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join } from 'node:path'
import { readFileSync, writeFileSync } from 'fs-extra'
import { readFile, writeFile } from 'node:fs/promises'
import type { ReleaseType } from 'semver'
import semver from 'semver'
import consola from 'consola'
Expand All @@ -17,10 +17,10 @@ export const templates = [
'packages/create-valaxy/template-blog',
]

export function updateTemplateVersions(version: string) {
export async function updateTemplateVersions(version: string) {
for (const template of templates) {
const pkgPath = join(template, 'package.json')
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))
const pkg = JSON.parse(await readFile(pkgPath, 'utf-8'))
const deps = ['dependencies', 'devDependencies']
for (const name of deps) {
if (!pkg[name])
Expand All @@ -33,15 +33,15 @@ export function updateTemplateVersions(version: string) {
}
}
}
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`)
await writeFile(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`)
}
}

export function updateVersion(pkgPath: string, version: string): void {
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))
export async function updateVersion(pkgPath: string, version: string) {
const pkg = JSON.parse(await readFile(pkgPath, 'utf-8'))
consola.info(`${cyan(pkg.name)} ${gray(`v${pkg.version}`)} -> ${yellow(`v${version}`)}`)
pkg.version = version
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`)
await writeFile(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`)
}

export function getVersionChoices(currentVersion: string) {
Expand Down

0 comments on commit 910166e

Please sign in to comment.