This commit is contained in:
SrGooglo 2025-02-11 16:10:11 +00:00
parent c9b485991e
commit 79f64eaec2

View File

@ -3,28 +3,51 @@ import path from "node:path"
async function main() {
const cwd = process.cwd()
const outputFilePath = path.resolve(process.cwd(), "public", "oss-licenses.json")
const outputFilePath = path.resolve(
process.cwd(),
"public",
"oss-licenses.json",
)
if (await fs.promises.stat(outputFilePath).then(() => true, () => false)) {
if (
await fs.promises.stat(outputFilePath).then(
() => true,
() => false,
)
) {
fs.unlinkSync(outputFilePath)
}
const rootPkgJson = JSON.parse(fs.readFileSync(path.resolve(cwd, "package.json")))
const rootPkgJson = JSON.parse(
fs.readFileSync(path.resolve(cwd, "package.json")),
)
const modules = Object.entries(rootPkgJson.dependencies).map(([name, version]) => ({ name, version }))
const modules = Object.entries(rootPkgJson.dependencies).map(
([name, version]) => ({ name, version }),
)
let licenses = []
for await (const mod of modules) {
const pkgJsonPath = path.resolve(cwd, "node_modules", mod.name, "package.json")
const pkgJsonPath = path.resolve(
cwd,
"node_modules",
mod.name,
"package.json",
)
if (!await fs.promises.stat(pkgJsonPath).then(() => true, () => false)) {
if (
!(await fs.promises.stat(pkgJsonPath).then(
() => true,
() => false,
))
) {
continue
}
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath))
console.log(`Computing license for [${mod}]`)
console.log(`Computing license for [${mod.name}]`)
licenses.push({
name: pkgJson.name,