Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 23rd, 2012  |  syntax: None  |  size: 7.20 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env bash
  2.  
  3.  
  4. src=$PWD
  5. ant_build_script_remote=git://github.com/h5bp/ant-build-script.git
  6. h5bp_remote=git://github.com/h5bp/html5-boilerplate.git
  7. bootstrap_remote=git://github.com/twitter/bootstrap.git
  8.  
  9. ant_build_script_branch=master
  10. h5bp_branch=master
  11. bootstrap_branch=master
  12.  
  13. # list of bootstrap plugins to be prompted
  14. PLUGINS=$(cat bootstrap-plugins.txt)
  15.  
  16. # the less cmd to run to compiles bootstrap's css files
  17. LESS_CMDS="#!/usr/bin/env bash
  18.  
  19. mkdir css/bs/
  20. ./node_modules/.bin/lessc css/less/bootstrap.less css/bs/bootstrap.css
  21. ./node_modules/.bin/lessc css/less/responsive.less css/bs/bootstrap-responsive.css
  22. ./node_modules/.bin/lessc --compress css/less/bootstrap.less css/bs/bootstrap.min.css
  23. ./node_modules/.bin/lessc --compress css/less/responsive.less css/bs/bootstrap-responsive.min.css
  24.  
  25. # edit the few lines below to not include responsive's css into final bootstrap css
  26.  
  27. cat css/bs/bootstrap.css css/bs/bootstrap-responsive.css >> css/bootstrap.css
  28. cat css/bs/bootstrap.min.css css/bs/bootstrap-responsive.min.css >> css/bootstrap.min.css
  29.  
  30. "
  31.  
  32. # need help ? if no args and help flags
  33. if [ "$1" == '-h' ]
  34. then
  35.   cat <<EOF
  36.  
  37.   Usage:
  38.  
  39.     h5bp-twitter-bootstrap [-h] [dirname]
  40.  
  41. EOF
  42.   exit
  43. fi
  44.  
  45.  
  46. echo "
  47.  
  48.   Cool, let's start.
  49.  
  50. "
  51.  
  52. if [ $# -eq 1 ]
  53. then
  54.   # get a name for new project from command line arguments
  55.   name="$1"
  56. fi
  57.  
  58. # get a name for new project from input
  59. while [ -z $name ]
  60. do
  61.   echo "To create a new project, enter a new directory name"
  62.   read name || exit
  63. done
  64.  
  65. [ -d $name ] && echo "Directory $name already exists" && exit 1
  66.  
  67. echo "
  68.   1a. Get html5boilerplate project (git clone into ./tmp/h5bp)
  69. "
  70.  
  71. if ! [ -d .tmp/h5bp ]
  72. then git clone $h5bp_remote .tmp/h5bp || exit 1
  73. fi
  74.  
  75. cd .tmp/h5bp
  76. [ $(git branch | grep "*" | sed s/*//) != $h5bp_branch ] &&
  77.   # not the current branch, attempt to create new branch
  78.   git checkout -b $h5bp_branch origin/$h5bp_branch ||
  79.   # if already created, then attempt to checkout
  80.   git checkout $h5bp_branch
  81.  
  82. git pull && cd $src
  83.  
  84. echo "
  85.   1b. Get h5bp/ant-build-script project (git clone into ./tmp/ant-build-script)
  86. "
  87.  
  88. if ! [ -d .tmp/ant-build-script ]
  89. then git clone $ant_build_script_remote .tmp/ant-build-script || exit 1
  90. fi
  91.  
  92. cd .tmp/ant-build-script
  93. [ $(git branch | grep "*" | sed s/*//) != $ant_build_script_branch ] &&
  94.   # not the current branch, attempt to create new branch
  95.   git checkout -b $ant_build_script_branch origin/$ant_build_script_branch ||
  96.   # if already created, then attempt to checkout
  97.   git checkout $ant_build_script_branch
  98.  
  99. git pull && cd $src
  100.  
  101. echo "
  102.   2. Get twitter bootstrap project (git clone into ./tmp/bootstrap).
  103. "
  104. if ! [ -d .tmp/bootstrap ]
  105. then git clone $bootstrap_remote .tmp/bootstrap || exit 1
  106. fi
  107.  
  108. cd .tmp/bootstrap
  109. [ $(git branch | grep "*" | sed s/*//) != $bootstrap_branch ] &&
  110.   # not the current branch, attempt to create new branch
  111.   git checkout -b $bootstrap_branch origin/$bootstrap_branch ||
  112.   # if already created, then attempt to checkout
  113.   git checkout $bootstrap_branch
  114.  
  115. git pull && cd $src
  116.  
  117.  
  118. echo "
  119.   3. Create html5boilerplate directory/file structure by running build/createproject.sh
  120. "
  121. cd .tmp/h5bp && ../ant-build-script/createproject.sh project && cd $src
  122. mkdir -p $name
  123. echo "Created directory: $name"
  124. cd .tmp/h5bp && cp -r -- css js img *.html *.xml *.txt *.png *.ico .htaccess "../../$name"
  125. echo "Created h5bp project's structure: $name"
  126. cd $src
  127.  
  128. echo "
  129.   4. Copy bootstrap's 'less' folder to 'css/less/' (or any other path you'd like, following assumes 'css/less/')
  130. "
  131. cp -vr .tmp/bootstrap/less $name/css/less
  132. echo "Create bootstrap's less directory in css/less"
  133.  
  134. # Commenting out the reset bootstrap drop. By default, the whole bootstrap's css files is used and h5bp's one
  135. # is renamed into h5bp.css. The style.css file importing the css assets does not use h5bp.css.
  136.  
  137. # echo "\n5. Go in 'css/less', edit the bootstrap.less file and remove the '@import \"reset.less\";' line."
  138. # cp $name/css/less/bootstrap.less $name/css/less/bootstrap.less.orig
  139. # sed '/reset/d' $name/css/less/bootstrap.less.orig | sed '/Reset/d' > $name/css/less/bootstrap.less
  140.  
  141. echo "
  142.   5. Create the app.css file
  143. "
  144. echo "
  145.  
  146. /* =============================================================================
  147.    App specific CSS file.
  148.  
  149.    This is usually where the site/app's CSS specific rules are setup. Note that you could
  150.    do exactly the same using less by adding a '@import "app.less";' at the end of
  151.    css/less/bootstrap.less file.
  152.  
  153.    ========================================================================== */
  154.  
  155. " > $name/css/app.css
  156.  
  157. echo "
  158.   6. Go in 'css', rename h5bp's 'style.css' to 'h5bp.css'.
  159. "
  160. cd $name/css && mv style.css h5bp.css && cd $src
  161.  
  162. echo "
  163.   7. Create a new 'css/style.css' file:
  164. "
  165. echo "
  166.  
  167. /* =============================================================================
  168.    CSS App imports.
  169.  
  170.    These imports are inlined and minified by the build script. If
  171.    you don't intend to use a build script, do not use @import
  172.    statements. Use a single style.css file with bootstrap's style first,
  173.    then your specific CSS files.
  174.  
  175.    Following assumes an app.css to put specific CSS rules.
  176.  
  177.    Both unminified and minified version of bootstrap's css will be generated by the
  178.    less script command. You may want to switch the bootstrap.css to bootstrap.min.css
  179.  
  180.    ========================================================================== */
  181.  
  182. @import url('bootstrap.css');
  183. @import url('app.css');
  184.  
  185. " > $name/css/style.css
  186.  
  187. echo "
  188.   8. Processing of bootstrap's plugins, you'll be prompted for each files in
  189.   .tmp/bootstrap/js/ directory. Simply put a y/n to tell wheter you want them
  190.   included and concat'd to the js/plugins.js file.
  191.  
  192.   Note that popover plugin requires tooltip to be included fist, so be sure to
  193.   tell this script to include both tooltip / popover. You'll be prompted for
  194.   tooltip plugin at first.
  195. "
  196.  
  197.  
  198. cd .tmp/bootstrap/js/
  199. for f in $PLUGINS; do
  200.  
  201.   while [ "$yepnope" != "y" -a "$yepnope" != "n" -a "$yepnope" != "yep" -a "$yepnope" != "nope"  ]
  202.   do
  203.     read -p "$f >> $name/js/plugins.js: (yep) " yepnope || exit
  204.     [ -z $yepnope ] && yepnope="yep"
  205.  
  206.     [ "$yepnope" == "y" -o "$yepnope" == "n" ] ||
  207.       [ "$yepnope" == "yep" -o "$yepnope" == "nope" ] ||
  208.       echo "Incorrect value"
  209.   done
  210.  
  211.   [ "$yepnope" == "y" -o "$yepnope" == "yep" ] && cat $f >> $src/$name/js/plugins.js
  212.   unset yepnope
  213. done
  214. cd $src
  215.  
  216.  
  217. echo "
  218.   9. Init npm package for the website
  219. "
  220. cd $name && npm init || exit 0
  221.  
  222. echo "You may want to tweak the package.json file, only name/version are mandatory."
  223.  
  224. echo "
  225.   10. Add less as package.json's dependency (npm install less --save)
  226. "
  227. npm install less --save || exit 0
  228.  
  229. echo "
  230.   11. Add an npm script to trigger the less build.
  231. "
  232. mv package.json package.json.orig
  233. cat package.json.orig | sed "$ s/}/  , \"scripts\": { \"less\": \"sh build-bootstrap.sh\" } }/g" > package.json
  234. echo "$LESS_CMDS" > build-bootstrap.sh
  235. cd $src
  236.  
  237. echo "
  238.   12. Leaving out temporary dirs (.tmp/). You may want to remove this dir or let it be so that
  239.   next builds will pull instead of clones (significantly faster).
  240.  
  241.   This is relative to the current working directory though: $src
  242. "
  243.  
  244.  
  245. echo "
  246.   13. Running a first compile step to generate $name/css/bootstrap.css
  247. "
  248. cd $name && npm run-script less || exit 0
  249.  
  250. echo "
  251.  
  252.     All done!
  253.  
  254. Check out the $name directory.
  255.  
  256. Simply run 'npm run-script less' to trigger the less compile step.
  257.  
  258. "