Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripts: Add check-engines script to the package #12721

Merged
merged 4 commits into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );