2015-08-14 06:16:54 +02:00
|
|
|
module.exports = function createPackages(grunt) {
|
|
|
|
let { config } = grunt;
|
2016-06-17 15:20:44 +02:00
|
|
|
let { resolve } = require('path');
|
2015-08-14 06:16:54 +02:00
|
|
|
let { execFile } = require('child_process');
|
|
|
|
let { all, fromNode } = require('bluebird');
|
|
|
|
|
2016-06-16 16:36:06 +02:00
|
|
|
const targetDir = config.get('target');
|
2015-08-14 22:27:41 +02:00
|
|
|
let buildPath = resolve(config.get('root'), 'build');
|
2015-08-14 06:16:54 +02:00
|
|
|
let exec = async (cmd, args) => {
|
|
|
|
grunt.log.writeln(` > ${cmd} ${args.join(' ')}`);
|
2015-08-14 22:27:41 +02:00
|
|
|
await fromNode(cb => execFile(cmd, args, { cwd: buildPath }, cb));
|
2015-08-14 06:16:54 +02:00
|
|
|
};
|
|
|
|
|
2015-08-14 20:53:26 +02:00
|
|
|
|
2015-08-14 06:16:54 +02:00
|
|
|
let archives = async (platform) => {
|
|
|
|
if (/windows/.test(platform.name)) {
|
2016-06-17 15:20:44 +02:00
|
|
|
await exec('zip', ['-rq', '-ll', platform.zipPath, platform.buildName]);
|
2015-08-14 06:16:54 +02:00
|
|
|
} else {
|
2016-06-17 15:20:44 +02:00
|
|
|
await exec('tar', ['-zchf', platform.tarPath, platform.buildName]);
|
2015-08-14 06:16:54 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-14 22:27:41 +02:00
|
|
|
grunt.registerTask('_build:archives', function () {
|
2015-08-14 06:16:54 +02:00
|
|
|
|
|
|
|
all(
|
|
|
|
grunt.config.get('platforms')
|
|
|
|
.map(async platform => {
|
|
|
|
|
2016-06-16 16:36:06 +02:00
|
|
|
grunt.file.mkdir(targetDir);
|
2015-08-14 06:16:54 +02:00
|
|
|
await archives(platform);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.nodeify(this.async());
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|