Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for iBazel #370

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Command line parameters:
* `--wait=MILLISECONDS` - (default 100ms) wait for all changes, before reloading
* `--htpasswd=PATH` - Enables http-auth expecting htpasswd file located at PATH
* `--cors` - Enables CORS for any origin (reflects request origin, requests with credentials are supported)
* `--ibazel` - Enables the [iBazel notification protocol](https://github.com/bazelbuild/bazel-watcher)
* `--https=PATH` - PATH to a HTTPS configuration module
* `--https-module=MODULE_NAME` - Custom HTTPS module (e.g. `spdy`)
* `--proxy=ROUTE:URL` - proxy all requests for ROUTE to URL
Expand Down
20 changes: 19 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var fs = require('fs'),
open = require('opn'),
es = require("event-stream"),
os = require('os'),
chokidar = require('chokidar');
chokidar = require('chokidar'),
readline = require('readline');
require('colors');

var INJECTED_CODE = fs.readFileSync(path.join(__dirname, "injected.html"), "utf8");
Expand Down Expand Up @@ -369,6 +370,23 @@ LiveServer.start = function(options) {
ws.send(cssChange ? 'refreshcss' : 'reload');
});
}

if (options.ibazelListener) {
var rl = readline.createInterface({
input: process.stdin,
terminal: false,
});

rl.on('line', function (line) {
if (line === 'IBAZEL_BUILD_COMPLETED SUCCESS') {
clients.forEach(function (ws) {
if (ws)
ws.send(cssChange ? 'refreshcss' : 'reload');
});
}
})
}

LiveServer.watcher
.on("change", handleChange)
.on("add", handleChange)
Expand Down
7 changes: 6 additions & 1 deletion live-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var opts = {
proxy: [],
middleware: [],
logLevel: 2,
ibazelListener: false,
};

var homeDir = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
Expand Down Expand Up @@ -146,8 +147,12 @@ for (var i = process.argv.length - 1; i >= 2; --i) {
opts.middleware.push(arg.substring(13));
process.argv.splice(i, 1);
}
else if (arg === "--ibazel") {
opts.ibazelListener = true;
process.argv.splice(i, 1);
}
else if (arg === "--help" || arg === "-h") {
console.log('Usage: live-server [-v|--version] [-h|--help] [-q|--quiet] [--port=PORT] [--host=HOST] [--open=PATH] [--no-browser] [--browser=BROWSER] [--ignore=PATH] [--ignorePattern=RGXP] [--no-css-inject] [--entry-file=PATH] [--spa] [--mount=ROUTE:PATH] [--wait=MILLISECONDS] [--htpasswd=PATH] [--cors] [--https=PATH] [--https-module=MODULE_NAME] [--proxy=PATH] [PATH]');
console.log('Usage: live-server [-v|--version] [-h|--help] [-q|--quiet] [--port=PORT] [--host=HOST] [--open=PATH] [--no-browser] [--browser=BROWSER] [--ignore=PATH] [--ignorePattern=RGXP] [--no-css-inject] [--entry-file=PATH] [--spa] [--mount=ROUTE:PATH] [--wait=MILLISECONDS] [--htpasswd=PATH] [--cors] [--ibazel] [--https=PATH] [--https-module=MODULE_NAME] [--proxy=PATH] [PATH]');
process.exit();
}
else if (arg === "--test") {
Expand Down