forked from siemonster/project-free
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatchman.js
140 lines (116 loc) · 4.62 KB
/
watchman.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
var watchman = require('fb-watchman');
var client = new watchman.Client();
var colors = require('colors');
var sys = require('sys');
var exec = require('child_process').exec;
var dir_of_interest = process.env.PROJECTPATH + '/domain';
var app_relative_path = 'domain';
client.capabilityCheck({optional: [], required: ['relative_root']},
function(error, resp) {
if (error) {
console.log(error);
client.end();
return;
}
// Initiate the watch
client.command(['watch-project', dir_of_interest],
function(error, resp) {
if (error) {
console.error('Error initiating watch:', error);
return;
}
if ('warning' in resp) {
console.log('warning: ', resp.warning);
}
console.log(('watch established on ' + resp.watch +
' | relative_path' + resp.relative_path).green);
make_subscriptions(client, resp.watch, app_relative_path);
});
// todo: watch gulpfile
});
function make_subscriptions(client, watch, relative_path) {
var sub_js = {
expression: ['allof', ['match', '*.js']],
fields: ['name', 'size', 'exists', 'type']
};
var sub_css = {
expression: ['anyof', ['match', '*.css'], ['match', '*.scss']],
fields: ['name', 'size', 'exists', 'type']
};
var sub_gulpfile = {
expression: ['allof', ['match', 'Gulpfile.js']],
fields: ['name', 'size', 'exists', 'type']
};
if (relative_path) {
sub_js.relative_root = relative_path;
sub_css.relative_root = relative_path;
sub_gulpfile.relative_root = process.env.PROJECTPATH;
}
client.command(['subscribe', watch, 'js_build_subscription', sub_js],
function(error, resp) {
if (error) {
// Probably an error in the subscription criteria
console.error('failed to subscribe: ', error);
return;
}
console.log(('\nsubscription ' + resp.subscribe + ' established').magenta);
});
client.command(['subscribe', watch, 'css_build_subscription', sub_css],
function(error, resp) {
if (error) {
// Probably an error in the subscription criteria
console.error('failed to subscribe: ', error);
return;
}
console.log(('\nsubscription ' + resp.subscribe + ' established').magenta);
// run build for external css files on the lunch
exec('gulp css-externals-build', function (err, stdout, stderr) {
console.log('stdout: ' + stdout);
if (stderr) console.log('stderr: ' + stderr);
});
}
);
client.command(['subscribe', watch, 'gulpfile_subscription', sub_gulpfile],
function(error, resp) {
if (error) {
// Probably an error in the subscription criteria
console.error('failed to subscribe: ', error);
return;
}
console.log(('\nsubscription ' + resp.subscribe + ' established').magenta);
});
client.on('subscription', function(resp) {
if (resp.subscription == 'js_build_subscription') {
exec('gulp js-build', function(err, stdout, stderr) {
console.log('stdout: \n' + stdout);
if(stderr) console.log('stderr: \m' + stderr);
});
}
if (resp.subscription == 'css_build_subscription') {
exec('gulp sass-build', function(err, stdout, stderr) {
console.log('stdout: \n' + stdout);
if(stderr) console.log('stderr: \m' + stderr);
});
}
if (resp.subscription == 'gulpfile_subscription') {
exec('gulp css-externals-build', function(err, stdout, stderr) {
console.log('stdout: \n' + stdout);
if(stderr) console.log('stderr: \m' + stderr);
});
exec('gulp js-build', function(err, stdout, stderr) {
console.log('stdout: \n' + stdout);
if(stderr) console.log('stderr: \m' + stderr);
});
}
for (var i in resp.files) {
var f = resp.files[i];
console.log('Changed file: ' + f.name);
}
});
client.on('connect', function(res) {
exec('gulp css-externals-build', function(err, stdout, stderr) {
console.log('stdout: \n' + stdout);
if(stderr) console.log('stderr: \m' + stderr);
});
});
}