Skip to content

Commit

Permalink
Multiline params
Browse files Browse the repository at this point in the history
  • Loading branch information
packpacka authored and daynin committed May 7, 2021
1 parent 6fc7f6a commit 48b9a2a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: 'Node.js License Checker'
description: 'Check licenses of a project dependencies'
inputs:
allow-only:
description: 'List of allowed licences separated by semicolon (example: "MIT;BSD;GPL")'
description: 'List of allowed licences separated by line-break'
required: true
default: 'MIT;BSD'
exclude-packages:
description: 'List of excluded packages with version separated by semicolon (example: "[email protected];[email protected]")'
description: 'List of excluded packages with version (example: "[email protected]") separated by line-break'
required: false
default: ''
paths:
description: 'List of sub-packages in monorepo (including root)'
description: 'List of sub-packages in monorepo (including root) separated by line-break'
required: false
default: './'
runs:
Expand Down
22 changes: 12 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14603,15 +14603,17 @@ var __webpack_exports__ = {};
const core = __nccwpck_require__(2186)
const licenseChecker = __nccwpck_require__(5840)

const getMultilineInput = (name) => core.getInput(name).split('\n');

const checkLicenses = (path) => {
return new Promise((resolve) => {
const allowedLicenses = core.getInput('allow-only')
const excludePackages = core.getInput('exclude-packages')
const allowedLicenses = getMultilineInput('allow-only')
const excludePackages = getMultilineInput('exclude-packages')
try {
licenseChecker.init({
start: path,
onlyAllow: allowedLicenses,
excludePackages: excludePackages
onlyAllow: allowedLicenses.join(';'),
excludePackages: excludePackages.join(';')
}, err => {
resolve(err);
})
Expand All @@ -14622,14 +14624,14 @@ const checkLicenses = (path) => {
}

try {
const paths = (core.getInput('paths') || './').split(';');
const paths = getMultilineInput('paths');

Promise.all(paths.map(checkLicenses)).then((errors) => {
if (errors.filter(Boolean).length) {
errors.forEach((error, index) => {
if (error) {
Promise.all(paths.map(checkLicenses)).then((pathsErrors) => {
if (pathsErrors.filter(Boolean).length) {
pathsErrors.forEach((pathCheckErrors, index) => {
if (pathErrors) {
console.log(`Found errors while check path "${paths[index]}"`);
console.log(error);
console.log(pathCheckErrors);
}
})
core.setFailed('Licenses check has been failed')
Expand Down
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const core = require('@actions/core')
const licenseChecker = require('license-checker')

const getMultilineInput = (name) => core.getInput(name).split('\n');

const checkLicenses = (path) => {
return new Promise((resolve) => {
const allowedLicenses = core.getInput('allow-only')
const excludePackages = core.getInput('exclude-packages')
const allowedLicenses = getMultilineInput('allow-only')
const excludePackages = getMultilineInput('exclude-packages')
try {
licenseChecker.init({
start: path,
onlyAllow: allowedLicenses,
excludePackages: excludePackages
onlyAllow: allowedLicenses.join(';'),
excludePackages: excludePackages.join(';')
}, err => {
resolve(err);
})
Expand All @@ -20,7 +22,7 @@ const checkLicenses = (path) => {
}

try {
const paths = core.getInput('paths').split(';');
const paths = getMultilineInput('paths');

Promise.all(paths.map(checkLicenses)).then((pathsErrors) => {
if (pathsErrors.filter(Boolean).length) {
Expand Down

0 comments on commit 48b9a2a

Please sign in to comment.