Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add --reload option on component build --watch #549

Merged
merged 2 commits into from

7 participants

@wryk wryk changed the title from add --reload option on component build --watch (#514) to add --reload option on component build --watch
@vendethiel

shouldn't it imply --watch ?

@wryk

actually --reload need an explicit --watch, should i make an implicit --watch on --reload ?

@vendethiel

Either require it or make it implicit, imho.

@vendethiel

Haha oh wow thanks @jonathanong :)

@jonathanong

haha i always see you commenting and being helpful in every repo on github, so why not? :D

@vendethiel

Travis failure looks like a transient failure ? Seems like it's #548

@wryk

wow, @Nami-Doc in component organization, nice :3

first travis failure is my fault, but now it's just a malformed json from bitbucket on component install

@jonathanong

yeah, i should fix that.

@vendethiel

I wonder thogh, should this really be in the core ? Do we consider it's a common enough case ?
I see how --watch is useful for nearly every component but I'm not that sure for --reload

(I'm actually wondering if people later will come and ask for another option to change port and stuff haha)

@jonathanong

dunno. sounds like more options ~_~

these option lists are getting too long.

i'm not even a big fan of reload. makes sense for css, but sometimes reloading js just messes things up. but i think it's important for a lot of devs workflow.

@jonathanong

anyone wanna try this out?

@tj
tj commented

I'm not sure we even need watch really, just introduces a race between viewing something and having it build, vs building on demand

@jonathanong

it's for components though. apps shouldn't be using it, but components don't have middleware to build on demand.

@tj
tj commented

ah yeah true that makes more sense

@hallas

having played around with a few webkit apps I really love watch, and for dev flow, I guess live reload is a neat feature

@wryk

i forget that pull request i rebuild and now travis pass, others things to add ?

@trevorgerhardt

Looks good to me

@trevorgerhardt trevorgerhardt merged commit d92e91c into componentjs:master

1 check passed

Details continuous-integration/travis-ci The Travis CI build passed
@chemzqm

How to let the users know that they should add livereload script in the html file to make livereload works?

@wryk

I'll add a note in component/guide api.md file tonight

@wryk wryk deleted the wryk:add/watch-livereload branch
@wryk

tonigth

ah ah ah ah :<
componentjs/guide@c55b9a4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 30 additions and 2 deletions.
  1. +28 −1 bin/component-build
  2. +2 −1  package.json
View
29 bin/component-build
@@ -7,6 +7,7 @@ var program = require('commander');
program
.usage('component build [scripts] [styles] [files]')
.option('-w, --watch', 'watch for file changes and rebuild automatically')
+ .option('-r, --reload', 'refresh livereload server on file changes (works only with --watch)')
.option('-o, --out <dir>', 'output directory defaulting to ./build', 'build')
.option('-n, --name <file>', 'base name for build files defaulting to build', 'build')
.option('-d, --dev', 'build development dependencies, use aliases, and use sourceURLs')
@@ -51,6 +52,7 @@ var fs = require('fs');
var exists = fs.existsSync || path.existsSync;
var args = program.args;
var log = utils.log;
+var slice = Array.prototype.slice;
// object of which files to build
var builds;
@@ -97,7 +99,7 @@ var options = {
copy: program.copy,
};
-var watching = program.watch;
+var watching = program.watch || program.reload;
var resolving = false;
var build;
@@ -130,6 +132,29 @@ process.stdin.on('data', function (data) {
}
});
+if (!program.reload) return;
+
+var server = require('tiny-lr-fork')();
+server.listen(35729);
+
+server.on('error', function (err) {
+ if (err.code === 'EADDRINUSE') {
+ utils.fatal('livereload port 35729 is already in use by another process');
+ }
+
+ utils.fatal(err);
+});
+
+function reload() {
+ if (program.reload) {
+ server.changed({
+ body: {
+ files: slice.call(arguments)
+ }
+ });
+ }
+}
+
function resolve() {
if (resolving) return;
resolving = true;
@@ -163,6 +188,7 @@ function buildScripts() {
log('build', jsPath + ' in '
+ (Date.now() - start) + 'ms - '
+ (js.length / 1024 | 0) + 'kb');
+ reload(jsPath);
})
}
@@ -177,6 +203,7 @@ function buildStyles() {
log('build', cssPath + ' in '
+ (Date.now() - start) + 'ms - '
+ (css.length / 1024 | 0) + 'kb');
+ reload(cssPath);
})
}
View
3  package.json
@@ -32,7 +32,8 @@
"debug": "*",
"open": "~0.0.4",
"cogent": "~0.4.3",
- "co": "^3.0.0"
+ "co": "^3.0.0",
+ "tiny-lr-fork": "0.0.5"
},
"devDependencies": {
"mocha": "1",
Something went wrong with that request. Please try again.