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"
|
import path from "node:path"
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const cwd = process.cwd()
|
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 (
|
||||||
fs.unlinkSync(outputFilePath)
|
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) {
|
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 (
|
||||||
continue
|
!(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({
|
licenses.push({
|
||||||
name: pkgJson.name,
|
name: pkgJson.name,
|
||||||
version: pkgJson.version,
|
version: pkgJson.version,
|
||||||
license: pkgJson.license,
|
license: pkgJson.license,
|
||||||
author: pkgJson.author,
|
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