@darabonba/python-generator 1.2.19 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChangeLog.md +0 -158
- package/lib/builtin.js +818 -0
- package/lib/generator.js +2708 -0
- package/lib/helper.js +422 -0
- package/package.json +6 -5
- package/tests/expected/alias/setup.py +79 -0
- package/tests/expected/alias/tea_python_tests/__init__.py +1 -0
- package/tests/expected/alias/tea_python_tests/client.py +35 -0
- package/tests/expected/annotation/tea_python_tests/__init__.py +1 -0
- package/tests/expected/annotation/tea_python_tests/client.py +93 -0
- package/tests/expected/annotation/tea_python_tests/models.py +37 -0
- package/tests/expected/api/tea_python_tests/__init__.py +1 -0
- package/tests/expected/api/tea_python_tests/client.py +106 -0
- package/tests/expected/builtin/tea_python_tests/client.py +685 -0
- package/tests/expected/comment/tea_python_tests/__init__.py +1 -0
- package/tests/expected/comment/tea_python_tests/client.py +288 -0
- package/tests/expected/comment/tea_python_tests/models.py +195 -0
- package/tests/expected/complex/tea_python_tests/__init__.py +1 -0
- package/tests/expected/complex/tea_python_tests/client.py +1169 -0
- package/tests/expected/complex/tea_python_tests/exceptions.py +39 -0
- package/tests/expected/complex/tea_python_tests/models.py +570 -0
- package/tests/expected/const/tea_python_tests/__init__.py +1 -0
- package/tests/expected/const/tea_python_tests/client.py +14 -0
- package/{src/langs/python/files/setup.py.tmpl → tests/expected/empty/setup.py} +11 -11
- package/tests/expected/empty/tea_python_tests/__init__.py +1 -0
- package/tests/expected/empty/tea_python_tests/client.py +10 -0
- package/tests/expected/exec/tea_python_tests/__init__.py +1 -0
- package/tests/expected/exec/tea_python_tests/exec_client.py +21 -0
- package/tests/expected/function/tea_python_tests/__init__.py +1 -0
- package/tests/expected/function/tea_python_tests/client.py +64 -0
- package/tests/expected/import/setup.py +78 -0
- package/tests/expected/import/tea_python_tests/__init__.py +1 -0
- package/tests/expected/import/tea_python_tests/client.py +29 -0
- package/tests/expected/map/tea_python_tests/__init__.py +1 -0
- package/tests/expected/map/tea_python_tests/client.py +39 -0
- package/tests/expected/model/tea_python_tests/__init__.py +1 -0
- package/tests/expected/model/tea_python_tests/client.py +10 -0
- package/tests/expected/model/tea_python_tests/exceptions.py +28 -0
- package/tests/expected/model/tea_python_tests/models.py +780 -0
- package/tests/expected/multi/tea_python_tests/api.py +95 -0
- package/tests/expected/multi/tea_python_tests/client.py +40 -0
- package/tests/expected/multi/tea_python_tests/lib/util.py +19 -0
- package/tests/expected/multi/tea_python_tests/model/user.py +26 -0
- package/tests/expected/multi/tea_python_tests/model/user_exceptions.py +83 -0
- package/tests/expected/multi/tea_python_tests/model/user_models.py +145 -0
- package/tests/expected/statements/tea_python_tests/__init__.py +1 -0
- package/tests/expected/statements/tea_python_tests/client.py +86 -0
- package/tests/expected/super/tea_python_tests/__init__.py +1 -0
- package/tests/expected/super/tea_python_tests/client.py +16 -0
- package/tests/expected/typedef/setup.py +77 -0
- package/tests/expected/typedef/tea_python_tests/__init__.py +1 -0
- package/tests/expected/typedef/tea_python_tests/client.py +74 -0
- package/tests/expected/typedef/tea_python_tests/models.py +42 -0
- package/tests/fixtures/alias/Darafile +11 -0
- package/tests/fixtures/alias/libraries/Alias/Darafile +11 -0
- package/tests/fixtures/alias/libraries/Alias-Symbol/Darafile +11 -0
- package/tests/fixtures/builtin/Darafile +6 -0
- package/tests/fixtures/builtin/main.dara +333 -0
- package/tests/fixtures/complex/libraries/import.dara +18 -11
- package/tests/fixtures/complex/main.dara +452 -103
- package/tests/fixtures/import/libraries/Darafile +1 -1
- package/tests/fixtures/import/pack/Darafile +3 -0
- package/tests/fixtures/map/libraries/Darafile +3 -0
- package/tests/fixtures/map/libraries/import.dara +4 -0
- package/tests/fixtures/map/main.dara +17 -2
- package/tests/fixtures/model/.libraries.json +3 -0
- package/tests/fixtures/model/Darafile +5 -2
- package/tests/fixtures/model/libraries/Darafile +20 -0
- package/tests/fixtures/model/libraries/import.dara +27 -0
- package/tests/fixtures/model/main.dara +60 -42
- package/tests/fixtures/multi/.libraries.json +3 -0
- package/tests/fixtures/multi/Darafile +12 -0
- package/tests/fixtures/multi/api.dara +20 -0
- package/tests/fixtures/multi/lib/util.dara +5 -0
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/Teafile +68 -0
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/main.tea +244 -0
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/util.tea +2 -0
- package/tests/fixtures/multi/main.dara +32 -0
- package/tests/fixtures/multi/model/user.dara +35 -0
- package/tests/{python3.tests.js → main.tests.js} +107 -65
- package/tests/output/alias/setup.py +79 -0
- package/tests/output/alias/tea_python_tests/client.py +35 -0
- package/{src/langs/python2/files/setup.py.tmpl → tests/output/annotation/setup.py} +19 -24
- package/tests/output/annotation/tea_python_tests/client.py +93 -0
- package/tests/output/annotation/tea_python_tests/models.py +37 -0
- package/tests/output/api/setup.py +77 -0
- package/tests/output/api/tea_python_tests/client.py +106 -0
- package/tests/output/builtin/setup.py +77 -0
- package/tests/output/builtin/tea_python_tests/client.py +685 -0
- package/tests/output/comment/setup.py +77 -0
- package/tests/output/comment/tea_python_tests/client.py +288 -0
- package/tests/output/comment/tea_python_tests/models.py +195 -0
- package/tests/output/complex/setup.py +77 -0
- package/tests/output/complex/tea_python_tests/client.py +1169 -0
- package/tests/output/complex/tea_python_tests/exceptions.py +39 -0
- package/tests/output/complex/tea_python_tests/models.py +570 -0
- package/tests/output/const/setup.py +77 -0
- package/tests/output/const/tea_python_tests/client.py +14 -0
- package/tests/output/empty/setup.py +77 -0
- package/tests/output/empty/tea_python_tests/client.py +10 -0
- package/tests/output/exec/setup.py +77 -0
- package/tests/output/exec/tea_python_tests/exec_client.py +21 -0
- package/tests/output/function/setup.py +77 -0
- package/tests/output/function/tea_python_tests/client.py +64 -0
- package/tests/output/import/setup.py +78 -0
- package/tests/output/import/tea_python_tests/client.py +29 -0
- package/tests/output/map/setup.py +77 -0
- package/tests/output/map/tea_python_tests/client.py +39 -0
- package/tests/output/model/setup.py +77 -0
- package/tests/output/model/tea_python_tests/client.py +10 -0
- package/tests/output/model/tea_python_tests/exceptions.py +28 -0
- package/tests/output/model/tea_python_tests/models.py +780 -0
- package/tests/output/multi/setup.py +77 -0
- package/tests/output/multi/tea_python_tests/api.py +95 -0
- package/tests/output/multi/tea_python_tests/client.py +40 -0
- package/tests/output/multi/tea_python_tests/lib/util.py +19 -0
- package/tests/output/multi/tea_python_tests/model/user.py +26 -0
- package/tests/output/multi/tea_python_tests/model/user_exceptions.py +83 -0
- package/tests/output/multi/tea_python_tests/model/user_models.py +145 -0
- package/tests/output/statements/setup.py +77 -0
- package/tests/output/statements/tea_python_tests/client.py +86 -0
- package/tests/output/super/setup.py +77 -0
- package/tests/output/super/tea_python_tests/client.py +16 -0
- package/tests/output/typedef/setup.py +78 -0
- package/tests/output/typedef/tea_python_tests/client.py +74 -0
- package/tests/output/typedef/tea_python_tests/models.py +42 -0
- package/src/generator.js +0 -231
- package/src/langs/common/combinator.js +0 -193
- package/src/langs/common/config.js +0 -60
- package/src/langs/common/enum.js +0 -179
- package/src/langs/common/items.js +0 -551
- package/src/langs/common/package_info.js +0 -53
- package/src/langs/python/combinator.js +0 -1898
- package/src/langs/python/config.js +0 -169
- package/src/langs/python/files/.gitignore.tmpl +0 -5
- package/src/langs/python/files/__init__.py.tmpl +0 -1
- package/src/langs/python/package_info.js +0 -78
- package/src/langs/python2/combinator.js +0 -1770
- package/src/langs/python2/config.js +0 -162
- package/src/langs/python2/files/.gitignore.tmpl +0 -5
- package/src/langs/python2/files/__init__.py.tmpl +0 -1
- package/src/langs/python2/package_info.js +0 -78
- package/src/lib/debug.js +0 -55
- package/src/lib/emitter.js +0 -95
- package/src/lib/helper.js +0 -207
- package/src/resolver/base.js +0 -282
- package/src/resolver/client.js +0 -1013
- package/src/resolver/model.js +0 -159
- package/tests/common.tests.js +0 -244
- package/tests/lib.tests.js +0 -269
- package/tests/python2.tests.js +0 -283
- package/tests/resolver.tests.js +0 -434
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const defaultConfig = require('../common/config');
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
...defaultConfig,
|
|
7
|
-
indent: ' ',
|
|
8
|
-
ext: '.py',
|
|
9
|
-
keywords: {
|
|
10
|
-
general: [
|
|
11
|
-
'and',
|
|
12
|
-
'as',
|
|
13
|
-
'assert',
|
|
14
|
-
'break',
|
|
15
|
-
'class',
|
|
16
|
-
'continue',
|
|
17
|
-
'def',
|
|
18
|
-
'del',
|
|
19
|
-
'elif',
|
|
20
|
-
'else',
|
|
21
|
-
'except',
|
|
22
|
-
'finally',
|
|
23
|
-
'for',
|
|
24
|
-
'from',
|
|
25
|
-
'False',
|
|
26
|
-
'global',
|
|
27
|
-
'if',
|
|
28
|
-
'import',
|
|
29
|
-
'in',
|
|
30
|
-
'is',
|
|
31
|
-
'lambda',
|
|
32
|
-
'not',
|
|
33
|
-
'None',
|
|
34
|
-
'or',
|
|
35
|
-
'pass',
|
|
36
|
-
'raise',
|
|
37
|
-
'return',
|
|
38
|
-
'try',
|
|
39
|
-
'True',
|
|
40
|
-
'while',
|
|
41
|
-
'with',
|
|
42
|
-
'yield'
|
|
43
|
-
],
|
|
44
|
-
function: [],
|
|
45
|
-
class: [],
|
|
46
|
-
param_variables: [
|
|
47
|
-
'exec',
|
|
48
|
-
'print',
|
|
49
|
-
'self'
|
|
50
|
-
]
|
|
51
|
-
},
|
|
52
|
-
symbolMap: {
|
|
53
|
-
'ASSIGN': '=',
|
|
54
|
-
'EQ': '==',
|
|
55
|
-
'NOT': 'NOT',
|
|
56
|
-
'AND': 'and',
|
|
57
|
-
'OR': 'or',
|
|
58
|
-
'PLUS': '+',
|
|
59
|
-
'SUB': '-',
|
|
60
|
-
'MULTI': '*',
|
|
61
|
-
'DIV': '/',
|
|
62
|
-
'POWER': '^',
|
|
63
|
-
'GREATER': '>',
|
|
64
|
-
'GREATER_EQ': '>=',
|
|
65
|
-
'LESS': '<',
|
|
66
|
-
'LESS_EQ': '<=',
|
|
67
|
-
'REVERSE': 'not ',
|
|
68
|
-
'CONCAT': '+'
|
|
69
|
-
},
|
|
70
|
-
typeMap: {
|
|
71
|
-
'string': 'str',
|
|
72
|
-
'boolean': 'bool',
|
|
73
|
-
'number': 'int',
|
|
74
|
-
'integer': 'int',
|
|
75
|
-
'object': 'dict',
|
|
76
|
-
'map': 'dict',
|
|
77
|
-
'bytes': 'bytes',
|
|
78
|
-
'long': 'long',
|
|
79
|
-
'array': 'list',
|
|
80
|
-
'readable': 'READABLE',
|
|
81
|
-
'writable': 'WRITABLE',
|
|
82
|
-
'float': 'float',
|
|
83
|
-
'double': 'float',
|
|
84
|
-
'int64': 'long',
|
|
85
|
-
'int32': 'int',
|
|
86
|
-
'int16': 'int',
|
|
87
|
-
'int8': 'int',
|
|
88
|
-
'ulong': 'int',
|
|
89
|
-
'uint8': 'int',
|
|
90
|
-
'uint16': 'int',
|
|
91
|
-
'uint32': 'int',
|
|
92
|
-
'uint64': 'long',
|
|
93
|
-
'any': 'any',
|
|
94
|
-
'void': 'None',
|
|
95
|
-
'null': 'None'
|
|
96
|
-
},
|
|
97
|
-
type: {
|
|
98
|
-
'long': 'base',
|
|
99
|
-
'unicode': 'base',
|
|
100
|
-
'basestring': 'base',
|
|
101
|
-
'str': 'base',
|
|
102
|
-
'int': 'base',
|
|
103
|
-
'float': 'base',
|
|
104
|
-
'bool': 'base',
|
|
105
|
-
'None': 'base',
|
|
106
|
-
'dict': 'complex',
|
|
107
|
-
'list': 'complex',
|
|
108
|
-
'READABLE': 'custom',
|
|
109
|
-
'WRITABLE': 'custom'
|
|
110
|
-
},
|
|
111
|
-
exceptionMap: {
|
|
112
|
-
'BASE': 'Exception',
|
|
113
|
-
},
|
|
114
|
-
model: {
|
|
115
|
-
dir: 'models',
|
|
116
|
-
mode: 'single_file',
|
|
117
|
-
include: [],
|
|
118
|
-
},
|
|
119
|
-
client: {
|
|
120
|
-
defaultName: 'client',
|
|
121
|
-
include: []
|
|
122
|
-
},
|
|
123
|
-
tea: {
|
|
124
|
-
core: {
|
|
125
|
-
name: 'Tea.core.TeaCore',
|
|
126
|
-
doAction: 'do_action',
|
|
127
|
-
allowRetry: 'allow_retry',
|
|
128
|
-
sleep: 'sleep',
|
|
129
|
-
getBackoffTime: 'get_backoff_time',
|
|
130
|
-
isRetryable: 'is_retryable',
|
|
131
|
-
toModel: 'toModel',
|
|
132
|
-
merge: 'merge',
|
|
133
|
-
toMap: 'to_map',
|
|
134
|
-
fromMap: 'from_map'
|
|
135
|
-
},
|
|
136
|
-
model: {
|
|
137
|
-
name: 'Tea.model.TeaModel'
|
|
138
|
-
},
|
|
139
|
-
converter: {
|
|
140
|
-
name: 'Tea.converter.TeaConverter',
|
|
141
|
-
toStr: 'to_str',
|
|
142
|
-
toUnicode: 'to_unicode',
|
|
143
|
-
toString: 'to_string',
|
|
144
|
-
toBytes: 'to_bytes'
|
|
145
|
-
},
|
|
146
|
-
response: {
|
|
147
|
-
name: 'Tea.response.TeaResponse'
|
|
148
|
-
},
|
|
149
|
-
request: {
|
|
150
|
-
name: 'Tea.request.TeaRequest'
|
|
151
|
-
},
|
|
152
|
-
exception: {
|
|
153
|
-
name: 'Tea.exceptions.TeaException'
|
|
154
|
-
},
|
|
155
|
-
error: {
|
|
156
|
-
name: 'Tea.exceptions.TeaException'
|
|
157
|
-
},
|
|
158
|
-
exceptionUnretryable: {
|
|
159
|
-
name: 'Tea.exceptions.UnretryableException'
|
|
160
|
-
},
|
|
161
|
-
}
|
|
162
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '0.0.1'
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const debug = require('../../lib/debug');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
const BasePackageInfo = require('../common/package_info');
|
|
7
|
-
|
|
8
|
-
const OPTION_LOCAL = 1;
|
|
9
|
-
const OPTION_SOURCE = 2;
|
|
10
|
-
const OPTION_RENDER = 4;
|
|
11
|
-
|
|
12
|
-
// file_name : OPTIONS
|
|
13
|
-
const files = {
|
|
14
|
-
'.gitignore': OPTION_LOCAL,
|
|
15
|
-
'setup.py': OPTION_LOCAL | OPTION_RENDER | OPTION_SOURCE,
|
|
16
|
-
'LICENSE': OPTION_SOURCE,
|
|
17
|
-
'README-CN.md': OPTION_SOURCE | OPTION_RENDER,
|
|
18
|
-
'README.md': OPTION_SOURCE | OPTION_RENDER
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
class PackageInfo extends BasePackageInfo {
|
|
22
|
-
emit(packageInfo, requirePackage) {
|
|
23
|
-
let outputDir = path.join(this.config.dir, '../');
|
|
24
|
-
if (packageInfo.outputDir) {
|
|
25
|
-
outputDir = path.join(outputDir, packageInfo.outputDir);
|
|
26
|
-
}
|
|
27
|
-
if (!fs.existsSync(outputDir)) {
|
|
28
|
-
fs.mkdirSync(outputDir, {
|
|
29
|
-
recursive: true
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
const checkParams = ['name', 'desc', 'github'];
|
|
33
|
-
checkParams.forEach(key => {
|
|
34
|
-
if (typeof packageInfo[key] === 'undefined') {
|
|
35
|
-
debug.stack('need config packageInfo.' + key, packageInfo);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
let requires = [];
|
|
40
|
-
requirePackage.forEach(packageItem => {
|
|
41
|
-
let packages = packageItem.split(':');
|
|
42
|
-
let [moduleName, version] = packages;
|
|
43
|
-
const requireItem = `${moduleName}>=${version}, <${parseInt(version.split('.')[0])+1}.0.0`;
|
|
44
|
-
requires.push(requireItem);
|
|
45
|
-
});
|
|
46
|
-
const date = new Date();
|
|
47
|
-
const keywords = JSON.stringify(packageInfo.name.split(/_|-/));
|
|
48
|
-
const params = {
|
|
49
|
-
email: '',
|
|
50
|
-
author: '',
|
|
51
|
-
package: this.config.package,
|
|
52
|
-
require: JSON.stringify(requires, null, 4),
|
|
53
|
-
namespace: this.config.package.split('.').join('\\\\'),
|
|
54
|
-
date: ('0' + date.getDate()).slice(-2) + '/' + ('0' + (date.getMonth() + 1)).slice(-2) + '/' + date.getFullYear(),
|
|
55
|
-
keywords: keywords,
|
|
56
|
-
...packageInfo
|
|
57
|
-
};
|
|
58
|
-
Object.keys(files).forEach(filename => {
|
|
59
|
-
let content = '';
|
|
60
|
-
let optional = files[filename];
|
|
61
|
-
if (optional & OPTION_SOURCE && packageInfo.files && packageInfo.files[filename]) {
|
|
62
|
-
let filepath = path.isAbsolute(packageInfo.files[filename]) ?
|
|
63
|
-
packageInfo.files[filename] : path.join(this.config.pkgDir, packageInfo.files[filename]);
|
|
64
|
-
content = fs.readFileSync(filepath).toString();
|
|
65
|
-
} else if (optional & OPTION_LOCAL) {
|
|
66
|
-
content = fs.readFileSync(path.join(__dirname, './files/' + filename + '.tmpl')).toString();
|
|
67
|
-
}
|
|
68
|
-
if (content !== '') {
|
|
69
|
-
if (optional & OPTION_RENDER) {
|
|
70
|
-
content = this.render(content, params);
|
|
71
|
-
}
|
|
72
|
-
fs.writeFileSync(path.join(outputDir, filename), content);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
module.exports = PackageInfo;
|
package/src/lib/debug.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
const os = require('os');
|
|
3
|
-
|
|
4
|
-
var count = 0;
|
|
5
|
-
|
|
6
|
-
function dump(...data) {
|
|
7
|
-
data.forEach(d => {
|
|
8
|
-
console.log(d);
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function halt(...data) {
|
|
13
|
-
this.dump(...data);
|
|
14
|
-
process.exit(-1);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function jump(jumpNumber = 0, ...data) {
|
|
18
|
-
if (count === jumpNumber) {
|
|
19
|
-
this.halt(...data);
|
|
20
|
-
count = 0;
|
|
21
|
-
} else {
|
|
22
|
-
count++;
|
|
23
|
-
}
|
|
24
|
-
return count;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function stack(...data) {
|
|
28
|
-
let msg = '';
|
|
29
|
-
if (data[0] && typeof data[0] === 'string') {
|
|
30
|
-
msg = data[0];
|
|
31
|
-
data = data.slice(1);
|
|
32
|
-
}
|
|
33
|
-
this.dump(...data);
|
|
34
|
-
throw new Error(msg);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function warning(...data) {
|
|
38
|
-
let msg = '';
|
|
39
|
-
if (data[0] && typeof data[0] === 'string') {
|
|
40
|
-
msg = data[0];
|
|
41
|
-
data = data.slice(1);
|
|
42
|
-
}
|
|
43
|
-
this.dump(...data);
|
|
44
|
-
if (msg.length) {
|
|
45
|
-
process.stdout.write(`\x1b[33m[WARNING] ${msg}\x1b[0m${os.EOL}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
module.exports = {
|
|
50
|
-
dump,
|
|
51
|
-
halt,
|
|
52
|
-
stack,
|
|
53
|
-
jump,
|
|
54
|
-
warning
|
|
55
|
-
};
|
package/src/lib/emitter.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const os = require('os');
|
|
6
|
-
|
|
7
|
-
class Emitter {
|
|
8
|
-
constructor(option = {}) {
|
|
9
|
-
this.config = {
|
|
10
|
-
indent: ' ',
|
|
11
|
-
eol: 'auto', // \n | \r\n | auto
|
|
12
|
-
dir: '',
|
|
13
|
-
layer: '',
|
|
14
|
-
filename: '',
|
|
15
|
-
ext: '',
|
|
16
|
-
...option
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
this.output = '';
|
|
20
|
-
|
|
21
|
-
this.eol = this.config.eol === 'auto' ? os.EOL : this.config.eol;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
indent(level) {
|
|
25
|
-
if (typeof level === 'undefined') {
|
|
26
|
-
level = 0;
|
|
27
|
-
}
|
|
28
|
-
return this.config.indent.repeat(level);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
emit(str = '', level) {
|
|
32
|
-
this.output += this.indent(level) + str;
|
|
33
|
-
return this;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
emitln(str = '', level) {
|
|
37
|
-
this.emit(str + this.eol, level);
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
emits(level, ...strs) {
|
|
42
|
-
strs.forEach(str => {
|
|
43
|
-
this.emitln(str, level);
|
|
44
|
-
});
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
erase(lenght) {
|
|
49
|
-
this.output = this.output.substring(0, this.output.length - lenght);
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
savePath() {
|
|
54
|
-
return path.join(
|
|
55
|
-
this.config.dir,
|
|
56
|
-
this.config.layer.split('.').join(path.sep),
|
|
57
|
-
this.config.filename + this.config.ext
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
save(append = false) {
|
|
62
|
-
if (!this.config.dir) {
|
|
63
|
-
throw new Error('`option.dir` should not be empty');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (!this.config.filename) {
|
|
67
|
-
throw new Error('filename cannot be empty');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const targetPath = this.savePath();
|
|
71
|
-
|
|
72
|
-
if (!fs.existsSync(path.dirname(targetPath))) {
|
|
73
|
-
fs.mkdirSync(path.dirname(targetPath), {
|
|
74
|
-
recursive: true
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (append && fs.existsSync(targetPath)) {
|
|
79
|
-
fs.appendFileSync(targetPath, this.output);
|
|
80
|
-
} else {
|
|
81
|
-
fs.writeFileSync(targetPath, this.output);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
this.output = '';
|
|
85
|
-
|
|
86
|
-
const consoleInfo = append ? 'append file : ' : 'save path : ';
|
|
87
|
-
if (this.config.showInfo) {
|
|
88
|
-
console.log('');
|
|
89
|
-
console.log(`\x1b[32${consoleInfo}${path.resolve(targetPath)}\x1b[0m`);
|
|
90
|
-
console.log('');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
module.exports = Emitter;
|
package/src/lib/helper.js
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const DSL = require('@darabonba/parser');
|
|
4
|
-
|
|
5
|
-
let config = {};
|
|
6
|
-
|
|
7
|
-
function _config(langConfig = null) {
|
|
8
|
-
if (null !== langConfig) {
|
|
9
|
-
config = langConfig;
|
|
10
|
-
}
|
|
11
|
-
return config;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function _upperFirst(str) {
|
|
15
|
-
if (!str) {
|
|
16
|
-
return '';
|
|
17
|
-
}
|
|
18
|
-
return str[0].toUpperCase() + str.substring(1);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function _camelCase(str, split = '_') {
|
|
22
|
-
if (str.indexOf(split) > -1) {
|
|
23
|
-
let tmp = str.split(split);
|
|
24
|
-
tmp = tmp.map((s, i) => {
|
|
25
|
-
if (s.length > 0 && i !== 0) {
|
|
26
|
-
return _upperFirst(s);
|
|
27
|
-
}
|
|
28
|
-
return s;
|
|
29
|
-
});
|
|
30
|
-
str = tmp.join('');
|
|
31
|
-
}
|
|
32
|
-
return str;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function _lowerFirst(str) {
|
|
36
|
-
return str[0].toLowerCase() + str.substring(1);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function _subModelName(name) {
|
|
40
|
-
return name.split('.').map((name) => _upperFirst(name)).join('');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function _string(str) {
|
|
44
|
-
if (str.string === '""') {
|
|
45
|
-
return '\\"\\"';
|
|
46
|
-
}
|
|
47
|
-
return str.string.replace(/([^\\])"+|^"/g, function (str) {
|
|
48
|
-
return str.replace(/"/g, '\\"');
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function _isBasicType(type) {
|
|
53
|
-
return DSL.util.isBasicType(type);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function _deepClone(obj) {
|
|
57
|
-
return JSON.parse(JSON.stringify(obj));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function _avoidKeywords(str) {
|
|
61
|
-
if (config.keywords.general.indexOf(str.toLowerCase()) > -1) {
|
|
62
|
-
return str + '_';
|
|
63
|
-
}
|
|
64
|
-
return str;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function _avoidFuncKeywords(str) {
|
|
68
|
-
if (config.keywords.general.indexOf(str.toLowerCase()) > -1
|
|
69
|
-
|| config.keywords.function.indexOf(str.toLowerCase()) > -1) {
|
|
70
|
-
return str + '_';
|
|
71
|
-
}
|
|
72
|
-
return str;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function _avoidClassKeywords(str) {
|
|
76
|
-
if (config.keywords.general.indexOf(str.toLowerCase()) > -1
|
|
77
|
-
|| config.keywords.class.indexOf(str.toLowerCase()) > -1) {
|
|
78
|
-
return str + '_';
|
|
79
|
-
}
|
|
80
|
-
return str;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function _avoidVarKeywords(str) {
|
|
84
|
-
if (config.keywords.general.indexOf(str.toLowerCase()) > -1
|
|
85
|
-
|| config.keywords.param_variables.indexOf(str.toLowerCase()) > -1) {
|
|
86
|
-
return str + '_';
|
|
87
|
-
}
|
|
88
|
-
return str;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function _convertStaticParam(param) {
|
|
92
|
-
if (param === '__response') {
|
|
93
|
-
param = config.response;
|
|
94
|
-
} else if (param === '__request') {
|
|
95
|
-
param = config.request;
|
|
96
|
-
}
|
|
97
|
-
return param;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function _isKeywords(str) {
|
|
101
|
-
return config.keywords.general.indexOf(str.toLowerCase()) > -1;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function _modify(modify) {
|
|
105
|
-
if (Array.isArray(modify)) {
|
|
106
|
-
return modify.filter((m) => config.modifyOrder.indexOf(m) > -1)
|
|
107
|
-
.map((m) => _modify(m)).sort(function (a, b) {
|
|
108
|
-
return config.modifyOrder.indexOf(a.toUpperCase()) - config.modifyOrder.indexOf(b.toUpperCase());
|
|
109
|
-
}).join(' ');
|
|
110
|
-
}
|
|
111
|
-
return modify.toLowerCase();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function _symbol(str) {
|
|
115
|
-
if (config.symbolMap[str]) {
|
|
116
|
-
return config.symbolMap[str];
|
|
117
|
-
}
|
|
118
|
-
throw new Error(`Unsupported symbol : ${str}`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function _exception(str) {
|
|
122
|
-
if (config.exceptionMap[str]) {
|
|
123
|
-
return config.exceptionMap[str];
|
|
124
|
-
}
|
|
125
|
-
return str;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function _isSnakeCase(str) {
|
|
129
|
-
if (/[^\da-z_]/.test(str)) {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (/\d/.test(str[0])) {
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function _toCamelCase(str) {
|
|
141
|
-
if (!str) {
|
|
142
|
-
return '';
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const word = str.split('_');
|
|
146
|
-
let tmp = '';
|
|
147
|
-
word.forEach(w => {
|
|
148
|
-
tmp += _upperFirst(w);
|
|
149
|
-
});
|
|
150
|
-
return tmp;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function _toSnakeCase(str) {
|
|
154
|
-
if (!str) {
|
|
155
|
-
return '';
|
|
156
|
-
}
|
|
157
|
-
let res = '';
|
|
158
|
-
let tmp = '';
|
|
159
|
-
for (const c of str) {
|
|
160
|
-
if (/[A-Z|0-9]/.test(c)) {
|
|
161
|
-
tmp += c;
|
|
162
|
-
} else {
|
|
163
|
-
if (tmp.length > 0) {
|
|
164
|
-
res += res === '' ? tmp.toLowerCase() : '_' + tmp.toLowerCase();
|
|
165
|
-
tmp = '';
|
|
166
|
-
}
|
|
167
|
-
res += c;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (tmp.length > 0) {
|
|
171
|
-
res += '_' + tmp.toLowerCase();
|
|
172
|
-
}
|
|
173
|
-
res = res.replace(/-/g, '_');
|
|
174
|
-
if (res[0] === '_' && str[0] !== '_') {
|
|
175
|
-
res = res.substring(1);
|
|
176
|
-
}
|
|
177
|
-
return res;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function _escape(str) {
|
|
181
|
-
return str.includes('-') ? `${str}` : str;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
module.exports = {
|
|
186
|
-
_config,
|
|
187
|
-
_escape,
|
|
188
|
-
_upperFirst,
|
|
189
|
-
_camelCase,
|
|
190
|
-
_string,
|
|
191
|
-
_subModelName,
|
|
192
|
-
_lowerFirst,
|
|
193
|
-
_isBasicType,
|
|
194
|
-
_deepClone,
|
|
195
|
-
_avoidKeywords,
|
|
196
|
-
_avoidFuncKeywords,
|
|
197
|
-
_avoidClassKeywords,
|
|
198
|
-
_avoidVarKeywords,
|
|
199
|
-
_convertStaticParam,
|
|
200
|
-
_isKeywords,
|
|
201
|
-
_modify,
|
|
202
|
-
_symbol,
|
|
203
|
-
_exception,
|
|
204
|
-
_toSnakeCase,
|
|
205
|
-
_toCamelCase,
|
|
206
|
-
_isSnakeCase
|
|
207
|
-
};
|