From e03516addc781c6361aa2a1f7082905ef3bc194c Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Mon, 19 Feb 2018 13:09:22 +0100 Subject: [PATCH 1/7] :recycle: Change bin/lisky to ES6 --- bin/.eslintrc.json | 11 +++--- bin/lisky | 86 +++++++++++++++++++++++++------------------- bin/lisky.js | 89 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 4 files changed, 147 insertions(+), 41 deletions(-) create mode 100644 bin/lisky.js diff --git a/bin/.eslintrc.json b/bin/.eslintrc.json index 93bba791..e27ab87f 100644 --- a/bin/.eslintrc.json +++ b/bin/.eslintrc.json @@ -1,8 +1,11 @@ { - "env": { - "es6": false - }, + "extends": ["lisk-base"], "rules": { - "no-var": "off" + "arrow-parens": "off", + "curly": "off", + "function-paren-newline": "off", + "indent": "off", + "no-confusing-arrow": "off", + "object-curly-newline": "off" } } diff --git a/bin/lisky b/bin/lisky index 62606f04..a956f8c0 100755 --- a/bin/lisky +++ b/bin/lisky @@ -1,4 +1,32 @@ #!/usr/bin/env node +'use strict'; + +var _os = require('os'); + +var _os2 = _interopRequireDefault(_os); + +var _lockfile = require('lockfile'); + +var _lockfile2 = _interopRequireDefault(_lockfile); + +var _semver = require('semver'); + +var _semver2 = _interopRequireDefault(_semver); + +var _package = require('../package.json'); + +var _package2 = _interopRequireDefault(_package); + +var _dist = require('../dist'); + +var _dist2 = _interopRequireDefault(_dist); + +var _execFile = require('../dist/execFile'); + +var _execFile2 = _interopRequireDefault(_execFile); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + /* * LiskHQ/lisky * Copyright © 2017 Lisk Foundation @@ -14,23 +42,11 @@ * Removal or modification of this copyright notice is prohibited. * */ -var os = require('os'); -var lockfile = require('lockfile'); -var semver = require('semver'); - -var packageJSON = require('../package.json'); - -var configLockfilePath; -var lisky; -var execFile; -var firstCommandWords; var nonInteractiveLiskyArg = process.argv[1]; var nonInteractiveCommandArg = process.argv[2]; -var nonInteractiveOptions; -var commandArgIsFilePath = false; -process.env.LISKY_CONFIG_DIR = process.env.LISKY_CONFIG_DIR || `${os.homedir()}/.lisky`; -configLockfilePath = `${process.env.LISKY_CONFIG_DIR}/config.lock`; +process.env.LISKY_CONFIG_DIR = process.env.LISKY_CONFIG_DIR || _os2.default.homedir() + '/.lisky'; +var configLockfilePath = process.env.LISKY_CONFIG_DIR + '/config.lock'; process.env.NON_INTERACTIVE_MODE = !(nonInteractiveLiskyArg.endsWith('lisky') && process.argv.length === 2); @@ -38,45 +54,43 @@ function exit(code) { process.exit(code || 0); } -if (!semver.satisfies(process.version, packageJSON.engines.node)) { - console.error('\x1b[31m', `ERROR: Requires Node.js version ${semver.clean(packageJSON.engines.node)}, but was started with version ${semver.clean(process.version)}.`, '\x1b[0m'); +if (!_semver2.default.satisfies(process.version, _package2.default.engines.node)) { + console.error('\x1b[31m', 'ERROR: Requires Node.js version ' + _semver2.default.clean(_package2.default.engines.node) + ', but was started with version ' + _semver2.default.clean(process.version) + '.', '\x1b[0m'); exit(); } // eslint-disable-next-line default-case switch (process.argv[2]) { -case 'clean': - console.warn('\x1b[33m', 'WARNING: Attempting to remove configuration lockfile. I hope you know what you’re doing.', '\x1b[0m'); - lockfile.unlockSync(configLockfilePath); - exit(); - break; -case '--version': -case '-v': - console.info(packageJSON.version); - exit(); - break; -default: + case 'clean': + console.warn('\x1b[33m', 'WARNING: Attempting to remove configuration lockfile. I hope you know what you’re doing.', '\x1b[0m'); + _lockfile2.default.unlockSync(configLockfilePath); + exit(); + break; + case '--version': + case '-v': + console.info(_package2.default.version); + exit(); + break; + default: // continue... } -lisky = require('../dist').default; -execFile = require('../dist/exec_file').default; - // eslint-disable-next-line no-underscore-dangle -firstCommandWords = lisky.commands.map(c => c._name.split(' ')[0]); +var firstCommandWords = _dist2.default.commands.map(function (c) { + return c._name.split(' ')[0]; +}); +var commandArgIsFilePath = false; if (firstCommandWords.indexOf(nonInteractiveCommandArg) === -1) { commandArgIsFilePath = true; try { - nonInteractiveOptions = process.argv.slice(3); - execFile(lisky, nonInteractiveCommandArg, nonInteractiveOptions, exit); + var nonInteractiveOptions = process.argv.slice(3); + (0, _execFile2.default)(_dist2.default, nonInteractiveCommandArg, nonInteractiveOptions, exit); } catch (error) { commandArgIsFilePath = false; } } if (!commandArgIsFilePath) { - module.exports = process.env.NON_INTERACTIVE_MODE === 'true' - ? (lisky.parse(process.argv)) - : lisky; + module.exports = process.env.NON_INTERACTIVE_MODE === 'true' ? _dist2.default.parse(process.argv) : _dist2.default; } diff --git a/bin/lisky.js b/bin/lisky.js new file mode 100644 index 00000000..bd5a38f7 --- /dev/null +++ b/bin/lisky.js @@ -0,0 +1,89 @@ +#!/usr/bin/env node +/* + * LiskHQ/lisky + * Copyright © 2017 Lisk Foundation + * + * See the LICENSE file at the top-level directory of this distribution + * for licensing information. + * + * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, + * no part of this software, including this file, may be copied, modified, + * propagated, or distributed except according to the terms contained in the + * LICENSE file. + * + * Removal or modification of this copyright notice is prohibited. + * + */ +import os from 'os'; +import lockfile from 'lockfile'; +import semver from 'semver'; +import packageJSON from '../package.json'; +import lisky from '../dist'; +import execFile from '../dist/execFile'; + +const nonInteractiveLiskyArg = process.argv[1]; +const nonInteractiveCommandArg = process.argv[2]; + +process.env.LISKY_CONFIG_DIR = + process.env.LISKY_CONFIG_DIR || `${os.homedir()}/.lisky`; +const configLockfilePath = `${process.env.LISKY_CONFIG_DIR}/config.lock`; + +process.env.NON_INTERACTIVE_MODE = !( + nonInteractiveLiskyArg.endsWith('lisky') && process.argv.length === 2 +); + +function exit(code) { + process.exit(code || 0); +} + +if (!semver.satisfies(process.version, packageJSON.engines.node)) { + console.error( + '\x1b[31m', + `ERROR: Requires Node.js version ${semver.clean( + packageJSON.engines.node, + )}, but was started with version ${semver.clean(process.version)}.`, + '\x1b[0m', + ); + exit(); +} + +// eslint-disable-next-line default-case +switch (process.argv[2]) { + case 'clean': + console.warn( + '\x1b[33m', + 'WARNING: Attempting to remove configuration lockfile. I hope you know what you’re doing.', + '\x1b[0m', + ); + lockfile.unlockSync(configLockfilePath); + exit(); + break; + case '--version': + case '-v': + console.info(packageJSON.version); + exit(); + break; + default: + // continue... +} + +// eslint-disable-next-line no-underscore-dangle +const firstCommandWords = lisky.commands.map(c => c._name.split(' ')[0]); + +let commandArgIsFilePath = false; +if (firstCommandWords.indexOf(nonInteractiveCommandArg) === -1) { + commandArgIsFilePath = true; + try { + const nonInteractiveOptions = process.argv.slice(3); + execFile(lisky, nonInteractiveCommandArg, nonInteractiveOptions, exit); + } catch (error) { + commandArgIsFilePath = false; + } +} + +if (!commandArgIsFilePath) { + module.exports = + process.env.NON_INTERACTIVE_MODE === 'true' + ? lisky.parse(process.argv) + : lisky; +} diff --git a/package.json b/package.json index be1aa1f7..8ee0963f 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "cover:test": "NODE_ENV=test nyc --include \"test/**\" --exclude \"**/node_modules/** coverage/**\" mocha test/specs", "prebuild": "if test -d dist; then rm -r dist; fi", - "build": "babel src -d dist", + "build": "babel src -d dist && babel bin/lisky.js -o bin/lisky", "precommit": "lint-staged && npm run lint", "prepush": "npm run lint && npm test", "prepublishOnly": From ab02965392946f34c0767cca8ac041a4b3970b18 Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Mon, 19 Feb 2018 13:25:57 +0100 Subject: [PATCH 2/7] :nail_care: Change dynamically imported files not to be checked --- bin/lisky.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/lisky.js b/bin/lisky.js index bd5a38f7..0555fa76 100644 --- a/bin/lisky.js +++ b/bin/lisky.js @@ -18,7 +18,10 @@ import os from 'os'; import lockfile from 'lockfile'; import semver from 'semver'; import packageJSON from '../package.json'; + +// eslint-disable-next-line import/extensions,import/no-unresolved import lisky from '../dist'; +// eslint-disable-next-line import/extensions,import/no-unresolved import execFile from '../dist/execFile'; const nonInteractiveLiskyArg = process.argv[1]; @@ -47,7 +50,6 @@ if (!semver.satisfies(process.version, packageJSON.engines.node)) { exit(); } -// eslint-disable-next-line default-case switch (process.argv[2]) { case 'clean': console.warn( From 667bb146bf957bf38c37d481a650527be1b3d657 Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Mon, 19 Feb 2018 16:29:40 +0100 Subject: [PATCH 3/7] :recycle: Remove dependency to babel on bin/lisky --- bin/lisky | 76 ++++++++++++++++++------------------------- bin/lisky.js | 91 ---------------------------------------------------- package.json | 2 +- 3 files changed, 32 insertions(+), 137 deletions(-) delete mode 100644 bin/lisky.js diff --git a/bin/lisky b/bin/lisky index a956f8c0..0434279c 100755 --- a/bin/lisky +++ b/bin/lisky @@ -1,32 +1,4 @@ #!/usr/bin/env node -'use strict'; - -var _os = require('os'); - -var _os2 = _interopRequireDefault(_os); - -var _lockfile = require('lockfile'); - -var _lockfile2 = _interopRequireDefault(_lockfile); - -var _semver = require('semver'); - -var _semver2 = _interopRequireDefault(_semver); - -var _package = require('../package.json'); - -var _package2 = _interopRequireDefault(_package); - -var _dist = require('../dist'); - -var _dist2 = _interopRequireDefault(_dist); - -var _execFile = require('../dist/execFile'); - -var _execFile2 = _interopRequireDefault(_execFile); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - /* * LiskHQ/lisky * Copyright © 2017 Lisk Foundation @@ -42,33 +14,45 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de * Removal or modification of this copyright notice is prohibited. * */ -var nonInteractiveLiskyArg = process.argv[1]; -var nonInteractiveCommandArg = process.argv[2]; +const os = require('os'); +const lockfile = require('lockfile'); +const semver = require('semver'); +const packageJSON = require('../package.json'); + +// eslint-disable-next-line import/extensions,import/no-unresolved +const lisky = require('../dist').default; +// eslint-disable-next-line import/extensions,import/no-unresolved +const execFile = require('../dist/execFile').default; -process.env.LISKY_CONFIG_DIR = process.env.LISKY_CONFIG_DIR || _os2.default.homedir() + '/.lisky'; -var configLockfilePath = process.env.LISKY_CONFIG_DIR + '/config.lock'; +const nonInteractiveLiskyArg = process.argv[1]; +const nonInteractiveCommandArg = process.argv[2]; -process.env.NON_INTERACTIVE_MODE = !(nonInteractiveLiskyArg.endsWith('lisky') && process.argv.length === 2); +process.env.LISKY_CONFIG_DIR = + process.env.LISKY_CONFIG_DIR || `${os.homedir()}/.lisky`; +const configLockfilePath = `${process.env.LISKY_CONFIG_DIR}/config.lock`; + +process.env.NON_INTERACTIVE_MODE = !( + nonInteractiveLiskyArg.endsWith('lisky') && process.argv.length === 2 +); function exit(code) { process.exit(code || 0); } -if (!_semver2.default.satisfies(process.version, _package2.default.engines.node)) { - console.error('\x1b[31m', 'ERROR: Requires Node.js version ' + _semver2.default.clean(_package2.default.engines.node) + ', but was started with version ' + _semver2.default.clean(process.version) + '.', '\x1b[0m'); +if (!semver.satisfies(process.version, packageJSON.engines.node)) { + console.error('\x1b[31m', `ERROR: Requires Node.js version ${semver.clean(packageJSON.engines.node)}, but was started with version ${semver.clean(process.version)}.`, '\x1b[0m'); exit(); } -// eslint-disable-next-line default-case switch (process.argv[2]) { case 'clean': console.warn('\x1b[33m', 'WARNING: Attempting to remove configuration lockfile. I hope you know what you’re doing.', '\x1b[0m'); - _lockfile2.default.unlockSync(configLockfilePath); + lockfile.unlockSync(configLockfilePath); exit(); break; case '--version': case '-v': - console.info(_package2.default.version); + console.info(packageJSON.version); exit(); break; default: @@ -76,21 +60,23 @@ switch (process.argv[2]) { } // eslint-disable-next-line no-underscore-dangle -var firstCommandWords = _dist2.default.commands.map(function (c) { - return c._name.split(' ')[0]; -}); +const firstCommandWords = lisky.commands.map(c => c._name.split(' ')[0]); -var commandArgIsFilePath = false; +let commandArgIsFilePath = false; if (firstCommandWords.indexOf(nonInteractiveCommandArg) === -1) { commandArgIsFilePath = true; try { - var nonInteractiveOptions = process.argv.slice(3); - (0, _execFile2.default)(_dist2.default, nonInteractiveCommandArg, nonInteractiveOptions, exit); + const nonInteractiveOptions = process.argv.slice(3); + execFile(lisky, nonInteractiveCommandArg, nonInteractiveOptions, exit); } catch (error) { commandArgIsFilePath = false; } } if (!commandArgIsFilePath) { - module.exports = process.env.NON_INTERACTIVE_MODE === 'true' ? _dist2.default.parse(process.argv) : _dist2.default; + module.exports = + process.env.NON_INTERACTIVE_MODE === 'true' + ? lisky.parse(process.argv) + : lisky; } + diff --git a/bin/lisky.js b/bin/lisky.js deleted file mode 100644 index 0555fa76..00000000 --- a/bin/lisky.js +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env node -/* - * LiskHQ/lisky - * Copyright © 2017 Lisk Foundation - * - * See the LICENSE file at the top-level directory of this distribution - * for licensing information. - * - * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, - * no part of this software, including this file, may be copied, modified, - * propagated, or distributed except according to the terms contained in the - * LICENSE file. - * - * Removal or modification of this copyright notice is prohibited. - * - */ -import os from 'os'; -import lockfile from 'lockfile'; -import semver from 'semver'; -import packageJSON from '../package.json'; - -// eslint-disable-next-line import/extensions,import/no-unresolved -import lisky from '../dist'; -// eslint-disable-next-line import/extensions,import/no-unresolved -import execFile from '../dist/execFile'; - -const nonInteractiveLiskyArg = process.argv[1]; -const nonInteractiveCommandArg = process.argv[2]; - -process.env.LISKY_CONFIG_DIR = - process.env.LISKY_CONFIG_DIR || `${os.homedir()}/.lisky`; -const configLockfilePath = `${process.env.LISKY_CONFIG_DIR}/config.lock`; - -process.env.NON_INTERACTIVE_MODE = !( - nonInteractiveLiskyArg.endsWith('lisky') && process.argv.length === 2 -); - -function exit(code) { - process.exit(code || 0); -} - -if (!semver.satisfies(process.version, packageJSON.engines.node)) { - console.error( - '\x1b[31m', - `ERROR: Requires Node.js version ${semver.clean( - packageJSON.engines.node, - )}, but was started with version ${semver.clean(process.version)}.`, - '\x1b[0m', - ); - exit(); -} - -switch (process.argv[2]) { - case 'clean': - console.warn( - '\x1b[33m', - 'WARNING: Attempting to remove configuration lockfile. I hope you know what you’re doing.', - '\x1b[0m', - ); - lockfile.unlockSync(configLockfilePath); - exit(); - break; - case '--version': - case '-v': - console.info(packageJSON.version); - exit(); - break; - default: - // continue... -} - -// eslint-disable-next-line no-underscore-dangle -const firstCommandWords = lisky.commands.map(c => c._name.split(' ')[0]); - -let commandArgIsFilePath = false; -if (firstCommandWords.indexOf(nonInteractiveCommandArg) === -1) { - commandArgIsFilePath = true; - try { - const nonInteractiveOptions = process.argv.slice(3); - execFile(lisky, nonInteractiveCommandArg, nonInteractiveOptions, exit); - } catch (error) { - commandArgIsFilePath = false; - } -} - -if (!commandArgIsFilePath) { - module.exports = - process.env.NON_INTERACTIVE_MODE === 'true' - ? lisky.parse(process.argv) - : lisky; -} diff --git a/package.json b/package.json index 8ee0963f..be1aa1f7 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "cover:test": "NODE_ENV=test nyc --include \"test/**\" --exclude \"**/node_modules/** coverage/**\" mocha test/specs", "prebuild": "if test -d dist; then rm -r dist; fi", - "build": "babel src -d dist && babel bin/lisky.js -o bin/lisky", + "build": "babel src -d dist", "precommit": "lint-staged && npm run lint", "prepush": "npm run lint && npm test", "prepublishOnly": From a60a98f789ab2ed8057a62bcdcf6f8c72359a7f8 Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Wed, 28 Feb 2018 11:52:52 +0100 Subject: [PATCH 4/7] :recycle: Update bin to use parent eslint, use babel and require dist when it is required --- bin/.eslintrc.json | 11 ------ bin/lisky | 70 ++++++++++++++++++++--------------- bin/lisky.js | 92 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 4 +- 4 files changed, 135 insertions(+), 42 deletions(-) delete mode 100644 bin/.eslintrc.json create mode 100644 bin/lisky.js diff --git a/bin/.eslintrc.json b/bin/.eslintrc.json deleted file mode 100644 index e27ab87f..00000000 --- a/bin/.eslintrc.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": ["lisk-base"], - "rules": { - "arrow-parens": "off", - "curly": "off", - "function-paren-newline": "off", - "indent": "off", - "no-confusing-arrow": "off", - "object-curly-newline": "off" - } -} diff --git a/bin/lisky b/bin/lisky index 0434279c..7286ebd3 100755 --- a/bin/lisky +++ b/bin/lisky @@ -1,4 +1,24 @@ #!/usr/bin/env node +'use strict'; + +var _os = require('os'); + +var _os2 = _interopRequireDefault(_os); + +var _lockfile = require('lockfile'); + +var _lockfile2 = _interopRequireDefault(_lockfile); + +var _semver = require('semver'); + +var _semver2 = _interopRequireDefault(_semver); + +var _package = require('../package.json'); + +var _package2 = _interopRequireDefault(_package); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + /* * LiskHQ/lisky * Copyright © 2017 Lisk Foundation @@ -14,59 +34,55 @@ * Removal or modification of this copyright notice is prohibited. * */ -const os = require('os'); -const lockfile = require('lockfile'); -const semver = require('semver'); -const packageJSON = require('../package.json'); - -// eslint-disable-next-line import/extensions,import/no-unresolved -const lisky = require('../dist').default; -// eslint-disable-next-line import/extensions,import/no-unresolved -const execFile = require('../dist/execFile').default; +var nonInteractiveLiskyArg = process.argv[1]; +// eslint-disable-next-line import/order -const nonInteractiveLiskyArg = process.argv[1]; -const nonInteractiveCommandArg = process.argv[2]; +var nonInteractiveCommandArg = process.argv[2]; -process.env.LISKY_CONFIG_DIR = - process.env.LISKY_CONFIG_DIR || `${os.homedir()}/.lisky`; -const configLockfilePath = `${process.env.LISKY_CONFIG_DIR}/config.lock`; +process.env.LISKY_CONFIG_DIR = process.env.LISKY_CONFIG_DIR || _os2.default.homedir() + '/.lisky'; +var configLockfilePath = process.env.LISKY_CONFIG_DIR + '/config.lock'; -process.env.NON_INTERACTIVE_MODE = !( - nonInteractiveLiskyArg.endsWith('lisky') && process.argv.length === 2 -); +process.env.NON_INTERACTIVE_MODE = !(nonInteractiveLiskyArg.endsWith('lisky') && process.argv.length === 2); function exit(code) { process.exit(code || 0); } -if (!semver.satisfies(process.version, packageJSON.engines.node)) { - console.error('\x1b[31m', `ERROR: Requires Node.js version ${semver.clean(packageJSON.engines.node)}, but was started with version ${semver.clean(process.version)}.`, '\x1b[0m'); +if (!_semver2.default.satisfies(process.version, _package2.default.engines.node)) { + console.error('\x1b[31m', 'ERROR: Requires Node.js version ' + _semver2.default.clean(_package2.default.engines.node) + ', but was started with version ' + _semver2.default.clean(process.version) + '.', '\x1b[0m'); exit(); } switch (process.argv[2]) { case 'clean': console.warn('\x1b[33m', 'WARNING: Attempting to remove configuration lockfile. I hope you know what you’re doing.', '\x1b[0m'); - lockfile.unlockSync(configLockfilePath); + _lockfile2.default.unlockSync(configLockfilePath); exit(); break; case '--version': case '-v': - console.info(packageJSON.version); + console.info(_package2.default.version); exit(); break; default: // continue... } +// eslint-disable-next-line import/extensions,import/no-unresolved +var lisky = require('../dist').default; +// eslint-disable-next-line import/extensions,import/no-unresolved +var execFile = require('../dist/exec_file').default; + // eslint-disable-next-line no-underscore-dangle -const firstCommandWords = lisky.commands.map(c => c._name.split(' ')[0]); +var firstCommandWords = lisky.commands.map(function (c) { + return c._name.split(' ')[0]; +}); -let commandArgIsFilePath = false; +var commandArgIsFilePath = false; if (firstCommandWords.indexOf(nonInteractiveCommandArg) === -1) { commandArgIsFilePath = true; try { - const nonInteractiveOptions = process.argv.slice(3); + var nonInteractiveOptions = process.argv.slice(3); execFile(lisky, nonInteractiveCommandArg, nonInteractiveOptions, exit); } catch (error) { commandArgIsFilePath = false; @@ -74,9 +90,5 @@ if (firstCommandWords.indexOf(nonInteractiveCommandArg) === -1) { } if (!commandArgIsFilePath) { - module.exports = - process.env.NON_INTERACTIVE_MODE === 'true' - ? lisky.parse(process.argv) - : lisky; + module.exports = process.env.NON_INTERACTIVE_MODE === 'true' ? lisky.parse(process.argv) : lisky; } - diff --git a/bin/lisky.js b/bin/lisky.js new file mode 100644 index 00000000..c29b2b2a --- /dev/null +++ b/bin/lisky.js @@ -0,0 +1,92 @@ +#!/usr/bin/env node +/* + * LiskHQ/lisky + * Copyright © 2017 Lisk Foundation + * + * See the LICENSE file at the top-level directory of this distribution + * for licensing information. + * + * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, + * no part of this software, including this file, may be copied, modified, + * propagated, or distributed except according to the terms contained in the + * LICENSE file. + * + * Removal or modification of this copyright notice is prohibited. + * + */ +import os from 'os'; +import lockfile from 'lockfile'; +import semver from 'semver'; +// eslint-disable-next-line import/order +import packageJSON from '../package.json'; + +const nonInteractiveLiskyArg = process.argv[1]; +const nonInteractiveCommandArg = process.argv[2]; + +process.env.LISKY_CONFIG_DIR = + process.env.LISKY_CONFIG_DIR || `${os.homedir()}/.lisky`; +const configLockfilePath = `${process.env.LISKY_CONFIG_DIR}/config.lock`; + +process.env.NON_INTERACTIVE_MODE = !( + nonInteractiveLiskyArg.endsWith('lisky') && process.argv.length === 2 +); + +function exit(code) { + process.exit(code || 0); +} + +if (!semver.satisfies(process.version, packageJSON.engines.node)) { + console.error( + '\x1b[31m', + `ERROR: Requires Node.js version ${semver.clean( + packageJSON.engines.node, + )}, but was started with version ${semver.clean(process.version)}.`, + '\x1b[0m', + ); + exit(); +} + +switch (process.argv[2]) { + case 'clean': + console.warn( + '\x1b[33m', + 'WARNING: Attempting to remove configuration lockfile. I hope you know what you’re doing.', + '\x1b[0m', + ); + lockfile.unlockSync(configLockfilePath); + exit(); + break; + case '--version': + case '-v': + console.info(packageJSON.version); + exit(); + break; + default: + // continue... +} + +// eslint-disable-next-line import/extensions,import/no-unresolved +const lisky = require('../dist').default; +// eslint-disable-next-line import/extensions,import/no-unresolved +const execFile = require('../dist/exec_file').default; + +// eslint-disable-next-line no-underscore-dangle +const firstCommandWords = lisky.commands.map(c => c._name.split(' ')[0]); + +let commandArgIsFilePath = false; +if (firstCommandWords.indexOf(nonInteractiveCommandArg) === -1) { + commandArgIsFilePath = true; + try { + const nonInteractiveOptions = process.argv.slice(3); + execFile(lisky, nonInteractiveCommandArg, nonInteractiveOptions, exit); + } catch (error) { + commandArgIsFilePath = false; + } +} + +if (!commandArgIsFilePath) { + module.exports = + process.env.NON_INTERACTIVE_MODE === 'true' + ? lisky.parse(process.argv) + : lisky; +} diff --git a/package.json b/package.json index be1aa1f7..2539c094 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "scripts": { "start": "babel-node src/index.js", "format": - "prettier --write \"./*.{js,json,md}\" \"{docs,src,test}{,/**}/*.{js,json,md}\"", + "prettier --write \"./*.{js,json,md}\" \"{bin,docs,src,test}{,/**}/*.{js,json,md}\"", "lint": "eslint .", "lint:fix": "npm run lint -- --fix", "test": @@ -44,7 +44,7 @@ "cover:test": "NODE_ENV=test nyc --include \"test/**\" --exclude \"**/node_modules/** coverage/**\" mocha test/specs", "prebuild": "if test -d dist; then rm -r dist; fi", - "build": "babel src -d dist", + "build": "babel src -d dist && babel bin/lisky.js -o bin/lisky", "precommit": "lint-staged && npm run lint", "prepush": "npm run lint && npm test", "prepublishOnly": From 748d4948e3d55e70c1d70bae17207f315197de6a Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Mon, 19 Mar 2018 10:16:14 +0100 Subject: [PATCH 5/7] :nail_care: Delete eslint ignore by changing build order --- Jenkinsfile | 10 +++++----- bin/lisky | 2 -- bin/lisky.js | 2 -- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 972dea47..57ff0be7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,6 +6,11 @@ pipeline { sh 'npm install --verbose' } } + stage('Build') { + steps { + sh 'npm run build' // Running build first, since "bin" requires reference to the "dist" folder + } + } stage('Run lint') { steps { ansiColor('xterm') { @@ -13,11 +18,6 @@ pipeline { } } } - stage('Build') { - steps { - sh 'npm run build' - } - } stage('Run tests') { steps { ansiColor('xterm') { diff --git a/bin/lisky b/bin/lisky index 7286ebd3..fbd16da4 100755 --- a/bin/lisky +++ b/bin/lisky @@ -68,9 +68,7 @@ switch (process.argv[2]) { // continue... } -// eslint-disable-next-line import/extensions,import/no-unresolved var lisky = require('../dist').default; -// eslint-disable-next-line import/extensions,import/no-unresolved var execFile = require('../dist/exec_file').default; // eslint-disable-next-line no-underscore-dangle diff --git a/bin/lisky.js b/bin/lisky.js index c29b2b2a..5f5546c4 100644 --- a/bin/lisky.js +++ b/bin/lisky.js @@ -65,9 +65,7 @@ switch (process.argv[2]) { // continue... } -// eslint-disable-next-line import/extensions,import/no-unresolved const lisky = require('../dist').default; -// eslint-disable-next-line import/extensions,import/no-unresolved const execFile = require('../dist/exec_file').default; // eslint-disable-next-line no-underscore-dangle From c9ec05ae449613ed4ba0f5ffe278d18654f813e8 Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Mon, 19 Feb 2018 15:33:12 +0100 Subject: [PATCH 6/7] :recycle: Clean up bin/lisky to increase readability --- bin/lisky | 173 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 103 insertions(+), 70 deletions(-) diff --git a/bin/lisky b/bin/lisky index fbd16da4..37c9dbbe 100755 --- a/bin/lisky +++ b/bin/lisky @@ -1,24 +1,4 @@ #!/usr/bin/env node -'use strict'; - -var _os = require('os'); - -var _os2 = _interopRequireDefault(_os); - -var _lockfile = require('lockfile'); - -var _lockfile2 = _interopRequireDefault(_lockfile); - -var _semver = require('semver'); - -var _semver2 = _interopRequireDefault(_semver); - -var _package = require('../package.json'); - -var _package2 = _interopRequireDefault(_package); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - /* * LiskHQ/lisky * Copyright © 2017 Lisk Foundation @@ -34,59 +14,112 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de * Removal or modification of this copyright notice is prohibited. * */ -var nonInteractiveLiskyArg = process.argv[1]; -// eslint-disable-next-line import/order - -var nonInteractiveCommandArg = process.argv[2]; - -process.env.LISKY_CONFIG_DIR = process.env.LISKY_CONFIG_DIR || _os2.default.homedir() + '/.lisky'; -var configLockfilePath = process.env.LISKY_CONFIG_DIR + '/config.lock'; - -process.env.NON_INTERACTIVE_MODE = !(nonInteractiveLiskyArg.endsWith('lisky') && process.argv.length === 2); - -function exit(code) { - process.exit(code || 0); -} +const os = require('os'); +const lockfile = require('lockfile'); +const semver = require('semver'); +const packageJSON = require('../package.json'); + +// eslint-disable-next-line import/extensions,import/no-unresolved +const lisky = require('../dist').default; +// eslint-disable-next-line import/extensions,import/no-unresolved +const execFile = require('../dist/execFile').default; + +const nonInteractiveLiskyArg = process.argv[1]; +const nonInteractiveCommandArg = process.argv[2]; +const configLockfilePath = `${process.env.LISKY_CONFIG_DIR}/config.lock`; + +const errorNodeVersion = (expected, actual) => + Error(`ERROR: Requires Node.js version ${expected}, but was started with version ${actual}.`); + +const exit = code => process.exit(code || 0); + +const showWarn = msg => console.warn('\x1b[33m', msg, '\x1b[0m'); +const showError = error => console.error('\x1b[31m', error.message, '\x1b[0m'); + +const showVersion = version => console.info(version); +const execClean = path => { + showWarn('WARNING: Attempting to remove configuration lockfile. I hope you know what you’re doing.'); + lockfile.unlockSync(path); +}; + +const isFileInput = command => { + // eslint-disable-next-line no-underscore-dangle + const firstCommandWords = lisky.commands.map(c => c._name.split(' ')[0]); + return firstCommandWords.indexOf(command) === -1; +}; + +const setEnvironment = () => { + process.env.LISKY_CONFIG_DIR = + process.env.LISKY_CONFIG_DIR || `${os.homedir()}/.lisky`; + + process.env.NON_INTERACTIVE_MODE = !( + nonInteractiveLiskyArg.endsWith('lisky') && process.argv.length === 2 + ); +}; + +const checkNodeVersion = (expected, actual) => { + if (!semver.satisfies(actual, expected)) { + throw errorNodeVersion(semver.clean(expected), semver.clean(actual)); + } +}; + +const handleBasicCommands = (command, lockFilePath, version) => { + switch (command) { + case 'clean': + execClean(lockFilePath); + return true; + case '--version': + case '-v': + showVersion(version); + return true; + default: + return false; + } +}; -if (!_semver2.default.satisfies(process.version, _package2.default.engines.node)) { - console.error('\x1b[31m', 'ERROR: Requires Node.js version ' + _semver2.default.clean(_package2.default.engines.node) + ', but was started with version ' + _semver2.default.clean(process.version) + '.', '\x1b[0m'); - exit(); -} +const handleFileInput = (liskyInstnce, command, options, exitFn) => { + try { + execFile(liskyInstnce, command, options, exitFn); + return true; + } catch (e) { + return false; + } +}; -switch (process.argv[2]) { - case 'clean': - console.warn('\x1b[33m', 'WARNING: Attempting to remove configuration lockfile. I hope you know what you’re doing.', '\x1b[0m'); - _lockfile2.default.unlockSync(configLockfilePath); +const run = () => { + setEnvironment(); + try { + checkNodeVersion(packageJSON.engines.node, process.version); + } catch (err) { + showError(err); exit(); - break; - case '--version': - case '-v': - console.info(_package2.default.version); + } + + const handled = handleBasicCommands( + nonInteractiveCommandArg, + configLockfilePath, + packageJSON.version); + if (handled) { exit(); - break; - default: - // continue... -} - -var lisky = require('../dist').default; -var execFile = require('../dist/exec_file').default; - -// eslint-disable-next-line no-underscore-dangle -var firstCommandWords = lisky.commands.map(function (c) { - return c._name.split(' ')[0]; -}); - -var commandArgIsFilePath = false; -if (firstCommandWords.indexOf(nonInteractiveCommandArg) === -1) { - commandArgIsFilePath = true; - try { - var nonInteractiveOptions = process.argv.slice(3); - execFile(lisky, nonInteractiveCommandArg, nonInteractiveOptions, exit); - } catch (error) { - commandArgIsFilePath = false; } -} -if (!commandArgIsFilePath) { - module.exports = process.env.NON_INTERACTIVE_MODE === 'true' ? lisky.parse(process.argv) : lisky; -} + const commandArgIsFilePath = isFileInput(nonInteractiveCommandArg); + let fileHandled = false; + if (commandArgIsFilePath) { + const nonInteractiveOptions = process.argv.slice(3); + fileHandled = handleFileInput( + lisky, + nonInteractiveCommandArg, + nonInteractiveOptions, + exit); + } + if (!commandArgIsFilePath || !fileHandled) { + return process.env.NON_INTERACTIVE_MODE === 'true' + ? lisky.parse(process.argv) + : lisky; + } + return null; +}; + +module.export = run(); + From 3dcdf8c20932039c08f1978ade77d63108fd13cf Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Mon, 19 Mar 2018 16:15:27 +0100 Subject: [PATCH 7/7] :recycle: Changed namings --- bin/lisky | 144 +++++++++++++++++++++++++------------------------ bin/lisky.js | 147 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 170 insertions(+), 121 deletions(-) diff --git a/bin/lisky b/bin/lisky index 37c9dbbe..74f455ed 100755 --- a/bin/lisky +++ b/bin/lisky @@ -1,4 +1,28 @@ #!/usr/bin/env node +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _os = require('os'); + +var _os2 = _interopRequireDefault(_os); + +var _lockfile = require('lockfile'); + +var _lockfile2 = _interopRequireDefault(_lockfile); + +var _semver = require('semver'); + +var _semver2 = _interopRequireDefault(_semver); + +var _package = require('../package.json'); + +var _package2 = _interopRequireDefault(_package); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + /* * LiskHQ/lisky * Copyright © 2017 Lisk Foundation @@ -14,112 +38,96 @@ * Removal or modification of this copyright notice is prohibited. * */ -const os = require('os'); -const lockfile = require('lockfile'); -const semver = require('semver'); -const packageJSON = require('../package.json'); +var nonInteractiveLiskyArg = process.argv[1]; +var nonInteractiveCommandArg = process.argv[2]; +var nonInteractiveOptions = process.argv.slice(3); -// eslint-disable-next-line import/extensions,import/no-unresolved -const lisky = require('../dist').default; -// eslint-disable-next-line import/extensions,import/no-unresolved -const execFile = require('../dist/execFile').default; - -const nonInteractiveLiskyArg = process.argv[1]; -const nonInteractiveCommandArg = process.argv[2]; -const configLockfilePath = `${process.env.LISKY_CONFIG_DIR}/config.lock`; - -const errorNodeVersion = (expected, actual) => - Error(`ERROR: Requires Node.js version ${expected}, but was started with version ${actual}.`); - -const exit = code => process.exit(code || 0); +var exit = function exit(code) { + return process.exit(code || 0); +}; -const showWarn = msg => console.warn('\x1b[33m', msg, '\x1b[0m'); -const showError = error => console.error('\x1b[31m', error.message, '\x1b[0m'); +var printWarning = function printWarning(message) { + return console.warn('\x1b[33m', message, '\x1b[0m'); +}; +var printError = function printError(message) { + return console.error('\x1b[31m', message, '\x1b[0m'); +}; +var printVersion = function printVersion(version) { + return console.info(version); +}; -const showVersion = version => console.info(version); -const execClean = path => { - showWarn('WARNING: Attempting to remove configuration lockfile. I hope you know what you’re doing.'); - lockfile.unlockSync(path); +var execClean = function execClean(path) { + printWarning('WARNING: Attempting to remove configuration lockfile. I hope you know what you’re doing.'); + _lockfile2.default.unlockSync(path); }; -const isFileInput = command => { +var isUnknownCommand = function isUnknownCommand(liskyInstance, command) { // eslint-disable-next-line no-underscore-dangle - const firstCommandWords = lisky.commands.map(c => c._name.split(' ')[0]); + var firstCommandWords = liskyInstance.commands.map(function (c) { + return c._name.split(' ')[0]; + }); return firstCommandWords.indexOf(command) === -1; }; -const setEnvironment = () => { - process.env.LISKY_CONFIG_DIR = - process.env.LISKY_CONFIG_DIR || `${os.homedir()}/.lisky`; +var setEnvironment = function setEnvironment() { + process.env.LISKY_CONFIG_DIR = process.env.LISKY_CONFIG_DIR || _os2.default.homedir() + '/.lisky'; - process.env.NON_INTERACTIVE_MODE = !( - nonInteractiveLiskyArg.endsWith('lisky') && process.argv.length === 2 - ); + process.env.NON_INTERACTIVE_MODE = !(nonInteractiveLiskyArg.endsWith('lisky') && process.argv.length === 2); }; -const checkNodeVersion = (expected, actual) => { - if (!semver.satisfies(actual, expected)) { - throw errorNodeVersion(semver.clean(expected), semver.clean(actual)); +var checkNodeVersion = function checkNodeVersion(expected, actual) { + if (!_semver2.default.satisfies(actual, expected)) { + throw new Error('ERROR: Requires Node.js version ' + _semver2.default.clean(expected) + ', but was started with version ' + _semver2.default.clean(actual) + '.'); } }; -const handleBasicCommands = (command, lockFilePath, version) => { +var handleBasicCommands = function handleBasicCommands(command, lockFilePath, version) { switch (command) { case 'clean': execClean(lockFilePath); return true; case '--version': case '-v': - showVersion(version); + printVersion(version); return true; default: return false; } }; -const handleFileInput = (liskyInstnce, command, options, exitFn) => { - try { - execFile(liskyInstnce, command, options, exitFn); - return true; - } catch (e) { - return false; - } +var getLiskyInstanceByMode = function getLiskyInstanceByMode(liskyInstance, nonInteractiveMode) { + return nonInteractiveMode ? liskyInstance.parse(process.argv) : liskyInstance; }; -const run = () => { +var run = function run() { setEnvironment(); try { - checkNodeVersion(packageJSON.engines.node, process.version); - } catch (err) { - showError(err); + checkNodeVersion(_package2.default.engines.node, process.version); + } catch (error) { + printError(error.message); exit(); } - const handled = handleBasicCommands( - nonInteractiveCommandArg, - configLockfilePath, - packageJSON.version); - if (handled) { + if (handleBasicCommands(nonInteractiveCommandArg, process.env.LISKY_CONFIG_DIR + '/config.lock', _package2.default.version)) { exit(); } - const commandArgIsFilePath = isFileInput(nonInteractiveCommandArg); - let fileHandled = false; - if (commandArgIsFilePath) { - const nonInteractiveOptions = process.argv.slice(3); - fileHandled = handleFileInput( - lisky, - nonInteractiveCommandArg, - nonInteractiveOptions, - exit); - } - if (!commandArgIsFilePath || !fileHandled) { - return process.env.NON_INTERACTIVE_MODE === 'true' - ? lisky.parse(process.argv) - : lisky; + // Dynamically required, otherwise it starts the CLI before handling above codes + // eslint-disable-next-line global-require + var lisky = require('../dist').default; + // eslint-disable-next-line global-require + var execFile = require('../dist/exec_file').default; + if (isUnknownCommand(lisky, nonInteractiveCommandArg)) { + try { + // "execFile" throws error when it "nonInteractiveCommandArg" is not a filepath + return execFile(lisky, nonInteractiveCommandArg, nonInteractiveOptions, exit); + } catch (error) { + return getLiskyInstanceByMode(lisky, process.env.NON_INTERACTIVE_MODE === 'true'); + } } - return null; + return getLiskyInstanceByMode(lisky, process.env.NON_INTERACTIVE_MODE === 'true'); }; -module.export = run(); +run(); +exports.default = run; diff --git a/bin/lisky.js b/bin/lisky.js index 5f5546c4..f79e2cb8 100644 --- a/bin/lisky.js +++ b/bin/lisky.js @@ -17,74 +17,115 @@ import os from 'os'; import lockfile from 'lockfile'; import semver from 'semver'; -// eslint-disable-next-line import/order import packageJSON from '../package.json'; const nonInteractiveLiskyArg = process.argv[1]; const nonInteractiveCommandArg = process.argv[2]; +const nonInteractiveOptions = process.argv.slice(3); -process.env.LISKY_CONFIG_DIR = - process.env.LISKY_CONFIG_DIR || `${os.homedir()}/.lisky`; -const configLockfilePath = `${process.env.LISKY_CONFIG_DIR}/config.lock`; +const exit = code => process.exit(code || 0); -process.env.NON_INTERACTIVE_MODE = !( - nonInteractiveLiskyArg.endsWith('lisky') && process.argv.length === 2 -); +const printWarning = message => console.warn('\x1b[33m', message, '\x1b[0m'); +const printError = message => console.error('\x1b[31m', message, '\x1b[0m'); +const printVersion = version => console.info(version); -function exit(code) { - process.exit(code || 0); -} +const execClean = path => { + printWarning( + 'WARNING: Attempting to remove configuration lockfile. I hope you know what you’re doing.', + ); + lockfile.unlockSync(path); +}; + +const isUnknownCommand = (liskyInstance, command) => { + const firstCommandWords = liskyInstance.commands.map( + // eslint-disable-next-line no-underscore-dangle + c => c._name.split(' ')[0], + ); + return firstCommandWords.indexOf(command) === -1; +}; + +const setEnvironment = () => { + process.env.LISKY_CONFIG_DIR = + process.env.LISKY_CONFIG_DIR || `${os.homedir()}/.lisky`; -if (!semver.satisfies(process.version, packageJSON.engines.node)) { - console.error( - '\x1b[31m', - `ERROR: Requires Node.js version ${semver.clean( - packageJSON.engines.node, - )}, but was started with version ${semver.clean(process.version)}.`, - '\x1b[0m', + process.env.NON_INTERACTIVE_MODE = !( + nonInteractiveLiskyArg.endsWith('lisky') && process.argv.length === 2 ); - exit(); -} +}; -switch (process.argv[2]) { - case 'clean': - console.warn( - '\x1b[33m', - 'WARNING: Attempting to remove configuration lockfile. I hope you know what you’re doing.', - '\x1b[0m', +const checkNodeVersion = (expected, actual) => { + if (!semver.satisfies(actual, expected)) { + throw new Error( + `ERROR: Requires Node.js version ${semver.clean( + expected, + )}, but was started with version ${semver.clean(actual)}.`, ); - lockfile.unlockSync(configLockfilePath); - exit(); - break; - case '--version': - case '-v': - console.info(packageJSON.version); - exit(); - break; - default: - // continue... -} + } +}; -const lisky = require('../dist').default; -const execFile = require('../dist/exec_file').default; +const handleBasicCommands = (command, lockFilePath, version) => { + switch (command) { + case 'clean': + execClean(lockFilePath); + return true; + case '--version': + case '-v': + printVersion(version); + return true; + default: + return false; + } +}; -// eslint-disable-next-line no-underscore-dangle -const firstCommandWords = lisky.commands.map(c => c._name.split(' ')[0]); +const getLiskyInstanceByMode = (liskyInstance, nonInteractiveMode) => + nonInteractiveMode ? liskyInstance.parse(process.argv) : liskyInstance; -let commandArgIsFilePath = false; -if (firstCommandWords.indexOf(nonInteractiveCommandArg) === -1) { - commandArgIsFilePath = true; +const run = () => { + setEnvironment(); try { - const nonInteractiveOptions = process.argv.slice(3); - execFile(lisky, nonInteractiveCommandArg, nonInteractiveOptions, exit); + checkNodeVersion(packageJSON.engines.node, process.version); } catch (error) { - commandArgIsFilePath = false; + printError(error.message); + exit(); + } + + if ( + handleBasicCommands( + nonInteractiveCommandArg, + `${process.env.LISKY_CONFIG_DIR}/config.lock`, + packageJSON.version, + ) + ) { + exit(); } -} -if (!commandArgIsFilePath) { - module.exports = - process.env.NON_INTERACTIVE_MODE === 'true' - ? lisky.parse(process.argv) - : lisky; -} + // Dynamically required, otherwise it starts the CLI before handling above codes + // eslint-disable-next-line global-require + const lisky = require('../dist').default; + // eslint-disable-next-line global-require + const execFile = require('../dist/exec_file').default; + if (isUnknownCommand(lisky, nonInteractiveCommandArg)) { + try { + // "execFile" throws error when it "nonInteractiveCommandArg" is not a filepath + return execFile( + lisky, + nonInteractiveCommandArg, + nonInteractiveOptions, + exit, + ); + } catch (error) { + return getLiskyInstanceByMode( + lisky, + process.env.NON_INTERACTIVE_MODE === 'true', + ); + } + } + return getLiskyInstanceByMode( + lisky, + process.env.NON_INTERACTIVE_MODE === 'true', + ); +}; + +run(); + +export default run;