2014-11-08 02:55:33 +01:00
|
|
|
var child_process = require('child_process');
|
|
|
|
var util = require('util');
|
2014-10-31 08:40:00 +01:00
|
|
|
|
2014-10-30 02:32:29 +01:00
|
|
|
module.exports = function(grunt) {
|
2014-11-23 04:36:52 +01:00
|
|
|
'use strict';
|
|
|
|
|
2014-10-31 01:57:37 +01:00
|
|
|
var bower = grunt.file.readJSON('bower.json');
|
2014-10-30 02:32:29 +01:00
|
|
|
var components = [];
|
2014-10-31 08:40:00 +01:00
|
|
|
for (var i in bower.concat.app) {
|
2014-10-31 01:57:37 +01:00
|
|
|
components.push('components/' + bower.concat.app[i] + '/**/*.js');
|
2014-10-30 02:32:29 +01:00
|
|
|
}
|
|
|
|
|
2015-01-14 23:22:26 +01:00
|
|
|
var libtextsecurecomponents = [];
|
|
|
|
for (i in bower.concat.libtextsecure) {
|
|
|
|
libtextsecurecomponents.push('components/' + bower.concat.libtextsecure[i] + '/**/*.js');
|
2015-01-14 02:23:11 +01:00
|
|
|
}
|
|
|
|
|
2014-10-30 02:32:29 +01:00
|
|
|
grunt.initConfig({
|
2014-11-23 04:36:52 +01:00
|
|
|
pkg: grunt.file.readJSON('package.json'),
|
2014-10-30 02:32:29 +01:00
|
|
|
concat: {
|
|
|
|
components: {
|
|
|
|
src: components,
|
2014-10-31 00:53:08 +01:00
|
|
|
dest: 'js/components.js',
|
2014-10-30 02:32:29 +01:00
|
|
|
},
|
2015-01-14 23:22:26 +01:00
|
|
|
libtextsecurecomponents: {
|
|
|
|
src: libtextsecurecomponents,
|
2015-01-14 02:23:11 +01:00
|
|
|
dest: 'libtextsecure/components.js',
|
|
|
|
},
|
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',
|
2015-01-14 01:09:32 +01:00
|
|
|
},
|
2015-01-16 01:30:55 +01:00
|
|
|
//TODO: Move errors back down?
|
2015-01-14 01:09:32 +01:00
|
|
|
libtextsecure: {
|
|
|
|
src: [
|
2015-01-16 01:30:55 +01:00
|
|
|
'libtextsecure/errors.js',
|
2015-03-17 22:31:33 +01:00
|
|
|
'libtextsecure/libaxolotl.js',
|
2015-01-15 00:42:01 +01:00
|
|
|
'libtextsecure/axolotl_wrapper.js',
|
2015-01-14 02:49:38 +01:00
|
|
|
|
2015-01-16 05:11:08 +01:00
|
|
|
'libtextsecure/crypto.js',
|
2015-01-14 23:22:26 +01:00
|
|
|
'libtextsecure/storage.js',
|
2015-03-24 23:48:59 +01:00
|
|
|
'libtextsecure/storage/user.js',
|
2015-01-14 23:22:26 +01:00
|
|
|
'libtextsecure/storage/devices.js',
|
2015-01-21 06:48:27 +01:00
|
|
|
'libtextsecure/storage/groups.js',
|
2015-01-14 01:09:32 +01:00
|
|
|
'libtextsecure/protobufs.js',
|
|
|
|
'libtextsecure/websocket.js',
|
|
|
|
'libtextsecure/websocket-resources.js',
|
|
|
|
'libtextsecure/helpers.js',
|
|
|
|
'libtextsecure/stringview.js',
|
|
|
|
'libtextsecure/api.js',
|
|
|
|
'libtextsecure/sendmessage.js',
|
|
|
|
],
|
|
|
|
dest: 'js/libtextsecure.js',
|
|
|
|
},
|
2015-01-14 02:04:21 +01:00
|
|
|
libtextsecuretest: {
|
|
|
|
src: [
|
|
|
|
'components/mocha/mocha.js',
|
|
|
|
'components/chai/chai.js',
|
|
|
|
'libtextsecure/test/_test.js'
|
|
|
|
],
|
|
|
|
dest: 'libtextsecure/test/test.js',
|
2014-10-31 01:57:37 +01:00
|
|
|
}
|
2014-11-07 09:32:32 +01:00
|
|
|
},
|
|
|
|
sass: {
|
|
|
|
stylesheets: {
|
|
|
|
files: {
|
2015-03-06 20:43:53 +01:00
|
|
|
'stylesheets/manifest.css': 'stylesheets/manifest.scss',
|
|
|
|
'stylesheets/options.css': 'stylesheets/options.scss'
|
2014-11-07 09:32:32 +01:00
|
|
|
}
|
|
|
|
}
|
2014-11-08 02:55:33 +01:00
|
|
|
},
|
|
|
|
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'
|
2014-11-08 02:55:33 +01:00
|
|
|
],
|
|
|
|
methods: [
|
|
|
|
'curve25519_donna',
|
|
|
|
'curve25519_sign',
|
|
|
|
'curve25519_verify',
|
|
|
|
'crypto_sign_ed25519_ref10_ge_scalarmult_base',
|
|
|
|
'sph_sha512_init',
|
2015-02-11 11:55:42 +01:00
|
|
|
'malloc',
|
|
|
|
'free'
|
2014-11-08 02:55:33 +01:00
|
|
|
]
|
|
|
|
}
|
2014-11-23 04:36:52 +01:00
|
|
|
},
|
|
|
|
jshint: {
|
2015-02-19 09:20:22 +01:00
|
|
|
files: [
|
|
|
|
'Gruntfile.js',
|
|
|
|
'js/background.js',
|
|
|
|
'js/chromium.js',
|
|
|
|
'js/bimap.js',
|
|
|
|
'js/conversation_panel.js',
|
|
|
|
'js/database.js',
|
|
|
|
'js/inbox_controller.js',
|
|
|
|
'js/index.js',
|
|
|
|
'js/libphonenumber-util.js',
|
|
|
|
'js/options.js',
|
|
|
|
'js/panel_controller.js',
|
|
|
|
'js/models/*.js',
|
|
|
|
'js/views/*.js',
|
|
|
|
],
|
2014-11-23 04:36:52 +01:00
|
|
|
options: { jshintrc: '.jshintrc' },
|
|
|
|
},
|
2015-03-20 00:46:58 +01:00
|
|
|
dist: {
|
|
|
|
src: [
|
|
|
|
'manifest.json',
|
|
|
|
'background.html',
|
|
|
|
'index.html',
|
2015-03-20 18:47:45 +01:00
|
|
|
'conversation.html',
|
2015-03-20 00:46:58 +01:00
|
|
|
'options.html',
|
|
|
|
'protos/*',
|
|
|
|
'js/**',
|
|
|
|
'stylesheets/*.css',
|
|
|
|
'images/**',
|
|
|
|
'fonts/*',
|
|
|
|
'!js/register.js'
|
|
|
|
]
|
|
|
|
},
|
|
|
|
copy: {
|
|
|
|
dist: {
|
|
|
|
files: [{ expand: true, dest: 'dist/', src: ['<%= dist.src %>'] }]
|
|
|
|
}
|
|
|
|
},
|
2015-01-14 18:33:34 +01:00
|
|
|
jscs: {
|
|
|
|
all: {
|
2015-03-17 00:28:37 +01:00
|
|
|
src: ['js/**/*.js', '!js/libtextsecure.js', '!js/components.js', 'test/**/*.js']
|
2015-01-14 18:33:34 +01:00
|
|
|
}
|
|
|
|
},
|
2014-11-23 04:36:52 +01:00
|
|
|
watch: {
|
2015-01-26 21:36:12 +01:00
|
|
|
scripts: {
|
|
|
|
files: ['<%= jshint.files %>', './js/**/*.js'],
|
|
|
|
tasks: ['jshint']
|
|
|
|
},
|
|
|
|
sass: {
|
2015-01-30 05:53:49 +01:00
|
|
|
files: ['./stylesheets/*.scss'],
|
2015-01-26 21:36:12 +01:00
|
|
|
tasks: ['sass']
|
2015-02-23 20:54:40 +01:00
|
|
|
},
|
|
|
|
libtextsecure: {
|
|
|
|
files: ['./libtextsecure/*.js', './libtextsecure/storage/*.js'],
|
|
|
|
tasks: ['concat:libtextsecure']
|
|
|
|
},
|
2015-03-20 00:46:58 +01:00
|
|
|
dist: {
|
|
|
|
files: ['<%= dist.src %>'],
|
|
|
|
tasks: ['copy']
|
|
|
|
},
|
2014-11-23 04:36:52 +01:00
|
|
|
},
|
|
|
|
connect: {
|
|
|
|
server: {
|
|
|
|
options: {
|
|
|
|
base: '.',
|
|
|
|
port: 9999
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'saucelabs-mocha': {
|
|
|
|
all: {
|
|
|
|
options: {
|
2015-03-06 03:28:02 +01:00
|
|
|
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-03-06 03:28:02 +01:00
|
|
|
browsers: [
|
|
|
|
{ browserName: 'chrome', version: '40' },
|
|
|
|
{ browserName: 'firefox', version: '34' }
|
|
|
|
],
|
2014-11-23 04:36:52 +01:00
|
|
|
testname: 'TextSecure-Browser Tests'
|
|
|
|
}
|
|
|
|
}
|
2015-03-20 00:46:58 +01:00
|
|
|
},
|
2014-11-23 04:36:52 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
Object.keys(grunt.config.get('pkg').devDependencies).forEach(function(key) {
|
|
|
|
if (/^grunt(?!(-cli)?$)/.test(key)) { // ignore grunt and grunt-cli
|
|
|
|
grunt.loadNpmTasks(key);
|
2014-10-31 01:57:37 +01:00
|
|
|
}
|
2014-10-30 02:32:29 +01:00
|
|
|
});
|
|
|
|
|
2014-11-08 02:55:33 +01: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 = [
|
2015-03-16 23:23:41 +01:00
|
|
|
'-O1',
|
2014-11-08 02:55:33 +01:00
|
|
|
'-Qunused-arguments',
|
|
|
|
'-o', outfile,
|
2015-01-14 22:30:48 +01:00
|
|
|
'-Inative/ed25519/nacl_includes -Inative/ed25519 -Inative/ed25519/sha512',
|
2014-11-08 02:55:33 +01:00
|
|
|
'-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 09:32:32 +01:00
|
|
|
|
2015-01-22 05:55:56 +01:00
|
|
|
grunt.registerTask('dev', ['connect', 'watch', 'sass']);
|
2015-01-14 18:33:34 +01:00
|
|
|
grunt.registerTask('test', ['jshint', 'jscs', 'connect', 'saucelabs-mocha']);
|
2014-11-07 09:32:32 +01:00
|
|
|
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
|
|
|
|
2014-10-30 02:32:29 +01:00
|
|
|
};
|