forked from tidev/alloy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.js
48 lines (42 loc) · 1.17 KB
/
base.js
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
var _ = require('../Alloy/lib/alloy/underscore')._,
U = require('../Alloy/utils');
module.exports = function(def) {
if (!def.platform) {
U.die([
'platform undefined',
new Error().stack
]);
}
_.extend(this, _.defaults(def, {
alloyFolder: def.platform,
titaniumFolder: def.platform,
name: def.platform,
osname: def.platform,
condition: {}
}));
this.condition = {
compile: def.condition.compile || 'OS_' + this.platform.toUpperCase(),
runtime: def.condition.runtime || runtimeCondition(this.osname, this.name)
};
};
function runtimeCondition(osname, name) {
var output, map;
osname = osname || [];
name = name || [];
if (!osname && !name) {
return 'true';
} else if (_.isString(name)) {
return "Ti.Platform.name === '" + name + "'";
} else if (_.isString(osname)) {
return "Ti.Platform.osname === '" + osname + "'";
} else {
if (_.isArray(name)) {
map = _.map(name, function(n) { return "Ti.Platform.name === '" + n + "'"; });
}
if (_.isArray(osname) && (!map || osname.length < name.length)) {
map = _.map(osname, function(n) { return "Ti.Platform.osname === '" + n + "'"; });
}
if (!map) { return 'true'; }
}
return map.join('||');
}