src/GenerateApi.js   A
last analyzed

Size

Lines of Code 56

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
nc 1
dl 0
loc 56
rs 10
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A GenerateApi.js ➔ ??? 0 13 1
1
const fs            = require('fs'),
2
      swagger       = require('swagger-vue'),
3
      parse         = require('./2.0/generator-api/parser'),
4
      codegen       = require('./2.0/generator-api/generator'),
5
      BaseGenerator = require('./BaseGenerator')
6
7
/**
8
 * @class GenerateApi
9
 * Generate api with VUE generator
10
 *
11
 * @property {string} filename Source swagger filename
12
 * @property {GeneratorOptions} options Generator options
13
 * @property {Swagger20} data Swagger data
14
 */
15
class GenerateApi extends BaseGenerator {
16
    /**
17
     *
18
     * @param {String} filename
19
     * @param {GeneratorOptions|undefined} options
20
     */
21
    constructor(filename, options) {
22
        super()
23
24
        this.filename = filename
25
26
        this.options = options || {}
27
        this.outFile = options.outFile || __dirname + '/../dist/'
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
28
        this._checkFile()
29
        this._content       = fs.readFileSync(this.filename)
30
        this.data           = this._parseData()
31
        this.data.modelPath = options.modelPath || 'docs/models'
32
        this.data.docPath   = options.docsPath || 'docs'
33
    }
34
35
    /**
36
     * Generate vue.js client
37
     */
38
    generate() {
39
        let data       = parse({
40
            swagger   : this.data,
41
            moduleName: this.options.moduleName,
42
            className : this.options.className
43
        })
44
        let codeResult = codegen(data)
45
46
        fs.writeFileSync(this.outFile, codeResult)
47
    }
48
}
49
50
/**
51
 *
52
 * @ignore module.exports
53
 * @ignore exports
54
 */
55
56
module.exports = GenerateApi