-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.js
38 lines (32 loc) · 1.06 KB
/
convert.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
const core = require('@actions/core');
const cp = require('child_process');
const executable = core.getInput('executable');
const runConverter = async (filePath) => {
const converter = cp.spawn('node', [executable, filePath], {
stdio: ['ignore', 'ipc', 'pipe'],
});
return new Promise((resolve, reject) => {
converter.stderr.on('data', (data) => {
converter.kill('SIGABRT');
reject(new Error(data.toString()));
});
converter.on('message', (message) => {
const parsed = JSON.parse(message);
switch (parsed.type) {
case 'error': {
converter.kill('SIGABRT');
reject(new Error(message));
return;
}
case 'progress':
console.log('PROGRESS: Working on %s (%d out of %d)', parsed.currentArtboardName, parsed.currentArtboard, parsed.totalArtboards);
return;
case 'warning':
console.warn('WARNING: %s', parsed.message);
return;
}
});
converter.on('exit', (code) => resolve());
});
};
module.exports.runConverter = runConverter;