Skip to content

Commit

Permalink
chore(*) gulp serve now uses pkg.config.port
Browse files Browse the repository at this point in the history
  • Loading branch information
topheman committed Aug 24, 2015
1 parent ed5bdc7 commit ed2d8db
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 0 additions & 2 deletions gulp/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import gitRev from 'git-rev-sync';

import {ENV} from './utils.js';

export const DEFAULT_SERVER_PORT = 9000;

var infos = {
file: '',
pkg: pkg,
Expand Down
14 changes: 6 additions & 8 deletions gulp/tasks/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import browserSync from 'browser-sync';

import jspmOverride from '../../test/jspm.override.json';

import {COLORS,LOG,SERVER_PORT,OPEN,ENV} from '../utils.js';

import {DEFAULT_SERVER_PORT} from '../const.js';
import {COLORS,LOG,PORT,OPEN,ENV} from '../utils.js';

import path from '../paths';

Expand All @@ -31,13 +29,13 @@ function infos(env) {
* @param [options]
* @param [options.files='default']
* @param [options.browser='default']
* @param [options.port=DEFAULT_SERVER_PORT]
* @param [options.port=PORT]
*/
function startBrowserSync(env, baseDir, options = {}) {
env = env.toLowerCase();
options.browser = options.browser === undefined ? 'default' : options.browser;
options.files = options.files === undefined ? 'default' : options.files;
options.port = options.port === undefined ? DEFAULT_SERVER_PORT : options.port;
options.port = options.port === undefined ? PORT : options.port;
options.open = options.open === undefined ? true : options.open;

var config = {
Expand Down Expand Up @@ -129,13 +127,13 @@ gulp.task('serve', gulpServeDependencyTasks, () => {
infos(ENV);
switch(ENV){
case 'prod':
startBrowserSync('prod', ['./build/dist'], {port: SERVER_PORT, open: OPEN});
startBrowserSync('prod', ['./build/dist'], {port: PORT, open: OPEN});
break;
case 'test':
startBrowserSync('test', ['.tmp', 'src', 'jspm_packages', './'], {port: SERVER_PORT, open: OPEN});
startBrowserSync('test', ['.tmp', 'src', 'jspm_packages', './'], {port: PORT, open: OPEN});
break;
case 'dev':
startBrowserSync('dev', ['.tmp', 'src', 'jspm_packages', './'], {port: SERVER_PORT, open: OPEN});
startBrowserSync('dev', ['.tmp', 'src', 'jspm_packages', './'], {port: PORT, open: OPEN});
break;
}
});
6 changes: 3 additions & 3 deletions gulp/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import util from 'gulp-util';
export const LOG = util.log;
export const COLORS = util.colors;

import {DEFAULT_SERVER_PORT} from './const.js';
import pkg from '../package.json';

//launch your task with `--port 9002` for example
export const SERVER_PORT = util.env.port || DEFAULT_SERVER_PORT;
export const PORT = util.env.port || (pkg.config ? (pkg.config.port ? pkg.config.port : null) : null) || 9000;

//launch your task with `--open` `--open false` for example
export const OPEN = util.env.open === 'false' ? false : true;
Expand All @@ -23,7 +23,7 @@ var environment = ((util.env.env === true ? 'dev' : util.env.env) || process.env
if (['dev', 'prod', 'test'].indexOf(environment) === -1) {
throw new Error('--env flag only accepts dev/prod/test')
}
if(!process.env.ENV){
if (!process.env.ENV) {
LOG(COLORS.yellow('[INFOS] Setting process.env.ENV=' + environment));
process.env.ENV = environment;
}
Expand Down

0 comments on commit ed2d8db

Please sign in to comment.