|
2 | 2 |
|
3 | 3 | # Author: @ralfhandl (inspired by the work of @MikeRalphson) |
4 | 4 |
|
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" | "dev"] |
| 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 "1.0.0" or "latest" |
| 11 | +# Finally, it may be run with "dev" to build "versions/*-dev.md" |
| 12 | +# |
6 | 13 | # It contains bashisms |
7 | 14 |
|
8 | | -mkdir -p deploy/overlay |
9 | | -mkdir -p deploy/js |
| 15 | +if [ "$1" = "dev" ]; then |
| 16 | + deploydir="deploy-preview" |
| 17 | +else |
| 18 | + deploydir="deploy/overlay" |
| 19 | +fi |
| 20 | + |
| 21 | +mkdir -p $deploydir/js |
| 22 | +mkdir -p $deploydir/temp |
| 23 | +cp -p node_modules/respec/builds/respec-w3c.* $deploydir/js/ |
10 | 24 |
|
11 | | -cd scripts/md2html |
12 | | -mkdir -p history |
13 | | -cp ../../EDITORS.md history/EDITORS_v1.0.0.md |
| 25 | +latest=$(git describe --abbrev=0 --tags) |
14 | 26 |
|
15 | | -# temporarily copy installed version of respec into build directory |
16 | | -cp -p ../../node_modules/respec/builds/respec-w3c.* ../../deploy/js/ |
| 27 | +if [ -z "$1" ]; then |
| 28 | + specifications=$(ls -1 versions/[1-9].[0-9].[0-9].md | sort -r) |
| 29 | +elif [ "$1" = "latest" ]; then |
| 30 | + specifications=$(ls -1 versions/$latest.md) |
| 31 | +elif [ "$1" = "dev" ]; then |
| 32 | + specifications=$(ls -1 versions/[1-9].[0-9].[0-9]-dev.md | sort -r) |
| 33 | +else |
| 34 | + specifications=$(ls -1 versions/$1.md) |
| 35 | +fi |
17 | 36 |
|
18 | | -# latest=`git describe --abbrev=0 --tags` -- introduce after release tags created |
19 | | -latest=1.0.0 |
20 | | -latestCopied=none |
| 37 | +latestCopied="none" |
21 | 38 | lastMinor="-" |
22 | | -for filename in $(ls -1 ../../versions/[1-9].[0-9].[0-9].md | sort -r) ; do |
23 | | - version=$(basename "$filename" .md) |
| 39 | + |
| 40 | +for specification in $specifications; do |
| 41 | + version=$(basename "$specification" .md) |
| 42 | + |
| 43 | + destination="$deploydir/v$version.html" |
| 44 | + if [ "$1" = "dev" ]; then |
| 45 | + maintainers="EDITORS.md" |
| 46 | + else |
| 47 | + maintainers="$(dirname $specification)/$version-editors.md" |
| 48 | + fi |
| 49 | + |
24 | 50 | minorVersion=${version:0:3} |
25 | | - tempfile=../../deploy/overlay/v$version-tmp.html |
26 | | - echo -e "\n=== v$version ===" |
| 51 | + tempfile="$deploydir/temp/$version.html" |
| 52 | + tempfile2="$deploydir/temp/$version-2.html" |
| 53 | + |
| 54 | + echo === Building $version to $destination |
27 | 55 |
|
28 | | - node md2html.js --maintainers ./history/EDITORS_v$version.md ${filename} > $tempfile |
29 | | - npx respec --use-local --src $tempfile --out ../../deploy/overlay/v$version.html |
30 | | - rm $tempfile |
| 56 | + node scripts/md2html/md2html.js --maintainers $maintainers $specification "$allVersions" > $tempfile |
| 57 | + npx respec --no-sandbox --use-local --src $tempfile --out $tempfile2 |
| 58 | + # remove unwanted Google Tag Manager and Google Analytics scripts |
| 59 | + sed -e 's/<script type="text\/javascript" async="" src="https:\/\/www.google-analytics.com\/analytics.js"><\/script>//' \ |
| 60 | + -e 's/<script type="text\/javascript" async="" src="https:\/\/www.googletagmanager.com\/gtag\/js?id=G-[^"]*"><\/script>//' \ |
| 61 | + $tempfile2 > $destination |
| 62 | + |
| 63 | + echo === Built $destination |
31 | 64 |
|
32 | 65 | if [ $version = $latest ]; then |
33 | | - if [[ ${version} != *"rc"* ]];then |
| 66 | + if [[ ${version} != *"rc"* ]]; then |
34 | 67 | # version is not a Release Candidate |
35 | | - ( cd ../../deploy/overlay && ln -sf v$version.html latest.html ) |
36 | | - latestCopied=v$version |
| 68 | + ln -sf $(basename $destination) $deploydir/latest.html |
| 69 | + latestCopied="v$version" |
37 | 70 | fi |
38 | 71 | fi |
39 | 72 |
|
40 | | - if [ ${minorVersion} != ${lastMinor} ]; then |
41 | | - ( cd ../../deploy/overlay && ln -sf v$version.html v$minorVersion.html ) |
| 73 | + if [ ${minorVersion} != ${lastMinor} ] && [ -z "$1" ]; then |
| 74 | + ln -sf $(basename $destination) $deploydir/v$minorVersion.html |
42 | 75 | lastMinor=$minorVersion |
43 | 76 | fi |
44 | 77 | done |
45 | | -echo Latest tag is $latest, copied $latestCopied to latest.html |
46 | 78 |
|
47 | | -# clean up build directory |
48 | | -rm ../../deploy/js/respec-w3c.* |
| 79 | +if [ "$latestCopied" != "none" ]; then |
| 80 | + echo Latest tag is $latest, copied $latestCopied to latest.html |
| 81 | +fi |
| 82 | + |
| 83 | +rm -r $deploydir/js |
| 84 | +rm -r $deploydir/temp |
0 commit comments