session-desktop/Gruntfile.js

188 lines
5.1 KiB
JavaScript
Raw Normal View History

const importOnce = require('node-sass-import-once');
const rimraf = require('rimraf');
const mkdirp = require('mkdirp');
const sass = require('node-sass');
/* eslint-disable more/no-then, no-console */
2014-11-23 04:36:52 +01:00
2021-10-04 01:56:54 +02:00
const toConcatForApp = [
'node_modules/jquery/dist/jquery.js',
'node_modules/bytebuffer/dist/bytebuffer.min.js',
'node_modules/long/dist/long.js',
'components/protobuf/**/*.js',
'node_modules/mustache/mustache.js',
'node_modules/underscore/underscore.js',
'node_modules/backbone/backbone.js',
];
const toConcatForComponentTextsecure = [
'node_modules/long/dist/long.js',
'components/protobuf/**/*.js',
];
module.exports = grunt => {
const components = [];
// eslint-disable-next-line guard-for-in, no-restricted-syntax
2021-10-04 01:56:54 +02:00
for (const i in toConcatForApp) {
components.push(toConcatForApp[i]);
}
const libtextsecurecomponents = [];
// eslint-disable-next-line guard-for-in, no-restricted-syntax
2021-10-04 01:56:54 +02:00
for (const i in toConcatForComponentTextsecure) {
libtextsecurecomponents.push(toConcatForComponentTextsecure[i]);
}
const utilWorkerComponents = [
'node_modules/bytebuffer/dist/bytebuffer.js',
'js/curve/curve25519_compiled.js',
'js/curve/curve25519_wrapper.js',
'node_modules/libsodium/dist/modules/libsodium.js',
'node_modules/libsodium-wrappers/dist/modules/libsodium-wrappers.js',
'libtextsecure/libsignal-protocol.js',
'js/util_worker_tasks.js',
];
2018-04-27 23:25:04 +02:00
grunt.loadNpmTasks('grunt-sass');
grunt.initConfig({
2014-11-23 04:36:52 +01:00
pkg: grunt.file.readJSON('package.json'),
concat: {
components: {
src: components,
dest: 'js/components.js',
},
util_worker: {
src: utilWorkerComponents,
dest: 'js/util_worker.js',
},
2015-01-14 23:22:26 +01:00
libtextsecurecomponents: {
src: libtextsecurecomponents,
dest: 'libtextsecure/components.js',
},
libtextsecure: {
options: {
2018-04-27 23:25:04 +02:00
banner: ';(function() {\n',
footer: '})();\n',
},
src: [
'libtextsecure/errors.js',
'libtextsecure/libsignal-protocol.js',
'libtextsecure/crypto.js',
2015-01-14 23:22:26 +01:00
'libtextsecure/storage.js',
'libtextsecure/storage/user.js',
'libtextsecure/helpers.js',
],
dest: 'js/libtextsecure.js',
},
libtextsecuretest: {
src: [
'node_modules/jquery/dist/jquery.js',
'node_modules/mocha/mocha.js',
'node_modules/chai/chai.js',
2018-04-27 23:25:04 +02:00
'libtextsecure/test/_test.js',
],
dest: 'libtextsecure/test/test.js',
2018-04-27 23:25:04 +02:00
},
},
sass: {
options: {
implementation: sass,
sourceMap: true,
2018-04-27 23:25:04 +02:00
importer: importOnce,
},
dev: {
files: {
2018-04-27 23:25:04 +02:00
'stylesheets/manifest.css': 'stylesheets/manifest.scss',
},
},
},
2014-11-23 04:36:52 +01:00
watch: {
2015-02-23 20:54:40 +01:00
libtextsecure: {
files: ['./libtextsecure/*.js', './libtextsecure/storage/*.js'],
2018-04-27 23:25:04 +02:00
tasks: ['concat:libtextsecure'],
2015-02-23 20:54:40 +01:00
},
utilworker: {
files: utilWorkerComponents,
tasks: ['concat:util_worker'],
},
protobuf: {
files: ['./protos/SignalService.proto'],
tasks: ['exec:build-protobuf'],
},
2018-05-07 20:10:49 +02:00
sass: {
files: ['./stylesheets/*.scss'],
tasks: ['sass'],
},
transpile: {
2021-04-22 10:03:58 +02:00
files: ['./ts/**/*.ts', './ts/**/*.tsx', './ts/**/**/*.tsx', './test/ts/**.ts'],
2018-04-27 23:25:04 +02:00
tasks: ['exec:transpile'],
},
2014-11-23 04:36:52 +01:00
},
exec: {
2018-04-27 23:25:04 +02:00
transpile: {
2018-05-07 20:11:12 +02:00
cmd: 'yarn transpile',
2018-04-27 23:25:04 +02:00
},
'build-protobuf': {
cmd: 'yarn build-protobuf',
},
},
2018-04-27 23:25:04 +02:00
gitinfo: {}, // to be populated by grunt gitinfo
2014-11-23 04:36:52 +01:00
});
Object.keys(grunt.config.get('pkg').devDependencies).forEach(key => {
2018-04-27 23:25:04 +02:00
if (/^grunt(?!(-cli)?$)/.test(key)) {
// ignore grunt and grunt-cli
2014-11-23 04:36:52 +01:00
grunt.loadNpmTasks(key);
}
});
function updateLocalConfig(update) {
const environment = process.env.SIGNAL_ENV || 'development';
const configPath = `config/local-${environment}.json`;
let localConfig;
try {
localConfig = grunt.file.readJSON(configPath);
} catch (e) {
//
}
localConfig = {
...localConfig,
...update,
};
grunt.file.write(configPath, `${JSON.stringify(localConfig)}\n`);
}
grunt.registerTask('getExpireTime', () => {
2018-04-27 23:25:04 +02:00
grunt.task.requires('gitinfo');
const gitinfo = grunt.config.get('gitinfo');
2018-12-13 22:41:42 +01:00
const committed = gitinfo.local.branch.current.lastCommitTime;
const time = Date.parse(committed) + 1000 * 60 * 60 * 24 * 90;
updateLocalConfig({ buildExpiration: time });
});
grunt.registerTask('getCommitHash', () => {
grunt.task.requires('gitinfo');
const gitinfo = grunt.config.get('gitinfo');
const hash = gitinfo.local.branch.current.SHA;
updateLocalConfig({ commitHash: hash });
});
grunt.registerTask('clean-release', () => {
rimraf.sync('release');
mkdirp.sync('release');
});
grunt.registerTask('dev', ['default', 'watch']);
grunt.registerTask('date', ['gitinfo', 'getExpireTime']);
2018-04-27 23:25:04 +02:00
grunt.registerTask('default', [
2018-05-08 01:05:49 +02:00
'exec:build-protobuf',
'exec:transpile',
2018-04-27 23:25:04 +02:00
'concat',
'sass',
'date',
'getCommitHash',
2018-04-27 23:25:04 +02:00
]);
};