How to use fullGlob method in storybook-root

Best JavaScript code snippet using storybook-root

editorconfig.js

Source:editorconfig.js Github

copy

Full Screen

1var Promise = require('bluebird');2var fs = require('fs');3var os = require('os');4var path = require('path');5var semver = require('semver');6var util = require('util');7var whenReadFile = Promise.promisify(fs.readFile);8var iniparser = require('./lib/ini');9var minimatch = require('./lib/fnmatch');10var pkg = require('./package.json');11var knownProps = [12 'end_of_line',13 'indent_style',14 'indent_size',15 'insert_final_newline',16 'trim_trailing_whitespace',17 'charset'18].reduce(function (set, prop) {19 set[prop] = true;20 return set;21}, {});22function fnmatch(filepath, glob) {23 var matchOptions = {matchBase: true, dot: true, noext: true};24 glob = glob.replace(/\*\*/g, '{*,**/**/**}');25 return minimatch(filepath, glob, matchOptions);26}27function getConfigFileNames(filepath, options) {28 var paths = [];29 do {30 filepath = path.dirname(filepath);31 paths.push(path.join(filepath, options.config));32 } while (filepath !== options.root);33 return paths;34}35function getFilepathRoot(filepath) {36 if (path.parse !== undefined) {37 // Node.js >= 0.11.1538 return path.parse(filepath).root;39 }40 if (os.platform() === 'win32') {41 return path.resolve(filepath).match(/^(\\\\[^\\]+\\)?[^\\]+\\/)[0];42 }43 return '/';44}45function processMatches(matches, version) {46 // Set indent_size to "tab" if indent_size is unspecified and47 // indent_style is set to "tab".48 if ("indent_style" in matches && matches.indent_style === "tab" &&49 !("indent_size" in matches) && semver.gte(version, "0.10.0")) {50 matches.indent_size = "tab";51 }52 // Set tab_width to indent_size if indent_size is specified and53 // tab_width is unspecified54 if ("indent_size" in matches && !("tab_width" in matches) &&55 matches.indent_size !== "tab")56 matches.tab_width = matches.indent_size;57 // Set indent_size to tab_width if indent_size is "tab"58 if("indent_size" in matches && "tab_width" in matches &&59 matches.indent_size === "tab")60 matches.indent_size = matches.tab_width;61 return matches;62}63function processOptions(options, filepath) {64 options = options || {};65 return {66 config: options.config || '.editorconfig',67 version: options.version || pkg.version,68 root: path.resolve(options.root || getFilepathRoot(filepath))69 };70}71function buildFullGlob(pathPrefix, glob) {72 switch (glob.indexOf('/')) {73 case -1: glob = "**/" + glob; break;74 case 0: glob = glob.substring(1); break;75 }76 return path.join(pathPrefix, glob);77}78function extendProps(props, options) {79 for (var key in options) {80 var value = options[key];81 key = key.toLowerCase();82 if (knownProps[key]) {83 value = value.toLowerCase();84 }85 try {86 value = JSON.parse(value);87 } catch(e) {}88 if (typeof value === 'undefined' || value === null) {89 // null and undefined are values specific to JSON (no special meaning90 // in editorconfig) & should just be returned as regular strings.91 value = String(value);92 }93 props[key] = value;94 }95 return props;96}97function parseFromFiles(filepath, files, options) {98 return getConfigsForFiles(files).then(function (configs) {99 return configs.reverse();100 }).reduce(function (matches, file) {101 var pathPrefix = path.dirname(file.name);102 file.contents.forEach(function (section) {103 var glob = section[0], options = section[1];104 if (!glob) return;105 var fullGlob = buildFullGlob(pathPrefix, glob);106 if (!fnmatch(filepath, fullGlob)) return;107 matches = extendProps(matches, options);108 });109 return matches;110 }, {}).then(function (matches) {111 return processMatches(matches, options.version);112 });113}114function parseFromFilesSync(filepath, files, options) {115 var configs = getConfigsForFilesSync(files);116 configs.reverse();117 var matches = {};118 configs.forEach(function(config) {119 var pathPrefix = path.dirname(config.name);120 config.contents.forEach(function(section) {121 var glob = section[0], options = section[1];122 if (!glob) return;123 var fullGlob = buildFullGlob(pathPrefix, glob);124 if (!fnmatch(filepath, fullGlob)) return;125 matches = extendProps(matches, options);126 });127 });128 return processMatches(matches, options.version);129}130function StopReduce(array) {131 this.array = array;132}133StopReduce.prototype = Object.create(Error.prototype);134function getConfigsForFiles(files) {135 return Promise.reduce(files, function (configs, file) {136 var contents = iniparser.parseString(file.contents);137 configs.push({138 name: file.name,139 contents: contents140 });141 if ((contents[0][1].root || '').toLowerCase() === 'true') {142 return Promise.reject(new StopReduce(configs));143 }144 return configs;145 }, []).catch(StopReduce, function (stop) {146 return stop.array;147 });148}149function getConfigsForFilesSync(files) {150 var configs = [];151 for (var i in files) {152 var file = files[i];153 var contents = iniparser.parseString(file.contents);154 configs.push({155 name: file.name,156 contents: contents157 });158 if ((contents[0][1].root || '').toLowerCase() === 'true') {159 break;160 }161 };162 return configs;163}164function readConfigFiles(filepaths) {165 return Promise.map(filepaths, function (path) {166 return whenReadFile(path, 'utf-8').catch(function () {167 return '';168 }).then(function (contents) {169 return {name: path, contents: contents};170 });171 });172}173function readConfigFilesSync(filepaths) {174 var files = [];175 var file;176 filepaths.forEach(function(filepath) {177 try {178 file = fs.readFileSync(filepath, 'utf8');179 } catch (e) {180 file = '';181 }182 files.push({name: filepath, contents: file});183 });184 return files;185}186module.exports.parseFromFiles = function (filepath, files, options) {187 return new Promise (function (resolve, reject) {188 filepath = path.resolve(filepath);189 options = processOptions(options, filepath);190 resolve(parseFromFiles(filepath, files, options));191 });192};193module.exports.parseFromFilesSync = function (filepath, files, options) {194 filepath = path.resolve(filepath);195 options = processOptions(options, filepath);196 return parseFromFilesSync(filepath, files, options);197};198module.exports.parse = function (filepath, options) {199 return new Promise (function (resolve, reject) {200 filepath = path.resolve(filepath);201 options = processOptions(options, filepath);202 var filepaths = getConfigFileNames(filepath, options);203 var files = readConfigFiles(filepaths);204 resolve(parseFromFiles(filepath, files, options));205 });206};207module.exports.parseSync = function (filepath, options) {208 filepath = path.resolve(filepath);209 options = processOptions(options, filepath);210 var filepaths = getConfigFileNames(filepath, options);211 var files = readConfigFilesSync(filepaths);212 return parseFromFilesSync(filepath, files, options);...

Full Screen

Full Screen

get-filenames.ts

Source:get-filenames.ts Github

copy

Full Screen

1import { globby } from "globby"2import isGlob from "is-glob"3import * as configuration from "../configuration/index.js"4import { UserError } from "../errors/user-error.js"5import * as files from "./index.js"6/**7 * Returns the FullPaths of all files/directories relative to the given sourceDir8 * that match the given glob9 */10export async function getFileNames(config: configuration.Data): Promise<files.FullFilePath[]> {11 let filenames = await getFiles(config)12 filenames = removeExcludedFiles(filenames, config.exclude)13 filenames = removeExcludedFiles(filenames, "node_modules")14 if (config.emptyWorkspace === false) {15 if (!config.workspace.matches(config.sourceDir)) {16 const fullWorkspace = config.workspace.toFullDir(config.sourceDir)17 filenames = removeExcludedFiles(filenames, fullWorkspace.platformified())18 }19 }20 return filenames21}22/**23 * Returns files described by the given configuration.24 * Filenames are relative to config.sourceDir.25 */26async function getFiles(config: configuration.Data): Promise<files.FullFilePath[]> {27 let fullGlob = config.sourceDir.joinStr(config.files)28 if (process.platform === "win32") {29 // globby cannot handle backslashes in globs,30 // see https://github.com/sindresorhus/globby/issues/155#issuecomment-73296146631 // and https://github.com/micromatch/micromatch#backslashes32 fullGlob = fullGlob.replace(/\\/g, "/")33 }34 if (config.files === "") {35 return markdownFilesInDir("", config.sourceDir)36 } else if (await files.hasDirectory(fullGlob)) {37 return markdownFilesInDir(fullGlob, config.sourceDir)38 } else if (await files.isMarkdownFile(fullGlob)) {39 return [new files.FullFilePath(config.files)]40 } else if (isGlob(config.files)) {41 return config.sourceDir.fullFilesMatchingGlob(fullGlob)42 } else {43 throw new UserError(44 `file or directory does not exist: ${config.files}`,45 "You can provide a glob expression or the path to a file or folder."46 )47 }48}49/**50 * returns all the markdown files in this directory and its children,51 * relative to the given sourceDir52 */53export async function markdownFilesInDir(dirName: string, sourceDir: files.SourceDir): Promise<files.FullFilePath[]> {54 const allFiles = await globby(`${dirName}/**/*.md`)55 return allFiles56 .filter(file => !file.includes("node_modules"))57 .sort()58 .map(file => new files.AbsoluteFilePath(file).toFullFile(sourceDir))59}60/** Removes the given excluded files from the given list of filenames */61export function removeExcludedFiles(fileList: files.FullFilePath[], excluded: string | string[]): files.FullFilePath[] {62 const excludedFilesArray = Array.isArray(excluded) ? excluded : [excluded]63 const excludedRegexes = excludedFilesArray.map(file => new RegExp(file))64 return fileList.filter(file => {65 for (const excludedRegex of excludedRegexes) {66 if (excludedRegex.test(file.unixified())) {67 return false68 }69 }70 return true71 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fullGlob } from 'storybook-root-alias';2import { storiesOf } from '@storybook/react';3import { action } from '@storybook/addon-actions';4import { linkTo } from '@storybook/addon-links';5import { Button } from '@storybook/react/demo';6storiesOf('Button', module)7 .add('with text', () => (8 <Button onClick={action('clicked')}>Hello Button</Button>9 .add('with some emoji', () => (10 <Button onClick={action('clicked')}>πŸ˜€ 😎 πŸ‘ πŸ’―</Button>11 ));12storiesOf('Welcome', module).add('to Storybook', () => <Button onClick={linkTo('Button')}>Go to Button</Button>);13const path = require('path');14const rootAlias = require('storybook-root-alias');15const { fullGlob } = rootAlias;16module.exports = {17 module: {18 {19 include: path.resolve(__dirname, 'src'),20 {21 },22 },23 },24 resolve: {25 alias: {26 },27 },28};29{30 "scripts": {31 },32 "devDependencies": {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fullGlob } from 'storybook-root-decorator';2import { storiesOf } from '@storybook/react';3storiesOf('Button', module)4 .addDecorator(fullGlob)5 .add('with text', () => <button>Click me</button>);6import { fullGlob } from 'storybook-root-decorator';7import { storiesOf } from '@storybook/react';8storiesOf('Button', module)9 .addDecorator(fullGlob)10 .add('with text', () => <button>Click me</button>);11import { addDecorator } from '@storybook/react';12import { fullGlob } from 'storybook-root-decorator';13addDecorator(fullGlob);14module.exports = (baseConfig, env, config) => {15 config.module.rules.push({16 {17 },18 {19 options: {20 },21 },22 include: path.resolve(__dirname, '../'),23 });24 return config;25};26module.exports = (baseConfig, env, config) => {27 config.module.rules.push({28 {29 },30 {31 options: {32 },33 },34 include: path.resolve(__dirname, '../'),35 });36 return config;37};

Full Screen

Using AI Code Generation

copy

Full Screen

1import fullGlob from 'storybook-root-alias/fullGlob';2import { storiesOf } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4import { withKnobs } from '@storybook/addon-knobs';5const stories = storiesOf('Button', module)6 .addDecorator(withInfo)7 .addDecorator(withKnobs);8const req = require.context('../src/components', true, fullGlob('.stories.js'));9req.keys().forEach(filename => req(filename));10export default stories;11import React from 'react';12import { storiesOf } from '@storybook/react';13import { withInfo } from '@storybook/addon-info';14import { withKnobs } from '@storybook/addon-knobs';15import Button from './Button';16const stories = storiesOf('Button', module)17 .addDecorator(withInfo)18 .addDecorator(withKnobs);19stories.add('Button', () => (20));21export default stories;22import React from 'react';23import PropTypes from 'prop-types';24import './Button.css';25const Button = ({ children, ...props }) => (26 <button {...props}>{children}</button>27);28Button.propTypes = {29};30export default Button;31.button {32 background: #0074D9;33 color: #fff;34 border: none;35 padding: 10px 20px;36 border-radius: 5px;37 font-size: 16px;38 cursor: pointer;39}40.button:hover {41 background: #0061B1;42}43.button:active {44 background: #00497B;45}46import { configure } from '@storybook/react';47import { setOptions } from '@storybook/addon-options';48import { setDefaults } from '@storybook/addon-info';49setOptions({

Full Screen

Using AI Code Generation

copy

Full Screen

1import fullGlob from 'storybook-addon-root-import/fullGlob';2module.exports = {3 stories: fullGlob('./src/**/*.stories.js'),4 addons: ['storybook-addon-root-import/register'],5};6const path = require('path');7const rootImport = require('storybook-addon-root-import');8module.exports = ({ config }) => {9 config.resolve.alias = {10 };11 ...(config.resolve.modules || []),12 path.resolve(__dirname, '../'),13 ];14 return config;15};16import 'storybook-addon-root-import/register';17module.exports = {18 stories: fullGlob('./src/stories/**/*.stories.js'),19 addons: ['storybook-addon-root-import/register'],20};21module.exports = {22 stories: fullGlob('./src/**/*.stories.js'),23 addons: ['storybook-addon-root-import/register'],24};25module.exports = {26 stories: fullGlob('./stories/**/*.stories.js'),27 addons: ['storybook-addon-root-import/register'],28};29module.exports = {

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require('storybook-root');2const fullGlob = storybookRoot.fullGlob;3const pattern = fullGlob('stories/*.stories.js');4module.exports = {5};6import React from 'react';7import { storiesOf } from '@storybook/react';8import { action } from '@storybook/addon-actions';9import Button from '../Button';10storiesOf('Button', module)11 .add('with text', () => (12 <Button onClick={action('clicked')}>Hello Button</Button>13 .add('with some emoji', () => (14 <Button onClick={action('clicked')}><span role="img" aria-label="so cool">πŸ˜€ 😎 πŸ‘ πŸ’―</span></Button>15 ));16import React from 'react';17import PropTypes from 'prop-types';18const Button = ({ children, onClick }) => (19 <button onClick={onClick}>{children}</button>20);21Button.propTypes = {22};23export default Button;24.button {25 border: none;26 border-radius: 3px;27 padding: 0.25em 1em;28 margin: 0 1em;29 background: transparent;30 color: palevioletred;31 cursor: pointer;32}33.button:hover {34 color: white;35 background: palevioletred;36}37import React from 'react';38import { storiesOf } from '@storybook/react';39import { action } from '@storybook/addon-actions';40import Button from './index';41storiesOf('Button', module)42 .add('with text', () => (43 <Button onClick={action('clicked')}>Hello Button</Button>44 .add('with some emoji', () => (45 <Button onClick={action('clicked')}><span role="img" aria-label="so cool">πŸ˜€ 😎 πŸ‘ πŸ’―</span></Button>46 ));47import React from 'react';48import ReactDOM from 'react-dom';49import Button from './index';50it('renders without crashing', () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require('storybook-root');2const glob = storybookRoot.fullGlob('**/*.stories.js');3console.log(glob);4const storybookRoot = require('storybook-root');5const glob = storybookRoot.storybookRoot('**/*.stories.js');6console.log(glob);7const storybookRoot = require('storybook-root');8const glob = storybookRoot.storybookRoot('**/*.stories.js');9console.log(glob);10const storybookRoot = require('storybook-root');11const glob = storybookRoot.storybookRoot('**/*.stories.js');12console.log(glob);13const storybookRoot = require('storybook-root');14const glob = storybookRoot.storybookRoot('**/*.stories.js');15console.log(glob);16const storybookRoot = require('storybook-root');17const glob = storybookRoot.storybookRoot('**/*.stories.js');18console.log(glob);19const storybookRoot = require('storybook-root');20const glob = storybookRoot.storybookRoot('**/*.stories.js');21console.log(glob);

Full Screen

Using AI Code Generation

copy

Full Screen

1const rootDir = require('storybook-root-dir').fullGlob;2module.exports = {3 rootDir('./stories/**/*.stories.js'),4}5### `rootDir` (string)6### `globOptions` (object)

Full Screen

Using AI Code Generation

copy

Full Screen

1const { fullGlob } = require('@storybook/react/dist/server/options');2const path = require('path');3const storybookRoot = path.resolve(__dirname, '../');4const stories = fullGlob(storybookRoot, '**/*.stories.js');5console.log(stories);6const { fullGlob } = require('@storybook/react/dist/server/options');7const path = require('path');8const storybookRoot = path.resolve(__dirname, '../');9const stories = fullGlob(storybookRoot, '**/ComponentName.stories.js');10console.log(stories);11const { fullGlob } = require('@storybook/react/dist/server/options');12const path = require('path');13const storybookRoot = path.resolve(__dirname, '../');14const stories = fullGlob(storybookRoot, '**/ComponentName.stories.js');15console.log(stories);16const { fullGlob } = require('@storybook/react/dist/server/options');17const path = require('path');18const storybookRoot = path.resolve(__dirname, '../');19const stories = fullGlob(storybookRoot, '**/ComponentName.stories.js');20console.log(stories);21const { fullGlob } = require('@storybook/react/dist/server/options');

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