newspack-scripts 5.5.1 → 5.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +1 -1
- package/.eslintrc.js +9 -0
- package/.nvmrc +1 -1
- package/README.md +93 -31
- package/bin/newspack-scripts.js +35 -35
- package/config/babel.config.js +6 -7
- package/config/commitlint.config.js +1 -1
- package/config/eslintrc.js +74 -62
- package/config/getWebpackConfig.js +21 -23
- package/config/postcss.config.js +3 -3
- package/config/prettier.config.js +6 -0
- package/config/stylelint.config.js +32 -28
- package/config/tsconfig.json +24 -20
- package/package.json +85 -82
- package/scripts/commit.js +10 -10
- package/scripts/commitlint.js +10 -9
- package/scripts/release.js +143 -145
- package/scripts/semantic-release.js +25 -0
- package/scripts/test.js +42 -32
- package/scripts/typescript-check.js +11 -12
- package/scripts/utils/babelJestTransformer.js +11 -12
- package/scripts/utils/index.js +17 -17
- package/scripts/utils/jestSetup.js +35 -35
- package/scripts/utils/modules.js +22 -3
- package/scripts/wp-scripts.js +23 -0
- package/src/jobs/lint-js-scss.yml +2 -2
- package/scripts/build.js +0 -19
- package/scripts/watch.js +0 -13
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const spawn = require(
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const utils = require("./utils/index.js");
|
|
3
|
+
const spawn = require( 'cross-spawn' );
|
|
4
|
+
const utils = require( './utils/index.js' );
|
|
5
|
+
const tsc = require.resolve( 'typescript/bin/tsc' );
|
|
7
6
|
|
|
8
|
-
utils.log(
|
|
7
|
+
utils.log( 'Starting TypeScript check…' );
|
|
9
8
|
|
|
10
|
-
const result = spawn.sync(
|
|
11
|
-
|
|
12
|
-
});
|
|
9
|
+
const result = spawn.sync( tsc, [], {
|
|
10
|
+
stdio: 'inherit',
|
|
11
|
+
} );
|
|
13
12
|
|
|
14
|
-
if (result.status === 0) {
|
|
15
|
-
|
|
13
|
+
if ( result.status === 0 ) {
|
|
14
|
+
utils.log( 'All good!' );
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
process.exit(result.status);
|
|
17
|
+
process.exit( result.status );
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const babelJest = require(
|
|
3
|
+
const babelJest = require( 'babel-jest' ).default;
|
|
4
4
|
|
|
5
|
-
module.exports = babelJest.createTransformer({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
});
|
|
5
|
+
module.exports = babelJest.createTransformer( {
|
|
6
|
+
presets: [
|
|
7
|
+
require.resolve( '@babel/preset-env' ),
|
|
8
|
+
require.resolve( '@babel/preset-typescript' ),
|
|
9
|
+
require.resolve( '@wordpress/babel-preset-default' ),
|
|
10
|
+
],
|
|
11
|
+
babelrc: false,
|
|
12
|
+
configFile: false,
|
|
13
|
+
} );
|
package/scripts/utils/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
const { exec } = require(
|
|
1
|
+
const { exec } = require( 'child_process' );
|
|
2
2
|
|
|
3
|
-
const { version } = require(
|
|
3
|
+
const { version } = require( '../../package.json' );
|
|
4
4
|
|
|
5
|
-
const log = (content, type) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const log = ( content, type ) => {
|
|
6
|
+
console.log(
|
|
7
|
+
`[newspack-scripts@${ version }]${ type ? `[${ type }]` : '' } ${ content }`
|
|
8
|
+
);
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
const getGitBranch = () =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
new Promise( ( resolve, reject ) => {
|
|
13
|
+
return exec( 'git rev-parse --abbrev-ref HEAD', ( err, stdout ) => {
|
|
14
|
+
if ( err ) {
|
|
15
|
+
reject( `getGitBranch Error: ${ err }` );
|
|
16
|
+
} else if ( typeof stdout === 'string' ) {
|
|
17
|
+
resolve( stdout.trim() );
|
|
18
|
+
}
|
|
19
|
+
} );
|
|
20
|
+
} );
|
|
21
21
|
|
|
22
22
|
module.exports = {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
log,
|
|
24
|
+
getGitBranch,
|
|
25
25
|
};
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
2
|
|
|
3
3
|
// matchMedia does not exist in JSDOM, see https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
|
|
4
|
-
Object.defineProperty(window,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
});
|
|
4
|
+
Object.defineProperty( window, 'matchMedia', {
|
|
5
|
+
writable: true,
|
|
6
|
+
value: jest.fn().mockImplementation( ( query ) => ( {
|
|
7
|
+
matches: false,
|
|
8
|
+
media: query,
|
|
9
|
+
onchange: null,
|
|
10
|
+
addListener: jest.fn(), // deprecated
|
|
11
|
+
removeListener: jest.fn(), // deprecated
|
|
12
|
+
addEventListener: jest.fn(),
|
|
13
|
+
removeEventListener: jest.fn(),
|
|
14
|
+
dispatchEvent: jest.fn(),
|
|
15
|
+
} ) ),
|
|
16
|
+
} );
|
|
17
17
|
|
|
18
18
|
// IntersectionObserver does not exist in JSDOM.
|
|
19
19
|
// https://stackoverflow.com/a/58651649/3772847
|
|
20
20
|
class MockIntersectionObserver {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
constructor( fn ) {
|
|
22
|
+
this.root = null;
|
|
23
|
+
this.rootMargin = '';
|
|
24
|
+
this.thresholds = [];
|
|
25
|
+
this.disconnect = () => null;
|
|
26
|
+
this.observe = () => null;
|
|
27
|
+
this.takeRecords = () => [];
|
|
28
|
+
this.unobserve = () => null;
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
// Pass a single entry, which is intersecting.
|
|
31
|
+
fn( [ { isIntersecting: true } ] );
|
|
32
|
+
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
Object.defineProperty(window,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
35
|
+
Object.defineProperty( window, 'IntersectionObserver', {
|
|
36
|
+
writable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
value: MockIntersectionObserver,
|
|
39
|
+
} );
|
|
40
40
|
|
|
41
|
-
Object.defineProperty(global,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
41
|
+
Object.defineProperty( global, 'IntersectionObserver', {
|
|
42
|
+
writable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
value: MockIntersectionObserver,
|
|
45
|
+
} );
|
package/scripts/utils/modules.js
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
|
-
const fs = require(
|
|
1
|
+
const fs = require( 'fs' );
|
|
2
|
+
|
|
3
|
+
const rootDirectory = fs.realpathSync( process.cwd() );
|
|
2
4
|
|
|
3
5
|
module.exports = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
rootDirectory,
|
|
7
|
+
// Get webpack bundle args for `build` and `start` commands.
|
|
8
|
+
buildArgs: ( cmd, args = [] ) => {
|
|
9
|
+
if ( 'build' !== cmd && 'start' !== cmd ) {
|
|
10
|
+
return [ cmd, ...args ];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const defaults = [
|
|
14
|
+
'--config',
|
|
15
|
+
'webpack.config.js',
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
// Default build path: ./dist
|
|
19
|
+
if ( ! args.includes( '--output-path' ) ) {
|
|
20
|
+
defaults.push( '--output-path', 'dist' );
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return [ cmd, ...defaults, ...args ];
|
|
24
|
+
},
|
|
6
25
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const spawn = require( 'cross-spawn' );
|
|
4
|
+
const modules = require( './utils/modules' );
|
|
5
|
+
const utils = require( './utils/index.js' );
|
|
6
|
+
const wpScripts = require.resolve( '@wordpress/scripts/bin/wp-scripts' );
|
|
7
|
+
|
|
8
|
+
const args = process.argv.slice( 2 );
|
|
9
|
+
const cmd = args.shift();
|
|
10
|
+
|
|
11
|
+
utils.log( `Running ${ cmd }...` );
|
|
12
|
+
|
|
13
|
+
const result = spawn.sync( wpScripts, modules.buildArgs( cmd, args ), {
|
|
14
|
+
cwd: modules.rootDirectory,
|
|
15
|
+
stdio: 'inherit',
|
|
16
|
+
env: { ...process.env, NODE_ENV: 'build' === cmd ? 'production' : 'development' },
|
|
17
|
+
} );
|
|
18
|
+
|
|
19
|
+
if ( result.status === 0 ) {
|
|
20
|
+
utils.log( `${ cmd } complete!` );
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
process.exit( result.status );
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
description: >
|
|
2
|
-
Lint the JS & SCSS files.
|
|
2
|
+
Lint the JS & SCSS (temporarily skipped) files.
|
|
3
3
|
|
|
4
4
|
executor: default
|
|
5
5
|
|
|
@@ -8,4 +8,4 @@ steps:
|
|
|
8
8
|
- set_node_version
|
|
9
9
|
- run:
|
|
10
10
|
name: Run Linter
|
|
11
|
-
command: npm run lint
|
|
11
|
+
command: npm run lint:js # Temporarily skip linting SCSS due to stylelint config updates. Remove :js when ready to re-enable linting of SCSS.
|
package/scripts/build.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const spawn = require("cross-spawn");
|
|
4
|
-
const modules = require("./utils/modules");
|
|
5
|
-
const utils = require("./utils/index.js");
|
|
6
|
-
|
|
7
|
-
utils.log("Starting to build…");
|
|
8
|
-
|
|
9
|
-
const buildResult = spawn.sync(process.execPath, [modules.calypsoBuild], {
|
|
10
|
-
cwd: modules.rootDirectory,
|
|
11
|
-
stdio: "inherit",
|
|
12
|
-
env: { ...process.env, NODE_ENV: "production" },
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
if (buildResult.status === 0) {
|
|
16
|
-
utils.log("Build succeeded!");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
process.exit(buildResult.status);
|
package/scripts/watch.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const spawn = require("cross-spawn");
|
|
4
|
-
const modules = require("./utils/modules");
|
|
5
|
-
const utils = require("./utils/index.js");
|
|
6
|
-
|
|
7
|
-
utils.log("Starting to watch…");
|
|
8
|
-
|
|
9
|
-
spawn.sync(process.execPath, [modules.calypsoBuild, "--watch"], {
|
|
10
|
-
cwd: modules.rootDirectory,
|
|
11
|
-
stdio: "inherit",
|
|
12
|
-
env: { ...process.env, NODE_ENV: "development" },
|
|
13
|
-
});
|