2014-10-31 07:40:00 +00:00
|
|
|
'use strict';
|
2014-11-08 01:55:33 +00:00
|
|
|
var child_process = require('child_process');
|
|
|
|
var util = require('util');
|
2014-10-31 07:40:00 +00:00
|
|
|
|
2014-10-30 01:32:29 +00:00
|
|
|
module.exports = function(grunt) {
|
2014-10-31 00:57:37 +00:00
|
|
|
var bower = grunt.file.readJSON('bower.json');
|
2014-10-30 01:32:29 +00:00
|
|
|
var components = [];
|
2014-10-31 07:40:00 +00:00
|
|
|
for (var i in bower.concat.app) {
|
2014-10-31 00:57:37 +00:00
|
|
|
components.push('components/' + bower.concat.app[i] + '/**/*.js');
|
2014-10-30 01:32:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
grunt.initConfig({
|
|
|
|
concat: {
|
|
|
|
components: {
|
|
|
|
src: components,
|
2014-10-30 23:53:08 +00:00
|
|
|
dest: 'js/components.js',
|
2014-10-30 01:32:29 +00:00
|
|
|
},
|
2014-11-01 03:02:58 +00:00
|
|
|
cryptojs: {
|
|
|
|
src: [
|
|
|
|
"components/cryptojs/src/core.js",
|
|
|
|
"components/cryptojs/src/sha256.js",
|
|
|
|
"components/cryptojs/src/hmac.js",
|
|
|
|
"components/cryptojs/src/enc-base64.js",
|
|
|
|
"components/cryptojs/src/md5.js",
|
|
|
|
"components/cryptojs/src/evpkdf.js",
|
|
|
|
"components/cryptojs/src/cipher-core.js",
|
|
|
|
"components/cryptojs/src/aes.js"
|
|
|
|
],
|
|
|
|
dest: 'js-deps/CryptoJS.js'
|
|
|
|
},
|
2014-10-31 00:57:37 +00:00
|
|
|
test: {
|
|
|
|
src: [
|
|
|
|
'components/mocha/mocha.js',
|
|
|
|
'components/chai/chai.js',
|
|
|
|
'test/_test.js'
|
|
|
|
],
|
|
|
|
dest: 'test/test.js',
|
2014-11-08 01:55:33 +00:00
|
|
|
},
|
|
|
|
curve25519: {
|
|
|
|
src: [
|
|
|
|
'build/_before.js',
|
|
|
|
'build/curve25519_compiled.js',
|
|
|
|
'build/curve25519.js',
|
|
|
|
'build/_after.js'
|
|
|
|
],
|
|
|
|
dest: 'js/curve25519_compiled.js'
|
2014-10-31 00:57:37 +00:00
|
|
|
}
|
2014-11-07 08:32:32 +00:00
|
|
|
},
|
|
|
|
sass: {
|
|
|
|
stylesheets: {
|
|
|
|
files: {
|
|
|
|
'stylesheets/manifest.css': 'stylesheets/manifest.scss'
|
|
|
|
}
|
|
|
|
}
|
2014-11-08 01:55:33 +00:00
|
|
|
},
|
|
|
|
compile: {
|
|
|
|
curve25519_compiled: {
|
|
|
|
src_files: [
|
|
|
|
'nacl/ed25519/additions/*.c',
|
|
|
|
'nacl/curve25519-donna.c',
|
|
|
|
'nacl/ed25519/*.c',
|
|
|
|
'nacl/ed25519/sha512/sha2big.c'
|
|
|
|
],
|
|
|
|
methods: [
|
|
|
|
'curve25519_donna',
|
|
|
|
'curve25519_sign',
|
|
|
|
'curve25519_verify',
|
|
|
|
'crypto_sign_ed25519_ref10_ge_scalarmult_base',
|
|
|
|
'sph_sha512_init',
|
|
|
|
'malloc'
|
|
|
|
]
|
|
|
|
}
|
2014-10-31 00:57:37 +00:00
|
|
|
}
|
2014-10-30 01:32:29 +00:00
|
|
|
});
|
|
|
|
grunt.loadNpmTasks('grunt-preen');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-concat');
|
2014-11-07 08:32:32 +00:00
|
|
|
grunt.loadNpmTasks('grunt-contrib-sass');
|
2014-10-30 01:32:29 +00:00
|
|
|
|
2014-11-08 01:55:33 +00:00
|
|
|
grunt.registerMultiTask('compile', 'Compile the C libraries with emscripten.', function() {
|
|
|
|
var callback = this.async();
|
|
|
|
var outfile = 'build/' + this.target + '.js';
|
|
|
|
|
|
|
|
var exported_functions = this.data.methods.map(function(name) {
|
|
|
|
return "'_" + name + "'";
|
|
|
|
});
|
|
|
|
var flags = [
|
|
|
|
'-O2',
|
|
|
|
'-Qunused-arguments',
|
|
|
|
'-o', outfile,
|
|
|
|
'-Inacl/ed25519/nacl_includes -Inacl/ed25519 -Inacl/ed25519/sha512',
|
|
|
|
'-s', "EXPORTED_FUNCTIONS=\"[" + exported_functions.join(',') + "]\""];
|
|
|
|
var command = [].concat('emcc', this.data.src_files, flags).join(' ');
|
|
|
|
grunt.log.writeln('Compiling via emscripten to ' + outfile);
|
|
|
|
|
|
|
|
var exitCode = 0;
|
|
|
|
grunt.verbose.subhead(command);
|
|
|
|
grunt.verbose.writeln(util.format('Expecting exit code %d', exitCode));
|
|
|
|
|
|
|
|
var child = child_process.exec(command);
|
|
|
|
child.stdout.on('data', function (d) { grunt.log.write(d); });
|
|
|
|
child.stderr.on('data', function (d) { grunt.log.error(d); });
|
|
|
|
child.on('exit', function(code) {
|
|
|
|
if (code !== exitCode) {
|
|
|
|
grunt.log.error(util.format('Exited with code: %d.', code));
|
|
|
|
return callback(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
grunt.verbose.ok(util.format('Exited with code: %d.', code));
|
|
|
|
callback(true);
|
|
|
|
});
|
|
|
|
});
|
2014-11-07 08:32:32 +00:00
|
|
|
|
|
|
|
grunt.registerTask('default', ['preen', 'concat', 'sass']);
|
2014-10-30 01:32:29 +00:00
|
|
|
};
|