feat(cli): support skip gh-release in prepublish command
This commit is contained in:
parent
bbd495a795
commit
253360efb9
1 changed files with 41 additions and 19 deletions
|
@ -37,6 +37,9 @@ export class PrePublishCommand extends Command {
|
||||||
@Command.Boolean('--dry-run')
|
@Command.Boolean('--dry-run')
|
||||||
isDryRun = false
|
isDryRun = false
|
||||||
|
|
||||||
|
@Command.Boolean('--skip-gh-release')
|
||||||
|
skipGHRelease = false
|
||||||
|
|
||||||
@Command.Path('prepublish')
|
@Command.Path('prepublish')
|
||||||
async execute() {
|
async execute() {
|
||||||
const { packageJsonPath, platforms, version, packageName, binaryName } =
|
const { packageJsonPath, platforms, version, packageName, binaryName } =
|
||||||
|
@ -69,11 +72,6 @@ export class PrePublishCommand extends Command {
|
||||||
const filename = `${binaryName}.${platformDetail.platformArchABI}.node`
|
const filename = `${binaryName}.${platformDetail.platformArchABI}.node`
|
||||||
const dstPath = join(pkgDir, filename)
|
const dstPath = join(pkgDir, filename)
|
||||||
|
|
||||||
debug(
|
|
||||||
`Start upload [${chalk.greenBright(
|
|
||||||
dstPath,
|
|
||||||
)}] to Github release, [${chalk.greenBright(pkgInfo.tag)}]`,
|
|
||||||
)
|
|
||||||
if (!this.isDryRun) {
|
if (!this.isDryRun) {
|
||||||
if (!(await existsAsync(dstPath))) {
|
if (!(await existsAsync(dstPath))) {
|
||||||
console.warn(`[${chalk.yellowBright(dstPath)}] is not existed`)
|
console.warn(`[${chalk.yellowBright(dstPath)}] is not existed`)
|
||||||
|
@ -83,6 +81,12 @@ export class PrePublishCommand extends Command {
|
||||||
cwd: pkgDir,
|
cwd: pkgDir,
|
||||||
env: process.env,
|
env: process.env,
|
||||||
})
|
})
|
||||||
|
if (!this.skipGHRelease) {
|
||||||
|
debug(
|
||||||
|
`Start upload [${chalk.greenBright(
|
||||||
|
dstPath,
|
||||||
|
)}] to Github release, [${chalk.greenBright(pkgInfo.tag)}]`,
|
||||||
|
)
|
||||||
const putasset = require('putasset')
|
const putasset = require('putasset')
|
||||||
try {
|
try {
|
||||||
const downloadUrl = await putasset(process.env.GITHUB_TOKEN, {
|
const downloadUrl = await putasset(process.env.GITHUB_TOKEN, {
|
||||||
|
@ -95,15 +99,27 @@ export class PrePublishCommand extends Command {
|
||||||
console.info(`Download url: ${chalk.blueBright(downloadUrl)}`)
|
console.info(`Download url: ${chalk.blueBright(downloadUrl)}`)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debug(
|
debug(
|
||||||
`Param: ${{ owner, repo, tag: pkgInfo.tag, filename: dstPath }}`,
|
`Param: ${JSON.stringify(
|
||||||
|
{ owner, repo, tag: pkgInfo.tag, filename: dstPath },
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
)}`,
|
||||||
)
|
)
|
||||||
console.error(e)
|
console.error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async createGhRelease(packageName: string, version: string) {
|
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'))
|
const headCommit = (await spawn('git log -1 --pretty=%B'))
|
||||||
.toString('utf8')
|
.toString('utf8')
|
||||||
.trim()
|
.trim()
|
||||||
|
@ -144,7 +160,13 @@ export class PrePublishCommand extends Command {
|
||||||
tag_name: pkgInfo.tag,
|
tag_name: pkgInfo.tag,
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} 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)
|
console.error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue