@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
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
or more contributor license agreements. See the NOTICE file
|
|
5
|
+
distributed with this work for additional information
|
|
6
|
+
regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
to you under the Apache License, Version 2.0 (the
|
|
8
|
+
"License"); you may not use this file except in compliance
|
|
9
|
+
with the License. You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing,
|
|
14
|
+
software distributed under the License is distributed on an
|
|
15
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
KIND, either express or implied. See the License for the
|
|
17
|
+
specific language governing permissions and limitations
|
|
18
|
+
under the License.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import os
|
|
22
|
+
from setuptools import setup, find_packages
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
setup module for tea_python_tests.
|
|
26
|
+
|
|
27
|
+
Created on *
|
|
28
|
+
|
|
29
|
+
@author: Alibaba
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
PACKAGE = "tea_python_tests"
|
|
33
|
+
NAME = "tea_python_tests"
|
|
34
|
+
DESCRIPTION = ""
|
|
35
|
+
AUTHOR = "Alibaba"
|
|
36
|
+
AUTHOR_EMAIL = "sdk-team@alibabacloud.com"
|
|
37
|
+
URL = "https://github.com/"
|
|
38
|
+
VERSION = __import__(PACKAGE).__version__
|
|
39
|
+
REQUIRES = [
|
|
40
|
+
"darabonba-core>=1.0.0, <2.0.0",
|
|
41
|
+
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
LONG_DESCRIPTION = ''
|
|
45
|
+
if os.path.exists('./README.md'):
|
|
46
|
+
with open("README.md", encoding='utf-8') as fp:
|
|
47
|
+
LONG_DESCRIPTION = fp.read()
|
|
48
|
+
|
|
49
|
+
setup(
|
|
50
|
+
name=NAME,
|
|
51
|
+
version=VERSION,
|
|
52
|
+
description=DESCRIPTION,
|
|
53
|
+
long_description=LONG_DESCRIPTION,
|
|
54
|
+
long_description_content_type='text/markdown',
|
|
55
|
+
author=AUTHOR,
|
|
56
|
+
author_email=AUTHOR_EMAIL,
|
|
57
|
+
license="Apache License 2.0",
|
|
58
|
+
url=URL,
|
|
59
|
+
keywords=["tea","python","tests"],
|
|
60
|
+
packages=find_packages(exclude=["tests*"]),
|
|
61
|
+
include_package_data=True,
|
|
62
|
+
platforms="any",
|
|
63
|
+
install_requires=REQUIRES,
|
|
64
|
+
python_requires=">=3.6",
|
|
65
|
+
classifiers=(
|
|
66
|
+
"Development Status :: 4 - Beta",
|
|
67
|
+
"Intended Audience :: Developers",
|
|
68
|
+
"License :: OSI Approved :: Apache Software License",
|
|
69
|
+
"Programming Language :: Python",
|
|
70
|
+
"Programming Language :: Python :: 3",
|
|
71
|
+
"Programming Language :: Python :: 3.6",
|
|
72
|
+
"Programming Language :: Python :: 3.7",
|
|
73
|
+
"Programming Language :: Python :: 3.8",
|
|
74
|
+
"Programming Language :: Python :: 3.9",
|
|
75
|
+
"Topic :: Software Development"
|
|
76
|
+
)
|
|
77
|
+
)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# This file is auto-generated, don't edit it. Thanks.
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from Source.source_client import SourceClient
|
|
5
|
+
from Source import models as source_models
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Client(SourceClient):
|
|
11
|
+
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
config: source_models.Config,
|
|
15
|
+
):
|
|
16
|
+
super().__init__(config)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
or more contributor license agreements. See the NOTICE file
|
|
5
|
+
distributed with this work for additional information
|
|
6
|
+
regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
to you under the Apache License, Version 2.0 (the
|
|
8
|
+
"License"); you may not use this file except in compliance
|
|
9
|
+
with the License. You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing,
|
|
14
|
+
software distributed under the License is distributed on an
|
|
15
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
KIND, either express or implied. See the License for the
|
|
17
|
+
specific language governing permissions and limitations
|
|
18
|
+
under the License.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import os
|
|
22
|
+
from setuptools import setup, find_packages
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
setup module for tea_python_tests.
|
|
26
|
+
|
|
27
|
+
Created on *
|
|
28
|
+
|
|
29
|
+
@author: Alibaba
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
PACKAGE = "tea_python_tests"
|
|
33
|
+
NAME = "tea_python_tests"
|
|
34
|
+
DESCRIPTION = ""
|
|
35
|
+
AUTHOR = "Alibaba"
|
|
36
|
+
AUTHOR_EMAIL = "sdk-team@alibabacloud.com"
|
|
37
|
+
URL = "https://github.com/"
|
|
38
|
+
VERSION = __import__(PACKAGE).__version__
|
|
39
|
+
REQUIRES = [
|
|
40
|
+
"darabonba-core>=1.0.0, <2.0.0",
|
|
41
|
+
"requests>=2.21.0, <3.0.0",
|
|
42
|
+
"alibabacloud-tea>=0.2.9, <1.0.0"
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
LONG_DESCRIPTION = ''
|
|
46
|
+
if os.path.exists('./README.md'):
|
|
47
|
+
with open("README.md", encoding='utf-8') as fp:
|
|
48
|
+
LONG_DESCRIPTION = fp.read()
|
|
49
|
+
|
|
50
|
+
setup(
|
|
51
|
+
name=NAME,
|
|
52
|
+
version=VERSION,
|
|
53
|
+
description=DESCRIPTION,
|
|
54
|
+
long_description=LONG_DESCRIPTION,
|
|
55
|
+
long_description_content_type='text/markdown',
|
|
56
|
+
author=AUTHOR,
|
|
57
|
+
author_email=AUTHOR_EMAIL,
|
|
58
|
+
license="Apache License 2.0",
|
|
59
|
+
url=URL,
|
|
60
|
+
keywords=["tea","python","tests"],
|
|
61
|
+
packages=find_packages(exclude=["tests*"]),
|
|
62
|
+
include_package_data=True,
|
|
63
|
+
platforms="any",
|
|
64
|
+
install_requires=REQUIRES,
|
|
65
|
+
python_requires=">=3.6",
|
|
66
|
+
classifiers=(
|
|
67
|
+
"Development Status :: 4 - Beta",
|
|
68
|
+
"Intended Audience :: Developers",
|
|
69
|
+
"License :: OSI Approved :: Apache Software License",
|
|
70
|
+
"Programming Language :: Python",
|
|
71
|
+
"Programming Language :: Python :: 3",
|
|
72
|
+
"Programming Language :: Python :: 3.6",
|
|
73
|
+
"Programming Language :: Python :: 3.7",
|
|
74
|
+
"Programming Language :: Python :: 3.8",
|
|
75
|
+
"Programming Language :: Python :: 3.9",
|
|
76
|
+
"Topic :: Software Development"
|
|
77
|
+
)
|
|
78
|
+
)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# This file is auto-generated, don't edit it. Thanks.
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from requests import Request
|
|
5
|
+
from Tea.model import TeaModel
|
|
6
|
+
from Source.source_client import SourceClient
|
|
7
|
+
from tea_python_tests import models as main_models
|
|
8
|
+
from requests import Response
|
|
9
|
+
from typing import Dict, Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Client:
|
|
13
|
+
_vid: Request = None
|
|
14
|
+
_model: TeaModel = None
|
|
15
|
+
|
|
16
|
+
def __init__(
|
|
17
|
+
self,
|
|
18
|
+
request: Request,
|
|
19
|
+
model: TeaModel,
|
|
20
|
+
):
|
|
21
|
+
self._vid = request
|
|
22
|
+
self._model = model
|
|
23
|
+
|
|
24
|
+
def main(
|
|
25
|
+
self,
|
|
26
|
+
test_1: Request,
|
|
27
|
+
test_2: TeaModel,
|
|
28
|
+
) -> None:
|
|
29
|
+
oss = SourceClient(test_1)
|
|
30
|
+
m = main_models.M(
|
|
31
|
+
a = test_1,
|
|
32
|
+
b = test_2
|
|
33
|
+
)
|
|
34
|
+
self._vid = test_1
|
|
35
|
+
self._model = test_2
|
|
36
|
+
|
|
37
|
+
async def main_async(
|
|
38
|
+
self,
|
|
39
|
+
test_1: Request,
|
|
40
|
+
test_2: TeaModel,
|
|
41
|
+
) -> None:
|
|
42
|
+
oss = SourceClient(test_1)
|
|
43
|
+
m = main_models.M(
|
|
44
|
+
a = test_1,
|
|
45
|
+
b = test_2
|
|
46
|
+
)
|
|
47
|
+
self._vid = test_1
|
|
48
|
+
self._model = test_2
|
|
49
|
+
|
|
50
|
+
def test_http_request(
|
|
51
|
+
self,
|
|
52
|
+
req: Request,
|
|
53
|
+
) -> Response:
|
|
54
|
+
return self.test_http_request_with('test', req)
|
|
55
|
+
|
|
56
|
+
async def test_http_request_async(
|
|
57
|
+
self,
|
|
58
|
+
req: Request,
|
|
59
|
+
) -> Response:
|
|
60
|
+
return self.test_http_request_with('test', req)
|
|
61
|
+
|
|
62
|
+
@staticmethod
|
|
63
|
+
def test_http_request_with(
|
|
64
|
+
method: str,
|
|
65
|
+
req: Request,
|
|
66
|
+
) -> Response:
|
|
67
|
+
raise Exception('Un-implemented')
|
|
68
|
+
|
|
69
|
+
@staticmethod
|
|
70
|
+
def test_http_header(
|
|
71
|
+
method: str,
|
|
72
|
+
headers: Dict[str, Any],
|
|
73
|
+
) -> Response:
|
|
74
|
+
raise Exception('Un-implemented')
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# This file is auto-generated, don't edit it. Thanks.
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from darabonba.model import DaraModel
|
|
5
|
+
from requests import Request
|
|
6
|
+
from Tea.model import TeaModel
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class M(DaraModel):
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
a: Request = None,
|
|
15
|
+
b: TeaModel = None,
|
|
16
|
+
):
|
|
17
|
+
self.a = a
|
|
18
|
+
self.b = b
|
|
19
|
+
|
|
20
|
+
def validate(self):
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
def to_map(self):
|
|
24
|
+
_map = super().to_map()
|
|
25
|
+
if _map is not None:
|
|
26
|
+
return _map
|
|
27
|
+
|
|
28
|
+
result = dict()
|
|
29
|
+
if self.a is not None:
|
|
30
|
+
result['a'] = self.a
|
|
31
|
+
if self.b is not None:
|
|
32
|
+
result['b'] = self.b
|
|
33
|
+
return result
|
|
34
|
+
|
|
35
|
+
def from_map(self, m: dict = None):
|
|
36
|
+
m = m or dict()
|
|
37
|
+
if m.get('a') is not None:
|
|
38
|
+
self.a = m.get('a')
|
|
39
|
+
if m.get('b') is not None:
|
|
40
|
+
self.b = m.get('b')
|
|
41
|
+
return self
|
|
42
|
+
|
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;
|