Grunt + angular gettext: how to extract and/or compile continuously?

1.6k views Asked by At

I am using grunt and grunt-angular-gettext with my angularJS project.
I would like to let grunt run grunt task nggettext_extract whenever a source file is updated, and nggettext_compile whenever a 'po' file is updated.
I thought I could just add the tasks names to my 'grunt.task.run' tasks list, this way:

...
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
  grunt.task.run([
    'nggettext_extract', <== added task, just executed on the first run
    'nggettext_compile', <== added task, just executed on the first run
    'clean:server',
    'wiredep',
    'concurrent:server',
    'autoprefixer',
    'connect:livereload',
    'watch'
  ]);
});
...

but unfortunately this works only for the first grunt run, and not afterwards... It would even be acceptable for me to have both tasks run whenever any file changes in my project (I am not sure how to specify dependencies within Gruntfile.js, I'm quite new with it... :-().

If it can be of any help, these are my nggettext_ tasks configurations (quite standard):

   ...

   nggettext_extract: {
      pot: {
        files: {
          'po/template.pot': [ 'app/**/*.html', 'app/scripts/**/*.js' ]
        }
      }
    },

    nggettext_compile: {
      all: {
        files: {
          'app/scripts/translations.js': ['po/*.po']
        }
      }
    },

    ...
1

There are 1 answers

1
Austin Thompson On BEST ANSWER

I think something similar to this in your gruntfile should work:

 ...
 watch: {
  po-changed: {
    files: ["po/*.po"],
    tasks: ["nggettext_compile"],
  },
  update-pot: {
    files: ['app/**/*.html', 'app/scripts/**/*.js'],
    tasks: ["nggettext_extract"],
  },
 },
 ...