Gruntfile.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. var child_process = require('child_process');
  2. var util = require('util');
  3. module.exports = function(grunt) {
  4. 'use strict';
  5. var bower = grunt.file.readJSON('bower.json');
  6. var components = [];
  7. for (var i in bower.concat.app) {
  8. components.push('components/' + bower.concat.app[i] + '/**/*.js');
  9. }
  10. var libcomponents = [];
  11. for (i in bower.concat.lib) {
  12. libcomponents.push('components/' + bower.concat.lib[i] + '/**/*.js');
  13. }
  14. grunt.initConfig({
  15. pkg: grunt.file.readJSON('package.json'),
  16. concat: {
  17. components: {
  18. src: components,
  19. dest: 'js/components.js',
  20. },
  21. libcomponents: {
  22. src: libcomponents,
  23. dest: 'libtextsecure/components.js',
  24. },
  25. curve25519: {
  26. src: [
  27. 'build/curve25519_compiled.js',
  28. 'build/curve25519.js',
  29. ],
  30. dest: 'libtextsecure/curve25519_concat.js',
  31. options: {
  32. banner: ';(function(){\n',
  33. footer: '\n})();'
  34. }
  35. },
  36. webcrypto: {
  37. src: [
  38. 'components/cryptojs/src/core.js',
  39. 'components/cryptojs/src/sha256.js',
  40. 'components/cryptojs/src/hmac.js',
  41. 'components/cryptojs/src/enc-base64.js',
  42. 'components/cryptojs/src/md5.js',
  43. 'components/cryptojs/src/evpkdf.js',
  44. 'components/cryptojs/src/cipher-core.js',
  45. 'components/cryptojs/src/aes.js',
  46. 'build/webcrypto.js'
  47. ],
  48. dest: 'libtextsecure/webcrypto_concat.js',
  49. options: {
  50. banner: ';(function(){\n',
  51. footer: '\n})();'
  52. }
  53. },
  54. test: {
  55. src: [
  56. 'components/mocha/mocha.js',
  57. 'components/chai/chai.js',
  58. 'test/_test.js'
  59. ],
  60. dest: 'test/test.js',
  61. },
  62. libtextsecure: {
  63. src: [
  64. 'libtextsecure/curve25519_concat.js',
  65. 'libtextsecure/webcrypto_concat.js',
  66. 'libtextsecure/protobufs.js',
  67. 'libtextsecure/websocket.js',
  68. 'libtextsecure/websocket-resources.js',
  69. 'libtextsecure/helpers.js',
  70. 'libtextsecure/errors.js',
  71. 'libtextsecure/stringview.js',
  72. 'libtextsecure/storage.js',
  73. 'libtextsecure/storage/devices.js',
  74. 'libtextsecure/storage/groups.js',
  75. 'libtextsecure/api.js',
  76. 'libtextsecure/crypto.js',
  77. 'libtextsecure/protocol.js',
  78. 'libtextsecure/sendmessage.js',
  79. ],
  80. dest: 'js/libtextsecure.js',
  81. },
  82. libtextsecuretest: {
  83. src: [
  84. 'components/mocha/mocha.js',
  85. 'components/chai/chai.js',
  86. 'libtextsecure/test/_test.js'
  87. ],
  88. dest: 'libtextsecure/test/test.js',
  89. }
  90. },
  91. sass: {
  92. stylesheets: {
  93. files: {
  94. 'stylesheets/manifest.css': 'stylesheets/manifest.scss'
  95. }
  96. }
  97. },
  98. compile: {
  99. curve25519_compiled: {
  100. src_files: [
  101. 'native/ed25519/additions/*.c',
  102. 'native/curve25519-donna.c',
  103. 'native/ed25519/*.c',
  104. 'native/ed25519/sha512/sha2big.c'
  105. ],
  106. methods: [
  107. 'curve25519_donna',
  108. 'curve25519_sign',
  109. 'curve25519_verify',
  110. 'crypto_sign_ed25519_ref10_ge_scalarmult_base',
  111. 'sph_sha512_init',
  112. 'malloc',
  113. 'free'
  114. ]
  115. }
  116. },
  117. jshint: {
  118. files: ['Gruntfile.js'], // add 'src/**/*.js', 'test/**/*.js'
  119. options: { jshintrc: '.jshintrc' },
  120. },
  121. jscs: {
  122. all: {
  123. src: ['js/**/*.js', '!js/components.js', 'test/**/*.js']
  124. }
  125. },
  126. watch: {
  127. files: ['<%= jshint.files %>', './js/**/*.js', './stylesheets/**/!(manifest.css)'],
  128. tasks: ['jshint', 'sass']
  129. },
  130. connect: {
  131. server: {
  132. options: {
  133. base: '.',
  134. port: 9999
  135. }
  136. }
  137. },
  138. 'saucelabs-mocha': {
  139. all: {
  140. options: {
  141. urls: ['http://127.0.0.1:9999/test/index.html', 'http://127.0.0.1:9999/libtextsecure/test/index.html'],
  142. build: process.env.TRAVIS_JOB_ID,
  143. browsers: [{ browserName: 'chrome', version: '38' }, { browserName: 'firefox', version: '34' }],
  144. testname: 'TextSecure-Browser Tests'
  145. }
  146. }
  147. }
  148. });
  149. Object.keys(grunt.config.get('pkg').devDependencies).forEach(function(key) {
  150. if (/^grunt(?!(-cli)?$)/.test(key)) { // ignore grunt and grunt-cli
  151. grunt.loadNpmTasks(key);
  152. }
  153. });
  154. grunt.registerMultiTask('compile', 'Compile the C libraries with emscripten.', function() {
  155. var callback = this.async();
  156. var outfile = 'build/' + this.target + '.js';
  157. var exported_functions = this.data.methods.map(function(name) {
  158. return "'_" + name + "'";
  159. });
  160. var flags = [
  161. '-O2',
  162. '-Qunused-arguments',
  163. '-o', outfile,
  164. '-Inative/ed25519/nacl_includes -Inative/ed25519 -Inative/ed25519/sha512',
  165. '-s', "EXPORTED_FUNCTIONS=\"[" + exported_functions.join(',') + "]\""];
  166. var command = [].concat('emcc', this.data.src_files, flags).join(' ');
  167. grunt.log.writeln('Compiling via emscripten to ' + outfile);
  168. var exitCode = 0;
  169. grunt.verbose.subhead(command);
  170. grunt.verbose.writeln(util.format('Expecting exit code %d', exitCode));
  171. var child = child_process.exec(command);
  172. child.stdout.on('data', function (d) { grunt.log.write(d); });
  173. child.stderr.on('data', function (d) { grunt.log.error(d); });
  174. child.on('exit', function(code) {
  175. if (code !== exitCode) {
  176. grunt.log.error(util.format('Exited with code: %d.', code));
  177. return callback(false);
  178. }
  179. grunt.verbose.ok(util.format('Exited with code: %d.', code));
  180. callback(true);
  181. });
  182. });
  183. grunt.registerTask('dev', ['connect', 'watch', 'sass']);
  184. grunt.registerTask('test', ['jshint', 'jscs', 'connect', 'saucelabs-mocha']);
  185. grunt.registerTask('default', ['preen', 'concat', 'sass']);
  186. grunt.registerTask('build', ['compile', 'concat:curve25519', 'concat:libtextsecure']);
  187. };