-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
59 lines (45 loc) · 1.39 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
#!/usr/bin/env node
const path = require('path');
const fs = require('fs')
const process = require('child_process');
const { cwd } = require('process');
const { Command } = require('commander');
const Message = require('./module/message')
const ErrorModule = require('./module/error')
const {
getRemoteName,
trimTitle,
handleTitle
} = require('./utils');
const program = new Command();
const message = new Message();
const error = new ErrorModule();
function shellAction (dirName, commandDir) {
const localName = trimTitle(dirName)
const remoteName = getRemoteName(localName)
if (!remoteName) {
error.titleNotExit()
}
process.exec(`fetcher --url="https://github.com/type-challenges/type-challenges/blob/main/questions/${remoteName}/template.ts"`, {
cwd: path.resolve(cwd(), commandDir)
}, error.command())
process.exec(`fetcher --url="https://github.com/type-challenges/type-challenges/blob/main/questions/${remoteName}/test-cases.ts"`, {
cwd: path.resolve(cwd(), commandDir)
}, error.command())
}
program
.version('0.1.0')
.argument("<dirName...>", 'folder name')
.action((dirName) => {
const commandDir = handleTitle(dirName)
console.log(path.resolve(cwd(), commandDir))
fs.mkdir(commandDir, {}, () => {
message.loading();
shellAction(dirName, commandDir)
})
})
program
.command("shell")
.action(() => {
})
program.parse(process.argv);