Skip to content

Commit

Permalink
set hash in cache when initializing new project
Browse files Browse the repository at this point in the history
  • Loading branch information
TMisiukiewicz committed Sep 19, 2023
1 parent b9b2ba9 commit 979f872
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions __e2e__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,19 @@ test('init uses npm as the package manager with --npm', () => {
expect(fs.existsSync(path.join(initDirPath, file))).toBe(true);
});
});

test('should prompt a question about pods installation', () => {
createCustomTemplateFiles();

const {stdout} = runCLI(DIR, [
'init',
'--template',
templatePath,
'TestInit',
]);

expect(stdout).toContain('Do you want to install CocoaPods now?');

// make sure we don't leave garbage
expect(fs.readdirSync(DIR)).toContain('custom');
});
13 changes: 13 additions & 0 deletions packages/cli/src/commands/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
logger,
getLoader,
Loader,
cacheManager,
} from '@react-native-community/cli-tools';
import {installPods} from '@react-native-community/cli-platform-ios';
import {
Expand All @@ -26,6 +27,7 @@ import TemplateAndVersionError from './errors/TemplateAndVersionError';
import {getBunVersionIfAvailable} from '../../tools/bun';
import {getNpmVersionIfAvailable} from '../../tools/npm';
import {getYarnVersionIfAvailable} from '../../tools/yarn';
import {createHash} from 'crypto';

const DEFAULT_VERSION = 'latest';

Expand Down Expand Up @@ -87,6 +89,15 @@ function getTemplateName(cwd: string) {
return name;
}

//set cache to empty string to prevent installing cocoapods on freshly created project
function setEmptyHashForCachedDependencies(projectName: string) {
cacheManager.set(
projectName,
'dependencies',
createHash('md5').update('').digest('hex'),
);
}

async function createFromTemplate({
projectName,
templateUri,
Expand Down Expand Up @@ -181,6 +192,7 @@ async function createFromTemplate({
if (installPodsValue === 'true') {
await installPods(loader);
loader.succeed();
setEmptyHashForCachedDependencies(projectName);
} else if (installPodsValue === 'undefined') {
const {installCocoapods} = await prompt({
type: 'confirm',
Expand All @@ -193,6 +205,7 @@ async function createFromTemplate({
if (installCocoapods) {
await installPods(loader);
loader.succeed();
setEmptyHashForCachedDependencies(projectName);
}
}
}
Expand Down

0 comments on commit 979f872

Please sign in to comment.