Skip to content

Commit

Permalink
Simplify gulp by removing separate prod/dev scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
simison committed Nov 18, 2018
1 parent 4aafa3f commit b977c2b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 98 deletions.
2 changes: 1 addition & 1 deletion config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var validateEnvironmentVariable = function () {
} else {
console.error(chalk.red('NODE_ENV is not defined! Using default development environment'));
}
process.env.NODE_ENV = 'development';
// process.env.NODE_ENV = 'development';
} else {
console.log(chalk.bold('Loaded "' + process.env.NODE_ENV + '" environment configuration'));
}
Expand Down
103 changes: 18 additions & 85 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ var environmentAssets,

/**
* Load config + assets
* Note that loading config before `env:*`
* tasks would load configs with wrong environment
*/
function loadConfig(done) {
console.log('->loadConfig');
if (!config) {
console.log('->loadConfig -> config');
config = require('./config/config');
}
if (!environmentAssets) {
console.log('->loadConfig -> environmentAssets');
environmentAssets = require('./config/assets/' + process.env.NODE_ENV || 'development') || {};
}
if (!assets) {
console.log('->loadConfig -> assets');
assets = _.extend(defaultAssets, environmentAssets);
}
done();
Expand Down Expand Up @@ -119,22 +121,6 @@ function runNodemonWorker(done) {
done();
}

// Set NODE_ENV to 'test' and prepare environment
gulp.task('env:test', gulp.series(
function (done) {
process.env.NODE_ENV = 'test';
done();
}
));

// Set NODE_ENV to 'development' and prepare environment
gulp.task('env:dev', gulp.series(
function (done) {
process.env.NODE_ENV = 'development';
done();
}
));

gulp.task('webpack', gulp.parallel(
webpackTask({
entry: './config/webpack/entries/main.js',
Expand Down Expand Up @@ -167,14 +153,6 @@ function webpackTask(opts) {
};
}

// Set NODE_ENV to 'production' and prepare environment
gulp.task('env:prod', gulp.series(
function (done) {
process.env.NODE_ENV = 'production';
done();
}
));

// Watch files for changes
gulp.task('watch', function watch(done) {
// Start Refresh
Expand Down Expand Up @@ -470,9 +448,8 @@ gulp.task('lint', gulp.parallel('eslint', 'eslint-angular'));
// Clean dist css and js files
gulp.task('clean', gulp.parallel('clean:css', 'clean:js'));

// Build assets for development mode
gulp.task('build:dev', gulp.series(
'env:dev',
// Build assets
gulp.task('build', gulp.series(
gulp.parallel(
'lint',
'clean'
Expand All @@ -484,63 +461,38 @@ gulp.task('build:dev', gulp.series(
)
));

// Build assets for production mode
gulp.task('build:prod', gulp.series(
'env:prod',
gulp.parallel(
'lint',
'clean'
),
gulp.parallel(
'build:styles',
'build:scripts'
)
));

// Run the project tests
gulp.task('test', gulp.series(
'env:test',
karma,
mocha
));

gulp.task('test:server', gulp.series(
'env:test',
gulp.parallel(
'lint',
mocha
)
));

gulp.task('test:server:no-lint', gulp.series(
'env:test',
gulp.task('test:server', gulp.parallel(
'lint',
mocha
));

gulp.task('test:server:no-lint', mocha);

// Watch all server files for changes & run server tests (test:server) task on changes
gulp.task('test:server:watch', gulp.series(
'test:server:no-lint',
'watch:server:run-tests'
));

gulp.task('test:client', gulp.series(
'build:dev',
'env:test',
'build',
karma
));

gulp.task('test:client:watch', gulp.series(
'env:test',
gulp.parallel(
'lint',
karmaWatch
)
gulp.task('test:client:watch', gulp.parallel(
'lint',
karmaWatch
));

// Run the project in development mode
gulp.task('develop', gulp.series(
'env:dev',
'build:dev',
// Run the development server
gulp.task('server', gulp.series(
'build',
gulp.parallel(
runNodemon,
'watch',
Expand All @@ -557,24 +509,5 @@ gulp.task('develop', gulp.series(
)
));

// Run the project in production mode
gulp.task('prod', gulp.series(
'env:prod',
'build:prod',
gulp.parallel(
runNodemon,
'watch'
)
));

// Run worker script in development mode
gulp.task('worker:dev', gulp.series(
'env:dev',
runNodemonWorker
));

// Run worker script in production mode
gulp.task('worker:prod', gulp.series(
'env:prod',
runNodemonWorker
));
gulp.task('worker', runNodemonWorker);
28 changes: 28 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,17 @@
"seed:tribes": "node ./bin/fillTestData/Tribes.js",
"seed:users": "node ./bin/fillTestData/Users.js",
"seed": "npm run seed:tribes 100 && npm run seed:users 1000 admin1 admin2 admin3 && npm run seed:messages 2000 10",
"start:develop": "gulp develop",
"start:docker": "npm run prestart && concurrently --raw --kill-others --kill-others-on-fail 'gulp develop' 'npm run start:worker'",
"start:prod": "gulp prod",
"start:worker:prod": "gulp worker:prod",
"start:worker": "gulp worker:dev",
"start": "concurrently --raw --kill-others --kill-others-on-fail 'npm run start:develop' 'npm run start:worker' 'npm run dashboard:mail'",
"test:client:watch": "npm run pretest && gulp test:client:watch",
"test:client": "npm run pretest && gulp test:client",
"start:docker": "npm run prestart && concurrently --raw --kill-others --kill-others-on-fail 'npm run start:server' 'npm run start:worker'",
"start:worker": "gulp worker",
"start:server": "gulp server",
"start": "concurrently --raw --kill-others --kill-others-on-fail 'npm run start:server' 'npm run start:worker' 'npm run dashboard:mail'",
"test:client:watch": "cross-env-shell NODE_ENV=test npm run pretest && gulp test:client:watch",
"test:client": "cross-env-shell NODE_ENV=test npm run pretest && gulp test:client",
"test:selenium": "python ./scripts/selenium/test.py",
"test:server:no-lint": "npm run pretest && gulp test:server:no-lint",
"test:server:watch": "npm run pretest && gulp test:server:watch",
"test:server": "npm run pretest && gulp test:server",
"test": "npm run lint && gulp test"
"test:server:no-lint": "cross-env-shell NODE_ENV=test npm run pretest && gulp test:server:no-lint",
"test:server:watch": "cross-env-shell NODE_ENV=test npm run pretest && gulp test:server:watch",
"test:server": "cross-env-shell NODE_ENV=test npm run pretest && gulp test:server",
"test": "cross-env-shell NODE_ENV=test npm run lint && cross-env-shell NODE_ENV=test gulp test"
},
"dependencies": {
"acl": "~0.4.11",
Expand Down Expand Up @@ -95,6 +93,7 @@
"connect-flash": "~0.1.1",
"connect-mongo": "~2.0.1",
"cookie-parser": "~1.4.3",
"cross-env": "~5.2.0",
"del": "~3.0.0",
"eslint-plugin-angular": "~4.0.0",
"expect-ct": "~0.1.1",
Expand Down

0 comments on commit b977c2b

Please sign in to comment.