From 2fcacd6781bf7a446b8d8ff413322d88f5f354ec Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Wed, 1 May 2024 08:21:31 -0400 Subject: [PATCH] [CI] Add scripts to generate and check Chroma styles (#1976) --- netlify.toml | 4 +-- package.json | 20 +++++------ tools/gen-chroma-styles.sh | 71 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 13 deletions(-) create mode 100755 tools/gen-chroma-styles.sh diff --git a/netlify.toml b/netlify.toml index faebe858..10e6ec8e 100644 --- a/netlify.toml +++ b/netlify.toml @@ -3,11 +3,11 @@ [build] publish = "userguide/public" -command = "npm run docs-install && npm run build:preview" +command = "npm run ci:prepare && npm run build:preview" [build.environment] GO_VERSION = "1.21.6" HUGO_THEME = "repo" [context.production] -command = "npm run docs-install && npm run build:production" +command = "npm run ci:prepare && npm run build:production" diff --git a/package.json b/package.json index bff23185..a0a24a16 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "docsy", - "version": "0.9.2-dev.0-unreleased", - "version.next": "0.9.3-dev.0-unreleased", + "version": "0.10.0-dev.0-unreleased", + "version.next": "0.10.1-dev.0-unreleased", "repository": "github:google/docsy", "homepage": "https://www.docsy.dev", "license": "Apache-2.0", @@ -10,29 +10,27 @@ "_check:format": "npx prettier --check .??* *.md", "_cp:bs-rfs": "npx cpy 'node_modules/bootstrap/scss/vendor/*' assets/_vendor/bootstrap/scss/", "_diff:check": "git diff --name-only --exit-code", + "_gen-chroma-styles": "bash -c tools/gen-chroma-styles.sh && bash -c 'tools/gen-chroma-styles.sh -s onedark -o _dark.scss'", "_mkdir:hugo-mod": "npx mkdirp ../github.com/FortAwesome/Font-Awesome ../github.com/twbs/bootstrap", - "_prebuild": "npm run _cp:bs-rfs", - "_test:docs": "npm run cd:docs test", + "_prepare": "npm run _cp:bs-rfs && npm run _gen-chroma-styles", "build:preview": "npm run cd:docs build:preview", "build:production": "npm run cd:docs build:production", "build": "npm run cd:docs build", "cd:docs": "npm run _cd:docs -- npm run", - "check": "npm run check:format && npm run check:links--md", "check:format": "npm run _check:format || (echo '[help] Run: npm run fix:format'; exit 1)", "check:links--md": "ls *.md | xargs npx markdown-link-check --config .markdown-link-check.json", "check:links:all": "npm run cd:docs check:links:all", "check:links": "npm run cd:docs check:links", + "check": "npm run check:format && npm run check:links--md", + "ci:post": "npm run fix:format && npm run _diff:check", + "ci:prepare": "npm run docs-install && npm run _prepare && npm run _diff:check", "docs-install": "npm run _cd:docs -- npm install", "fix:format": "npm run _check:format -- --write", "get:hugo-modules": "node tools/getHugoModules/index.mjs", "postinstall": "npm run _mkdir:hugo-mod", - "prebuild:preview": "npm run _prebuild", - "prebuild:production": "npm run _prebuild", - "preserve": "npm run _prebuild", - "pretest": "npm run _prebuild", "serve": "npm run cd:docs serve", - "test:all": "npm run _test:docs && npm run check && npm run fix:format && npm run _diff:check", - "test": "npm run _test:docs", + "test:all": "npm run ci:prepare && npm run check && npm run cd:docs test && npm run ci:post", + "test": "npm run cd:docs test", "update:pkg:dep": "npm install --save-exact @fortawesome/fontawesome-free@latest bootstrap@latest", "update:pkg:hugo": "npm install --save-exact -D hugo-extended@latest" }, diff --git a/tools/gen-chroma-styles.sh b/tools/gen-chroma-styles.sh new file mode 100755 index 00000000..2a839414 --- /dev/null +++ b/tools/gen-chroma-styles.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +set -eo pipefail + +HUGO="npx hugo" +CHROMA_STYLE=tango +DEST_DIR=assets/scss/td/chroma +DEST_FILE=_light.scss +DEST_PATH=/dev/null # Set in process_CLI_args + +function _usage() { + cat <&2 + exit $status +} + +function process_CLI_args() { + while getopts ":ho:s:" opt; do + case $opt in + h) + usage + ;; + o) + DEST_FILE="$OPTARG" + ;; + s) + CHROMA_STYLE="$OPTARG" + ;; + \?) + echo "ERROR: unrecognized flag: -$OPTARG" + usage 1; + ;; + esac + done + + shift $((OPTIND-1)) + if [ "$#" -gt 0 ]; then + echo "ERROR: extra argument(s): $*" >&2 + usage 1; + fi + + DEST_PATH="$DEST_DIR/$DEST_FILE" +} + +function main() { + process_CLI_args "$@" + + # For more options, see https://gohugo.io/commands/hugo_gen_chromastyles/ + local cmd="$HUGO gen chromastyles --style=$CHROMA_STYLE >> $DEST_PATH" + echo "Generating $DEST_FILE using: $cmd" + + echo "/* Chroma style: $CHROMA_STYLE */" > $DEST_PATH + eval "$cmd" +} + +main "$@"