Skip to content

Commit

Permalink
Add --no-publish flag (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
moeriki authored and sindresorhus committed Dec 13, 2016
1 parent 82e33a5 commit ca0f193
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const cli = meow(`
--any-branch Allow publishing from any branch
--no-cleanup Skips cleanup of node_modules
--yolo Skips cleanup and testing
--no-publish Skips publishing
--tag Publish under a given dist-tag
Examples
Expand Down
32 changes: 18 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module.exports = (input, opts) => {
input = input || 'patch';

opts = Object.assign({
cleanup: true
cleanup: true,
publish: true
}, opts);

// TODO: remove sometime far in the future
Expand All @@ -35,6 +36,7 @@ module.exports = (input, opts) => {

const runTests = !opts.yolo;
const runCleanup = opts.cleanup && !opts.yolo;
const runPublish = opts.publish;
const pkg = util.readPkg();

const tasks = new Listr([
Expand Down Expand Up @@ -70,26 +72,28 @@ module.exports = (input, opts) => {
});
}

tasks.add([
{
title: 'Bumping version',
// Specify --force flag to proceed even if the working directory is dirty as np already does a dirty check anyway
task: () => exec('npm', ['version', input, '--force'])
},
{
tasks.add({
title: 'Bumping version',
// Specify --force flag to proceed even if the working directory is dirty as np already does a dirty check anyway
task: () => exec('npm', ['version', input, '--force'])
});

if (runPublish) {
tasks.add({
title: 'Publishing package',
skip: () => {
if (pkg.private) {
return 'Private package: not publishing to npm.';
}
},
task: () => exec('npm', ['publish'].concat(opts.tag ? ['--tag', opts.tag] : []))
},
{
title: 'Pushing tags',
task: () => exec('git', ['push', '--follow-tags'])
}
]);
});
}

tasks.add({
title: 'Pushing tags',
task: () => exec('git', ['push', '--follow-tags'])
});

return tasks.run()
.then(() => readPkgUp())
Expand Down
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ $ np --help
--any-branch Allow publishing from any branch
--no-cleanup Skips cleanup of node_modules
--yolo Skips cleanup and testing
--no-publish Skips publishing
--tag Publish under a given dist-tag
Examples
Expand Down Expand Up @@ -111,6 +112,10 @@ Set the [`registry` option](https://docs.npmjs.com/misc/config#registry) in pack
}
```

### Publish with a CI

If you use a Continuous Integration server to publish your tagged commits, use the `--no-publish` flag to skip the publishing step of `np`.

### Initial version

For new packages, start the `version` field in package.json at `0.0.0` and let `np` bump it to `1.0.0` or `0.1.0` when publishing.
Expand Down

0 comments on commit ca0f193

Please sign in to comment.