Bash template generator with dummy app
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent fbbe136 · Browse files · 3 files·+137 added−54 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+137 added−54 removed
- other:+137 added−54 removed
Provenance
- Commit
2caf67b- Tree
009c695- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
fbbe136
3 files changed+137 added−54 removed
modified:bin/express+132 added-53 removed
1-#!/usr/bin/env node1+#!/usr/bin/env bash2 3-var arg,4- dir = '.',5- fs = require('fs'),6- sys = require('sys'),7- args = process.argv.slice(2)3+#4+# Output usage information and exit.5+# 6 9-// Parse arguments7+function usage() {8+ echo 'usage: express [options] [dir]'9+ exit 110+}11 11-while (arg = args.shift())12- switch (arg) {13- case '-h':14- case '--help':15- sys.print('Usage: express [options] [dir]\n')16- break17- default:18- dir = arg19- }20- 21-// Helpers12+#13+# Create template in the givin [dir] or cwd.14+# 15+# [dir]16+#17 23-function confirm(msg, fn) {24- sys.print(msg)25- var stdin = process.openStdin()26- stdin.setEncoding('utf8')27- stdin.addListener('data', function(chunk){28- switch (chunk.trim().toLowerCase()) {29- case 'yes':30- case 'y':31- return stdin.destroy(), fn(true)32- case 'no':33- case 'n':34- return stdin.destroy(), fn(false)35- default:36- sys.print(msg)37- }38- })18+function 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 }29 41-function createTemplateIn(dir, mode) {42- fs.writeFile(dir + '/app.js', '// your app here')43- fs.mkdir(dir + '/views', mode)44- fs.mkdir(dir + '/public', mode, function(err){45- if (err) throw err46- fs.mkdir(dir + '/public/javascripts', mode)47- fs.mkdir(dir + '/public/stylesheets', mode)48- fs.mkdir(dir + '/public/images', mode)49- })30+#31+# views/style.css.sass32+# 33+34+function sass_template() {35+ cat <<-EOF36+blue: #03ADF037+light: #4d4d4d38+lighter: #eee39+40+body41+ :margin 80px42+ :font 14px/1.5 "Helvetica Nueue", "Lucida Grande", "Arial", sans-serif43+44+code45+ :padding 3px 10px46+ :border 1px solid !lighter47+ :color !light48+49+a50+ :color !blue51+ :text-decoration none52+ &:hover53+ :text-decoration underline54+EOF55 }56 52-// Setup template57+#58+# views/front.html.haml59+#60 54-fs.readdir(dir, function(err, files){55- if (err) throw err56- if (files.length)57- confirm(dir + ' is not empty, continue? ', function(ok){58- if (ok) createTemplateIn(dir, 0666)59- })60- else61- createTemplateIn(dir, 0666)62-})61+function 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. 72+EOF73+}74+75+#76+# views/layout.html.haml77+# 78+79+function layout_template() {80+ cat <<-EOF81+!!! strict82+%html83+ %head84+ %title Express85+ %link{ rel: 'stylesheet', href: 'style.css' }86+ %body!= body87+EOF88+}89+90+#91+# app.js92+# 93+94+function app_template() {95+ cat <<-EOF96+// If you are using the kiwi package manager97+var kiwi = require('kiwi'),98+ express = kiwi.require('express')99+100+// Otherwise you will need to expose the path to express101+// require.paths.unshift('path/to/express/lib')102+// require('express')103+104+configure(function(){105+ set('root', __dirname)106+})107+108+get('/', function(){109+ this.render('front.html.haml')110+})111+112+get('/*.css', function(path){113+ this.render(path + '.css.sass', { layout: false })114+})115+116+run()117+EOF118+}119+120+#121+# Confirm <msg> or exit.122+# 123+# <msg>124+#125+126+function 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+}135+136+# Process arguments137+138+case $1 in139+ -h|--help|help) usage ;;140+ *) create_template $1 ;;141+esacmodified:Makefile+1 added-1 removed
3 unmodified lines4 5 all: test6 7 install: bin/express8- install bin/express /usr/local/bin/express8+ ln -s bin/express /usr/local/bin/express9 10 test:11 @$(NODE) spec/node.js all12 15 unmodified linesmodified:Readme.md+4 added
55 unmodified lines56575859606162636465666769 unmodified lines55 unmodified lines
require.paths.unshift('express/lib') require('express') configure(function(){ set('root', __dirname) }) get('/user', function(){ this.redirect('/user/' + this.currentUser.id) }) 69 unmodified lines