Skip to content

Commit

Permalink
Scripts: Add check-engines script to the package (#12721)
Browse files Browse the repository at this point in the history
* Scripts: Add check-engines script to the package

* Update packages/scripts/CHANGELOG.md

Co-Authored-By: gziolo <grzegorz@gziolo.pl>

* Update packages/scripts/README.md

Co-Authored-By: gziolo <grzegorz@gziolo.pl>

* Update minimal node version to 10.x

Co-Authored-By: gziolo <grzegorz@gziolo.pl>
  • Loading branch information
gziolo authored and youknowriad committed Jan 9, 2019
1 parent 23db8aa commit 120f80d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 6 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
"WordPress",
"editor"
],
"engines": {
"node": ">=8.0.0",
"npm": ">=6.0.0"
},
"dependencies": {
"@wordpress/a11y": "file:packages/a11y",
"@wordpress/annotations": "file:packages/annotations",
Expand Down Expand Up @@ -72,7 +68,6 @@
"autoprefixer": "8.2.0",
"babel-loader": "8.0.0",
"chalk": "2.4.1",
"check-node-version": "3.1.1",
"concurrently": "3.5.0",
"copy-webpack-plugin": "4.5.2",
"core-js": "2.5.7",
Expand Down Expand Up @@ -145,7 +140,7 @@
"prebuild:packages": "npm run clean:packages && lerna run build && cross-env INCLUDE_PACKAGES=babel-plugin-import-jsx-pragma,postcss-themes,jest-console SKIP_JSX_PRAGMA_TRANSFORM=1 node ./bin/packages/build.js",
"build:packages": "cross-env EXCLUDE_PACKAGES=babel-plugin-import-jsx-pragma,jest-console,postcss-themes node ./bin/packages/build.js",
"build": "npm run build:packages && cross-env NODE_ENV=production webpack",
"check-engines": "check-node-version --package",
"check-engines": "wp-scripts check-engines",
"check-licenses": "concurrently \"wp-scripts check-licenses --prod --gpl2\" \"wp-scripts check-licenses --dev\"",
"precheck-local-changes": "npm run docs:build",
"check-local-changes": "( git diff -U0 | xargs -0 node bin/process-git-diff ) || ( echo \"There are local uncommitted changes after one or both of 'npm install' or 'npm run docs:build'!\" && exit 1 );",
Expand Down
6 changes: 6 additions & 0 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.5.0 (Unreleased)

### New Feature

- Added support for `check-engines` script ([#12721](https://github.com/WordPress/gutenberg/pull/12721))

## 2.4.4 (2018-11-20)

## 2.4.3 (2018-11-09)
Expand Down
19 changes: 19 additions & 0 deletions packages/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ _Example:_
```json
{
"scripts": {
"check-engines": "wp-scripts check-engines",
"lint:pkg-json": "wp-scripts lint-pkg-json .",
"test": "wp-scripts test-unit-js"
}
Expand All @@ -27,6 +28,24 @@ _Example:_

## Available Scripts

### `check-engines`

Check if the current `node`, `npm` (or `yarn`) versions match the given [semantic version](https://semver.org/) ranges. If the given version is not satisfied, information about installing the needed version is printed and the program exits with an error code. It uses [check-node-version](https://www.npmjs.com/package/check-node-version) behind the scenes with the default configuration provided. You can specify your own ranges as described in [check-node-version docs](https://www.npmjs.com/package/check-node-version).

_Example:_

```json
{
"scripts": {
"check-engines": "wp-scripts check-engines"
}
}
```

This is how you execute the script with presented setup:
* `npm run check-engines` - checks installed version of `node` and `npm`.


### `wp-scripts lint-js`

Helps enforce coding style guidelines for your JavaScript files. It uses [eslint](https://eslint.org/) with no rules provided (we plan to add zero config support in the near future). You can specify your own rules as described in [eslint docs](https://eslint.org/docs/rules/).
Expand Down
1 change: 1 addition & 0 deletions packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@wordpress/npm-package-json-lint-config": "file:../npm-package-json-lint-config",
"babel-eslint": "8.0.3",
"chalk": "^2.4.1",
"check-node-version": "^3.1.1",
"cross-spawn": "^5.1.0",
"eslint": "^4.19.1",
"jest": "^23.6.0",
Expand Down
34 changes: 34 additions & 0 deletions packages/scripts/scripts/check-engines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* External dependencies
*/
const { sync: spawn } = require( 'cross-spawn' );
const { sync: resolveBin } = require( 'resolve-bin' );

/**
* Internal dependencies
*/
const {
getCliArgs,
hasCliArg,
} = require( '../utils' );

const args = getCliArgs();

const hasConfig = hasCliArg( '--package' ) ||
hasCliArg( '--node' ) ||
hasCliArg( '--npm' ) ||
hasCliArg( '--yarn' );
const config = ! hasConfig ?
[
'--node', '>=10.0.0',
'--npm', '>=6.0.0',
] :
[];

const result = spawn(
resolveBin( 'check-node-version' ),
[ ...config, ...args ],
{ stdio: 'inherit' }
);

process.exit( result.status );

0 comments on commit 120f80d

Please sign in to comment.