Skip to content

Commit

Permalink
breaking(pod): remove unused API & bump minimum version requirements …
Browse files Browse the repository at this point in the history
…to 1.8.0 (#849)

* breaking: remove unused API check_cocoapods_repo_size
* breaking(pod): bump minimum version requirements to 1.8.0
  • Loading branch information
erisu authored May 19, 2020
1 parent a63841c commit 1f753f6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 117 deletions.
77 changes: 4 additions & 73 deletions bin/templates/scripts/cordova/lib/check_reqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

const Q = require('q');
const shell = require('shelljs');
const util = require('util');
const versions = require('./versions');

const SUPPORTED_OS_PLATFORMS = ['darwin'];
Expand All @@ -34,15 +33,8 @@ const IOS_DEPLOY_MIN_VERSION = '1.9.2';
const IOS_DEPLOY_NOT_FOUND_MESSAGE =
`Please download, build and install version ${IOS_DEPLOY_MIN_VERSION} or greater from https://github.com/ios-control/ios-deploy into your path, or do 'npm install -g ios-deploy'`;

const COCOAPODS_MIN_VERSION = '1.0.1';
const COCOAPODS_NOT_FOUND_MESSAGE =
`Please install version ${COCOAPODS_MIN_VERSION} or greater from https://cocoapods.org/`;
const COCOAPODS_NOT_SYNCED_MESSAGE =
'The CocoaPods repo has not been synced yet, this will take a long time (approximately 500MB as of Sept 2016). Please run `pod setup` first to sync the repo.';
const COCOAPODS_SYNCED_MIN_SIZE = 475; // in megabytes
const COCOAPODS_SYNC_ERROR_MESSAGE =
`The CocoaPods repo has been created, but there appears to be a sync error. The repo size should be at least ${COCOAPODS_SYNCED_MIN_SIZE}. Please run \`pod setup --verbose\` to sync the repo.`;
const COCOAPODS_REPO_NOT_FOUND_MESSAGE = 'The CocoaPods repo at ~/.cocoapods was not found.';
const COCOAPODS_MIN_VERSION = '1.8.0';
const COCOAPODS_NOT_FOUND_MESSAGE = `Please install version ${COCOAPODS_MIN_VERSION} or greater from https://cocoapods.org/`;

/**
* Checks if xcode util is available
Expand Down Expand Up @@ -71,73 +63,12 @@ function os_platform_is_supported () {
return (SUPPORTED_OS_PLATFORMS.indexOf(process.platform) !== -1);
}

function check_cocoapod_tool (toolChecker) {
toolChecker = toolChecker || checkTool;
if (os_platform_is_supported()) { // CB-12856
return toolChecker('pod', COCOAPODS_MIN_VERSION, COCOAPODS_NOT_FOUND_MESSAGE, 'CocoaPods');
} else {
return Q.resolve({
ignore: true,
ignoreMessage: `CocoaPods check and installation ignored on ${process.platform}`
});
}
}

/**
* Checks if cocoapods repo size is what is expected
* @return {Promise} Returns a promise either resolved or rejected
*/
module.exports.check_cocoapods_repo_size = () => {
return check_cocoapod_tool()
.then(toolOptions => {
// check size of ~/.cocoapods repo
const commandString = util.format('du -sh %s/.cocoapods', process.env.HOME);
const command = shell.exec(commandString, { silent: true });
// command.output is e.g "750M path/to/.cocoapods", we just scan the number
const size = toolOptions.ignore ? 0 : parseFloat(command.output);

if (toolOptions.ignore || command.code === 0) { // success, parse output
return Q.resolve(size, toolOptions);
} else { // error, perhaps not found
return Q.reject(util.format('%s (%s)', COCOAPODS_REPO_NOT_FOUND_MESSAGE, command.output));
}
})
.then((repoSize, toolOptions) => {
if (toolOptions.ignore || COCOAPODS_SYNCED_MIN_SIZE <= repoSize) { // success, expected size
return Q.resolve(toolOptions);
} else {
return Q.reject(COCOAPODS_SYNC_ERROR_MESSAGE);
}
});
};

/**
* Checks if cocoapods is available, and whether the repo is synced (because it takes a long time to download)
* Checks if cocoapods is available.
* @return {Promise} Returns a promise either resolved or rejected
*/
module.exports.check_cocoapods = toolChecker => {
return check_cocoapod_tool(toolChecker)
// check whether the cocoapods repo has been synced through `pod repo` command
// a value of '0 repos' means it hasn't been synced
.then(toolOptions => {
if (toolOptions.ignore) return toolOptions;

// starting with 1.8.0 cocoapods now use cdn and we dont need to sync first
if (versions.compareVersions(toolOptions.version, '1.8.0') >= 0) {
return toolOptions;
}

const code = shell.exec('pod repo | grep -e "^0 repos"', { silent: true }).code;
const repoIsSynced = (code !== 0);

if (repoIsSynced) {
// return check_cocoapods_repo_size();
// we could check the repo size above, but it takes too long.
return toolOptions;
} else {
return Promise.reject(COCOAPODS_NOT_SYNCED_MESSAGE);
}
});
return checkTool('pod', COCOAPODS_MIN_VERSION, COCOAPODS_NOT_FOUND_MESSAGE, 'CocoaPods');
};

/**
Expand Down
44 changes: 0 additions & 44 deletions tests/spec/unit/lib/check_reqs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,48 +66,4 @@ describe('check_reqs', () => {
);
});
});

describe('check_cocoapods method', () => {
let toolsChecker;
beforeEach(() => {
toolsChecker = jasmine.createSpy('toolsChecker')
.and.returnValue(Promise.resolve({ version: '1.2.3' }));
});

it('should resolve when on an unsupported platform', () => {
checkReqs.__set__({
os_platform_is_supported: () => false
});

return checkReqs.check_cocoapods(toolsChecker).then(toolOptions => {
expect(toolsChecker).not.toHaveBeenCalled();
expect(toolOptions.ignore).toBeDefined();
expect(toolOptions.ignoreMessage).toBeDefined();
});
});

it('should resolve when toolsChecker resolves', () => {
checkReqs.__set__({
os_platform_is_supported: () => true
});
spyOn(shell, 'exec').and.returnValue({ code: 1 });

return checkReqs.check_cocoapods(toolsChecker).then(() => {
expect(shell.exec).toHaveBeenCalled();
});
});

it('should reject when toolsChecker rejects', () => {
checkReqs.__set__({
os_platform_is_supported: () => true
});
const testError = new Error();
toolsChecker.and.callFake(() => Promise.reject(testError));

return checkReqs.check_cocoapods(toolsChecker).then(
() => fail('Expected promise to be rejected'),
err => expect(err).toBe(testError)
);
});
});
});

0 comments on commit 1f753f6

Please sign in to comment.