forked from googleapis/nodejs-firestore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
synth.py
193 lines (175 loc) · 5.29 KB
/
synth.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import synthtool as s
import synthtool.gcp as gcp
import synthtool.languages.node as node
import logging
import os
import subprocess
logging.basicConfig(level=logging.DEBUG)
AUTOSYNTH_MULTIPLE_COMMITS = True
gapic_bazel = gcp.GAPICBazel()
v1_admin_library = gapic_bazel.node_library(
"firestore-admin", "v1", proto_path="/google/firestore/admin/v1"
)
v1beta1_library = gapic_bazel.node_library(
"firestore", "v1beta1", proto_path="/google/firestore/v1beta1"
)
v1_library = gapic_bazel.node_library(
"firestore", "v1", proto_path="/google/firestore/v1"
)
# skip index, protos, package.json, and README.md
s.copy(v1_admin_library, "dev", excludes=["package.json", "README.md", "src/index.ts", "src/v1/index.ts",
"tsconfig.json", "linkinator.config.json", "webpack.config.js"])
s.copy(v1beta1_library, "dev", excludes=["package.json", "README.md", "src/index.ts", "src/v1beta1/index.ts",
"tsconfig.json", "linkinator.config.json", "webpack.config.js"])
s.copy(v1_library, "dev", excludes=["package.json", "README.md", "src/index.ts", "src/v1/index.ts",
"tsconfig.json", "linkinator.config.json", "webpack.config.js"])
# Fix dropping of google-cloud-resource-header
# See: https://github.com/googleapis/nodejs-firestore/pull/375
s.replace(
"dev/src/v1beta1/firestore_client.ts",
"return this\.innerApiCalls\.listen\(options\);",
"return this.innerApiCalls.listen({}, options);",
)
s.replace(
"dev/src/v1/firestore_client.ts",
"return this\.innerApiCalls\.listen\(options\);",
"return this.innerApiCalls.listen({}, options);",
)
s.replace(
"dev/test/gapic_firestore_v1beta1.ts",
"calledWithExactly\(undefined\)",
"calledWithExactly({}, undefined)",
)
s.replace(
"dev/src/v1beta1/firestore_client.ts",
"return this\.innerApiCalls\.write\(options\);",
"return this.innerApiCalls.write({}, options);",
)
s.replace(
"dev/src/v1/firestore_client.ts",
"return this\.innerApiCalls\.write\(options\);",
"return this.innerApiCalls.write({}, options);",
)
s.replace(
"dev/test/gapic_firestore_v1.ts",
"calledWithExactly\(undefined\)",
"calledWithExactly({}, undefined)",
)
# use the existing proto .js / .d.ts files
s.replace(
"dev/src/v1/firestore_client.ts",
"/protos/protos'",
"/protos/firestore_v1_proto_api'"
)
s.replace(
"dev/test/gapic_firestore_v1.ts",
"/protos/protos'",
"/protos/firestore_v1_proto_api'"
)
s.replace(
"dev/test/gapic_firestore_v1.ts",
"import \* as firestoreModule from '\.\./src';",
"import * as firestoreModule from '../src/v1';"
)
s.replace(
"dev/test/gapic_firestore_v1.ts",
"firestoreModule\.v1",
"firestoreModule"
)
s.replace(
"dev/src/v1/firestore_admin_client.ts",
"/protos/protos'",
"/protos/firestore_admin_v1_proto_api'"
)
s.replace(
"dev/test/gapic_firestore_admin_v1.ts",
"/protos/protos'",
"/protos/firestore_admin_v1_proto_api'"
)
s.replace(
"dev/test/gapic_firestore_admin_v1.ts",
"import \* as firestoreadminModule from '\.\./src';",
"import * as firestoreadminModule from '../src/v1';"
)
s.replace(
"dev/test/gapic_firestore_admin_v1.ts",
"firestoreadminModule\.v1",
"firestoreadminModule"
)
s.replace(
"dev/src/v1beta1/firestore_client.ts",
"/protos/protos'",
"/protos/firestore_v1beta1_proto_api'"
)
s.replace(
"dev/test/gapic_firestore_v1beta1.ts",
"/protos/protos'",
"/protos/firestore_v1beta1_proto_api'"
)
s.replace(
"dev/test/gapic_firestore_v1beta1.ts",
"import \* as firestoreModule from \'../src\';",
"import * as firestoreModule from '../src/v1beta1';"
)
s.replace(
"dev/test/gapic_firestore_v1beta1.ts",
"firestoreModule\.v1beta1",
"firestoreModule"
)
# Mark v1beta1 as deprecated
s.replace(
"dev/src/v1beta1/firestore_client.ts",
"@class",
"@class\n * @deprecated Use v1/firestore_client instead."
)
s.replace(
"dev/src/v1beta1/firestore_client.ts",
"const version",
"// tslint:disable deprecation\n\nconst version",
1
)
os.rename("dev/.gitignore", ".gitignore")
os.rename("dev/.eslintignore", ".eslintignore")
os.rename("dev/.mocharc.js", ".mocharc.js")
os.rename("dev/.jsdoc.js", ".jsdoc.js")
os.rename("dev/.prettierrc.js", ".prettierrc.js")
os.unlink("dev/.eslintrc.json")
s.replace(".jsdoc.js", "protos", "build/protos", 1)
# Copy template files
common_templates = gcp.CommonTemplates()
templates = common_templates.node_library(
source_location="build/src", test_project="node-gcloud-ci"
)
s.copy(templates, excludes=[".eslintrc.json", ".kokoro/**/*", ".github/CODEOWNERS"])
# Remove auto-generated packaging tests
os.system('rm -rf dev/system-test/fixtures dev/system-test/install.ts')
node.install()
os.chdir("dev")
node.compile_protos()
os.chdir("protos")
os.unlink('protos.js')
os.unlink('protos.d.ts')
subprocess.run('./update.sh', shell=True)
os.chdir("../../")
# Copy types into types/
os.system("cp build/src/v1/firestore*.d.ts types/v1")
os.system("cp build/src/v1beta1/firestore_client.d.ts types/v1beta1")
os.system("cp build/protos/firestore*.d.ts types/protos")
s.replace(
"types/v1/firestore_client.d.ts",
"../../protos",
"../protos"
)
s.replace(
"types/v1/firestore_admin_client.d.ts",
"../../protos",
"../protos"
)
s.replace(
"types/v1beta1/firestore_client.d.ts",
"../../protos",
"../protos"
)
node.fix()
# Add license headers
os.system("node scripts/license.js types/v1/*.d.ts types/v1beta1/*.d.ts")