Skip to content

Commit 8e3015a

Browse files
authored
Merge pull request #4342 from duncanbeevers/build-src-changes
build.sh accepts version argument
2 parents 031d633 + 06a89cd commit 8e3015a

File tree

5 files changed

+77
-28
lines changed

5 files changed

+77
-28
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ target
66
atlassian-ide-plugin.xml
77
node_modules/
88
deploy/
9+
deploy-preview/
910
coverage/
1011
history
1112
Gemfile.lock

scripts/md2html/build.sh

+57-22
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,81 @@
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.
5+
# run this script from the root of the repo
6+
# It is designed to be run by a GitHub workflow
7+
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+
#
613
# It contains bashisms
714

8-
mkdir -p deploy/oas
9-
mkdir -p deploy/js
15+
if [ "$1" = "src" ]; then
16+
deploydir="deploy-preview"
17+
else
18+
deploydir="deploy/oas"
19+
fi
20+
21+
mkdir -p $deploydir/js
22+
mkdir -p $deploydir/temp
23+
cp -p node_modules/respec/builds/respec-w3c.* $deploydir/js/
1024

11-
cd scripts/md2html
25+
latest=$(git describe --abbrev=0 --tags)
1226

13-
cp -p ../../node_modules/respec/builds/respec-w3c.* ../../deploy/js/
27+
if [ -z "$1" ]; then
28+
specifications=$(ls -1 versions/[23456789].*.md | grep -v -e "\-editors" | sort -r)
29+
elif [ "$1" = "latest" ]; then
30+
specifications=$(ls -1 versions/$latest.md)
31+
elif [ "$1" = "src" ]; then
32+
specifications="src/oas.md"
33+
else
34+
specifications=$(ls -1 versions/$1.md)
35+
fi
1436

15-
latest=`git describe --abbrev=0 --tags`
16-
latestCopied=none
37+
latestCopied="none"
1738
lastMinor="-"
18-
for filename in $(ls -1 ../../versions/[23456789].*.md | sort -r) ; do
19-
if [[ ${filename} == *-editors.md ]];then
20-
continue
39+
40+
for specification in $specifications; do
41+
version=$(basename $specification .md)
42+
43+
if [ "$1" = "src" ]; then
44+
destination="$deploydir/$version.html"
45+
maintainers="EDITORS.md"
46+
else
47+
destination="$deploydir/v$version.html"
48+
maintainers="$(dirname $specification)/$version-editors.md"
2149
fi
2250

23-
version=$(basename "$filename" .md)
2451
minorVersion=${version:0:3}
25-
tempfile=../../deploy/oas/v$version-tmp.html
26-
echo -e "\n=== v$version ==="
52+
tempfile="$deploydir/temp/$version.html"
2753

28-
node md2html.js --maintainers ../../versions/$version-editors.md ${filename} > $tempfile
29-
npx respec --use-local --src $tempfile --out ../../deploy/oas/v$version.html
54+
echo === Building $version to $destination
55+
56+
node scripts/md2html/md2html.js --maintainers $maintainers $specification > $tempfile
57+
npx respec --use-local --src $tempfile --out $destination
3058
rm $tempfile
3159

60+
echo === Built $destination
61+
3262
if [ $version = $latest ]; then
33-
if [[ ${version} != *"rc"* ]];then
63+
if [[ ${version} != *"rc"* ]]; then
3464
# version is not a Release Candidate
35-
( cd ../../deploy/oas && ln -sf v$version.html latest.html )
36-
latestCopied=v$version
65+
ln -sf $(basename $destination) $deploydir/latest.html
66+
latestCopied="v$version"
3767
fi
3868
fi
3969

40-
if [ ${minorVersion} != ${lastMinor} ] && [ ${minorVersion} != 2.0 ]; then
41-
( cd ../../deploy/oas && ln -sf v$version.html v$minorVersion.html )
70+
if [ ${minorVersion} != ${lastMinor} ] && [[ ${minorVersion} =~ ^[3-9] ]]; then
71+
ln -sf $(basename $destination) $deploydir/v$minorVersion.html
4272
lastMinor=$minorVersion
4373
fi
4474
done
45-
echo Latest tag is $latest, copied $latestCopied to latest.html
4675

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

scripts/md2html/md2html.js

+1-4
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)