Skip to content

Commit

Permalink
some code additions
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammaddadu committed Feb 10, 2017
1 parent efd562c commit a21fb86
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
46 changes: 46 additions & 0 deletions bin/watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');
const exec = require('child_process').exec;
const p = (...args) => path.resolve.apply(path.resolve, [__dirname, '../', ...args]);

const DIRS_TO_WATCH = [
p('dist'),
p('src')
];

const FILTERS = {
JS: [/\.js/gi],
TS: [/\.ts(\.d)?/gi]
}

const ACTION_MAP = {
JS: [stopServer, startServer]
}

var serverInstance;

function onFileChanged(eventType, filename) {
console.log('file %s: %s', eventType, filename);
// add debounce
}

function startServer() {
serverInstance = exec('npm run start', (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
console.log(stdout);
});
}

function stopServer() {
serverInstance.kill('SIGHUP');
}

DIRS_TO_WATCH.forEach((dir) => {
fs.watch(dir, {encoding: 'buffer'}, onFileChanged)
});
startServer();
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"dist/"
],
"scripts": {
"start": "npm run build; node dist/server.js",
"watch": "node -e \"console.log('implement watch');\"",
"build": "tsc",
"clean": "rimraf dist",
"deploy": "git pull --rebase origin master && git push origin master",
Expand Down
7 changes: 0 additions & 7 deletions src/index.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('hello world');
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"compileOnSave": false,
"files": [
"./src/index.ts",
"./src/server.ts",
"./typings/main.d.ts"
]
}

0 comments on commit a21fb86

Please sign in to comment.