Skip to content

Commit

Permalink
chore: revert and optimize spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 3, 2020
1 parent 79d800e commit c57ce08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions build/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ const headerMap = {
if (Object.keys(bumpMap).length) {
for (const name in bumpMap) {
console.log(`publishing ${name}@${bumpMap[name]} ...`)
await spawnAsync('yarn', ['publish', name])
await spawnAsync(`yarn publish ${name}`)
}
}

const { version } = require('../packages/koishi-cli/package') as PackageJson
const tags = spawnSync('git', ['tag', '-l']).split(/\r?\n/)
const tags = spawnSync('git tag -l').split(/\r?\n/)
if (tags.includes(version)) {
return console.log(`Tag ${version} already exists.`)
}

const updates = { fix: '', feat: '' }
const lastTag = tags[tags.length - 1]
const commits = spawnSync('git', ['log', `${lastTag}..HEAD`, '--format="%H%s"']).split(/\r?\n/).reverse()
const commits = spawnSync(`git log ${lastTag}..HEAD --format="%H%s"`).split(/\r?\n/).reverse()
for (const commit of commits) {
const hash = commit.slice(0, 40)
const details = /^(fix|feat)(?:\((\S+)\))?: (.+)$/.exec(commit.slice(40))
Expand Down
10 changes: 6 additions & 4 deletions build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ export interface PackageJson extends Partial<Record<DependencyType, Record<strin
version?: string
}

export function spawnSync (command: string, args: string[], silent?: boolean) {
export function spawnSync (command: string, silent?: boolean) {
if (!silent) console.log(`$ ${command}`)
const result = spawn.sync(command, [...args, '--color'], { cwd, encoding: 'utf8' })
const args = command.split(/\s+/)
const result = spawn.sync(args[0], [...args.slice(1), '--color'], { cwd, encoding: 'utf8' })
if (result.status) {
throw new Error(result.stderr)
} else {
Expand All @@ -31,8 +32,9 @@ export function spawnSync (command: string, args: string[], silent?: boolean) {
}
}

export function spawnAsync (command: string, args: string[] = []) {
const child = spawn(command, args, { stdio: 'inherit' })
export function spawnAsync (command: string) {
const args = command.split(/\s+/)
const child = spawn(args[0], args.slice(1), { stdio: 'inherit' })
return new Promise((resolve, reject) => {
child.on('close', resolve)
})
Expand Down

0 comments on commit c57ce08

Please sign in to comment.