How to use findExportsMap method in storybook-root

Best JavaScript code snippet using storybook-root

traverse-helpers.js

Source:traverse-helpers.js Github

copy

Full Screen

...71 const titleAssignment = ast.program.body.find(d => d.type === 'ExpressionStatement' && d.expression && d.expression.type === 'AssignmentExpression' && d.expression.left && d.expression.left.type === 'MemberExpression' && d.expression.left.object && d.expression.left.object.type === 'Identifier' && d.expression.left.object.name === storyVar && d.expression.left.property.type === 'Identifier' && d.expression.left.property.name === 'story' && d.expression.right && d.expression.right.type === 'ObjectExpression');72 const nameProp = titleAssignment && titleAssignment.expression.right.properties.find(prop => prop.key.type === 'Identifier' && prop.key.name === 'name' && prop.value.type === 'StringLiteral');73 return nameProp && nameProp.value.value;74}75function findExportsMap(ast) {76 const addsMap = {};77 const idsToFrameworks = {};78 const metaDeclaration = ast && ast.program && ast.program.body && ast.program.body.find(d => d.type === 'ExportDefaultDeclaration' && d.declaration.type === 'ObjectExpression' && (d.declaration.properties || []).length);79 const titleProperty = metaDeclaration && metaDeclaration.declaration && metaDeclaration.declaration.properties.find(p => p.key && p.key.name === 'title');80 if (!titleProperty) {81 return {82 addsMap,83 idsToFrameworks84 };85 }86 const title = titleProperty.value.value;87 estraverse.traverse(ast, {88 fallback: 'iteration',89 enter: node => {...

Full Screen

Full Screen

generate-helpers.js

Source:generate-helpers.js Github

copy

Full Screen

1import { patchNode } from './parse-helpers';2import getParser from './parsers';3import {4 splitSTORYOF,5 findAddsMap,6 findDependencies,7 splitExports,8 popParametersObjectFromDefaultExport,9 findExportsMap as generateExportsMap,10} from './traverse-helpers';11function isUglyComment(comment, uglyCommentsRegex) {12 return uglyCommentsRegex.some(regex => regex.test(comment));13}14function generateSourceWithoutUglyComments(source, { comments, uglyCommentsRegex }) {15 let lastIndex = 0;16 const parts = [source];17 comments18 .filter(comment => isUglyComment(comment.value.trim(), uglyCommentsRegex))19 .map(patchNode)20 .forEach(comment => {21 parts.pop();22 const start = source.slice(lastIndex, comment.start);23 const end = source.slice(comment.end);24 parts.push(start, end);25 lastIndex = comment.end;26 });27 return parts.join('');28}29function prettifyCode(source, { prettierConfig, parser, filepath }) {30 let config = prettierConfig;31 let foundParser = null;32 if (parser === 'flow') foundParser = 'flow';33 if (parser === 'javascript' || /jsx?/.test(parser)) foundParser = 'javascript';34 if (parser === 'typescript' || /tsx?/.test(parser)) foundParser = 'typescript';35 if (!config.parser) {36 config = {37 ...prettierConfig,38 };39 } else if (filepath) {40 config = {41 ...prettierConfig,42 filepath,43 };44 } else {45 config = {46 ...prettierConfig,47 };48 }49 try {50 return getParser(foundParser || 'javascript').format(source, config);51 } catch (e) {52 // Can fail when the source is a JSON53 return source;54 }55}56const STORY_DECORATOR_STATEMENT =57 '.addDecorator(withSourceLoader(__STORY__, __ADDS_MAP__,__MAIN_FILE_LOCATION__,__MODULE_DEPENDENCIES__,__LOCAL_DEPENDENCIES__,__SOURCE_PREFIX__,__IDS_TO_FRAMEWORKS__))';58const ADD_PARAMETERS_STATEMENT =59 '.addParameters({ storySource: { source: __STORY__, locationsMap: __ADDS_MAP__ } })';60const applyExportDecoratorStatement = part =>61 part.declaration.isVariableDeclaration62 ? ` addSourceDecorator(${part.source}, {__STORY__, __ADDS_MAP__,__MAIN_FILE_LOCATION__,__MODULE_DEPENDENCIES__,__LOCAL_DEPENDENCIES__,__SOURCE_PREFIX__,__IDS_TO_FRAMEWORKS__});`63 : ` const ${part.declaration.ident} = addSourceDecorator(${part.source}, {__STORY__, __ADDS_MAP__,__MAIN_FILE_LOCATION__,__MODULE_DEPENDENCIES__,__LOCAL_DEPENDENCIES__,__SOURCE_PREFIX__,__IDS_TO_FRAMEWORKS__});`;64export function generateSourceWithDecorators(source, ast, withParameters) {65 const { comments = [] } = ast;66 const partsUsingStoryOfToken = splitSTORYOF(ast, source);67 if (partsUsingStoryOfToken.length > 1) {68 const newSource = partsUsingStoryOfToken.join(69 (withParameters ? ADD_PARAMETERS_STATEMENT : '') + STORY_DECORATOR_STATEMENT70 );71 return {72 storyOfTokenFound: true,73 changed: partsUsingStoryOfToken.length > 1,74 source: newSource,75 comments,76 };77 }78 const partsUsingExports = splitExports(ast, source);79 const newSource = partsUsingExports80 .map((part, i) => (i % 2 === 0 ? part.source : applyExportDecoratorStatement(part)))81 .join('');82 return {83 exportTokenFound: true,84 changed: partsUsingExports.length > 1,85 source: newSource,86 comments,87 };88}89export function generateSourceWithoutDecorators(source, ast) {90 const { comments = [] } = ast;91 return {92 changed: true,93 source,94 comments,95 };96}97export function generateAddsMap(ast, storiesOfIdentifiers) {98 return findAddsMap(ast, storiesOfIdentifiers);99}100export function generateStoriesLocationsMap(ast, storiesOfIdentifiers) {101 const usingAddsMap = generateAddsMap(ast, storiesOfIdentifiers);102 const { addsMap } = usingAddsMap;103 if (Object.keys(addsMap).length > 0) {104 return usingAddsMap;105 }106 const usingExportsMap = generateExportsMap(ast);107 return usingExportsMap || usingAddsMap;108}109export function generateDependencies(ast) {110 return findDependencies(ast);111}112export function generateStorySource({ source, ...options }) {113 let storySource = source;114 storySource = generateSourceWithoutUglyComments(storySource, options);115 storySource = prettifyCode(storySource, options);116 return storySource;117}118export function generateSourcesInExportedParameters(source, ast, additionalParameters) {119 const {120 splicedSource,121 parametersSliceOfCode,122 indexWhereToAppend,123 foundParametersProperty,124 } = popParametersObjectFromDefaultExport(source, ast);125 if (indexWhereToAppend !== -1) {126 const additionalParametersAsJson = JSON.stringify({ storySource: additionalParameters }).slice(127 0,128 -1129 );130 const propertyDeclaration = foundParametersProperty ? '' : 'parameters: ';131 const comma = foundParametersProperty ? '' : ',';132 const newParameters = `${propertyDeclaration}${additionalParametersAsJson},${parametersSliceOfCode.substring(133 1134 )}${comma}`;135 const additionalComma = comma === ',' ? '' : ',';136 const result = `${splicedSource.substring(137 0,138 indexWhereToAppend139 )}${newParameters}${additionalComma}${splicedSource.substring(indexWhereToAppend)}`;140 return result;141 }142 return source;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { findExportsMap } from 'storybook-root-decorator';2const exportsMap = findExportsMap();3const componentExportsMap = exportsMap['./src/components'];4const componentExportsMap = exportsMap['./src/components/ComponentName'];5const componentExportsMap = exportsMap['./src/components/ComponentName/ComponentName.js'];6const componentExportsMap = exportsMap['./src/components/ComponentName/ComponentName.jsx'];7const componentExportsMap = exportsMap['./src/components/ComponentName/ComponentName.ts'];8const componentExportsMap = exportsMap['./src/components/ComponentName/ComponentName.tsx'];9const componentExportsMap = exportsMap['./src/components/ComponentName/ComponentName.css'];10const componentExportsMap = exportsMap['./src/components/ComponentName/ComponentName.scss'];11const componentExportsMap = exportsMap['./src/components/ComponentName/ComponentName.less'];12const componentExportsMap = exportsMap['./src/components/ComponentName/ComponentName.stories.js'];13const componentExportsMap = exportsMap['./src/components/ComponentName/ComponentName.stories.jsx'];14const componentExportsMap = exportsMap['./src/components/ComponentName/ComponentName.stories.ts'];15const componentExportsMap = exportsMap['./src/components/ComponentName/ComponentName.stories.tsx'];

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

1import findExportsMap from 'storybook-root-exports';2import { configure } from '@storybook/react';3import { setOptions } from '@storybook/addon-options';4import { setDefaults } from '@storybook/addon-info';5import { setOptions as setKnobsOptions } from '@storybook/addon-knobs';6setOptions({

Full Screen

Using AI Code Generation

copy

Full Screen

1const { findExportsMap } = require('storybook-root-exports');2const exportsMap = findExportsMap();3console.log(exportsMap);4const { configure } = require('@storybook/react');5const { getStorybookConfig } = require('storybook-root-exports');6const exportsMap = require('./test.js');7const config = getStorybookConfig(exportsMap);8configure(config, module);9module.exports = {10 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx|mdx)'],11 webpackFinal: async (config) => {12 const exportsMap = require('./test.js');13 const { getStorybookConfig } = require('storybook-root-exports');14 const newConfig = getStorybookConfig(exportsMap);15 return { ...config, ...newConfig };16 }17};18module.exports = {19 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx|mdx)'],20 webpackFinal: async (config) => {21 const exportsMap = require('./test.js');22 const { getStorybookConfig } = require('storybook-root-exports');23 const newConfig = getStorybookConfig(exportsMap);24 return { ...config, ...newConfig };25 }26};27module.exports = {28 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx|mdx)'],29 webpackFinal: async (config) => {30 const exportsMap = require('./test.js');31 const { getStorybookConfig }

Full Screen

Using AI Code Generation

copy

Full Screen

1import { findExportsMap } from 'storybook-root-exports'2const exportsMap = findExportsMap('path/to/root/dir')3console.log(exportsMap)4import { findExportsMapSync } from 'storybook-root-exports'5const exportsMap = findExportsMapSync('path/to/root/dir')6console.log(exportsMap)7import { resolveExports } from 'storybook-root-exports'8const exportsMap = resolveExports('path/to/root/dir')9console.log(exportsMap)10import { resolveExportsSync } from 'storybook-root-exports'11const exportsMap = resolveExportsSync('path/to/root/dir')12console.log(exportsMap)13import { resolveExportsMap } from 'storybook-root-exports'14const exportsMap = resolveExportsMap('path/to/root/dir')15console.log(exportsMap)16import { resolveExportsMapSync } from 'storybook-root-exports'17const exportsMap = resolveExportsMapSync('path/to/root/dir')18console.log(exportsMap)19import { resolveExportsMap } from 'storybook-root-exports'20const exportsMap = resolveExportsMap('path/to/root/dir')21console.log(exportsMap)22import { resolveExportsMapSync } from 'storybook-root-exports'23const exportsMap = resolveExportsMapSync('path/to/root/dir')24console.log(exportsMap)25import { resolveExportsMap } from 'storybook-root-exports'26const exportsMap = resolveExportsMap('path/to/root/dir')27console.log(exportsMap)28import { resolveExportsMapSync } from 'storybook-root-exports'

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRootExports = require('storybook-root-exports');2const findExportsMap = storybookRootExports.findExportsMap;3const map = findExportsMap('./stories');4console.log(map);5{6 'src/components/Button/Button.js': {7 },8 'src/components/Icon/Icon.js': {9 }10}11const storybookRootExports = require('storybook-root-exports');12const findExports = storybookRootExports.findExports;13const map = findExports('./stories');14console.log(map);15 {16 },17 {18 }19const storybookRootExports = require('storybook-root-exports');20const findExports = storybookRootExports.findExports;21const map = findExports('./stories', { recursive: true });22console.log(map);23 {24 },25 {26 },27 {28 },29 {30 }31const storybookRootExports = require('storybook-root-exports');32const findExports = storybookRootExports.findExports;33const map = findExports('./stories', { recursive: true, exclude: ['src/components/Button'] });34console.log(map);35 {36 },37 {38 },39 {40 }

Full Screen

Using AI Code Generation

copy

Full Screen

1import { findExportsMap } from 'storybook-root-exports';2const map = findExportsMap();3const Component = map['component-name'].default;4import { findExportsMap } from 'storybook-root-exports';5export const parameters = {6 docs: {7 prepareForInline: (storyFn) => {8 const map = findExportsMap();9 const story = storyFn();10 return {11 };12 },13 },14};15import { findExportsMap } from 'storybook-root-exports';16export const parameters = {17 docs: {18 prepareForInline: (storyFn) => {19 const map = findExportsMap();20 const story = storyFn();21 return {22 };23 },24 },25};26import { findExportsMap } from 'storybook-root-exports';27export const parameters = {28 docs: {29 prepareForInline: (storyFn) => {30 const map = findExportsMap();31 const story = storyFn();32 return {33 };34 },35 },36};37import { findExportsMap } from 'storybook-root-exports';38export const parameters = {39 docs: {40 prepareForInline: (storyFn) => {41 const map = findExportsMap();42 const story = storyFn();43 return {44 };45 },46 },47};

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