nodeify #24
| + | ||
| +var exec = function (cmd, args) { | ||
| + const result = execa.sync(cmd, args); | ||
| + | ||
| + if (result.stderr !== '') { | ||
| + throw new Error(result.stderr); | ||
| + } | ||
| + | ||
| + return result.stdout; | ||
| +}; | ||
| + | ||
| +module.exports = function (input) { | ||
| + input = input || 'patch'; | ||
| + | ||
| + if (['patch', 'minor', 'major'].indexOf(input) === -1 && !semver.valid(input)) { | ||
| + throw new Error('Invalid version.'); |
|
SamVerschueren
Error message can be better. Might be something like
sindresorhus
|
|
Nice! I added you to https://www.npmjs.com/package/sindre-playground. Just use the package for manual testing. |
| @@ -0,0 +1,19 @@ | ||
| +#!/usr/bin/env node | ||
| +'use strict'; | ||
| +var meow = require('meow'); | ||
| +var logSymbols = require('log-symbols'); | ||
| +var np = require('./'); | ||
| + | ||
| +var cli = meow(` | ||
| + Usage | ||
| + $ np [patch | minor | major | <version>] |
|
SamVerschueren
Somehow we should inform the user that
sindresorhus
Yup. Don't know if there's any syntax convention for default values though. Might just write it in text below.
SamVerschueren
or
|
| @@ -0,0 +1,42 @@ | ||
| +'use strict'; | ||
| +var semver = require('semver'); | ||
| +var execa = require('execa'); | ||
| +var del = require('del'); | ||
| + | ||
| +var exec = function (cmd, args) { | ||
| + const result = execa.sync(cmd, args); | ||
| + | ||
| + if (result.stderr !== '') { |
|
SamVerschueren
I thought that if
sindresorhus
Nah,
sindresorhus
Instead just log both stdout and stderr in this method. The
SamVerschueren
It's used in the if (exec('git', ['status', '--porcelain']) !== '') {So just do something like this and print all the output? const exec = (cmd, args) => {
const {stdout, stderr} = execa.sync(cmd, args);
console.log(stdout);
console.log(stderr);
return stdout;
};
SamVerschueren
Going to drop using it in the
SamVerschueren
Should I only log if
sindresorhus
Actually, might be better to just pass
SamVerschueren
It's probably passed somewhere down the chain. If I pass in
sindresorhus
Alright. Just use console.log/err then. Do you get the error even with the latest master of
kevva
I think it is supported in
SamVerschueren
Is it possible to do a new
sindresorhus
Just use console.log/err for now, but add a TODO comment about switching when next execa version is out. I don't think we're ready to do a release there just yet. |
| +module.exports = input => { | ||
| + input = input || 'patch'; | ||
| + | ||
| + if (['patch', 'minor', 'major'].indexOf(input) === -1 && !semver.valid(input)) { | ||
| + throw new Error('Version should be either path, minor, major, or a valid semver version.'); | ||
| + } | ||
| + | ||
| + if (semver.gte(process.version, '6.0.0')) { | ||
| + throw new Error('You should not publish when running Node.js 6. Please downgrade and publish again. https://github.com/npm/npm/issues/5082'); | ||
| + } | ||
| + | ||
| + if (execa.sync('git', ['status', '--porcelain']).stdout !== '') { | ||
| + throw new Error('Unclean working tree. Commit or stash changes first.'); | ||
| + } | ||
| + | ||
| + if (execa.sync('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']).stdout !== '0') { |
|
SamVerschueren
Does this actually work? I updated
SamVerschueren
Tested it with running |
|
I processed the feedback. The only thing is that at the moment if |
|
Tested it for quite some scenarios. Released a package today with the new version and all seems to work quite fine. |
|
Maybe you can take a look to this https://github.com/MoOx/npmpub/blob/master/npmpub.js |
| +const meow = require('meow'); | ||
| +const logSymbols = require('log-symbols'); | ||
| +const np = require('./'); | ||
| + | ||
| +const cli = meow(` | ||
| + Usage | ||
| + $ np [patch | minor | major | <version>] (Default: patch) | ||
| + | ||
| + Example | ||
| + $ np patch | ||
| +`); | ||
| + | ||
| +try { | ||
| + np(cli.input[0]); | ||
| +} catch (err) { | ||
| + console.log(` ${logSymbols.error} ${err.message}`); |
|
SamVerschueren
Should we call |



Rewrote the module with Node. Any feedback is welcome. It's untested at the moment as I don't have a module at this time that should be released.
Should we drop 0.12 and 0.10?
Can you enable travis for this module?