1
0

grunt.js 5.6 KB

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