How to use directoryFromWorking 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

1import { directoryFromWorking } from 'storybook-root-decorator';2import { directoryFromStorybook } from 'storybook-root-decorator';3import { directoryFromStorybook } from 'storybook-root-decorator';4const root = directoryFromWorking();5const root = directoryFromStorybook();6const root = directoryFromStorybook();7const root = directoryFromWorking('src');8const root = directoryFromStorybook('src');9const root = directoryFromStorybook('src');10const root = directoryFromWorking('src', 'components');11const root = directoryFromStorybook('src', 'components');12const root = directoryFromStorybook('src', 'components');13const root = directoryFromWorking('src', 'components', 'Component');14const root = directoryFromStorybook('src', 'components', 'Component');15const root = directoryFromStorybook('src', 'components', 'Component');16const root = directoryFromWorking('src', 'components', 'Component', 'stories');17const root = directoryFromStorybook('src', 'components', 'Component', 'stories');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { directoryFromWorking } from 'storybook-root';2import { directoryFromRoot } from 'storybook-root';3import { directoryFromStorybook } from 'storybook-root';4import { directoryFromStorybook } from 'storybook-root';5import { directoryFromStorybook } from 'storybook-root';6import { directoryFromWorking } from 'storybook-root';7import { directoryFromRoot } from 'storybook-root';8import { directoryFromStorybook } from 'storybook-root';9import { directoryFromStorybook } from 'storybook-root';10import { directoryFromStorybook } from 'storybook-root';11import { directoryFromWorking } from 'storybook-root';12import { directoryFromRoot } from 'storybook-root';13import { directoryFromStorybook } from 'storybook-root';14import { directoryFromStorybook } from 'storybook-root';15import { directoryFromStorybook } from 'storybook-root';16import { directoryFromWorking } from 'storybook-root';17import { directoryFromRoot } from 'storybook-root';18import { directoryFromStorybook } from 'storybook-root';19import { directoryFromStorybook } from 'storybook-root';20import { directoryFromStorybook } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1import directoryFromWorking from 'storybook-root-require';2import { storiesOf } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4import { withKnobs } from '@storybook/addon-knobs';5import { withNotes } from '@storybook/addon-notes';6import { withReadme } from 'storybook-readme';7import readme from './readme.md';8import { withA11y } from '@storybook/addon-a11y';9import { withViewport } from '@storybook/addon-viewport';10const path = directoryFromWorking(__dirname);11const stories = storiesOf('Component', module);12stories.addDecorator(withInfo);13stories.addDecorator(withKnobs);14stories.addDecorator(withNotes);15stories.addDecorator(withReadme(readme));16stories.addDecorator(withA11y);17stories.addDecorator(withViewport('iphone6'));18stories.add('Component', () => <Component />);19| `cwd` | The current working directory to use when resolving the given path | `process.cwd()` |20MIT © [Sourabh Kumar](

Full Screen

Using AI Code Generation

copy

Full Screen

1import { directoryFromWorking } from 'storybook-root-decorator';2const stories = storiesOf('test', module);3stories.addDecorator(directoryFromWorking);4stories.add('test', () => <div>test</div>);5import { directoryFromWorking } from 'storybook-root-decorator';6const stories = storiesOf('test', module);7stories.addDecorator(directoryFromWorking);8stories.add('test', () => <div>test</div>);9import { directoryFromWorking } from 'storybook-root-decorator';10const stories = storiesOf('test', module);11stories.addDecorator(directoryFromWorking);12stories.add('test', () => <div>test</div>);13import { directoryFromWorking } from 'storybook-root-decorator';14const stories = storiesOf('test', module);15stories.addDecorator(directoryFromWorking);16stories.add('test', () => <div>test</div>);17import { directoryFromWorking } from 'storybook-root-decorator';18const stories = storiesOf('test', module);19stories.addDecorator(directoryFromWorking);20stories.add('test', () => <div>test</div>);21import { directoryFromWorking } from 'storybook-root-decorator';22const stories = storiesOf('test', module);23stories.addDecorator(directoryFromWorking);24stories.add('test', () => <div>test</div>);25import { directoryFromWorking } from 'storybook-root-decorator';26const stories = storiesOf('test', module);27stories.addDecorator(directoryFromWorking);28stories.add('test', () => <div>test</div>);29import { directoryFromWorking } from

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 directoryFromWorking: () => {3 return path.join(process.cwd(), 'storybook')4 },5 directoryFromProject: () => {6 return path.join(__dirname, 'storybook')7 },8 directoryFromProjectRoot: () => {9 return path.join(__dirname, '../storybook')10 }11}12{13 "scripts": {14 }15}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { directoryFromWorking } from 'storybook-root-module';2console.log(directoryFromWorking('src'));3module.exports = {4 directoryFromWorking: (directory) => {5 return path.resolve(process.cwd(), directory);6 },7};8{9}10{11}12module.exports = {13 stories: ['../components/**/*.stories.(js|mdx)'],14};

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path')2const directoryFromWorking = require('storybook-rootpath/directoryFromWorking')3const working = directoryFromWorking('test')4console.log(path.join(working, 'test.js'))5const path = require('path')6const directoryFromRoot = require('storybook-rootpath/directoryFromRoot')7const root = directoryFromRoot('test')8console.log(path.join(root, 'test.js'))9const path = require('path')10const directoryFromWorking = require('storybook-rootpath/directoryFromWorking')11const working = directoryFromWorking('test')12console.log(path.join(working, 'test.js'))13const path = require('path')14const directoryFromRoot = require('storybook-rootpath/directoryFromRoot')15const root = directoryFromRoot('test')16console.log(path.join(root, 'test.js'))17const path = require('path')18const directoryFromWorking = require('storybook-rootpath/directoryFromWorking')19const working = directoryFromWorking('test')20console.log(path.join(working, 'test.js'))21const path = require('path')22const directoryFromRoot = require('storybook-rootpath/directoryFromRoot')23const root = directoryFromRoot('test')24console.log(path.join(root, 'test.js'))25const path = require('path')26const directoryFromWorking = require('storybook-rootpath/directoryFromWorking')27const working = directoryFromWorking('test')28console.log(path

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