forked from lgwebdream/fe-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (31 loc) · 997 Bytes
/
Copy pathindex.js
File metadata and controls
33 lines (31 loc) · 997 Bytes
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
const fs = require('promise-fs');
const { resolve } = require('path');
const request = require('../request');
const { removeEmpty } = require('../../utils');
const quicktypeJSON = require('../../utils/quicktypeJSON');
const generateInterface = options => {
let babyData;
if (options.body) {
babyData = require(options.body);
}
console.log('Interface', options, babyData);
request(
removeEmpty({
method: options.httpMethod,
url: `${options.url}${options.path}`,
data: babyData,
}),
)
.then(({ data }) => {
quicktypeJSON('TypeScript', 'JSON', JSON.stringify(data))
.then(({ lines }) => {
console.log(lines.join('\n'));
fs.writeFile(resolve(process.cwd(), options.output), lines.join('\n'))
.then(res => console.log(res))
.catch(err => console.error(err));
})
.catch(err => console.log(err));
})
.catch(err => console.error(err));
};
module.exports = generateInterface;