GruntFile.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // GruntFile for building the final compiled files from the core.
  2. // Run using NodeJS and the Grunt module
  3. var fs = require("fs");
  4. var dirs = {
  5. core: "src/core",
  6. i18n: "src/i18n",
  7. build: "build"
  8. };
  9. var getI18NFiles = function () {
  10. return fs.readdirSync(dirs.i18n);
  11. };
  12. var buildMinifyFileList = function (dev) {
  13. var output_path = dev ? "" : "production/";
  14. var output_ext = dev ? "." : ".min.";
  15. var files = getI18NFiles();
  16. var output = {};
  17. files.map(function(item){
  18. var file_core_name = "date-" + item.replace(".js", "");
  19. var dest = dirs.build + "/"+output_path + file_core_name + output_ext + "js";
  20. output[dest] = [dirs.build + "/" + file_core_name + ".js"];
  21. return dest;
  22. });
  23. output[dirs.build + "/"+output_path + "date"+output_ext+"js"] = [dirs.build + "/" + "date.js"];
  24. return output;
  25. };
  26. var banner = "/** \n" +
  27. " * @overview <%= pkg.name %>\n" +
  28. " * @version <%= pkg.version %>\n" +
  29. " * @author <%= pkg.author.name %> <<%= pkg.author.email %>>\n" +
  30. " * @copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>\n" +
  31. " * @license <%= pkg.license %>\n" +
  32. " * @homepage <%= pkg.homepage %>\n" +
  33. " */";
  34. module.exports = function(grunt) {
  35. // Project configuration.
  36. grunt.initConfig({
  37. pkg: grunt.file.readJSON("package.json"),
  38. dirs: dirs,
  39. build_dev: {
  40. description: "Builds files designed for easy debugging on dev enviroments (non-minified)"
  41. },
  42. build_prod: {
  43. description: "Builds production ready files (minified)"
  44. },
  45. closurecompiler: {
  46. minify: {
  47. files: buildMinifyFileList(),
  48. options: {
  49. "compilation_level": "SIMPLE_OPTIMIZATIONS",
  50. "max_processes": 5,
  51. "banner": banner
  52. }
  53. }
  54. },
  55. concat: {
  56. options: {
  57. separator: "\n",
  58. banner: banner,
  59. nonull: true
  60. },
  61. core: {
  62. src: [
  63. "<%= dirs.core %>/i18n.js",
  64. "<%= dirs.core %>/core.js",
  65. "<%= dirs.core %>/core-prototypes.js",
  66. "<%= dirs.core %>/sugarpak.js",
  67. "<%= dirs.core %>/format_parser.js",
  68. "<%= dirs.core %>/parsing_operators.js",
  69. "<%= dirs.core %>/parsing_translator.js",
  70. "<%= dirs.core %>/parsing_grammar.js",
  71. "<%= dirs.core %>/parser.js",
  72. "<%= dirs.core %>/extras.js",
  73. "<%= dirs.core %>/time_span.js",
  74. "<%= dirs.core %>/time_period.js"
  75. ],
  76. dest: "<%= dirs.build %>/date-core.js"
  77. },
  78. basic: {
  79. src: [
  80. "<%= dirs.core %>/i18n.js",
  81. "<%= dirs.core %>/core.js",
  82. "<%= dirs.core %>/core-prototypes.js",
  83. "<%= dirs.core %>/sugarpak.js",
  84. "<%= dirs.core %>/format_parser.js",
  85. "<%= dirs.core %>/parsing_operators.js",
  86. "<%= dirs.core %>/parsing_translator.js",
  87. "<%= dirs.core %>/parsing_grammar.js",
  88. "<%= dirs.core %>/parser.js",
  89. "<%= dirs.core %>/extras.js",
  90. "<%= dirs.core %>/time_span.js",
  91. "<%= dirs.core %>/time_period.js"
  92. ],
  93. dest: "<%= dirs.build %>/date.js"
  94. }
  95. },
  96. i18n: {
  97. core: {
  98. core: "<%= dirs.build %>/date-core.js",
  99. src: ["<%= dirs.i18n %>/*.js"],
  100. dest: "<%= dirs.build %>/" // destination *directory*, probably better than specifying same file names twice
  101. }
  102. },
  103. shell: {
  104. updateCodeClimate: {
  105. command: "codeclimate < reports/lcov.info",
  106. options: {
  107. stdout: true,
  108. stderr: true,
  109. failOnError: true
  110. }
  111. }
  112. },
  113. jasmine : {
  114. src : [
  115. "src/core/i18n.js",
  116. "src/core/core.js",
  117. "src/core/core-prototypes.js",
  118. "src/core/sugarpak.js",
  119. "src/core/format_parser.js",
  120. "src/core/parsing_operators.js",
  121. "src/core/parsing_translator.js",
  122. "src/core/parsing_grammar.js",
  123. "src/core/parser.js",
  124. "src/core/extras.js",
  125. "src/core/time_period.js",
  126. "src/core/time_span.js"
  127. ],
  128. options : {
  129. specs : "specs/*-spec.js",
  130. template : require("grunt-template-jasmine-istanbul"),
  131. templateOptions: {
  132. template: "specs/jasmine-2.0.3/specrunner.tmpl",
  133. coverage: "reports/coverage.json",
  134. report: {
  135. type: "lcov",
  136. options: {
  137. replace: true,
  138. dir: "reports/"
  139. }
  140. }
  141. }
  142. }
  143. },
  144. });
  145. grunt.registerMultiTask("i18n", "Wraps DateJS core with Internationalization info.", function() {
  146. var data = this.data,
  147. path = require("path"),
  148. dest = grunt.template.process(data.dest),
  149. files = grunt.file.expand(data.src),
  150. core = grunt.file.read(grunt.template.process(data.core)),
  151. sep = grunt.util.linefeed,
  152. banner_compiled = grunt.template.process(banner);
  153. files.forEach(function(f) {
  154. var p = dest + "/" + "date-" + path.basename(f),
  155. contents = grunt.file.read(f);
  156. grunt.file.write(p, banner_compiled + sep + contents + sep + core );
  157. grunt.log.writeln("File \"" + p + "\" created.");
  158. });
  159. grunt.file.delete(dirs.build+"/date-core.js");
  160. });
  161. grunt.registerMultiTask("build_dev", "Builds compiled, non-minfied, files for development enviroments", function() {
  162. grunt.task.run(["concat:core", "concat:basic", "i18n:core"]);
  163. });
  164. grunt.registerMultiTask("build_prod", "Rebuilds dev and minifies files for production enviroments", function() {
  165. grunt.task.run(["concat:core", "concat:basic", "i18n:core", "closurecompiler:minify"]);
  166. });
  167. grunt.loadNpmTasks("grunt-contrib-jasmine");
  168. // now set the default
  169. grunt.registerTask("default", ["build_dev"]);
  170. // Load the plugin that provides the "minify" task.
  171. grunt.loadNpmTasks("grunt-shell");
  172. grunt.loadNpmTasks("grunt-closurecompiler");
  173. grunt.loadNpmTasks("grunt-contrib-concat");
  174. grunt.registerTask("test", ["jasmine", "shell:updateCodeClimate"]);
  175. };