Skip to content
This repository has been archived by the owner on Jul 9, 2018. It is now read-only.

Scripts: Add support for lint-pkg-json script #128

Merged
merged 2 commits into from
May 23, 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
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"is-plain-obj": "^1.1.0",
"lerna": "^2.9.0",
"mkdirp": "^0.5.1",
"npm-package-json-lint": "^3.0.1",
"npm-run-all": "^4.1.2",
"path-type": "^3.0.0",
"rimraf": "^2.6.1",
Expand Down Expand Up @@ -56,7 +55,7 @@
"check-engines": "check-node-version --package",
"create-symlinks": "node ./scripts/create-symlinks.js",
"lerna-bootstrap": "lerna bootstrap --hoist",
"lint:pkg-json": "npmPkgJsonLint ./packages",
"lint:pkg-json": "wp-scripts lint-pkg-json ./packages",
"postinstall": "npm-run-all lerna-bootstrap create-symlinks build",
"pretest": "npm run lint:pkg-json",
"test": "wp-scripts test-unit-js",
Expand Down
6 changes: 5 additions & 1 deletion packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.2.0 (2018-05-23)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will wait for license checker before we release 1.2.0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will wait for license checker before we release 1.2.0.

So will this or won't this be published on 2018-05-23 ? I think we should either:

  • Not compile CHANGELOG.md edits until immediately before a published release.
    • This is what I thought had been settled upon in a previous core-js meeting (reference)
  • Not merge with an explicit date for a version until the date is known (either omit entirely, or a placeholder value like "Unreleased" or "TBD").

Regardless, we should codify this in CONTRIBUTING.md workflow documentation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Unreleased seems like a good choice in this case. I can publish new version just to make sure it doesn't lie 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, it is still unpublished, we should update docs and follow the flow @aduth described 👍


- Added support for `lint-pkg-json` script ([#128](https://github.com/WordPress/packages/pull/128))

## 1.1.5 (2018-05-18)

- Fix: Standardized `package.json` format ([#119](https://github.com/WordPress/packages/pull/119))
- Fix: Standardized `package.json` format ([#119](https://github.com/WordPress/packages/pull/119))
49 changes: 40 additions & 9 deletions packages/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,46 @@ npm install @wordpress/scripts --save-dev

## Setup

This is a CLI and exposes a binary called `wp-scripts` so you can call it directly. However this module is designed to be configured using the `scripts` section in the `package.json` file of your project. Example configuration:
This is a CLI and exposes a binary called `wp-scripts` so you can call it directly. However this module is designed to be configured using the `scripts` section in the `package.json` file of your project.

_Example:_

```json
{
"scripts": {
"lint:pkg-json": "wp-scripts lint-pkg-json .",
"test": "wp-scripts test-unit-js"
}
}
```

## Available Scripts

### `wp-scripts lint-pkg-json`

Helps enforce standards for your package.json file. It uses [npm-package-json-lint](https://www.npmjs.com/package/npm-package-json-lint) with the set of default rules provided. You can override them with your own rules as described in [npm-package-json-lint wiki](https://github.com/tclindner/npm-package-json-lint/wiki).

_Example:_

```json
{
"scripts": {
"lint:pkg-json": "wp-scripts lint-pkg-json ."
}
}
```

This is how you execute those scripts using the presented setup:
* `npm run lint:pkg-jsont` - lints `package.json` file in the project's root folder.

### `wp-scripts test-unit-js`

_Alias_: `wp-scripts test-unit-jest`

Launches the test runner. It uses [Jest](https://facebook.github.io/jest/) behind the scenes and you are able to utilize all of its [CLI options](https://facebook.github.io/jest/docs/en/cli.html). You can also run `./node_modules/.bin/wp-scripts test-unit-js --help` or `npm run test:help` (as presented below) to view all of the available options.

_Example:_

```json
{
"scripts": {
Expand All @@ -28,14 +67,6 @@ This is how you execute those scripts using the presented setup:
* `npm run test:help` - prints all available options to configure unit tests runner.
* `npm run test:watch` - runs all unit tests in the watch mode.

## Available Scripts

### `wp-scripts test-unit-js`

_Alias_: `wp-scripts test-unit-jest`

Launches the test runner. It uses [Jest](https://facebook.github.io/jest/) behind the scenes and you are able to utilize all of its [CLI options](https://facebook.github.io/jest/docs/en/cli.html). You can also run `./node_modules/.bin/wp-scripts test-unit-js --help` or `npm run test:help` (if you use `package.json` setup shared above) to view all of the available options.

## Inspiration

This is inspired by [react-scripts](https://www.npmjs.com/package/react-scripts) and [kcd-scripts](https://www.npmjs.com/package/kcd-scripts).
Expand Down
3 changes: 3 additions & 0 deletions packages/scripts/config/npmpackagejsonlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@wordpress/npm-package-json-lint-config"
}
5 changes: 4 additions & 1 deletion packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
"dependencies": {
"@wordpress/babel-preset-default": "^1.3.0",
"@wordpress/jest-preset-default": "^1.0.6",
"@wordpress/npm-package-json-lint-config": "^1.0.0",
"cross-spawn": "^5.1.0",
"jest": "^22.4.0",
"read-pkg-up": "^3.0.0"
"npm-package-json-lint": "^3.0.1",
"read-pkg-up": "^3.0.0",
"resolve-bin": "^0.4.0"
},
"publishConfig": {
"access": "public"
Expand Down
36 changes: 36 additions & 0 deletions packages/scripts/scripts/lint-pkg-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* External dependencies
*/
const { sync: spawn } = require( 'cross-spawn' );
const { sync: resolveBin } = require( 'resolve-bin' );

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

const args = getCliArgs();

const hasLintConfig = hasCliArg( '-c' ) ||
hasCliArg( '--configFile' ) ||
hasProjectFile( '.npmpackagejsonlintrc.json' ) ||
hasProjectFile( 'npmpackagejsonlint.config.js' ) ||
hasPackageProp( 'npmPackageJsonLintConfig' );

const config = ! hasLintConfig
? [ '--configFile', fromConfigRoot( 'npmpackagejsonlint.json' ) ]
: [];

const result = spawn(
resolveBin( 'npm-package-json-lint', { executable: 'npmPkgJsonLint' } ),
[ ...config, ...args ],
{ stdio: 'inherit' }
);

process.exit( result.status );
4 changes: 4 additions & 0 deletions packages/scripts/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const fromProjectRoot = ( fileName ) =>
const hasProjectFile = ( fileName ) =>
existsSync( fromProjectRoot( fileName ) );

const fromConfigRoot = ( fileName ) =>
path.join( path.dirname( __dirname ), 'config', fileName );

const fromScriptsRoot = ( scriptName ) =>
path.join( path.dirname( __dirname ), 'scripts', `${ scriptName }.js` );

Expand Down Expand Up @@ -74,6 +77,7 @@ const spawnScript = ( scriptName, args = [] ) => {
};

module.exports = {
fromConfigRoot,
getCliArgs,
hasCliArg,
hasProjectFile,
Expand Down
4 changes: 2 additions & 2 deletions packages/scripts/utils/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* External dependencies
*/
const { realpathSync } = require( 'fs' );
const readPkgUp = require( 'read-pkg-up' );
const { sync: readPkgUp } = require( 'read-pkg-up' );

/**
* Internal dependencies
*/
const { getCurrentWorkingDirectory } = require( './process' );

const { pkg, path: pkgPath } = readPkgUp.sync( {
const { pkg, path: pkgPath } = readPkgUp( {
cwd: realpathSync( getCurrentWorkingDirectory() ),
} );

Expand Down