2
0

Gruntfile.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * Copyright 2018 Scytl Secure Electronic Voting SA
  3. *
  4. * All rights reserved
  5. *
  6. * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package
  7. */
  8. module.exports = function(grunt) {
  9. 'use strict';
  10. var config = {};
  11. config.pkg = grunt.file.readJSON('package.json');
  12. var xml = grunt.file.read('pom.xml').toString('UTF-8');
  13. var DOMParser = require('xmldom').DOMParser;
  14. var pom = new DOMParser().parseFromString(xml, 'text/xml');
  15. var versionElement = pom.documentElement.getElementsByTagName('version')[0];
  16. var version = versionElement.textContent;
  17. if (version.endsWith('SNAPSHOT')) {
  18. version += '.' + Date.now();
  19. }
  20. config.pkg.version = version;
  21. delete config.pkg.devDependencies;
  22. delete config.pkg.private;
  23. config.clean = {target: ['target']};
  24. config.compile = {
  25. config: ['Gruntfile.js', 'karma.conf.js', 'banner.js'],
  26. lib: ['lib/*.js'],
  27. spec: ['spec/*.js'],
  28. options: {jshintrc: true}
  29. };
  30. config.test = {
  31. options: {
  32. configFile: 'karma.conf.js',
  33. files: [
  34. 'node_modules/node-forge/dist/forge.min.js',
  35. 'node_modules/sjcl/sjcl.js',
  36. 'lib/cryptolib.js',
  37. 'lib/**/*.js',
  38. 'spec/cryptolib.spec.js',
  39. 'spec/proofs.service/proofs.service.spec.lib.js',
  40. ]
  41. },
  42. asymmetric: {
  43. files: [
  44. {src: ['spec/asymmetric*.spec.js'], served: true},
  45. ]
  46. },
  47. certificates: {
  48. files: [
  49. {src: ['spec/certificates*.spec.js'], served: true},
  50. ]
  51. },
  52. commons: {
  53. files: [
  54. {src: ['spec/commons*.spec.js'], served: true},
  55. ]
  56. },
  57. crypto: {
  58. files: [
  59. {src: ['spec/crypto*.spec.js'], served: true},
  60. ]
  61. },
  62. digitalenvelope: {
  63. files: [
  64. {src: ['spec/digitalenvelope*.spec.js'], served: true},
  65. ]
  66. },
  67. homomorphic: {
  68. files: [
  69. {src: ['spec/homomorphic*.spec.js'], served: true},
  70. ]
  71. },
  72. primitives: {
  73. files: [
  74. {src: ['spec/primitives*.spec.js'], served: true},
  75. ]
  76. },
  77. proofs: {
  78. files: [
  79. {src: ['spec/proofs.spec.js'], served: true},
  80. ]
  81. },
  82. proofs_service_exponentiation: {
  83. files: [
  84. {
  85. src: ['spec/proofs.service/proofs.service.exponentiation.spec.js'],
  86. served: true
  87. },
  88. ]
  89. },
  90. proofs_service_plaintext: {
  91. files: [
  92. {
  93. src: ['spec/proofs.service/proofs.service.plaintext.spec.js'],
  94. served: true
  95. },
  96. ]
  97. },
  98. proofs_service_plaintext_equality: {
  99. files: [
  100. {
  101. src:
  102. ['spec/proofs.service/proofs.service.plaintext_equality.spec.js'],
  103. served: true
  104. },
  105. ]
  106. },
  107. proofs_service_plaintext_exponent_equality: {
  108. files: [
  109. {
  110. src: [
  111. 'spec/proofs.service/proofs.service.plaintext_exponent_equality.spec.js'
  112. ],
  113. served: true
  114. },
  115. ]
  116. },
  117. proofs_service_schnorr: {
  118. files: [
  119. {
  120. src: ['spec/proofs.service/proofs.service.schnorr.spec.js'],
  121. served: true
  122. },
  123. ]
  124. },
  125. proofs_service_simple_plaintext_equality: {
  126. files: [
  127. {
  128. src: [
  129. 'spec/proofs.service/proofs.service.simple_plaintext_equality.spec.js'
  130. ],
  131. served: true
  132. },
  133. ]
  134. },
  135. proofs_service_or: {
  136. files: [
  137. {src: ['spec/proofs.service/proofs.service.or.spec.js'], served: true},
  138. ]
  139. },
  140. stores: {
  141. files: [
  142. {src: ['spec/stores*.spec.js'], served: true},
  143. ]
  144. },
  145. symmetric: {
  146. files: [
  147. {src: ['spec/symmetric*.spec.js'], served: true},
  148. ]
  149. }
  150. };
  151. var banner = grunt.file.read('banner.js').toString('UTF-8');
  152. config.concat = {
  153. all: {
  154. src: ['lib/cryptolib.js', 'lib/*.js'],
  155. dest: 'target/package/lib/<%= pkg.name %>.js'
  156. },
  157. options: {banner: banner}
  158. };
  159. config.uglify = {
  160. all: {
  161. files: {
  162. 'target/package/lib/<%= pkg.name %>.min.js':
  163. ['target/package/lib/<%= pkg.name %>.js']
  164. }
  165. },
  166. options: {banner: banner}
  167. };
  168. config.copy = {
  169. all: {
  170. files: [
  171. {src: '*.md', dest: 'target/package/'},
  172. {src: 'vendor/*.js', dest: 'target/package/'}
  173. ]
  174. }
  175. };
  176. config.run = {
  177. pack: {exec: 'npm pack package/', options: {cwd: 'target'}},
  178. publish: {exec: 'npm publish --dd <%= pkg.name %>-<%= pkg.version %>.tgz', options: {cwd: 'target'}},
  179. format: {
  180. exec:
  181. 'node node_modules/clang-format -style=Google -i lib/*.js spec/*.js spec/**/*.js Gruntfile.js karma.conf.js'
  182. }
  183. };
  184. grunt.initConfig(config);
  185. grunt.loadNpmTasks('grunt-contrib-clean');
  186. grunt.loadNpmTasks('grunt-contrib-jshint');
  187. grunt.loadNpmTasks('grunt-karma');
  188. grunt.loadNpmTasks('grunt-contrib-concat');
  189. grunt.loadNpmTasks('grunt-contrib-uglify');
  190. grunt.loadNpmTasks('grunt-contrib-copy');
  191. grunt.loadNpmTasks('grunt-run');
  192. grunt.renameTask('jshint', 'compile');
  193. grunt.renameTask('karma', 'test');
  194. grunt.registerTask('compose', function() {
  195. var json = JSON.stringify(config.pkg, null, 4);
  196. grunt.file.write('target/package/package.json', json);
  197. });
  198. grunt.registerTask(
  199. 'package', ['compose', 'concat', 'uglify', 'copy', 'run:pack']);
  200. grunt.registerTask('deploy', ['package', 'run:publish']);
  201. grunt.registerTask('default', ['clean', 'compile', 'test', 'package']);
  202. grunt.registerTask('format', ['run:format']);
  203. };