forked from meteor/meteor
/
index.js
133 lines (111 loc) · 3.66 KB
/
index.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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import _ from 'underscore';
import assert from 'assert';
import utils from '../utils/utils.js';
import buildmessage from '../utils/buildmessage.js';
import { oldToNew as oldToNewPluginIds, newToOld as newToOldPluginIds }
from 'cordova-registry-mapper';
export const CORDOVA_ARCH = "web.cordova";
export const CORDOVA_PLATFORMS = ['ios', 'android'];
export const CORDOVA_PLATFORM_VERSIONS = {
'android': '6.2.3',
'ios': '4.5.1'
};
const PLATFORM_TO_DISPLAY_NAME_MAP = {
'ios': 'iOS',
'android': 'Android'
};
export function displayNameForPlatform(platform) {
return PLATFORM_TO_DISPLAY_NAME_MAP[platform] || platform;
};
export function displayNamesForPlatforms(platforms) {
return platforms.map((platform) =>
displayNameForPlatform(platform)).join(', ');
}
// This filters the Cordova platforms from a list of app-level platforms.
// Right now, the only other platforms are the default browser and server
// platforms.
export function filterPlatforms(platforms) {
return _.intersection(platforms, CORDOVA_PLATFORMS);
}
export function splitPluginsAndPackages(packages) {
let result = {
plugins: [],
packages: []
};
for (let pkg of packages) {
const [namespace, ...rest] = pkg.split(':');
if (namespace === 'cordova') {
const name = rest.join(':');
result.plugins.push(name);
} else {
result.packages.push(pkg);
}
}
return result;
}
// Returns the cordovaDependencies of the Cordova arch from a star manifest.
export function pluginVersionsFromStarManifest(star) {
var cordovaProgram = _.findWhere(star.programs, { arch: CORDOVA_ARCH });
return cordovaProgram ? cordovaProgram.cordovaDependencies : {};
}
export function newPluginId(id) {
return oldToNewPluginIds[id];
}
export function convertPluginVersions(pluginVersions) {
assert(pluginVersions);
buildmessage.assertInJob();
let newPluginVersions = {};
_.each(pluginVersions, (version, id) => {
if (utils.isUrlWithSha(version)) {
version = convertToGitUrl(version);
if (!version) {
// convertToGitUrl will add an error to buildmessage messages
return;
}
}
const newId = newPluginId(id);
if (newId) {
// If the plugin has already been added using the new ID, we do not
// overwrite the version.
if (!_.has(pluginVersions, newId)) {
newPluginVersions[newId] = version;
}
} else {
newPluginVersions[id] = version;
}
});
return newPluginVersions;
}
// Convert old-style GitHub tarball URLs to new Git URLs, and check if other
// Git URLs contain a SHA reference.
export function convertToGitUrl(url) {
buildmessage.assertInJob();
// Matches GitHub tarball URLs, like:
// https://github.com/meteor/com.meteor.cordova-update/tarball/92fe99b7248075318f6446b288995d4381d24cd2
const match =
url.match(/^https?:\/\/github.com\/(.+?)\/(.+?)\/tarball\/([0-9a-f]{40})/);
if (match) {
const [, organization, repository, sha] = match;
// Convert them to a Git URL
return `https://github.com/${organization}/${repository}.git#${sha}`;
// We only support Git URLs with a SHA reference to guarantee repeatability
// of builds
} else if (/\.git#[0-9a-f]{40}/.test(url)) {
return url;
} else {
buildmessage.error(`Meteor no longer supports installing Cordova plugins \
from arbitrary tarball URLs. You can either add a plugin from a Git URL with \
a SHA reference, or from a local path. (Attempting to install from ${url}.)`);
return null;
}
}
function displayNameForHostPlatform(platform = process.platform) {
switch (platform) {
case 'darwin':
return "Mac";
case 'linux':
return "Linux";
case 'win32':
return "Windows";
}
}