-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgenerate-metabase-task.js
More file actions
94 lines (81 loc) · 2.06 KB
/
Copy pathgenerate-metabase-task.js
File metadata and controls
94 lines (81 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
'use strict';
const BaseFileTask = require('appc-tasks').BaseFileTask;
const fs = require('fs-extra');
const metabase = require('../metabase');
/**
* A task that will generate the Android metabase
*
* This is implemented as a simple base task because the metabase generation
* itself has a caching mechanism, so we just delegate and return the result.
*/
class GenerateMetabaseTask extends BaseFileTask {
/**
* Constructs a new task for metabase generation
*
* @param {Object} taskInfo
*/
constructor(taskInfo) {
super(taskInfo);
this._builder = null;
this._metabase = null;
}
/**
* Gets the output directory where the metabase JSON will be written to.
*
* @return {String} Full path to the output directory.
*/
get outputDirectory() {
return this._outputDirectory;
}
/**
* Sets the output directory where the metabase JSON file will be written to.
*
* @param {String} outputPath Full path to the output directory.
*/
set outputDirectory(outputPath) {
this._outputDirectory = outputPath;
}
/**
* Sets the AndroidBuilder instance
*
* @param {AndroidBuilder} builder
*/
set builder(builder) {
this._builder = builder;
}
/**
* Gets the generated metabase
*
* @return {Object} Metabase object
*/
get metabase() {
return this._metabase;
}
/**
* Starts the metabase generation by delegating to the existing metabase loader
*
* @return {Promise}
*/
async runTaskAction() {
const inputFiles = Array.from(this.inputFiles);
this.logger.trace('Generating metabase for JARs: ' + inputFiles);
const options = {
platform: 'android-' + this._builder.realTargetSDK
};
if (this._outputDirectory) {
await fs.ensureDir(this._outputDirectory);
options.cacheDir = this._outputDirectory;
}
return new Promise((resolve, reject) => {
metabase.metabase.loadMetabase(inputFiles, options, (err, json) => {
if (err) {
this.logger.error('Failed to generated metabase: ' + err);
return reject(err);
}
this._metabase = json;
resolve();
});
});
}
}
module.exports = GenerateMetabaseTask;