napi-rs/cli/src/update-package.ts

18 lines
449 B
TypeScript
Raw Normal View History

import { debugFactory } from './debug'
import { writeFileAsync, fileExists } from './utils'
const debug = debugFactory('update-package')
2020-09-04 17:22:15 +09:00
export async function updatePackageJson(
path: string,
partial: Record<string, any>,
) {
const exists = await fileExists(path)
if (!exists) {
debug(`File not exists ${path}`)
return
}
2020-09-04 17:22:15 +09:00
const old = require(path)
await writeFileAsync(path, JSON.stringify({ ...old, ...partial }, null, 2))
}