grunt.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. module.exports = function(grunt) {
  2. grunt.loadTasks('./grunt/tasks');
  3. grunt.loadNpmTasks('grunt-image-embed');
  4. grunt.loadNpmTasks('grunt-contrib-mincss');
  5. grunt.registerTask('default', 'pegjs amberc:all');
  6. grunt.initConfig({
  7. pkg: '<json:package.json>',
  8. meta: {
  9. banner: '/*!\n <%= pkg.title || pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> \n License: <%= pkg.license.type %> \n*/\n'
  10. },
  11. pegjs: {
  12. amber_parser: {
  13. src: 'js/parser.pegjs',
  14. dest: 'js/parser.js',
  15. trackLineAndColumn: true,
  16. cache: true,
  17. export_var: 'smalltalk.parser'
  18. }
  19. },
  20. amberc: {
  21. _config: {
  22. amber_dir: process.cwd(),
  23. closure_jar: ''
  24. },
  25. all: {
  26. working_dir: 'st',
  27. target_dir : 'js',
  28. src: ['Kernel-Objects.st', 'Kernel-Classes.st', 'Kernel-Methods.st', 'Kernel-Collections.st',
  29. 'Kernel-Exceptions.st', 'Kernel-Transcript.st', 'Kernel-Announcements.st',
  30. 'Importer-Exporter.st', 'Compiler-Exceptions.st', 'Compiler-Core.st', 'Compiler-AST.st',
  31. 'Compiler-IR.st', 'Compiler-Inlining.st', 'Compiler-Semantic.st',
  32. 'Canvas.st', 'SUnit.st', 'IDE.st',
  33. 'Kernel-Tests.st', 'Compiler-Tests.st', 'SUnit-Tests.st'
  34. ],
  35. deploy: true
  36. },
  37. amber_kernel: {
  38. working_dir: 'st',
  39. target_dir : 'js',
  40. src: ['Kernel-Objects.st', 'Kernel-Classes.st', 'Kernel-Methods.st', 'Kernel-Collections.st',
  41. 'Kernel-Exceptions.st', 'Kernel-Transcript.st', 'Kernel-Announcements.st'],
  42. deploy: true
  43. },
  44. amber_compiler: {
  45. working_dir: 'st',
  46. target_dir : 'js',
  47. src: ['Importer-Exporter.st', 'Compiler-Exceptions.st', 'Compiler-Core.st', 'Compiler-AST.st',
  48. 'Compiler-IR.st', 'Compiler-Inlining.st', 'Compiler-Semantic.st'],
  49. output_name: 'Compiler',
  50. deploy: true
  51. },
  52. amber_canvas: {
  53. working_dir: 'st',
  54. target_dir : 'js',
  55. src: ['Canvas.st', 'SUnit.st'],
  56. deploy: true
  57. },
  58. amber_IDE: {
  59. working_dir: 'st',
  60. target_dir : 'js',
  61. src: ['IDE.st'],
  62. libraries: ['Canvas'],
  63. deploy: true
  64. },
  65. amber_tests: {
  66. working_dir: 'st',
  67. target_dir : 'js',
  68. src: ['Kernel-Tests.st', 'Compiler-Tests.st', 'SUnit-Tests.st'],
  69. libraries: ['SUnit']
  70. },
  71. amber_test_runner: {
  72. working_dir: 'test',
  73. src: ['Test.st'],
  74. libraries: [
  75. 'Compiler-Exceptions', 'Compiler-Core', 'Compiler-AST',
  76. 'Compiler-IR', 'Compiler-Inlining', 'Compiler-Semantic', 'Compiler-Interpreter', 'parser',
  77. 'SUnit',
  78. 'Kernel-Tests', 'Compiler-Tests', 'SUnit-Tests'],
  79. output_name: 'run'
  80. },
  81. amber_dev: {
  82. working_dir: 'js',
  83. src: [
  84. 'Compiler-Exceptions.js', 'Compiler-Core.js', 'Compiler-AST.js',
  85. 'Compiler-IR.js', 'Compiler-Inlining.js', 'Compiler-Semantic.js',
  86. 'Canvas.js', 'IDE.js', 'SUnit.js',
  87. 'Kernel-Tests.js', 'Compiler-Tests.js', 'SUnit-Tests.js'],
  88. output_name: 'amber_dev'
  89. },
  90. server: {
  91. working_dir: 'server',
  92. src: ['FileServer.st'],
  93. main_class: 'FileServer',
  94. output_name: 'server'
  95. },
  96. repl: {
  97. working_dir: 'repl',
  98. src: ['REPL.st'],
  99. main_class: 'Repl',
  100. output_name: 'amber'
  101. }
  102. },
  103. lint: {
  104. amber: ['js/*.js'],
  105. server: ['server/*.js'],
  106. repl: ['repl/*.js'],
  107. tests: ['test/*.js'],
  108. grunt: ['grunt.js', 'grunt/**/*.js']
  109. },
  110. /*
  111. concat: {
  112. deploy: {
  113. src: ['tmp/amber-compiled.deploy.js'],
  114. dest: 'dist/amber-<%= pkg.version %>.deploy.js'
  115. },
  116. css: {
  117. src: [
  118. 'css/amber.css',
  119. 'js/lib/CodeMirror/codemirror.css',
  120. 'js/lib/CodeMirror/amber.css'
  121. ],
  122. dest: 'tmp/amber.css'
  123. },
  124. dev: {
  125. src: [
  126. 'js/lib/jQuery/jquery-ui-1.8.16.custom.min.js',
  127. 'js/lib/jQuery/jquery.textarea.js',
  128. 'js/lib/CodeMirror/codemirror.js',
  129. 'js/lib/CodeMirror/smalltalk.js',
  130. 'tmp/amber-compiled.js',
  131. 'tmp/css.js'
  132. ],
  133. dest: 'dist/amber-<%= pkg.version %>.js'
  134. }
  135. },
  136. imageEmbed: {
  137. dev: {
  138. src: ['tmp/amber.css'],
  139. dest: 'tmp/amber-images.css',
  140. options: {baseDir: 'public'}
  141. }
  142. },
  143. mincss: {
  144. dev: {
  145. src: ['tmp/amber-images.css'],
  146. dest: 'tmp/amber.min.css'
  147. }
  148. },
  149. css2js: {
  150. dev: {
  151. src: 'tmp/amber.min.css',
  152. dest: 'tmp/css.js'
  153. }
  154. },
  155. min: {
  156. deploy: {
  157. src: 'dist/amber-<%= pkg.version %>.deploy.js',
  158. dest: 'dist/amber-<%= pkg.version %>.deploy.min.js'
  159. }
  160. }
  161. */
  162. });
  163. grunt.registerMultiTask('css2js', 'Embed CSS into JS', function() {
  164. var cssContent = grunt.task.directive(grunt.file.expandFiles(this.data.src)[0], grunt.file.read);
  165. var content =
  166. 'var css="' + cssContent + '";' +
  167. 'var cssTag = document.createElement("link");' +
  168. 'document.head = document.head || document.getElementsByTagName("head")[0];' +
  169. 'cssTag.href = "data:text/css,"+css;' +
  170. 'cssTag.rel = "stylesheet";' +
  171. 'document.head.appendChild(cssTag);';
  172. grunt.file.write(this.data.dest, content);
  173. grunt.log.writeln('File "' + this.data.dest + '" created.');
  174. });
  175. grunt.registerMultiTask('pegjs', 'Generate JavaScript parser from PEG.js description', function() {
  176. var PEG = require('pegjs');
  177. var pegOptions = {
  178. cache: this.data.cache || false,
  179. trackLineAndColumn: this.data.trackLineAndColumn || false
  180. };
  181. var export_var = this.data.export_var || 'module.exports';
  182. var parser = PEG.buildParser(grunt.file.read(this.data.src), pegOptions);
  183. var content = export_var + ' = ' + parser.toSource() + ';\n';
  184. grunt.file.write(this.data.dest, content);
  185. });
  186. };