-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathapi2code.js
More file actions
82 lines (78 loc) · 2.24 KB
/
api2code.js
File metadata and controls
82 lines (78 loc) · 2.24 KB
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
const inquirer = require('inquirer');
const generateInterface = require('../lib/api2code/generateInterface');
const generateCrud = require('../lib/api2code/generateCrud');
const { parserMap } = require('../lib/api2code/parser');
const { removeEmpty } = require('../lib/utils');
const { languages } = require('../lib/utils/constants');
const handleTargetMap = {
interface: generateInterface,
crud: generateCrud,
};
// main questions
const promptList = [
{
type: 'list',
name: 'target',
message: 'Please select the type of generation',
choices: Object.keys(handleTargetMap),
},
// {
// type: 'confirm',
// name: 'skip',
// message: 'skip all the files generated before ? ',
// },
{
type: 'list',
name: 'jsonType',
message: 'please select the type of json',
choices: Object.keys(parserMap),
when: ({ target }) => target === 'crud',
},
{
type: 'list',
name: 'language',
message: 'Please select the coding language you used',
choices: Object.keys(languages),
when: ({ target }) => target === 'crud',
},
// {
// type: 'list',
// name: 'requestLib',
// message: 'Please select the request library you used',
// choices: ['axios', 'fetch' /** graphQL */],
// when: ({ target }) => target === 'crud',
// },
// {
// type: 'list',
// name: 'codeStyle',
// message: 'Please select the style for code',
// choices: ['code-snippets', 'service'],
// when: ({ target }) => target === 'crud',
// },
];
// main program
const api2code = program => {
program
.command('api2code')
.alias('a2c')
.description('🌽 api translation typescript')
// .option('-u, --url <url>', 'api addres(domain or ip)', config.request.url)
// .option('-p, --path <path>', 'api path')
.requiredOption('-i, --input <input>', 'input json file')
.requiredOption('-o, --output <output>', 'output code file')
.action(options => {
const { output, input } = options;
inquirer.prompt(promptList).then(({ target, ...props }) => {
handleTargetMap[target](
removeEmpty({
// url,
// path,
output,
input,
...props,
}),
);
});
});
};
module.exports = api2code;