How to use CURATED_TEMPLATES method in storybook-root

Best JavaScript code snippet using storybook-root

repro.ts

Source:repro.ts Github

copy

Full Screen

1import prompts from 'prompts';2import fs from 'fs';3import path from 'path';4import chalk from 'chalk';5import boxen from 'boxen';6import dedent from 'ts-dedent';7import { createAndInit, exec } from './repro-generators/scripts';8import * as configs from './repro-generators/configs';9import type { Parameters } from './repro-generators/configs';10import { SupportedFrameworks } from './project_types';11const logger = console;12interface ReproOptions {13 outputDirectory: string;14 framework?: SupportedFrameworks;15 list?: boolean;16 template?: string;17 e2e?: boolean;18 generator?: string;19 pnp?: boolean;20}21const TEMPLATES = configs as Record<string, Parameters>;22// Create a curate list of template because some of them only make sense in E2E23// context, fon instance react_in_yarn_workspace24const CURATED_TEMPLATES = Object.fromEntries(25 Object.entries(configs).filter((entry) => entry[0] !== 'react_in_yarn_workspace')26) as Record<string, Parameters>;27const FRAMEWORKS = Object.values(CURATED_TEMPLATES).reduce<28 Record<SupportedFrameworks, Parameters[]>29>((acc, cur) => {30 acc[cur.framework] = [...(acc[cur.framework] || []), cur];31 return acc;32}, {} as Record<SupportedFrameworks, Parameters[]>);33export const repro = async ({34 outputDirectory,35 list,36 template,37 framework,38 generator,39 e2e,40 pnp,41}: ReproOptions) => {42 logger.info(43 boxen(44 dedent`45 🤗 Welcome to ${chalk.yellow('sb repro')}! 🤗 46 Create a ${chalk.green('new project')} to minimally reproduce Storybook issues.47 48 1. select an environment that most closely matches your project setup.49 2. select a location for the reproduction, outside of your project.50 51 After the reproduction is ready, we'll guide you through the next steps.52 `.trim(),53 { borderStyle: 'round', padding: 1, borderColor: '#F1618C' } as any54 )55 );56 if (list) {57 logger.info('🌈 Available templates');58 Object.entries(FRAMEWORKS).forEach(([fmwrk, templates]) => {59 logger.info(fmwrk);60 templates.forEach((t) => logger.info(`- ${t.name}`));61 if (fmwrk === 'other') {62 logger.info('- blank');63 }64 });65 return;66 }67 let selectedTemplate = template;68 let selectedFramework = framework;69 if (!selectedTemplate && !generator) {70 if (!selectedFramework) {71 const { framework: frameworkOpt } = await prompts({72 type: 'select',73 message: '🌈 Select the repro framework',74 name: 'framework',75 choices: Object.keys(FRAMEWORKS).map((f) => ({ title: f, value: f })),76 });77 selectedFramework = frameworkOpt;78 }79 if (!selectedFramework) {80 throw new Error('🚨 Repro: please select a framework!');81 }82 selectedTemplate = (83 await prompts({84 type: 'select',85 message: '📝 Select the repro base template',86 name: 'template',87 choices: FRAMEWORKS[selectedFramework as SupportedFrameworks].map((f) => ({88 title: f.name,89 value: f.name,90 })),91 })92 ).template;93 }94 const selectedConfig = !generator95 ? TEMPLATES[selectedTemplate]96 : {97 name: 'custom',98 version: 'custom',99 generator,100 };101 if (!selectedConfig) {102 throw new Error('🚨 Repro: please specify a valid template type');103 }104 let selectedDirectory = outputDirectory;105 if (!selectedDirectory) {106 const { directory } = await prompts({107 type: 'text',108 message: 'Enter the output directory',109 name: 'directory',110 initial: selectedConfig.name,111 validate: (directoryName) =>112 fs.existsSync(directoryName)113 ? `${directoryName} already exists. Please choose another name.`114 : true,115 });116 selectedDirectory = directory;117 }118 try {119 const cwd = path.isAbsolute(selectedDirectory)120 ? selectedDirectory121 : path.join(process.cwd(), selectedDirectory);122 logger.info(`🏃 Running ${selectedTemplate} into ${cwd}`);123 await createAndInit(cwd, selectedConfig, {124 e2e: !!e2e,125 pnp: !!pnp,126 });127 if (!e2e) {128 await initGitRepo(cwd);129 }130 logger.info(131 boxen(132 dedent`133 🎉 Your Storybook reproduction project is ready to use! 🎉134 ${chalk.yellow(`cd ${selectedDirectory}`)}135 ${chalk.yellow(`yarn storybook`)}136 Once you've recreated the problem you're experiencing, please:137 138 1. Document any additional steps in ${chalk.cyan('README.md')}139 2. Publish the repository to github140 3. Link to the repro repository in your issue141 Having a clean repro helps us solve your issue faster! 🙏142 `.trim(),143 { borderStyle: 'round', padding: 1, borderColor: '#F1618C' } as any144 )145 );146 } catch (error) {147 logger.error('🚨 Failed to create repro');148 throw new Error(error);149 }150};151const initGitRepo = async (cwd: string) => {152 await exec('git init', { cwd });153 await exec('echo "node_modules" >> .gitignore', { cwd });154 await exec('git add --all', { cwd });155 await exec('git commit -am "added storybook"', { cwd });156 await exec('git tag repro-base', { cwd });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storiesOf } from "@storybook/react";2import { withRootDecorator } from "storybook-root-decorator";3import { CURATED_TEMPLATES } from "storybook-root-decorator";4import { withKnobs } from "@storybook/addon-knobs";5import { withInfo } from "@storybook/addon-info";6import { withA11y } from "@storybook/addon-a11y";7storiesOf("Test", module)8 .addDecorator(withRootDecorator(CURATED_TEMPLATES))9 .addDecorator(withKnobs)10 .addDecorator(withInfo)11 .addDecorator(withA11y)12 .add("test", () => <div>test</div>);13import React from "react";14import { withA11y } from "@storybook/addon-a11y";15import { withInfo } from "@storybook/addon-info";16import { withKnobs } from "@storybook/addon-knobs";17import { withRootDecorator } from "storybook-root-decorator";18const CURATED_TEMPLATES = {19};20export { CURATED_TEMPLATES };21import React from "react";22import { ThemeProvider } from "styled-components";23import { theme } from "theme";24import { GlobalStyles } from "theme/global-styles";25export const withRootDecorator = (templates = {}) => story => {26 const storyWithTemplates = Object.keys(templates).reduce(27 (acc, template) => {28 return template(acc);29 },30 );31 return (32 <ThemeProvider theme={theme}>33 {storyWithTemplates()}34 );35};36export default withRootDecorator;37import { createGlobalStyle } from "styled-components";38 html {39 box-sizing: border-box;40 }41 *, *:before, *:after {42 box-sizing: inherit;43 }44 body {45 margin: 0;46 padding: 0;47 font-family: sans-serif;

