Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

licenses.jsonの生成スクリプトを追加 #275

Merged
merged 7 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ data/

# release
electron-builder.yml

# generated licenses.json
/*licenses.json
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ Issue 側で取り組み始めたことを伝えるか、最初に Draft プル
npm run electron:build
```

## 依存ライブラリのライセンス情報の生成

```bash
# get licenses.json from voicevox_engine as engine_licenses.json

npm run license:generate -- -o voicevox_licenses.json
npm run license:merge -- -o public/licenses.json -i engine_licenses.json -i voicevox_licenses.json
```

## コードフォーマット

コードのフォーマットを整えます。プルリクエストを送る前に実行してください。
Expand Down
48 changes: 48 additions & 0 deletions build/generateLicenses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable @typescript-eslint/no-var-requires */

const process = require("process");
const yargs = require("yargs/yargs");
const { hideBin } = require("yargs/helpers");
const argv = yargs(hideBin(process.argv))
.option("output_path", {
alias: "o",
demandOption: true,
type: "string"
})
.help()
.parse();

const { execSync } = require("child_process");
const fs = require("fs");

const customFormat = JSON.stringify({
name: "",
version: "",
description: "",
licenses: "",
copyright: "",
licenseFile: "none",
licenseText: "none",
licenseModified: "no"
});

// https://github.com/davglass/license-checker
// npm install -g license-checker
const licenseJson = execSync(
`license-checker --production --excludePrivatePackages --json --customPath ${customFormat}`,
{
encoding: "utf-8"
}
);

const checkerLicenses = JSON.parse(licenseJson);

const licenses = Object.entries(checkerLicenses).map(([packageName, license]) => ({
name: license.name,
version: license.version,
license: license.licenses,
text: license.licenseText,
}));

const outputPath = argv.output_path;
fs.writeFileSync(outputPath, JSON.stringify(licenses));
37 changes: 37 additions & 0 deletions build/mergeLicenses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* eslint-disable @typescript-eslint/no-var-requires */

const process = require("process");
const yargs = require("yargs/yargs");
const { hideBin } = require("yargs/helpers");
const argv = yargs(hideBin(process.argv))
.option("output_path", {
alias: "o",
demandOption: true,
type: "string"
})
.option("input_path", {
alias: "i",
demandOption: true,
type: "string"
})
.help()
.parse();

const fs = require("fs");

const inputPathList = typeof argv.input_path === 'string' ?
[ argv.input_path ] : argv.input_path;

let mergedLicenses = [];

for (const inputPath of inputPathList) {
const licenseJson = fs.readFileSync(inputPath, {
encoding: 'utf-8'
});

const licenses = JSON.parse(licenseJson);
mergedLicenses = mergedLicenses.concat(licenses);
}

outputPath = argv.output_path;
fs.writeFileSync(outputPath, JSON.stringify(mergedLicenses));
Loading