Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 4.14 #117

Merged
merged 31 commits into from
Oct 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b7ca4e5
gen: update express to ~1.14.0
dougwilson Jun 19, 2016
7f3c353
deps: [email protected]
dougwilson Jun 19, 2016
38812a9
Remove -V as an alias to --version
dougwilson Jun 20, 2016
cfa589f
Show help/usage when given an unknown option
dougwilson Jun 20, 2016
0b68625
Provide help/usage when --css missing <engine>
dougwilson Jun 21, 2016
55b2f87
build: [email protected]
dougwilson Jun 21, 2016
15eb34b
tests: simplify environment setup boilerplate
dougwilson Jun 21, 2016
6ad07b6
gen: update node-sass-middleware to 0.9.8
dougwilson Jun 21, 2016
9585ddb
tests: add tests for --hogan
dougwilson Jun 21, 2016
1bd6f64
Add pug as a view engine
williammincy Jun 25, 2016
cf99380
Simplify the default error handler
miletbaker Mar 26, 2015
91adc07
Rename variable holding main router
Aug 24, 2016
02fe77b
Add --view <engine> option
dougwilson Jul 1, 2016
79ac9c9
gen: update body-parser to ~1.15.1
IShinji Oct 20, 2016
15d47e6
Add vash as a view engine
Jul 7, 2016
9dc7f97
docs: document where to access the app
dougwilson Oct 21, 2016
cda298d
Add twig as a view engine
Jan 21, 2016
9ce9443
gen: update ejs to ~2.5.2
dougwilson Oct 26, 2016
6340224
gen: update hbs to ~4.0.1
dougwilson Oct 26, 2016
8a5b5e9
gen: update pug to ~2.0.0-beta6
dougwilson Oct 26, 2016
1781463
gen: update vash to ~0.12.2
dougwilson Oct 26, 2016
ed1b049
gen: update less-middleware to ~2.2.0
dougwilson Oct 26, 2016
3293492
build: [email protected]
dougwilson Oct 26, 2016
06e5857
build: support Node.js 5.x
dougwilson Oct 26, 2016
89cdfa0
build: support Node.js 6.x
dougwilson Oct 26, 2016
ee1a3b5
build: support Node.js 7.x
dougwilson Oct 26, 2016
2f88e63
build: cache node_modules on CI
dougwilson Oct 26, 2016
ee43be8
Add missing "pug" to --view help description
dougwilson Oct 27, 2016
2718358
Add warning when using the default view engine
dougwilson Oct 27, 2016
3da410a
Add warning to old view engine options
dougwilson Oct 27, 2016
180ec56
Create valid package name
dougwilson Oct 27, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ node_js:
- "1.8"
- "2.5"
- "3.3"
- "4.4"
- "4.6"
- "5.12"
- "6.9"
- "7.0"
sudo: false
cache:
directories:
- node_modules
before_install:
# Update Node.js modules
- "test ! -d node_modules || npm prune"
- "test ! -d node_modules || npm rebuild"
script: "npm run-script test-ci"
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(The MIT License)

Copyright (c) 2009-2013 TJ Holowaychuk <[email protected]>
Copyright (c) 2015-2016 Douglas Christopher Wilson <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The quickest way to get started with express is to utilize the executable `expre
Create the app:

```bash
$ express /tmp/foo && cd /tmp/foo
$ express --view=hbs /tmp/foo && cd /tmp/foo
```

Install dependencies:
Expand All @@ -30,7 +30,7 @@ Install dependencies:
$ npm install
```

Rock and Roll
Start your Express.js app at `http://localhost:3000/`:

