Skip to content

Commit 6cc198f

Browse files
committed
feat(gen): add configurable ports
dev, debug, & prod ports are now configurable through yeoman arguments
1 parent 4287ed8 commit 6cc198f

File tree

10 files changed

+45
-17
lines changed

10 files changed

+45
-17
lines changed

Diff for: docs/generators/app.md

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Options:
1111
--skip-cache # Do not remember prompt answers Default: false
1212
--skip-install # Do not install dependencies Default: false
1313
--app-suffix # Allow a custom suffix to be added to the module name Default: App
14+
--dev-port # Port to use for the development HTTP server Default: 9000
15+
--debug-port # Port to use for the server debugger Default: 5858
16+
--prod-port # Port to use for the production HTTP Server Default: 8080
1417

1518
Arguments:
1619
name Type: String Required: false

Diff for: src/generators/app/index.js

+26-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ export class Generator extends Base {
3131
type: String,
3232
defaults: 'App'
3333
});
34+
35+
this.option('dev-port', {
36+
desc: 'Port to use for the development HTTP server',
37+
type: String,
38+
defaults: '9000'
39+
});
40+
41+
this.option('debug-port', {
42+
desc: 'Port to use for the server debugger',
43+
type: String,
44+
defaults: '5858'
45+
});
46+
47+
this.option('prod-port', {
48+
desc: 'Port to use for the production HTTP Server',
49+
type: String,
50+
defaults: '8080'
51+
});
3452
}
3553

3654
get initializing() {
@@ -90,9 +108,9 @@ export class Generator extends Base {
90108

91109
this.scriptExt = this.filters.ts ? 'ts' : 'js';
92110
this.templateExt = this.filters.jade ? 'jade' : 'html';
93-
this.styleExt = this.filters.sass ? 'scss' :
94-
this.filters.less ? 'less' :
95-
this.filters.stylus ? 'styl' :
111+
this.styleExt = this.filters.sass ? 'scss' :
112+
this.filters.less ? 'less' :
113+
this.filters.stylus ? 'styl' :
96114
'css';
97115
} else {
98116
insight.track('skipConfig', 'false');
@@ -103,6 +121,11 @@ export class Generator extends Base {
103121
}
104122
});
105123
}
124+
},
125+
assignPorts() {
126+
this.devPort = this.options['dev-port'];
127+
this.debugPort = this.options['debug-port'];
128+
this.prodPort = this.options['prod-port'];
106129
}
107130
};
108131
}

Diff for: templates/app/Gruntfile(grunt).js

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = function(grunt) {
3636
},
3737
express: {
3838
options: {
39-
port: process.env.PORT || 9000
39+
port: process.env.PORT || <%= devPort %>
4040
},
4141
dev: {
4242
options: {
@@ -239,7 +239,7 @@ module.exports = function(grunt) {
239239
options: {
240240
nodeArgs: ['--debug-brk'],
241241
env: {
242-
PORT: process.env.PORT || 9000
242+
PORT: process.env.PORT || <%= devPort %>
243243
},
244244
callback: function(nodemon) {
245245
nodemon.on('log', function(event) {
@@ -249,7 +249,7 @@ module.exports = function(grunt) {
249249
// opens browser on initial server start
250250
nodemon.on('config:update', function() {
251251
setTimeout(function() {
252-
require('open')('http://localhost:8080/debug?port=5858');
252+
require('open')('http://localhost:<%= devPort %>/debug?port=<%= debugPort %>');
253253
}, 500);
254254
});
255255
}

Diff for: templates/app/gulpfile.babel(gulp).js

+7-5
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ gulp.task('inject:tsconfig', () => {
247247
`${clientPath}/**/!(*.spec|*.mock).ts`,
248248
`!${clientPath}/bower_components/**/*`,
249249
`typings/main.d.ts`
250-
],
250+
],
251251
'./tsconfig.client.json');
252252
});
253253

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

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

402402
gulp.task('start:inspector', () => {
403403
gulp.src([])
404-
.pipe(plugins.nodeInspector());
404+
.pipe(plugins.nodeInspector({
405+
debugPort: <%= debugPort %>
406+
}));
405407
});
406408

407409
gulp.task('start:server:debug', () => {
408410
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
409-
config = require(`./${serverPath}/config/environment`);
410-
nodemon(`-w ${serverPath} --debug-brk ${serverPath}`)
411+
config = require(`./${serverPath}/config/environment`);
412+
nodemon(`-w ${serverPath} --debug=<%= debugPort %> --debug-brk ${serverPath}`)
411413
.on('log', onServerLog);
412414
});
413415

Diff for: templates/app/karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ module.exports = function(config) {
6161
exclude: [],
6262

6363
// web server port
64-
port: 8080,
64+
port: <%= devPort %>,
6565

6666
// level of logging
6767
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG

Diff for: templates/app/protractor.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var config = {
1010

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

1515
// Credientials for Saucelabs
1616
sauceUser: process.env.SAUCE_USERNAME,

Diff for: templates/app/server/config/_local.env.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// You will need to set these on the server you deploy to.
77

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

1212
FACEBOOK_ID: 'app-id',

Diff for: templates/app/server/config/_local.env.sample.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// You will need to set these on the server you deploy to.
77

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

1212
FACEBOOK_ID: 'app-id',

Diff for: templates/app/server/config/environment/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var all = {
1919
root: path.normalize(__dirname + '/../../..'),
2020

2121
// Server port
22-
port: process.env.PORT || 9000,
22+
port: process.env.PORT || <%= devPort %>,
2323

2424
// Server IP
2525
ip: process.env.IP || '0.0.0.0',

Diff for: templates/app/server/config/environment/production.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
// Server port
1212
port: process.env.OPENSHIFT_NODEJS_PORT ||
1313
process.env.PORT ||
14-
8080<% if (filters.mongoose) { %>,
14+
<%= prodPort %><% if (filters.mongoose) { %>,
1515

1616
// MongoDB connection options
1717
mongo: {

0 commit comments

Comments
 (0)