signal-desktop/Gruntfile.js

252 lines
7.3 KiB
JavaScript
Raw Normal View History

module.exports = function(grunt) {
2014-11-23 03:36:52 +00:00
'use strict';
var bower = grunt.file.readJSON('bower.json');
var components = [];
2014-10-31 07:40:00 +00:00
for (var i in bower.concat.app) {
components.push('components/' + bower.concat.app[i] + '/**/*.js');
}
2016-08-15 22:36:29 +00:00
components.push('components/' + 'webaudiorecorder/lib/WebAudioRecorder.js');
2015-01-14 22:22:26 +00:00
var libtextsecurecomponents = [];
for (i in bower.concat.libtextsecure) {
libtextsecurecomponents.push('components/' + bower.concat.libtextsecure[i] + '/**/*.js');
}
grunt.initConfig({
2014-11-23 03:36:52 +00:00
pkg: grunt.file.readJSON('package.json'),
concat: {
components: {
src: components,
dest: 'js/components.js',
},
2015-01-14 22:22:26 +00:00
libtextsecurecomponents: {
src: libtextsecurecomponents,
dest: 'libtextsecure/components.js',
},
2014-11-10 05:44:56 +00:00
test: {
src: [
'components/mocha/mocha.js',
'components/chai/chai.js',
'test/_test.js'
],
dest: 'test/test.js',
},
//TODO: Move errors back down?
libtextsecure: {
options: {
banner: ";(function() {\n",
footer: "})();\n",
},
src: [
'libtextsecure/errors.js',
'libtextsecure/libsignal-protocol.js',
2016-04-22 20:43:09 +00:00
'libtextsecure/protocol_wrapper.js',
'libtextsecure/crypto.js',
2015-01-14 22:22:26 +00:00
'libtextsecure/storage.js',
'libtextsecure/storage/user.js',
'libtextsecure/storage/groups.js',
'libtextsecure/storage/unprocessed.js',
'libtextsecure/protobufs.js',
'libtextsecure/websocket-resources.js',
'libtextsecure/helpers.js',
'libtextsecure/stringview.js',
'libtextsecure/event_target.js',
'libtextsecure/api.js',
'libtextsecure/account_manager.js',
'libtextsecure/message_receiver.js',
'libtextsecure/outgoing_message.js',
'libtextsecure/sendmessage.js',
'libtextsecure/sync_request.js',
'libtextsecure/contacts_parser.js',
'libtextsecure/ProvisioningCipher.js',
'libtextsecure/task_with_timeout.js',
],
dest: 'js/libtextsecure.js',
},
libtextsecuretest: {
src: [
'components/jquery/dist/jquery.js',
'components/mock-socket/dist/mock-socket.js',
'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',
'stylesheets/options.css': 'stylesheets/options.scss'
}
}
},
2014-11-23 03:36:52 +00:00
jshint: {
files: [
'Gruntfile.js',
2016-02-18 00:00:50 +00:00
'js/**/*.js',
'!js/libtextsecure.js',
2016-08-15 22:36:29 +00:00
'!js/WebAudioRecorderMp3.js',
'!js/Mp3LameEncoder.min.js',
'!js/libsignal-protocol-worker.js',
2016-02-18 00:00:50 +00:00
'!js/components.js',
2016-04-21 23:45:21 +00:00
'!js/signal_protocol_store.js',
2016-02-18 00:00:50 +00:00
'_locales/**/*'
],
2014-11-23 03:36:52 +00:00
options: { jshintrc: '.jshintrc' },
},
dist: {
src: [
'manifest.json',
'background.html',
'index.html',
'options.html',
2015-12-14 23:10:49 +00:00
'_locales/**',
'protos/*',
'js/**',
'stylesheets/*.css',
2015-05-15 20:13:32 +00:00
'!js/register.js'
],
res: [
2017-02-04 00:53:43 +00:00
'audio/**',
'images/**/*',
'fonts/*',
]
},
copy: {
2015-05-15 20:13:32 +00:00
res: {
files: [{ expand: true, dest: 'dist/', src: ['<%= dist.res %>'] }],
},
src: {
2015-05-07 21:45:07 +00:00
files: [{ expand: true, dest: 'dist/', src: ['<%= dist.src %>'] }],
options: {
process: function(content, srcpath) {
if (srcpath.match('background.js')) {
2015-05-15 20:13:32 +00:00
return content.replace(
/textsecure-service-staging.whispersystems.org/g,
'textsecure-service-ca.whispersystems.org');
} else if (srcpath.match('expire.js')) {
var gitinfo = grunt.config.get('gitinfo');
var commited = gitinfo.local.branch.current.lastCommitTime;
var time = Date.parse(commited) + 1000 * 60 * 60 * 24 * 90;
return content.replace(
/var BUILD_EXPIRATION = 0/,
"var BUILD_EXPIRATION = " + time
);
2015-05-15 20:13:32 +00:00
} else {
return content;
}
2015-05-07 21:45:07 +00:00
}
}
}
},
jscs: {
all: {
src: [
'Gruntfile',
'js/**/*.js',
'!js/libtextsecure.js',
2016-08-15 22:36:29 +00:00
'!js/WebAudioRecorderMp3.js',
'!js/Mp3LameEncoder.min.js',
'!js/libsignal-protocol-worker.js',
'!js/components.js',
'test/**/*.js',
'!test/blanket_mocha.js',
'!test/test.js',
]
}
},
2014-11-23 03:36:52 +00:00
watch: {
2015-01-26 20:36:12 +00:00
sass: {
files: ['./stylesheets/*.scss'],
2015-01-26 20:36:12 +00:00
tasks: ['sass']
2015-02-23 19:54:40 +00:00
},
libtextsecure: {
files: ['./libtextsecure/*.js', './libtextsecure/storage/*.js'],
tasks: ['concat:libtextsecure']
},
dist: {
2015-05-15 20:13:32 +00:00
files: ['<%= dist.src %>', '<%= dist.res %>'],
tasks: ['copy_dist']
},
scripts: {
files: ['<%= jshint.files %>', './js/**/*.js'],
tasks: ['jshint']
},
style: {
files: ['<%= jscs.all.src %>', './js/**/*.js'],
tasks: ['jscs']
},
2014-11-23 03:36:52 +00:00
},
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 03:36:52 +00:00
build: process.env.TRAVIS_JOB_ID,
browsers: [
{ browserName: 'chrome', version: '41' },
],
testname: 'TextSecure-Browser Tests',
'max-duration': 300,
statusCheckAttempts: 200
2014-11-23 03:36:52 +00:00
}
}
},
exec: {
'tx-pull': {
cmd: 'tx pull'
}
},
gitinfo: {} // to be populated by grunt gitinfo
2014-11-23 03:36:52 +00:00
});
Object.keys(grunt.config.get('pkg').devDependencies).forEach(function(key) {
if (/^grunt(?!(-cli)?$)/.test(key)) { // ignore grunt and grunt-cli
grunt.loadNpmTasks(key);
}
});
// Transifex does not understand placeholders, so this task patches all non-en
// locales with missing placeholders
grunt.registerTask('locale-patch', function(){
var en = grunt.file.readJSON('_locales/en/messages.json');
grunt.file.recurse('_locales', function(abspath, rootdir, subdir, filename){
if (subdir === 'en' || filename !== 'messages.json'){
return;
}
var messages = grunt.file.readJSON(abspath);
for (var key in messages){
2016-03-11 20:00:55 +00:00
if (en[key] !== undefined && messages[key] !== undefined){
if (en[key].placeholders !== undefined && messages[key].placeholders === undefined){
messages[key].placeholders = en[key].placeholders;
}
}
}
grunt.file.write(abspath, JSON.stringify(messages, null, 4) + '\n');
});
});
grunt.registerTask('tx', ['exec:tx-pull', 'locale-patch']);
grunt.registerTask('dev', ['default', 'connect', 'watch']);
grunt.registerTask('test', ['jshint', 'jscs', 'connect', 'saucelabs-mocha']);
grunt.registerTask('copy_dist', ['gitinfo', 'copy']);
grunt.registerTask('default', ['concat', 'sass', 'copy_dist']);
2014-11-23 03:36:52 +00:00
};