UNPKG

1.26 kBJavaScriptView Raw
1'use strict'
2
3const ModelsGenerator = require('./models/ModelsGenerator')
4const fs = require('fs')
5const net = require('tiny_request')
6
7net.get('https://core.telegram.org/bots/api', data => {
8 const generator = new ModelsGenerator(data)
9
10 const models = generator.generateModels()
11
12 console.info(`${models.length} models generated\n`)
13
14 models.forEach(model => {
15 fs.writeFile(`./lib/models/${model.name}.js`, model.modelCode, err => {
16 if(err) {
17 return console.error(`Failed to save model: ${model.name}`, err)
18 }
19 console.info(`Saved model: ${model.name}`)
20 })
21 })
22
23 fs.writeFile(`./lib/models/Models.js`, generateAllModelsExport(models), err => {
24 if(err) {
25 return console.error(`Failed to save models export file:`, err)
26 }
27 console.info(`Saved models export file`)
28 })
29
30})
31
32function generateAllModelsExport(models) {
33 let code = ``
34 code += `module.exports = {\n`
35
36 models.forEach(model => code += ` ${model.name}: require('./${model.name}'),\n`)
37 code += ` InputMessageContent: require('./InputMessageContent'),\n`
38 code += ` InlineQueryResult: require('./InlineQueryResult'),\n`
39
40 code += '}'
41
42 return code
43}
\No newline at end of file