```bash
$ npm start
Expand All @@ -41,10 +41,12 @@ $ npm start
This generator can also be further configured with the following command line flags.

-h, --help output usage information
-V, --version output the version number
-e, --ejs add ejs engine support (defaults to jade)
--version output the version number
-e, --ejs add ejs engine support
--hbs add handlebars engine support
--pug add pug engine support
-H, --hogan add hogan.js engine support
-v, --view <engine> add view <engine> support (ejs|hbs|hjs|jade|pug|twig|vash) (defaults to jade)
-c, --css <engine> add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)
--git add .gitignore
-f, --force force on non-empty directory
Expand Down
9 changes: 8 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ environment:
- nodejs_version: "1.8"
- nodejs_version: "2.5"
- nodejs_version: "3.3"
- nodejs_version: "4.4"
- nodejs_version: "4.6"
- nodejs_version: "5.12"
- nodejs_version: "6.9"
- nodejs_version: "7.0"
cache:
- node_modules
install:
- ps: Install-Product node $env:nodejs_version
- if exist node_modules npm prune
- if exist node_modules npm rebuild
- npm install
build: off
test_script:
Expand Down
146 changes: 126 additions & 20 deletions bin/express
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var fs = require('fs');
var path = require('path');
var readline = require('readline');
var sortedObject = require('sorted-object');
var util = require('util');

var _exit = process.exit;
var eol = os.EOL;
Expand All @@ -20,16 +21,35 @@ process.exit = exit

// CLI

around(program, 'optionMissingArgument', function (fn, args) {
program.outputHelp()
fn.apply(this, args)
return { args: [], unknown: [] }
})

before(program, 'outputHelp', function () {
this.allowUnknownOption();
// track if help was shown for unknown option
this._helpShown = true
});

before(program, 'unknownOption', function () {
// allow unknown options if help was shown, to prevent trailing error
this._allowUnknownOption = this._helpShown

// show help if not yet shown
if (!this._helpShown) {
program.outputHelp()
}
})

program
.version(version)
.version(version, ' --version')
.usage('[options] [dir]')
.option('-e, --ejs', 'add ejs engine support (defaults to jade)')
.option(' --hbs', 'add handlebars engine support')
.option('-H, --hogan', 'add hogan.js engine support')
.option('-e, --ejs', 'add ejs engine support', renamedOption('--ejs', '--view=ejs'))
.option(' --pug', 'add pug engine support', renamedOption('--pug', '--view=pug'))
.option(' --hbs', 'add handlebars engine support', renamedOption('--hbs', '--view=hbs'))
.option('-H, --hogan', 'add hogan.js engine support', renamedOption('--hogan', '--view=hogan'))
.option('-v, --view <engine>', 'add view <engine> support (ejs|hbs|hjs|jade|pug|twig|vash) (defaults to jade)')
.option('-c, --css <engine>', 'add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)')
.option(' --git', 'add .gitignore')
.option('-f, --force', 'force on non-empty directory')
Expand All @@ -39,6 +59,20 @@ if (!exit.exited) {
main();
}

/**
* Install an around function; AOP.
*/

function around(obj, method, fn) {
var old = obj[method]

obj[method] = function () {
var args = new Array(arguments.length)
for (var i = 0; i < args.length; i++) args[i] = arguments[i]
return fn.call(this, old, args)
}
}

/**
* Install a before function; AOP.
*/
Expand Down Expand Up @@ -141,7 +175,7 @@ function createApplication(app_name, path) {
});

mkdir(path + '/views', function(){
switch (program.template) {
switch (program.view) {
case 'ejs':
copy_template('ejs/index.ejs', path + '/views/index.ejs');
copy_template('ejs/error.ejs', path + '/views/error.ejs');
Expand All @@ -160,6 +194,21 @@ function createApplication(app_name, path) {
copy_template('hbs/layout.hbs', path + '/views/layout.hbs');
copy_template('hbs/error.hbs', path + '/views/error.hbs');
break;
case 'pug':
copy_template('pug/index.pug', path + '/views/index.pug');
copy_template('pug/layout.pug', path + '/views/layout.pug');
copy_template('pug/error.pug', path + '/views/error.pug');
break;
case 'twig':
copy_template('twig/index.twig', path + '/views/index.twig');
copy_template('twig/layout.twig', path + '/views/layout.twig');
copy_template('twig/error.twig', path + '/views/error.twig');
break;
case 'vash':
copy_template('vash/index.vash', path + '/views/index.vash');
copy_template('vash/layout.vash', path + '/views/layout.vash');
copy_template('vash/error.vash', path + '/views/error.vash');
break;
}
complete();
});
Expand All @@ -183,7 +232,7 @@ function createApplication(app_name, path) {
}

// Template support
app = app.replace('{views}', program.template);
app = app.replace('{views}', program.view);

// package.json
var pkg = {
Expand All @@ -192,35 +241,44 @@ function createApplication(app_name, path) {
, private: true
, scripts: { start: 'node ./bin/www' }
, dependencies: {
'express': '~4.13.4',
'body-parser': '~1.15.1',
'express': '~4.14.0',
'body-parser': '~1.15.2',
'cookie-parser': '~1.4.3',
'debug': '~2.2.0',
'morgan': '~1.7.0',
'serve-favicon': '~2.3.0'
}
}

switch (program.template) {
switch (program.view) {
case 'jade':
pkg.dependencies['jade'] = '~1.11.0';
break;
case 'ejs':
pkg.dependencies['ejs'] = '~2.4.1';
pkg.dependencies['ejs'] = '~2.5.2';
break;
case 'hjs':
pkg.dependencies['hjs'] = '~0.0.6';
break;
case 'hbs':
pkg.dependencies['hbs'] = '~4.0.0';
pkg.dependencies['hbs'] = '~4.0.1';
break;
case 'pug':
pkg.dependencies['pug'] = '~2.0.0-beta6';
break;
case 'twig':
pkg.dependencies['twig'] = '~0.9.5';
break;
case 'vash':
pkg.dependencies['vash'] = '~0.12.2';
break;
default:
}

// CSS Engine support
switch (program.css) {
case 'less':
pkg.dependencies['less-middleware'] = '1.0.x';
pkg.dependencies['less-middleware'] = '~2.2.0';
break;
case 'compass':
pkg.dependencies['node-compass'] = '0.2.3';
Expand All @@ -229,7 +287,7 @@ function createApplication(app_name, path) {
pkg.dependencies['stylus'] = '0.54.5';
break;
case 'sass':
pkg.dependencies['node-sass-middleware'] = '0.8.0';
pkg.dependencies['node-sass-middleware'] = '0.9.8';
break;
default:
}
Expand Down Expand Up @@ -258,6 +316,18 @@ function copy_template(from, to) {
from = path.join(__dirname, '..', 'templates', from);
write(to, fs.readFileSync(from, 'utf-8'));
}
/**
* Create an app name from a directory path, fitting npm naming requirements.
*
* @param {String} pathName
*/

function createAppName(pathName) {
return path.basename(pathName)
.replace(/[^A-Za-z0-9\.()!~*'-]+/g, '-')
.replace(/^[-_\.]+|-+$/g, '')
.toLowerCase()
}

/**
* Check if the given directory `path` is empty.
Expand Down Expand Up @@ -325,13 +395,21 @@ function main() {
var destinationPath = program.args.shift() || '.';

// App name
var appName = path.basename(path.resolve(destinationPath));
var appName = createAppName(path.resolve(destinationPath)) || 'hello-world'

// View engine
if (program.view === undefined) {
if (program.ejs) program.view = 'ejs'
if (program.hbs) program.view = 'hbs'
if (program.hogan) program.view = 'hjs'
if (program.pug) program.view = 'pug'
}

// Template engine
program.template = 'jade';
if (program.ejs) program.template = 'ejs';
if (program.hogan) program.template = 'hjs';
if (program.hbs) program.template = 'hbs';
// Default view engine
if (program.view === undefined) {
warning("the default view engine will not be jade in future releases\nuse `--view=jade' or `--help' for additional options")
program.view = 'jade'
}

// Generate application
emptyDirectory(destinationPath, function (empty) {
Expand All @@ -351,6 +429,34 @@ function main() {
});
}

/**
* Generate a callback function for commander to warn about renamed option.
*
* @param {String} originalName
* @param {String} newName
*/

function renamedOption(originalName, newName) {
return function (val) {
warning(util.format("option `%s' has been renamed to `%s'", originalName, newName))
return val
}
}

/**
* Display a warning similar to how errors are displayed by commander.
*
* @param {String} message
*/

function warning(message) {
console.error()
message.split('\n').forEach(function (line) {
console.error(' warning: %s', line)
})
console.error()
}

/**
* echo str > path.
*
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"repository": "expressjs/generator",
"license": "MIT",
"dependencies": {
"commander": "2.7.1",
"commander": "2.9.0",
"mkdirp": "0.5.1",
"sorted-object": "2.0.0"
},
Expand All @@ -35,9 +35,10 @@
"express": "./bin/express"
},
"devDependencies": {
"mocha": "2.4.5",
"mocha": "2.5.3",
"rimraf": "2.5.2",
"supertest": "1.2.0"
"supertest": "1.2.0",
"validate-npm-package-name": "2.2.2"
},
"engines": {
"node": ">= 0.10"
Expand Down
Loading