-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathconverter.js
53 lines (40 loc) · 1.13 KB
/
converter.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
exports.convert = convert;
exports.dispose = dispose;
var sassCompiler = require('./compiler');
var spawn = require('child_process').spawn;
var path = require('path');
var watcherProcess = null;
function convert(logger, projectDir, appDir, appResourcesDir, options) {
options = options || {};
var data = {
projectDir,
appDir,
appResourcesDir,
logger
};
if (options.watch) {
return createWatcher(data);
}
return sassCompiler.compile(data);
}
function createWatcher(data) {
if (watcherProcess) {
return;
}
watcherProcess = spawn(process.execPath, [ path.join(__dirname, "./watcher.js"), JSON.stringify({appDir: data.appDir, appResourcesDir: data.appResourcesDir, projectDir: data.projectDir })], { stdio: ["ignore", "ignore", "ignore", "ipc"] });
watcherProcess.on('error', error => {
throw new Error(error);
});
watcherProcess.on('message', message => {
if (message && message.logLevel) {
data.logger[message.logLevel](message.message);
}
});
return sassCompiler.compile(data);
}
function dispose() {
if (watcherProcess && watcherProcess.connected) {
watcherProcess.disconnect();
watcherProcess = null;
}
}