Skip to content

Commit

Permalink
chore: fix license check script
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Oct 11, 2024
1 parent adbc427 commit d9e8db9
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 16 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"dev:electron": "lerna run dev --stream --scope=superconductor",
"dev:bridge": "lerna run dev --stream --scope=tsr-bridge",
"test": "lerna run test",
"license-validate": "node scripts/license-check.js",
"license-validate": "node scripts/license-check.mjs",
"release:bump": "lerna version --force-publish --no-push",
"release:prerelease": "lerna version prerelease --force-publish --no-push",
"release:preminor": "lerna version preminor --force-publish --no-push"
Expand All @@ -47,6 +47,7 @@
"@sofie-automation/eslint-plugin": "^0.1.1",
"@tsconfig/node20": "^20.1.4",
"@types/jest": "^29.5.13",
"@types/license-checker": "^25",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.16.11",
"@types/shelljs": "^0",
Expand All @@ -60,6 +61,7 @@
"husky": "^9.1.6",
"jest": "^29.7.0",
"lerna": "^8.1.8",
"license-checker": "^25.0.1",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
Expand Down
42 changes: 32 additions & 10 deletions scripts/license-check.js → scripts/license-check.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
/* eslint-disable n/no-process-exit, n/no-extraneous-require,@typescript-eslint/no-require-imports */
'use strict'
const fs = require('fs')
const path = require('path')
const shell = require('shelljs')
// @ts-check

import fs from 'fs'
import path from 'path'
import checker from 'license-checker'
import { createRequire } from 'module'

const require = createRequire(import.meta.url)

const DEBUG = false

function getDirectories(source) {
return fs
Expand All @@ -14,20 +20,36 @@ function getDirectories(source) {
const sharedPackages = getDirectories(path.resolve('./shared/packages'))
if (sharedPackages.length < 4) throw new Error('expected more shared/packages')

const ROOT_VERSION = require('../package.json').version
const CURRENT_VERSION = require('@shared/api/package.json').version

const allowPackages = [
`[email protected]`,
`[email protected]`,
`[email protected]`,
`[email protected]`,
`[email protected]`,
...sharedPackages.map((pkg) => `@shared/${pkg}@${CURRENT_VERSION}`),
`superconductor-monorepo@${ROOT_VERSION}`,
`superconductor@${CURRENT_VERSION}`,
`tsr-bridge@${CURRENT_VERSION}`,
]

const cmd = ['yarn', 'sofie-licensecheck', '--allowPackages', `"${allowPackages.join(';')}"`]

const res = shell.exec(cmd.join(' '))
process.exit(res.code)
checker.init(
{
start: path.resolve('.'),
onlyAllow: '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',
excludePackages: allowPackages.join(';'),
summary: !DEBUG,
},
(err, packages) => {
if (err) {
//Handle error
console.error(err)
process.exit(1)
} else {
if (DEBUG) {
console.log(packages)
}
process.exit(0)
}
}
)
Loading

0 comments on commit d9e8db9

Please sign in to comment.