Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: also generate samples/README.md #214

Merged
merged 10 commits into from
Apr 2, 2019
2 changes: 1 addition & 1 deletion synthtool/gcp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def node_library(self, **kwargs) -> Path:
# .repo-metadata.json, or excluding README.md, we can remove this.
if not os.path.exists("./.repo-metadata.json"):
self.excludes.append("README.md")
self.excludes.append("samples/README.md")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't want to generate the new README until we've plopped a .repo-metadata.json in the folder, otherwise we get a junk file.


kwargs["metadata"] = node.read_metadata()
kwargs["publish_token"] = node.get_publish_token(kwargs["metadata"]["name"])
Expand Down Expand Up @@ -128,7 +129,6 @@ def _read_quickstart(self, samples_dir):
# The following fields are currently supported:
#
# introduction: a more thorough introduction than metadata["description"].
# quickstart_footer: add additional context to footer of quickstart.
#
def _load_partials(self, metadata):
cwd_path = Path(os.getcwd())
Expand Down
5 changes: 2 additions & 3 deletions synthtool/gcp/templates/node_library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].
### Using the client library

```{{ metadata['repo']['language']|syntax_highlighter }}
{{ metadata['quickstart'] }}{% if metadata['partials'] and metadata['partials']['quickstart_footer'] %}
{{ metadata['partials']['quickstart_footer'] }}
bcoe marked this conversation as resolved.
Show resolved Hide resolved
{% endif %}```
{{ metadata['quickstart'] }}
```
{% endif %}

{% if metadata['samples']|length %}
Expand Down
51 changes: 51 additions & 0 deletions synthtool/gcp/templates/node_library/samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
[//]: # "To regenerate it, use `npm run generate-scaffolding`."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we want npm run generate-scaffolding

<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# [{{ metadata['repo']['name_pretty'] }}: {{ metadata['repo']['language']|language_pretty }} Samples](https://github.com/{{ metadata['repo']['repo'] }})

[![Open in Cloud Shell][shell_img]][shell_link]

{{ metadata['partials'] and metadata['partials']['introduction'] }}

## Table of Contents

* [Before you begin](#before-you-begin)
* [Samples](#samples){% if metadata['samples']|length %}{% for sample in metadata['samples'] %}
* [{{ sample.name }}](#{{ sample.name|slugify }}){% endfor %}{% endif %}

## Before you begin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this README has been simplified, the need for executing samples to generate yargs output, this matches the direction we're moving in for samples any ways.

Before running the samples, make sure you've followed the steps in the
[Using the client library](https://github.com/{{ metadata['repo']['repo'] }}#using-the-client-library) of the client
library's README.

## Samples
{% if metadata['samples']|length %}
{% for sample in metadata['samples'] %}

### {{sample.name}}

View the [source code](https://github.com/{{ metadata['repo']['repo'] }}/blob/master/samples/{{ sample.file }}).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/{{ metadata['repo']['repo'] }}&page=editor&open_in_editor=samples/{{ sample.file }},samples/README.md)

__Usage:__

See available commands:

`node {{ sample.file }} --help`

Run the sample:

`node {{ sample.file }} [command] [options]`

{% if not loop.last %}
-----
{% endif %}

{% endfor %}
{% endif %}

[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/{{ metadata['repo']['repo'] }}&page=editor&open_in_editor=samples/README.md
8 changes: 8 additions & 0 deletions synthtool/sources/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def _make_env(location):
)
env.filters["release_quality_badge"] = release_quality_badge
env.filters["language_pretty"] = language_pretty
env.filters["slugify"] = slugify
env.filters["syntax_highlighter"] = syntax_highlighter
return env

Expand Down Expand Up @@ -123,6 +124,13 @@ def language_pretty(input):
return input


#
# converts Foo Bar into foo-bar, for use wih anchor links.
#
def slugify(input):
bcoe marked this conversation as resolved.
Show resolved Hide resolved
return input.lower().replace(" ", "-")


#
# .repo-metadata.json language field to syntax highlighter name.
#
Expand Down