Skip to content

Commit

Permalink
feat: generate rules information json in travis build (zalando#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-tschumak committed Sep 19, 2018
1 parent f871fff commit a5e606e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ script:
- docker run -v $TRAVIS_BUILD_DIR:/documents/ --name asciidoctor-epub3 asciidoctor/docker-asciidoctor asciidoctor-epub3 -D /documents/output index.adoc
- cp -r assets output/
- cp -r -n legacy/* output/
- ./generate_rules_json.sh output
- mv output/index.pdf output/zalando-guidelines.pdf
- mv output/index.epub output/zalando-guidelines.epub

Expand Down
7 changes: 1 addition & 6 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ docker run -v ${SCRIPT_DIR}:/documents/ asciidoctor/docker-asciidoctor asciidoct
cp -r assets ${BUILD_DIR}/
cp -r -n legacy/* ${BUILD_DIR}/

grep -Pzoh "(?s)\[(#[0-9]+)\]\n[=]+\s+.*?\n" chapters/* | \
sed '$!N;s/\n/ /' | tr -d "[]{}\000"| sed '/^\s*$/d' | \
sort | perl -pi -e 'chomp if eof' | \
jq -Rs '{rules: split("\n") }' | \
jq '{rules: .rules | map(. | {id: split(" == ")[0], title: split(" == ")[1]})}' \
> ${BUILD_DIR}/rules
./generate_rules_json.sh

mv ${BUILD_DIR}/index.pdf ${BUILD_DIR}/zalando-guidelines.pdf
mv ${BUILD_DIR}/index.epub ${BUILD_DIR}/zalando-guidelines.epub
11 changes: 11 additions & 0 deletions generate_rules_json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# This script generates a JSON with information about the guideline rules.

build_dir=${1:-output}

grep -Pzoh "(?s)\[(#[0-9]+)\]\n[=]+\s+.*?\n" chapters/* | \
sed '$!N;s/\n/ /' | tr -d "[]{}\000"| sed '/^\s*$/d' | \
sort | perl -pi -e 'chomp if eof' | \
jq -Rs '{rules: split("\n") }' | \
jq '{rules: .rules | map(. | {id: split(" == ")[0], title: split(" == ")[1]})}' \
> ${build_dir}/rules

0 comments on commit a5e606e

Please sign in to comment.