tmod.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * grunt-tmod
  3. * https://github.com/jsonzhang/grunt-tmodjs
  4. *
  5. * Copyright (c) 2013 Json
  6. * Licensed under the MIT license.
  7. */
  8. 'use strict';
  9. var TmodJS = require("tmodjs");
  10. module.exports = function(grunt) {
  11. // Please see the Grunt documentation for more information regarding task
  12. // creation: http://gruntjs.com/creating-tasks
  13. var path = require('path');
  14. grunt.registerMultiTask('tmod', 'the grunt plugin for tmodjs', function() {
  15. // Merge task-specific and/or target-specific options with these defaults.
  16. var options = {
  17. output: this.options().dest || this.data.files[0].dest || './build',
  18. charset: this.options().charset || 'utf-8',
  19. debug: this.options().debug||false ,// 此字段不会保存在配置中
  20. watch: this.options().watch || false,
  21. type : this.options().type || "templatejs"
  22. };
  23. var file = this.data.file;
  24. var src;
  25. this.files.forEach(function(f){
  26. if(!f.src[0]){
  27. grunt.fail.warn("src is not be found");
  28. }
  29. var src = f.src.forEach(function(filepath){
  30. TmodJS.init(path.resolve(filepath), options);
  31. TmodJS.compile(file, false);
  32. //TmodJS.watch();
  33. TmodJS.saveUserConfig();
  34. })
  35. });
  36. });
  37. };