Skip to content

Commit

Permalink
Chore: Stop a use of ES6 modules. And upgrade eslint.
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed May 6, 2016
1 parent 40554ef commit 2f26fa5
Show file tree
Hide file tree
Showing 53 changed files with 711 additions and 364 deletions.
10 changes: 2 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
{
"root": true,
"extends": ["mysticatea/nodejs"],
"plugins": ["node"],
"extends": ["mysticatea", "mysticatea/node"],
"rules": {
"no-param-reassign": [2, {"props": false}],
"node/no-missing-import": 2,
"node/no-missing-require": 2,
"node/no-unpublished-import": 2,
"node/no-unpublished-require": 2,
"node/shebang": 2
"node/no-unsupported-features": "off"
},
"settings": {
"node": {
Expand Down
8 changes: 0 additions & 8 deletions index.js

This file was deleted.

13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
"run-s": "bin/run-s/index.js",
"npm-run-all": "bin/npm-run-all/index.js"
},
"main": "lib/index.js",
"files": [
"bin",
"lib",
"index.js"
"lib"
],
"scripts": {
"preversion": "npm run build",
"postversion": "git push && git push --tags",
"pretest": "node scripts/make-slink.js",
"clean": "rimraf bin coverage docs lib",
"lint": "eslint src test test-workspace",
"lint": "eslint src test test-workspace/tasks/*",
"build": "babel-node src/bin/run-s/index.js clean lint build:*",
"build:babel": "babel src --out-dir .",
"build:esdoc": "esdoc -c esdoc.json",
Expand Down Expand Up @@ -46,10 +47,8 @@
"coveralls": "^2.11.4",
"esdoc": "^0.4.3",
"esdoc-importpath-plugin": "^0.0.1",
"eslint": "^1.10.3",
"eslint-config-mysticatea": "^1.9.0",
"eslint-plugin-mysticatea": "^1.0.3",
"eslint-plugin-node": "^0.6.0",
"eslint": "^2.9.0",
"eslint-config-mysticatea": "^3.0.0",
"isparta": "^4.0.0",
"mocha": "^2.3.4",
"power-assert": "^1.2.0",
Expand Down
9 changes: 9 additions & 0 deletions scripts/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"root": true,
"extends": ["mysticatea/es5", "mysticatea/node"],
"rules": {
"no-console": 0,
"no-process-env": 0,
"no-process-exit": 0
}
}
22 changes: 22 additions & 0 deletions scripts/make-slink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @author Toru Nagashima
* @copyright 2016 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
"use strict";

var fs = require("fs");
var path = require("path");

try {
fs.symlinkSync(
path.resolve(__dirname, "../test/lib"),
path.resolve(__dirname, "../test-workspace/tasks/lib"),
"junction"
);
}
catch (err) {
if (err.code !== "EEXIST") {
throw err;
}
}
77 changes: 77 additions & 0 deletions src/bin/common/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* @author Toru Nagashima
* @copyright 2016 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
"use strict";

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

/**
* Define the function for main process.
*
* @param {string} name - A program name.
* @returns {function} The function for main process.
*/
function defineMain(name) {
/**
* The main process of `npm-run-all` command.
*
* @param {string[]} args - Arguments to parse.
* @param {stream.Writable} stdout - A writable stream to print logs.
* @param {stream.Writable} stderr - A writable stream to print errors.
* @returns {Promise} A promise which comes to be fulfilled when all
* npm-scripts are completed.
* @private
*/
return function main(args, stdout = null, stderr = null) {
switch (args[0]) {
case undefined:
case "-h":
case "--help":
return require(`../${name}/help`)(stdout);

case "-v":
case "--version":
return require("./version")(stdout);

default:
return require(`../${name}/main`)(args, stdout, stderr);
}
};
}

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------

module.exports = function bootstrap(entryModule, name) {
const main = entryModule.exports = defineMain(name);

/* eslint-disable no-console, no-process-exit */
/* istanbul ignore if */
if (require.main === entryModule) {
// Execute.
const promise = main(
process.argv.slice(2),
process.stdout,
process.stderr
);

// Error Handling.
promise.then(
() => {
// I'm not sure why, but maybe the process never exits
// on Git Bash (MINGW64)
process.exit(0);
},
(err) => {
console.error("ERROR:", err.message);
process.exit(1);
}
);
}
};

12 changes: 9 additions & 3 deletions src/bin/common/parse-cli-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
* @copyright 2016 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
"use strict";

/*eslint no-process-env: "off"*/

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

import assign from "object-assign";
const assign = require("object-assign");

//------------------------------------------------------------------------------
// Helpers
Expand Down Expand Up @@ -95,6 +98,9 @@ class ArgumentSet {
addGroup(this.groups, initialValues);
}

/**
* Gets the last group.
*/
get lastGroup() {
return this.groups[this.groups.length - 1];
}
Expand Down Expand Up @@ -213,6 +219,6 @@ function parseCLIArgsCore(set, args) { // eslint-disable-line complexity
* @param {object} options - A key-value map for the options.
* @returns {ArgumentSet} The parsed CLI arguments.
*/
export default function parseCLIArgs(args, initialValues, options) {
module.exports = function parseCLIArgs(args, initialValues, options) {
return parseCLIArgsCore(new ArgumentSet(initialValues, options), args);
}
};
7 changes: 4 additions & 3 deletions src/bin/common/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
* @copyright 2016 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

import {sync as readPkgUp} from "read-pkg-up";
const {sync: readPkgUp} = require("read-pkg-up");

//------------------------------------------------------------------------------
// Public Interface
Expand All @@ -21,10 +22,10 @@ import {sync as readPkgUp} from "read-pkg-up";
* @returns {Promise} Always a fulfilled promise.
* @private
*/
export default function printVersion(output) {
module.exports = function printVersion(output) {
const version = readPkgUp(__dirname).pkg.version;

output.write(`v${version}\n`);

return Promise.resolve(null);
}
};
5 changes: 3 additions & 2 deletions src/bin/npm-run-all/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @copyright 2015 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
"use strict";

//------------------------------------------------------------------------------
// Public Interface
Expand All @@ -15,7 +16,7 @@
* @returns {Promise} Always a fulfilled promise.
* @private
*/
export default function printHelp(output) {
module.exports = function printHelp(output) {
output.write(`
Usage:
$ npm-run-all [--help | -h | --version | -v]
Expand Down Expand Up @@ -55,4 +56,4 @@ See Also:
`);

return Promise.resolve(null);
}
};
54 changes: 2 additions & 52 deletions src/bin/npm-run-all/index.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,13 @@
#!/usr/bin/env node

/**
* @author Toru Nagashima
* @copyright 2015 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

/**
* The main process of `npm-run-all` command.
*
* @param {string[]} args - Arguments to parse.
* @param {stream.Writable} stdout - A writable stream to print logs.
* @param {stream.Writable} stderr - A writable stream to print errors.
* @returns {Promise} A promise which comes to be fulfilled when all npm-scripts are completed.
* @private
*/
export default function main(
args,
stdout = null,
stderr = null
) {
switch (args[0]) {
case undefined:
case "-h":
case "--help":
return require("./help").default(stdout);

case "-v":
case "--version":
return require("../common/version").default(stdout);

default:
return require("./main").default(args, stdout, stderr);
}
}
"use strict";

//------------------------------------------------------------------------------
// Main
//------------------------------------------------------------------------------

/* eslint-disable no-process-exit */
/* istanbul ignore if */
if (require.main === module) {
// Execute.
const promise = main(process.argv.slice(2), process.stdout, process.stderr);

// Error Handling.
promise.then(
() => {
// I'm not sure why, but maybe the process never exits on Git Bash (MINGW64)
process.exit(0);
},
(err) => {
console.error("ERROR:", err.message); // eslint-disable-line no-console
process.exit(1);
}
);
}
require("../common/bootstrap")(module, "npm-run-all");
9 changes: 5 additions & 4 deletions src/bin/npm-run-all/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
* @copyright 2015 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

import parseCLIArgs from "../common/parse-cli-args";
import runAll from "../../lib/npm-run-all";
const runAll = require("../../lib");
const parseCLIArgs = require("../common/parse-cli-args");

//------------------------------------------------------------------------------
// Public Interface
Expand All @@ -24,7 +25,7 @@ import runAll from "../../lib/npm-run-all";
* @returns {Promise} A promise which comes to be fulfilled when all npm-scripts are completed.
* @private
*/
export default function npmRunAll(args, stdout, stderr) {
module.exports = function npmRunAll(args, stdout, stderr) {
try {
const stdin = process.stdin;
const {groups, silent, packageConfig} = parseCLIArgs(args);
Expand Down Expand Up @@ -64,4 +65,4 @@ export default function npmRunAll(args, stdout, stderr) {
catch (err) {
return Promise.reject(err);
}
}
};
5 changes: 3 additions & 2 deletions src/bin/run-p/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @copyright 2016 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
"use strict";

//------------------------------------------------------------------------------
// Public Interface
Expand All @@ -15,7 +16,7 @@
* @returns {Promise} Always a fulfilled promise.
* @private
*/
export default function printHelp(output) {
module.exports = function printHelp(output) {
output.write(`
Usage:
$ run-p [--help | -h | --version | -v]
Expand Down Expand Up @@ -51,4 +52,4 @@ See Also:
`);

return Promise.resolve(null);
}
};

0 comments on commit 2f26fa5

Please sign in to comment.