This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
176 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,81 @@ | ||
'use strict'; | ||
|
||
var _ = require('lodash'), | ||
glob = require('glob'); | ||
glob = require('glob'); | ||
|
||
/** | ||
* Before we begin, lets set the envrionment variable | ||
* We'll Look for a valid NODE_ENV variable and if one cannot be found load the development NODE_ENV | ||
*/ | ||
glob('./config/env/' + process.env.NODE_ENV + '.js', { | ||
sync: true | ||
sync: true | ||
}, function(err, environmentFiles) { | ||
process.env.NODE_ENV = environmentFiles.length ? process.env.NODE_ENV : 'development'; | ||
process.env.NODE_ENV = environmentFiles.length ? process.env.NODE_ENV : 'development'; | ||
}); | ||
|
||
// Load app configurations | ||
module.exports = _.extend( | ||
require('./env/all'), | ||
require('./env/' + process.env.NODE_ENV) || {} | ||
require('./env/all'), | ||
require('./env/' + process.env.NODE_ENV) || {} | ||
); | ||
|
||
/** | ||
* Get the modules JavaScript files | ||
*/ | ||
module.exports.getGlobbedFiles = function(globPatterns, removeRoot) { | ||
// For context switching | ||
var _this = this; | ||
// For context switching | ||
var _this = this; | ||
|
||
// The output array | ||
var output = []; | ||
// URL paths regex | ||
var urlRegex = new RegExp('^(?:[a-z]+:)?//', 'i'); | ||
|
||
// If glob pattern is array so we use each pattern in a recursive way, otherwise we use glob | ||
if (_.isArray(globPatterns)) { | ||
globPatterns.forEach(function(globPattern) { | ||
output = _.union(output, _this.getGlobbedFiles(globPattern, removeRoot)); | ||
}); | ||
} else if (_.isString(globPatterns)) { | ||
glob(globPatterns, { | ||
sync: true | ||
}, function(err, files) { | ||
if (removeRoot) { | ||
files = files.map(function(file) { | ||
return file.replace(removeRoot, ''); | ||
}); | ||
} | ||
// The output array | ||
var output = []; | ||
|
||
output = _.union(output, files); | ||
}); | ||
} | ||
// If glob pattern is array so we use each pattern in a recursive way, otherwise we use glob | ||
if (_.isArray(globPatterns)) { | ||
globPatterns.forEach(function(globPattern) { | ||
output = _.union(output, _this.getGlobbedFiles(globPattern, removeRoot)); | ||
}); | ||
} else if (_.isString(globPatterns)) { | ||
if (urlRegex.test(globPatterns)) { | ||
output.push(globPatterns); | ||
} else { | ||
glob(globPatterns, { | ||
sync: true | ||
}, function(err, files) { | ||
if (removeRoot) { | ||
files = files.map(function(file) { | ||
return file.replace(removeRoot, ''); | ||
}); | ||
} | ||
|
||
return output; | ||
output = _.union(output, files); | ||
}); | ||
} | ||
} | ||
|
||
return output; | ||
}; | ||
|
||
/** | ||
* Get the modules JavaScript files | ||
*/ | ||
module.exports.getJavaScriptAssets = function(includeTests) { | ||
var output = this.getGlobbedFiles(this.assets.lib.concat(this.assets.js), 'public/'); | ||
var output = this.getGlobbedFiles(this.assets.lib.concat(this.assets.js), 'public/'); | ||
|
||
// To include tests | ||
if (includeTests) { | ||
output = _.union(output, this.getGlobbedFiles(this.assets.tests)); | ||
} | ||
// To include tests | ||
if (includeTests) { | ||
output = _.union(output, this.getGlobbedFiles(this.assets.tests)); | ||
} | ||
|
||
return output; | ||
return output; | ||
}; | ||
|
||
/** | ||
* Get the modules CSS files | ||
*/ | ||
module.exports.getCSSAssets = function() { | ||
var output = this.getGlobbedFiles(this.assets.css, 'public/'); | ||
return output; | ||
var output = this.getGlobbedFiles(this.assets.css, 'public/'); | ||
return output; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,130 +1,136 @@ | ||
'use strict'; | ||
|
||
var config = require('./config/config'); | ||
|
||
module.exports = function(grunt) { | ||
// Project Configuration | ||
grunt.initConfig({ | ||
pkg: grunt.file.readJSON('package.json'), | ||
watch: { | ||
serverViews: { | ||
files: ['app/views/**'], | ||
options: { | ||
livereload: true, | ||
} | ||
}, | ||
serverJS: { | ||
files: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js'], | ||
tasks: ['jshint'], | ||
options: { | ||
livereload: true, | ||
} | ||
}, | ||
clientViews: { | ||
files: ['public/modules/**/views/*.html'], | ||
options: { | ||
livereload: true, | ||
} | ||
}, | ||
clientJS: { | ||
files: ['public/js/**/*.js', 'public/modules/**/*.js'], | ||
tasks: ['jshint'], | ||
options: { | ||
livereload: true, | ||
} | ||
}, | ||
clientCSS: { | ||
files: ['public/**/css/*.css'], | ||
tasks: ['csslint'], | ||
options: { | ||
livereload: true, | ||
} | ||
} | ||
}, | ||
jshint: { | ||
all: { | ||
src: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js', 'public/js/**/*.js', 'public/modules/**/*.js'], | ||
options: { | ||
jshintrc: true | ||
} | ||
} | ||
}, | ||
csslint: { | ||
options: { | ||
csslintrc: '.csslintrc', | ||
}, | ||
all: { | ||
src: ['public/modules/**/css/*.css'] | ||
} | ||
}, | ||
uglify: { | ||
production: { | ||
options: { | ||
mangle: false | ||
}, | ||
files: { | ||
'public/dist/application.min.js': config.assets.js | ||
} | ||
} | ||
}, | ||
cssmin: { | ||
combine: { | ||
files: { | ||
'public/dist/application.min.css': config.assets.css | ||
} | ||
} | ||
}, | ||
nodemon: { | ||
dev: { | ||
script: 'server.js', | ||
options: { | ||
nodeArgs: ['--debug'] | ||
} | ||
} | ||
}, | ||
concurrent: { | ||
tasks: ['nodemon', 'watch'], | ||
options: { | ||
logConcurrentOutput: true | ||
} | ||
}, | ||
env: { | ||
test: { | ||
NODE_ENV: 'test' | ||
} | ||
}, | ||
mochaTest: { | ||
src: ['app/tests/**/*.js'], | ||
options: { | ||
reporter: 'spec', | ||
require: 'server.js' | ||
} | ||
}, | ||
karma: { | ||
unit: { | ||
configFile: 'karma.conf.js' | ||
} | ||
} | ||
}); | ||
// Project Configuration | ||
grunt.initConfig({ | ||
pkg: grunt.file.readJSON('package.json'), | ||
watch: { | ||
serverViews: { | ||
files: ['app/views/**'], | ||
options: { | ||
livereload: true, | ||
} | ||
}, | ||
serverJS: { | ||
files: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js'], | ||
tasks: ['jshint'], | ||
options: { | ||
livereload: true, | ||
} | ||
}, | ||
clientViews: { | ||
files: ['public/modules/**/views/*.html'], | ||
options: { | ||
livereload: true, | ||
} | ||
}, | ||
clientJS: { | ||
files: ['public/js/**/*.js', 'public/modules/**/*.js'], | ||
tasks: ['jshint'], | ||
options: { | ||
livereload: true, | ||
} | ||
}, | ||
clientCSS: { | ||
files: ['public/**/css/*.css'], | ||
tasks: ['csslint'], | ||
options: { | ||
livereload: true, | ||
} | ||
} | ||
}, | ||
jshint: { | ||
all: { | ||
src: ['gruntfile.js', 'server.js', 'config/**/*.js', 'app/**/*.js', 'public/js/**/*.js', 'public/modules/**/*.js'], | ||
options: { | ||
jshintrc: true | ||
} | ||
} | ||
}, | ||
csslint: { | ||
options: { | ||
csslintrc: '.csslintrc', | ||
}, | ||
all: { | ||
src: ['public/modules/**/css/*.css'] | ||
} | ||
}, | ||
uglify: { | ||
production: { | ||
options: { | ||
mangle: false | ||
}, | ||
files: { | ||
'public/dist/application.min.js': '<%= applicationJavaScriptFiles %>' | ||
} | ||
} | ||
}, | ||
cssmin: { | ||
combine: { | ||
files: { | ||
'public/dist/application.min.css': '<%= applicationCSSFiles %>' | ||
} | ||
} | ||
}, | ||
nodemon: { | ||
dev: { | ||
script: 'server.js', | ||
options: { | ||
nodeArgs: ['--debug'] | ||
} | ||
} | ||
}, | ||
concurrent: { | ||
tasks: ['nodemon', 'watch'], | ||
options: { | ||
logConcurrentOutput: true | ||
} | ||
}, | ||
env: { | ||
test: { | ||
NODE_ENV: 'test' | ||
} | ||
}, | ||
mochaTest: { | ||
src: ['app/tests/**/*.js'], | ||
options: { | ||
reporter: 'spec', | ||
require: 'server.js' | ||
} | ||
}, | ||
karma: { | ||
unit: { | ||
configFile: 'karma.conf.js' | ||
} | ||
} | ||
}); | ||
|
||
// Load NPM tasks | ||
require('load-grunt-tasks')(grunt); | ||
|
||
// Making grunt default to force in order not to break the project. | ||
grunt.option('force', true); | ||
|
||
//Load NPM tasks | ||
require('load-grunt-tasks')(grunt); | ||
// A Task for loading the configuration object | ||
grunt.task.registerTask('loadConfig', 'Task that loads the config into a grunt option.', function() { | ||
var config = require('./config/config'); | ||
|
||
//Making grunt default to force in order not to break the project. | ||
grunt.option('force', true); | ||
grunt.config.set('applicationJavaScriptFiles', config.assets.js); | ||
grunt.config.set('applicationCSSFiles', config.assets.css); | ||
}); | ||
|
||
//Default task(s). | ||
grunt.registerTask('default', ['jshint', 'csslint', 'concurrent']); | ||
// Default task(s). | ||
grunt.registerTask('default', ['jshint', 'csslint', 'concurrent']); | ||
|
||
//Lint task(s). | ||
grunt.registerTask('lint', ['jshint', 'csslint']); | ||
// Lint task(s). | ||
grunt.registerTask('lint', ['jshint', 'csslint']); | ||
|
||
//Build task(s). | ||
grunt.registerTask('build', ['jshint', 'csslint', 'uglify', 'cssmin']); | ||
// Build task(s). | ||
grunt.registerTask('build', ['jshint', 'csslint', 'loadConfig' ,'uglify', 'cssmin']); | ||
|
||
//Build task(s). | ||
grunt.registerTask('heroku-deploy', ['jshint', 'csslint', 'uglify', 'cssmin']); | ||
// Build task(s). | ||
grunt.registerTask('heroku-deploy', ['jshint', 'csslint', 'uglify', 'cssmin']); | ||
|
||
//Test task. | ||
grunt.registerTask('test', ['env:test', 'mochaTest', 'karma:unit']); | ||
// Test task. | ||
grunt.registerTask('test', ['env:test', 'mochaTest', 'karma:unit']); | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
8cccae2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amoshaviv Not sure if this is the direction you want to go in, but I did make a suggestion to move grunt tasks into the environment specific configurations. That would mean potentially one less file that needed to be changed if you wanted to deploy to different environments.
Here is my suggestion (let me know if it is not OK to link to that site, and I will remove it):
https://github.com/linnovate/mean/pull/413/files