Created
August 9, 2013 02:16
-
-
Save techieBrandon/6190647 to your computer and use it in GitHub Desktop.
local dev CI
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
techieBrandon$ cat Gruntfile.coffee | |
module.exports = (grunt) -> | |
path = require('path') | |
coffeeFiles = | |
'web-app/cs/**/*.coffee': { expand: true, flatten: false, cwd: 'web-app/cs/', src: ['**/*.coffee'], dest: '.grunt/web-app/js/', ext: '.js' } | |
'web-app/coffeeConfig/**/*.coffee': { expand: true, flatten: false, cwd: 'web-app/coffeeConfig/', src: ['**/*.coffee'], dest: '.grunt/web-app/coffeeConfig/', ext: '.js' } | |
'spec/cs/**/*.coffee': { expand: true, flatten: false, cwd: 'spec/cs/', src: ['**/*.coffee'], dest: '.grunt/spec/js/', ext: '.js' } | |
lessFiles = | |
'web-app/less/**/*.less': { expand: true, flatten: false, cwd: 'web-app/less/', src: ['**/*.less'], dest: '.grunt/web-app/css/', ext: '.css' } | |
yamlFiles = | |
'spec/**/*.yml': { expand: true, flatten: false, cwd: 'spec/', src: ['**/*.yml'], dest: '.grunt/spec/' } | |
'spec/**/*.yaml': { expand: true, flatten: false, cwd: 'spec/', src: ['**/*.yaml'], dest: '.grunt/spec/' } | |
coffeeWebAppFileSrc = | |
files: [ | |
coffeeFiles['web-app/cs/**/*.coffee'] | |
] | |
coffeeSpecFileSrc = | |
files: [ | |
coffeeFiles['spec/cs/**/*.coffee'] | |
] | |
coffeeCustomerConfigFileSrc = | |
files: [ | |
coffeeFiles['web-app/coffeeConfig/**/*.coffee'] | |
] | |
lessFileSrc = | |
files: [ | |
lessFiles['web-app/less/**/*.less'] | |
] | |
jasmineYamlFileSrc = | |
files: [ | |
{ expand: true, flatten: false, cwd: 'spec/', src: ['**/*.yaml', '**/*.yml'], dest: 'spec/' } | |
] | |
gruntConfig = | |
pkg: grunt.file.readJSON('package.json') | |
yaml: | |
jasmine: | |
options: | |
space: 2 | |
files: jasmineYamlFileSrc.files | |
coffee: | |
jasmine: | |
options: | |
force: true | |
files: coffeeSpecFileSrc.files | |
customerConfig: | |
options: | |
force: true | |
files: coffeeCustomerConfigFileSrc.files | |
webApp: | |
options: | |
force: true | |
files: coffeeWebAppFileSrc.files | |
watch: | |
options: | |
force: true | |
less: | |
compile: | |
options: | |
dumpLineNumbers: 'all' | |
strictImports: true | |
syncImport: true | |
files: lessFileSrc.files | |
jasmine: | |
options: | |
keepRunner: true | |
csslint: | |
options: | |
csslintrc: '.csslintrc' | |
strict: | |
src: ['web-app/css/'] | |
exec: | |
generateAppResourcesJson: | |
cmd: () -> | |
"grails my-resources --module=specs --dest=.grunt/spec/spec-resources.json" | |
watch: | |
coffeeJasmineSpec: | |
files: 'spec/cs/**/*.coffee' | |
options: | |
nospawn: true | |
debounceDelay: 500 | |
interval: 1000 | |
coffeeCustomerConfig: | |
files: 'web-app/coffeeConfig/**/*.coffee' | |
options: | |
nospawn: true | |
debounceDelay: 500 | |
interval: 1000 | |
coffeeWebApp: | |
files: 'web-app/cs/**/*.coffee' | |
options: | |
nospawn: true | |
debounceDelay: 500 | |
interval: 1000 | |
groovyWebAppResources: | |
files: 'grails-app/conf/ApplicationResources.groovy' | |
tasks: ['exec:generateAppResourcesJson'] | |
jsonWebAppResources: | |
files: '.grunt/spec/spec-resources.json' | |
options: | |
nospawn: true | |
less: | |
files: 'web-app/less/**/*.less' | |
options: | |
nospawn: true | |
debounceDelay: 500 | |
interval: 1000 | |
touch: | |
specResources: ['.grunt/spec'] | |
mkdir: | |
spec: | |
create: ['.grunt/spec'] | |
grunt.initConfig gruntConfig | |
compileLess = (filepath) -> | |
compile(['less','compile'],filepath,lessFiles,['less:compile','jasmine']) | |
compileCoffee = (filepath) -> | |
compile(['coffee','watch'],filepath,coffeeFiles,['coffee:watch','jasmine']) | |
compile = (target, file, contexts, callbacks) -> | |
compile = grunt.config.get(target) | |
for glob of contexts | |
do (glob, contexts) -> | |
if grunt.file.match(glob,file).length > 0 | |
context = contexts[glob] | |
context.src = file.replace(context.cwd, '') | |
compile.files = [context] | |
grunt.config(target, compile) | |
grunt.task.run(callbacks) | |
updateJasmineFiles = (filepath) -> | |
console.log "Determining converted app resource file #{filepath} exists..." | |
unless grunt.file.exists(filepath) | |
console.log "File exists #{grunt.file.exists(filepath)}" | |
console.log grunt.task.run | |
grunt.task.run(['exec:generateAppResourcesJson']) | |
console.log "New app resource file generated." | |
updateJson = grunt.file.readJSON(filepath) | |
resources = updateJson.resources | |
jasmineConfig = | |
src: [] | |
options: | |
keepRunner: true | |
specs: [] | |
vendor: [] | |
helpers: [] | |
styles: [] | |
for resource, i in resources | |
ext = path.extname(resource) | |
if ext is ".less" or ext is ".css" | |
filePath = path.join('web-app',resource) | |
if ext is ".less" | |
filePath = path.join('.grunt',filePath.replace(/\/less\//,"\/css\/").replace(/\.less/,".css")) | |
jasmineConfig.options.styles.push filePath | |
if ext is ".coffee" or ext is ".js" | |
filePath = path.join('web-app',resource) | |
if ext is ".coffee" | |
filePath = path.join('.grunt', filePath.replace(/\/cs\//,"\/js\/").replace(/\.coffee/,".js")) | |
if filePath.match(/\/js\/thirdparty\//) | |
jasmineConfig.options.vendor.push filePath | |
else if filePath.match(/\/spec\//) | |
jasmineConfig.options.specs.push filePath | |
else | |
jasmineConfig.src.push filePath | |
for name, attribute of jasmineConfig | |
if grunt.util._.isArray(attribute) is true | |
jasmineConfig[name] = grunt.util._.uniq(attribute) | |
jasmine = grunt.config.get(['jasmine']) | |
grunt.util._.extend(jasmine, jasmineConfig) | |
grunt.config(['jasmine'], jasmine) | |
console.log jasmine | |
grunt.task.run('jasmine') | |
watchFx = (action,filepath) -> | |
if action? | |
if action == "changed" or action == "added" | |
ext = path.extname(filepath) | |
if ext == ".less" | |
compileLess(filepath) | |
if ext == ".coffee" | |
compileCoffee(filepath) | |
if path.basename(filepath) == "spec-resources.json" | |
updateJasmineFiles(filepath) | |
grunt.event.on 'watch', watchFx | |
grunt.loadNpmTasks 'grunt-exec' | |
grunt.loadNpmTasks 'grunt-yaml' | |
grunt.loadNpmTasks 'grunt-contrib-coffee' | |
grunt.loadNpmTasks 'grunt-contrib-jasmine' | |
grunt.loadNpmTasks 'grunt-contrib-csslint' | |
grunt.loadNpmTasks 'grunt-contrib-watch' | |
grunt.loadNpmTasks 'grunt-contrib-less' | |
grunt.loadNpmTasks 'grunt-touch' | |
grunt.loadNpmTasks 'grunt-mkdir' | |
grunt.registerTask 'compile', ['yaml','less','coffee'] | |
grunt.registerTask 'install', ['compile'] | |
grunt.registerTask 'specRunner', ['compile','jasmine','csslint'] | |
grunt.registerTask 'default', ['specRunner'] | |
grunt.registerTask 'spec', 'Runs test suites', () -> | |
updateJasmineFiles('.grunt/spec/spec-resources.json') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment