express
This file
Path
bin/express
141 lines · 2.1 KiB
Last changed by
Merge branch 'bin'visionmediabefore adoption12c2682
History of this fileTake it
1#!/usr/bin/env bash23#4# Output usage information and exit.5# 67function usage() {8 echo 'usage: express [options] [dir]'9 exit 110}1112#13# Create template in the givin [dir] or cwd.14# 15# [dir]16#1718function create_template() {19 local dir=${1-.}20 mkdir -p $dir21 [[ $(ls $dir) ]] && confirm "$dir is not empty, continue?"22 mkdir -p $dir/public/{javascripts,stylesheets,images}23 mkdir -p $dir/views/partials24 app_template > $dir/app.js25 layout_template > $dir/views/layout.html.haml26 front_template > $dir/views/front.html.haml27 sass_template > $dir/views/style.css.sass28}2930#31# views/style.css.sass32# 3334function sass_template() {35 cat <<-EOF36blue: #03ADF037light: #4d4d4d38lighter: #eee3940body41 :margin 80px42 :font 14px/1.5 "Helvetica Nueue", "Lucida Grande", "Arial", sans-serif4344code45 :padding 3px 10px46 :border 1px solid !lighter47 :color !light4849a50 :color !blue51 :text-decoration none52 &:hover53 :text-decoration underline54EOF55}5657#58# views/front.html.haml59#6061function front_template() {62 cat <<-EOF63%h1 Express64%p65 Generated by the66 <code>express</code>67 executable.68%p69 Visit70 %a{ href: 'http://expressjs.com' } ExpressJS.com71 for more information. 72EOF73}7475#76# views/layout.html.haml77# 7879function layout_template() {80 cat <<-EOF81!!! strict82%html83 %head84 %title Express85 %link{ rel: 'stylesheet', href: 'style.css' }86 %body!= body87EOF88}8990#91# app.js92# 9394function app_template() {95 cat <<-EOF96// If you are using the kiwi package manager97var kiwi = require('kiwi'),98 express = kiwi.require('express')99100// Otherwise you will need to expose the path to express101// require.paths.unshift('path/to/express/lib')102// require('express')103104configure(function(){105 set('root', __dirname)106})107108get('/', function(){109 this.render('front.html.haml')110})111112get('/*.css', function(path){113 this.render(path + '.css.sass', { layout: false })114})115116run()117EOF118}119120#121# Confirm <msg> or exit.122# 123# <msg>124#125126function confirm() {127 echo -n "$1 "128 read answer129 case $answer in130 n|N|no) exit 1 ;;131 y|Y|yes) ;;132 *) confirm "yes or no?" ;;133 esac134}135136# Process arguments137138case $1 in139 -h|--help|help) usage ;;140 *) create_template $1 ;;141esac