Cable-Desktop/Gruntfile.js

200 lines
5.9 KiB
JavaScript
Raw Normal View History

var child_process = require('child_process');
var util = require('util');
2014-10-31 08:40:00 +01:00
module.exports = function(grunt) {
2014-11-23 04:36:52 +01:00
'use strict';
var bower = grunt.file.readJSON('bower.json');
var components = [];
2014-10-31 08:40:00 +01:00
for (var i in bower.concat.app) {
components.push('components/' + bower.concat.app[i] + '/**/*.js');
}
var libcomponents = [];
for (i in bower.concat.lib) {
libcomponents.push('components/' + bower.concat.lib[i] + '/**/*.js');
}
grunt.initConfig({
2014-11-23 04:36:52 +01:00
pkg: grunt.file.readJSON('package.json'),
concat: {
components: {
src: components,
dest: 'js/components.js',
},
libcomponents: {
src: libcomponents,
dest: 'libtextsecure/components.js',
},
curve25519: {
src: [
'build/curve25519_compiled.js',
'build/curve25519.js',
],
dest: 'libtextsecure/curve25519_concat.js',
2014-11-08 20:38:32 +01:00
options: {
banner: ';(function(){\n',
footer: '\n})();'
}
},
webcrypto: {
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',
'build/webcrypto.js'
],
dest: 'libtextsecure/webcrypto_concat.js',
options: {
banner: ';(function(){\n',
footer: '\n})();'
}
2014-11-10 06:44:56 +01:00
},
test: {
src: [
'components/mocha/mocha.js',
'components/chai/chai.js',
'test/_test.js'
],
dest: 'test/test.js',
},
libtextsecure: {
src: [
'libtextsecure/curve25519_concat.js',
'libtextsecure/webcrypto_concat.js',
'libtextsecure/protobufs.js',
'libtextsecure/websocket.js',
'libtextsecure/websocket-resources.js',
'libtextsecure/helpers.js',
'libtextsecure/errors.js',
'libtextsecure/stringview.js',
'libtextsecure/storage.js',
'libtextsecure/storage/devices.js',
'libtextsecure/storage/groups.js',
'libtextsecure/api.js',
'libtextsecure/crypto.js',
'libtextsecure/protocol.js',
'libtextsecure/sendmessage.js',
],
dest: 'js/libtextsecure.js',
},
libtextsecuretest: {
src: [
'components/mocha/mocha.js',
'components/chai/chai.js',
'libtextsecure/test/_test.js'
],
dest: 'libtextsecure/test/test.js',
}
},
sass: {
stylesheets: {
files: {
'stylesheets/manifest.css': 'stylesheets/manifest.scss'
}
}
},
compile: {
curve25519_compiled: {
src_files: [
2015-01-14 22:30:48 +01:00
'native/ed25519/additions/*.c',
'native/curve25519-donna.c',
'native/ed25519/*.c',
'native/ed25519/sha512/sha2big.c'
],
methods: [
'curve25519_donna',
'curve25519_sign',
'curve25519_verify',
'crypto_sign_ed25519_ref10_ge_scalarmult_base',
'sph_sha512_init',
'malloc'
]
}
2014-11-23 04:36:52 +01:00
},
jshint: {
files: ['Gruntfile.js'], // add 'src/**/*.js', 'test/**/*.js'
options: { jshintrc: '.jshintrc' },
},
jscs: {
all: {
src: ['js/**/*.js', '!js/components.js', 'test/**/*.js']
}
},
2014-11-23 04:36:52 +01:00
watch: {
files: ['<%= jshint.files %>'],
tasks: ['jshint']
},
connect: {
server: {
options: {
base: '.',
port: 9999
}
}
},
'saucelabs-mocha': {
all: {
options: {
urls: ['http://127.0.0.1:9999/test/index.html', 'http://127.0.0.1:9999/libtextsecure/test/index.html'],
2014-11-23 04:36:52 +01:00
build: process.env.TRAVIS_JOB_ID,
2015-01-14 03:18:27 +01:00
browsers: [{ browserName: 'chrome', version: '38' }, { browserName: 'firefox', version: '34' }],
2014-11-23 04:36:52 +01:00
testname: 'TextSecure-Browser Tests'
}
}
}
});
Object.keys(grunt.config.get('pkg').devDependencies).forEach(function(key) {
if (/^grunt(?!(-cli)?$)/.test(key)) { // ignore grunt and grunt-cli
grunt.loadNpmTasks(key);
}
});
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,
2015-01-14 22:30:48 +01:00
'-Inative/ed25519/nacl_includes -Inative/ed25519 -Inative/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-23 04:36:52 +01:00
grunt.registerTask('dev', ['connect', 'watch']);
grunt.registerTask('test', ['jshint', 'jscs', 'connect', 'saucelabs-mocha']);
grunt.registerTask('default', ['preen', 'concat', 'sass']);
2015-01-14 22:38:55 +01:00
grunt.registerTask('build', ['compile', 'concat:curve25519', 'concat:libtextsecure']);
2014-11-23 04:36:52 +01:00
};