Skip to content

Commit 9449ce8

Browse files
committed
Build single targets
build.sh with no arguments builds all versions build.sh <version> builds single version build.sh latest builds latest version build.sh src builds from src/oas.md Resolve Google Analytics snippet location relative to md2html.js Update tests to reflect inclusion of snippet Pre-requisite to #4341
1 parent 031d633 commit 9449ce8

File tree

4 files changed

+76
-29
lines changed

4 files changed

+76
-29
lines changed

scripts/md2html/build.sh

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,80 @@
22

33
# Author: @MikeRalphson
44

5-
# run this script from the root of the repo. It is designed to be run by a GitHub workflow.
6-
# It contains bashisms
5+
# run this script from the root of the repo
6+
# It is designed to be run by a GitHub workflow
77

8-
mkdir -p deploy/oas
9-
mkdir -p deploy/js
8+
# Usage: build.sh [version | "latest" | "src"]
9+
# When run with no arguments, it builds artifacts for all published specification versions.
10+
# It may also be run with a specific version argument, such as "3.1.1" or "latest"
11+
# Finally, it may be run with "src" to build "src/oas.md"
12+
#
13+
# It contains bashisms
1014

11-
cd scripts/md2html
15+
if [ -z "$1" ]; then
16+
deploydir="deploy/oas"
17+
else
18+
deploydir="deploy-preview"
19+
fi
1220

13-
cp -p ../../node_modules/respec/builds/respec-w3c.* ../../deploy/js/
21+
mkdir -p $deploydir/js
22+
mkdir -p $deploydir/temp
1423

15-
latest=`git describe --abbrev=0 --tags`
16-
latestCopied=none
24+
latest=$(git describe --abbrev=0 --tags)
25+
latestCopied="none"
1726
lastMinor="-"
18-
for filename in $(ls -1 ../../versions/[23456789].*.md | sort -r) ; do
19-
if [[ ${filename} == *-editors.md ]];then
20-
continue
21-
fi
2227

23-
version=$(basename "$filename" .md)
28+
if [ -z "$1" ]; then
29+
specifications=$(ls -1 versions/[23456789].*.md | grep -v -e "\-editors" | sort -r)
30+
elif [ "$1" = "latest" ]; then
31+
specifications=$(ls -1 versions/$latest.md)
32+
elif [ "$1" = "src" ]; then
33+
specifications="src/oas.md"
34+
else
35+
specifications=$(ls -1 versions/$1.md)
36+
fi
37+
38+
cp -p node_modules/respec/builds/respec-w3c.* $deploydir/js/
39+
40+
for specification in $specifications; do
41+
version=$(basename $specification .md)
2442
minorVersion=${version:0:3}
25-
tempfile=../../deploy/oas/v$version-tmp.html
26-
echo -e "\n=== v$version ==="
43+
tempfile="$deploydir/temp/$version.html"
2744

28-
node md2html.js --maintainers ../../versions/$version-editors.md ${filename} > $tempfile
29-
npx respec --use-local --src $tempfile --out ../../deploy/oas/v$version.html
45+
if [ "$1" = "src" ]; then
46+
destination="$deploydir/$version.html"
47+
maintainers="EDITORS.md"
48+
else
49+
destination="$deploydir/v$version.html"
50+
maintainers="$(dirname $specification)/$version-editors.md"
51+
fi
52+
53+
echo === Building $version to $destination
54+
55+
node scripts/md2html/md2html.js --maintainers $maintainers $specification > $tempfile
56+
npx respec --use-local --src $tempfile --out $destination
3057
rm $tempfile
3158

59+
echo === Built $destination
60+
3261
if [ $version = $latest ]; then
33-
if [[ ${version} != *"rc"* ]];then
62+
if [[ ${version} != *"rc"* ]]; then
3463
# version is not a Release Candidate
35-
( cd ../../deploy/oas && ln -sf v$version.html latest.html )
36-
latestCopied=v$version
64+
ln -sf $(basename $destination) $deploydir/latest.html
65+
latestCopied="v$version"
3766
fi
3867
fi
3968

4069
if [ ${minorVersion} != ${lastMinor} ] && [ ${minorVersion} != 2.0 ]; then
41-
( cd ../../deploy/oas && ln -sf v$version.html v$minorVersion.html )
70+
ln -sf $(basename $destination) $deploydir/v$minorVersion.html
4271
lastMinor=$minorVersion
4372
fi
4473
done
45-
echo Latest tag is $latest, copied $latestCopied to latest.html
4674

47-
rm ../../deploy/js/respec-w3c.*
75+
if [ "$latestCopied" != "none" ]; then
76+
echo Latest tag is $latest, copied $latestCopied to latest.html
77+
fi
78+
79+
rm $deploydir/js/respec-w3c.*
80+
rmdir $deploydir/js
81+
rmdir $deploydir/temp

scripts/md2html/md2html.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ function preface(title,options) {
132132
preface += '<meta name="color-scheme" content="light dark">';
133133
preface += '<script src="../js/respec-w3c.js" class="remove"></script>';
134134
preface += `<script class="remove">var respecConfig = ${JSON.stringify(respec)};</script>`;
135-
try {
136-
preface += fs.readFileSync('./analytics/google.html','utf8');
137-
}
138-
catch (ex) {}
135+
preface += fs.readFileSync(path.resolve(__dirname,'./analytics/google.html'),'utf8');
139136
preface += '</head><body>';
140137
preface += '<style>';
141138
preface += fs.readFileSync(path.resolve(__dirname,'main.css'),'utf8').split(/\r?\n/).join(' ');

0 commit comments

Comments
 (0)