Skip to content

Commit

Permalink
REF: migrate to es7ish code
Browse files Browse the repository at this point in the history
  • Loading branch information
royriojas committed Jan 18, 2017
1 parent dd66a13 commit 27f141e
Show file tree
Hide file tree
Showing 17 changed files with 541 additions and 333 deletions.
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": ["es2015", "react", "stage-0"],

"plugins": [
"add-module-exports",
"transform-decorators-legacy"
]
}
1 change: 1 addition & 0 deletions .cache/.cache_15qy1o4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"/Users/roy/royws/shell-executor/source/src/process.js":{"size":26,"mtime":1483338490000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/src/process.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/source/bin/cli.js":{"size":182,"mtime":1484751608000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/bin/cli.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/source/src/options.js":{"size":676,"mtime":1484751608000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/src/options.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/source/time-manager.js":{"size":390,"mtime":1484751608000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/time-manager.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/source/index.js":{"size":2879,"mtime":1484751986000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/index.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/source/src/main.js":{"size":3272,"mtime":1484752318000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/source/src/main.js","messages":[],"errorCount":0,"warningCount":0}},"/Users/roy/royws/shell-executor/specs/index.spec.js":{"size":1072,"mtime":1484752145000,"hashOfConfig":"suduii","results":{"filePath":"/Users/roy/royws/shell-executor/specs/index.spec.js","messages":[],"errorCount":0,"warningCount":0}}}
177 changes: 177 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
module.exports = {
"parser": "babel-eslint",
"plugins": [
"import",
"mocha",
"jsx-a11y",
"react",
],
"extends": ["eslint:recommended", "airbnb"],
"rules": {
"mocha/no-exclusive-tests": 2,
"eqeqeq": [2, "smart"],
"curly": 2,
"quotes": [2, "single", "avoid-escape"],
"strict": 0,
"no-unused-expressions": 0,
"no-underscore-dangle": 0,
"no-unused-vars": [2, { "vars": "all", "args": "after-used" }],
"no-spaced-func" : 0,
"jsx-a11y/anchor-has-content": 0,
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"func-names": 2,
"no-shadow": 2,
"camelcase": 2,
"new-cap": [2, {"capIsNewExceptions": ["Then", "When", "Given", "AfterFeatures", "After", "BeforeFeatures", "Before", "BeforeFeature"]}],
"dot-notation": 2,
"no-native-reassign": 1,
"no-new": 1,
"no-confusing-arrow": [2, {"allowParens": true}],
"no-console": 0,
"no-constant-condition": 1,
"object-curly-spacing": 2,
"consistent-return": 2,
"jsx-quotes": 1,
"newline-per-chained-call": 0,
"no-unneeded-ternary": [2, {"defaultAssignment": true }],
"no-extra-strict": 0,
"no-alert": 2,
"no-array-constructor": 2,
"no-caller": 2,
"no-catch-shadow": 2,
"no-eval": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-implied-eval": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-loop-func": 2,
"no-multi-spaces": 0,
"no-multi-str": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-wrappers": 2,
"no-octal-escape": 2,
"no-process-exit": 2,
"no-proto": 2,
"no-return-assign": 2,
"no-script-url": 2,
"no-sequences": 2,
"no-undef": 2,
"no-shadow-restricted-names": 2,
"no-trailing-spaces": 2,
"quote-props": 2,
"object-shorthand": 2,
"prefer-arrow-callback": 2,
"template-curly-spacing": 0,
"no-undef-init": 2,
"id-length": 0,
"no-use-before-define": 2,
"no-with": 2,
"comma-spacing": 2,
"eol-last": 2,
"padded-blocks": 0,
"no-extra-parens": [2, "functions"],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"new-parens": 2,
"semi": 2,
"semi-spacing": [2, {"before": false, "after": true}],
"space-infix-ops": 2,
"keyword-spacing": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"yoda": [2, "never"],
"indent": 0,
"vars-on-top": 0,
"max-len": 0,
"no-param-reassign": 0,
"arrow-body-style": 2,
"brace-style": 2,
"prefer-template": 2,
"computed-property-spacing": 1,
"space-in-parens": 1,
"no-useless-constructor": 2,
"prefer-rest-params": 2,
"array-bracket-spacing": 1,
"no-case-declarations": 2,
"array-callback-return": 2,
"prefer-const": 2,
"global-require": 2,
"no-useless-escape": 2,
"no-restricted-syntax": 2,
"no-duplicate-imports": [2, { "includeExports": true }],
"import/no-duplicates": [0, { "commonjs": true }],
"import/no-unresolved": [0, { "commonjs": true }],
"import/export": 1,
"jsx-a11y/img-has-alt": 0,
"react/jsx-equals-spacing": [1, "never"],
"react/display-name": 0,
"react/jsx-no-undef": 1,
"react/jsx-no-bind": 2,
"react/jsx-curly-spacing": [2, "always"],
"react/jsx-first-prop-new-line": [2, "never"],
"react/jsx-indent": [0, 2],
"react/jsx-boolean-value": 0,
"react/jsx-sort-prop-types": 0,
"react/jsx-sort-props": 0,
"react/jsx-uses-react": 1,
"react/jsx-uses-vars": 1,
"react/no-did-mount-set-state": 1,
"react/no-did-update-set-state": 1,
"react/jsx-closing-bracket-location": 0,
"react/jsx-space-before-closing": 2,
"react/no-multi-comp": 1,
"react/no-unknown-property": 1,
"react/prop-types": 0,
"react/react-in-jsx-scope": 1,
"react/self-closing-comp": 2,
"react/sort-comp": 0,
"react/wrap-multilines": 0,
"react/jsx-indent-props": 0,
"react/prefer-stateless-function": 1,
"generator-star-spacing": 0,
"import/no-extraneous-dependencies": 0,
"linebreak-style": 2,
"import/imports-first": 0,
"react/no-string-refs": 0,
"react/jsx-filename-extension": 0,
"react/jsx-wrap-multilines": 0,
"no-mixed-operators": 0,
"import/prefer-default-export": 0,
"import/newline-after-import": 0,
"require-yield": 1,
"no-extra-boolean-cast": 2,
"no-continue": 2,
"object-property-newline": 1,
"no-prototype-builtins": 2,
"operator-assignment": 2,
"jsx-a11y/label-has-for": 2,
"react/no-find-dom-node": 2,
"no-lonely-if": 2,
"dot-location": 2,
"import/no-named-as-default": 1,
"prefer-spread": 1
},
"env": {
"browser": true,
"node": true,
"mocha": true,
"es6": true
},
"ecmaFeatures": {
"jsx" : true,
"modules": true
},
"globals": {
"__MOBX_DEVTOOLS__": true,
"__DEVELOPMENT__": true,
"__CLIENT__": true,
"__SERVER__": true,
"__DISABLE_SSR__": true,
"__DEVTOOLS__": true,
"socket": true,
"jest": true,
"expect": true,
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ build/Release
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
.eslintrc
dist/
8 changes: 0 additions & 8 deletions bin/cli.js

This file was deleted.

116 changes: 1 addition & 115 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,115 +1 @@
var spawnly = require( 'spawnly' );
var extend = require( 'extend' );
var dispatchy = require( 'dispatchy' );
var Promise = require( 'es6-promise' ).Promise;

var timeManager = require( './time-manager' );

function streamToString( stream ) {
var chunks = [ ];
return new Promise( function ( resolve, reject ) {
if ( !stream.readable ) {
return resolve( '' );
}
stream.on( 'data', function ( chunk ) {
chunks.push( chunk.toString() );
} );
stream.on( 'end', function () {
resolve( chunks.join( '' ) );
} );
stream.on( 'error', function ( err ) {
reject( err );
} );
} );
}

module.exports = {
create: function () {
var commands = [ ];

return extend( dispatchy.create(), {
runCmds: function ( cmds, options ) {
var me = this;
cmds = cmds || [ ];

var promises = cmds.map( function ( cmd ) {
return me.run( cmd, options );
} );

return Promise.all( promises );
},
run: function ( cmd, options ) {
var me = this;

var opts = extend( { stdio: 'inherit' }, options );

var timer = timeManager.start();

var cp = spawnly( cmd, opts );

me.fire( 'command:start', { cp: cp, cmd: cmd } );

cp.cmd = cmd;
commands.push( cp );

return new Promise( function ( resolve, reject ) {
cp.on( 'exit', function ( exitCode ) {
var res = timer.stop();

var stdoutPromise = Promise.resolve( '' );
var stderrPromise = Promise.resolve( '' );

if ( cp.stdout ) {
stdoutPromise = streamToString( cp.stdout );
}

if ( cp.stderr ) {
stderrPromise = streamToString( cp.stderr );
}

Promise.all( [ stdoutPromise, stderrPromise ] ).then( function ( results ) {
var args = {
cp: cp,
stdout: results[ 0 ],
stderr: results[ 1 ],
cmd: cmd,
exitCode: exitCode,
duration: res.diff,
durationFormatted: res.diffFormatted
};
me.fire( 'command:exit', args );
resolve( args );
} );

} );

cp.on( 'error', function ( err ) {
err = err || { };
var res = timer.stop();
err.duration = res.diff;
err.durationFormatted = res.diffFormatted;
me.fire( 'command:error', err );
reject( err );
} );
} );
},
getKillCommand: function () {
return 'kill -9 ' + commands.map( function ( cmd ) {
return cmd.pid;
} ).join( ' ' );
},
stopAll: function () {
var me = this;
commands.forEach( function ( cp ) {
if ( !cp.exitCode ) {

cp.removeAllListeners( 'exit' );
cp.removeAllListeners( 'error' );
me.fire( 'command:killed', cp );
cp.kill( 'SIGINT' );
}
} );
}
} );
}
};
module.exports = require('./dist/index.js');
45 changes: 30 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
"description": "A small nodejs module to execute shell commands in parallel",
"main": "index.js",
"scripts": {
"beautify": "esbeautifier './index.js' './src/**/*.js' './specs/**/*.js' './bin/**/*.js'",
"beautify-check": "esbeautifier -k './index.js' './src/**/*.js' './specs/**/*.js' './bin/**/*.js'",
"eslint": "eslinter './index.js' './src/**/*.js' './specs/**/*.js' './bin/**/*.js'",
"lint": "npm run beautify && npm run eslint",
"test": "mocha-runner './specs/**/*.js'",
"cover": "istanbul cover -x 'specs/**/*.js' mocha-runner './specs/**/*.js' html text-summary",
"watch": "watch-spawn -i -p './specs/**/*.js' npm run cover",
"check": "npm run beautify-check && npm run eslint",
"verify": "npm run check --silent && npm test --silent",
"autofix": "npm run eslint -- --fix",
"_lint": "eslint --cache --cache-location='.cache/' -f 'node_modules/eslint-friendly-formatter' ",
"eslint": "npm run _lint -- 'source/**/*.js' 'specs/**/*.spec.js' ",
"test": "npm run verify && babel-node node_modules/.bin/mocha-runner 'specs/**/*.spec.js'",
"cover": "istanbul cover -x 'specs/**/*.spec.js' babel-node node_modules/.bin/mocha-runner 'specs/**/*.spec.js' html text-summary",
"watch": "npm run cover && watch-spawn -p 'specs/**/*.spec.js' npm run cover",
"verify": "npm run eslint",
"changelog": "changelogx -f markdown -o ./changelog.md",
"do-changelog": "npm run changelog && git add ./changelog.md && git commit -m 'DOC: Generate changelog'",
"do-changelog": "npm run changelog && git add ./changelog.md && git commit -m 'DOC: Generate changelog' --no-verify",
"install-hooks": "prepush install && changelogx install-hook && precommit install",
"pre-v": "npm run verify",
"pre-v": "npm run test",
"post-v": "npm run do-changelog && git push --no-verify && git push --tags --no-verify",
"bump-major": "npm run pre-v && npm version major -m 'BLD: Release v%s' && npm run post-v",
"bump-minor": "npm run pre-v && npm version minor -m 'BLD: Release v%s' && npm run post-v",
"bump-patch": "npm run pre-v && npm version patch -m 'BLD: Release v%s' && npm run post-v"
"bump-patch": "npm run pre-v && npm version patch -m 'BLD: Release v%s' && npm run post-v",
"prepublish": "npm run build",
"build": "babel source/ -d dist/"
},
"bin": {
"shell-exec": "./bin/cli.js"
"shell-exec": "./dist/bin/cli.js"
},
"repository": {
"type": "git",
Expand All @@ -45,9 +45,22 @@
"onDirtyState": "stash"
},
"devDependencies": {
"babel-cli": "6.18.0",
"babel-eslint": "7.1.1",
"babel-plugin-add-module-exports": "0.2.1",
"babel-plugin-transform-decorators-legacy": "1.3.4",
"babel-polyfill": "6.16.0",
"babel-preset-es2015": "6.18.0",
"babel-preset-react": "6.16.0",
"babel-preset-stage-0": "6.16.0",
"changelogx": "2.0.1",
"esbeautifier": "^4.0.1",
"eslinter": "^2.1.0",
"eslint": "3.13.1",
"eslint-config-airbnb": "14.0.0",
"eslint-friendly-formatter": "2.0.7",
"eslint-plugin-import": "2.2.0",
"eslint-plugin-jsx-a11y": "3.0.2",
"eslint-plugin-mocha": "4.8.0",
"eslint-plugin-react": "6.9.0",
"istanbul": "^0.3.17",
"mocha-runner": "^1.0.8",
"precommit": "1.2.2",
Expand All @@ -56,6 +69,8 @@
"watch-spawn": "2.0.0"
},
"dependencies": {
"blessed": "0.1.81",
"blessed-contrib": "4.7.5",
"clix": "2.2.1",
"dispatchy": "1.0.3",
"es6-promise": "4.0.5",
Expand Down
Loading

0 comments on commit 27f141e

Please sign in to comment.