Skip to content

Commit

Permalink
Merge pull request #26099 from storybookjs/norbert/add-line-to-gitign…
Browse files Browse the repository at this point in the history
…ore-file

CLI: Add line ignoring storybook's `.log` files upon `init`
  • Loading branch information
ndelangen authored Feb 20, 2024
2 parents 018f58a + 998bcaf commit b5f8d9b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions code/lib/cli/src/initiate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
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';
import { telemetry } from '@storybook/telemetry';
Expand All @@ -10,6 +12,7 @@ import {
JsPackageManagerFactory,
commandLog,
paddedLog,
getProjectRoot,
} from '@storybook/core-common';
import type { JsPackageManager } from '@storybook/core-common';

Expand Down Expand Up @@ -369,6 +372,15 @@ export async function doInitiate(
return { shouldRunDev: false };
}

const foundGitIgnoreFile = await findUp('.gitignore');
const rootDirectory = getProjectRoot();
if (foundGitIgnoreFile && foundGitIgnoreFile.includes(rootDirectory)) {
const contents = await readFile(foundGitIgnoreFile, 'utf-8');
if (!contents.includes('*storybook.log')) {
await appendFile(foundGitIgnoreFile, '\n*storybook.log');
}
}

const storybookCommand =
projectType === ProjectType.ANGULAR
? `ng run ${installResult.projectName}:storybook`
Expand Down

0 comments on commit b5f8d9b

Please sign in to comment.