|
18 | 18 | import fs from 'fs';
|
19 | 19 | import path from 'path';
|
20 | 20 | import xcode from 'xcode';
|
| 21 | +import childProcess from 'child_process'; |
21 | 22 |
|
22 | 23 | export default (context) => {
|
23 |
| - const platformMetadata = context.requireCordovaModule('cordova-lib/src/cordova/project_metadata'); |
24 | 24 | const projectRoot = context.opts.projectRoot;
|
25 | 25 | 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 | + }; |
26 | 46 |
|
27 | 47 | // This script has to be executed depending on the command line arguments, not
|
28 | 48 | // on the hook execution cycle.
|
29 | 49 | if ((context.hook === 'after_platform_add' && context.cmdLine.includes('platform add')) ||
|
30 | 50 | (context.hook === 'after_prepare' && context.cmdLine.includes('prepare')) ||
|
31 | 51 | (context.hook === 'after_plugin_add' && context.cmdLine.includes('plugin add'))) {
|
32 |
| - platformMetadata.getPlatforms(projectRoot).then((platformVersions) => { |
| 52 | + getPlatformVersionsFromFileSystem(projectRoot).then((platformVersions) => { |
33 | 53 | const IOS_MIN_DEPLOYMENT_TARGET = '7.0';
|
34 | 54 | const platformPath = path.join(projectRoot, 'platforms', 'ios');
|
35 | 55 | const config = getConfigParser(context, path.join(projectRoot, 'config.xml'));
|
|
0 commit comments