mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
40 lines
1.0 KiB
TypeScript
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] })
|
|
}
|