diff --git a/bin/express-cli.js b/bin/express-cli.js index 380a447d..1530975e 100755 --- a/bin/express-cli.js +++ b/bin/express-cli.js @@ -95,11 +95,15 @@ function createApplication (name, dir, options, done) { version: '0.0.0', private: true, scripts: { + dev: 'nodemon ./bin/www', start: 'node ./bin/www' }, dependencies: { - debug: '~2.6.9', - express: '~4.17.1' + debug: '~4.4.1', + express: '~5.1.0' + }, + devDependencies: { + nodemon: '~3.1.10' } } @@ -125,36 +129,49 @@ function createApplication (name, dir, options, done) { app.locals.uses.push('express.json()') app.locals.uses.push('express.urlencoded({ extended: false })') - // Cookie parser - app.locals.modules.cookieParser = 'cookie-parser' - app.locals.uses.push('cookieParser()') - pkg.dependencies['cookie-parser'] = '~1.4.5' + if (options.view !== false) { + // Cookie parser + app.locals.modules.cookieParser = 'cookie-parser' + app.locals.uses.push('cookieParser()') + pkg.dependencies['cookie-parser'] = '~1.4.7' + } else { + app.locals.modules['{ responseMiddleware }'] = 'express-response-rest' + app.locals.uses.push('responseMiddleware') + pkg.dependencies['express-response-rest'] = '~1.0.1' + } if (dir !== '.') { mkdir(dir, '.') } mkdir(dir, 'public') - mkdir(dir, 'public/javascripts') + mkdir(dir, 'public/js') mkdir(dir, 'public/images') - mkdir(dir, 'public/stylesheets') + mkdir(dir, 'controllers') + mkdir(dir, 'models') + mkdir(dir, 'utils') + mkdir(dir, 'middleware') + + if (options.css) { + mkdir(dir, 'public/css') + } // copy css templates switch (options.css) { case 'less': - copyTemplateMulti('css', dir + '/public/stylesheets', '*.less') + copyTemplateMulti('css', dir + '/public/css', '*.less') break case 'stylus': - copyTemplateMulti('css', dir + '/public/stylesheets', '*.styl') + copyTemplateMulti('css', dir + '/public/css', '*.styl') break case 'compass': - copyTemplateMulti('css', dir + '/public/stylesheets', '*.scss') + copyTemplateMulti('css', dir + '/public/css', '*.scss') break case 'sass': - copyTemplateMulti('css', dir + '/public/stylesheets', '*.sass') + copyTemplateMulti('css', dir + '/public/css', '*.sass') break default: - copyTemplateMulti('css', dir + '/public/stylesheets', '*.css') + copyTemplateMulti('css', dir + '/public/css', '*.css') break } @@ -165,7 +182,7 @@ function createApplication (name, dir, options, done) { if (options.view) { // Copy view templates mkdir(dir, 'views') - pkg.dependencies['http-errors'] = '~1.7.2' + pkg.dependencies['http-errors'] = '~2.0.0' switch (options.view) { case 'dust': copyTemplateMulti('views', dir + '/views', '*.dust') @@ -202,22 +219,22 @@ function createApplication (name, dir, options, done) { case 'compass': app.locals.modules.compass = 'node-compass' app.locals.uses.push("compass({ mode: 'expanded' })") - pkg.dependencies['node-compass'] = '0.2.3' + pkg.dependencies['node-compass'] = '0.2.4' break case 'less': app.locals.modules.lessMiddleware = 'less-middleware' app.locals.uses.push("lessMiddleware(path.join(__dirname, 'public'))") - pkg.dependencies['less-middleware'] = '~2.2.1' + pkg.dependencies['less-middleware'] = '~3.1.0' break case 'sass': app.locals.modules.sassMiddleware = 'node-sass-middleware' app.locals.uses.push("sassMiddleware({\n src: path.join(__dirname, 'public'),\n dest: path.join(__dirname, 'public'),\n indentedSyntax: true, // true = .sass and false = .scss\n sourceMap: true\n})") - pkg.dependencies['node-sass-middleware'] = '0.11.0' + pkg.dependencies['node-sass-middleware'] = '1.1.0' break case 'stylus': app.locals.modules.stylus = 'stylus' app.locals.uses.push("stylus.middleware(path.join(__dirname, 'public'))") - pkg.dependencies.stylus = '0.54.5' + pkg.dependencies.stylus = '0.64.0' break } @@ -241,11 +258,11 @@ function createApplication (name, dir, options, done) { break case 'ejs': app.locals.view = { engine: 'ejs' } - pkg.dependencies.ejs = '~2.6.1' + pkg.dependencies.ejs = '~3.1.10' break case 'hbs': app.locals.view = { engine: 'hbs' } - pkg.dependencies.hbs = '~4.0.4' + pkg.dependencies.hbs = '~4.2.0' break case 'hjs': app.locals.view = { engine: 'hjs' } @@ -257,15 +274,15 @@ function createApplication (name, dir, options, done) { break case 'pug': app.locals.view = { engine: 'pug' } - pkg.dependencies.pug = '2.0.0-beta11' + pkg.dependencies.pug = '3.0.3' break case 'twig': app.locals.view = { engine: 'twig' } - pkg.dependencies.twig = '~0.10.3' + pkg.dependencies.twig = '~1.17.1' break case 'vash': app.locals.view = { engine: 'vash' } - pkg.dependencies.vash = '~0.12.6' + pkg.dependencies.vash = '~0.13.0' break default: app.locals.view = false diff --git a/templates/js/app.js.ejs b/templates/js/app.js.ejs index 2ef75aec..e9104a6a 100644 --- a/templates/js/app.js.ejs +++ b/templates/js/app.js.ejs @@ -1,17 +1,17 @@ <% if (view) { -%> -var createError = require('http-errors'); +const createError = require('http-errors'); <% } -%> -var express = require('express'); -var path = require('path'); +const express = require('express'); +const path = require('path'); <% Object.keys(modules).sort().forEach(function (variable) { -%> -var <%- variable %> = require('<%- modules[variable] %>'); +const <%- variable %> = require('<%- modules[variable] %>'); <% }); -%> <% Object.keys(localModules).sort().forEach(function (variable) { -%> -var <%- variable %> = require('<%- localModules[variable] %>'); +const <%- variable %> = require('<%- localModules[variable] %>'); <% }); -%> -var app = express(); +const app = express(); <% if (view) { -%> // view engine setup diff --git a/templates/js/index.html b/templates/js/index.html index ab1ad8a9..a79e94c5 100644 --- a/templates/js/index.html +++ b/templates/js/index.html @@ -2,7 +2,7 @@ Express - + diff --git a/templates/js/www.ejs b/templates/js/www.ejs index 690fc488..1364ec15 100644 --- a/templates/js/www.ejs +++ b/templates/js/www.ejs @@ -4,28 +4,30 @@ * Module dependencies. */ -var app = require('../app'); -var debug = require('debug')('<%- name %>:server'); -var http = require('http'); +const app = require('../app'); +const debug = require('debug')('<%- name %>:server'); +const http = require('http'); /** * Get port from environment and store in Express. */ -var port = normalizePort(process.env.PORT || '3000'); +const port = normalizePort(process.env.PORT || '3000'); app.set('port', port); /** * Create HTTP server. */ -var server = http.createServer(app); +const server = http.createServer(app); /** * Listen on provided port, on all network interfaces. */ -server.listen(port); +server.listen(port, () => { + console.log(`Server is running on http://localhost:${port}`); +}); server.on('error', onError); server.on('listening', onListening); @@ -34,7 +36,7 @@ server.on('listening', onListening); */ function normalizePort(val) { - var port = parseInt(val, 10); + const port = parseInt(val, 10); if (isNaN(port)) { // named pipe @@ -58,7 +60,7 @@ function onError(error) { throw error; } - var bind = typeof port === 'string' + const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; @@ -82,8 +84,8 @@ function onError(error) { */ function onListening() { - var addr = server.address(); - var bind = typeof addr === 'string' + const addr = server.address(); + const bind = typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port; debug('Listening on ' + bind); diff --git a/templates/views/error.dust b/templates/views/error.dust index 32a93665..948518ef 100644 --- a/templates/views/error.dust +++ b/templates/views/error.dust @@ -2,7 +2,7 @@ {title} - +

{message}

diff --git a/templates/views/index.dust b/templates/views/index.dust index 7170cffa..73d2a73e 100644 --- a/templates/views/index.dust +++ b/templates/views/index.dust @@ -2,7 +2,7 @@ {title} - +

{title}

diff --git a/templates/views/index.ejs b/templates/views/index.ejs index 7b7a1d6d..4ada1771 100644 --- a/templates/views/index.ejs +++ b/templates/views/index.ejs @@ -2,7 +2,7 @@ <%= title %> - +

<%= title %>

diff --git a/templates/views/index.hjs b/templates/views/index.hjs index 821a8dee..af12d7e5 100644 --- a/templates/views/index.hjs +++ b/templates/views/index.hjs @@ -2,7 +2,7 @@ {{ title }} - +

{{ title }}

diff --git a/templates/views/layout.hbs b/templates/views/layout.hbs index 068eb6be..bbb1cee8 100644 --- a/templates/views/layout.hbs +++ b/templates/views/layout.hbs @@ -2,7 +2,7 @@ {{title}} - + {{{body}}} diff --git a/templates/views/layout.jade b/templates/views/layout.jade index 15af079b..215cbc6c 100644 --- a/templates/views/layout.jade +++ b/templates/views/layout.jade @@ -2,6 +2,6 @@ doctype html html head title= title - link(rel='stylesheet', href='/stylesheets/style.css') + link(rel='stylesheet', href='/css/style.css') body block content diff --git a/templates/views/layout.pug b/templates/views/layout.pug index 15af079b..215cbc6c 100644 --- a/templates/views/layout.pug +++ b/templates/views/layout.pug @@ -2,6 +2,6 @@ doctype html html head title= title - link(rel='stylesheet', href='/stylesheets/style.css') + link(rel='stylesheet', href='/css/style.css') body block content diff --git a/templates/views/layout.twig b/templates/views/layout.twig index bce6dd55..0d70694a 100644 --- a/templates/views/layout.twig +++ b/templates/views/layout.twig @@ -2,7 +2,7 @@ {{ title }} - + {% block body %}{% endblock %} diff --git a/templates/views/layout.vash b/templates/views/layout.vash index ab67afb9..dff45f69 100644 --- a/templates/views/layout.vash +++ b/templates/views/layout.vash @@ -3,7 +3,7 @@ @model.title - + @html.block('content')