Skip to content

Commit f39a9f5

Browse files
Kenichi Naitoakofman
authored andcommitted
Fix irregular ios version by using getPlatformVersionsFromFileSystem
1 parent ae587fb commit f39a9f5

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/main.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,38 @@
1818
import fs from 'fs';
1919
import path from 'path';
2020
import xcode from 'xcode';
21+
import childProcess from 'child_process';
2122

2223
export default (context) => {
23-
const platformMetadata = context.requireCordovaModule('cordova-lib/src/cordova/project_metadata');
2424
const projectRoot = context.opts.projectRoot;
2525
const glob = context.requireCordovaModule('glob');
26+
const cordovaUtil = context.requireCordovaModule('cordova-lib/src/cordova/util');
27+
const Q = context.requireCordovaModule('q');
28+
const getPlatformVersionsFromFileSystem = (projectRoot) => {
29+
var platformsOnFs = cordovaUtil.listPlatforms(projectRoot);
30+
var platformVersions = platformsOnFs.map(function (platform) {
31+
var script = path.join(projectRoot, 'platforms', platform, 'cordova', 'version');
32+
return Q.ninvoke(childProcess, 'exec', script, {}).then(function (result) {
33+
var version = result[0];
34+
35+
// clean the version we get back from the script
36+
// This is necessary because the version script uses console.log to pass back
37+
// the version. Using console.log ends up adding additional line breaks/newlines to the value returned.
38+
// ToDO: version scripts should be refactored to not use console.log()
39+
var versionCleaned = version.replace(/\r?\n|\r/g, '');
40+
return {platform: platform, version: versionCleaned};
41+
});
42+
});
43+
44+
return Q.all(platformVersions);
45+
};
2646

2747
// This script has to be executed depending on the command line arguments, not
2848
// on the hook execution cycle.
2949
if ((context.hook === 'after_platform_add' && context.cmdLine.includes('platform add')) ||
3050
(context.hook === 'after_prepare' && context.cmdLine.includes('prepare')) ||
3151
(context.hook === 'after_plugin_add' && context.cmdLine.includes('plugin add'))) {
32-
platformMetadata.getPlatforms(projectRoot).then((platformVersions) => {
52+
getPlatformVersionsFromFileSystem(projectRoot).then((platformVersions) => {
3353
const IOS_MIN_DEPLOYMENT_TARGET = '7.0';
3454
const platformPath = path.join(projectRoot, 'platforms', 'ios');
3555
const config = getConfigParser(context, path.join(projectRoot, 'config.xml'));

0 commit comments

Comments
 (0)