Skip to content

Commit

Permalink
Merge pull request #1 from fernandomoraes/feature-cwd
Browse files Browse the repository at this point in the history
Adding cwd parameter
  • Loading branch information
fernandomoraes authored Jan 29, 2021
2 parents 0c148f3 + f11bd77 commit 75c72dc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
```

## Parameters

The following parameters can be used:

```
tiny-livereload-server \
cwd src
```
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]:fernandomoraes/tiny-livereload.git",
Expand All @@ -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"
}
}
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '</head>';

const cwd = argv.cwd ? `${process.cwd()}/${argv.cwd}` : process.cwd();

const LIVERELOAD_FRAGMENT = `
<script>
const protocol = window.location.protocol === 'http:' ? 'ws' : 'wss';
Expand All @@ -41,7 +45,7 @@ function startWatcher() {
ignoreInitial: true
};

const watcher = chokidar.watch(process.cwd(), options);
const watcher = chokidar.watch(cwd, options);

watcher.on('all', (event, pathFile) => {
const isCss = path.extname(pathFile) === '.css';
Expand All @@ -53,7 +57,7 @@ function startWatcher() {
function startServer() {
const server = http.createServer((req, res) => {
const safeRequestPath = path.normalize(req.url).replace(/^(\.\.[\/\\])+/, '');
const filePath = path.join(process.cwd(), safeRequestPath);
const filePath = path.join(cwd, safeRequestPath);

const injectLiveReload = ['', 'html'].indexOf(path.extname(filePath)) > -1;

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==

minimist@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==

[email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
Expand Down

0 comments on commit 75c72dc

Please sign in to comment.