Skip to content

Commit

Permalink
fix: ensure .storbook exists on eject
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Mar 3, 2022
1 parent 9be451f commit 30e6098
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync } from 'fs'
import { existsSync, mkdirSync } from 'fs'
import path from 'path'
import pathe from 'pathe'
import vueOptions from '@storybook/vue/dist/cjs/server/options'
Expand Down Expand Up @@ -211,9 +211,13 @@ function generateStorybookFiles (options) {
export function eject (options: StorybookOptions) {
const configDir = path.resolve(options.rootDir, '.storybook')
const templatesRoot = path.resolve(__dirname, '../storybook')
if (!options.force && existsSync(configDir)) {
logger.warn('Storybook is already ejected, use `--force` to overwrite files.')
return
if (existsSync(configDir)) {
if (!options.force) {
logger.warn('Storybook is already ejected, use `--force` to overwrite files.')
return
}
} else {
mkdirSync(configDir)
}
compileTemplate(path.resolve(templatesRoot, 'eject', 'main.js'), path.join(configDir, 'main.js'), {})
compileTemplate(path.resolve(templatesRoot, 'eject', 'middleware.js'), path.join(configDir, 'middleware.js'), {})
Expand Down

0 comments on commit 30e6098

Please # to comment.