-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
6 changed files
with
583 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,6 @@ data/ | |
|
||
# release | ||
electron-builder.yml | ||
|
||
# generated licenses.json | ||
/*licenses.json |
This file contains 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
This file contains 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
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)); |
This file contains 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
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)); |
Oops, something went wrong.