Permalink
Browse files

follow-up to #97

  • Loading branch information...
1 parent df32774 commit 53a77863be7c1403be8b62ff9c3e2e49f40fe964 @sindresorhus committed Nov 4, 2016
Showing with 24 additions and 12 deletions.
  1. +1 −0 .gitattributes
  2. +4 −2 cli.js
  3. +1 −0 lib/prerequisite.js
  4. +6 −7 lib/ui.js
  5. +4 −3 lib/version.js
  6. +8 −0 readme.md
  7. BIN screenshot-ui.png
View
@@ -1 +1,2 @@
* text=auto
+*.js text eol=lf
View
@@ -31,23 +31,25 @@ updateNotifier({pkg: cli.pkg}).notify();
Promise
.resolve()
.then(() => {
- if (cli.input.length !== 0) {
+ if (cli.input.length > 0) {
return Object.assign({}, cli.flags, {
confirm: true,
version: cli.input[0]
});
}
+
return ui(cli.flags);
})
.then(options => {
if (!options.confirm) {
process.exit(0);
}
+
return options;
})
.then(options => np(options.version, options))
.then(pkg => {
- console.log(`\n ${pkg.name} ${pkg.version} published`);
+ console.log(`\n ${pkg.name} ${pkg.version} published 🎉`);
})
.catch(err => {
console.error(`\n${err.message}`);
View
@@ -5,6 +5,7 @@ const version = require('./version');
module.exports = (input, pkg, opts) => {
let newVersion = null;
+
const tasks = [
{
title: 'Validate version',
View
@@ -9,9 +9,7 @@ module.exports = options => {
const pkg = readPkgUp.sync().pkg;
const oldVersion = pkg.version;
- console.log('\n');
- console.log(`Releasing a new version of ${chalk.bold(pkg.name)} ${chalk.gray.dim(`(current version: ${oldVersion})`)}`);
- console.log('\n');
+ console.log(`\nPublish a new version of ${chalk.bold.magenta(pkg.name)} ${chalk.dim(`(${oldVersion})`)}\n`);
const prompts = [
{
@@ -40,10 +38,11 @@ module.exports = options => {
filter: input => version.isValidVersionInput(input) ? version.getNewVersion(pkg.version, input) : input,
validate: input => {
if (!version.isValidVersionInput(input)) {
- return 'Please specify a valid semver, e.g. 1.2.3. See http://semver.org';
+ return 'Please specify a valid semver, for example, `1.2.3`. See http://semver.org';
} else if (!version.isVersionGreater(oldVersion, input)) {
return `Version must be greater than ${oldVersion}`;
}
+
return true;
}
},
@@ -79,9 +78,9 @@ module.exports = options => {
when: answers => !pkg.private && version.isPrereleaseVersion(answers.version) && !options.tag && !answers.tag,
validate: input => {
if (input.length === 0) {
- return 'Please specify a tag, e.g. next.';
+ return 'Please specify a tag, for example, `next`.';
} else if (input.toLowerCase() === 'latest') {
- return 'It\'s not possible to publish pre-releases under the latest tag. Please specifiy something else, e.g. next.';
+ return 'It\'s not possible to publish pre-releases under the `latest` tag. Please specify something else, for example, `next`.';
}
return true;
}
@@ -93,7 +92,7 @@ module.exports = options => {
const tag = answers.tag || options.tag;
const tagPart = tag ? ` and tag this release in npm as ${tag}` : '';
- return `Will bump from ${oldVersion} to ${answers.version}${tagPart}. Continue?`;
+ return `Will bump from ${chalk.cyan(oldVersion)} to ${chalk.cyan(answers.version + tagPart)}. Continue?`;
}
}
];
View
@@ -4,9 +4,7 @@ const semver = require('semver');
exports.SEMVER_INCREMENTS = ['patch', 'minor', 'major', 'prepatch', 'preminor', 'premajor', 'prerelease'];
exports.PRERELEASE_VERSIONS = ['prepatch', 'preminor', 'premajor', 'prerelease'];
-function isValidVersion(input) {
- return Boolean(semver.valid(input));
-}
+const isValidVersion = input => Boolean(semver.valid(input));
exports.isValidVersionInput = input => exports.SEMVER_INCREMENTS.indexOf(input) !== -1 || isValidVersion(input);
@@ -16,20 +14,23 @@ exports.getNewVersion = (oldVersion, input) => {
if (!exports.isValidVersionInput(input)) {
throw new Error(`Version should be either ${exports.SEMVER_INCREMENTS.join(', ')} or a valid semver version.`);
}
+
return exports.SEMVER_INCREMENTS.indexOf(input) === -1 ? input : semver.inc(oldVersion, input);
};
exports.isVersionGreater = (oldVersion, newVersion) => {
if (!isValidVersion(newVersion)) {
throw new Error('Version should be a valid semver version.');
}
+
return semver.gt(newVersion, oldVersion);
};
exports.isVersionLower = (oldVersion, newVersion) => {
if (!isValidVersion(newVersion)) {
throw new Error('Version should be a valid semver version.');
}
+
return semver.lt(newVersion, oldVersion);
};
View
@@ -7,6 +7,7 @@
## Why
+- [Interative UI](#interactive-ui)
- Ensures you are publishing from the `master` branch
- 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
@@ -49,6 +50,13 @@ $ np --help
```
+## Interactive UI
+
+Run `np` without arguments to launch the interactive UI that guides you through publishing a new version.
+
+<img src="screenshot-ui.png" width="1290">
+
+
## Tips
### npm hooks
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 53a7786

Please sign in to comment.