Skip to content

Commit

Permalink
Merge pull request #18389 from storybookjs/feat/cli-add-additional-files
Browse files Browse the repository at this point in the history
CLI: Add additional files api to sb repro
  • Loading branch information
shilman committed Jun 6, 2022
2 parents 6aa3f16 + 4f5b90e commit 9d3e860
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/cli/src/repro-generators/configs.ts
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
@@ -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

0 comments on commit 9d3e860

Please sign in to comment.