Skip to content

Commit ab5b1dd

Browse files
committed
chore: add example standards, template and CI format checks
1 parent 00f2922 commit ab5b1dd

15 files changed

Lines changed: 215 additions & 56 deletions

File tree

.claude/settings.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"hooks": {
3+
"SessionStart": [
4+
{
5+
"matcher": "startup|resume|clear|compact",
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"command": "echo 'Examples in this repo follow STANDARDS.md at the root — read it before adding or changing one. Formatting and linting are enforced in CI by .prettierrc and ruff.toml; run them before committing.'",
10+
"timeout": 5
11+
}
12+
]
13+
}
14+
]
15+
}
16+
}

.github/workflows/check.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: check
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [master]
7+
8+
jobs:
9+
format-and-lint:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version-file: .nvmrc
17+
18+
- run: npx prettier@3 --check .
19+
20+
- uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.12'
23+
24+
# Passes trivially until an example ships Python.
25+
- run: pip install ruff==0.16.1 && ruff check .

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Clone this repo, or head into the folder for the example you want. Each example
1010
- [rapidreels](examples/rapidreels) creates faceless short-form videos using generative AI. [View demo](https://shotstack.io/demos/social-media-video-maker/).
1111
- [reelestate](examples/reelestate) turns static real estate images into fully edited video slideshows. [View demo](https://shotstack.io/demos/real-estate-video-listing-maker/).
1212

13+
## Contributing
14+
15+
New example? Copy [`examples/_template`](examples/_template) and read [STANDARDS.md](STANDARDS.md) — it covers credential handling, failure behaviour, README shape, and what to check before opening a pull request.
16+
1317
## Editing with an AI agent
1418

1519
If you are working on these examples with Claude Code or another coding agent, install the Shotstack CLI and its skill first:

STANDARDS.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Standards for cookbook examples
2+
3+
Everything here is published code that strangers copy into their own projects. These rules keep the examples
4+
consistent and safe to copy. New examples start by copying `examples/_template/`.
5+
6+
## Structure
7+
8+
- One example per directory under `examples/`. Self-contained: it runs from a fresh clone with no steps
9+
beyond the ones in its own README.
10+
- The `name` in `package.json` matches the directory name.
11+
- Declare a Node floor in `engines` wherever an example has a `package.json`. The repo floor is `.nvmrc`.
12+
- An example with no `package.json` has no machine-checkable floor, so its README must not document flags
13+
that depend on a specific runtime version. Use plain environment variables instead.
14+
15+
## Credentials
16+
17+
- Read keys from the environment. Never hard-code one, never print one, never commit one.
18+
- Ship a `.env.example` with placeholder values. Next.js examples use `.env.local.example`, because that is
19+
the file Next loads.
20+
- Gitignore the real env file.
21+
22+
## Formatting and linting
23+
24+
- `.prettierrc` at the root governs JavaScript, TypeScript, JSON, CSS and Markdown. `ruff.toml` governs
25+
Python.
26+
- Every example with a `package.json` exposes `npm run format`.
27+
- CI runs `prettier --check` and `ruff check` on every pull request. Run both locally first.
28+
29+
## Failure behaviour
30+
31+
Expected failures — no API key set, a rejected key, a network error — print one line the reader can act on
32+
and exit non-zero. A stack trace on any of those paths is a bug. The missing-key path is the most common
33+
first-run experience an example has, so it deserves the most care.
34+
35+
## README shape
36+
37+
The same order in every example, so a reader can skim any of them:
38+
39+
1. What it does, in a sentence or two, with a link to the companion guide where one exists
40+
2. Requirements
41+
3. Setup
42+
4. Run
43+
5. What happens when you do
44+
45+
Prefer fewer claims to more. Every version number, flag and command in a README is a promise somebody has to
46+
keep true.
47+
48+
## Before you open a pull request
49+
50+
Whoever opens the pull request has read and run the code in it. Before asking for review:
51+
52+
- Run the example from a fresh clone with no credentials set, then with a wrong key, and read what it prints.
53+
- Copy every command out of your README and run it, in the order written.
54+
- Run the formatter and the linter.
55+
- Where the same flow ships in two languages, diff them. A disagreement means one of the two is wrong.

examples/_template/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SHOTSTACK_API_KEY=your_api_key

examples/_template/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
.env

examples/_template/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Example name
2+
3+
What it does, in a sentence or two. Say what a reader gets at the end of it.
4+
5+
Companion code for [Guide title](https://shotstack.io/learn/...) — delete this line if there is no guide.
6+
7+
## Requirements
8+
9+
- A [Shotstack account](https://dashboard.shotstack.io/register) and your API key
10+
- Anything else the example needs, with the minimum version
11+
12+
## Setup
13+
14+
```bash
15+
git clone https://github.com/shotstack/shotstack-cookbook.git
16+
cd shotstack-cookbook/examples/<name>
17+
```
18+
19+
```bash
20+
export SHOTSTACK_API_KEY="your_api_key"
21+
```
22+
23+
## Run
24+
25+
```bash
26+
<the command>
27+
```
28+
29+
## What happens
30+
31+
What the example prints, how long it takes, and what to do with the result.
32+
33+
---
34+
35+
Delete this line and everything below it.
36+
37+
Keep the five sections above, in this order. `STANDARDS.md` at the repo root has the rules that apply to
38+
every example — credential handling, failure behaviour, formatting, and what to check before opening a pull
39+
request. Add a `package.json` only if the example has dependencies; if it does, set `engines` and a `format`
40+
script.

0 commit comments

Comments
 (0)