Skip to content

Instantly share code, notes, and snippets.

@techieBrandon
Created August 9, 2013 03:04
Show Gist options
  • Save techieBrandon/6190878 to your computer and use it in GitHub Desktop.
Save techieBrandon/6190878 to your computer and use it in GitHub Desktop.
Local dev CI problem focus
techieBrandon$ cat Gruntfile.coffee
module.exports = (grunt) ->
path = require('path')
gruntConfig =
pkg: grunt.file.readJSON('package.json')
exec:
generateAppResourcesJson:
cmd: () ->
"grails my-resources --module=specs --dest=.grunt/spec/spec-resources.json"
watch:
groovyWebAppResources:
files: 'grails-app/conf/ApplicationResources.groovy'
tasks: ['exec:generateAppResourcesJson']
grunt.initConfig gruntConfig
updateJasmineFiles = (filepath) ->
console.log "Determining converted app resource file #{filepath} exists..."
unless grunt.file.exists(filepath)
console.log "File exists #{grunt.file.exists(filepath)}"
exec = grunt.config.get('exec:generateAppResourcesJson')
grunt.config(exec)
grunt.task.run('exec:generateAppResourcesJson')
console.log "New app resource file generated."
updateJson = grunt.file.readJSON(filepath)
watchFx = (action,filepath) ->
if action?
if action == "changed" or action == "added"
if path.basename(filepath) == "spec-resources.json"
updateJasmineFiles(filepath)
grunt.event.on 'watch', watchFx
grunt.loadNpmTasks 'grunt-exec'
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.registerTask 'spec', 'Runs test suites', () =>
updateJasmineFiles('.grunt/spec/spec-resources.json')
@vladikoff
Copy link

techieBrandon$(cat(Gruntfile.coffee));

module.exports = function(grunt) {
  var gruntConfig, path, updateJasmineFiles, watchFx,
    _this = this;
  path = require('path');
  gruntConfig = {
    pkg: grunt.file.readJSON('package.json'),
    exec: {
      generateAppResourcesJson: {
        cmd: function() {
          return "grails my-resources --module=specs --dest=.grunt/spec/spec-resources.json";
        }
      }
    },
    watch: {
      groovyWebAppResources: {
        files: 'grails-app/conf/ApplicationResources.groovy',
        tasks: ['exec:generateAppResourcesJson']
      }
    }
  };
  grunt.initConfig(gruntConfig);
  updateJasmineFiles = function(filepath) {
    var exec, updateJson;
    console.log("Determining converted app resource file " + filepath + " exists...");
    if (!grunt.file.exists(filepath)) {
      console.log("File exists " + (grunt.file.exists(filepath)));
      exec = grunt.config.get('exec:generateAppResourcesJson');
      grunt.config(exec);
      grunt.task.run('exec:generateAppResourcesJson');
      console.log("New app resource file generated.");
    }
    return updateJson = grunt.file.readJSON(filepath);
  };
  watchFx = function(action, filepath) {
    if (action != null) {
      if (action === "changed" || action === "added") {
        if (path.basename(filepath) === "spec-resources.json") {
          return updateJasmineFiles(filepath);
        }
      }
    }
  };
  grunt.event.on('watch', watchFx);
  grunt.loadNpmTasks('grunt-exec');
  grunt.loadNpmTasks('grunt-contrib-watch');
  return grunt.registerTask('spec', 'Runs test suites', function() {
    return updateJasmineFiles('.grunt/spec/spec-resources.json');
  });
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment