Created
September 19, 2025 01:22
-
-
Save akagoma/46976b801611469491a66924c155bdee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // convert-licenses.js | |
| const fs = require("fs"); | |
| const path = require("path"); | |
| // 入力JSONファイルと出力CSVファイルのパス | |
| const inputFile = path.resolve(__dirname, "license.json"); | |
| const outputFile = path.resolve(__dirname, "license.csv"); | |
| // ライセンス名とURLの対応表 | |
| const licenseUrls = { | |
| MIT: "https://opensource.org/licenses/MIT", | |
| ISC: "https://opensource.org/licenses/ISC", | |
| Apache: "https://www.apache.org/licenses/LICENSE-2.0", | |
| "Apache-2.0": "https://www.apache.org/licenses/LICENSE-2.0", | |
| "Python-2.0": "https://www.python.org/download/releases/2.0/license/", | |
| "BSD-2-Clause": "https://opensource.org/licenses/BSD-2-Clause", | |
| "BSD-3-Clause": "https://opensource.org/license/BSD-3-Clause", | |
| "CC0-1.0": "https://creativecommons.org/publicdomain/zero/1.0/", | |
| // 必要に応じて追加 | |
| }; | |
| // JSON読み込み | |
| const raw = fs.readFileSync(inputFile, "utf-8"); | |
| const data = JSON.parse(raw); | |
| // CSVのヘッダー | |
| const header = ["package", "version", "repository", "license", "licenseUrl", "", "", "url"]; | |
| const rows = [header.join(",")]; | |
| // JSONをCSVに変換 | |
| for (const [key, value] of Object.entries(data)) { | |
| // key は "@scope/name@version" 形式なので分割 | |
| let packageName = key; | |
| let version = ""; | |
| if (key.includes("@")) { | |
| const idx = key.lastIndexOf("@"); | |
| packageName = key.slice(0, idx); | |
| version = key.slice(idx + 1); | |
| } | |
| const repository = value.repository || ""; | |
| const license = value.licenses || ""; | |
| const licenseUrl = licenseUrls[license] || ""; // 該当がなければ空 | |
| const url = value.url || ""; | |
| rows.push([packageName, version, repository, license, licenseUrl, "", "", url].join(",")); | |
| } | |
| // CSVファイルに書き込み | |
| fs.writeFileSync(outputFile, rows.join("\n"), "utf-8"); | |
| console.log("✅ CSVに変換しました:", outputFile); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment