Mailspring/packages/client-app/build/tasks/installer-linux-task.js
Evan Morikawa a7686bb35b [client-app] build tasks now use absolute paths
Summary:
Grunt is hardcoded to use paths relative to wherever the Gruntfile is
located. Unfortunately it also expects the grunt packages to be siblings
of that gruntfile. We can get around this by changing the relative base
path, but then the cwd is different for each tasks. This is okay as long
as we use absolute paths for various files in each of our tasks. This
updates our grunt tasks to use absolute paths

Test Plan: `npm run build-client`

Reviewers: spang, halla, jerm, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3987
2017-02-21 14:35:51 -05:00

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'), `nylas-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/nylas',
linuxAssetsDir: linuxAssetsDir,
contentsDir: contentsDir,
}
// This populates nylas.spec
const specInFilePath = path.join(linuxAssetsDir, 'redhat', 'nylas.spec.in')
writeFromTemplate(specInFilePath, templateData)
// This populates nylas.desktop
const desktopInFilePath = path.join(linuxAssetsDir, 'nylas-mail.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/nylas-mail',
arch: arch,
section: 'devel',
maintainer: 'Nylas Team <support@nylas.com>',
installedSize: installedSize,
}
writeFromTemplate(path.join(linuxAssetsDir, 'debian', 'control.in'), data)
writeFromTemplate(path.join(linuxAssetsDir, 'nylas-mail.desktop.in'), data)
const icon = path.join(grunt.config('appDir'), 'build', 'resources', 'nylas.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}/nylas-${version}-${arch}.deb`);
return done()
});
});
});
}