diff --git a/readme.md b/readme.md index 0cb0d4d2..53830ad0 100644 --- a/readme.md +++ b/readme.md @@ -7,7 +7,7 @@ ## Why - [Interactive UI](#interactive-ui) -- Ensures you are publishing from the `master` branch +- Ensures you are publishing from your release branch (`master` by default) - Ensures the working directory is clean and that there are no unpulled changes - Reinstalls dependencies to ensure your project works with the latest dependency tree - Ensures your Node.js and npm versions are supported by the project and its dependencies @@ -51,6 +51,7 @@ $ np --help Options --any-branch Allow publishing from any branch + --branch Name of the release branch (default: `master`) --no-cleanup Skips cleanup of node_modules --no-tests Skips tests --yolo Skips cleanup and testing @@ -82,6 +83,7 @@ Run `np` without arguments to launch the interactive UI that guides you through Currently, these are the flags you can configure: - `anyBranch` - Allow publishing from any branch (`false` by default). +- `branch` - Name of the release branch (`master` by default). - `cleanup` - Cleanup `node_modules` (`true` by default). - `tests` - Run `npm test` (`true` by default). - `yolo` - Skip cleanup and testing (`false` by default). @@ -95,6 +97,7 @@ Currently, these are the flags you can configure: For example, this configures `np` to never use Yarn and to use `dist` as the subdirectory to publish: `package.json` + ```json { "name": "superb-package", @@ -106,6 +109,7 @@ For example, this configures `np` to never use Yarn and to use `dist` as the sub ``` `.np-config.json` + ```json { "yarn": false, @@ -114,10 +118,11 @@ For example, this configures `np` to never use Yarn and to use `dist` as the sub ``` `.np-config.js` + ```js module.exports = { yarn: false, - contents: 'dist' + contents: "dist" }; ``` diff --git a/source/cli.js b/source/cli.js index 5ebb2f3b..f2939ce2 100755 --- a/source/cli.js +++ b/source/cli.js @@ -22,6 +22,7 @@ const cli = meow(` Options --any-branch Allow publishing from any branch + --branch Name of the release branch (default: master) --no-cleanup Skips cleanup of node_modules --no-tests Skips tests --yolo Skips cleanup and testing @@ -44,6 +45,9 @@ const cli = meow(` anyBranch: { type: 'boolean' }, + branch: { + type: 'string', + }, cleanup: { type: 'boolean' }, diff --git a/source/git-tasks.js b/source/git-tasks.js index 7397c36c..8f7376f6 100644 --- a/source/git-tasks.js +++ b/source/git-tasks.js @@ -6,7 +6,7 @@ module.exports = options => { const tasks = [ { title: 'Check current branch', - task: () => git.verifyCurrentBranchIsMaster() + task: () => git.verifyCurrentBranchIsReleaseBranch(options.branch) }, { title: 'Check local working tree', diff --git a/source/git-util.js b/source/git-util.js index e59b0570..c5118845 100644 --- a/source/git-util.js +++ b/source/git-util.js @@ -38,9 +38,9 @@ exports.currentBranch = async () => { return stdout; }; -exports.verifyCurrentBranchIsMaster = async () => { - if (await exports.currentBranch() !== 'master') { - throw new Error('Not on `master` branch. Use --any-branch to publish anyway.'); +exports.verifyCurrentBranchIsReleaseBranch = async (releaseBranch = 'master') => { + if (await exports.currentBranch() !== releaseBranch) { + throw new Error(`Not on \`${releaseBranch}\` branch. Use --any-branch to publish anyway, or set a different release branch using --branch.`); } }; diff --git a/test/git-tasks.js b/test/git-tasks.js index 0598262c..6153af35 100644 --- a/test/git-tasks.js +++ b/test/git-tasks.js @@ -24,7 +24,7 @@ test.beforeEach(() => { execaStub.resetStub(); }); -test.serial('should fail when current branch not master and publishing from any branch not permitted', async t => { +test.serial('should fail when current branch is not the specified release branch and publishing from any branch not permitted', async t => { execaStub.createStub([ { command: 'git symbolic-ref --short HEAD', @@ -32,8 +32,8 @@ test.serial('should fail when current branch not master and publishing from any stdout: 'feature' } ]); - await t.throwsAsync(run(testedModule({})), - {message: 'Not on `master` branch. Use --any-branch to publish anyway.'}); + await t.throwsAsync(run(testedModule({branch: 'main'})), + {message: 'Not on `main` branch. Use --any-branch to publish anyway, or set a different release branch using --branch.'}); t.true(SilentRenderer.tasks.some(task => task.title === 'Check current branch' && task.hasFailed())); });