Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ Skip git repository initialization.

Replaces the directory if it already exists

#### `--yarn-config-options <string>`

Passes extra options that will be added to `.yarnrc.yml` file, format: key=value,key2=value2.

### `upgrade`

Usage:
Expand Down
13 changes: 13 additions & 0 deletions packages/cli/src/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,18 @@ export default {
name: '--replace-directory [boolean]',
description: 'Replaces the directory if it already exists.',
},
{
name: '--yarn-config-options <string>',
description:
'Passes extra options that will be added to `.yarnrc.yml` file, format: key=value,key2=value2.',
parse: (val: string): Record<string, string> => {
return Object.fromEntries(
val.split(',').map((option) => {
const [key, value] = option.split('=');
return [key, value];
}),
);
},
},
],
};
5 changes: 5 additions & 0 deletions packages/cli/src/commands/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Options = {
platformName?: string;
skipGitInit?: boolean;
replaceDirectory?: string | boolean;
yarnConfigOptions?: Record<string, string>;
};

interface TemplateOptions {
Expand All @@ -67,6 +68,7 @@ interface TemplateOptions {
installCocoaPods?: string | boolean;
version?: string;
replaceDirectory?: string | boolean;
yarnConfigOptions?: Record<string, string>;
}

interface TemplateReturnType {
Expand Down Expand Up @@ -199,6 +201,7 @@ async function createFromTemplate({
packageName,
installCocoaPods,
replaceDirectory,
yarnConfigOptions,
}: TemplateOptions): Promise<TemplateReturnType> {
logger.debug('Initializing new project');
// Only print out the banner if we're not in a CI
Expand Down Expand Up @@ -244,6 +247,7 @@ async function createFromTemplate({
templateUri,
templateSourceDir,
packageManager,
yarnConfigOptions,
);

loader.succeed();
Expand Down Expand Up @@ -419,6 +423,7 @@ async function createProject(
installCocoaPods: options.installPods,
version,
replaceDirectory: options.replaceDirectory,
yarnConfigOptions: options.yarnConfigOptions,
});
}

Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/commands/init/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export async function installTemplatePackage(
templateName: string,
root: string,
packageManager: PackageManager.PackageManager,
yarnConfigOptions?: Record<string, string>,
) {
logger.debug(`Installing template from ${templateName}`);

Expand Down Expand Up @@ -47,6 +48,13 @@ export async function installTemplatePackage(
['config', 'set', 'nmHoistingLimits', 'workspaces'],
options,
);

for (let key in yarnConfigOptions) {
if (yarnConfigOptions.hasOwnProperty(key)) {
let value = yarnConfigOptions[key];
executeCommand('yarn', ['config', 'set', key, value], options);
}
}
}

return PackageManager.install([templateName], {
Expand Down