@intentius/chant-lexicon-docker 0.124.98 → 0.124.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codegen/docs-cli.d.ts +0 -1
- package/dist/codegen/docs.d.ts +0 -1
- package/dist/codegen/generate-cli.d.ts +0 -1
- package/dist/codegen/generate-compose.d.ts +0 -1
- package/dist/codegen/generate-dockerfile.d.ts +0 -1
- package/dist/codegen/generate.d.ts +0 -1
- package/dist/codegen/naming.d.ts +0 -1
- package/dist/codegen/package.d.ts +0 -1
- package/dist/codegen/patches.d.ts +0 -1
- package/dist/codegen/versions.d.ts +0 -1
- package/dist/compose-key.d.ts +0 -1
- package/dist/composites/catalog.d.ts +0 -1
- package/dist/composites/docker-otel-collector.d.ts +0 -1
- package/dist/composites/docker-web-service.d.ts +0 -1
- package/dist/composites/index.d.ts +0 -1
- package/dist/coverage.d.ts +0 -1
- package/dist/default-labels.d.ts +0 -1
- package/dist/detect.d.ts +0 -1
- package/dist/dockerfile-order.d.ts +0 -1
- package/dist/export-resources.d.ts +0 -1
- package/dist/generated/index.d.ts +0 -1
- package/dist/generated/runtime.d.ts +0 -1
- package/dist/import/adapter.d.ts +0 -1
- package/dist/import/adapter.js +4 -2
- package/dist/import/embedded.d.ts +0 -1
- package/dist/import/engine.d.ts +0 -1
- package/dist/import/generator.d.ts +9 -2
- package/dist/import/generator.js +23 -1
- package/dist/import/live-export.d.ts +0 -1
- package/dist/import/parser.d.ts +0 -1
- package/dist/import/testdata/tar.d.ts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/integrity.json +2 -2
- package/dist/interpolation.d.ts +0 -1
- package/dist/lint/audit-catalog.d.ts +0 -1
- package/dist/lint/audit-lineage.d.ts +0 -1
- package/dist/lint/post-synth/add-url-checksum.d.ts +0 -1
- package/dist/lint/post-synth/apt-no-recommends.d.ts +0 -1
- package/dist/lint/post-synth/apt-update-alone.d.ts +0 -1
- package/dist/lint/post-synth/cache-busting-copy.d.ts +0 -1
- package/dist/lint/post-synth/copy-from-stage.d.ts +0 -1
- package/dist/lint/post-synth/docker-helpers.d.ts +0 -1
- package/dist/lint/post-synth/index.d.ts +0 -1
- package/dist/lint/post-synth/no-latest-image.d.ts +0 -1
- package/dist/lint/post-synth/no-root-user.d.ts +0 -1
- package/dist/lint/post-synth/prefer-copy.d.ts +0 -1
- package/dist/lint/post-synth/relative-workdir.d.ts +0 -1
- package/dist/lint/post-synth/repeated-cmd.d.ts +0 -1
- package/dist/lint/post-synth/root-after-user.d.ts +0 -1
- package/dist/lint/post-synth/ssh-port-exposed.d.ts +0 -1
- package/dist/lint/post-synth/unused-global-arg.d.ts +0 -1
- package/dist/lint/post-synth/unused-volume.d.ts +0 -1
- package/dist/lint/rules/data/deprecated-images.d.ts +0 -1
- package/dist/lint/rules/data/known-base-images.d.ts +0 -1
- package/dist/lint/rules/index.d.ts +0 -1
- package/dist/lint/rules/no-latest-tag.d.ts +0 -1
- package/dist/lint/rules/per-kind-order.d.ts +0 -1
- package/dist/list-artifacts.d.ts +0 -1
- package/dist/lsp/completions.d.ts +0 -1
- package/dist/lsp/hover.d.ts +0 -1
- package/dist/manifest.json +1 -1
- package/dist/package-cli.d.ts +0 -1
- package/dist/plugin.d.ts +0 -1
- package/dist/serializer.d.ts +0 -1
- package/dist/spec/fetch-compose.d.ts +0 -1
- package/dist/spec/fetch-engine.d.ts +0 -1
- package/dist/spec/parse-compose.d.ts +0 -1
- package/dist/spec/parse-engine.d.ts +0 -1
- package/dist/validate-cli.d.ts +0 -1
- package/dist/validate.d.ts +0 -1
- package/dist/variables.d.ts +0 -1
- package/package.json +4 -5
- package/dist/codegen/docs-cli.d.ts.map +0 -1
- package/dist/codegen/docs.d.ts.map +0 -1
- package/dist/codegen/generate-cli.d.ts.map +0 -1
- package/dist/codegen/generate-compose.d.ts.map +0 -1
- package/dist/codegen/generate-dockerfile.d.ts.map +0 -1
- package/dist/codegen/generate.d.ts.map +0 -1
- package/dist/codegen/naming.d.ts.map +0 -1
- package/dist/codegen/package.d.ts.map +0 -1
- package/dist/codegen/patches.d.ts.map +0 -1
- package/dist/codegen/versions.d.ts.map +0 -1
- package/dist/compose-key.d.ts.map +0 -1
- package/dist/composites/catalog.d.ts.map +0 -1
- package/dist/composites/docker-otel-collector.d.ts.map +0 -1
- package/dist/composites/docker-web-service.d.ts.map +0 -1
- package/dist/composites/index.d.ts.map +0 -1
- package/dist/coverage.d.ts.map +0 -1
- package/dist/default-labels.d.ts.map +0 -1
- package/dist/detect.d.ts.map +0 -1
- package/dist/dockerfile-order.d.ts.map +0 -1
- package/dist/export-resources.d.ts.map +0 -1
- package/dist/generated/index.d.ts.map +0 -1
- package/dist/generated/runtime.d.ts.map +0 -1
- package/dist/import/adapter.d.ts.map +0 -1
- package/dist/import/embedded.d.ts.map +0 -1
- package/dist/import/engine.d.ts.map +0 -1
- package/dist/import/generator.d.ts.map +0 -1
- package/dist/import/live-export.d.ts.map +0 -1
- package/dist/import/parser.d.ts.map +0 -1
- package/dist/import/testdata/tar.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/interpolation.d.ts.map +0 -1
- package/dist/lint/audit-catalog.d.ts.map +0 -1
- package/dist/lint/audit-lineage.d.ts.map +0 -1
- package/dist/lint/post-synth/add-url-checksum.d.ts.map +0 -1
- package/dist/lint/post-synth/apt-no-recommends.d.ts.map +0 -1
- package/dist/lint/post-synth/apt-update-alone.d.ts.map +0 -1
- package/dist/lint/post-synth/cache-busting-copy.d.ts.map +0 -1
- package/dist/lint/post-synth/copy-from-stage.d.ts.map +0 -1
- package/dist/lint/post-synth/docker-helpers.d.ts.map +0 -1
- package/dist/lint/post-synth/index.d.ts.map +0 -1
- package/dist/lint/post-synth/no-latest-image.d.ts.map +0 -1
- package/dist/lint/post-synth/no-root-user.d.ts.map +0 -1
- package/dist/lint/post-synth/prefer-copy.d.ts.map +0 -1
- package/dist/lint/post-synth/relative-workdir.d.ts.map +0 -1
- package/dist/lint/post-synth/repeated-cmd.d.ts.map +0 -1
- package/dist/lint/post-synth/root-after-user.d.ts.map +0 -1
- package/dist/lint/post-synth/ssh-port-exposed.d.ts.map +0 -1
- package/dist/lint/post-synth/unused-global-arg.d.ts.map +0 -1
- package/dist/lint/post-synth/unused-volume.d.ts.map +0 -1
- package/dist/lint/rules/data/deprecated-images.d.ts.map +0 -1
- package/dist/lint/rules/data/known-base-images.d.ts.map +0 -1
- package/dist/lint/rules/index.d.ts.map +0 -1
- package/dist/lint/rules/no-latest-tag.d.ts.map +0 -1
- package/dist/lint/rules/per-kind-order.d.ts.map +0 -1
- package/dist/list-artifacts.d.ts.map +0 -1
- package/dist/lsp/completions.d.ts.map +0 -1
- package/dist/lsp/hover.d.ts.map +0 -1
- package/dist/package-cli.d.ts.map +0 -1
- package/dist/plugin.d.ts.map +0 -1
- package/dist/serializer.d.ts.map +0 -1
- package/dist/spec/fetch-compose.d.ts.map +0 -1
- package/dist/spec/fetch-engine.d.ts.map +0 -1
- package/dist/spec/parse-compose.d.ts.map +0 -1
- package/dist/spec/parse-engine.d.ts.map +0 -1
- package/dist/validate-cli.d.ts.map +0 -1
- package/dist/validate.d.ts.map +0 -1
- package/dist/variables.d.ts.map +0 -1
- package/src/codegen/__snapshots__/okf.test.ts.snap +0 -555
- package/src/codegen/docs-cli.ts +0 -10
- package/src/codegen/docs.ts +0 -171
- package/src/codegen/generate-cli.ts +0 -36
- package/src/codegen/generate-compose.ts +0 -21
- package/src/codegen/generate-dockerfile.ts +0 -21
- package/src/codegen/generate.test.ts +0 -115
- package/src/codegen/generate.ts +0 -258
- package/src/codegen/naming.test.ts +0 -81
- package/src/codegen/naming.ts +0 -54
- package/src/codegen/okf.test.ts +0 -36
- package/src/codegen/package.ts +0 -59
- package/src/codegen/patches.ts +0 -42
- package/src/codegen/versions.ts +0 -46
- package/src/compose-key.ts +0 -31
- package/src/composites/catalog.test.ts +0 -39
- package/src/composites/catalog.ts +0 -118
- package/src/composites/docker-otel-collector.ts +0 -83
- package/src/composites/docker-web-service.test.ts +0 -34
- package/src/composites/docker-web-service.ts +0 -75
- package/src/composites/index.ts +0 -9
- package/src/coverage.test.ts +0 -33
- package/src/coverage.ts +0 -54
- package/src/default-labels.test.ts +0 -85
- package/src/default-labels.ts +0 -72
- package/src/detect.ts +0 -7
- package/src/dockerfile-order.ts +0 -20
- package/src/docs-examples.test.ts +0 -141
- package/src/export-resources.ts +0 -90
- package/src/generated/index.d.ts +0 -407
- package/src/generated/index.ts +0 -410
- package/src/generated/runtime.ts +0 -4
- package/src/import/adapter.ts +0 -99
- package/src/import/embedded-live.test.ts +0 -250
- package/src/import/embedded.ts +0 -83
- package/src/import/engine.ts +0 -107
- package/src/import/generator.test.ts +0 -134
- package/src/import/generator.ts +0 -202
- package/src/import/live-export.test.ts +0 -271
- package/src/import/live-export.ts +0 -359
- package/src/import/parser.test.ts +0 -137
- package/src/import/parser.ts +0 -269
- package/src/import/roundtrip.test.ts +0 -257
- package/src/import/testdata/configs-secrets.yaml +0 -15
- package/src/import/testdata/full.yaml +0 -43
- package/src/import/testdata/names-and-fields.yaml +0 -44
- package/src/import/testdata/simple.yaml +0 -9
- package/src/import/testdata/tar.ts +0 -24
- package/src/import/testdata/webapp.yaml +0 -41
- package/src/index.ts +0 -32
- package/src/interpolation.test.ts +0 -41
- package/src/interpolation.ts +0 -76
- package/src/lint/audit-catalog.ts +0 -28
- package/src/lint/audit-lineage.ts +0 -48
- package/src/lint/post-synth/add-url-checksum.ts +0 -38
- package/src/lint/post-synth/apt-no-recommends.ts +0 -43
- package/src/lint/post-synth/apt-update-alone.ts +0 -39
- package/src/lint/post-synth/cache-busting-copy.ts +0 -65
- package/src/lint/post-synth/copy-from-stage.ts +0 -54
- package/src/lint/post-synth/docker-helpers.ts +0 -194
- package/src/lint/post-synth/index.ts +0 -33
- package/src/lint/post-synth/no-latest-image.ts +0 -36
- package/src/lint/post-synth/no-root-user.ts +0 -38
- package/src/lint/post-synth/post-synth.test.ts +0 -330
- package/src/lint/post-synth/prefer-copy.ts +0 -53
- package/src/lint/post-synth/relative-workdir.ts +0 -38
- package/src/lint/post-synth/repeated-cmd.ts +0 -35
- package/src/lint/post-synth/root-after-user.ts +0 -44
- package/src/lint/post-synth/ssh-port-exposed.ts +0 -68
- package/src/lint/post-synth/unused-global-arg.ts +0 -38
- package/src/lint/post-synth/unused-volume.ts +0 -49
- package/src/lint/rules/data/deprecated-images.ts +0 -28
- package/src/lint/rules/data/known-base-images.ts +0 -20
- package/src/lint/rules/index.ts +0 -6
- package/src/lint/rules/no-latest-tag.ts +0 -63
- package/src/lint/rules/per-kind-order.ts +0 -130
- package/src/lint/rules/rules.test.ts +0 -170
- package/src/list-artifacts.test.ts +0 -141
- package/src/list-artifacts.ts +0 -164
- package/src/lsp/completions.test.ts +0 -40
- package/src/lsp/completions.ts +0 -21
- package/src/lsp/hover.test.ts +0 -35
- package/src/lsp/hover.ts +0 -39
- package/src/package-cli.ts +0 -25
- package/src/plugin.test.ts +0 -121
- package/src/plugin.ts +0 -268
- package/src/serializer.test.ts +0 -545
- package/src/serializer.ts +0 -444
- package/src/skills/chant-docker-patterns.md +0 -222
- package/src/skills/chant-docker.md +0 -156
- package/src/spec/fetch-compose.ts +0 -35
- package/src/spec/fetch-engine.ts +0 -25
- package/src/spec/parse-compose.ts +0 -195
- package/src/spec/parse-engine.ts +0 -59
- package/src/typecheck.e2e.test.ts +0 -125
- package/src/typed-props.test.ts +0 -60
- package/src/validate-cli.ts +0 -19
- package/src/validate.test.ts +0 -16
- package/src/validate.ts +0 -44
- package/src/variables.test.ts +0 -32
- package/src/variables.ts +0 -47
- /package/{src → dist}/generated/lexicon-docker.json +0 -0
package/src/codegen/docs.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Docker lexicon docs generation.
|
|
3
|
-
*
|
|
4
|
-
* Uses the shared docsPipeline/writeDocsSite flow like every other lexicon
|
|
5
|
-
* (chant #1731, #1755). Hand-written prose lives under docs/pages/, each
|
|
6
|
-
* page tagged with a Diátaxis quadrant; index.mdx and serialization.mdx are
|
|
7
|
-
* generated from the overview/outputFormat strings below, and rules.mdx is
|
|
8
|
-
* generated from the rule sources under src/lint/ the same way it always
|
|
9
|
-
* was — this used to be the one lexicon whose rules table could drift from
|
|
10
|
-
* source without anything catching it (#1312), and the shared pipeline
|
|
11
|
-
* keeps that guarantee.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { dirname, join } from "path";
|
|
15
|
-
import { fileURLToPath } from "url";
|
|
16
|
-
import { docsPipeline, writeDocsSite, type DocsConfig } from "@intentius/chant/codegen/docs";
|
|
17
|
-
|
|
18
|
-
const overview = `
|
|
19
|
-
The **Docker** lexicon provides typed constructors for Docker Compose services
|
|
20
|
-
and Dockerfile build instructions — services, volumes, networks, configs, secrets,
|
|
21
|
-
and multi-stage Dockerfiles.
|
|
22
|
-
|
|
23
|
-
\`\`\`bash
|
|
24
|
-
npm install --save-dev @intentius/chant-lexicon-docker
|
|
25
|
-
\`\`\`
|
|
26
|
-
|
|
27
|
-
## Quick Start
|
|
28
|
-
|
|
29
|
-
\`\`\`typescript
|
|
30
|
-
import { Service, Volume, Dockerfile, env } from "@intentius/chant-lexicon-docker";
|
|
31
|
-
|
|
32
|
-
export const db = new Service({
|
|
33
|
-
image: "postgres:16-alpine",
|
|
34
|
-
environment: {
|
|
35
|
-
POSTGRES_DB: "myapp",
|
|
36
|
-
POSTGRES_PASSWORD: env("DB_PASSWORD", { required: true }),
|
|
37
|
-
},
|
|
38
|
-
volumes: ["pgdata:/var/lib/postgresql/data"],
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
export const pgdata = new Volume({});
|
|
42
|
-
|
|
43
|
-
export const api = new Service({
|
|
44
|
-
image: "myapp:1.0",
|
|
45
|
-
ports: ["8080:8080"],
|
|
46
|
-
depends_on: ["db"],
|
|
47
|
-
});
|
|
48
|
-
\`\`\`
|
|
49
|
-
|
|
50
|
-
Build:
|
|
51
|
-
|
|
52
|
-
\`\`\`bash
|
|
53
|
-
chant build src --lexicon docker -o docker-compose.yml
|
|
54
|
-
\`\`\`
|
|
55
|
-
|
|
56
|
-
## Output Domains
|
|
57
|
-
|
|
58
|
-
| Entity | Output file | Section |
|
|
59
|
-
|--------|-------------|---------|
|
|
60
|
-
| \`Service\` | \`docker-compose.yml\` | \`services:\` |
|
|
61
|
-
| \`Volume\` | \`docker-compose.yml\` | \`volumes:\` |
|
|
62
|
-
| \`Network\` | \`docker-compose.yml\` | \`networks:\` |
|
|
63
|
-
| \`Config\` | \`docker-compose.yml\` | \`configs:\` |
|
|
64
|
-
| \`Secret\` | \`docker-compose.yml\` | \`secrets:\` |
|
|
65
|
-
| \`Dockerfile\` | \`Dockerfile.{name}\` | — |`;
|
|
66
|
-
|
|
67
|
-
const outputFormat = `
|
|
68
|
-
The Docker lexicon serializes to two output formats.
|
|
69
|
-
|
|
70
|
-
## docker-compose.yml
|
|
71
|
-
|
|
72
|
-
\`\`\`bash
|
|
73
|
-
chant build src --lexicon docker -o docker-compose.yml
|
|
74
|
-
\`\`\`
|
|
75
|
-
|
|
76
|
-
Each entity type maps to a top-level Compose section. The TypeScript export name becomes the key within that section.
|
|
77
|
-
|
|
78
|
-
\`\`\`typescript
|
|
79
|
-
export const db = new Service({ image: "postgres:16-alpine" });
|
|
80
|
-
export const pgdata = new Volume({});
|
|
81
|
-
export const backend = new Network({ driver: "bridge" });
|
|
82
|
-
\`\`\`
|
|
83
|
-
|
|
84
|
-
Produces:
|
|
85
|
-
|
|
86
|
-
\`\`\`yaml
|
|
87
|
-
services:
|
|
88
|
-
db:
|
|
89
|
-
image: postgres:16-alpine
|
|
90
|
-
|
|
91
|
-
volumes:
|
|
92
|
-
pgdata: null
|
|
93
|
-
|
|
94
|
-
networks:
|
|
95
|
-
backend:
|
|
96
|
-
driver: bridge
|
|
97
|
-
\`\`\`
|
|
98
|
-
|
|
99
|
-
\`defaultLabels()\` entities are not emitted as separate keys — their labels are merged into each service.
|
|
100
|
-
|
|
101
|
-
## Dockerfile.\\{name\\}
|
|
102
|
-
|
|
103
|
-
\`\`\`bash
|
|
104
|
-
chant build src --lexicon docker
|
|
105
|
-
# Writes Dockerfile.app, Dockerfile.builder, etc.
|
|
106
|
-
\`\`\`
|
|
107
|
-
|
|
108
|
-
Each \`Dockerfile\` entity produces a separate file. The export name is the suffix.
|
|
109
|
-
|
|
110
|
-
\`\`\`typescript
|
|
111
|
-
export const builder = new Dockerfile({ from: "node:20-alpine", ... });
|
|
112
|
-
// → Dockerfile.builder
|
|
113
|
-
\`\`\`
|
|
114
|
-
|
|
115
|
-
## Field mapping
|
|
116
|
-
|
|
117
|
-
| TypeScript | docker-compose.yml | Notes |
|
|
118
|
-
|-----------|-------------------|-------|
|
|
119
|
-
| \`env("X", { required: true })\` | \`\${X:?X is required}\` | Compose interpolation |
|
|
120
|
-
| \`env("X", { default: "v" })\` | \`\${X:-v}\` | Compose interpolation |
|
|
121
|
-
| \`env("X")\` | \`\${X}\` | Compose interpolation |
|
|
122
|
-
| \`external: true\` | \`external: true\` | Volume/Network |
|
|
123
|
-
|
|
124
|
-
## Specifying lexicon at build time
|
|
125
|
-
|
|
126
|
-
The \`--lexicon docker\` flag restricts output to Docker entities only — useful in mixed-lexicon projects:
|
|
127
|
-
|
|
128
|
-
\`\`\`bash
|
|
129
|
-
# Only Docker output
|
|
130
|
-
chant build src --lexicon docker -o docker-compose.yml
|
|
131
|
-
|
|
132
|
-
# Other lexicons still get their own outputs
|
|
133
|
-
chant build src --lexicon aws -o template.json
|
|
134
|
-
\`\`\``;
|
|
135
|
-
|
|
136
|
-
// "Optional: hand this page to your coding agent", shown under the overview's
|
|
137
|
-
// title. The Dockerfile shape is the ordered \`steps\` list from chant #3926.
|
|
138
|
-
const prompt = `Read https://intentius.io/chant/lexicons/docker/ and https://intentius.io/chant/lexicons/docker/dockerfiles/ first.
|
|
139
|
-
Bring this project's Docker files into chant TypeScript under src/.
|
|
140
|
-
Import each existing file. \`-o\` names a directory, and each import writes main.ts in it: \`chant import --lexicon docker docker-compose.yml -o src/compose/\`, and \`chant import --lexicon docker Dockerfile -o src/<name>/\` for each Dockerfile.
|
|
141
|
-
An imported Dockerfile is exported as \`app\`. Rename each export after its image, since the export name sets the output file (Dockerfile.<export>), and point the Compose service's \`build.dockerfile\` at that export (\`dockerfile: webImage\`) instead of the old file name.
|
|
142
|
-
Write every Dockerfile stage as an ordered \`steps\` list, one instruction per step, with FROM as the stage's \`from\` and ARGs before the first FROM in \`globalArgs\`:
|
|
143
|
-
steps: [{ workdir: "/app" }, { copy: "package*.json ./" }, { run: "npm ci" }, { copy: ". ." }, { user: "node" }, { cmd: ["node", "dist/index.js"] }]
|
|
144
|
-
Where two Dockerfiles repeat a stage or a run of steps, export it once as a const (a \`DockerfileStage\` or a \`DockerfileStep[]\`) from its own module and import it in both. Spread imported consts, not function results; a Dockerfile that needs parameters is a \`Composite\`.
|
|
145
|
-
Run \`chant build src --lexicon docker -o build/docker-compose.yml\` (Dockerfiles are written beside it) and compare with the original files, then \`chant lint src\`. Run \`chant lint src --fix\` for DKRS002 (per-kind fields to \`steps\`, then reorder the steps it writes), fix every other finding by hand, and repeat until lint is clean.
|
|
146
|
-
Report the generated docker-compose.yml and each Dockerfile.<name>, and any finding you left and why.
|
|
147
|
-
Do not push an image, run \`docker compose up\` against anything but the local Docker daemon, or change files outside this project.
|
|
148
|
-
Never deploy to a real cloud account or shared environment (with \`chant run\`, \`chant components\` or a platform's own CLI), approve (a pull request review, \`chant approve\` or \`chant run approve\`), override a policy denial (\`chant approve policy-override\`), or merge; never cut or publish a release (\`chant release cut --yes\` or \`chant release publish\`), push or delete a \`ci/*\` tag (\`chant ci tick\` pushes them), or change the value of an existing flag; never touch \`.chant/allowed_signers\` or \`chant/lifecycle\`.`;
|
|
149
|
-
|
|
150
|
-
export async function generateDocs(opts?: { verbose?: boolean }): Promise<void> {
|
|
151
|
-
const pkgDir = dirname(dirname(dirname(fileURLToPath(import.meta.url))));
|
|
152
|
-
|
|
153
|
-
const config: DocsConfig = {
|
|
154
|
-
name: "docker",
|
|
155
|
-
displayName: "Docker",
|
|
156
|
-
description: "Typed constructors for Docker Compose and Dockerfile configuration",
|
|
157
|
-
distDir: join(pkgDir, "dist"),
|
|
158
|
-
outDir: join(pkgDir, "docs"),
|
|
159
|
-
basePath: "/chant/lexicons/docker/",
|
|
160
|
-
overview,
|
|
161
|
-
outputFormat,
|
|
162
|
-
prompt,
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const result = docsPipeline(config);
|
|
166
|
-
writeDocsSite(config, result);
|
|
167
|
-
|
|
168
|
-
if (opts?.verbose) {
|
|
169
|
-
console.error("Documentation generated");
|
|
170
|
-
}
|
|
171
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env tsx
|
|
2
|
-
/**
|
|
3
|
-
* CLI entry point for Docker lexicon generation.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { dirname } from "path";
|
|
7
|
-
import { fileURLToPath } from "url";
|
|
8
|
-
import { generate, writeGeneratedFiles } from "./generate";
|
|
9
|
-
|
|
10
|
-
const pkgDir = dirname(dirname(dirname(fileURLToPath(import.meta.url))));
|
|
11
|
-
|
|
12
|
-
async function main() {
|
|
13
|
-
const verbose = process.argv.includes("--verbose") || process.argv.includes("-v");
|
|
14
|
-
const force = process.argv.includes("--force") || process.argv.includes("-f");
|
|
15
|
-
|
|
16
|
-
console.error("Generating Docker lexicon...");
|
|
17
|
-
|
|
18
|
-
const result = await generate({ verbose, force });
|
|
19
|
-
writeGeneratedFiles(result, pkgDir);
|
|
20
|
-
|
|
21
|
-
console.error(
|
|
22
|
-
`Generated ${result.resources} entities, ${result.properties} property types, ${result.enums} enums`,
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
if (result.warnings.length > 0) {
|
|
26
|
-
console.error(`${result.warnings.length} warnings:`);
|
|
27
|
-
for (const w of result.warnings) {
|
|
28
|
-
console.error(` ${w.file}: ${w.error}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
main().catch((err) => {
|
|
34
|
-
console.error("Generation failed:", err);
|
|
35
|
-
process.exit(1);
|
|
36
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate Compose entity types from the Compose Spec JSON Schema.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { fetchComposeSpec } from "../spec/fetch-compose";
|
|
6
|
-
import { parseComposeSpec, type ComposeParseResult } from "../spec/parse-compose";
|
|
7
|
-
|
|
8
|
-
export interface ComposeGenerateResult {
|
|
9
|
-
results: ComposeParseResult[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export async function generateComposePipeline(opts: { force?: boolean; verbose?: boolean } = {}): Promise<ComposeGenerateResult> {
|
|
13
|
-
if (opts.verbose) console.error("Fetching Compose Spec...");
|
|
14
|
-
const data = await fetchComposeSpec(opts.force);
|
|
15
|
-
|
|
16
|
-
if (opts.verbose) console.error("Parsing Compose Spec...");
|
|
17
|
-
const results = parseComposeSpec(data);
|
|
18
|
-
|
|
19
|
-
if (opts.verbose) console.error(`Parsed ${results.length} Compose entity types`);
|
|
20
|
-
return { results };
|
|
21
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate Dockerfile entity types from the Docker Engine API OpenAPI spec.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { fetchEngineApi } from "../spec/fetch-engine";
|
|
6
|
-
import { parseEngineApi, type DockerfileParseResult } from "../spec/parse-engine";
|
|
7
|
-
|
|
8
|
-
export interface DockerfileGenerateResult {
|
|
9
|
-
result: DockerfileParseResult;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export async function generateDockerfilePipeline(opts: { force?: boolean; verbose?: boolean } = {}): Promise<DockerfileGenerateResult> {
|
|
13
|
-
if (opts.verbose) console.error("Fetching Docker Engine API...");
|
|
14
|
-
const data = await fetchEngineApi(opts.force);
|
|
15
|
-
|
|
16
|
-
if (opts.verbose) console.error("Parsing Engine API for Dockerfile types...");
|
|
17
|
-
const result = parseEngineApi(data);
|
|
18
|
-
|
|
19
|
-
if (opts.verbose) console.error(`Parsed ${result.instructions.length} Dockerfile instructions`);
|
|
20
|
-
return { result };
|
|
21
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect, vi } from "vitest";
|
|
2
|
-
import { generate, writeGeneratedFiles } from "./generate";
|
|
3
|
-
import { mkdirSync, rmSync, existsSync, readFileSync } from "fs";
|
|
4
|
-
import { join } from "path";
|
|
5
|
-
import { tmpdir } from "os";
|
|
6
|
-
|
|
7
|
-
// Mock the network fetches so tests run offline and fast
|
|
8
|
-
vi.mock("../spec/fetch-compose", () => ({
|
|
9
|
-
fetchComposeSpec: async () => Buffer.from("{}"),
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
vi.mock("../spec/fetch-engine", () => ({
|
|
13
|
-
fetchEngineApi: async () => Buffer.from("{}"),
|
|
14
|
-
}));
|
|
15
|
-
|
|
16
|
-
describe("generate()", () => {
|
|
17
|
-
test("returns a GenerateResult with correct shape", async () => {
|
|
18
|
-
const result = await generate({ verbose: false });
|
|
19
|
-
|
|
20
|
-
expect(result).toBeDefined();
|
|
21
|
-
expect(typeof result.resources).toBe("number");
|
|
22
|
-
expect(typeof result.properties).toBe("number");
|
|
23
|
-
expect(typeof result.enums).toBe("number");
|
|
24
|
-
expect(Array.isArray(result.warnings)).toBe(true);
|
|
25
|
-
expect(typeof result.lexiconJSON).toBe("string");
|
|
26
|
-
expect(typeof result.typesDTS).toBe("string");
|
|
27
|
-
expect(typeof result.indexTS).toBe("string");
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("generates all 6 entity types", async () => {
|
|
31
|
-
const result = await generate({ verbose: false });
|
|
32
|
-
expect(result.resources).toBe(6); // 5 Compose + 1 Dockerfile
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test("lexiconJSON includes all entity class names", async () => {
|
|
36
|
-
const result = await generate({ verbose: false });
|
|
37
|
-
const json = JSON.parse(result.lexiconJSON);
|
|
38
|
-
|
|
39
|
-
expect(json.Service).toBeDefined();
|
|
40
|
-
expect(json.Volume).toBeDefined();
|
|
41
|
-
expect(json.Network).toBeDefined();
|
|
42
|
-
expect(json.DockerConfig).toBeDefined();
|
|
43
|
-
expect(json.DockerSecret).toBeDefined();
|
|
44
|
-
expect(json.Dockerfile).toBeDefined();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test("lexiconJSON entries have resourceType and kind", async () => {
|
|
48
|
-
const result = await generate({ verbose: false });
|
|
49
|
-
const json = JSON.parse(result.lexiconJSON);
|
|
50
|
-
|
|
51
|
-
expect(json.Service.resourceType).toBe("Docker::Compose::Service");
|
|
52
|
-
expect(json.Service.kind).toBe("resource");
|
|
53
|
-
expect(json.Dockerfile.resourceType).toBe("Docker::Dockerfile");
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test("indexTS exports all entity names", async () => {
|
|
57
|
-
const result = await generate({ verbose: false });
|
|
58
|
-
expect(result.indexTS).toContain("export const Service");
|
|
59
|
-
expect(result.indexTS).toContain("export const Dockerfile");
|
|
60
|
-
expect(result.indexTS).toContain('createResource("Docker::Compose::Service"');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test("typesDTS declares all entity interfaces", async () => {
|
|
64
|
-
const result = await generate({ verbose: false });
|
|
65
|
-
expect(result.typesDTS).toContain("interface ServiceProps");
|
|
66
|
-
expect(result.typesDTS).toContain("interface DockerfileProps");
|
|
67
|
-
expect(result.typesDTS).toContain("declare const Service");
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test("every Compose entity's props accept x- extension fields, which import keeps (#4136)", async () => {
|
|
71
|
-
const result = await generate({ verbose: false });
|
|
72
|
-
for (const out of [result.typesDTS, result.indexTS]) {
|
|
73
|
-
for (const name of ["ServiceProps", "VolumeProps", "NetworkProps", "DockerConfigProps", "DockerSecretProps"]) {
|
|
74
|
-
const body = out.slice(out.indexOf(`export interface ${name} {`));
|
|
75
|
-
expect(body.slice(0, body.indexOf("\n}")), name).toContain("[extension: `x-${string}`]: unknown;");
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test("properties count is non-zero", async () => {
|
|
81
|
-
const result = await generate({ verbose: false });
|
|
82
|
-
expect(result.properties).toBeGreaterThan(0);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
describe("writeGeneratedFiles()", () => {
|
|
87
|
-
const tmpDir = join(tmpdir(), `chant-docker-test-${Date.now()}`);
|
|
88
|
-
|
|
89
|
-
test("writes all expected files to src/generated/", async () => {
|
|
90
|
-
mkdirSync(join(tmpDir, "src", "generated"), { recursive: true });
|
|
91
|
-
|
|
92
|
-
const result = await generate({ verbose: false });
|
|
93
|
-
writeGeneratedFiles(result, tmpDir);
|
|
94
|
-
|
|
95
|
-
expect(existsSync(join(tmpDir, "src", "generated", "lexicon-docker.json"))).toBe(true);
|
|
96
|
-
expect(existsSync(join(tmpDir, "src", "generated", "index.ts"))).toBe(true);
|
|
97
|
-
expect(existsSync(join(tmpDir, "src", "generated", "index.d.ts"))).toBe(true);
|
|
98
|
-
expect(existsSync(join(tmpDir, "src", "generated", "runtime.ts"))).toBe(true);
|
|
99
|
-
|
|
100
|
-
// Clean up
|
|
101
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test("lexicon-docker.json is valid JSON", async () => {
|
|
105
|
-
mkdirSync(join(tmpDir, "src", "generated"), { recursive: true });
|
|
106
|
-
|
|
107
|
-
const result = await generate({ verbose: false });
|
|
108
|
-
writeGeneratedFiles(result, tmpDir);
|
|
109
|
-
|
|
110
|
-
const json = readFileSync(join(tmpDir, "src", "generated", "lexicon-docker.json"), "utf-8");
|
|
111
|
-
expect(() => JSON.parse(json)).not.toThrow();
|
|
112
|
-
|
|
113
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
114
|
-
});
|
|
115
|
-
});
|
package/src/codegen/generate.ts
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Docker lexicon generation pipeline.
|
|
3
|
-
*
|
|
4
|
-
* Orchestrates both Compose and Dockerfile type generation,
|
|
5
|
-
* then writes merged artifacts to src/generated/.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { writeFileSync, mkdirSync } from "fs";
|
|
9
|
-
import { join } from "path";
|
|
10
|
-
import { generateComposePipeline } from "./generate-compose";
|
|
11
|
-
import { generateDockerfilePipeline } from "./generate-dockerfile";
|
|
12
|
-
import { entityTypeToTsName } from "./naming";
|
|
13
|
-
import { PER_KIND_ORDER } from "../dockerfile-order";
|
|
14
|
-
import { COMPOSE_STRING, type ComposeParseResult } from "../spec/parse-compose";
|
|
15
|
-
import type { DockerfileParseResult, DockerfileInstruction } from "../spec/parse-engine";
|
|
16
|
-
|
|
17
|
-
export interface DockerGenerateResult {
|
|
18
|
-
resources: number;
|
|
19
|
-
properties: number;
|
|
20
|
-
enums: number;
|
|
21
|
-
warnings: Array<{ file: string; error: string }>;
|
|
22
|
-
lexiconJSON: string;
|
|
23
|
-
typesDTS: string;
|
|
24
|
-
indexTS: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Run the full Docker generation pipeline.
|
|
29
|
-
*/
|
|
30
|
-
export async function generate(opts: { verbose?: boolean; force?: boolean } = {}): Promise<DockerGenerateResult> {
|
|
31
|
-
const [composeResult, dockerfileResult] = await Promise.all([
|
|
32
|
-
generateComposePipeline(opts),
|
|
33
|
-
generateDockerfilePipeline(opts),
|
|
34
|
-
]);
|
|
35
|
-
|
|
36
|
-
const allCompose = composeResult.results;
|
|
37
|
-
const dockerfile = dockerfileResult.result;
|
|
38
|
-
|
|
39
|
-
const lexiconJSON = generateLexiconJSON(allCompose, dockerfile);
|
|
40
|
-
const typesDTS = generateTypesDTS(allCompose, dockerfile);
|
|
41
|
-
const indexTS = generateIndexTS(allCompose, dockerfile);
|
|
42
|
-
|
|
43
|
-
const propertyCount = allCompose.reduce((n, c) => n + c.properties.length, 0) + dockerfile.instructions.length;
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
resources: allCompose.length + 1, // +1 for Dockerfile
|
|
47
|
-
properties: propertyCount,
|
|
48
|
-
enums: 0,
|
|
49
|
-
warnings: [],
|
|
50
|
-
lexiconJSON,
|
|
51
|
-
typesDTS,
|
|
52
|
-
indexTS,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function generateLexiconJSON(compose: ComposeParseResult[], dockerfile: DockerfileParseResult): string {
|
|
57
|
-
const entries: Record<string, unknown> = {};
|
|
58
|
-
|
|
59
|
-
for (const c of compose) {
|
|
60
|
-
const tsName = entityTypeToTsName(c.typeName);
|
|
61
|
-
entries[tsName] = {
|
|
62
|
-
resourceType: c.typeName,
|
|
63
|
-
kind: "resource",
|
|
64
|
-
description: c.description ?? "",
|
|
65
|
-
properties: Object.fromEntries(
|
|
66
|
-
c.properties.map((p) => [p.name, { type: p.type, description: p.description ?? "" }]),
|
|
67
|
-
),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const dfName = entityTypeToTsName(dockerfile.typeName);
|
|
72
|
-
entries[dfName] = {
|
|
73
|
-
resourceType: dockerfile.typeName,
|
|
74
|
-
kind: "resource",
|
|
75
|
-
description: dockerfile.description ?? "",
|
|
76
|
-
properties: {
|
|
77
|
-
...Object.fromEntries(
|
|
78
|
-
dockerfile.instructions.filter((i) => !i.stepOnly).map((i) => [i.name, { description: i.description ?? "" }]),
|
|
79
|
-
),
|
|
80
|
-
globalArgs: { description: "ARG instructions written before the first FROM" },
|
|
81
|
-
steps: { description: "Instructions after FROM, written in the order given; one instruction per step" },
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
return JSON.stringify(entries, null, 2);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function generateTypesDTS(compose: ComposeParseResult[], dockerfile: DockerfileParseResult): string {
|
|
89
|
-
const lines: string[] = [
|
|
90
|
-
"// Code generated by chant generate. DO NOT EDIT.",
|
|
91
|
-
'import type { Declarable } from "@intentius/chant/declarable";',
|
|
92
|
-
"",
|
|
93
|
-
// This file is type-checked on its own (validate's types-compile), so it
|
|
94
|
-
// can't import the interpolation module; an env() value is matched by shape.
|
|
95
|
-
"/** An `env()` interpolation, as returned by the lexicon's `env`. */",
|
|
96
|
-
"interface EnvIntrinsic { toJSON(): string; toString(): string; }",
|
|
97
|
-
"",
|
|
98
|
-
];
|
|
99
|
-
|
|
100
|
-
lines.push(...composeTypeLines(compose));
|
|
101
|
-
for (const c of compose) {
|
|
102
|
-
const tsName = entityTypeToTsName(c.typeName);
|
|
103
|
-
lines.push(`export declare const ${tsName}: new (props?: ${tsName}Props, attributes?: Record<string, unknown>) => Declarable;`);
|
|
104
|
-
}
|
|
105
|
-
lines.push("");
|
|
106
|
-
|
|
107
|
-
const dfName = entityTypeToTsName(dockerfile.typeName);
|
|
108
|
-
lines.push(...dockerfileTypeLines(dockerfile));
|
|
109
|
-
lines.push(`export declare const ${dfName}: new (props?: DockerfileProps, attributes?: Record<string, unknown>) => Declarable;`);
|
|
110
|
-
lines.push("");
|
|
111
|
-
|
|
112
|
-
return lines.join("\n");
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function generateIndexTS(compose: ComposeParseResult[], dockerfile: DockerfileParseResult): string {
|
|
116
|
-
const lines: string[] = [
|
|
117
|
-
"// Code generated by chant generate. DO NOT EDIT.",
|
|
118
|
-
'import { createResource } from "./runtime";',
|
|
119
|
-
'import type { Declarable } from "@intentius/chant/declarable";',
|
|
120
|
-
'import type { EnvIntrinsic } from "../interpolation";',
|
|
121
|
-
"",
|
|
122
|
-
// createResource returns a constructor with untyped props. Each constructor
|
|
123
|
-
// below is cast to one that takes its props type, so a misspelled key or a
|
|
124
|
-
// wrong field type is a compile error where the resource is written, and
|
|
125
|
-
// the editor completes the fields (#3934).
|
|
126
|
-
"/** A docker resource constructor whose props are type-checked. */",
|
|
127
|
-
"export type DockerResourceConstructor<P> = new (props?: P, attributes?: Record<string, unknown>) => InstanceType<ReturnType<typeof createResource>>;",
|
|
128
|
-
"",
|
|
129
|
-
];
|
|
130
|
-
|
|
131
|
-
lines.push(...composeTypeLines(compose));
|
|
132
|
-
for (const c of compose) {
|
|
133
|
-
const tsName = entityTypeToTsName(c.typeName);
|
|
134
|
-
lines.push(
|
|
135
|
-
`export const ${tsName} = createResource("${c.typeName}", "docker", {}) as unknown as DockerResourceConstructor<${tsName}Props>;`,
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
lines.push("");
|
|
140
|
-
// The Dockerfile prop types are exported from here too (not only from
|
|
141
|
-
// index.d.ts, which index.ts shadows) so a module can type a shared stage
|
|
142
|
-
// or step list: `export const install: DockerfileStep[] = [...]`.
|
|
143
|
-
lines.push(...dockerfileTypeLines(dockerfile));
|
|
144
|
-
lines.push("");
|
|
145
|
-
const dfName = entityTypeToTsName(dockerfile.typeName);
|
|
146
|
-
lines.push(
|
|
147
|
-
`export const ${dfName} = createResource("${dockerfile.typeName}", "docker", {}) as unknown as DockerResourceConstructor<DockerfileProps>;`,
|
|
148
|
-
);
|
|
149
|
-
lines.push("");
|
|
150
|
-
|
|
151
|
-
return lines.join("\n");
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/** One props interface per Compose entity. */
|
|
155
|
-
function composeTypeLines(compose: ComposeParseResult[]): string[] {
|
|
156
|
-
const lines: string[] = [
|
|
157
|
-
"/**",
|
|
158
|
-
" * A Compose string value: a string, an `env()` interpolation, or an entity",
|
|
159
|
-
" * (service, network, volume, config, secret or Dockerfile), which is written as its name.",
|
|
160
|
-
" */",
|
|
161
|
-
`export type ${COMPOSE_STRING} = string | EnvIntrinsic | Declarable;`,
|
|
162
|
-
"",
|
|
163
|
-
];
|
|
164
|
-
for (const c of compose) {
|
|
165
|
-
const tsName = entityTypeToTsName(c.typeName);
|
|
166
|
-
if (c.description) lines.push(`/** ${c.description} */`);
|
|
167
|
-
lines.push(`export interface ${tsName}Props {`);
|
|
168
|
-
for (const p of c.properties) {
|
|
169
|
-
const opt = p.required ? "" : "?";
|
|
170
|
-
if (p.description) lines.push(` /** ${p.description} */`);
|
|
171
|
-
lines.push(` ${p.name}${opt}: ${p.type};`);
|
|
172
|
-
}
|
|
173
|
-
// The Compose spec allows `x-` extension fields on every entity, and import keeps them (#4136).
|
|
174
|
-
lines.push(` /** A Compose extension field. The spec allows any \`x-\` key, and Compose itself ignores it. */`);
|
|
175
|
-
lines.push(" [extension: `x-${string}`]: unknown;");
|
|
176
|
-
lines.push(`}`);
|
|
177
|
-
lines.push("");
|
|
178
|
-
}
|
|
179
|
-
return lines;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* The Dockerfile prop types: one `DockerfileStep` variant per instruction,
|
|
184
|
-
* the stage, and the props. The per-kind fields keep the instructions they
|
|
185
|
-
* always had; SHELL, STOPSIGNAL and ONBUILD are steps only.
|
|
186
|
-
*/
|
|
187
|
-
function dockerfileTypeLines(dockerfile: DockerfileParseResult): string[] {
|
|
188
|
-
const lines: string[] = [];
|
|
189
|
-
const stepInstructions = dockerfile.instructions.filter((i) => i.name !== "from");
|
|
190
|
-
const perKind = stepInstructions.filter((i) => !i.stepOnly);
|
|
191
|
-
const stepValue = (i: DockerfileInstruction): string =>
|
|
192
|
-
["string", ...(i.numeric ? ["number"] : []), ...(i.execForm ? ["string[]"] : [])].join(" | ");
|
|
193
|
-
const fixed = PER_KIND_ORDER.map((k) => k.toUpperCase()).join(", ");
|
|
194
|
-
|
|
195
|
-
lines.push(`/** The Dockerfile instructions a step can name. FROM is the stage's own \`from\` field. */`);
|
|
196
|
-
lines.push(`export type DockerfileInstructionName = ${stepInstructions.map((i) => JSON.stringify(i.name)).join(" | ")};`);
|
|
197
|
-
lines.push(`type DockerfileStepOf<K extends DockerfileInstructionName, V> = { [P in K]: V } & { [P in Exclude<DockerfileInstructionName, K>]?: never };`);
|
|
198
|
-
lines.push(`/**`);
|
|
199
|
-
lines.push(` * One Dockerfile instruction, named by its single key: \`{ run: "npm ci" }\` is \`RUN npm ci\`.`);
|
|
200
|
-
lines.push(` * A string[] value (run, cmd, entrypoint, shell) is written in JSON exec form.`);
|
|
201
|
-
lines.push(` */`);
|
|
202
|
-
lines.push(`export type DockerfileStep =`);
|
|
203
|
-
for (const i of stepInstructions) {
|
|
204
|
-
lines.push(` /** ${i.name.toUpperCase()}: ${i.description ?? ""} */`);
|
|
205
|
-
lines.push(` | DockerfileStepOf<${JSON.stringify(i.name)}, ${stepValue(i)}>`);
|
|
206
|
-
}
|
|
207
|
-
lines[lines.length - 1] += ";";
|
|
208
|
-
|
|
209
|
-
const fields = (): void => {
|
|
210
|
-
lines.push(` /** Instructions after FROM, written exactly in this order. Can't be combined with the per-kind fields. */`);
|
|
211
|
-
lines.push(` steps?: DockerfileStep[];`);
|
|
212
|
-
for (const i of perKind) {
|
|
213
|
-
lines.push(` /** ${i.name.toUpperCase()} as a per-kind field, written in the fixed order. Use \`steps\` to choose the order. */`);
|
|
214
|
-
lines.push(` ${i.name}?: ${i.multi ? "string[]" : "string"};`);
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
const fixedDoc = ` * Without \`steps\`, the per-kind fields are written in a fixed order: ${fixed}.`;
|
|
218
|
-
|
|
219
|
-
lines.push(`/**`);
|
|
220
|
-
lines.push(` * One build stage: FROM, then its instructions.`);
|
|
221
|
-
lines.push(fixedDoc);
|
|
222
|
-
lines.push(` */`);
|
|
223
|
-
lines.push(`export interface DockerfileStage {`);
|
|
224
|
-
lines.push(` from: string;`);
|
|
225
|
-
lines.push(` as?: string;`);
|
|
226
|
-
fields();
|
|
227
|
-
lines.push(`}`);
|
|
228
|
-
lines.push(`/**`);
|
|
229
|
-
lines.push(` * A Dockerfile: \`stages\` for a multi-stage build, or \`from\` and the stage fields for one stage.`);
|
|
230
|
-
lines.push(fixedDoc);
|
|
231
|
-
lines.push(` */`);
|
|
232
|
-
lines.push(`export interface DockerfileProps {`);
|
|
233
|
-
lines.push(` name?: string;`);
|
|
234
|
-
lines.push(` /** ARG instructions written before the first FROM, e.g. \`["NODE_VERSION=20"]\`. */`);
|
|
235
|
-
lines.push(` globalArgs?: string[];`);
|
|
236
|
-
lines.push(` from?: string;`);
|
|
237
|
-
lines.push(` as?: string;`);
|
|
238
|
-
lines.push(` stages?: DockerfileStage[];`);
|
|
239
|
-
fields();
|
|
240
|
-
lines.push(`}`);
|
|
241
|
-
return lines;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Write generated artifacts to disk under baseDir/src/generated/.
|
|
246
|
-
*/
|
|
247
|
-
export function writeGeneratedFiles(result: DockerGenerateResult, baseDir: string): void {
|
|
248
|
-
const generatedDir = join(baseDir, "src", "generated");
|
|
249
|
-
mkdirSync(generatedDir, { recursive: true });
|
|
250
|
-
|
|
251
|
-
writeFileSync(join(generatedDir, "lexicon-docker.json"), result.lexiconJSON);
|
|
252
|
-
writeFileSync(join(generatedDir, "index.d.ts"), result.typesDTS);
|
|
253
|
-
writeFileSync(join(generatedDir, "index.ts"), result.indexTS);
|
|
254
|
-
writeFileSync(
|
|
255
|
-
join(generatedDir, "runtime.ts"),
|
|
256
|
-
`/**\n * Runtime factory constructors — re-exported from core.\n */\nexport { createResource, createProperty } from "@intentius/chant/runtime";\n`,
|
|
257
|
-
);
|
|
258
|
-
}
|