[Pkg-javascript-commits] [node-express-generator] 01/02: Imported Upstream version 4.0.0

Leo Iannacone l3on-guest at moszumanska.debian.org
Tue Apr 29 08:50:05 UTC 2014


This is an automated email from the git hooks/post-receive script.

l3on-guest pushed a commit to branch master
in repository node-express-generator.

commit 7095c875f336341d6d29b187af3cee1b30a67ff2
Author: Leo Iannacone <l3on at ubuntu.com>
Date:   Mon Apr 28 18:51:34 2014 +0200

    Imported Upstream version 4.0.0
---
 LICENSE                      |  22 ++++
 README.md                    |  47 ++++++++
 bin/express                  | 260 +++++++++++++++++++++++++++++++++++++++++++
 package.json                 |  47 ++++++++
 templates/css/style.css      |   8 ++
 templates/css/style.less     |   8 ++
 templates/css/style.scss     |  10 ++
 templates/css/style.styl     |   5 +
 templates/ejs/error.ejs      |   3 +
 templates/ejs/index.ejs      |  11 ++
 templates/hogan/error.hjs    |   3 +
 templates/hogan/index.hjs    |  11 ++
 templates/jade/error.jade    |   6 +
 templates/jade/index.jade    |   5 +
 templates/jade/layout.jade   |   7 ++
 templates/js/app.js          |  59 ++++++++++
 templates/js/routes/index.js |   9 ++
 templates/js/routes/users.js |   9 ++
 templates/js/www             |   9 ++
 19 files changed, 539 insertions(+)

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d23e93c
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2009-2013 TJ Holowaychuk <tj at vision-media.ca>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..c139f8d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,47 @@
+[![express logo](http://f.cl.ly/items/0V2S1n0K1i3y1c122g04/Screen%20Shot%202012-04-11%20at%209.59.42%20AM.png)](http://expressjs.com/)
+
+  Fast, unopinionated, minimalist web framework for [node](http://nodejs.org).
+
+  [![Gittip](http://img.shields.io/gittip/visionmedia.png)](https://www.gittip.com/visionmedia/)
+
+## Quick Start
+
+ The quickest way to get started with express is to utilize the executable `express(1)` to generate an application as shown below:
+
+ Create the app:
+
+    $ npm install -g express-generator
+    $ express /tmp/foo && cd /tmp/foo
+
+ Install dependencies:
+
+    $ npm install
+
+ Rock and Roll
+
+    $ npm start
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2009-2012 TJ Holowaychuk <tj at vision-media.ca>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/bin/express b/bin/express
new file mode 100755
index 0000000..5537200
--- /dev/null
+++ b/bin/express
@@ -0,0 +1,260 @@
+#!/usr/bin/env node
+
+var program = require('commander');
+var mkdirp = require('mkdirp');
+var os = require('os');
+var fs = require('fs');
+var path = require('path');
+
+var pkg = require('../package.json');
+
+var version = pkg.version;
+
+// CLI
+
+program
+  .version(version)
+  .usage('[options] [dir]')
+  .option('-e, --ejs', 'add ejs engine support (defaults to jade)')
+  .option('-H, --hogan', 'add hogan.js engine support')
+  .option('-c, --css <engine>', 'add stylesheet <engine> support (less|stylus|compass) (defaults to plain css)')
+  .option('-f, --force', 'force on non-empty directory')
+  .parse(process.argv);
+
+// Path
+
+var destination_path = program.args.shift() || '.';
+
+// end-of-line code
+
+var eol = os.EOL
+
+// Template engine
+
+program.template = 'jade';
+if (program.ejs) program.template = 'ejs';
+if (program.hogan) program.template = 'hjs';
+
+function load_template(name) {
+  return fs.readFileSync(path.join(__dirname, '..', 'templates', name), 'utf-8');
+}
+
+var index = load_template('js/routes/index.js');
+var users = load_template('js/routes/users.js');
+
+/// css
+
+var css = fs.readFileSync(__dirname + '/../templates/css/style.css', 'utf-8');
+var less = fs.readFileSync(__dirname + '/../templates/css/style.less', 'utf-8');
+var stylus = fs.readFileSync(__dirname + '/../templates/css/style.styl', 'utf-8');
+var compass = fs.readFileSync(__dirname + '/../templates/css/style.scss', 'utf-8');
+
+var app = fs.readFileSync(__dirname + '/../templates/js/app.js', 'utf-8');
+var www = fs.readFileSync(__dirname + '/../templates/js/www', 'utf-8');
+
+// Generate application
+
+(function createApplication(path) {
+  emptyDirectory(path, function(empty){
+    if (empty || program.force) {
+      createApplicationAt(path);
+    } else {
+      program.confirm('destination is not empty, continue? ', function(ok){
+        if (ok) {
+          process.stdin.destroy();
+          createApplicationAt(path);
+        } else {
+          abort('aborting');
+        }
+      });
+    }
+  });
+})(destination_path);
+
+/**
+ * Create application at the given directory `path`.
+ *
+ * @param {String} path
+ */
+
+function createApplicationAt(path) {
+  console.log();
+  process.on('exit', function(){
+    console.log();
+    console.log('   install dependencies:');
+    console.log('     $ cd %s && npm install', path);
+    console.log();
+    console.log('   run the app:');
+    console.log('     $ DEBUG=my-application ./bin/www');
+    console.log();
+  });
+
+  mkdir(path, function(){
+    mkdir(path + '/public');
+    mkdir(path + '/public/javascripts');
+    mkdir(path + '/public/images');
+    mkdir(path + '/public/stylesheets', function(){
+      switch (program.css) {
+        case 'less':
+          write(path + '/public/stylesheets/style.less', less);
+          break;
+        case 'stylus':
+          write(path + '/public/stylesheets/style.styl', stylus);
+          break;
+        case 'compass':
+          write(path + '/public/stylesheets/style.scss', compass);
+          break;
+        default:
+          write(path + '/public/stylesheets/style.css', css);
+      }
+    });
+
+    mkdir(path + '/routes', function(){
+      write(path + '/routes/index.js', index);
+      write(path + '/routes/users.js', users);
+    });
+
+    mkdir(path + '/views', function(){
+      switch (program.template) {
+        case 'ejs':
+          copy_template('ejs/index.ejs', path + '/views/index.ejs');
+          copy_template('ejs/error.ejs', path + '/views/error.ejs');
+          break;
+        case 'jade':
+          copy_template('jade/index.jade', path + '/views/index.jade');
+          copy_template('jade/layout.jade', path + '/views/layout.jade');
+          copy_template('jade/error.jade', path + '/views/error.jade');
+          break;
+        case 'hjs':
+          copy_template('hogan/index.hjs', path + '/views/index.hjs');
+          copy_template('hogan/error.hjs', path + '/views/error.hjs');
+          break;
+
+      }
+    });
+
+    // CSS Engine support
+    switch (program.css) {
+      case 'less':
+        app = app.replace('{css}', eol + 'app.use(require(\'less-middleware\')({ src: path.join(__dirname, \'public\') }));');
+        break;
+      case 'stylus':
+        app = app.replace('{css}', eol + 'app.use(require(\'stylus\').middleware(path.join(__dirname, \'public\')));');
+        break;
+      case 'compass':
+        app = app.replace('{css}', eol + 'app.use(require(\'node-compass\')({mode: \'expanded\'}));');
+        break;
+      default:
+        app = app.replace('{css}', '');
+    }
+
+    // Template support
+    app = app.replace('{views}', program.template);
+
+    // package.json
+    var pkg = {
+        name: 'application-name'
+      , version: '0.0.1'
+      , private: true
+      , scripts: { start: 'node ./bin/www' }
+      , dependencies: {
+          'express': '~4.0.0',
+          'static-favicon': '~1.0.0',
+          'morgan': '~1.0.0',
+          'cookie-parser': '~1.0.1',
+          'body-parser': '~1.0.0',
+          'debug': '~0.7.4'
+      }
+    }
+
+    switch (program.template) {
+      case 'jade':
+        pkg.dependencies['jade'] = '~1.3.0';
+        break;
+      case 'ejs':
+        pkg.dependencies['ejs'] = '~0.8.5';
+        break;
+      case 'hjs':
+        pkg.dependencies['hjs'] = '~0.0.6';
+        break;
+      default:
+    }
+
+    // CSS Engine support
+    switch (program.css) {
+      case 'less':
+        pkg.dependencies['less-middleware'] = '0.1.15';
+        break;
+      case 'compass':
+        pkg.dependencies['node-compass'] = '0.2.3';
+        break;
+      case 'stylus':
+        pkg.dependencies['stylus'] = '0.42.3';
+        break;
+      default:
+    }
+
+    write(path + '/package.json', JSON.stringify(pkg, null, 2));
+    write(path + '/app.js', app);
+    mkdir(path + '/bin', function(){
+      write(path + '/bin/www', www, 0755);
+    });
+  });
+}
+
+function copy_template(from, to) {
+  from = path.join(__dirname, '..', 'templates', from);
+  write(to, fs.readFileSync(from, 'utf-8'));
+}
+
+/**
+ * Check if the given directory `path` is empty.
+ *
+ * @param {String} path
+ * @param {Function} fn
+ */
+
+function emptyDirectory(path, fn) {
+  fs.readdir(path, function(err, files){
+    if (err && 'ENOENT' != err.code) throw err;
+    fn(!files || !files.length);
+  });
+}
+
+/**
+ * echo str > path.
+ *
+ * @param {String} path
+ * @param {String} str
+ */
+
+function write(path, str, mode) {
+  fs.writeFile(path, str, { mode: mode || 0666 });
+  console.log('   \x1b[36mcreate\x1b[0m : ' + path);
+}
+
+/**
+ * Mkdir -p.
+ *
+ * @param {String} path
+ * @param {Function} fn
+ */
+
+function mkdir(path, fn) {
+  mkdirp(path, 0755, function(err){
+    if (err) throw err;
+    console.log('   \033[36mcreate\033[0m : ' + path);
+    fn && fn();
+  });
+}
+
+/**
+ * Exit with the given `str`.
+ *
+ * @param {String} str
+ */
+
+function abort(str) {
+  console.error(str);
+  process.exit(1);
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..60353d6
--- /dev/null
+++ b/package.json
@@ -0,0 +1,47 @@
+{
+  "name": "express-generator",
+  "description": "Express' application generator",
+  "version": "4.0.0",
+  "author": "TJ Holowaychuk <tj at vision-media.ca>",
+  "contributors": [
+    {
+      "name": "TJ Holowaychuk",
+      "email": "tj at vision-media.ca"
+    },
+    {
+      "name": "Aaron Heckmann",
+      "email": "aaron.heckmann+github at gmail.com"
+    },
+    {
+      "name": "Ciaran Jessup",
+      "email": "ciaranj at gmail.com"
+    },
+    {
+      "name": "Guillermo Rauch",
+      "email": "rauchg at gmail.com"
+    }
+  ],
+  "dependencies": {
+    "commander": "1.3.2",
+    "mkdirp": "0.3.5"
+  },
+  "keywords": [
+    "express",
+    "framework",
+    "sinatra",
+    "web",
+    "rest",
+    "restful",
+    "router",
+    "app",
+    "api"
+  ],
+  "repository": "git://github.com/expressjs/generator",
+  "main": "bin/express",
+  "bin": {
+    "express": "./bin/express"
+  },
+  "engines": {
+    "node": ">= 0.8.0"
+  }
+}
diff --git a/templates/css/style.css b/templates/css/style.css
new file mode 100644
index 0000000..30e047d
--- /dev/null
+++ b/templates/css/style.css
@@ -0,0 +1,8 @@
+body {
+  padding: 50px;
+  font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
+}
+
+a {
+  color: #00B7FF;
+}
\ No newline at end of file
diff --git a/templates/css/style.less b/templates/css/style.less
new file mode 100644
index 0000000..30e047d
--- /dev/null
+++ b/templates/css/style.less
@@ -0,0 +1,8 @@
+body {
+  padding: 50px;
+  font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
+}
+
+a {
+  color: #00B7FF;
+}
\ No newline at end of file
diff --git a/templates/css/style.scss b/templates/css/style.scss
new file mode 100644
index 0000000..d24112c
--- /dev/null
+++ b/templates/css/style.scss
@@ -0,0 +1,10 @@
+ at import "compass/css3";
+
+body {
+  padding: 50px;
+  font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
+}
+
+a {
+  color: #00B7FF;
+}
\ No newline at end of file
diff --git a/templates/css/style.styl b/templates/css/style.styl
new file mode 100644
index 0000000..1377e2f
--- /dev/null
+++ b/templates/css/style.styl
@@ -0,0 +1,5 @@
+body
+  padding: 50px
+  font: 14px "Lucida Grande", Helvetica, Arial, sans-serif
+a
+  color: #00B7FF
\ No newline at end of file
diff --git a/templates/ejs/error.ejs b/templates/ejs/error.ejs
new file mode 100644
index 0000000..7cf94ed
--- /dev/null
+++ b/templates/ejs/error.ejs
@@ -0,0 +1,3 @@
+<h1><%= message %></h1>
+<h2><%= error.status %></h2>
+<pre><%= error.stack %></pre>
diff --git a/templates/ejs/index.ejs b/templates/ejs/index.ejs
new file mode 100644
index 0000000..7b7a1d6
--- /dev/null
+++ b/templates/ejs/index.ejs
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title><%= title %></title>
+    <link rel='stylesheet' href='/stylesheets/style.css' />
+  </head>
+  <body>
+    <h1><%= title %></h1>
+    <p>Welcome to <%= title %></p>
+  </body>
+</html>
diff --git a/templates/hogan/error.hjs b/templates/hogan/error.hjs
new file mode 100644
index 0000000..36a6196
--- /dev/null
+++ b/templates/hogan/error.hjs
@@ -0,0 +1,3 @@
+<h1>{{ message }}</h1>
+<h2>{{ error.status }}</h2>
+<pre>{{ error.stack }}</pre>
diff --git a/templates/hogan/index.hjs b/templates/hogan/index.hjs
new file mode 100644
index 0000000..390869c
--- /dev/null
+++ b/templates/hogan/index.hjs
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>{{ title }}</title>
+    <link rel='stylesheet' href='/stylesheets/style.css' />
+  </head>
+  <body>
+    <h1>{{ title }}</h1>
+    <p>Welcome to {{ title }}</p>
+  </body>
+</html>
\ No newline at end of file
diff --git a/templates/jade/error.jade b/templates/jade/error.jade
new file mode 100644
index 0000000..51ec12c
--- /dev/null
+++ b/templates/jade/error.jade
@@ -0,0 +1,6 @@
+extends layout
+
+block content
+  h1= message
+  h2= error.status
+  pre #{error.stack}
diff --git a/templates/jade/index.jade b/templates/jade/index.jade
new file mode 100644
index 0000000..3d63b9a
--- /dev/null
+++ b/templates/jade/index.jade
@@ -0,0 +1,5 @@
+extends layout
+
+block content
+  h1= title
+  p Welcome to #{title}
diff --git a/templates/jade/layout.jade b/templates/jade/layout.jade
new file mode 100644
index 0000000..b945f57
--- /dev/null
+++ b/templates/jade/layout.jade
@@ -0,0 +1,7 @@
+doctype html
+html
+  head
+    title= title
+    link(rel='stylesheet', href='/stylesheets/style.css')
+  body
+    block content
\ No newline at end of file
diff --git a/templates/js/app.js b/templates/js/app.js
new file mode 100644
index 0000000..3b31cd8
--- /dev/null
+++ b/templates/js/app.js
@@ -0,0 +1,59 @@
+var express = require('express');
+var path = require('path');
+var favicon = require('static-favicon');
+var logger = require('morgan');
+var cookieParser = require('cookie-parser');
+var bodyParser = require('body-parser');
+
+var routes = require('./routes/index');
+var users = require('./routes/users');
+
+var app = express();
+
+// view engine setup
+app.set('views', path.join(__dirname, 'views'));
+app.set('view engine', '{views}');
+
+app.use(favicon());
+app.use(logger('dev'));
+app.use(bodyParser.json());
+app.use(bodyParser.urlencoded());
+app.use(cookieParser());{css}
+app.use(express.static(path.join(__dirname, 'public')));
+
+app.use('/', routes);
+app.use('/users', users);
+
+/// catch 404 and forwarding to error handler
+app.use(function(req, res, next) {
+    var err = new Error('Not Found');
+    err.status = 404;
+    next(err);
+});
+
+/// error handlers
+
+// development error handler
+// will print stacktrace
+if (app.get('env') === 'development') {
+    app.use(function(err, req, res, next) {
+        res.status(err.status || 500);
+        res.render('error', {
+            message: err.message,
+            error: err
+        });
+    });
+}
+
+// production error handler
+// no stacktraces leaked to user
+app.use(function(err, req, res, next) {
+    res.status(err.status || 500);
+    res.render('error', {
+        message: err.message,
+        error: {}
+    });
+});
+
+
+module.exports = app;
diff --git a/templates/js/routes/index.js b/templates/js/routes/index.js
new file mode 100644
index 0000000..896c948
--- /dev/null
+++ b/templates/js/routes/index.js
@@ -0,0 +1,9 @@
+var express = require('express');
+var router = express.Router();
+
+/* GET home page. */
+router.get('/', function(req, res) {
+  res.render('index', { title: 'Express' });
+});
+
+module.exports = router;
diff --git a/templates/js/routes/users.js b/templates/js/routes/users.js
new file mode 100644
index 0000000..c00d7de
--- /dev/null
+++ b/templates/js/routes/users.js
@@ -0,0 +1,9 @@
+var express = require('express');
+var router = express.Router();
+
+/* GET users listing. */
+router.get('/', function(req, res) {
+  res.send('respond with a resource');
+});
+
+module.exports = router;
diff --git a/templates/js/www b/templates/js/www
new file mode 100755
index 0000000..3cfbf77
--- /dev/null
+++ b/templates/js/www
@@ -0,0 +1,9 @@
+#!/usr/bin/env node
+var debug = require('debug')('my-application');
+var app = require('../app');
+
+app.set('port', process.env.PORT || 3000);
+
+var server = app.listen(app.get('port'), function() {
+  debug('Express server listening on port ' + server.address().port);
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-express-generator.git



More information about the Pkg-javascript-commits mailing list