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,27 +81,45 @@ export class PrePublishCommand extends Command {
|
||||||
cwd: pkgDir,
|
cwd: pkgDir,
|
||||||
env: process.env,
|
env: process.env,
|
||||||
})
|
})
|
||||||
const putasset = require('putasset')
|
if (!this.skipGHRelease) {
|
||||||
try {
|
|
||||||
const downloadUrl = await putasset(process.env.GITHUB_TOKEN, {
|
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
tag: pkgInfo.tag,
|
|
||||||
filename: dstPath,
|
|
||||||
})
|
|
||||||
console.info(`${chalk.green(dstPath)} upload success`)
|
|
||||||
console.info(`Download url: ${chalk.blueBright(downloadUrl)}`)
|
|
||||||
} catch (e) {
|
|
||||||
debug(
|
debug(
|
||||||
`Param: ${{ owner, repo, tag: pkgInfo.tag, filename: dstPath }}`,
|
`Start upload [${chalk.greenBright(
|
||||||
|
dstPath,
|
||||||
|
)}] to Github release, [${chalk.greenBright(pkgInfo.tag)}]`,
|
||||||
)
|
)
|
||||||
console.error(e)
|
const putasset = require('putasset')
|
||||||
|
try {
|
||||||
|
const downloadUrl = await putasset(process.env.GITHUB_TOKEN, {
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
tag: pkgInfo.tag,
|
||||||
|
filename: dstPath,
|
||||||
|
})
|
||||||
|
console.info(`${chalk.green(dstPath)} upload success`)
|
||||||
|
console.info(`Download url: ${chalk.blueBright(downloadUrl)}`)
|
||||||
|
} catch (e) {
|
||||||
|
debug(
|
||||||
|
`Param: ${JSON.stringify(
|
||||||
|
{ owner, repo, tag: pkgInfo.tag, filename: dstPath },
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
)}`,
|
||||||
|
)
|
||||||
|
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