fix(cli): wrong release assets content

This commit is contained in:
LongYinan 2021-11-21 21:39:36 +08:00
parent 47c5867922
commit 458c5c9457
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
2 changed files with 11 additions and 5 deletions

View file

@ -1,3 +1,4 @@
import { createReadStream, existsSync, statSync } from 'fs'
import { join } from 'path'
import { Octokit } from '@octokit/rest'
@ -8,7 +9,6 @@ import { getNapiConfig } from './consts'
import { debugFactory } from './debug'
import { spawn } from './spawn'
import { updatePackageJson } from './update-package'
import { existsAsync } from './utils'
import { VersionCommand } from './version'
const debug = debugFactory('prepublish')
@ -69,7 +69,7 @@ export class PrePublishCommand extends Command {
const dstPath = join(pkgDir, filename)
if (!this.isDryRun) {
if (!(await existsAsync(dstPath))) {
if (!existsSync(dstPath)) {
console.warn(`[${chalk.yellowBright(dstPath)}] is not existed`)
continue
}
@ -89,12 +89,19 @@ export class PrePublishCommand extends Command {
owner: owner!,
tag: pkgInfo.tag!,
})
const dstFileStats = statSync(dstPath)
const assetInfo = await octokit!.repos.uploadReleaseAsset({
owner: owner!,
repo: repo!,
data: dstPath,
name: filename,
release_id: releaseInfo.data.id,
mediaType: { format: 'raw' },
headers: {
'content-length': dstFileStats.size,
'content-type': 'application/octet-stream',
},
// @ts-expect-error
data: createReadStream(dstPath),
})
console.info(`${chalk.green(dstPath)} upload success`)
console.info(

View file

@ -1,9 +1,8 @@
import { readFile, writeFile, exists, copyFile, mkdir, unlink } from 'fs'
import { readFile, writeFile, copyFile, mkdir, unlink } from 'fs'
import { promisify } from 'util'
export const readFileAsync = promisify(readFile)
export const writeFileAsync = promisify(writeFile)
export const existsAsync = promisify(exists)
export const unlinkAsync = promisify(unlink)
export const copyFileAsync = promisify(copyFile)
export const mkdirAsync = promisify(mkdir)