Skip to content
Myr

2 spaces in bin/express

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 88bbef9 · Browse files · 1 file+150 added−150 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+150 added−150 removed

  • other:+150 added−150 removed

1 file+150 added−150 removed

modified:bin/express+150 added-150 removed
2 unmodified lines
3/**4 * Module dependencies.5 */67var sys = require('sys'),8 fs = require('fs'),9 childProcess = require('child_process');7var fs = require('fs')8 , exec = require('child_process').exec;910/**11 * Framework version.12 */
10 unmodified lines
23 * Usage documentation.24 */2526var usage = ''28 + '\x1b[1mUsage\x1b[0m: express [options] [PATH]\n'29 + '\n'30 + '\x1b[1mOptions\x1b[0m:\n'31 + ' -v, --version Output framework version\n'32 + ' -h, --help Output help information\n';27 + '\x1b[1mUsage\x1b[0m: express [options] [PATH]\n'28 + '\n'29 + '\x1b[1mOptions\x1b[0m:\n'30 + ' -v, --version Output framework version\n'31 + ' -h, --help Output help information\n';3233/**34 * Jade layout template.35 */3637var jadeLayout = [39 '!!!',40 'html',41 ' head',42 ' title= title',43 ' link(rel=\'stylesheet\', href=\'/stylesheets/style.css\')',44 ' body!= body'38 '!!!'39 , 'html'40 , ' head'41 , ' title= title'42 , ' link(rel=\'stylesheet\', href=\'/stylesheets/style.css\')'43 , ' body!= body'44].join('\n');4546/**47 * Default less template.48 */4950var less = [52 'body {',53 ' padding: 50px;',54 ' font: 14px "Lucida Grande", "Helvetica Nueue", Arial, sans-serif;',55 '}'51 'body {'52 , ' padding: 50px;'53 , ' font: 14px "Lucida Grande", "Helvetica Nueue", Arial, sans-serif;'54 , '}'55].join('\n');5657/**58 * Jade index template.59 */6061var jadeIndex = [63 'h1= title',64 'p Welcome to #{title}'62 'h1= title'63 , 'p Welcome to #{title}'64].join('\n');6566/**67 * App test template.68 */6970var appTest = [72 "",73 "// Run $ expresso",74 "",75 "/**",76 " * Module dependencies.",77 " */",78 "",79 "var app = require('../app');",80 "",81 "module.exports = {",82 " 'GET /': function(assert){",83 " assert.response(app,",84 " { url: '/' },",85 " { status: 200, headers: { 'Content-Type': 'text/html; charset=utf-8' }},",86 " function(res){",87 " assert.includes(res.body, '<title>Express</title>');",88 " });",89 " }",90 "};",71 ""72 , "// Run $ expresso"73 , ""74 , "/**"75 , " * Module dependencies."76 , " */"77 , ""78 , "var app = require('../app');"79 , "",80 , "module.exports = {"81 , " 'GET /': function(assert){"82 , " assert.response(app,"83 , " { url: '/' },"84 , " { status: 200, headers: { 'Content-Type': 'text/html; charset=utf-8' }},"85 , " function(res){"86 , " assert.includes(res.body, '<title>Express</title>');"87 , " });"88 , " }"89 , "};"90].join('\n');9192/**93 * App template.94 */9596var app = [98 '',99 '/**',100 ' * Module dependencies.',101 ' */',102 '',103 'var express = require(\'express\');',104 '',105 'var app = module.exports = express.createServer();',106 '',107 '// Configuration',108 '',109 'app.configure(function(){',110 ' app.set(\'views\', __dirname + \'/views\');',111 ' app.use(express.bodyDecoder());',112 ' app.use(express.methodOverride());',113 ' app.use(express.compiler({ src: __dirname + \'/public\', enable: [\'less\'] }));',114 ' app.use(app.router);',115 ' app.use(express.staticProvider(__dirname + \'/public\'));',116 '});',117 '',118 'app.configure(\'development\', function(){',119 ' app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); ',120 '});',121 '',122 'app.configure(\'production\', function(){',123 ' app.use(express.errorHandler()); ',124 '});',125 '',126 '// Routes',127 '',128 'app.get(\'/\', function(req, res){',129 ' res.render(\'index.jade\', {',130 ' locals: {',131 ' title: \'Express\'',132 ' }',133 ' });',134 '});',135 '',136 '// Only listen on $ node app.js',137 '',138 'if (!module.parent) {',139 ' app.listen(3000);',140 ' console.log("Express server listening on port %d", app.address().port)',141 '}',97 ''98 , '/**'99 , ' * Module dependencies.'100 , ' */'101 , ''102 , 'var express = require(\'express\');'103 , ''104 , 'var app = module.exports = express.createServer();'105 , ''106 , '// Configuration'107 , ''108 , 'app.configure(function(){'109 , ' app.set(\'views\', __dirname + \'/views\');'110 , ' app.use(express.bodyDecoder());'111 , ' app.use(express.methodOverride());'112 , ' app.use(express.compiler({ src: __dirname + \'/public\', enable: [\'less\'] }));'113 , ' app.use(app.router);'114 , ' app.use(express.staticProvider(__dirname + \'/public\'));'115 , '});'116 , ''117 , 'app.configure(\'development\', function(){'118 , ' app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); '119 , '});'120 , ''121 , 'app.configure(\'production\', function(){'122 , ' app.use(express.errorHandler()); '123 , '});'124 , ''125 , '// Routes'126 , ''127 , 'app.get(\'/\', function(req, res){'128 , ' res.render(\'index.jade\', {'129 , ' locals: {'130 , ' title: \'Express\''131 , ' }'132 , ' });'133 , '});'134 , ''135 , '// Only listen on $ node app.js'136 , ''137 , 'if (!module.parent) {'138 , ' app.listen(3000);'139 , ' console.log("Express server listening on port %d", app.address().port)'140 , '}'141 , ''142].join('\n');143144// Parse arguments145147var args = process.argv.slice(2),148 path = '.';146var args = process.argv.slice(2)147 , path = '.';148149while (args.length) {150 var arg = args.shift();151 switch (arg) {152 case '-h':153 case '--help':154 abort(usage);155 break;156 case '-v':157 case '--version':158 abort(version);159 break;160 default:161 path = arg;162 }150 var arg = args.shift();151 switch (arg) {152 case '-h':153 case '--help':154 abort(usage);155 break;156 case '-v':157 case '--version':158 abort(version);159 break;160 default:161 path = arg;162 }163}164165// Generate application166167(function createApplication(path) {168 emptyDirectory(path, function(empty){169 if (empty) {170 createApplicationAt(path);168 emptyDirectory(path, function(empty){169 if (empty) {170 createApplicationAt(path);171 } else {172 confirm('destination is not empty, continue? ', function(ok){173 if (ok) {174 stdin.destroy();175 createApplicationAt(path);176 } else {172 confirm('destination is not empty, continue? ', function(ok){173 if (ok) {174 stdin.destroy();175 createApplicationAt(path);176 } else {177 abort('aborting');177 abort('aborting');178 }179 });178 }181 });179 });180 }181 });182})(path);183184/**185 * Create application at the given directory `path`.
1 unmodified line
187 * @param {String} path188 */189190function createApplicationAt(path) {191 mkdir(path, function(){192 mkdir(path + '/pids');193 mkdir(path + '/logs');194 mkdir(path + '/public/javascripts');195 mkdir(path + '/public/images');196 mkdir(path + '/public/stylesheets', function(){197 write(path + '/public/stylesheets/style.less', less);198 });199 mkdir(path + '/views/partials', function(){200 write(path + '/views/layout.jade', jadeLayout);201 write(path + '/views/index.jade', jadeIndex);202 });203 mkdir(path + '/test', function(){204 write(path + '/test/app.test.js', appTest);205 });206 write(path + '/app.js', app);191 mkdir(path, function(){192 mkdir(path + '/pids');193 mkdir(path + '/logs');194 mkdir(path + '/public/javascripts');195 mkdir(path + '/public/images');196 mkdir(path + '/public/stylesheets', function(){197 write(path + '/public/stylesheets/style.less', less);198 });199 mkdir(path + '/views/partials', function(){200 write(path + '/views/layout.jade', jadeLayout);201 write(path + '/views/index.jade', jadeIndex);202 });203 mkdir(path + '/test', function(){204 write(path + '/test/app.test.js', appTest);205 });206 write(path + '/app.js', app);207 });208}209210/**211 * Check if the given directory `path` is empty.
2 unmodified lines
214 * @param {Function} fn215 */216217function emptyDirectory(path, fn) {218 fs.readdir(path, function(err, files){219 if (err && err.errno !== process.ENOENT) throw err;220 fn(!files || !files.length);221 });218 fs.readdir(path, function(err, files){219 if (err && err.errno !== process.ENOENT) throw err;220 fn(!files || !files.length);221 });222}223224/**225 * echo str > path.
2 unmodified lines
228 * @param {String} str229 */230231function write(path, str) {232 fs.writeFile(path, str);233 sys.puts(' create : ' + path);232 fs.writeFile(path, str);233 sys.puts(' create : ' + path);234}235236/**237 * Prompt confirmation with the given `msg`.
2 unmodified lines
240 * @param {Function} fn241 */242243function confirm(msg, fn) {244 prompt(msg, function(val){245 fn(/^ *y(es)?/i.test(val));246 });244 prompt(msg, function(val){245 fn(/^ *y(es)?/i.test(val));246 });247}248249/**250 * Prompt input with the given `msg` and callback `fn`.
2 unmodified lines
253 * @param {Function} fn254 */255256function prompt(msg, fn) {257 stdin = stdin || process.openStdin();258 sys[msg[msg.length - 1] == ' ' ? 'print' : 'puts'](msg);259 stdin.setEncoding('ascii');260 stdin.addListener('data', function(data){261 fn(data);262 stdin.removeListener('data', arguments.callee);263 });257 stdin = stdin || process.openStdin();258 sys[msg[msg.length - 1] == ' ' ? 'print' : 'puts'](msg);259 stdin.setEncoding('ascii');260 stdin.addListener('data', function(data){261 fn(data);262 stdin.removeListener('data', arguments.callee);263 });264}265266/**267 * Mkdir -p.
2 unmodified lines
270 * @param {Function} fn271 */272273function mkdir(path, fn) {274 childProcess.exec('mkdir -p ' + path, function(err){275 if (err) throw err;276 sys.puts(' create : ' + path);277 fn && fn();278 });274 exec('mkdir -p ' + path, function(err){275 if (err) throw err;276 sys.puts(' create : ' + path);277 fn && fn();278 });279}280281/**282 * Exit with the given `str`.
1 unmodified line
284 * @param {String} str285 */286287function abort(str) {288 sys.error(str);289 process.exit(1);290}288 sys.error(str);289 process.exit(1);290}