How to use directoryFromConfig method in storybook-root

Best JavaScript code snippet using storybook-root

normalize-stories.ts

Source:normalize-stories.ts Github

copy

Full Screen

1import fs from 'fs';2import path from 'path';3import deprecate from 'util-deprecate';4import dedent from 'ts-dedent';5import { scan } from 'picomatch';6import slash from 'slash';7import type { StoriesEntry, NormalizedStoriesSpecifier } from '../types';8import { normalizeStoryPath } from './paths';9import { globToRegexp } from './glob-to-regexp';10const DEFAULT_TITLE_PREFIX = '';11const DEFAULT_FILES = '**/*.stories.@(mdx|tsx|ts|jsx|js)';12// LEGACY support for bad glob patterns we had in SB 5 - remove in SB713const fixBadGlob = deprecate(14 (match: RegExpMatchArray) => {15 return match.input.replace(match[1], `@${match[1]}`);16 },17 dedent`18 You have specified an invalid glob, we've attempted to fix it, please ensure that the glob you specify is valid. See: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#correct-globs-in-mainjs19 `20);21const detectBadGlob = (val: string) => {22 const match = val.match(/\.(\([^)]+\))/);23 if (match) {24 return fixBadGlob(match);25 }26 return val;27};28const isDirectory = (configDir: string, entry: string) => {29 try {30 return fs.lstatSync(path.resolve(configDir, entry)).isDirectory();31 } catch (err) {32 return false;33 }34};35export const getDirectoryFromWorkingDir = ({36 configDir,37 workingDir,38 directory,39}: NormalizeOptions & { directory: string }) => {40 const directoryFromConfig = path.resolve(configDir, directory);41 const directoryFromWorking = path.relative(workingDir, directoryFromConfig);42 // relative('/foo', '/foo/src') => 'src'43 // but we want `./src` to match importPaths44 return normalizeStoryPath(directoryFromWorking);45};46export const normalizeStoriesEntry = (47 entry: StoriesEntry,48 { configDir, workingDir }: NormalizeOptions49): NormalizedStoriesSpecifier => {50 let specifierWithoutMatcher: Omit<NormalizedStoriesSpecifier, 'importPathMatcher'>;51 if (typeof entry === 'string') {52 const fixedEntry = detectBadGlob(entry);53 const globResult = scan(fixedEntry);54 if (globResult.isGlob) {55 const directory = globResult.prefix + globResult.base;56 const files = globResult.glob;57 specifierWithoutMatcher = {58 titlePrefix: DEFAULT_TITLE_PREFIX,59 directory,60 files,61 };62 } else if (isDirectory(configDir, entry)) {63 specifierWithoutMatcher = {64 titlePrefix: DEFAULT_TITLE_PREFIX,65 directory: entry,66 files: DEFAULT_FILES,67 };68 } else {69 specifierWithoutMatcher = {70 titlePrefix: DEFAULT_TITLE_PREFIX,71 directory: path.dirname(entry),72 files: path.basename(entry),73 };74 }75 } else {76 specifierWithoutMatcher = {77 titlePrefix: DEFAULT_TITLE_PREFIX,78 files: DEFAULT_FILES,79 ...entry,80 };81 }82 // We are going to be doing everything with node importPaths which use83 // URL format, i.e. `/` as a separator, so let's make sure we've normalized84 const files = slash(specifierWithoutMatcher.files);85 // At this stage `directory` is relative to `main.js` (the config dir)86 // We want to work relative to the working dir, so we transform it here.87 const { directory: directoryRelativeToConfig } = specifierWithoutMatcher;88 const directory = slash(89 getDirectoryFromWorkingDir({90 configDir,91 workingDir,92 directory: directoryRelativeToConfig,93 })94 ).replace(/\/$/, '');95 // Now make the importFn matcher.96 const importPathMatcher = globToRegexp(`${directory}/${files}`);97 return {98 ...specifierWithoutMatcher,99 directory,100 importPathMatcher,101 };102};103interface NormalizeOptions {104 configDir: string;105 workingDir: string;106}107export const normalizeStories = (entries: StoriesEntry[], options: NormalizeOptions) =>...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { directoryFromConfig } = require('storybook-root-dirs');2const { getStorybookRootDir } = require('storybook-root-dirs');3const { getStorybookRootDir } = require('storybook-root-dirs');4const { getStorybookRootDir } = require('storybook-root-dirs');5const { getStorybookRootDir } = require('storybook-root-dirs');6const { getStorybookRootDir } = require('storybook-root-dirs');7const { getStorybookRootDir } = require('storybook-root-dirs');8const { getStorybookRootDir } = require('storybook-root-dirs');9const { getStorybookRootDir } = require('storybook-root-dirs');10const { getStorybookRootDir } = require('storybook-root-dirs');11const { getStorybookRootDir } = require('storybook-root-dirs');12const { getStorybookRootDir } = require('storybook-root-dirs');13const { getStorybookRootDir } = require('storybook-root-dirs');14const { getStorybookRootDir } = require('storybook-root-dirs');15const { getStorybookRootDir } = require('storybook-root-dirs');16const { getStory

