|
1 |
| -module.exports = function createPackages(grunt) { |
2 |
| - let { config } = grunt; |
3 |
| - let { resolve } = require('path'); |
4 |
| - let { execFile } = require('child_process'); |
5 |
| - let { all, fromNode } = require('bluebird'); |
| 1 | +import { execFile } from 'child_process'; |
| 2 | +import { all, fromNode } from 'bluebird'; |
6 | 3 |
|
| 4 | +export default (grunt) => { |
| 5 | + const { config, log } = grunt; |
| 6 | + |
| 7 | + const cwd = config.get('buildDir'); |
7 | 8 | const targetDir = config.get('target');
|
8 |
| - let buildPath = resolve(config.get('root'), 'build'); |
9 |
| - let exec = async (cmd, args) => { |
10 |
| - grunt.log.writeln(` > ${cmd} ${args.join(' ')}`); |
11 |
| - await fromNode(cb => execFile(cmd, args, { cwd: buildPath }, cb)); |
12 |
| - }; |
13 | 9 |
|
| 10 | + async function exec(cmd, args) { |
| 11 | + log.writeln(` > ${cmd} ${args.join(' ')}`); |
| 12 | + await fromNode(cb => execFile(cmd, args, { cwd }, cb)); |
| 13 | + }; |
14 | 14 |
|
15 |
| - let archives = async (platform) => { |
16 |
| - if (/windows/.test(platform.name)) { |
17 |
| - await exec('zip', ['-rq', '-ll', platform.zipPath, platform.buildName]); |
| 15 | + async function archives({ name, buildName, zipPath, tarPath }) { |
| 16 | + if (/windows/.test(name)) { |
| 17 | + await exec('zip', ['-rq', '-ll', zipPath, buildName]); |
18 | 18 | } else {
|
19 |
| - await exec('tar', ['-zchf', platform.tarPath, platform.buildName]); |
| 19 | + await exec('tar', ['-zchf', tarPath, buildName]); |
20 | 20 | }
|
21 | 21 | };
|
22 | 22 |
|
23 | 23 | grunt.registerTask('_build:archives', function () {
|
| 24 | + grunt.file.mkdir(targetDir); |
24 | 25 |
|
25 | 26 | all(
|
26 |
| - grunt.config.get('platforms') |
27 |
| - .map(async platform => { |
28 |
| - |
29 |
| - grunt.file.mkdir(targetDir); |
30 |
| - await archives(platform); |
31 |
| - }) |
| 27 | + config.get('platforms').map(async platform => await archives(platform)) |
32 | 28 | )
|
33 | 29 | .nodeify(this.async());
|
34 | 30 |
|
|
0 commit comments