-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·90 lines (76 loc) · 2.38 KB
/
index.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
#!/usr/bin/env node
var inquirer = require("inquirer");
var cp = require("child_process");
const {read} = require("node-yaml")
const path = require("path")
const os = require("os")
const configFilePath = path.join(os.homedir(), '.run-in-iterm2.yaml')
function formatCommand(command){
if(typeof command === 'string'){
return [command]
}else{
return command
}
}
async function main(){
let { defaultPath, defaultCommand, projects } = await read(configFilePath)
projects = projects.map(project => {
if(typeof project === 'string'){
project = {
name: project,
title: project,
}
}else if(!project.title){
project = {
...project,
title: project.name
}
}
project = {
command: defaultCommand,
path: path.join(defaultPath, project.name),
...project
}
project.command = formatCommand(project.command)
return project
})
inquirer
.prompt([
{
type: "list",
name: "project",
message: "请选择项目",
choices: projects.map(e => ({
name: e.name,
value: e,
}))
}
])
.then(answers => {
cp.exec("open /Applications/iTerm.app", (error, stdout, stderr) => {
if (!error) {
let { project } = answers;
let job = cp.spawn("python3", [
"/Users/futunn/run_futu/run.py",
project.title,
project.path,
...project.command
]);
job.stdout.on("data", data => {
console.log(`${data}`);
});
job.stderr.on("data", data => {
console.error(`${data}`);
});
job.on("close", code => {
if(!code){
console.log(`🎈 run success 🎈`);
}else{
console.error(`run failed!`);
}
});
}
});
});
}
main()