Permalink
Browse files

nodeify (#24)

  • Loading branch information...
1 parent d6a221c commit c46e63c3488384d737c29e92a13093aa93700b89 @SamVerschueren SamVerschueren committed with May 30, 2016
Showing with 125 additions and 34 deletions.
  1. +12 −0 .editorconfig
  2. +4 −0 .travis.yml
  3. +20 −0 cli.js
  4. +51 −0 index.js
  5. +0 −25 np.sh
  6. +19 −4 package.json
  7. +10 −5 readme.md
  8. +9 −0 test.js
View
@@ -0,0 +1,12 @@
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[{package.json,*.yml}]
+indent_style = space
+indent_size = 2
View
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - '6'
+ - '4'
View
@@ -0,0 +1,20 @@
+#!/usr/bin/env node
+'use strict';
+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.error(` ${logSymbols.error} ${err.message}`);
+ process.exit(1);
+}
View
@@ -0,0 +1,51 @@
+'use strict';
+const semver = require('semver');
+const execa = require('execa');
+const del = require('del');
+
+const exec = (cmd, args) => {
+ // TODO Switch to `{stdio: 'inherit'}` instead of manual logging when a new execa version is released
+ const result = execa.sync(cmd, args);
+
+ if (result.stdout) {
+ console.log(result.stdout);
+ }
+
+ if (result.stderr) {
+ console.error(result.stderr);
+ }
+
+ if (result.status !== 0) {
+ throw new Error(`Exitted with status ${result.status}.`);
+ }
+};
+
+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.');
+ }
+
+ execa.sync('git', ['fetch']);
+
+ if (execa.sync('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']).stdout !== '0') {
+ throw new Error('Remote history differ. Please pull changes.');
+ }
+
+ del.sync('node_modules');
+
+ exec('npm', ['install']);
+ exec('npm', ['test']);
+ exec('npm', ['version', input]);
+ exec('npm', ['publish']);
+ exec('git', ['push', '--follow-tags']);
+};
View
@@ -1,25 +0,0 @@
-#!/usr/bin/env sh
-
-if test -n "$(git status --porcelain)"; then
- echo 'Unclean working tree. Commit or stash changes first.' >&2;
- exit 128;
-fi
-
-if ! git fetch --quiet 2>/dev/null; then
- echo 'There was a problem fetching your branch.' >&2;
- exit 128;
-fi
-
-if test "0" != "$(git rev-list --count --left-only @'{u}'...HEAD)"; then
- echo 'Remote history differ. Please pull changes.' >&2;
- exit 128;
-fi
-
-trashCli=$(node -e "var path = require('path');console.log(path.join(path.dirname(require('fs').realpathSync('$0')), 'node_modules/.bin/trash'))");
-
-node "$trashCli" node_modules &&
-npm install &&
-npm test &&
-npm version ${1:-patch} &&
-npm publish &&
-git push --follow-tags
View
@@ -9,12 +9,16 @@
"email": "[email protected]",
"url": "sindresorhus.com"
},
- "bin": "np.sh",
+ "bin": "cli.js",
"engines": {
- "node": ">=0.10.0"
+ "node": ">=4"
+ },
+ "scripts": {
+ "test": "xo && ava"
},
"files": [
- "np.sh"
+ "index.js",
+ "cli.js"
],
"keywords": [
"cli-app",
@@ -28,6 +32,17 @@
"commit"
],
"dependencies": {
- "trash-cli": "^1.0.0"
+ "del": "^2.2.0",
+ "execa": "^0.4.0",
+ "log-symbols": "^1.0.2",
+ "meow": "^3.7.0",
+ "semver": "^5.1.0"
+ },
+ "devDependencies": {
+ "ava": "*",
+ "xo": "*"
+ },
+ "xo": {
+ "esnext": true
}
}
View
@@ -1,4 +1,4 @@
-# np
+# np [![Build Status](https://travis-ci.org/sindresorhus/np.svg?branch=master)](https://travis-ci.org/sindresorhus/np)
> A better `npm publish`
@@ -22,12 +22,17 @@ $ npm install --global np
## Usage
-```sh
-np [patch | minor | major | <version>]
-# `patch` is default
+```
+$ np --help
+
+ Usage
+ $ np [patch | minor | major | <version>] (Default: patch)
+
+ Example
+ $ np patch
```
## License
-MIT © [Sindre Sorhus](http://sindresorhus.com)
+MIT © [Sindre Sorhus](https://sindresorhus.com)
View
@@ -0,0 +1,9 @@
+import test from 'ava';
+import m from './';
+
+const np = input => m.bind(m, input);
+
+test('wrong input', t => {
+ t.throws(np('foo'), 'Version should be either path, minor, major, or a valid semver version.');
+ t.throws(np('4.x.3'), 'Version should be either path, minor, major, or a valid semver version.');
+});

0 comments on commit c46e63c

Please sign in to comment.