Skip to content

Commit 2df9580

Browse files
committed
Merge branch 'dev'
2 parents 98be312 + acaa05b commit 2df9580

25 files changed

+2505
-3317
lines changed

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
doc
2+
node_modules

.eslintrc.js

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
node: true,
6+
es6: true,
7+
},
8+
9+
// add your custom rules here
10+
rules: {
11+
'accessor-pairs': 2,
12+
'arrow-spacing': [2, {
13+
'before': true,
14+
'after': true
15+
}],
16+
'block-spacing': [2, 'always'],
17+
'brace-style': [2, '1tbs', {
18+
'allowSingleLine': true
19+
}],
20+
'camelcase': [0, {
21+
'properties': 'always'
22+
}],
23+
'comma-dangle': [2, 'never'],
24+
'comma-spacing': [2, {
25+
'before': false,
26+
'after': true
27+
}],
28+
'comma-style': [2, 'last'],
29+
'constructor-super': 2,
30+
'curly': [2, 'multi-line'],
31+
'dot-location': [2, 'property'],
32+
'eol-last': 2,
33+
'eqeqeq': ["error", "always", {"null": "ignore"}],
34+
'generator-star-spacing': [2, {
35+
'before': true,
36+
'after': true
37+
}],
38+
'handle-callback-err': [2, '^(err|error)$'],
39+
'indent': [2, 2, {
40+
'SwitchCase': 1
41+
}],
42+
'jsx-quotes': [2, 'prefer-single'],
43+
'key-spacing': [2, {
44+
'beforeColon': false,
45+
'afterColon': true
46+
}],
47+
'keyword-spacing': [2, {
48+
'before': true,
49+
'after': true
50+
}],
51+
'new-cap': [2, {
52+
'newIsCap': true,
53+
'capIsNew': false
54+
}],
55+
'new-parens': 2,
56+
'no-array-constructor': 2,
57+
'no-caller': 2,
58+
'no-console': 'off',
59+
'no-class-assign': 2,
60+
'no-cond-assign': 2,
61+
'no-const-assign': 2,
62+
'no-control-regex': 0,
63+
'no-delete-var': 2,
64+
'no-dupe-args': 2,
65+
'no-dupe-class-members': 2,
66+
'no-dupe-keys': 2,
67+
'no-duplicate-case': 2,
68+
'no-empty-character-class': 2,
69+
'no-empty-pattern': 2,
70+
'no-eval': 2,
71+
'no-ex-assign': 2,
72+
'no-extend-native': 2,
73+
'no-extra-bind': 2,
74+
'no-extra-boolean-cast': 2,
75+
'no-extra-parens': [2, 'functions'],
76+
'no-fallthrough': 2,
77+
'no-floating-decimal': 2,
78+
'no-func-assign': 2,
79+
'no-implied-eval': 2,
80+
'no-inner-declarations': [2, 'functions'],
81+
'no-invalid-regexp': 2,
82+
'no-irregular-whitespace': 2,
83+
'no-iterator': 2,
84+
'no-label-var': 2,
85+
'no-labels': [2, {
86+
'allowLoop': false,
87+
'allowSwitch': false
88+
}],
89+
'no-lone-blocks': 2,
90+
'no-mixed-spaces-and-tabs': 2,
91+
'no-multi-spaces': 2,
92+
'no-multi-str': 2,
93+
'no-multiple-empty-lines': [2, {
94+
'max': 1
95+
}],
96+
'no-native-reassign': 2,
97+
'no-negated-in-lhs': 2,
98+
'no-new-object': 2,
99+
'no-new-require': 2,
100+
'no-new-symbol': 2,
101+
'no-new-wrappers': 2,
102+
'no-obj-calls': 2,
103+
'no-octal': 2,
104+
'no-octal-escape': 2,
105+
'no-path-concat': 2,
106+
'no-proto': 2,
107+
'no-redeclare': 2,
108+
'no-regex-spaces': 2,
109+
'no-return-assign': [2, 'except-parens'],
110+
'no-self-assign': 2,
111+
'no-self-compare': 2,
112+
'no-sequences': 2,
113+
'no-shadow-restricted-names': 2,
114+
'no-spaced-func': 2,
115+
'no-sparse-arrays': 2,
116+
'no-this-before-super': 2,
117+
'no-throw-literal': 2,
118+
'no-trailing-spaces': 2,
119+
'no-undef': 2,
120+
'no-undef-init': 2,
121+
'no-unexpected-multiline': 2,
122+
'no-unmodified-loop-condition': 2,
123+
'no-unneeded-ternary': [2, {
124+
'defaultAssignment': false
125+
}],
126+
'no-unreachable': 2,
127+
'no-unsafe-finally': 2,
128+
'no-unused-vars': [2, {
129+
'vars': 'all',
130+
'args': 'none'
131+
}],
132+
'no-useless-call': 2,
133+
'no-useless-computed-key': 2,
134+
'no-useless-constructor': 2,
135+
'no-useless-escape': 0,
136+
'no-whitespace-before-property': 2,
137+
'no-with': 2,
138+
'one-var': [2, {
139+
'initialized': 'never'
140+
}],
141+
'operator-linebreak': [2, 'after', {
142+
'overrides': {
143+
'?': 'before',
144+
':': 'before'
145+
}
146+
}],
147+
'padded-blocks': [2, 'never'],
148+
'quotes': [2, 'single', {
149+
'avoidEscape': true,
150+
'allowTemplateLiterals': true
151+
}],
152+
'semi': [2, 'never'],
153+
'semi-spacing': [2, {
154+
'before': false,
155+
'after': true
156+
}],
157+
'space-before-blocks': [2, 'always'],
158+
'space-before-function-paren': [2, 'never'],
159+
'space-in-parens': [2, 'never'],
160+
'space-infix-ops': 2,
161+
'space-unary-ops': [2, {
162+
'words': true,
163+
'nonwords': false
164+
}],
165+
'spaced-comment': [2, 'always', {
166+
'markers': ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ',']
167+
}],
168+
'template-curly-spacing': [2, 'never'],
169+
'use-isnan': 2,
170+
'valid-typeof': 2,
171+
'wrap-iife': [2, 'any'],
172+
'yield-star-spacing': [2, 'both'],
173+
'yoda': [2, 'never'],
174+
'prefer-const': 2,
175+
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
176+
'object-curly-spacing': [2, 'always', {
177+
objectsInObjects: false
178+
}],
179+
'array-bracket-spacing': [2, 'never']
180+
}
181+
}

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ language: node_js
22
node_js: 10
33
script:
44
- yarn
5-
- yarn build:swagger
5+
- yarn test-yaml
6+
- yarn test-json

