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: Add additional files api to sb repro #18389

Merged
merged 5 commits into from
Jun 6, 2022
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
7 changes: 6 additions & 1 deletion lib/cli/src/repro-generators/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export interface Parameters {
autoDetect?: boolean;
/** Dependencies to add before building Storybook */
additionalDeps?: string[];
/** Files to add before installing Storybook */
additionalFiles?: {
path: string;
contents: string;
}[];
/** Add typescript dependency and creates a tsconfig.json file */
typescript?: boolean;
/** Merge configurations to main.js before running the tests */
Expand Down Expand Up @@ -119,7 +124,7 @@ const baseAngular: Parameters = {
framework: 'angular',
name: 'angular',
version: 'latest',
generator: `npx -p @angular/cli@{{version}} ng new {{appName}} --routing=true --minimal=true --style=scss --skipInstall=true --strict`,
generator: `npx -p @angular/cli@{{version}} ng new {{appName}} --routing=true --minimal=true --style=scss --skip-install=true --strict`,
};

export const angular10: Parameters = {
Expand Down
18 changes: 17 additions & 1 deletion lib/cli/src/repro-generators/scripts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { readJSON, writeJSON } from 'fs-extra';
import { readJSON, writeJSON, outputFile } from 'fs-extra';
import shell, { ExecOptions } from 'shelljs';
import chalk from 'chalk';
import { cra, cra_typescript } from './configs';
Expand All @@ -22,6 +22,11 @@ export interface Parameters {
ensureDir?: boolean;
/** Dependencies to add before building Storybook */
additionalDeps?: string[];
/** Files to add before installing Storybook */
additionalFiles?: {
path: string;
contents: string;
}[];
/** Add typescript dependency and creates a tsconfig.json file */
typescript?: boolean;
}
Expand Down Expand Up @@ -136,6 +141,16 @@ const generate = async ({ cwd, name, appName, version, generator }: Options) =>
);
};

const addAdditionalFiles = async ({ additionalFiles, cwd }: Options) => {
logger.info(`⤵️ Adding required files`);

await Promise.all(
additionalFiles.map(async (file) => {
await outputFile(path.resolve(cwd, file.path), file.contents, { encoding: 'UTF-8' });
})
);
};

const initStorybook = async ({ cwd, autoDetect = true, name, e2e }: Options) => {
const type = autoDetect ? '' : `--type ${name}`;
const linkable = e2e ? '' : '--linkable';
Expand Down Expand Up @@ -228,6 +243,7 @@ export const createAndInit = async (
logger.log();

await doTask(generate, { ...options, cwd: options.creationPath });
await doTask(addAdditionalFiles, { ...options, cwd }, !!options.additionalFiles);
if (e2e) {
await doTask(addPackageResolutions, options);
}
Expand Down