mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
fix log
This commit is contained in:
parent
c9b485991e
commit
79f64eaec2
@ -2,43 +2,66 @@ import fs from "node:fs"
|
||||
import path from "node:path"
|
||||
|
||||
async function main() {
|
||||
const cwd = process.cwd()
|
||||
const outputFilePath = path.resolve(process.cwd(), "public", "oss-licenses.json")
|
||||
const cwd = process.cwd()
|
||||
const outputFilePath = path.resolve(
|
||||
process.cwd(),
|
||||
"public",
|
||||
"oss-licenses.json",
|
||||
)
|
||||
|
||||
if (await fs.promises.stat(outputFilePath).then(() => true, () => false)) {
|
||||
fs.unlinkSync(outputFilePath)
|
||||
}
|
||||
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 = []
|
||||
let licenses = []
|
||||
|
||||
for await (const mod of modules) {
|
||||
const pkgJsonPath = path.resolve(cwd, "node_modules", mod.name, "package.json")
|
||||
for await (const mod of modules) {
|
||||
const pkgJsonPath = path.resolve(
|
||||
cwd,
|
||||
"node_modules",
|
||||
mod.name,
|
||||
"package.json",
|
||||
)
|
||||
|
||||
if (!await fs.promises.stat(pkgJsonPath).then(() => true, () => false)) {
|
||||
continue
|
||||
}
|
||||
if (
|
||||
!(await fs.promises.stat(pkgJsonPath).then(
|
||||
() => true,
|
||||
() => false,
|
||||
))
|
||||
) {
|
||||
continue
|
||||
}
|
||||
|
||||
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath))
|
||||
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,
|
||||
version: pkgJson.version,
|
||||
license: pkgJson.license,
|
||||
author: pkgJson.author,
|
||||
})
|
||||
}
|
||||
licenses.push({
|
||||
name: pkgJson.name,
|
||||
version: pkgJson.version,
|
||||
license: pkgJson.license,
|
||||
author: pkgJson.author,
|
||||
})
|
||||
}
|
||||
|
||||
licenses = licenses.sort((a, b) => a.name.localeCompare(b.name))
|
||||
licenses = licenses.sort((a, b) => a.name.localeCompare(b.name))
|
||||
|
||||
fs.writeFileSync(outputFilePath, JSON.stringify(licenses, null, 4))
|
||||
fs.writeFileSync(outputFilePath, JSON.stringify(licenses, null, 4))
|
||||
|
||||
console.log(`Wrote [${licenses.length}] licenses to > ${outputFilePath}`)
|
||||
console.log(`Wrote [${licenses.length}] licenses to > ${outputFilePath}`)
|
||||
}
|
||||
|
||||
main()
|
||||
main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user