-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
44 lines (35 loc) · 1.48 KB
/
Copy pathMakefile
File metadata and controls
44 lines (35 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Codegen only. Task running is in the justfile, so bare `make` regenerates.
#
# A fixture is built from a document by this generator, so both are
# prerequisites: editing a document rebuilds that fixture, editing the
# generator rebuilds all of them. lib/build.ts rewrites the manifest on every
# run, which makes it a dependable stamp for the whole output directory.
CODEGEN := bin/index.ts $(wildcard lib/*.ts)
FIXTURES := __tests__/fixtures
MANIFEST := .openapi-codegen-manifest.json
DOCUMENTS := petstore test1 openai docker
STAMPS := $(DOCUMENTS:%=$(FIXTURES)/%/$(MANIFEST))
.DEFAULT_GOAL := fixtures
# a half-written document would otherwise satisfy the rule that produced it
.DELETE_ON_ERROR:
.PHONY: fixtures
fixtures: $(STAMPS)
$(FIXTURES)/%/$(MANIFEST): $(FIXTURES)/%.json $(CODEGEN) | node_modules
node --enable-source-maps bin/index.ts \
-i $< \
-o $(@D)
pnpm exec oxfmt --write $(@D)
# the generator reads json, and openai publishes yaml
$(FIXTURES)/openai.json: $(FIXTURES)/openai.yaml | node_modules
mkdir -p $(@D)
pnpm exec js-yaml $< > $@
$(FIXTURES)/openai.yaml:
curl https://raw.githubusercontent.com/openai/openai-openapi/refs/heads/master/openapi.yaml --output $@
# `make petstore` reads better than the stamp path
.PHONY: $(DOCUMENTS)
$(DOCUMENTS): %: $(FIXTURES)/%/$(MANIFEST)
# pnpm leaves the directory alone when it has nothing to do, so the touch is
# what stops every invocation reinstalling
node_modules: package.json pnpm-lock.yaml
pnpm install
touch node_modules