Gruntfile.js

-49
This file was deleted.

README.md

+8-17
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,17 @@
2828

2929
Modify `package.json`, the `definition` is the input swagger file, the `dist` is the js where to output.
3030

31-
```json
32-
{
33-
"swagger": {
34-
"definition": "./example/swagger/swagger.json",
35-
"className": "API",
36-
"moduleName": "apis",
37-
"dist": "./example/dist"
38-
}
39-
}
40-
```
41-
4231
```bash
43-
yarn
44-
yarn build:swagger
32+
usage: swagger-builder.js [-h] [-v] [-f FILE] [-o OUTPUT]
33+
34+
Optional arguments:
35+
-h, --help Show this help message and exit.
36+
-v, --version Show program's version number and exit.
37+
-f FILE, --file FILE Swagger file to build
38+
-o OUTPUT, --output OUTPUT
39+
Js file to output
4540
```
4641
47-
## TODO
48-
49-
- support npm package
50-
5142
## Contributors
5243
- [kaisawind](https://github.com/kaisawind) - creator, maintainer
5344

bin/swagger-builder.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env node
2+
3+
'use strict'
4+
5+
/*eslint-disable no-console*/
6+
7+
// stdlib
8+
var fs = require('fs')
9+
10+
// 3rd-party
11+
var argparse = require('argparse')
12+
13+
// internal
14+
var builder = require('..')
15+
16+
// //////////////////////////////////////////////////////////////////////////////
17+
18+
var cli = new argparse.ArgumentParser({
19+
version: require('../package.json').version,
20+
addHelp: true
21+
})
22+
23+
cli.addArgument(['-f', '--file'], {
24+
help: 'Swagger file to build'
25+
})
26+
27+
cli.addArgument(['-o', '--output'], {
28+
help: 'Js file to output'
29+
})
30+
31+
// //////////////////////////////////////////////////////////////////////////////
32+
33+
var options = cli.parseArgs()
34+
35+
// //////////////////////////////////////////////////////////////////////////////
36+
37+
function readFile(filename, callback) {
38+
builder.SwaggerBuilder(filename, callback)
39+
}
40+
41+
readFile(options.file, (template) => {
42+
fs.writeFile(options.output, template, (error) => {
43+
if (error) {
44+
throw error
45+
}
46+
console.log('build ' + options.file + ' to ' + options.output + ' success')
47+
})
48+
})

example/dist/api.js

-54
This file was deleted.

0 commit comments

Comments
 (0)