Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Remove unused arg from initiate and sandbox functions #26498

Merged
merged 1 commit into from
Mar 14, 2024
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: 2 additions & 2 deletions code/lib/cli/src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ command('init')
.option('-b --builder <webpack5 | vite>', 'Builder library')
.option('-l --linkable', 'Prepare installation for link (contributor helper)')
.action((options: CommandOptions) => {
initiate(options, pkg).catch(() => process.exit(1));
initiate(options).catch(() => process.exit(1));
});

command('add <addon>')
Expand Down Expand Up @@ -155,7 +155,7 @@ command('sandbox [filterValue]')
.option('-o --output <outDir>', 'Define an output directory')
.option('--no-init', 'Whether to download a template without an initialized Storybook', false)
.action((filterValue, options) =>
sandbox({ filterValue, ...options }, pkg).catch((e) => {
sandbox({ filterValue, ...options }).catch((e) => {
logger.error(e);
process.exit(1);
})
Expand Down
10 changes: 3 additions & 7 deletions code/lib/cli/src/initiate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { appendFile, readFile } from 'fs/promises';
import type { PackageJson } from 'read-pkg-up';
import findUp from 'find-up';
import chalk from 'chalk';
import prompts from 'prompts';
Expand Down Expand Up @@ -228,10 +227,7 @@ const projectTypeInquirer = async (
process.exit(0);
};

export async function doInitiate(
options: CommandOptions,
pkg: PackageJson
): Promise<
export async function doInitiate(options: CommandOptions): Promise<
| {
shouldRunDev: true;
projectType: ProjectType;
Expand Down Expand Up @@ -409,14 +405,14 @@ export async function doInitiate(
};
}

export async function initiate(options: CommandOptions, pkg: PackageJson): Promise<void> {
export async function initiate(options: CommandOptions): Promise<void> {
const initiateResult = await withTelemetry(
'init',
{
cliOptions: options,
printError: (err) => !err.handled && logger.error(err),
},
() => doInitiate(options, pkg)
() => doInitiate(options)
);

if (initiateResult?.shouldRunDev) {
Expand Down
21 changes: 10 additions & 11 deletions code/lib/cli/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import invariant from 'tiny-invariant';
import { lt, prerelease } from 'semver';
import type { Template, TemplateKey } from './sandbox-templates';
import { allTemplates as TEMPLATES } from './sandbox-templates';
import type { PackageJson, PackageManagerName } from '@storybook/core-common';
import type { PackageManagerName } from '@storybook/core-common';
import { JsPackageManagerFactory } from '@storybook/core-common';
import { versions } from '@storybook/core-common';
import { doInitiate } from './initiate';
Expand All @@ -28,10 +28,12 @@ type Choice = keyof typeof TEMPLATES;

const toChoices = (c: Choice): prompts.Choice => ({ title: TEMPLATES[c].name, value: c });

export const sandbox = async (
{ output: outputDirectory, filterValue, init, ...options }: SandboxOptions,
pkg: PackageJson
) => {
export const sandbox = async ({
output: outputDirectory,
filterValue,
init,
...options
}: SandboxOptions) => {
// Either get a direct match when users pass a template id, or filter through all templates
let selectedConfig: Template | undefined = TEMPLATES[filterValue as TemplateKey];
let templateId: Choice | null = selectedConfig ? (filterValue as TemplateKey) : null;
Expand Down Expand Up @@ -222,12 +224,9 @@ export const sandbox = async (
const before = process.cwd();
process.chdir(templateDestination);
// we run doInitiate, instead of initiate, to avoid sending this init event to telemetry, because it's not a real world project
await doInitiate(
{
...options,
},
pkg
);
await doInitiate({
...options,
});
process.chdir(before);
}
} catch (err) {
Expand Down
Loading