Skip to content

Commit

Permalink
feat: apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Dec 13, 2023
1 parent 6918762 commit 0e66055
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
13 changes: 13 additions & 0 deletions __e2e__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,16 @@ test('init --platform-name should work for out of tree platform', () => {

expect(dirFiles.length).toBeGreaterThan(0);
});

test('init should contain Cocoapods instructions when pods are not installed automatically', () => {
createCustomTemplateFiles();

const {stdout} = runCLI(DIR, ['init', PROJECT_NAME, '--skip-install']);
expect(stdout).toContain('Install Cocoapods');

// make sure we don't leave garbage
expect(fs.readdirSync(DIR)).toContain('custom');

let dirFiles = fs.readdirSync(path.join(DIR, PROJECT_NAME));
expect(dirFiles.length).toBeGreaterThan(0);
});
22 changes: 12 additions & 10 deletions packages/cli/src/commands/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ interface TemplateOptions {
}

interface TemplateReturnType {
automaticPodsInstallation?: boolean;
didInstallPods?: boolean;
}

function doesDirectoryExist(dir: string) {
Expand Down Expand Up @@ -119,7 +119,7 @@ async function createFromTemplate({
}: TemplateOptions): Promise<TemplateReturnType> {
logger.debug('Initializing new project');
logger.log(banner);
let automaticPodsInstallation = String(installCocoaPods) === 'true';
let didInstallPods = String(installCocoaPods) === 'true';
let packageManager = pm;

if (pm) {
Expand Down Expand Up @@ -200,7 +200,7 @@ async function createFromTemplate({
const installPodsValue = String(installCocoaPods);

if (installPodsValue === 'true') {
automaticPodsInstallation = true;
didInstallPods = true;
await installPods(loader);
loader.succeed();
setEmptyHashForCachedDependencies(projectName);
Expand All @@ -212,10 +212,10 @@ async function createFromTemplate({
'Only needed if you run your project in Xcode directly',
)}`,
});
automaticPodsInstallation = installCocoapods;
didInstallPods = installCocoapods;
logger.log('\n');
logger.info(
`To enable automatic CocoaPods installation when building for iOS you can create react-native.config.js with automaticPodsInstallation field. \n${chalk.reset.dim(
`💡 To enable automatic CocoaPods installation when building for iOS you can create react-native.config.js with automaticPodsInstallation field. \n${chalk.reset.dim(
`For more details, see ${chalk.underline(
'https://github.com/react-native-community/cli/blob/main/docs/projects.md#projectiosautomaticpodsinstallation',
)}`,
Expand All @@ -235,14 +235,16 @@ async function createFromTemplate({
}
} catch (e) {
if (e instanceof Error) {
logger.error(e.message);
logger.error(
'Installing pods failed. This doesn\'t affect project initialization and you can safely proceed. \nHowever, you will need to install pods manually when running iOS, follow additional steps in "Run instructions for iOS" section.\n',
);
}
loader.fail();
automaticPodsInstallation = false;
didInstallPods = false;
} finally {
fs.removeSync(templateSourceDir);
}
return {automaticPodsInstallation};
return {didInstallPods};
}

async function installDependencies({
Expand Down Expand Up @@ -367,7 +369,7 @@ export default (async function initialize(
return;
}

const {automaticPodsInstallation} = await createProject(
const {didInstallPods} = await createProject(
projectName,
directoryName,
version,
Expand All @@ -381,6 +383,6 @@ export default (async function initialize(
}

printRunInstructions(projectFolder, projectName, {
showPodsInstructions: !automaticPodsInstallation,
showPodsInstructions: !didInstallPods,
});
});

0 comments on commit 0e66055

Please sign in to comment.