forked from googleapis/nodejs-spanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
synth.py
79 lines (63 loc) · 2.88 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
import synthtool as s
import synthtool.gcp as gcp
import logging
from pathlib import Path
import subprocess
logging.basicConfig(level=logging.DEBUG)
gapic = gcp.GAPICGenerator()
spanner = gapic.node_library(
'spanner', 'v1',
config_path='/google/spanner/artman_spanner.yaml')
spanner_admin_database = gapic.node_library(
'spanner-admin-database', 'v1',
config_path='/google/spanner/admin/database/artman_spanner_admin_database.yaml')
spanner_admin_instance = gapic.node_library(
'spanner-admin-instance', 'v1',
config_path='/google/spanner/admin/instance/artman_spanner_admin_instance.yaml')
# Copy all files except for 'README.md' and 'package.json'
s.copy(spanner, excludes=["src/index.js", "README.md", "package.json"])
s.copy(spanner_admin_database, excludes=["src/v1/index.js", "src/index.js", "README.md", "package.json"])
s.copy(spanner_admin_instance, excludes=["src/v1/index.js", "src/index.js", "README.md", "package.json"])
common_templates = gcp.CommonTemplates()
templates = common_templates.node_library(source_location='build/src')
s.copy(templates)
# nodejs-spanner is composed of 3 APIs: SpannerClient, SpannerAdminDatabase and
# SpannerAdminInstance, export all 3 in src/v1/index.js
s.replace(
"src/v1/index.js",
"(const SpannerClient = require\('\./spanner_client\'\);)",
"""const DatabaseAdminClient = require('./database_admin_client');
const InstanceAdminClient = require('./instance_admin_client');
\g<1>""")
s.replace(
"src/v1/index.js",
"(module\.exports\.SpannerClient = SpannerClient;)",
"""module.exports.DatabaseAdminClient = DatabaseAdminClient;
module.exports.InstanceAdminClient = InstanceAdminClient;
\g<1>""")
# Update path discovery due to build/ dir and TypeScript conversion.
s.replace("src/v1/database_admin_client.js", "../../package.json", "../../../package.json")
s.replace("src/v1/instance_admin_client.js", "../../package.json", "../../../package.json")
s.replace("src/v1/spanner_client.js", "../../package.json", "../../../package.json")
# [START fix-dead-link]
s.replace('**/doc/google/protobuf/doc_timestamp.js',
'https:\/\/cloud\.google\.com[\s\*]*http:\/\/(.*)[\s\*]*\)',
r"https://\1)")
s.replace('**/doc/google/protobuf/doc_timestamp.js',
'toISOString\]',
'toISOString)')
# Fix a dead link issue with specifying regex in comments that looks
# similar to a Markdown link.
s.replace("src/v1/doc/google/spanner/**/doc_spanner*.js",
"`\[a-z\]\(https:\/\/cloud\.google\.com\[-a-z0-9\]\*\[a-z0-9\]\)\?`",
"`\[a-z]([-a-z0-9]*[a-z0-9])?`")
s.replace("src/v1/doc/google/spanner/**/doc_spanner*.js",
"`\(\[a-z\]\(https:\/\/cloud\.google\.com\[-a-z0-9\]\*\[a-z0-9\]\)\?\)\?`",
"`(\[a-z]([-a-z0-9]*[a-z0-9])?)?`")
# [END fix-dead-link]
# '''
# Node.js specific cleanup
# '''
subprocess.run(['npm', 'install'])
subprocess.run(['npm', 'run', 'fix'])
subprocess.run(['npx', 'compileProtos', 'src'])