Skip to content

Commit 2adfcf9

Browse files
authored
fix(node-mono-repo): generate README and samples/README (#1524)
* fix(node-mono-repo): generate README and samples/README
1 parent 652738f commit 2adfcf9

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

synthtool/gcp/common.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ def __init__(self, template_path: Optional[Path] = None):
4949
self._templates = templates.Templates(self._template_root)
5050
self.excludes = [] # type: List[str]
5151

52-
def _generic_library(self, directory: str, **kwargs) -> Path:
52+
def _generic_library(self, directory: str, relative_dir=None, **kwargs) -> Path:
5353
# load common repo meta information (metadata that's not language specific).
5454
if "metadata" in kwargs:
55-
self._load_generic_metadata(kwargs["metadata"])
55+
self._load_generic_metadata(kwargs["metadata"], relative_dir=relative_dir)
5656
# if no samples were found, don't attempt to render a
5757
# samples/README.md.
5858
if "samples" not in kwargs["metadata"] or not kwargs["metadata"]["samples"]:
@@ -330,7 +330,7 @@ def node_library(self, **kwargs) -> Path:
330330
def node_mono_repo_library(self, relative_dir, **kwargs) -> Path:
331331
# TODO: once we've migrated all Node.js repos to either having
332332
# .repo-metadata.json, or excluding README.md, we can remove this.
333-
if not os.path.exists(Path(relative_dir, "/.repo-metadata.json").resolve()):
333+
if not os.path.exists(Path(relative_dir, ".repo-metadata.json").resolve()):
334334
self.excludes.append("README.md")
335335
if "samples/README.md" not in self.excludes:
336336
self.excludes.append("samples/README.md")
@@ -353,7 +353,9 @@ def node_mono_repo_library(self, relative_dir, **kwargs) -> Path:
353353
year=str(date.today().year),
354354
)
355355

356-
return self._generic_library("node_mono_repo_library", **kwargs)
356+
return self._generic_library(
357+
"node_mono_repo_library", relative_dir=relative_dir, **kwargs
358+
)
357359

358360
def php_library(self, **kwargs) -> Path:
359361
return self._generic_library("php_library", **kwargs)
@@ -369,7 +371,7 @@ def render(self, template_name: str, **kwargs) -> Path:
369371
_tracked_paths.add(template)
370372
return template
371373

372-
def _load_generic_metadata(self, metadata: Dict):
374+
def _load_generic_metadata(self, metadata: Dict, relative_dir=None):
373375
"""
374376
loads additional meta information from .repo-metadata.json.
375377
"""
@@ -380,7 +382,7 @@ def _load_generic_metadata(self, metadata: Dict):
380382
# metadata, so we don't need to do it again or overwrite it. Also, only
381383
# set the "repo" key.
382384
if "repo" not in metadata:
383-
metadata["repo"] = _load_repo_metadata()
385+
metadata["repo"] = _load_repo_metadata(relative_dir=relative_dir)
384386

385387

386388
def detect_versions(
@@ -462,7 +464,9 @@ def decamelize(value: str):
462464
return re.sub("([a-z0-9])([A-Z])", r"\1 \2", str_decamelize) # FooBar -> Foo Bar.
463465

464466

465-
def _load_repo_metadata(metadata_file: str = "./.repo-metadata.json") -> Dict:
467+
def _load_repo_metadata(
468+
relative_dir=None, metadata_file: str = "./.repo-metadata.json"
469+
) -> Dict:
466470
"""Parse a metadata JSON file into a Dict.
467471
468472
Currently, the defined fields are:
@@ -487,7 +491,11 @@ def _load_repo_metadata(metadata_file: str = "./.repo-metadata.json") -> Dict:
487491
Returns:
488492
A dictionary of metadata. This may not necessarily include all the defined fields above.
489493
"""
490-
if os.path.exists(metadata_file):
494+
if relative_dir is not None:
495+
if os.path.exists(Path(relative_dir, metadata_file).resolve()):
496+
with open(Path(relative_dir, metadata_file).resolve()) as f:
497+
return json.load(f)
498+
elif os.path.exists(metadata_file):
491499
with open(metadata_file) as f:
492500
return json.load(f)
493501
return {}

synthtool/languages/node_mono_repo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def postprocess_gapic_library_hermetic(relative_dir, hide_output=False):
256256
logger.debug("Post-processing completed")
257257

258258

259-
default_staging_excludes = ["README.md", "package.json", "src/index.ts"]
259+
default_staging_excludes = ["package.json", "src/index.ts"]
260260
default_templates_excludes: List[str] = []
261261

262262

@@ -272,7 +272,7 @@ def walk_through_owlbot_dirs(dir: Path):
272272
A list of client libs
273273
"""
274274
owlbot_dirs = []
275-
packages_to_exclude = [r"gapic-node-templating"]
275+
packages_to_exclude = [r"gapic-node-templating", r"node_modules"]
276276
for path_object in dir.glob("packages/**/.OwlBot.yaml"):
277277
if path_object.is_file() and not re.search(
278278
"(?:% s)" % "|".join(packages_to_exclude), str(Path(path_object))

0 commit comments

Comments
 (0)