Skip to content

Commit 9b4f0ef

Browse files
authored
Migrate code-excerpts tooling to npm package version (#9638)
1 parent 8b6a868 commit 9b4f0ef

File tree

12 files changed

+21
-61
lines changed

12 files changed

+21
-61
lines changed

.cspell.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ words:
9191
- desaturate
9292
- Docsy
9393
- errorf
94+
- excerpter
9495
- favicons
9596
- Goldmark
9697
- htmltest

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
with:
2424
node-version-file: .nvmrc
2525

26-
- run: npm install --ignore-scripts --omit=optional
26+
# Don't --ignore-scripts: code-excerpter needs submodules
27+
- run: npm install --omit=optional
2728

2829
- run: npm run test:compound-tests

content/en/docs/languages/java/getting-started.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ description: Get telemetry for your app in less than 5 minutes!
44
weight: 10
55
---
66

7-
<!-- markdownlint-disable blanks-around-fences -->
87
<?code-excerpt path-base="examples/java/getting-started"?>
98

109
This page will show you how to get started with OpenTelemetry in Java.
@@ -62,8 +61,8 @@ dependencies {
6261
In that same folder, create a file called `DiceApplication.java` and add the
6362
following code to the file:
6463

65-
<!-- prettier-ignore-start -->
6664
<?code-excerpt "src/main/java/otel/DiceApplication.java"?>
65+
6766
```java
6867
package otel;
6968

@@ -80,13 +79,12 @@ public class DiceApplication {
8079
}
8180
}
8281
```
83-
<!-- prettier-ignore-end -->
8482

8583
Create another file called `RollController.java` and add the following code to
8684
the file:
8785

88-
<!-- prettier-ignore-start -->
8986
<?code-excerpt "src/main/java/otel/RollController.java"?>
87+
9088
```java
9189
package otel;
9290

@@ -118,7 +116,6 @@ public class RollController {
118116
}
119117
}
120118
```
121-
<!-- prettier-ignore-end -->
122119

123120
Build and run the application with the following command, then open
124121
<http://localhost:8080/rolldice> in your web browser to ensure it is working.

content/en/site/build/npm-scripts.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ are internal helpers and are not intended to be run directly.
3939
| ---------------------- | ----------------------------------------------------------- |
4040
| `check` | Run the most commonly needed check scripts in sequence. |
4141
| `check:all` | Run all check scripts in sequence. |
42+
| `check:code-excerpts` | Check code excerpts, fail if updates needed. |
4243
| `check:format` | Prettier and prose-wrap checks. |
4344
| `check:i18n` | Validate localization front matter (`default_lang_commit`). |
4445
| `check:links` | Run HTML link checker. |
@@ -57,6 +58,7 @@ are internal helpers and are not intended to be run directly.
5758
| Script | Description |
5859
| ------------------------- | -------------------------------------------------------------- |
5960
| `fix` | Run the most commonly needed fix scripts. |
61+
| `fix:code-excerpts` | Refresh code excerpts. |
6062
| `fix:all` | Run all fix scripts. |
6163
| `fix:format` | Apply Prettier and trim trailing spaces. |
6264
| `fix:format:staged` | Format only staged files. |
@@ -74,14 +76,14 @@ are internal helpers and are not intended to be run directly.
7476

7577
## Submodules and content
7678

77-
| Script | Description |
78-
| ------------------ | -------------------------------------------------- |
79-
| `get:submodule` | Init/update git submodules (set `GET=no` to skip). |
80-
| `update:submodule` | Update submodules to latest remote and fetch tags. |
81-
| `pin:submodule` | Pin submodule revisions (optional `PIN_SKIP`). |
82-
| `cp:spec` | Copy spec content (content-modules). |
83-
| `schemas:update` | Update OpenTelemetry spec submodule and content. |
84-
| `code-excerpts` | Rebuild code excerpts and update docs. |
79+
| Script | Description |
80+
| ------------------ | ------------------------------------------------------------------------------------ |
81+
| `code-excerpts` | Refresh code excerpts. DEPRECATED: use `fix:code-excerpts` or `check:code-excerpts`. |
82+
| `cp:spec` | Copy spec content (content-modules). |
83+
| `get:submodule` | Init/update git submodules (set `GET=no` to skip). |
84+
| `pin:submodule` | Pin submodule revisions (optional `PIN_SKIP`). |
85+
| `schemas:update` | Update OpenTelemetry spec submodule and content. |
86+
| `update:submodule` | Update submodules to latest remote and fetch tags. |
8587

8688
## Test and CI
8789

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"_check:markdown": "npx gulp lint-md",
1919
"_check:registry": "npx gulp validate-registry",
2020
"_check:text": "npx textlint content data `ls *.md`",
21+
"_code-excerpter-over-en": "code-excerpter content/en",
2122
"_commit:public": "HASH=$(git rev-parse --short main); cd public && git add -A && git commit -m \"Site at $HASH\"",
2223
"_diff:check": "git diff --name-only --exit-code",
2324
"_diff:fail": "git diff --name-only --exit-code || exit 1",
@@ -62,6 +63,7 @@
6263
"build": "npm run _build --",
6364
"cd:public": "cd public &&",
6465
"check:all": "npm run seq -- $(npm run -s _list:check:*)",
66+
"check:code-excerpts": "npm run _code-excerpter-over-en -- --dry-run --fail-on-update",
6567
"check:collector-sync:lint": "cd scripts/collector-sync && uv run ruff check src/",
6668
"check:collector-sync:types": "cd scripts/collector-sync && uv run mypy src/",
6769
"check:collector-sync": "cd scripts/collector-sync && uv run pytest",
@@ -78,13 +80,12 @@
7880
"check:text": "npm run _check:text -- ",
7981
"check": "CMD_SKIP=collector-sync npm run check:all",
8082
"clean": "make clean",
81-
"code-excerpts:get": "cd tools && dart run build_runner build --delete-conflicting-outputs --output ../tmp/excerpts",
82-
"code-excerpts:update-docs": "cd tools && dart run code_excerpt_updater --fragment-dir-path ../tmp/excerpts --src-dir-path examples --yaml --write-in-place content",
83-
"code-excerpts": "rm -Rf tmp/excerpts/* && npm run seq -- code-excerpts:get code-excerpts:update-docs",
83+
"code-excerpts": "node -e 'console.error(\"\\x1b[31mWARNING: THIS IS A DEPRECATED ALIAS, instead use: `fix:code-excerpts` or `check:code-excerpts`\\x1b[0m\")' && npm run fix:code-excerpts --",
8484
"cp:spec": "scripts/content-modules/cp-pages.sh",
8585
"diff:check": "npm run _diff:check || (echo; echo 'WARNING: the files above have not been committed'; echo)",
8686
"diff:fail": "npm run _diff:check || (echo; echo 'ERROR: the files above have changed. Locally rerun `npm run test-and-fix` and commit changes'; echo; exit 1)",
8787
"fix:all": "npm run all -- $(npm -s run _list:fix:*)",
88+
"fix:code-excerpts": "npm run _code-excerpter-over-en",
8889
"fix:collector-sync:lint": "cd scripts/collector-sync && uv run ruff check --fix src/",
8990
"fix:dict": "scripts/sort-cspell-words.pl .cspell/*.txt && npm run _fix:dict",
9091
"fix:expired": "npm run -s check:expired -- -q | xargs -r -I {} sh -c 'echo \"Deleting expired file: {}\" && rm {}'",
@@ -135,7 +136,7 @@
135136
"test:all": "npm run test:base && npm run test:compound-tests",
136137
"test:base": "npm run check",
137138
"test:collector-sync": "npm run check:collector-sync && npm run check:collector-sync:types && npm run check:collector-sync:lint",
138-
"test:compound-tests": "npm run seq -- $(CMD_SKIP=collector-sync npm -s run _list:test:compound-tests)",
139+
"test:compound-tests": "npm run seq -- check:code-excerpts $(CMD_SKIP=collector-sync npm -s run _list:test:compound-tests)",
139140
"test:edge-functions:live": "npm run _test:ef:live --",
140141
"test:edge-functions": "node --test \"netlify/edge-functions/**/*.test.ts\"",
141142
"test:redirects:live": "npm run _test:redirects:live --",
@@ -156,6 +157,7 @@
156157
"ajv-errors": "^3.0.0",
157158
"ajv-formats": "^3.0.1",
158159
"autoprefixer": "^10.4.27",
160+
"code-excerpter": "^0.1.0",
159161
"cspell": "^10.0.0",
160162
"gulp": "^5.0.1",
161163
"hugo-extended": "0.157.0",

tools/README.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

tools/build.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

tools/content/go

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/content/java

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/content/java-zero-code

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)