Skip to content

Commit

Permalink
fix(cli): wrong release assets content
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Nov 21, 2021
1 parent 47c5867 commit 458c5c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
13 changes: 10 additions & 3 deletions cli/src/pre-publish.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createReadStream, existsSync, statSync } from 'fs'
import { join } from 'path'

import { Octokit } from '@octokit/rest'
Expand All @@ -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')
Expand Down Expand Up @@ -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
}
Expand All @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions cli/src/utils.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 458c5c9

Please sign in to comment.