-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.js
47 lines (36 loc) · 1.11 KB
/
run.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
const { homedir, platform } = require('os');
const fs = require('fs');
const { join } = require('path');
const { promisify } = require('util');
const exec = promisify(require('child_process').exec);
const filePath = join(homedir(), '.cycles.json');
async function run(name) {
console.log(filePath);
const jsonData = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
const match = name.match(/([a-zA-Z0-9_-]+)(\[(\d+)\])?/);
if (!match) return;
const identifier = match[1];
const index = match[3];
const configuration = jsonData.configurations.find(
(config) => config.name === identifier
);
if (configuration.type != platform()) {
console.error("Error: Current OS doesn't match the type entry");
return;
}
const scripts = configuration.scripts;
if (index) {
if (scripts[index]) {
const { stdout } = await exec(scripts[index]);
console.log(stdout.trim());
}
} else {
for (const script of scripts) {
const { stdout } = await exec(script);
console.log(stdout.trim());
}
}
}
module.exports = {
run,
};