From f11bd77666a43cc863f6069bf6f951ab8befaafd Mon Sep 17 00:00:00 2001 From: Fernando Moraes Date: Thu, 28 Jan 2021 21:05:18 -0300 Subject: [PATCH] Adding cwd parameter --- README.md | 13 +++++++++++-- package.json | 5 +++-- src/index.js | 8 ++++++-- yarn.lock | 5 +++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 68222c3..28f1a60 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,17 @@ There is only one rule, there is no configuration npm install -g @moraes/tiny-livereload-server ``` -inside project`s root: +Inside project`s root: ``` tiny-livereload-server -``` \ No newline at end of file +``` + +## Parameters + +The following parameters can be used: + +``` +tiny-livereload-server \ + cwd src +``` \ No newline at end of file diff --git a/package.json b/package.json index da25f5b..ab5e6eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moraes/tiny-livereload-server", - "version": "1.1.0", + "version": "1.2.0", "description": "tiny web live reload", "main": "src/index.js", "repository": "git@github.com:fernandomoraes/tiny-livereload.git", @@ -15,8 +15,9 @@ "dependencies": { "chokidar": "^3.4.2", "event-stream": "^4.0.1", + "minimist": "^1.2.5", "open": "^7.1.0", "send": "^0.17.1", - "ws": "^7.3.1" + "ws": "^7.3.1" } } diff --git a/src/index.js b/src/index.js index 2ebc860..33e3682 100755 --- a/src/index.js +++ b/src/index.js @@ -10,12 +10,16 @@ const send = require('send'); const open = require('open'); const chokidar = require('chokidar'); +const argv = require('minimist')(process.argv.slice(2)); + const ws = new WebSocket.Server({ noServer: true }); const liveReloadWsConnections = []; const SERVER_PORT = 3027; const LIVERELOAD_INJECT_TAG = ''; +const cwd = argv.cwd ? `${process.cwd()}/${argv.cwd}` : process.cwd(); + const LIVERELOAD_FRAGMENT = `