Full Screen

Using AI Code Generation

copy

Full Screen

1import { directoryFromConfig } from 'storybook-root-decorator';2import { rootDecorator } from 'storybook-root-decorator';3import { directoryFromConfig } from 'storybook-root-decorator';4import { rootDecorator } from 'storybook-root-decorator';5addDecorator(rootDecorator(directoryFromConfig));6addDecorator(rootDecorator(directoryFromConfig, { root: 'src' }));7addDecorator(rootDecorator(directoryFromConfig, { root: 'src', prefix: 'components' }));8addDecorator(rootDecorator(directoryFromConfig, { prefix: 'components' }));9addDecorator(rootDecorator(directoryFromConfig, { root: 'src', prefix: 'components' }, { root: 'src', prefix: 'components' }));10addDecorator(rootDecorator(directoryFromConfig, { root: 'src', prefix: 'components' }, { root: 'src', prefix: 'components' }, { root: 'src', prefix: 'components' }));11addDecorator(rootDecorator(directoryFromConfig, { root: 'src', prefix: 'components' }, { root: 'src', prefix: 'components' }, { root: 'src', prefix: 'components' }, { root: 'src', prefix: 'components' })

Full Screen

Using AI Code Generation

copy

Full Screen

1const { directoryFromConfig } = require('storybook-root-config');2const path = require('path');3module.exports = {4 stories: [path.resolve(directoryFromConfig(), '**/*.stories.js')],5};6"storybook-root-config": {7 }

Full Screen

Using AI Code Generation

copy

Full Screen

1import { directoryFromConfig } from 'storybook-root-config';2const path = directoryFromConfig('src');3const path = require('storybook-root-config').directoryFromConfig('src');4module.exports = {5 `${directoryFromConfig('src')}/**/*.stories.mdx`,6 `${directoryFromConfig('src')}/**/*.stories.@(js|jsx|ts|tsx)`,7};8import { directoryFromConfig } from 'storybook-root-config';9const path = directoryFromConfig('src');10const path = directoryFromConfig('src', 'components');11const path = require('storybook-root-config').directoryFromConfig('src');12const path = require('storybook-root-config').directoryFromConfig('src', 'components');13directoryFromConfig('src');14directoryFromConfig('src', 'components');15directoryFromConfig('src', 'components/Button');16directoryFromConfig('src', 'components/Button/Primary');17directoryFromConfig('src', 'components/Button/Secondary');18directoryFromConfig('src', 'components/Button/Primary/Small');19directoryFromConfig('src', 'components/Button/Primary/Small/Default');20directoryFromConfig('src', 'components/Button/Primary/Small/Default/Active');21directoryFromConfig('src', 'components/Button/Primary/Small/Default/Disabled');22directoryFromConfig('src', 'components/Button

Full Screen

Using AI Code Generation

copy

Full Screen

1import rootDirs from 'storybook-root-dirs';2const rootDir = rootDirs.directoryFromConfig('config.js');3console.log(rootDir);4import rootDirs from 'storybook-root-dirs';5const rootDir = rootDirs.directoryFromConfig(__filename);6console.log(rootDir);

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const config = require('./config');3const storybookRoot = require('@storybook/react/standalone');4const { directoryFromConfig } = storybookRoot;5const storybookConfigDir = directoryFromConfig(config);6const { getBaseConfig } = storybookRoot;7const storybookBaseConfig = getBaseConfig(config);

Full Screen

Using AI Code Generation

copy

Full Screen

1import { directoryFromConfig } from "storybook-root-decorator";2import { configure } from "@storybook/react";3const req = require.context("../src", true, /\.stories\.js$/);4function loadStories() {5 req.keys().forEach(filename => req(filename));6}7const rootDir = directoryFromConfig("./src");8configure(loadStories, module);9import { setRootDir } from "storybook-root-decorator";10setRootDir("./src");11import { configure } from "@storybook/react";12const req = require.context("../src", true, /\.stories\.js$/);13function loadStories() {14 req.keys().forEach(filename => req(filename));15}16configure(loadStories, module);

Full Screen

Using AI Code Generation

copy

Full Screen

1const directoryFromConfig = require('storybook-root-config').directoryFromConfig;2const path = require('path');3const configPath = path.join(__dirname, '../.storybook');4const directoryPath = directoryFromConfig(configPath);5const directoryPath = directoryFromConfig(configPath, 'src');6module.exports = {7 webpackFinal: async config => {8 return config;9 },10};11module.exports = {12 webpackFinal: async config => {13 return config;14 },15};16const directoryFromConfig = require('storybook-root-config').directoryFromConfig;17const path = require('path');18const configPath = path.join(__dirname, '../.storybook');19const directoryPath = directoryFromConfig(configPath);20const directoryPath = directoryFromConfig(configPath, 'src');

Full Screen

Using AI Code Generation

copy

Full Screen

1const root = directoryFromConfig('src');2const stories = root('stories/**/*.stories.js');3module.exports = {4};5const root = directoryFromConfig('src');6module.exports = {7};8const {root} = require('./paths');9const stories = root('stories/**/*.stories.js');10module.exports = {11};

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