Scripts for Newspack, heavily inspired by react-scripts
.
Will run jest
tests. Useful flags:
--watch
to run in file watch mode,--coverage
to collect test coverage
Will run calypso-build
, creating optimised production builds.
Will run calypso-build
in watch mode.
Uses commitizen
to create a structured commit message.
Lints to commit message, to be used in a git commit-msg
hook.
Will run semantic-release
based on a very opinionated configuration.
Will validate TypeScript code in the project. This requires a tsconfig.json
file to be placed in the project root. Example:
{
"extends": "newspack-scripts/config/tsconfig.json",
"compilerOptions": {
"rootDir": "src"
},
"include": ["src"]
}
This package contains a configuration of semantic-release
, which can be used for automated software releases, published on Github. It's configured to work with the following repository branch setup:
master
– ongoing developmentalpha
– release candidaterelease
– the production-ready, released code
The following assumes that CI will run:
npm run release
forrelease
,alpha
, andhotfix/*
branchespost-release.sh
script onrelease
branch, after the above command completes
- Commit ongoing changes to
master
branch, using structured commit messages - Merge
master
intoalpha
to create a release candidate (e.g.1.2.0-alpha.1
) - Merge
alpha
intorelease
to create a release (e.g.1.2.0
) alpha
branch will be reset on top ofrelease
master
branch will be updated with the changes from therelease
branch
- Create a new
hotfix/*
branch off therelease
branch - Push the branch to Github, so the CI can process it – don't create a PR just yet!*
- A new "hotfix" pre-release (e.g.
1.2.0-hotfix.1
) will be published - Merge the hotfix branch into
release
to create a release alpha
&master
branches will be updated with the changes from therelease
branch
* semantic-release
will not release if the CI job was triggered by a PR
This package exposes a couple of configuration files.
The webpack.config.js
file should use this package's config-extending function:
const getBaseWebpackConfig = require( 'newspack-scripts/config/getWebpackConfig' );
const webpackConfig = getBaseWebpackConfig(
{ WP: true },
{
entry: {
'some-script': './src/some-script.js'
},
}
);
module.exports = webpackConfig;
A basic babel.config.js
:
module.exports = api => {
api.cache( true );
return {
extends: 'newspack-scripts/config/babel.config.js',
};
};
Because of eslint's issue with resolving dependencies of extended configurations, a patch has to be used to use this config in a stand-alone fashion: install @rushstack/eslint-patch
and set up the .eslintrc.js
like so:
require( '@rushstack/eslint-patch/modern-module-resolution' );
module.exports = {
extends: [ './node_modules/newspack-scripts/config/eslintrc.js' ],
// Additional options…
};
Install stylelint
via npm and reference this package's config file when running it, e.g.:
stylelint '**/*.scss' --syntax scss --config=./node_modules/newspack-scripts/config/stylelint.config.js
Note: Due to issue with dependency resolving, you might end up a different version of prettier
in project's node_modules
and node_modules/newspack-scripts/node_modules
. See Automattic#1 for more information.
See note about typescript-check
script above.
This repository hosts a CircleCI Orb, in /src
directory. An Orb is a re-usable configuration – here's an example of how to use it:
version: 2.1
orbs:
newspack: adekbadek/[email protected]
workflows:
version: 2
all:
jobs:
- newspack/build
To update the Orb, use CircleCI's CLI's pack
and publish
commands:
# Replace the `version` at the end (e.g. 1.0.1)
circleci orb pack src/ > orb.yml && circleci orb publish orb.yml adekbadek/newspack@version
This project list @wordpress/*
packages as dependencies in order to provide them to consumers. In a project using calypso-build
(e.g. a consumer of newspack-scripts
), the @wordpress/*
packages are sourced from WP Core, not node_modules
. The packages should be included in node_modules
, though, to be available in other environments – notably when running tests. See Dependency Extraction Webpack Plugin for more information.