<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
93 lines
2.3 KiB
TypeScript
93 lines
2.3 KiB
TypeScript
import { execSync } from 'child_process';
|
|
import { platform } from 'os';
|
|
import * as chalk from 'chalk';
|
|
import { GeneratorCallback, logger } from '@nx/devkit';
|
|
import { existsSync } from 'fs-extra';
|
|
import { join } from 'path';
|
|
|
|
const podInstallErrorMessage = `
|
|
Running ${chalk.bold('pod install')} failed, see above.
|
|
Do you have CocoaPods (https://cocoapods.org/) installed?
|
|
|
|
Check that your XCode path is correct:
|
|
${chalk.bold('sudo xcode-select --print-path')}
|
|
|
|
If the path is wrong, switch the path: (your path may be different)
|
|
${chalk.bold('sudo xcode-select --switch /Applications/Xcode.app')}
|
|
`;
|
|
|
|
/**
|
|
* Run pod install on ios directory
|
|
* @param iosDirectory ios directory that contains Podfile
|
|
* @returns resolve with 0 if not error, reject with error otherwise
|
|
*/
|
|
export function runPodInstall(
|
|
iosDirectory: string,
|
|
install: boolean = true,
|
|
options: {
|
|
buildFolder?: string;
|
|
repoUpdate?: boolean;
|
|
deployment?: boolean;
|
|
useBundler?: boolean;
|
|
} = {
|
|
buildFolder: './build',
|
|
repoUpdate: false,
|
|
deployment: false,
|
|
useBundler: false,
|
|
}
|
|
): GeneratorCallback {
|
|
return () => {
|
|
if (platform() !== 'darwin') {
|
|
logger.info('Skipping `pod install` on non-darwin platform');
|
|
return;
|
|
}
|
|
|
|
if (!install || !existsSync(join(iosDirectory, 'Podfile'))) {
|
|
logger.info('Skipping `pod install`');
|
|
return;
|
|
}
|
|
|
|
logger.info(`Running \`pod install\` from "${iosDirectory}"`);
|
|
|
|
return podInstall(iosDirectory, options);
|
|
};
|
|
}
|
|
|
|
export function podInstall(
|
|
iosDirectory: string,
|
|
options: {
|
|
buildFolder?: string;
|
|
repoUpdate?: boolean;
|
|
deployment?: boolean;
|
|
useBundler?: boolean;
|
|
} = {
|
|
buildFolder: './build',
|
|
repoUpdate: false,
|
|
deployment: false,
|
|
useBundler: false,
|
|
}
|
|
) {
|
|
try {
|
|
if (existsSync(join(iosDirectory, '.xcode.env'))) {
|
|
execSync('touch .xcode.env', {
|
|
cwd: iosDirectory,
|
|
stdio: 'inherit',
|
|
windowsHide: true,
|
|
});
|
|
}
|
|
const podCommand = [
|
|
options.useBundler ? 'bundle exec pod install' : 'pod install',
|
|
options.repoUpdate ? '--repo-update' : '',
|
|
options.deployment ? '--deployment' : '',
|
|
].join(' ');
|
|
execSync(podCommand, {
|
|
cwd: iosDirectory,
|
|
stdio: 'inherit',
|
|
windowsHide: true,
|
|
});
|
|
} catch (e) {
|
|
logger.error(podInstallErrorMessage);
|
|
throw e;
|
|
}
|
|
}
|