Files
archived-next-auth/scripts/release/utils.ts
2022-07-08 19:55:08 +02:00

40 lines
1.0 KiB
TypeScript

import type { PackageJson } from "type-fest"
import fs from "node:fs/promises"
import path from "node:path"
import { execSync as nodeExecSync } from "node:child_process"
import { config } from "./config"
async function read(directory: string): Promise<PackageJson> {
const content = await fs.readFile(
path.join(process.cwd(), directory, "package.json"),
"utf8"
)
return JSON.parse(content)
}
async function update(
directory: string,
data: Partial<PackageJson>
): Promise<void> {
const original = await pkgJson.read(directory)
const content = JSON.stringify({ ...original, ...data }, null, 2)
await fs.writeFile(
path.join(process.cwd(), directory, "package.json"),
content,
"utf8"
)
}
export const pkgJson = { read, update }
export function debug(...args: any[]): void {
if (!config.verbose) return
const [first, ...rest] = args
console.log(`\n[debug] ${first}\n`, ...rest, "\n")
}
export function execSync(...args: Parameters<typeof nodeExecSync>) {
return nodeExecSync(args[0], { stdio: "inherit", ...args[1] })
}