Skip to content

Commit

Permalink
licenses.jsonの生成スクリプトを追加 (#275)
Browse files Browse the repository at this point in the history
* add generateLicences.js (npm run license:generate)

* yargs

* add mergeLicenses.js (npm run license:merge)

* doc: license generation

* fix dependencies (dev)

* fix long line

* ignore file *licenses.json
  • Loading branch information
aoirint authored Sep 28, 2021
1 parent 7d3e948 commit ae536ea
Show file tree
Hide file tree
Showing 6 changed files with 583 additions and 43 deletions.
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

0 comments on commit ae536ea

Please sign in to comment.