Skip to content

Commit

Permalink
feat: rewrite docs generation scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Aug 16, 2022
1 parent 9dc6983 commit 08550f1
Show file tree
Hide file tree
Showing 183 changed files with 3,588 additions and 26,033 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
with:
node-version: 16.x
cache: npm
- run: make freshdocs
- run: node scripts/git-dirty.js
- run: node bin/npm-cli.js run resetdeps
- run: node bin/npm-cli.js run docs

licenses:
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/create-cli-deps-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ jobs:
echo "Prepping CLI repo for release"
cd cli
git checkout "$npm_vtag"
make
make release
echo "Removing old npm"
Expand Down
1 change: 1 addition & 0 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ graph LR;
dezalgo-->asap;
dezalgo-->wrappy;
docs-->cmark-gfm;
docs-->front-matter;
docs-->jsdom;
docs-->marked-man;
docs-->mdx-js-mdx["@mdx-js/mdx"];
Expand Down
91 changes: 3 additions & 88 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,94 +4,9 @@ SHELL = bash
PUBLISHTAG = $(shell node scripts/publish-tag.js)
BRANCH = $(shell git rev-parse --abbrev-ref HEAD)

# these docs have the @VERSION@ tag in them, so they have to be rebuilt
# whenever the package.json is touched, in case the version changed.
version_mandocs = $(shell grep -rl '@VERSION@' docs/content \
|sed 's|.md|.1|g' \
|sed 's|docs/content/commands/|man/man1/|g' )

cli_mandocs = $(shell find docs/content/commands -name '*.md' \
|sed 's|.md|.1|g' \
|sed 's|docs/content/commands/|man/man1/|g' )

files_mandocs = $(shell find docs/content/configuring-npm -name '*.md' \
|sed 's|.md|.5|g' \
|sed 's|docs/content/configuring-npm/|man/man5/|g' )

misc_mandocs = $(shell find docs/content/using-npm -name '*.md' \
|sed 's|.md|.7|g' \
|sed 's|docs/content/using-npm/|man/man7/|g' )

mandocs = $(cli_mandocs) $(files_mandocs) $(misc_mandocs)

markdown_docs = $(shell for file in $(find lib/commands -name '*.js'); do echo docs/content/commands/npm-$(basename $file .js).md; done)

all: docs

docs: mandocs htmldocs $(markdown_docs)

# don't regenerate the snapshot if we're generating
# snapshots, since presumably we just did that.
mandocs: deps $(mandocs)
@ ! [ "$${npm_lifecycle_event}" = "snap" ] && \
! [ "$${npm_lifecycle_event}" = "postsnap" ] && \
TAP_SNAPSHOT=1 node test/lib/utils/config/definitions.js || true

$(version_mandocs): package.json

htmldocs: deps
node bin/npm-cli.js rebuild cmark-gfm
node docs/bin/dockhand.js

clean: docsclean gitclean

docsclean:
rm -rf man

deps:
node bin/npm-cli.js run resetdeps

## targets for man files, these are encouraged to be only built by running `make docs` or `make mandocs`
man/man1/%.1: docs/content/commands/%.md docs/bin/docs-build.js
@[ -d man/man1 ] || mkdir -p man/man1
node docs/bin/docs-build.js $< $@

man/man5/npm-json.5: man/man5/package.json.5
cp $< $@

man/man5/npm-global.5: man/man5/folders.5
cp $< $@

man/man5/%.5: docs/content/configuring-npm/%.md docs/bin/docs-build.js
@[ -d man/man5 ] || mkdir -p man/man5
node docs/bin/docs-build.js $< $@

man/man7/%.7: docs/content/using-npm/%.md docs/bin/docs-build.js
@[ -d man/man7 ] || mkdir -p man/man7
node docs/bin/docs-build.js $< $@

# Any time the config definitions description changes, automatically
# update the documentation to account for it
docs/content/using-npm/config.md: docs/bin/config-doc.js lib/utils/config/*.js
node docs/bin/config-doc.js

mddocs: docs/bin/config-doc-command.js lib/utils/config/*.js lib/utils/cmd-list.js
@for file in $(shell find docs/content/commands -name 'npm-*.md'); do \
cmdname=$$(basename $$file .md) ;\
cmdname=$${cmdname##npm-} ;\
echo node docs/bin/config-doc-command.js $${file} lib/commands/$${cmdname}.js ;\
node docs/bin/config-doc-command.js $${file} lib/commands/$${cmdname}.js ;\
done

docs/content/commands/npm-%.md: lib/commands/%.js
node docs/bin/config-doc-command.js $@ $<

freshdocs:
touch lib/utils/config/definitions.js
touch docs/bin/*.js
make docs
make mddocs

test-all: deps
node bin/npm-cli.js run test-all

Expand All @@ -111,12 +26,12 @@ prune: deps
node bin/npm-cli.js prune --omit=dev --no-save --no-audit --no-fund
node scripts/git-dirty.js

publish: gitclean ls-ok link test-all docs prune
publish: gitclean ls-ok link test-all prune
git push origin $(BRANCH) &&\
git push origin --tags &&\
node bin/npm-cli.js publish --tag=$(PUBLISHTAG)

release: gitclean ls-ok docs prune
release: gitclean ls-ok prune
@bash scripts/release.sh

.PHONY: all latest install dev link docs mddocs clean uninstall test-all man docsclean release ls-ok deps prune freshdocs
.PHONY: all link gitclean uninstall test-all release ls-ok deps prune
1 change: 0 additions & 1 deletion docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
!/.eslintrc.js
!/.gitignore
!/bin/
!/content/
!/lib/
!/nav.yml
!/package.json
21 changes: 21 additions & 0 deletions docs/bin/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { resolve, join } = require('path')
const run = require('../lib/build.js')

const rootDir = resolve(__dirname, '..')

run({
verify: !!process.env.CI,
content: join(rootDir, 'lib', 'content'),
template: join(rootDir, 'lib', 'template.html'),
nav: join(rootDir, 'nav.yml'),
man: resolve(rootDir, '..', 'man'),
html: join(rootDir, 'output'),
md: join(rootDir, 'content'),
})
.then((res) => {
console.log(`Wrote ${res.length} files`)
})
.catch((err) => {
process.exitCode = 1
console.error(err)
})
142 changes: 0 additions & 142 deletions docs/bin/config-doc-command.js

This file was deleted.

63 changes: 0 additions & 63 deletions docs/bin/config-doc.js

This file was deleted.

Loading

0 comments on commit 08550f1

Please sign in to comment.