mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 21:57:55 +08:00
116 lines
3.8 KiB
JavaScript
116 lines
3.8 KiB
JavaScript
/* eslint global-require:0 */
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const _ = require('underscore');
|
|
|
|
module.exports = (grunt) => {
|
|
const {spawn} = grunt.config('taskHelpers');
|
|
|
|
const outputDir = grunt.config.get('outputDir');
|
|
const contentsDir = path.join(grunt.config('outputDir'), `merani-linux-${process.arch}`);
|
|
const linuxAssetsDir = path.resolve(path.join(grunt.config('buildDir'), 'resources', 'linux'));
|
|
const arch = {
|
|
ia32: 'i386',
|
|
x64: 'amd64',
|
|
}[process.arch];
|
|
|
|
// a few helpers
|
|
|
|
const writeFromTemplate = (filePath, data) => {
|
|
const template = _.template(String(fs.readFileSync(filePath)))
|
|
const finishedPath = path.join(outputDir, path.basename(filePath).replace('.in', ''));
|
|
grunt.file.write(finishedPath, template(data));
|
|
return finishedPath;
|
|
}
|
|
|
|
const getInstalledSize = (dir, callback) => {
|
|
const cmd = 'du';
|
|
const args = ['-sk', dir];
|
|
spawn({cmd, args}, (error, {stdout}) => {
|
|
const installedSize = stdout.split(/\s+/).shift() || '200000'; // default to 200MB
|
|
callback(null, installedSize);
|
|
});
|
|
}
|
|
|
|
grunt.registerTask('create-rpm-installer', 'Create rpm package', function mkrpmf() {
|
|
const done = this.async()
|
|
if (!arch) {
|
|
done(new Error(`Unsupported arch ${process.arch}`));
|
|
return;
|
|
}
|
|
|
|
const rpmDir = path.join(grunt.config('outputDir'), 'rpm');
|
|
if (grunt.file.exists(rpmDir)) {
|
|
grunt.file.delete(rpmDir, {force: true});
|
|
}
|
|
|
|
const templateData = {
|
|
name: grunt.config('appJSON').name,
|
|
version: grunt.config('appJSON').version,
|
|
description: grunt.config('appJSON').description,
|
|
productName: grunt.config('appJSON').productName,
|
|
linuxShareDir: '/usr/local/share/merani',
|
|
linuxAssetsDir: linuxAssetsDir,
|
|
contentsDir: contentsDir,
|
|
}
|
|
|
|
// This populates merani.spec
|
|
const specInFilePath = path.join(linuxAssetsDir, 'redhat', 'merani.spec.in')
|
|
writeFromTemplate(specInFilePath, templateData)
|
|
|
|
// This populates merani.desktop
|
|
const desktopInFilePath = path.join(linuxAssetsDir, 'merani.desktop.in')
|
|
writeFromTemplate(desktopInFilePath, templateData)
|
|
|
|
const cmd = path.join(grunt.config('appDir'), 'script', 'mkrpm')
|
|
const args = [outputDir, contentsDir, linuxAssetsDir]
|
|
spawn({cmd, args}, (error) => {
|
|
if (error) {
|
|
return done(error);
|
|
}
|
|
grunt.log.ok(`Created rpm package in ${rpmDir}`);
|
|
return done();
|
|
});
|
|
});
|
|
|
|
grunt.registerTask('create-deb-installer', 'Create debian package', function mkdebf() {
|
|
const done = this.async()
|
|
if (!arch) {
|
|
done(`Unsupported arch ${process.arch}`);
|
|
return;
|
|
}
|
|
|
|
getInstalledSize(contentsDir, (error, installedSize) => {
|
|
if (error) {
|
|
done(error);
|
|
return;
|
|
}
|
|
|
|
const version = grunt.config('appJSON').version;
|
|
const data = {
|
|
version: version,
|
|
name: grunt.config('appJSON').name,
|
|
description: grunt.config('appJSON').description,
|
|
productName: grunt.config('appJSON').productName,
|
|
linuxShareDir: '/usr/share/merani',
|
|
arch: arch,
|
|
section: 'devel',
|
|
maintainer: 'Merani Team <support@getmerani.com>',
|
|
installedSize: installedSize,
|
|
}
|
|
writeFromTemplate(path.join(linuxAssetsDir, 'debian', 'control.in'), data)
|
|
writeFromTemplate(path.join(linuxAssetsDir, 'merani.desktop.in'), data)
|
|
|
|
const icon = path.join(grunt.config('appDir'), 'build', 'resources', 'merani.png')
|
|
const cmd = path.join(grunt.config('appDir'), 'script', 'mkdeb');
|
|
const args = [version, arch, icon, linuxAssetsDir, contentsDir, outputDir];
|
|
spawn({cmd, args}, (spawnError) => {
|
|
if (spawnError) {
|
|
return done(spawnError);
|
|
}
|
|
grunt.log.ok(`Created ${outputDir}/merani-${version}-${arch}.deb`);
|
|
return done()
|
|
});
|
|
});
|
|
});
|
|
}
|