Skip to content

Commit

Permalink
feat: add file watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharygolba committed Jun 12, 2016
1 parent 5425c51 commit 6bc225a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 35 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lux-framework",
"version": "0.0.1-beta.10",
"version": "0.0.1-beta.11",
"description": "A MVC style Node.js framework for building lightning fast JSON APIs",
"repository": "https://github.com/postlight/lux",
"keywords": [
Expand Down
75 changes: 41 additions & 34 deletions src/packages/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,38 +68,43 @@ export default function CLI() {
.option('-e, --environment [env]', '(Default: development)')
.option('-p, --port [port]', '(Default: 4000)')
.action(async ({ environment = 'development', port = 4000 } = {}) => {
const rescue = (err) => {
console.error(err);
exit(1);
};

await tryCatch(async () => {
const compiler = await createCompiler(PWD, environment);
let isRunning = false;

compiler.watch({
poll: false,
aggregateTimeout: 300
}, async (err, stats) => {
if (err) {
return rescue(err);
}
process.env.NODE_ENV = environment;

if (isMaster) {
const rescue = (err) => {
console.error(err);
exit(1);
};

await tryCatch(async () => {
const compiler = await createCompiler(PWD, environment);
let isRunning = false;

compiler.watch({
poll: false,
aggregateTimeout: 300
}, async (err, stats) => {
if (err) {
return rescue(err);
}

if (isMaster) {
displayStats(stats, isRunning);
if (isMaster) {
displayStats(stats, isRunning);

if (isRunning) {
process.emit('update');
if (isRunning) {
process.emit('update');
}
}
}

if (!isRunning) {
process.env.NODE_ENV = environment;
await serve(port);
isRunning = true;
}
});
}, rescue);
if (!isRunning) {
await serve(port);
isRunning = true;
}
});
}, rescue);
} else {
await serve(port);
}
});

cli
Expand Down Expand Up @@ -156,12 +161,14 @@ export default function CLI() {
const compiler = await createCompiler(PWD, NODE_ENV);

compiler.run(async (err) => {
if (err) {
rescue(err);
} else {
await dbCreate();
exit(0);
}
tryCatch(async () => {
if (err) {
rescue(err);
} else {
await dbCreate();
exit(0);
}
}, rescue);
});
}, rescue);
});
Expand Down
1 change: 1 addition & 0 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'path';

import Logger from '../src/packages/logger';
import loader from '../src/packages/loader';
import { createCompiler } from '../src/packages/compiler';
Expand Down

0 comments on commit 6bc225a

Please sign in to comment.