fix(cli): create dist dir if not existed while building
This commit is contained in:
parent
6e7540b2a3
commit
e90ea9304a
2 changed files with 18 additions and 5 deletions
|
@ -8,7 +8,13 @@ import toml from 'toml'
|
|||
import { getNapiConfig } from './consts'
|
||||
import { debugFactory } from './debug'
|
||||
import { getDefaultTargetTriple, parseTriple } from './parse-triple'
|
||||
import { copyFileAsync, existsAsync, readFileAsync, unlinkAsync } from './utils'
|
||||
import {
|
||||
copyFileAsync,
|
||||
existsAsync,
|
||||
mkdirAsync,
|
||||
readFileAsync,
|
||||
unlinkAsync,
|
||||
} from './utils'
|
||||
|
||||
const debug = debugFactory('build')
|
||||
|
||||
|
@ -156,12 +162,18 @@ export class BuildCommand extends Command {
|
|||
debug(`Platform name: ${platformName || chalk.green('[Empty]')}`)
|
||||
const distFileName = `${binaryName}${platformName}.node`
|
||||
|
||||
let distModulePath = join(this.destDir ?? '.', distFileName)
|
||||
const distModulePath = join(this.destDir ?? '.', distFileName)
|
||||
|
||||
const parsedDist = parse(distModulePath)
|
||||
|
||||
if (!parsedDist.ext) {
|
||||
distModulePath = `${distModulePath}${platformName}.node`
|
||||
if (parsedDist.dir && !(await existsAsync(parsedDist.dir))) {
|
||||
await mkdirAsync(parsedDist.dir, { recursive: true }).catch((e) => {
|
||||
console.warn(
|
||||
chalk.bgYellowBright(
|
||||
`Create dir [${parsedDist.dir}] failed, reason: ${e.message}`,
|
||||
),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
const sourcePath = join(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { readFile, writeFile, exists, copyFile, unlink } from 'fs'
|
||||
import { readFile, writeFile, exists, copyFile, mkdir, unlink } from 'fs'
|
||||
import { promisify } from 'util'
|
||||
|
||||
export const readFileAsync = promisify(readFile)
|
||||
|
@ -6,6 +6,7 @@ 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)
|
||||
|
||||
export function pick<O, K extends keyof O>(o: O, ...keys: K[]): Pick<O, K> {
|
||||
return keys.reduce((acc, key) => {
|
||||
|
|
Loading…
Reference in a new issue