feat(cli): support skip gh-release in prepublish command

This commit is contained in:
LongYinan 2021-06-07 11:35:26 +08:00
parent bbd495a795
commit 253360efb9
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7

View file

@ -37,6 +37,9 @@ export class PrePublishCommand extends Command {
@Command.Boolean('--dry-run')
isDryRun = false
@Command.Boolean('--skip-gh-release')
skipGHRelease = false
@Command.Path('prepublish')
async execute() {
const { packageJsonPath, platforms, version, packageName, binaryName } =
@ -69,11 +72,6 @@ export class PrePublishCommand extends Command {
const filename = `${binaryName}.${platformDetail.platformArchABI}.node`
const dstPath = join(pkgDir, filename)
debug(
`Start upload [${chalk.greenBright(
dstPath,
)}] to Github release, [${chalk.greenBright(pkgInfo.tag)}]`,
)
if (!this.isDryRun) {
if (!(await existsAsync(dstPath))) {
console.warn(`[${chalk.yellowBright(dstPath)}] is not existed`)
@ -83,6 +81,12 @@ export class PrePublishCommand extends Command {
cwd: pkgDir,
env: process.env,
})
if (!this.skipGHRelease) {
debug(
`Start upload [${chalk.greenBright(
dstPath,
)}] to Github release, [${chalk.greenBright(pkgInfo.tag)}]`,
)
const putasset = require('putasset')
try {
const downloadUrl = await putasset(process.env.GITHUB_TOKEN, {
@ -95,15 +99,27 @@ export class PrePublishCommand extends Command {
console.info(`Download url: ${chalk.blueBright(downloadUrl)}`)
} catch (e) {
debug(
`Param: ${{ owner, repo, tag: pkgInfo.tag, filename: dstPath }}`,
`Param: ${JSON.stringify(
{ owner, repo, tag: pkgInfo.tag, filename: dstPath },
null,
2,
)}`,
)
console.error(e)
}
}
}
}
}
private async createGhRelease(packageName: string, version: string) {
if (this.skipGHRelease) {
return {
owner: null,
repo: null,
pkgInfo: { name: null, version: null, tag: null },
}
}
const headCommit = (await spawn('git log -1 --pretty=%B'))
.toString('utf8')
.trim()
@ -144,7 +160,13 @@ export class PrePublishCommand extends Command {
tag_name: pkgInfo.tag,
})
} catch (e) {
debug(`Params: ${{ owner, repo, tag_name: pkgInfo.tag }}`)
debug(
`Params: ${JSON.stringify(
{ owner, repo, tag_name: pkgInfo.tag },
null,
2,
)}`,
)
console.error(e)
}
}