-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclaat.js
41 lines (33 loc) · 1.06 KB
/
claat.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
'use strict';
const childprocess = require('child_process');
const spawn = childprocess.spawn;
const http = require('http');
const fs = require('fs');
// claat is a wrapper around the claat tool.
//
// cwd - codelabs content dir
// cmd - claat command, either 'update' or 'export'
// auth - auth token to use
// fmt - output format, e.g. 'html'
// args - an array of source doc IDs or codelab names (IDs)
// callback - an async task callback function
// Based on: https://github.com/googlecodelabs/tools/blob/master/site/tasks/helpers/claat.js
exports.run = (cwd, cmd, auth, fmt, args, callback) => {
args.unshift(cmd, '-auth', auth, '-f', fmt);
const proc = spawn('./claat', args, {cwd: cwd, env: process.env });
// Get process stdout
let output = '';
proc.stderr.on('data', (data) => {
//Here is where the output goes
console.log('stderr: ' + data);
data = data.toString();
output += data;
});
// Handle error
proc.on('close', async (e) => {
if (e) {
throw new Error(e);
}
await callback(output);
});
};