Newer
Older
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
/**
Module helps to generate building options for plugin.
Those options then injected into platform-specific config.xml.
*/
var fs = require('fs');
var path = require('path');
var OPTIONS_FILE_NAME = 'chcpbuild.options';
module.exports = {
getBuildConfigurationByName: getBuildConfigurationByName
};
// region Public API
/**
* Generate build options depending on the options, provided in console.
*
* @param {String} buildName - build identifier
* @return {Object} build options; null - if none are found
*/
function getBuildConfigurationByName(ctx, buildName) {
// load options from the chcpbuild.options file
var chcpBuildOptions = getBuildOptionsFromConfig(ctx);
if (chcpBuildOptions == null) {
return null;
}
var resultConfig = chcpBuildOptions[buildName];
if (!resultConfig) {
return null;
}
// backwards capability
// TODO: remove this in the next versions
if (resultConfig['config-file'] && !resultConfig['config-file']['url']) {
var url = resultConfig['config-file'];
resultConfig['config-file'] = {
'url': url
};
}
return resultConfig;
}
// endregion
// region Private API
/**
* Read options, listed in chcpbuild.options file.
*
* @return {Object} options from chcpbuild.options file
*/
function getBuildOptionsFromConfig(ctx) {
var chcpBuildOptionsFilePath = path.join(ctx.opts.projectRoot, OPTIONS_FILE_NAME);
return readObjectFromFile(chcpBuildOptionsFilePath);
};
function readObjectFromFile(filePath) {
var objData = null;
try {
var data = fs.readFileSync(filePath, 'utf-8');
objData = JSON.parse(data, 'utf-8');
} catch (err) {}
return objData;
}
// endregion