Skip to content
Myr

remove binary

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

authored by Jonathan Ong · committed by Jonathan Ong · parent dc5932d · Browse files · 3 files+5 added−429 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+5 added−429 removed

  • other:+5 added−429 removed

3 files+5 added−429 removed

deleted:bin/express-423 removed
1#!/usr/bin/env node23/**4 * Module dependencies.5 */67var program = require('commander')8 , mkdirp = require('mkdirp')9 , pkg = require('../package.json')10 , version = pkg.version11 , os = require('os')12 , fs = require('fs');1314// CLI1516program17 .version(version)18 .usage('[options] [dir]')19 .option('-s, --sessions', 'add session support')20 .option('-e, --ejs', 'add ejs engine support (defaults to jade)')21 .option('-J, --jshtml', 'add jshtml engine support (defaults to jade)')22 .option('-H, --hogan', 'add hogan.js engine support')23 .option('-c, --css <engine>', 'add stylesheet <engine> support (less|stylus) (defaults to plain css)')24 .option('-f, --force', 'force on non-empty directory')25 .parse(process.argv);2627// Path2829var path = program.args.shift() || '.';3031// end-of-line code3233var eol = os.EOL3435// Template engine3637program.template = 'jade';38if (program.ejs) program.template = 'ejs';39if (program.jshtml) program.template = 'jshtml';40if (program.hogan) program.template = 'hjs';4142/**43 * Routes index template.44 */4546var index = [47 ''48 , '/*'49 , ' * GET home page.'50 , ' */'51 , ''52 , 'exports.index = function(req, res){'53 , ' res.render(\'index\', { title: \'Express\' });'54 , '};'55].join(eol);5657/**58 * Routes users template.59 */6061var users = [62 ''63 , '/*'64 , ' * GET users listing.'65 , ' */'66 , ''67 , 'exports.list = function(req, res){'68 , ' res.send("respond with a resource");'69 , '};'70].join(eol);7172/**73 * Jade layout template.74 */7576var jadeLayout = [77 'doctype html'78 , 'html'79 , ' head'80 , ' title= title'81 , ' link(rel=\'stylesheet\', href=\'/stylesheets/style.css\')'82 , ' body'83 , ' block content'84].join(eol);8586/**87 * Jade index template.88 */8990var jadeIndex = [91 'extends layout'92 , ''93 , 'block content'94 , ' h1= title'95 , ' p Welcome to #{title}'96].join(eol);9798/**99 * EJS index template.100 */101102var ejsIndex = [103 '<!DOCTYPE html>'104 , '<html>'105 , ' <head>'106 , ' <title><%= title %></title>'107 , ' <link rel=\'stylesheet\' href=\'/stylesheets/style.css\' />'108 , ' </head>'109 , ' <body>'110 , ' <h1><%= title %></h1>'111 , ' <p>Welcome to <%= title %></p>'112 , ' </body>'113 , '</html>'114].join(eol);115116/**117 * JSHTML layout template.118 */119120var jshtmlLayout = [121 '<!DOCTYPE html>'122 , '<html>'123 , ' <head>'124 , ' <title> @write(title) </title>'125 , ' <link rel=\'stylesheet\' href=\'/stylesheets/style.css\' />'126 , ' </head>'127 , ' <body>'128 , ' @write(body)'129 , ' </body>'130 , '</html>'131].join(eol);132133/**134 * JSHTML index template.135 */136137var jshtmlIndex = [138 '<h1>@write(title)</h1>'139 , '<p>Welcome to @write(title)</p>'140].join(eol);141142/**143 * Hogan.js index template.144 */145var hoganIndex = [146 '<!DOCTYPE html>'147 , '<html>'148 , ' <head>'149 , ' <title>{{ title }}</title>'150 , ' <link rel=\'stylesheet\' href=\'/stylesheets/style.css\' />'151 , ' </head>'152 , ' <body>'153 , ' <h1>{{ title }}</h1>'154 , ' <p>Welcome to {{ title }}</p>'155 , ' </body>'156 , '</html>'157].join(eol);158159/**160 * Default css template.161 */162163var css = [164 'body {'165 , ' padding: 50px;'166 , ' font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;'167 , '}'168 , ''169 , 'a {'170 , ' color: #00B7FF;'171 , '}'172].join(eol);173174/**175 * Default less template.176 */177178var less = [179 'body {'180 , ' padding: 50px;'181 , ' font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;'182 , '}'183 , ''184 , 'a {'185 , ' color: #00B7FF;'186 , '}'187].join(eol);188189/**190 * Default stylus template.191 */192193var stylus = [194 'body'195 , ' padding: 50px'196 , ' font: 14px "Lucida Grande", Helvetica, Arial, sans-serif'197 , 'a'198 , ' color: #00B7FF'199].join(eol);200201/**202 * App template.203 */204205var app = [206 ''207 , '/**'208 , ' * Module dependencies.'209 , ' */'210 , ''211 , 'var express = require(\'express\');'212 , 'var routes = require(\'./routes\');'213 , 'var user = require(\'./routes/user\');'214 , 'var http = require(\'http\');'215 , 'var path = require(\'path\');'216 , ''217 , 'var app = express();'218 , ''219 , '// all environments'220 , 'app.set(\'port\', process.env.PORT || 3000);'221 , 'app.set(\'views\', path.join(__dirname, \'views\'));'222 , 'app.set(\'view engine\', \':TEMPLATE\');'223 , 'app.use(express.favicon());'224 , 'app.use(express.logger(\'dev\'));'225 , 'app.use(express.json());'226 , 'app.use(express.urlencoded());'227 , 'app.use(express.methodOverride());{sess}'228 , 'app.use(app.router);{css}'229 , 'app.use(express.static(path.join(__dirname, \'public\')));'230 , ''231 , '// development only'232 , 'if (\'development\' == app.get(\'env\')) {'233 , ' app.use(express.errorHandler());'234 , '}'235 , ''236 , 'app.get(\'/\', routes.index);'237 , 'app.get(\'/users\', user.list);'238 , ''239 , 'http.createServer(app).listen(app.get(\'port\'), function(){'240 , ' console.log(\'Express server listening on port \' + app.get(\'port\'));'241 , '});'242 , ''243].join(eol);244245// Generate application246247(function createApplication(path) {248 emptyDirectory(path, function(empty){249 if (empty || program.force) {250 createApplicationAt(path);251 } else {252 program.confirm('destination is not empty, continue? ', function(ok){253 if (ok) {254 process.stdin.destroy();255 createApplicationAt(path);256 } else {257 abort('aborting');258 }259 });260 }261 });262})(path);263264/**265 * Create application at the given directory `path`.266 *267 * @param {String} path268 */269270function createApplicationAt(path) {271 console.log();272 process.on('exit', function(){273 console.log();274 console.log(' install dependencies:');275 console.log(' $ cd %s && npm install', path);276 console.log();277 console.log(' run the app:');278 console.log(' $ node app');279 console.log();280 });281282 mkdir(path, function(){283 mkdir(path + '/public');284 mkdir(path + '/public/javascripts');285 mkdir(path + '/public/images');286 mkdir(path + '/public/stylesheets', function(){287 switch (program.css) {288 case 'less':289 write(path + '/public/stylesheets/style.less', less);290 break;291 case 'stylus':292 write(path + '/public/stylesheets/style.styl', stylus);293 break;294 default:295 write(path + '/public/stylesheets/style.css', css);296 }297 });298299 mkdir(path + '/routes', function(){300 write(path + '/routes/index.js', index);301 write(path + '/routes/user.js', users);302 });303304 mkdir(path + '/views', function(){305 switch (program.template) {306 case 'ejs':307 write(path + '/views/index.ejs', ejsIndex);308 break;309 case 'jade':310 write(path + '/views/layout.jade', jadeLayout);311 write(path + '/views/index.jade', jadeIndex);312 break;313 case 'jshtml':314 write(path + '/views/layout.jshtml', jshtmlLayout);315 write(path + '/views/index.jshtml', jshtmlIndex);316 break;317 case 'hjs':318 write(path + '/views/index.hjs', hoganIndex);319 break;320321 }322 });323324 // CSS Engine support325 switch (program.css) {326 case 'less':327 app = app.replace('{css}', eol + 'app.use(require(\'less-middleware\')({ src: path.join(__dirname, \'public\') }));');328 break;329 case 'stylus':330 app = app.replace('{css}', eol + 'app.use(require(\'stylus\').middleware(path.join(__dirname, \'public\')));');331 break;332 default:333 app = app.replace('{css}', '');334 }335336 // Session support337 app = app.replace('{sess}', program.sessions338 ? eol + 'app.use(express.cookieParser(\'your secret here\'));' + eol + 'app.use(express.session());'339 : '');340341 // Template support342 app = app.replace(':TEMPLATE', program.template);343344 // package.json345 var pkg = {346 name: 'application-name'347 , version: '0.0.1'348 , private: true349 , scripts: { start: 'node app.js' }350 , dependencies: {351 express: version352 }353 }354355 if (program.template) pkg.dependencies[program.template] = '*';356357 // CSS Engine support358 switch (program.css) {359 case 'less':360 pkg.dependencies['less-middleware'] = '*';361 break;362 default:363 if (program.css) {364 pkg.dependencies[program.css] = '*';365 }366 }367368 write(path + '/package.json', JSON.stringify(pkg, null, 2));369 write(path + '/app.js', app);370 });371}372373/**374 * Check if the given directory `path` is empty.375 *376 * @param {String} path377 * @param {Function} fn378 */379380function emptyDirectory(path, fn) {381 fs.readdir(path, function(err, files){382 if (err && 'ENOENT' != err.code) throw err;383 fn(!files || !files.length);384 });385}386387/**388 * echo str > path.389 *390 * @param {String} path391 * @param {String} str392 */393394function write(path, str) {395 fs.writeFile(path, str);396 console.log(' \x1b[36mcreate\x1b[0m : ' + path);397}398399/**400 * Mkdir -p.401 *402 * @param {String} path403 * @param {Function} fn404 */405406function mkdir(path, fn) {407 mkdirp(path, 0755, function(err){408 if (err) throw err;409 console.log(' \033[36mcreate\033[0m : ' + path);410 fn && fn();411 });412}413414/**415 * Exit with the given `str`.416 *417 * @param {String} str418 */419420function abort(str) {421 console.error(str);422 process.exit(1);423}
modified:History.md+5 added
14.0.0 /2==================34 * remove binary (moved to [express-generator](https://github.com/expressjs/generator))563.4.7 / 2013-12-107==================89 * update connect
1248 unmodified lines
modified:package.json-6 removed