fix(cli): incorrent version without npm folder
This commit is contained in:
parent
69f043c8eb
commit
caeef4a675
2 changed files with 18 additions and 2 deletions
|
@ -1,9 +1,17 @@
|
||||||
import { writeFileAsync } from './utils'
|
import { debugFactory } from './debug'
|
||||||
|
import { writeFileAsync, fileExists } from './utils'
|
||||||
|
|
||||||
|
const debug = debugFactory('update-package')
|
||||||
|
|
||||||
export async function updatePackageJson(
|
export async function updatePackageJson(
|
||||||
path: string,
|
path: string,
|
||||||
partial: Record<string, any>,
|
partial: Record<string, any>,
|
||||||
) {
|
) {
|
||||||
|
const exists = await fileExists(path)
|
||||||
|
if (!exists) {
|
||||||
|
debug(`File not exists ${path}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
const old = require(path)
|
const old = require(path)
|
||||||
await writeFileAsync(path, JSON.stringify({ ...old, ...partial }, null, 2))
|
await writeFileAsync(path, JSON.stringify({ ...old, ...partial }, null, 2))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { readFile, writeFile, copyFile, mkdir, unlink } from 'fs'
|
import { readFile, writeFile, copyFile, mkdir, unlink, stat } from 'fs'
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util'
|
||||||
|
|
||||||
export const readFileAsync = promisify(readFile)
|
export const readFileAsync = promisify(readFile)
|
||||||
|
@ -6,6 +6,14 @@ export const writeFileAsync = promisify(writeFile)
|
||||||
export const unlinkAsync = promisify(unlink)
|
export const unlinkAsync = promisify(unlink)
|
||||||
export const copyFileAsync = promisify(copyFile)
|
export const copyFileAsync = promisify(copyFile)
|
||||||
export const mkdirAsync = promisify(mkdir)
|
export const mkdirAsync = promisify(mkdir)
|
||||||
|
export const statAsync = promisify(stat)
|
||||||
|
|
||||||
|
export async function fileExists(path: string) {
|
||||||
|
const exists = await statAsync(path)
|
||||||
|
.then(() => true)
|
||||||
|
.catch(() => false)
|
||||||
|
return exists
|
||||||
|
}
|
||||||
|
|
||||||
export function pick<O, K extends keyof O>(o: O, ...keys: K[]): Pick<O, K> {
|
export function pick<O, K extends keyof O>(o: O, ...keys: K[]): Pick<O, K> {
|
||||||
return keys.reduce((acc, key) => {
|
return keys.reduce((acc, key) => {
|
||||||
|
|
Loading…
Reference in a new issue