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

Topic/path options #2

Merged
merged 3 commits into from Nov 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 17 additions & 6 deletions index.js
Expand Up @@ -8,12 +8,14 @@ var child = require('child_process');

var watchman = require('fb-watchman');

var minimist = require('minimist');

var which = require('which');

var client = new watchman.Client();

var cwd = process.cwd();

var watchDirectories = [path.join(cwd, 'src'), path.join(cwd, 'bower_components'), path.join(cwd, 'test')];

var subscriptionPrefix = 'pulp-';

function subscribeToWatch(watchDirectory, watch, relativePath, callback) {
Expand Down Expand Up @@ -62,7 +64,7 @@ function watchProject(watchDirectory, callback) {
});
}

function watch(callback) {
function watch(watchDirectories, callback) {
client.capabilityCheck({optional:[], required:['relative_root']}, function (error, res){
if (error) {
console.error('Watchman capability check failed. ' + error);
Expand All @@ -88,19 +90,28 @@ function watch(callback) {
}

function run() {
var pulp = path.join(__dirname, 'node_modules', '.bin', 'pulp');
var pulp = fs.realpathSync(which.sync('pulp'));

var args = process.argv.slice(2);

var argv = minimist(args);

var src = argv['src-path'] || 'src';

var dependency = argv['dependency-path'] || 'bower_components';

var test = argv['test-path'] || 'test';

var directories = [path.join(cwd, src), path.join(cwd, dependency), path.join(cwd, test)];

var proc = child.fork(pulp, args);

var change = function() {
proc.kill('SIGTERM');
console.log('Files have changed. Restarting...');
proc = child.fork(pulp, args);
};

watch(change);
watch(directories, change);
};

run();
6 changes: 5 additions & 1 deletion package.json
Expand Up @@ -14,8 +14,12 @@
"files": [
"index.js"
],
"peerDependencies": {
"pulp": "^5.0.0"
},
"dependencies": {
"fb-watchman": "^1.6.0",
"pulp": "^4.4.1"
"minimist": "^1.2.0",
"which": "^1.2.0"
}
}