Skip to content

Commit

Permalink
fix: add --allowList and --allowLicenses to license-validate script (#21
Browse files Browse the repository at this point in the history
)
  • Loading branch information
nytamin authored Aug 21, 2023
1 parent a8e537d commit a9529ef
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions bin/checkLicenses.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const cli = meow(
Options
--debug Show full packages list
--allowPackages Semi-colon separated list of packages to ignore (eg [email protected];[email protected])
--allowList Which default list of licenses to use. Possible values: "MIT", "none". Defaults to "MIT"
--allowLicenses Semi-colon separated list of licenses to allow in addition to the default list (eg GPL-3.0-only;MIT)
`,
{
importMeta: import.meta,
Expand All @@ -32,17 +34,40 @@ const cli = meow(
const pkgInfo = readPackageUpSync()
const projectNameAndVersion = `${pkgInfo.packageJson.name}@${pkgInfo.packageJson.version}`

// TODO - Add option driven allowList selection with a list for GPL projects
const allowListForMit = 'MIT;BSD;ISC;Apache-2.0;CC0;CC-BY-3.0;CC-BY-4.0;Unlicense;Artistic-2.0;Python-2.0;BlueOak-1.0.0'
const allowLists = {
MIT: 'MIT;BSD;ISC;Apache-2.0;CC0;CC-BY-3.0;CC-BY-4.0;Unlicense;Artistic-2.0;Python-2.0;BlueOak-1.0.0',
none: '',
// TODO - Add allowList with a list for GPL projects
}

const useAllowList = cli.flags.allowList || 'MIT'
let allowList = ''
if (useAllowList === 'none') {
allowList = allowLists.none
} else if (useAllowList === 'MIT') {
allowList = allowLists.MIT
} else {
console.error(`Invalid argument value: --allowList: ${useAllowList} (possible values: "MIT", "none")`)
process.exit(1)
}
if (cli.flags.allowLicenses) {
allowList += `;${cli.flags.allowLicenses}`
}

let excludePackages = projectNameAndVersion
if (cli.flags.allowPackages) {
excludePackages += `;${cli.flags.allowPackages}`
}

if (cli.flags.debug) {
console.log('CLI flags', cli.flags)
console.log('excludePackages', excludePackages)
console.log('allowList', allowList)
}

checker.init({
start: path.resolve('.'),
onlyAllow: allowListForMit,
onlyAllow: allowList,
excludePackages: excludePackages,
summary: !cli.flags.debug
}, (err, packages) => {
Expand Down

0 comments on commit a9529ef

Please sign in to comment.