Full Screen

Using AI Code Generation

copy

Full Screen

1import { storiesOf } from 'storybook-root';2import { storiesOf } from 'storybook-root';3import { storiesOf } from 'storybook-root';4import { storiesOf } from 'storybook-root';5import { storiesOf } from 'storybook-root';6import { storiesOf } from 'storybook-root';7import { storiesOf } from 'storybook-root';8import { storiesOf } from 'storybook-root';9import { storiesOf } from 'storybook-root';10import { storiesOf } from 'storybook-root';11import { storiesOf } from 'storybook-root';12import { storiesOf } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1const { CURATED_TEMPLATES } = require('storybook-root');2const storybook = new Storybook({3});4const { CUSTOM_TEMPLATES } = require('storybook-root');5const storybook = new Storybook({6});7const { CUSTOM_TEMPLATES } = require('storybook-root');8const storybook = new Storybook({9});10const { CUSTOM_TEMPLATES } = require('storybook-root');11const storybook = new Storybook({12});13const { CUSTOM_TEMPLATES } = require('storybook-root');14const storybook = new Storybook({15});16const { CUSTOM_TEMPLATES } = require('storybook-root');17const storybook = new Storybook({18});19const { CUSTOM_TEMPLATES } = require('storybook-root');20const storybook = new Storybook({21});22const { CUSTOM_TEMPLATES } = require('storybook-root');23const storybook = new Storybook({24});25const { CUSTOM_TEMPLATES } = require('storybook-root');26const storybook = new Storybook({27});28const { CUSTOM_TEMPLATES } = require('storybook-root');29const storybook = new Storybook({30});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { CURATED_TEMPLATES } from 'storybook-root-config';2import { CUSTOM_TEMPLATE } from './custom-template';3CURATED_TEMPLATES.push(CUSTOM_TEMPLATE);4import { Template } from '@storybook/addon-docs/blocks';5export const CUSTOM_TEMPLATE = {6 template: Template.bind({}),7 templateProps: {8 },9};10import { CUSTOM_TEMPLATE } from '../test';11export const parameters = {12 docs: {13 },14};15import { CUSTOM_TEMPLATE } from '../test';16 {17 options: {18 templates: {19 },20 },21 },22];

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful