Skip to content

Commit 53a7786

Browse files
committed
follow-up to sindresorhus#97
1 parent df32774 commit 53a7786

7 files changed

Lines changed: 24 additions & 12 deletions

File tree

‎.gitattributes‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
* text=auto
2+
*.js text eol=lf

‎cli.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,25 @@ updateNotifier({pkg: cli.pkg}).notify();
3131
Promise
3232
.resolve()
3333
.then(() => {
34-
if (cli.input.length !== 0) {
34+
if (cli.input.length > 0) {
3535
return Object.assign({}, cli.flags, {
3636
confirm: true,
3737
version: cli.input[0]
3838
});
3939
}
40+
4041
return ui(cli.flags);
4142
})
4243
.then(options => {
4344
if (!options.confirm) {
4445
process.exit(0);
4546
}
47+
4648
return options;
4749
})
4850
.then(options => np(options.version, options))
4951
.then(pkg => {
50-
console.log(`\n ${pkg.name} ${pkg.version} published`);
52+
console.log(`\n ${pkg.name} ${pkg.version} published 🎉`);
5153
})
5254
.catch(err => {
5355
console.error(`\n${err.message}`);

‎lib/prerequisite.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const version = require('./version');
55

66
module.exports = (input, pkg, opts) => {
77
let newVersion = null;
8+
89
const tasks = [
910
{
1011
title: 'Validate version',

‎lib/ui.js‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ module.exports = options => {
99
const pkg = readPkgUp.sync().pkg;
1010
const oldVersion = pkg.version;
1111

12-
console.log('\n');
13-
console.log(`Releasing a new version of ${chalk.bold(pkg.name)} ${chalk.gray.dim(`(current version: ${oldVersion})`)}`);
14-
console.log('\n');
12+
console.log(`\nPublish a new version of ${chalk.bold.magenta(pkg.name)} ${chalk.dim(`(${oldVersion})`)}\n`);
1513

1614
const prompts = [
1715
{
@@ -40,10 +38,11 @@ module.exports = options => {
4038
filter: input => version.isValidVersionInput(input) ? version.getNewVersion(pkg.version, input) : input,
4139
validate: input => {
4240
if (!version.isValidVersionInput(input)) {
43-
return 'Please specify a valid semver, e.g. 1.2.3. See http://semver.org';
41+
return 'Please specify a valid semver, for example, `1.2.3`. See http://semver.org';
4442
} else if (!version.isVersionGreater(oldVersion, input)) {
4543
return `Version must be greater than ${oldVersion}`;
4644
}
45+
4746
return true;
4847
}
4948
},
@@ -79,9 +78,9 @@ module.exports = options => {
7978
when: answers => !pkg.private && version.isPrereleaseVersion(answers.version) && !options.tag && !answers.tag,
8079
validate: input => {
8180
if (input.length === 0) {
82-
return 'Please specify a tag, e.g. next.';
81+
return 'Please specify a tag, for example, `next`.';
8382
} else if (input.toLowerCase() === 'latest') {
84-
return 'It\'s not possible to publish pre-releases under the latest tag. Please specifiy something else, e.g. next.';
83+
return 'It\'s not possible to publish pre-releases under the `latest` tag. Please specify something else, for example, `next`.';
8584
}
8685
return true;
8786
}
@@ -93,7 +92,7 @@ module.exports = options => {
9392
const tag = answers.tag || options.tag;
9493
const tagPart = tag ? ` and tag this release in npm as ${tag}` : '';
9594

96-
return `Will bump from ${oldVersion} to ${answers.version}${tagPart}. Continue?`;
95+
return `Will bump from ${chalk.cyan(oldVersion)} to ${chalk.cyan(answers.version + tagPart)}. Continue?`;
9796
}
9897
}
9998
];

‎lib/version.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ const semver = require('semver');
44
exports.SEMVER_INCREMENTS = ['patch', 'minor', 'major', 'prepatch', 'preminor', 'premajor', 'prerelease'];
55
exports.PRERELEASE_VERSIONS = ['prepatch', 'preminor', 'premajor', 'prerelease'];
66

7-
function isValidVersion(input) {
8-
return Boolean(semver.valid(input));
9-
}
7+
const isValidVersion = input => Boolean(semver.valid(input));
108

119
exports.isValidVersionInput = input => exports.SEMVER_INCREMENTS.indexOf(input) !== -1 || isValidVersion(input);
1210

@@ -16,20 +14,23 @@ exports.getNewVersion = (oldVersion, input) => {
1614
if (!exports.isValidVersionInput(input)) {
1715
throw new Error(`Version should be either ${exports.SEMVER_INCREMENTS.join(', ')} or a valid semver version.`);
1816
}
17+
1918
return exports.SEMVER_INCREMENTS.indexOf(input) === -1 ? input : semver.inc(oldVersion, input);
2019
};
2120

2221
exports.isVersionGreater = (oldVersion, newVersion) => {
2322
if (!isValidVersion(newVersion)) {
2423
throw new Error('Version should be a valid semver version.');
2524
}
25+
2626
return semver.gt(newVersion, oldVersion);
2727
};
2828

2929
exports.isVersionLower = (oldVersion, newVersion) => {
3030
if (!isValidVersion(newVersion)) {
3131
throw new Error('Version should be a valid semver version.');
3232
}
33+
3334
return semver.lt(newVersion, oldVersion);
3435
};
3536

‎readme.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
## Why
99

10+
- [Interative UI](#interactive-ui)
1011
- Ensures you are publishing from the `master` branch
1112
- Ensures the working directory is clean and that there are no unpulled changes
1213
- Reinstalls dependencies to ensure your project works with the latest dependency tree
@@ -49,6 +50,13 @@ $ np --help
4950
```
5051

5152

53+
## Interactive UI
54+
55+
Run `np` without arguments to launch the interactive UI that guides you through publishing a new version.
56+
57+
<img src="screenshot-ui.png" width="1290">
58+
59+
5260
## Tips
5361

5462
### npm hooks

‎screenshot-ui.png‎

165 KB
Loading

0 commit comments

Comments
 (0)