Skip to content

Commit

Permalink
add --install-pods flag to init
Browse files Browse the repository at this point in the history
  • Loading branch information
TMisiukiewicz committed Sep 18, 2023
1 parent 5a35401 commit 1876e6a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
4 changes: 4 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ module.exports = {

Skip dependencies installation

#### `--install-pods [boolean]`

Determine if CocoaPods should be installed when initializing a project. If set to `true` it will install pods, if set to `false`, it will skip the step entirely. If not used, prompt will be displayed

#### `--npm`
> [!WARNING]
> `--npm` is deprecated and will be removed in the future. Please use `--pm npm` instead.
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/src/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export default {
name: '--skip-install',
description: 'Skips dependencies installation step',
},
{
name: '--install-pods [boolean]',
description:
'Determine if CocoaPods should be installed when initializing a project',
},
{
name: '--package-name <string>',
description:
Expand Down
30 changes: 21 additions & 9 deletions packages/cli/src/commands/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Options = {
skipInstall?: boolean;
version?: string;
packageName?: string;
installPods?: string;
};

interface TemplateOptions {
Expand All @@ -50,6 +51,7 @@ interface TemplateOptions {
projectTitle?: string;
skipInstall?: boolean;
packageName?: string;
installCocoaPods?: string;
}

function doesDirectoryExist(dir: string) {
Expand Down Expand Up @@ -94,6 +96,7 @@ async function createFromTemplate({
projectTitle,
skipInstall,
packageName,
installCocoaPods,
}: TemplateOptions) {
logger.debug('Initializing new project');
logger.log(banner);
Expand Down Expand Up @@ -173,16 +176,24 @@ async function createFromTemplate({
});

if (process.platform === 'darwin') {
const {installCocoapods} = await prompt({
type: 'confirm',
name: 'installCocoapods',
message: `Do you want to install CocoaPods? ${chalk.reset.dim(
'Only needed if you run your project in Xcode directly',
)}`,
});

if (installCocoapods) {
const installPodsValue = String(installCocoaPods);

if (installPodsValue === 'true') {
await installPods(loader);
loader.succeed();
} else if (installPodsValue === 'undefined') {
const {installCocoapods} = await prompt({
type: 'confirm',
name: 'installCocoapods',
message: `Do you want to install CocoaPods? ${chalk.reset.dim(
'Only needed if you run your project in Xcode directly',
)}`,
});

if (installCocoapods) {
await installPods(loader);
loader.succeed();
}
}
}
} else {
Expand Down Expand Up @@ -261,6 +272,7 @@ async function createProject(
projectTitle: options.title,
skipInstall: options.skipInstall,
packageName: options.packageName,
installCocoaPods: options.installPods,
});
}

Expand Down

0 comments on commit 1876e6a

Please sign in to comment.