Skip to content

Commit

Permalink
feat(gen): add configurable ports (#2005)
Browse files Browse the repository at this point in the history
dev, debug, & prod ports are now configurable through yeoman arguments
  • Loading branch information
Awk34 authored Jun 21, 2016
1 parent 4287ed8 commit 50e6d0c
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 17 deletions.
3 changes: 3 additions & 0 deletions docs/generators/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Options:
--skip-cache # Do not remember prompt answers Default: false
--skip-install # Do not install dependencies Default: false
--app-suffix # Allow a custom suffix to be added to the module name Default: App
--dev-port # Port to use for the development HTTP server Default: 9000
--debug-port # Port to use for the server debugger Default: 5858
--prod-port # Port to use for the production HTTP Server Default: 8080

Arguments:
name Type: String Required: false
Expand Down
29 changes: 26 additions & 3 deletions src/generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ export class Generator extends Base {
type: String,
defaults: 'App'
});

this.option('dev-port', {
desc: 'Port to use for the development HTTP server',
type: String,
defaults: '9000'
});

this.option('debug-port', {
desc: 'Port to use for the server debugger',
type: String,
defaults: '5858'
});

this.option('prod-port', {
desc: 'Port to use for the production HTTP Server',
type: String,
defaults: '8080'
});
}

get initializing() {
Expand Down Expand Up @@ -90,9 +108,9 @@ export class Generator extends Base {

this.scriptExt = this.filters.ts ? 'ts' : 'js';
this.templateExt = this.filters.jade ? 'jade' : 'html';
this.styleExt = this.filters.sass ? 'scss' :
this.filters.less ? 'less' :
this.filters.stylus ? 'styl' :
this.styleExt = this.filters.sass ? 'scss' :
this.filters.less ? 'less' :
this.filters.stylus ? 'styl' :
'css';
} else {
insight.track('skipConfig', 'false');
Expand All @@ -103,6 +121,11 @@ export class Generator extends Base {
}
});
}
},
assignPorts() {
this.devPort = this.options['dev-port'];
this.debugPort = this.options['debug-port'];
this.prodPort = this.options['prod-port'];
}
};
}
Expand Down
6 changes: 3 additions & 3 deletions templates/app/Gruntfile(grunt).js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = function(grunt) {
},
express: {
options: {
port: process.env.PORT || 9000
port: process.env.PORT || <%= devPort %>
},
dev: {
options: {
Expand Down Expand Up @@ -239,7 +239,7 @@ module.exports = function(grunt) {
options: {
nodeArgs: ['--debug-brk'],
env: {
PORT: process.env.PORT || 9000
PORT: process.env.PORT || <%= devPort %>
},
callback: function(nodemon) {
nodemon.on('log', function(event) {
Expand All @@ -249,7 +249,7 @@ module.exports = function(grunt) {
// opens browser on initial server start
nodemon.on('config:update', function() {
setTimeout(function() {
require('open')('http://localhost:8080/debug?port=5858');
require('open')('http://localhost:<%= devPort %>/debug?port=<%= debugPort %>');
}, 500);
});
}
Expand Down
12 changes: 7 additions & 5 deletions templates/app/gulpfile.babel(gulp).js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ gulp.task('inject:tsconfig', () => {
`${clientPath}/**/!(*.spec|*.mock).ts`,
`!${clientPath}/bower_components/**/*`,
`typings/main.d.ts`
],
],
'./tsconfig.client.json');
});

Expand All @@ -256,7 +256,7 @@ gulp.task('inject:tsconfigTest', () => {
`${clientPath}/**/+(*.spec|*.mock).ts`,
`!${clientPath}/bower_components/**/*`,
`typings/main.d.ts`
],
],
'./tsconfig.client.test.json');
});<% } %>

Expand Down Expand Up @@ -401,13 +401,15 @@ gulp.task('start:server:prod', () => {

gulp.task('start:inspector', () => {
gulp.src([])
.pipe(plugins.nodeInspector());
.pipe(plugins.nodeInspector({
debugPort: <%= debugPort %>
}));
});

gulp.task('start:server:debug', () => {
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
config = require(`./${serverPath}/config/environment`);
nodemon(`-w ${serverPath} --debug-brk ${serverPath}`)
config = require(`./${serverPath}/config/environment`);
nodemon(`-w ${serverPath} --debug=<%= debugPort %> --debug-brk ${serverPath}`)
.on('log', onServerLog);
});

Expand Down
2 changes: 1 addition & 1 deletion templates/app/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = function(config) {
exclude: [],

// web server port
port: 8080,
port: <%= devPort %>,

// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
Expand Down
2 changes: 1 addition & 1 deletion templates/app/protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var config = {

// A base URL for your application under test. Calls to protractor.get()
// with relative paths will be prepended with this.
baseUrl: 'http://localhost:' + (process.env.PORT || '9000'),
baseUrl: 'http://localhost:' + (process.env.PORT || '<%= devPort %>'),

// Credientials for Saucelabs
sauceUser: process.env.SAUCE_USERNAME,
Expand Down
2 changes: 1 addition & 1 deletion templates/app/server/config/_local.env.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// You will need to set these on the server you deploy to.

module.exports = {
DOMAIN: 'http://localhost:9000',
DOMAIN: 'http://localhost:<%= devPort %>',
SESSION_SECRET: '<%= lodash.slugify(appname) + "-secret" %>',<% if (filters.facebookAuth) { %>

FACEBOOK_ID: 'app-id',
Expand Down
2 changes: 1 addition & 1 deletion templates/app/server/config/_local.env.sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// You will need to set these on the server you deploy to.

module.exports = {
DOMAIN: 'http://localhost:9000',
DOMAIN: 'http://localhost:<%= devPort %>',
SESSION_SECRET: '<%= lodash.slugify(appname) + "-secret" %>',<% if (filters.facebookAuth) { %>

FACEBOOK_ID: 'app-id',
Expand Down
2 changes: 1 addition & 1 deletion templates/app/server/config/environment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var all = {
root: path.normalize(__dirname + '/../../..'),

// Server port
port: process.env.PORT || 9000,
port: process.env.PORT || <%= devPort %>,

// Server IP
ip: process.env.IP || '0.0.0.0',
Expand Down
2 changes: 1 addition & 1 deletion templates/app/server/config/environment/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
// Server port
port: process.env.OPENSHIFT_NODEJS_PORT ||
process.env.PORT ||
8080<% if (filters.mongoose) { %>,
<%= prodPort %><% if (filters.mongoose) { %>,

// MongoDB connection options
mongo: {
Expand Down

0 comments on commit 50e6d0c

Please sign in to comment.