"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/scripts/doc-build.sh" (11 Apr 2017, 3260 Bytes) of package /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/env bash
    2 
    3 if [[ $DEBUG != "" ]]; then
    4   set -x
    5 fi
    6 set -o errexit
    7 set -o pipefail
    8 
    9 if ! [ -x node_modules/.bin/marked-man ]; then
   10   ps=0
   11   if [ -f .building_marked-man ]; then
   12     pid=$(cat .building_marked-man)
   13     ps=$(ps -p $pid | grep $pid | wc -l) || true
   14   fi
   15 
   16   if [ -f .building_marked-man ] && [ $ps != 0 ]; then
   17     while [ -f .building_marked-man ]; do
   18       sleep 1
   19     done
   20   else
   21     # a race to see which make process will be the one to install marked-man
   22     echo $$ > .building_marked-man
   23     sleep 1
   24     if [ $(cat .building_marked-man) == $$ ]; then
   25       make node_modules/.bin/marked-man
   26       rm .building_marked-man
   27     else
   28       while [ -f .building_marked-man ]; do
   29         sleep 1
   30       done
   31     fi
   32   fi
   33 fi
   34 
   35 if ! [ -x node_modules/.bin/marked ]; then
   36   ps=0
   37   if [ -f .building_marked ]; then
   38     pid=$(cat .building_marked)
   39     ps=$(ps -p $pid | grep $pid | wc -l) || true
   40   fi
   41 
   42   if [ -f .building_marked ] && [ $ps != 0 ]; then
   43     while [ -f .building_marked ]; do
   44       sleep 1
   45     done
   46   else
   47     # a race to see which make process will be the one to install marked
   48     echo $$ > .building_marked
   49     sleep 1
   50     if [ $(cat .building_marked) == $$ ]; then
   51       make node_modules/.bin/marked
   52       rm .building_marked
   53     else
   54       while [ -f .building_marked ]; do
   55         sleep 1
   56       done
   57     fi
   58   fi
   59 fi
   60 
   61 src=$1
   62 dest=$2
   63 name=$(basename ${src%.*})
   64 date=$(date -u +'%Y-%m-%d %H:%M:%S')
   65 version=$(node cli.js -v)
   66 
   67 mkdir -p $(dirname $dest)
   68 
   69 html_replace_tokens () {
   70     local url=$1
   71     sed "s|@NAME@|$name|g" \
   72     | sed "s|@DATE@|$date|g" \
   73     | sed "s|@URL@|$url|g" \
   74     | sed "s|@VERSION@|$version|g" \
   75     | perl -p -e 's/<h1([^>]*)>([^\(]*\([0-9]\)) -- (.*?)<\/h1>/<h1>\2<\/h1> <p>\3<\/p>/g' \
   76     | perl -p -e 's/npm-npm/npm/g' \
   77     | perl -p -e 's/([^"-])(npm-)?README(?!\.html)(\(1\))?/\1<a href="..\/..\/doc\/README.html">README<\/a>/g' \
   78     | perl -p -e 's/<title><a href="[^"]+README.html">README<\/a><\/title>/<title>README<\/title>/g' \
   79     | perl -p -e 's/([^"-])([^\(> ]+)(\(1\))/\1<a href="..\/cli\/\2.html">\2\3<\/a>/g' \
   80     | perl -p -e 's/([^"-])([^\(> ]+)(\(3\))/\1<a href="..\/api\/\2.html">\2\3<\/a>/g' \
   81     | perl -p -e 's/([^"-])([^\(> ]+)(\(5\))/\1<a href="..\/files\/\2.html">\2\3<\/a>/g' \
   82     | perl -p -e 's/([^"-])([^\(> ]+)(\(7\))/\1<a href="..\/misc\/\2.html">\2\3<\/a>/g' \
   83     | perl -p -e 's/\([1357]\)<\/a><\/h1>/<\/a><\/h1>/g' \
   84     | (if [ $(basename $(dirname $dest)) == "doc" ]; then
   85             perl -p -e 's/ href="\.\.\// href="/g'
   86         else
   87             cat
   88         fi)
   89 }
   90 
   91 man_replace_tokens () {
   92     sed "s|@VERSION@|$version|g" \
   93     | perl -p -e 's/(npm\\-)?([a-zA-Z\\\.\-]*)\(1\)/npm help \2/g' \
   94     | perl -p -e 's/(npm\\-)?([a-zA-Z\\\.\-]*)\(([57])\)/npm help \3 \2/g' \
   95     | perl -p -e 's/(npm\\-)?([a-zA-Z\\\.\-]*)\(3\)/npm apihelp \2/g' \
   96     | perl -p -e 's/npm\(1\)/npm help npm/g' \
   97     | perl -p -e 's/npm\(3\)/npm apihelp npm/g'
   98 }
   99 
  100 case $dest in
  101   *.[1357])
  102     ./node_modules/.bin/marked-man --roff $src \
  103     | man_replace_tokens > $dest
  104     exit $?
  105     ;;
  106   *.html)
  107     url=${dest/html\//}
  108     (cat html/dochead.html && \
  109      cat $src | ./node_modules/.bin/marked &&
  110      cat html/docfoot.html)\
  111     | html_replace_tokens $url \
  112     > $dest
  113     exit $?
  114     ;;
  115   *)
  116     echo "Invalid destination type: $dest" >&2
  117     exit 1
  118     ;;
  119 esac