Skip to content

Commit

Permalink
Create the check-npm-licenses.sh script.
Browse files Browse the repository at this point in the history
  • Loading branch information
pento committed May 4, 2018
1 parent fea0c13 commit 9ee0b2e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- stage: test
script:
- npm install || exit 1
- npm run license-check || exit 1
- ./bin/check-npm-licenses.sh || exit 1
- npm run ci || exit 1

- stage: test
Expand Down
40 changes: 40 additions & 0 deletions bin/check-npm-licenses.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Include useful functions
. "$(dirname "$0")/includes.sh"

ALLOWED_LICENSES=(
"GPL-2.0-or-later"
"GPL-2.0+"
"(GPL-2.0 OR MIT)"
"MIT"
"ISC"
"BSD"
"BSD-2-Clause"
"BSD-3-Clause"
"CC0-1.0"
)

FOUND_INCOMPATIBLE_MODULE=false


for MODULE_DIR in $(npm ls --production --parseable); do
PACKAGE_JSON="${MODULE_DIR}/package.json"

PACKAGE_NAME=$(jq --raw-output '.name' $PACKAGE_JSON)
PACKAGE_LICENSE=$(jq --raw-output '( .license // .licenses[0].type )' $PACKAGE_JSON)

if ! in_array "${PACKAGE_LICENSE}" "${ALLOWED_LICENSES[@]}"; then
if ! $FOUND_INCOMPATIBLE_MODULE; then
FOUND_INCOMPATIBLE_MODULE=true;
echo "These modules have incompatible licences:"
fi
echo "${PACKAGE_NAME}: ${PACKAGE_LICENSE}"
fi
done

if ! $FOUND_INCOMPATIBLE_MODULE; then
echo "All module licenses are compatible."
else
exit 1;
fi
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"test": "npm run lint && npm run test-unit",
"test-php": "npm run lint-php && npm run test-unit-php",
"ci": "concurrently \"npm run lint && npm run build\" \"npm run test-unit:coverage-ci\"",
"license-check": "! npm ls --production --parseable | xargs -I {} jq --raw-output '.name + \" \" + ( .license // .licenses[0].type )' '{}/package.json' | grep -v -E '^.* .*(MIT|GPL-2|ISC|BSD|CC0).*$'",
"check-licenses": "./bin/check-npm-licenses.sh",
"fixtures:clean": "rimraf \"blocks/test/fixtures/*.+(json|serialized.html)\"",
"fixtures:server-registered": "docker-compose run -w /var/www/html/wp-content/plugins/gutenberg --rm wordpress ./bin/get-server-blocks.php > core-blocks/test/server-registered.json",
"fixtures:generate": "npm run fixtures:server-registered && cross-env GENERATE_MISSING_FIXTURES=y npm run test-unit",
Expand Down

0 comments on commit 9ee0b2e

Please sign in to comment.