From ac94e4c7b38afd141ec8d80dec9030299a95dbfc Mon Sep 17 00:00:00 2001 From: wangqingpeng Date: Tue, 4 Sep 2018 10:23:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=B1=95=E7=A4=BA=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E4=BA=8C=E7=BB=B4=E7=A0=81=20=20-q=20||=20-e=20=E8=A7=A6?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/anywhere | 27 ++++++++++++++++++++++++--- package.json | 1 + 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/bin/anywhere b/bin/anywhere index 94efacd..f0ee8ea 100755 --- a/bin/anywhere +++ b/bin/anywhere @@ -10,6 +10,7 @@ var connect = require('connect'); var serveStatic = require('serve-static'); var serveIndex = require('serve-index'); var fallback = require('connect-history-api-fallback'); +var qrcode = require('qrcode-terminal') var debug = require('debug'); debug.enable('anywhere'); @@ -23,10 +24,12 @@ var argv = require("minimist")(process.argv.slice(2), { 'hostname': 'h', 'dir': 'd', 'log': 'l', - 'fallback': 'f' + 'fallback': 'f', + 'QRcode': 'q', + 'QRcodeHttps': 'e' }, string: ['port', 'hostname', 'fallback'], - boolean: ['silent', 'log'], + boolean: ['silent', 'log', 'QRcode', 'QRcodeHttps'], 'default': { 'port': 8000, 'dir': process.cwd() @@ -44,6 +47,8 @@ if (argv.help) { console.log(" anywhere -d /home // /home as root"); console.log(" anywhere -l // print log"); console.log(" anywhere -f // Enable history fallback"); + console.log(" anywhere -q // show QRcode"); + console.log(" anywhere -e // show QRcode with https"); process.exit(0); } @@ -118,9 +123,15 @@ http.createServer(app).listen(port, function () { port = (port != 80 ? ':' + port : ''); var url = "http://" + hostname + port + '/'; console.log("Running at " + url); - if (!argv.silent) { + if (!argv.silent && !argv.QRcode && !argv.QRcodeHttps) { openURL(url); } + if (!!argv.QRcode) { + setTimeout(function(){ + console.log("This is your QR code"); + showQr(url) + },0) + } }); var options = { @@ -132,4 +143,14 @@ https.createServer(options, app).listen(secure, function () { secure = (secure != 80 ? ':' + secure : ''); var url = "https://" + hostname + secure + '/'; console.log("Also running at " + url); + if (!!argv.QRcodeHttps) { + console.log("This is your QR code with https link"); + showQr(url) + } }); + +var showQr = function(url) { + qrcode.generate(url, { + small: true + }); +} \ No newline at end of file diff --git a/package.json b/package.json index f18dd89..6870abe 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "connect-history-api-fallback": "^1.2.0", "debug": "^2.2.0", "minimist": "^1.2.0", + "qrcode-terminal": "^0.12.0", "serve-index": "^1.9.1", "serve-static": "^1.13.2" }, From 8febdcdabbbc62b71a41eeca6634fa68a9c1f547 Mon Sep 17 00:00:00 2001 From: wangqingpeng Date: Tue, 4 Sep 2018 10:37:13 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 5131fe7..a5df7de 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,10 @@ $ anywhere -h localhost -p 8888 $ anywhere -d ~/git/anywhere // or enable html5 history $ anywhere -f /index.html +// or with QRcode and silent +$ anywhere -q +// or with https QRcode and silent +$ anywhere -e ``` ## Help @@ -40,6 +44,8 @@ Usage: anywhere -h localhost // localhost as hostname anywhere -d /home // /home as root anywhere -f /index.html // Enable html5 history,the index is /index.html + anywhere -q // show QRcode + anywhere -e // show QRcode with https ``` ## Visit