-
Notifications
You must be signed in to change notification settings - Fork 407
/
generate-code.py
94 lines (72 loc) · 2.68 KB
/
generate-code.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import os
import subprocess
import sys
def run_command(command):
print(command)
proc = subprocess.run(command, shell=True, text=True, capture_output=True)
if len(proc.stdout) != 0:
print("\n\nSTDOUT:\n\n")
print(proc.stdout)
if len(proc.stderr) != 0:
print("\n\nSTDERR:\n\n")
print(proc.stderr)
print("\n\n")
if proc.returncode != 0:
print(f"\n\nCommand '{command}' returned non-zero exit status {proc.returncode}.")
sys.exit(1)
return proc.stdout.strip()
def generate_clients():
components = [
"shop.yml",
"channel-access-token.yml",
"insight.yml",
"liff.yml",
"manage-audience.yml",
"module-attach.yml",
"module.yml",
"messaging-api.yml",
]
for sourceYaml in components:
output_path = 'lib/' + sourceYaml.replace('.yml', '')
run_command(f'rm -rf {output_path}/')
command = f'''java \\
-cp ./generator/target/line-bot-sdk-nodejs-generator-openapi-generator-1.0.0.jar \\
org.openapitools.codegen.OpenAPIGenerator \\
generate \\
-e pebble \\
-g line-bot-sdk-nodejs-generator \\
--enable-post-process-file \\
-o {output_path} \\
-i line-openapi/{sourceYaml} \\
'''
run_command(command)
def generate_webhook():
source_yaml = "webhook.yml"
output_path = 'lib/' + source_yaml.replace('.yml', '')
run_command(f'rm -rf {output_path}/')
command = f'''java \\
-cp ./generator/target/line-bot-sdk-nodejs-generator-openapi-generator-1.0.0.jar \\
org.openapitools.codegen.OpenAPIGenerator \\
generate \\
--global-property apiTest=false,modelDocs=false,apiDocs=false \\
-e pebble \\
--enable-post-process-file \\
-g line-bot-sdk-nodejs-generator \\
--template-dir ./generator/src/main/resources/line-bot-sdk-nodejs-generator \\
-o {output_path} \\
-i line-openapi/{source_yaml} \\
'''
run_command(command)
run_command(f'rm -rf lib/webhook/api/')
run_command(f'rm -rf lib/webhook/tests/')
with open('lib/webhook/api.ts', 'w') as wfp:
wfp.write("""export * from './model/models.js';""")
def main():
os.chdir("generator")
run_command('mvn package -DskipTests=true')
os.chdir("..")
generate_clients()
generate_webhook()
run_command('npm run format')
if __name__ == "__main__":
main()