UNPKG

zenith-gen

Version:

A CLI tool designed to streamline the creation of projects within the Zenith Inova ecosystem, providing optimized configurations and modern development tools.

74 lines (64 loc) 2.12 kB
import inquirer from 'inquirer'; import chalk from 'chalk'; import { execSync } from 'child_process'; import fs from 'fs-extra'; import path from 'path'; import { storybookMainConfig, storybookPrevConfig, } from '../templates/storybook.config'; import { PackageManager } from '../types/packageManager'; export async function storybookPrompt(): Promise<boolean> { const useStorybook = await inquirer .prompt([ { type: 'confirm', name: 'useStorybook', message: 'Would you like to use Storybook?', default: true, }, ]) .then(ans => ans.useStorybook); return useStorybook; } export async function storybookConfigsPrompt() { const storybookConfigs = await inquirer.prompt([ { type: 'confirm', name: 'useStorybookDefaultConfig', message: "Would you like to use Storybook's default config?", default: false, }, { type: 'confirm', name: 'useChromatic', message: 'Would you like to use Chromatic?', default: true, }, ]); return storybookConfigs; } export function installStorybook(packageManager: PackageManager): void { console.log(chalk.blue('Setting up Storybook...')); let storybookInstall = `${packageManager} create storybook@latest --no-dev`; execSync(storybookInstall, { stdio: 'inherit' }); } export function configureStorybook( projectPath: string, useChromatic: boolean, ): void { try { fs.writeFileSync( path.join(projectPath, '.storybook/main.ts'), storybookMainConfig(useChromatic), ); fs.unlinkSync(path.join(projectPath, '.storybook/preview.ts')); console.log('Deleted .storybook/preview.ts'); fs.writeFileSync( path.join(projectPath, '.storybook/preview.tsx'), storybookPrevConfig, ); } catch (error) { console.log(error); } }