@darabonba/python-generator 2.0.0 → 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/lib/generator.js +10 -6
- package/package.json +1 -1
- package/tests/expected/complex/tea_python_tests/client.py +5 -4
- package/tests/expected/multi/tea_python_tests/model/user.py +3 -0
- package/tests/fixtures/complex/main.dara +1 -0
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/Teafile +7 -1
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/util.tea +2 -0
- package/tests/fixtures/multi/model/user.dara +2 -0
- package/tests/output/complex/tea_python_tests/client.py +5 -4
- package/tests/output/multi/tea_python_tests/model/user.py +3 -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/files/setup.py.tmpl +0 -74
- 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/files/setup.py.tmpl +0 -82
- 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/lib/generator.js
CHANGED
|
@@ -59,7 +59,6 @@ class Visitor {
|
|
|
59
59
|
// 新增:用于存储已使用的类型
|
|
60
60
|
this.isAsyncFunction = false; // 新增:用于标记是否为异步函数
|
|
61
61
|
this.isStaticFunction = true; // 新增:用于标记是否为非静态函数
|
|
62
|
-
this.clientName = new Map(); // 新增:用于存储importName
|
|
63
62
|
// this.moduleDir = this.config.modelDirName || 'Models'; // 新增,用于存储models文件
|
|
64
63
|
|
|
65
64
|
this.output = '';
|
|
@@ -274,6 +273,8 @@ setup(
|
|
|
274
273
|
this.notes = ast.notes;
|
|
275
274
|
this.builtin = getBuiltin(this);
|
|
276
275
|
ast.innerModule = new Map();
|
|
276
|
+
|
|
277
|
+
this.clientName = new Map();
|
|
277
278
|
this.packageInfo = {};
|
|
278
279
|
this.usedTypes = [];
|
|
279
280
|
this.imports = [];
|
|
@@ -566,7 +567,9 @@ setup(
|
|
|
566
567
|
this.emit('def __init__(self):\n', level + 2);
|
|
567
568
|
}
|
|
568
569
|
if (ast.initBody && ast.initBody.stmts.length !==0 ) {
|
|
570
|
+
this.isStaticFunction = false;
|
|
569
571
|
this.visitStmts(ast.initBody, level + 4);
|
|
572
|
+
this.isStaticFunction = true;
|
|
570
573
|
} else {
|
|
571
574
|
this.emit('pass\n', level + 4);
|
|
572
575
|
}
|
|
@@ -628,14 +631,15 @@ setup(
|
|
|
628
631
|
throw new Error(`The '${aliasId}' has no Python supported.`);
|
|
629
632
|
}
|
|
630
633
|
let className = _camelCase(pyPkg.clientName || 'client');
|
|
634
|
+
let filename = _snakeCase(className);
|
|
631
635
|
let classNamespace = pyPkg.package;
|
|
632
636
|
let models = 'models';
|
|
633
637
|
let exceptions = 'exceptions';
|
|
634
638
|
if(inner && pkg.exports[inner]) {
|
|
635
639
|
let pyPath = pkg.exports[inner];
|
|
636
|
-
|
|
637
|
-
models = filename
|
|
638
|
-
exceptions = filename
|
|
640
|
+
filename = pyPath.split(path.sep).slice(-1)[0].replace(/(\.tea)$|(\.spec)$|(\.dara)$/gi, '');
|
|
641
|
+
models = filename + '_models';
|
|
642
|
+
exceptions = filename + '_exceptions';
|
|
639
643
|
const arr = pyPath.split(path.sep).slice(1, -1);
|
|
640
644
|
arr.map(key => {
|
|
641
645
|
classNamespace += '.' + _snakeCase(key);
|
|
@@ -646,7 +650,7 @@ setup(
|
|
|
646
650
|
const aliasName = this.getAliasName(className, aliasId);
|
|
647
651
|
this.packageInfo[aliasId] = {
|
|
648
652
|
aliasName: aliasName || className,
|
|
649
|
-
fileName:
|
|
653
|
+
fileName: filename,
|
|
650
654
|
clientName: className,
|
|
651
655
|
namemespace: classNamespace,
|
|
652
656
|
models: models,
|
|
@@ -1954,7 +1958,7 @@ setup(
|
|
|
1954
1958
|
current = ast.propertyPathTypes[i];
|
|
1955
1959
|
}
|
|
1956
1960
|
}
|
|
1957
|
-
this.emit(`${expr}[
|
|
1961
|
+
this.emit(`${expr}[`);
|
|
1958
1962
|
this.visitExpr(ast.accessKey, level);
|
|
1959
1963
|
this.emit(']');
|
|
1960
1964
|
}
|
package/package.json
CHANGED
|
@@ -29,8 +29,9 @@ class Client(SourceClient):
|
|
|
29
29
|
source_config: source_models.Config,
|
|
30
30
|
):
|
|
31
31
|
super().__init__(source_config)
|
|
32
|
-
|
|
32
|
+
self._configs[0] = source_config
|
|
33
33
|
test = SourceClient(source_config)
|
|
34
|
+
self.print_data(DaraCore.to_map(source_config), 'test')
|
|
34
35
|
|
|
35
36
|
def complex_1(
|
|
36
37
|
self,
|
|
@@ -978,7 +979,7 @@ class Client(SourceClient):
|
|
|
978
979
|
'b',
|
|
979
980
|
'c'
|
|
980
981
|
]
|
|
981
|
-
|
|
982
|
+
configs[3] = config
|
|
982
983
|
return configs
|
|
983
984
|
|
|
984
985
|
@staticmethod
|
|
@@ -992,7 +993,7 @@ class Client(SourceClient):
|
|
|
992
993
|
'c'
|
|
993
994
|
]
|
|
994
995
|
}
|
|
995
|
-
|
|
996
|
+
data["configs"][3] = config
|
|
996
997
|
return data.get("configs")
|
|
997
998
|
|
|
998
999
|
@staticmethod
|
|
@@ -1000,7 +1001,7 @@ class Client(SourceClient):
|
|
|
1000
1001
|
request: main_models.ComplexRequest,
|
|
1001
1002
|
config: str,
|
|
1002
1003
|
) -> None:
|
|
1003
|
-
|
|
1004
|
+
request.configs.value[0] = config
|
|
1004
1005
|
|
|
1005
1006
|
@staticmethod
|
|
1006
1007
|
def map_access(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
# This file is auto-generated, don't edit it. Thanks.
|
|
3
3
|
from __future__ import annotations
|
|
4
|
+
from alibabacloud_tea_util.util import Utils
|
|
4
5
|
from tea_python_tests.lib.util import Util
|
|
5
6
|
from typing import Generator, AsyncGenerator
|
|
6
7
|
|
|
@@ -12,12 +13,14 @@ class Client:
|
|
|
12
13
|
|
|
13
14
|
@staticmethod
|
|
14
15
|
def test() -> Generator[str, None, None]:
|
|
16
|
+
Utils.test()
|
|
15
17
|
it = Util.test_1()
|
|
16
18
|
for test in it:
|
|
17
19
|
yield test
|
|
18
20
|
|
|
19
21
|
@staticmethod
|
|
20
22
|
async def test_async() -> AsyncGenerator[str, None, None]:
|
|
23
|
+
Utils.test()
|
|
21
24
|
it = Util.test_1()
|
|
22
25
|
for test in it:
|
|
23
26
|
yield test
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
"name": "Util",
|
|
4
4
|
"version": "0.2.11",
|
|
5
5
|
"main": "./main.tea",
|
|
6
|
+
"exports": {
|
|
7
|
+
"Util": "./util.tea"
|
|
8
|
+
},
|
|
6
9
|
"releases": {
|
|
7
10
|
"go": "github.com/alibabacloud-go/tea-utils/v2/service:v2.0.4",
|
|
8
11
|
"ts": "@alicloud/tea-util:^1.4.7",
|
|
@@ -29,7 +32,10 @@
|
|
|
29
32
|
},
|
|
30
33
|
"python": {
|
|
31
34
|
"package": "alibabacloud_tea_util",
|
|
32
|
-
"clientName": "client"
|
|
35
|
+
"clientName": "client",
|
|
36
|
+
"exports": {
|
|
37
|
+
"Util": "Utils"
|
|
38
|
+
}
|
|
33
39
|
},
|
|
34
40
|
"python2": {
|
|
35
41
|
"package": "alibabacloud_tea_util",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import DARAUtil;
|
|
2
|
+
import DARAUtil.Util as Utils;
|
|
2
3
|
import "../lib/util" Util;
|
|
3
4
|
|
|
4
5
|
|
|
@@ -13,6 +14,7 @@ model Info extends BaseInfo {
|
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
static async function test(): asyncIterator[string]{
|
|
17
|
+
Utils.test();
|
|
16
18
|
var it:iterator[string] = Util.test1();
|
|
17
19
|
for(var test : it) {
|
|
18
20
|
yield test;
|
|
@@ -29,8 +29,9 @@ class Client(SourceClient):
|
|
|
29
29
|
source_config: source_models.Config,
|
|
30
30
|
):
|
|
31
31
|
super().__init__(source_config)
|
|
32
|
-
|
|
32
|
+
self._configs[0] = source_config
|
|
33
33
|
test = SourceClient(source_config)
|
|
34
|
+
self.print_data(DaraCore.to_map(source_config), 'test')
|
|
34
35
|
|
|
35
36
|
def complex_1(
|
|
36
37
|
self,
|
|
@@ -978,7 +979,7 @@ class Client(SourceClient):
|
|
|
978
979
|
'b',
|
|
979
980
|
'c'
|
|
980
981
|
]
|
|
981
|
-
|
|
982
|
+
configs[3] = config
|
|
982
983
|
return configs
|
|
983
984
|
|
|
984
985
|
@staticmethod
|
|
@@ -992,7 +993,7 @@ class Client(SourceClient):
|
|
|
992
993
|
'c'
|
|
993
994
|
]
|
|
994
995
|
}
|
|
995
|
-
|
|
996
|
+
data["configs"][3] = config
|
|
996
997
|
return data.get("configs")
|
|
997
998
|
|
|
998
999
|
@staticmethod
|
|
@@ -1000,7 +1001,7 @@ class Client(SourceClient):
|
|
|
1000
1001
|
request: main_models.ComplexRequest,
|
|
1001
1002
|
config: str,
|
|
1002
1003
|
) -> None:
|
|
1003
|
-
|
|
1004
|
+
request.configs.value[0] = config
|
|
1004
1005
|
|
|
1005
1006
|
@staticmethod
|
|
1006
1007
|
def map_access(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
# This file is auto-generated, don't edit it. Thanks.
|
|
3
3
|
from __future__ import annotations
|
|
4
|
+
from alibabacloud_tea_util.util import Utils
|
|
4
5
|
from tea_python_tests.lib.util import Util
|
|
5
6
|
from typing import Generator, AsyncGenerator
|
|
6
7
|
|
|
@@ -12,12 +13,14 @@ class Client:
|
|
|
12
13
|
|
|
13
14
|
@staticmethod
|
|
14
15
|
def test() -> Generator[str, None, None]:
|
|
16
|
+
Utils.test()
|
|
15
17
|
it = Util.test_1()
|
|
16
18
|
for test in it:
|
|
17
19
|
yield test
|
|
18
20
|
|
|
19
21
|
@staticmethod
|
|
20
22
|
async def test_async() -> AsyncGenerator[str, None, None]:
|
|
23
|
+
Utils.test()
|
|
21
24
|
it = Util.test_1()
|
|
22
25
|
for test in it:
|
|
23
26
|
yield test
|
package/src/generator.js
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const debug = require('./lib/debug');
|
|
6
|
-
|
|
7
|
-
const { _deepClone } = require('./lib/helper');
|
|
8
|
-
const ClientResolver = require('./resolver/client');
|
|
9
|
-
const ModelResolver = require('./resolver/model');
|
|
10
|
-
|
|
11
|
-
class Generator {
|
|
12
|
-
constructor(meta = {}, lang = 'python') {
|
|
13
|
-
if (!meta.outputDir) {
|
|
14
|
-
throw new Error('`option.outputDir` should not empty');
|
|
15
|
-
}
|
|
16
|
-
this.lang = lang;
|
|
17
|
-
this.typedef = meta[lang] && meta[lang].typedef ? meta[lang].typedef : {};
|
|
18
|
-
this.additionalPackage = meta[lang] && meta[lang].additionalPackage ? meta[lang].additionalPackage : [];
|
|
19
|
-
this.initConfig(meta);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
visit(ast) {
|
|
23
|
-
this.imports = this.resolveImports(ast);
|
|
24
|
-
this.imports.typedef = this.typedef;
|
|
25
|
-
this.imports.additionalPackage = this.additionalPackage;
|
|
26
|
-
Object.keys(this.typedef).forEach((def) => {
|
|
27
|
-
if (this.typedef[def].package && !this.imports.requirePackage.includes(this.typedef[def].package)) {
|
|
28
|
-
this.imports.requirePackage.push(this.typedef[def].package);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
const objects = [];
|
|
32
|
-
|
|
33
|
-
// combine client code
|
|
34
|
-
const clientObjectItem = this.resolve('client', ast, ast);
|
|
35
|
-
objects.push(clientObjectItem);
|
|
36
|
-
|
|
37
|
-
// combine model code
|
|
38
|
-
ast.moduleBody.nodes.filter((item) => {
|
|
39
|
-
return item.type === 'model';
|
|
40
|
-
}).forEach((model) => {
|
|
41
|
-
const modelName = model.modelName.lexeme;
|
|
42
|
-
const modelObjectItem = this.resolve('model', model, ast);
|
|
43
|
-
if (ast.models) {
|
|
44
|
-
Object.keys(ast.models).filter((key) => {
|
|
45
|
-
return key.startsWith(modelName + '.');
|
|
46
|
-
}).forEach((key) => {
|
|
47
|
-
const subModel = ast.models[key];
|
|
48
|
-
const subModelObjectItem = this.resolve('model', subModel, ast);
|
|
49
|
-
modelObjectItem.subObject.push(subModelObjectItem);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
objects.push(modelObjectItem);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const combinator = this.getCombinator(this.config);
|
|
56
|
-
combinator.combine(objects);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
resolve(type, ast, globalAST) {
|
|
60
|
-
const combinator = this.getCombinator(this.config);
|
|
61
|
-
let resolver;
|
|
62
|
-
switch (type) {
|
|
63
|
-
case 'client':
|
|
64
|
-
resolver = new ClientResolver(ast, combinator, ast);
|
|
65
|
-
break;
|
|
66
|
-
case 'model':
|
|
67
|
-
resolver = new ModelResolver(ast, combinator, globalAST);
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
const objectItem = resolver.resolve();
|
|
71
|
-
objectItem.includeList = combinator.includeList;
|
|
72
|
-
objectItem.includeModelList = combinator.includeModelList;
|
|
73
|
-
return objectItem;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
getCombinator(configOriginal) {
|
|
77
|
-
const config = _deepClone(configOriginal);
|
|
78
|
-
|
|
79
|
-
// init combinator
|
|
80
|
-
const Combinator = require(`./langs/${this.lang}/combinator`);
|
|
81
|
-
return new Combinator(config, this.imports);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
initConfig(meta) {
|
|
85
|
-
const langDir = path.join(__dirname, `./langs/${this.lang}/`);
|
|
86
|
-
if (!fs.existsSync(langDir)) {
|
|
87
|
-
throw new Error(`Not supported language : ${this.lang}`);
|
|
88
|
-
}
|
|
89
|
-
const langConfig = require(`./langs/${this.lang}/config`);
|
|
90
|
-
|
|
91
|
-
const config = {
|
|
92
|
-
package: 'darabonba_sdk',
|
|
93
|
-
clientName: langConfig.client.defaultName,
|
|
94
|
-
include: [],
|
|
95
|
-
parent: [],
|
|
96
|
-
pkgDir: '',
|
|
97
|
-
output: true,
|
|
98
|
-
dir: meta.outputDir,
|
|
99
|
-
layer: '',
|
|
100
|
-
};
|
|
101
|
-
Object.assign(config,
|
|
102
|
-
langConfig,
|
|
103
|
-
meta,
|
|
104
|
-
);
|
|
105
|
-
if (meta[this.lang]) {
|
|
106
|
-
if (!meta[this.lang].package) {
|
|
107
|
-
debug.warning('Not found package in Darafile, default package name is "darabonba_sdk".');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (!meta[this.lang].clientName) {
|
|
111
|
-
debug.warning('Not found clientName in Darafile, default clientName is "client".');
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
Object.assign(config,
|
|
115
|
-
meta[this.lang],
|
|
116
|
-
);
|
|
117
|
-
} else {
|
|
118
|
-
debug.warning('Not found python config in Darafile, default config will be used.');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
this.config = config;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
resolveImports(ast) {
|
|
125
|
-
const imports = ast.imports;
|
|
126
|
-
|
|
127
|
-
let requirePackage = [];
|
|
128
|
-
let thirdPackageNamespace = {};
|
|
129
|
-
let thirdPackageModel = {};
|
|
130
|
-
let thirdPackageClient = {};
|
|
131
|
-
let thirdPackageClientAlias = {};
|
|
132
|
-
let importsTypedef = {};
|
|
133
|
-
|
|
134
|
-
if (imports.length > 0) {
|
|
135
|
-
const lockPath = path.join(this.config.pkgDir, '.libraries.json');
|
|
136
|
-
const lock = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
|
|
137
|
-
let packageNameSet = [];
|
|
138
|
-
let clientNameSet = [];
|
|
139
|
-
ast.imports.forEach((item) => {
|
|
140
|
-
const aliasId = item.lexeme;
|
|
141
|
-
const moduleDir = this.config.libraries[aliasId];
|
|
142
|
-
let targetPath;
|
|
143
|
-
if (moduleDir.startsWith('/')) {
|
|
144
|
-
targetPath = moduleDir;
|
|
145
|
-
} else if (moduleDir.startsWith('./') || moduleDir.startsWith('../')) {
|
|
146
|
-
targetPath = path.join(this.config.pkgDir, moduleDir);
|
|
147
|
-
} else {
|
|
148
|
-
targetPath = path.join(this.config.pkgDir, lock[moduleDir]);
|
|
149
|
-
}
|
|
150
|
-
// get dara meta
|
|
151
|
-
const daraFilePath = fs.existsSync(path.join(targetPath, 'Teafile'))
|
|
152
|
-
? path.join(targetPath, 'Teafile')
|
|
153
|
-
: path.join(targetPath, 'Darafile');
|
|
154
|
-
const daraMeta = JSON.parse(fs.readFileSync(daraFilePath));
|
|
155
|
-
|
|
156
|
-
// init package name,client name,modelDir name
|
|
157
|
-
let packageName, clientName, modelDir;
|
|
158
|
-
if (daraMeta[this.lang]) {
|
|
159
|
-
if (daraMeta[this.lang].package) {
|
|
160
|
-
packageName = daraMeta[this.lang].package;
|
|
161
|
-
} else {
|
|
162
|
-
debug.warning(`Not found package in ${daraMeta.name} Darafile, default package name is "${daraMeta.name}".`);
|
|
163
|
-
packageName = daraMeta.name;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
clientName = daraMeta[this.lang].clientName
|
|
167
|
-
? daraMeta[this.lang].clientName
|
|
168
|
-
: this.config.clientName;
|
|
169
|
-
|
|
170
|
-
modelDir = daraMeta[this.lang].modelDirName
|
|
171
|
-
? daraMeta[this.lang].modelDirName
|
|
172
|
-
: this.config.model.dir;
|
|
173
|
-
if (daraMeta[this.lang].typedef) {
|
|
174
|
-
importsTypedef[aliasId] = {};
|
|
175
|
-
const moduleTypedef = daraMeta[this.lang].typedef;
|
|
176
|
-
Object.keys(moduleTypedef || {}).forEach((types) => {
|
|
177
|
-
if (!importsTypedef[aliasId][types]) {
|
|
178
|
-
importsTypedef[aliasId][types] = {};
|
|
179
|
-
}
|
|
180
|
-
importsTypedef[aliasId][types].import = moduleTypedef[types].import;
|
|
181
|
-
importsTypedef[aliasId][types].type = moduleTypedef[types].type;
|
|
182
|
-
if (moduleTypedef[types].package && !requirePackage.includes(moduleTypedef[types].package)) {
|
|
183
|
-
requirePackage.push(moduleTypedef[types].package);
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
} else {
|
|
188
|
-
packageName = daraMeta.name;
|
|
189
|
-
clientName = this.config.clientName;
|
|
190
|
-
modelDir = this.config.model.dir;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// resolve third package namespace
|
|
194
|
-
if (packageNameSet.indexOf(packageName.toLowerCase()) < 0) {
|
|
195
|
-
thirdPackageNamespace[aliasId] = packageName;
|
|
196
|
-
packageNameSet.push(packageName.toLowerCase());
|
|
197
|
-
} else {
|
|
198
|
-
debug.stack('Duplication namespace');
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// resolve third package model client name
|
|
202
|
-
if (
|
|
203
|
-
clientNameSet.indexOf(clientName.toLowerCase()) > -1 ||
|
|
204
|
-
clientName.toLowerCase() === this.config.clientName.toLowerCase()
|
|
205
|
-
) {
|
|
206
|
-
const alias = packageName.split('.').join('') + '->' + clientName.split('.').join('');
|
|
207
|
-
thirdPackageClientAlias[aliasId] = alias;
|
|
208
|
-
thirdPackageClient[aliasId] = clientName;
|
|
209
|
-
} else {
|
|
210
|
-
thirdPackageClient[aliasId] = clientName;
|
|
211
|
-
clientNameSet.push(clientName.toLowerCase());
|
|
212
|
-
}
|
|
213
|
-
if (daraMeta.releases && daraMeta.releases[this.lang]) {
|
|
214
|
-
requirePackage.push(daraMeta.releases[this.lang]);
|
|
215
|
-
}
|
|
216
|
-
// third package model dir name
|
|
217
|
-
thirdPackageModel[aliasId] = modelDir;
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
return {
|
|
221
|
-
requirePackage,
|
|
222
|
-
thirdPackageNamespace,
|
|
223
|
-
thirdPackageClient,
|
|
224
|
-
thirdPackageClientAlias,
|
|
225
|
-
thirdPackageModel,
|
|
226
|
-
importsTypedef,
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
module.exports = Generator;
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const debug = require('../../lib/debug');
|
|
4
|
-
const Emitter = require('../../lib/emitter');
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
Grammer,
|
|
8
|
-
GrammerThrows,
|
|
9
|
-
|
|
10
|
-
Behavior,
|
|
11
|
-
PropItem,
|
|
12
|
-
AnnotationItem,
|
|
13
|
-
ObjectItem,
|
|
14
|
-
} = require('./items');
|
|
15
|
-
|
|
16
|
-
const {
|
|
17
|
-
_config,
|
|
18
|
-
_upperFirst,
|
|
19
|
-
_lowerFirst,
|
|
20
|
-
} = require('../../lib/helper.js');
|
|
21
|
-
|
|
22
|
-
class BaseCombinator {
|
|
23
|
-
constructor(config = {}, imports = {}) {
|
|
24
|
-
this.level = 0;
|
|
25
|
-
this.eol = '';
|
|
26
|
-
|
|
27
|
-
this.includeList = [];
|
|
28
|
-
this.includeModelList = [];
|
|
29
|
-
this.includeSet = [];
|
|
30
|
-
|
|
31
|
-
this.config = config;
|
|
32
|
-
this.imports = imports;
|
|
33
|
-
|
|
34
|
-
this.requirePackage = imports.requirePackage;
|
|
35
|
-
this.thirdPackageNamespace = imports.thirdPackageNamespace;
|
|
36
|
-
this.thirdPackageClient = imports.thirdPackageClient;
|
|
37
|
-
this.thirdPackageClientAlias = imports.thirdPackageClientAlias;
|
|
38
|
-
this.thirdPackageModel = imports.thirdPackageModel;
|
|
39
|
-
this.typedef = imports.typedef;
|
|
40
|
-
this.importsTypedef = imports.importsTypedef;
|
|
41
|
-
this.additionalPackage = imports.additionalPackage;
|
|
42
|
-
|
|
43
|
-
_config(this.config);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
combine(objects = []) {
|
|
47
|
-
if (objects.some(Object => !(Object instanceof ObjectItem))) {
|
|
48
|
-
throw new Error('Only supported ObjectItem.');
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
combineOutputParts(config, outputParts) {
|
|
53
|
-
const globalEmitter = new Emitter(config);
|
|
54
|
-
globalEmitter.emit(outputParts.head);
|
|
55
|
-
globalEmitter.emit(outputParts.body);
|
|
56
|
-
globalEmitter.emit(outputParts.foot);
|
|
57
|
-
globalEmitter.save();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
coreClass(objName) {
|
|
61
|
-
const key = _lowerFirst(objName.split('$').join(''));
|
|
62
|
-
if (this.config.tea[key]) {
|
|
63
|
-
return this.config.tea[key].name;
|
|
64
|
-
}
|
|
65
|
-
debug.stack('Unsupported core class name : ' + objName);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
resolveNotes(nodes) {
|
|
69
|
-
let notes = {};
|
|
70
|
-
nodes.filter(node => node instanceof PropItem).map(prop => {
|
|
71
|
-
if (prop.notes.length > 0) {
|
|
72
|
-
prop.notes.forEach(note => {
|
|
73
|
-
note.belong = prop.index;
|
|
74
|
-
note.prop = prop.name;
|
|
75
|
-
if (typeof notes[note.key] === 'undefined') {
|
|
76
|
-
notes[note.key] = [];
|
|
77
|
-
}
|
|
78
|
-
notes[note.key].push(note);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
return notes;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
emitAnnotations(emitter, annotations) {
|
|
86
|
-
annotations.forEach(annotation => {
|
|
87
|
-
this.emitAnnotation(emitter, annotation);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
findThrows(grammer, set = []) {
|
|
92
|
-
if (grammer.body) {
|
|
93
|
-
grammer.body.filter(node => {
|
|
94
|
-
if (node instanceof GrammerThrows) {
|
|
95
|
-
set.push(node);
|
|
96
|
-
} else if (node.body) {
|
|
97
|
-
this.findThrows(node, set);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return set;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
init(ast) {
|
|
105
|
-
throw new Error('unimpelemented');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
levelUp() {
|
|
109
|
-
this.level++;
|
|
110
|
-
return this.level;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
levelDown() {
|
|
114
|
-
this.level--;
|
|
115
|
-
return this.level;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
addModelInclude(modelName) {
|
|
119
|
-
throw new Error('unimpelemented');
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
addInclude(include) {
|
|
123
|
-
throw new Error('unimpelemented');
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
systemfunc(emitter, gram) {
|
|
127
|
-
let tmp = [];
|
|
128
|
-
gram.path.forEach(path => {
|
|
129
|
-
tmp.push(_upperFirst(path.name));
|
|
130
|
-
});
|
|
131
|
-
if (tmp.length === 0) {
|
|
132
|
-
debug.stack('Invalid path. path list cannot be empty.');
|
|
133
|
-
}
|
|
134
|
-
let systemFunc = 'sys' + tmp.join('');
|
|
135
|
-
if (this[systemFunc]) {
|
|
136
|
-
this[systemFunc].apply(this, [emitter, gram]);
|
|
137
|
-
} else {
|
|
138
|
-
debug.stack(`unimpelemented ${systemFunc}(emitter, gram){} method\n`, gram);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
grammer(emit, gram, eol = true, newLine = true) {
|
|
143
|
-
if (gram instanceof AnnotationItem) {
|
|
144
|
-
this.emitAnnotation(emit, gram);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
let emitter = new Emitter();
|
|
149
|
-
let method = null;
|
|
150
|
-
if (gram instanceof Behavior) {
|
|
151
|
-
method = gram.name;
|
|
152
|
-
} else if (gram instanceof Grammer) {
|
|
153
|
-
method = _lowerFirst(gram.constructor.name);
|
|
154
|
-
} else {
|
|
155
|
-
debug.stack('Unsupported', gram);
|
|
156
|
-
}
|
|
157
|
-
if (typeof this[method] !== 'undefined') {
|
|
158
|
-
this[method].call(this, emitter, gram);
|
|
159
|
-
} else {
|
|
160
|
-
debug.stack('Unimpelemented : ' + method);
|
|
161
|
-
}
|
|
162
|
-
if (gram.eol !== null) {
|
|
163
|
-
eol = gram.eol;
|
|
164
|
-
}
|
|
165
|
-
if (gram.newLine !== null) {
|
|
166
|
-
newLine = gram.newLine;
|
|
167
|
-
}
|
|
168
|
-
if (newLine) {
|
|
169
|
-
emit.emit('', this.level);
|
|
170
|
-
}
|
|
171
|
-
emit.emit(emitter.output);
|
|
172
|
-
if (eol) {
|
|
173
|
-
emit.emitln(this.eol);
|
|
174
|
-
}
|
|
175
|
-
emitter = null;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
grammerNewLine(emitter, gram) {
|
|
179
|
-
let number = gram.number;
|
|
180
|
-
while (number > 0) {
|
|
181
|
-
emitter.emitln();
|
|
182
|
-
number--;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
emitGrammerValue(gram) {
|
|
187
|
-
let emitter = new Emitter();
|
|
188
|
-
this.grammerValue(emitter, gram);
|
|
189
|
-
return emitter.output;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
module.exports = BaseCombinator;
|