Browse Source

initial version

master
Brett Langdon 8 years ago
commit
8d158c8c3c
No known key found for this signature in database GPG Key ID: B664881177781B04
4 changed files with 2090 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +105
    -0
      main.js
  3. +1959
    -0
      package-lock.json
  4. +25
    -0
      package.json

+ 1
- 0
.gitignore View File

@ -0,0 +1 @@
node_modules/

+ 105
- 0
main.js View File

@ -0,0 +1,105 @@
var argv = require('yargs')
.example('$0 ./path/to/files')
.example('$0 -w source/scss -w source/js ./public')
.option('bind', {
alias: 'b',
describe: 'Host/port for static server to bind to',
type: 'string',
default: '127.0.0.1:3000',
})
.option('lrbind', {
alias: 'l',
describe: 'Host/port for LiveReload to bind to',
type: 'string',
default: '127.0.0.1:35729',
})
.option('watch', {
alias: 'w',
describe: 'Directory to watch for changes',
type: 'array',
})
.command('$0', '', function (yargs) {
yargs.positional('serve', {
type: 'string',
describe: 'The directory to serve static files from',
});
})
.argv;
// Parse static server host/port
var host = '127.0.0.1';
var port = 3000;
if (argv.bind) {
if (typeof argv.bind === 'number') {
port = argv.bind;
} else {
var bind = argv.bind.split(':', 2);
if (bind.length > 1) {
host = bind[0];
port = parseInt(bind[1]);
} else {
port = parseInt(bind[0]);
}
}
}
// Parse LiveReload server host/port
var lrhost = '127.0.0.1';
var lrport = 35729;
if (argv.lrbind) {
if (typeof argv.lrbind === 'number') {
lrport = argv.lrbind;
} else {
var lrbind = argv.lrbind.split(':', 2);
if (lrbind.length > 1) {
lrhost = lrbind[0];
lrport = parseInt(lrbind[1]);
} else {
lrport = parseInt(lrbind[0]);
}
}
}
// Parse directories LiveReload should watch
var watching = argv.watch || [];
if (typeof watching === 'string') {
watching = [watching];
}
// Parse directory to serve static files from
var serve = argv._[0] || process.cwd();
if (watching.length === 0) {
watching.push(serve);
}
var express = require('express');
var livereload = require('livereload');
var lrserver = livereload.createServer({
// We will start this manually later
noListen: true,
port: lrport,
host: lrhost,
});
var app = express();
app.use(require('connect-livereload')());
app.use(express.static(serve));
module.exports = {
app: app,
lrserver: lrserver,
};
if (!module.parent) {
app.listen(port, host, function () {
console.log('Server listening at http://' + host + ':' + port + '/');
});
lrserver.listen(function () {
console.log('LiveReload server listening at ws://' + lrhost + ':' + lrport + '/');
watching.forEach(function (fname) {
console.log('LiveReloading is watching ' + fname);
lrserver.watch(fname);
});
});
}

+ 1959
- 0
package-lock.json
File diff suppressed because it is too large
View File


+ 25
- 0
package.json View File

@ -0,0 +1,25 @@
{
"name": "livereload-server",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/brettlangdon/livereload-server.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/brettlangdon/livereload-server/issues"
},
"homepage": "https://github.com/brettlangdon/livereload-server#readme",
"dependencies": {
"connect-livereload": "^0.6.0",
"express": "^4.16.2",
"livereload": "^0.6.3",
"yargs": "^10.0.3"
}
}

Loading…
Cancel
Save