build, doc: use new api doc tooling · nodejs/node@e55edde
@@ -101,7 +101,7 @@ V ?= 0
101101# Use -e to double check in case it's a broken link
102102available-node = \
103103 if [ -x '$(NODE)' ] && [ -e '$(NODE)' ]; then \
104- '$(NODE)' $(1); \
104+PATH='$(PWD)/out/$(BUILDTYPE):$$PATH' '$(NODE)' $(1); \
105105 elif [ -x `command -v node` ] && [ -e `command -v node` ] && [ `command -v node` ]; then \
106106`command -v node` $(1); \
107107 else \
@@ -340,7 +340,6 @@ coverage-run-js: ## Run JavaScript tests with coverage.
340340# This does not run tests of third-party libraries inside deps.
341341test: all ## Run default tests, linters, and build docs.
342342$(MAKE) -s tooltest
343-$(MAKE) -s test-doc
344343$(MAKE) -s build-addons
345344$(MAKE) -s build-js-native-api-tests
346345$(MAKE) -s build-node-api-tests
@@ -376,7 +375,7 @@ test-valgrind: all ## Run tests using valgrind.
376375test-check-deopts: all
377376$(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) --check-deopts parallel sequential
378377379-DOCBUILDSTAMP_PREREQS = tools/doc/addon-verify.mjs doc/api/addons.md
378+DOCBUILDSTAMP_PREREQS = doc/api/addons.md
380379381380ifeq ($(OSTYPE),aix)
382381DOCBUILDSTAMP_PREREQS := $(DOCBUILDSTAMP_PREREQS) out/$(BUILDTYPE)/node.exp
@@ -385,14 +384,22 @@ ifeq ($(OSTYPE),os400)
385384DOCBUILDSTAMP_PREREQS := $(DOCBUILDSTAMP_PREREQS) out/$(BUILDTYPE)/node.exp
386385endif
387386387+DOC_KIT ?= tools/doc/node_modules/@nodejs/doc-kit/bin/cli.mjs
388+388389node_use_openssl_and_icu = $(call available-node,"-p" \
389390 "process.versions.openssl != undefined && process.versions.icu != undefined")
390391test/addons/.docbuildstamp: $(DOCBUILDSTAMP_PREREQS) tools/doc/node_modules
391392 @if [ "$(shell $(node_use_openssl_and_icu))" != "true" ]; then \
392393echo "Skipping .docbuildstamp (no crypto and/or no ICU)"; \
393394else \
394395$(RM) -r test/addons/??_*/; \
395- [ -x '$(NODE)' ] && '$(NODE)' $< || node $< ; \
396+$(call available-node, \
397+$(DOC_KIT) generate \
398+ -t addon-verify \
399+ -i doc/api/addons.md \
400+ -o test/addons/ \
401+ --type-map doc/type-map.json \
402+ ) \
396403 [ $$? -eq 0 ] && touch $@; \
397404fi
398405@@ -791,14 +798,14 @@ test-v8 test-v8-intl test-v8-benchmarks test-v8-all:
791798$(warning Use the git repo instead: $$ git clone https://github.com/nodejs/node.git)
792799endif
793800794-apidoc_dirs = out/doc out/doc/api out/doc/api/assets
801+apidoc_dirs = out/doc out/doc/api
795802skip_apidoc_files = doc/api/quic.md
796803797804apidoc_sources = $(filter-out $(skip_apidoc_files), $(wildcard doc/api/*.md))
798805apidocs_html = $(addprefix out/,$(apidoc_sources:.md=.html))
799806apidocs_json = $(addprefix out/,$(apidoc_sources:.md=.json))
800807801-apiassets = $(subst api_assets,api/assets,$(addprefix out/,$(wildcard doc/api_assets/*)))
808+run-npm-ci = $(PWD)/$(NPM) ci --omit=dev
802809803810tools/doc/node_modules: tools/doc/package.json
804811 @if [ "$(shell $(node_use_openssl_and_icu))" != "true" ]; then \
@@ -807,14 +814,12 @@ tools/doc/node_modules: tools/doc/package.json
807814cd tools/doc && $(call available-node,$(run-npm-ci)) \
808815fi
809816817+RAWVER=$(shell $(PYTHON) tools/getnodeversion.py)
818+VERSION=v$(RAWVER)
819+810820.PHONY: doc-only
811-doc-only: tools/doc/node_modules \
812-$(apidoc_dirs) $(apiassets) ## Build the docs with the local or the global Node.js binary.
813- @if [ "$(shell $(node_use_openssl_and_icu))" != "true" ]; then \
814-echo "Skipping doc-only (no crypto and/or no ICU)"; \
815-else \
816-$(MAKE) out/doc/api/all.html out/doc/api/all.json out/doc/api/stability; \
817-fi
821+.NOTPARALLEL: doc-only
822+doc-only: $(apidoc_dirs) $(apidocs_html) $(apidocs_json) out/doc/api/all.html out/doc/api/all.json out/doc/apilinks.json ## Builds the docs with the local or the global Node.js binary.
818823819824.PHONY: doc
820825doc: $(NODE_EXE) doc-only ## Build Node.js, and then build the documentation with the new binary.
@@ -829,82 +834,60 @@ out/doc/api: doc/api
829834 mkdir -p $@
830835 cp -r doc/api out/doc
831836832-# If it's a source tarball, assets are already in doc/api/assets
833-out/doc/api/assets:
834- mkdir -p $@
835-if [ -d doc/api/assets ]; then cp -r doc/api/assets out/doc/api; fi;
836-837-# If it's not a source tarball, we need to copy assets from doc/api_assets
838-out/doc/api/assets/%: doc/api_assets/% | out/doc/api/assets
839- @cp $< $@ ; $(RM) out/doc/api/assets/README.md
840-841-842-run-npm-ci = '$(PWD)/$(NPM)' ci
843-844-LINK_DATA = out/doc/apilinks.json
845-VERSIONS_DATA = out/previous-doc-versions.json
846-gen-api = tools/doc/generate.mjs --node-version=$(FULLVERSION) \
847- --apilinks=$(LINK_DATA) $< --output-directory=out/doc/api \
848- --versions-file=$(VERSIONS_DATA)
849-gen-apilink = tools/doc/apilinks.mjs $(LINK_DATA) $(wildcard lib/*.js)
850-851-$(LINK_DATA): $(wildcard lib/*.js) tools/doc/apilinks.mjs | out/doc
852-$(call available-node, $(gen-apilink))
853-854-# Regenerate previous versions data if the current version changes
855-$(VERSIONS_DATA): CHANGELOG.md src/node_version.h tools/doc/versions.mjs
856-$(call available-node, tools/doc/versions.mjs $@)
857-858-node_use_icu = $(call available-node,"-p" "typeof Intl === 'object'")
859-860-out/doc/api/%.json out/doc/api/%.html: doc/api/%.md tools/doc/generate.mjs \
861- tools/doc/markdown.mjs tools/doc/html.mjs tools/doc/json.mjs \
862- tools/doc/apilinks.mjs $(VERSIONS_DATA) | $(LINK_DATA) out/doc/api
863- @if [ "$(shell $(node_use_icu))" != "true" ]; then \
864-echo "Skipping documentation generation (no ICU)"; \
865-else \
866-$(call available-node, $(gen-api)) \
867-fi
868-869-out/doc/api/all.html: $(apidocs_html) tools/doc/allhtml.mjs \
870- tools/doc/apilinks.mjs | out/doc/api
871- @if [ "$(shell $(node_use_icu))" != "true" ]; then \
872-echo "Skipping HTML single-page doc generation (no ICU)"; \
873-else \
874-$(call available-node, tools/doc/allhtml.mjs) \
875-fi
876-877-out/doc/api/all.json: $(apidocs_json) tools/doc/alljson.mjs | out/doc/api
878- @if [ "$(shell $(node_use_icu))" != "true" ]; then \
879-echo "Skipping JSON single-file generation (no ICU)"; \
837+# Generate all doc files (individual and all.html/all.json) in a single doc-kit call
838+# Using grouped targets (&:) so Make knows one command produces all outputs
839+ifeq ($(OSTYPE),aix)
840+# TODO(@nodejs/web-infra): AIX is currently hanging during HTML minification
841+$(apidocs_html) $(apidocs_json) out/doc/api/all.html out/doc/api/all.json:
842+ @echo "Skipping $@ (not currently supported by $(OSTYPE) machines)"
843+else
844+$(apidocs_html) $(apidocs_json) out/doc/api/all.html out/doc/api/all.json &: $(apidoc_sources) tools/doc/node_modules | out/doc/api
845+ @if [ "$(shell $(node_use_openssl_and_icu))" != "true" ]; then \
846+echo "Skipping $@ (no crypto and/or no ICU)"; \
880847else \
881-$(call available-node, tools/doc/alljson.mjs) \
848+$(call available-node, \
849+$(DOC_KIT) generate \
850+ -t legacy-html-all \
851+ -t legacy-json-all \
852+ -i doc/api/*.md \
853+ --ignore $(skip_apidoc_files) \
854+ -o out/doc/api \
855+ -c ./CHANGELOG.md \
856+ -v $(VERSION) \
857+ --index doc/api/index.md \
858+ --type-map doc/type-map.json \
859+ ) \
882860fi
861+endif
883862884-.PHONY: out/doc/api/stability
885-out/doc/api/stability: out/doc/api/all.json tools/doc/stability.mjs | out/doc/api
886- @if [ "$(shell $(node_use_icu))" != "true" ]; then \
887-echo "Skipping stability indicator generation (no ICU)"; \
863+out/doc/apilinks.json: $(wildcard lib/*.js) tools/doc/node_modules | out/doc
864+ @if [ "$(shell $(node_use_openssl_and_icu))" != "true" ]; then \
865+echo "Skipping $@ (no crypto and/or no ICU)"; \
888866else \
889-$(call available-node, tools/doc/stability.mjs) \
867+$(call available-node, \
868+$(DOC_KIT) generate \
869+ -t api-links \
870+ -i lib/*.js \
871+ -o $(@D) \
872+ -c ./CHANGELOG.md \
873+ -v $(VERSION) \
874+ --type-map doc/type-map.json \
875+ ) \
890876fi
891877892878.PHONY: docopen
893-docopen: out/doc/api/all.html ## Open the documentation in a web browser.
879+docopen: doc-only ## Open the documentation in a web browser.
894880 @$(PYTHON) -mwebbrowser file://$(abspath $<)
895881896882.PHONY: docserve
897-docserve: $(apidocs_html) $(apiassets) ## Serve the documentation on localhost:8000.
883+docserve: doc-only ## Serve the documentation on localhost:8000.
898884 @$(PYTHON) -m http.server 8000 --bind 127.0.0.1 --directory out/doc/api
899885900886.PHONY: docclean
901887.NOTPARALLEL: docclean
902888docclean: ## Remove the generated documentation.
903889$(RM) -r out/doc
904-$(RM) "$(VERSIONS_DATA)"
905890906-RAWVER=$(shell $(PYTHON) tools/getnodeversion.py)
907-VERSION=v$(RAWVER)
908891CHANGELOG=doc/changelogs/CHANGELOG_V$(firstword $(subst ., ,$(RAWVER))).md
909892910893# For nightly builds, you must set DISTTYPE to "nightly", "next-nightly" or