grunt.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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_dev: {
  63. working_dir: 'js',
  64. src: ['Kernel-Objects.js', 'Kernel-Classes.js', 'Kernel-Methods.js', 'Kernel-Collections.js',
  65. 'Kernel-Exceptions.js', 'Kernel-Transcript.js', 'Kernel-Announcements.js',
  66. 'Compiler.js', 'Compiler-Exceptions.js', 'Compiler-Core.js', 'Compiler-AST.js',
  67. 'Compiler-IR.js', 'Compiler-Inlining.js', 'Compiler-Semantic.js',
  68. 'Kernel-Tests.js', 'Compiler-Tests.js',
  69. 'Canvas.js', 'IDE.js', 'SUnit.js', 'Documentation.js'],
  70. output_name: 'amber_lib'
  71. },
  72. server: {
  73. working_dir: 'server',
  74. src: ['FileServer.st'],
  75. main_class: 'FileServer',
  76. output_name: 'server'
  77. },
  78. repl: {
  79. working_dir: 'repl',
  80. src: ['REPL.st'],
  81. main_class: 'Repl',
  82. output_name: 'amber'
  83. }
  84. },
  85. lint: {
  86. amber: ['js/*.js'],
  87. server: ['server/*.js'],
  88. repl: ['repl/*.js'],
  89. tests: ['test/*.js'],
  90. grunt: ['grunt.js', 'grunt/**/*.js']
  91. },
  92. concat: {
  93. deploy: {
  94. src: ['tmp/amber-compiled.deploy.js'],
  95. dest: 'dist/amber-<%= pkg.version %>.deploy.js'
  96. },
  97. css: {
  98. src: [
  99. 'css/amber.css',
  100. 'js/lib/CodeMirror/codemirror.css',
  101. 'js/lib/CodeMirror/amber.css'
  102. ],
  103. dest: 'tmp/amber.css'
  104. },
  105. dev: {
  106. src: [
  107. 'js/lib/jQuery/jquery-ui-1.8.16.custom.min.js',
  108. 'js/lib/jQuery/jquery.textarea.js',
  109. 'js/lib/CodeMirror/codemirror.js',
  110. 'js/lib/CodeMirror/smalltalk.js',
  111. 'tmp/amber-compiled.js',
  112. 'tmp/css.js'
  113. ],
  114. dest: 'dist/amber-<%= pkg.version %>.js'
  115. }
  116. },
  117. imageEmbed: {
  118. dev: {
  119. src: ['tmp/amber.css'],
  120. dest: 'tmp/amber-images.css',
  121. options: {baseDir: 'public'}
  122. }
  123. },
  124. mincss: {
  125. dev: {
  126. src: ['tmp/amber-images.css'],
  127. dest: 'tmp/amber.min.css'
  128. }
  129. },
  130. css2js: {
  131. dev: {
  132. src: 'tmp/amber.min.css',
  133. dest: 'tmp/css.js'
  134. }
  135. },
  136. min: {
  137. deploy: {
  138. src: 'dist/amber-<%= pkg.version %>.deploy.js',
  139. dest: 'dist/amber-<%= pkg.version %>.deploy.min.js'
  140. }
  141. }
  142. });
  143. grunt.registerMultiTask('css2js', 'Embed CSS into JS', function() {
  144. var cssContent = grunt.task.directive(grunt.file.expandFiles(this.data.src)[0], grunt.file.read);
  145. var content =
  146. 'var css="' + cssContent + '";' +
  147. 'var cssTag = document.createElement("link");' +
  148. 'document.head = document.head || document.getElementsByTagName("head")[0];' +
  149. 'cssTag.href = "data:text/css,"+css;' +
  150. 'cssTag.rel = "stylesheet";' +
  151. 'document.head.appendChild(cssTag);';
  152. grunt.file.write(this.data.dest, content);
  153. grunt.log.writeln('File "' + this.data.dest + '" created.');
  154. });
  155. grunt.registerMultiTask('pegjs', 'Generate JavaScript parser from PEG.js description', function() {
  156. var PEG = require('pegjs');
  157. var pegOptions = {
  158. cache: this.data.cache || false,
  159. trackLineAndColumn: this.data.trackLineAndColumn || false
  160. };
  161. var export_var = this.data.export_var || 'module.exports';
  162. var parser = PEG.buildParser(grunt.file.read(this.data.src), pegOptions);
  163. var content = export_var + ' = ' + parser.toSource() + ';\n';
  164. grunt.file.write(this.data.dest, content);
  165. });
  166. };