From c17751a041f2a27821021927a27a7a95def346ad Mon Sep 17 00:00:00 2001 From: Micooz Date: Thu, 9 Mar 2017 16:17:46 +0800 Subject: [PATCH] feat(bin): add 'blinksocks-init' and 'blinksocks-run' sub commands --- bin/bootstrap.js | 6 +++--- bin/cli-init.js | 3 +++ bin/cli-run.js | 6 ++++++ bin/cli.js | 21 +++++++++++++++++---- package.json | 10 ++++++---- start.sh | 2 +- yarn.lock | 18 +++++++++--------- 7 files changed, 45 insertions(+), 21 deletions(-) create mode 100755 bin/cli-init.js create mode 100755 bin/cli-run.js diff --git a/bin/bootstrap.js b/bin/bootstrap.js index b48e647..5a468d0 100644 --- a/bin/bootstrap.js +++ b/bin/bootstrap.js @@ -27,13 +27,13 @@ const examples = ` Examples: As simple as possible: - $ blinksocks -c config.json + $ blinksocks run -c config.json To start a server: - $ blinksocks --host 0.0.0.0 --port 7777 --key password + $ blinksocks run --host 0.0.0.0 --port 7777 --key password To start a client: - $ blinksocks --host localhost --port 1080 --server-host example.com --server-port 7777 --key password + $ blinksocks run --host localhost --port 1080 --server-host example.com --server-port 7777 --key password `; /** diff --git a/bin/cli-init.js b/bin/cli-init.js new file mode 100755 index 0000000..dceed39 --- /dev/null +++ b/bin/cli-init.js @@ -0,0 +1,3 @@ +#!/usr/bin/env node + +// TODO \ No newline at end of file diff --git a/bin/cli-run.js b/bin/cli-run.js new file mode 100755 index 0000000..f528032 --- /dev/null +++ b/bin/cli-run.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node +require('babel-polyfill'); +const Hub = require('../lib').Hub; +const bootstrap = require('./bootstrap'); + +bootstrap({Hub}); diff --git a/bin/cli.js b/bin/cli.js index f528032..88def5a 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,6 +1,19 @@ #!/usr/bin/env node -require('babel-polyfill'); -const Hub = require('../lib').Hub; -const bootstrap = require('./bootstrap'); +const program = require('commander'); +const packageJson = require('../package.json'); -bootstrap({Hub}); +const usage = '[command] [options]'; + +program + .version(packageJson.version) + .usage(usage) + .command('init', 'generate configuration pair randomly') + .command('run [options]', 'start service') + .parse(process.argv); + +// no options provided + +if (process.argv.length < 2) { + program.help(); + process.exit(0); +} diff --git a/package.json b/package.json index 4e31024..ec87109 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,9 @@ "description": "Yet another socks5 proxy, designed for speed.", "main": "lib/index.js", "bin": { - "blinksocks": "bin/cli.js" + "blinksocks": "bin/cli.js", + "blinksocks-init": "bin/cli-init.js", + "blinksocks-run": "bin/cli-run.js" }, "scripts": { "test": "npm run lint && npm run test:coverage", @@ -40,10 +42,10 @@ "babel-preset-latest": "^6.22.0", "babel-register": "^6.23.0", "benchmark": "^2.1.3", - "eslint": "^3.17.0", + "eslint": "^3.17.1", "eslint-config-babel": "^6.0.0", - "eslint-plugin-babel": "^4.1.0", - "eslint-plugin-flowtype": "^2.30.0", + "eslint-plugin-babel": "^4.1.1", + "eslint-plugin-flowtype": "^2.30.3", "husky": "^0.13.2", "jest": "^19.0.2" }, diff --git a/start.sh b/start.sh index f544854..fa51165 100644 --- a/start.sh +++ b/start.sh @@ -19,4 +19,4 @@ mkdir -p /blinksocks && touch ${CONFIG_FILE} echo ">>> Generated configuration with random key..." echo ">>> Running blinksocks with ${CONFIG_FILE}" -pm2 start blinksocks -i 3 -- --config ${CONFIG_FILE} +pm2 start blinksocks-run -i 3 -- --config ${CONFIG_FILE} diff --git a/yarn.lock b/yarn.lock index c6ba2ee..2065cde 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1170,19 +1170,19 @@ eslint-config-babel@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/eslint-config-babel/-/eslint-config-babel-6.0.0.tgz#66feedf6ce6e04abe585cec1a65b5bcc96bed50a" -eslint-plugin-babel@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-babel/-/eslint-plugin-babel-4.1.0.tgz#837a74c092ad4d74f9fc74aed43f750906adc827" +eslint-plugin-babel@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-babel/-/eslint-plugin-babel-4.1.1.tgz#ef285c87039b67beb3bbd227f5b0eed4fb376b87" -eslint-plugin-flowtype@^2.30.0: - version "2.30.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.30.0.tgz#3054a265f9c8afe3046c3d41b72d32a736f9b4ae" +eslint-plugin-flowtype@^2.30.3: + version "2.30.3" + resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.30.3.tgz#57835d2c0ed388da7a2725803ec32af2f437c301" dependencies: lodash "^4.15.0" -eslint@^3.17.0: - version "3.17.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.17.0.tgz#e2704b09c5bae9fb49ee8bafeea3832c7257d498" +eslint@^3.17.1: + version "3.17.1" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.17.1.tgz#b80ae12d9c406d858406fccda627afce33ea10ea" dependencies: babel-code-frame "^6.16.0" chalk "^1.1.3"