Best JavaScript code snippet using storybook-root
index.js
Source: index.js
1#!/usr/bin/env node2var Path = require('path');3var yargs = require('yargs');4var FileUtil = require('./lib/utils/file');5var ParseController = require('./lib/controllers/parser');6var ConfigController = require('./lib/controllers/config');7var CacheController = require('./lib/controllers/cache');8var FilterController = require('./lib/controllers/filter');9const Deferred = require('./lib/models/deferred');10const FS = require('fs');11const FileStore = require('./lib/models/fileStore');12yargs.command('transform <source> [destination]','Transform your delimited flat files', function(yargs){13 yargs.positional('source', {14 describe: 'Path to source file to be transformed.',15 type: 'string'16 }).positional('destination', {17 describe: 'Path to destination to place transformed file.',18 type: 'string',19 default: process.cwd()20 });21}, function(argv){22 var resolvedConfigPath;23 FileUtil.checkFile(argv.source).then(function(){24 return FileUtil.checkDirectory(argv.destination, true);25 }).then(function(){26 resolvedConfigPath = process.cwd()+'/'+ConfigController.FILENAME;27 if(argv.config){28 resolvedConfigPath = argv.config;29 if(argv.config.charAt(0) === '.'){30 resolvedConfigPath = process.cwd() + '/' + resolvedConfigPath;31 }32 }33 return FileUtil.checkFile(resolvedConfigPath);34 }).then(function(){35 var filename = Path.basename(argv.source);36 var filenameSplit = filename.split('.');37 filename = filenameSplit[0]+'-etlbot-'+Date.now()+'.'+filenameSplit[1];38 39 var config = ConfigController.resolveConfig(resolvedConfigPath);40 ParseController.parse(argv.source, argv.destination+'/'+filename, config);41 }).catch(function(e){42 console.log('Error',e);43 });44});45yargs.command('filter <source> [destination]','Filter your delimited flat files', function(yargs){46 yargs.positional('source', {47 describe: 'Path to source file to be filtered.',48 type: 'string'49 }).positional('destination', {50 describe: 'Path to destination to place filtered file.',51 type: 'string',52 default: process.cwd()53 });54}, function(argv){55 var resolvedConfigPath;56 FileUtil.checkFile(argv.source).then(function(){57 return FileUtil.checkDirectory(argv.destination);58 }).then(function(){59 resolvedConfigPath = process.cwd()+'/'+ConfigController.FILENAME;60 if(argv.config){61 resolvedConfigPath = argv.config;62 if(argv.config.charAt(0) === '.'){63 resolvedConfigPath = process.cwd() + '/' + resolvedConfigPath;64 }65 }66 return FileUtil.checkFile(resolvedConfigPath);67 }).then(function(){68 var filename = Path.basename(argv.source);69 var filenameSplit = filename.split('.');70 filename = filenameSplit[0]+'-etlbot-'+Date.now()+'.'+filenameSplit[1];71 72 var config = ConfigController.resolveConfig(resolvedConfigPath);73 var cachePath = Path.join(process.cwd(),CacheController.FOLDERNAME);74 var cache;75 if(argv.cache){76 cachePath = argv.cache;77 if(argv.config.charAt(0) === '.'){78 cachePath = process.cwd() + '/' + cachePath;79 }80 }81 FileUtil.checkDirectory(cachePath).then(function(){82 console.log('> Existing cache directory found', cachePath);83 cache = new FileStore(cachePath);84 }).catch(function(e){85 console.log('> cache not found', cachePath);86 }).then(function(){87 FilterController.parse(argv.source, argv.destination+'/'+filename, config, cache);88 }).catch(function(e){89 console.log('Error',e); 90 });91 }).catch(function(e){92 console.log('Error',e);93 });94});95yargs.command('cache <source> [destination]', 'Build a cache of key value pairs based on a delimited file to be used in subsequent ETL steps.', function(yargs){96 yargs.positional('source', {97 describe: 'Path to source file to be parsed.',98 type: 'string'99 }).positional('destination', {100 describe: 'Path to destination to place cache.',101 type: 'string'102 });103}, function(argv){104 var resolvedConfigPath;105 var resolvedCachePath;106 FileUtil.checkFile(argv.source).then(function(){107 var def = new Deferred();108 resolvedCachePath = argv.destination;109 if(!resolvedCachePath){110 resolvedCachePath = Path.join(process.cwd(),CacheController.FOLDERNAME);111 console.log('> No cache directory provided. Using default:', resolvedCachePath);112 }113 FileUtil.checkDirectory(resolvedCachePath).then(function(){114 console.log('> Existing cache directory found', resolvedCachePath);115 def.resolve();116 }).catch(function(e){117 console.log('> directory not found', resolvedCachePath);118 console.log('> creating cache directory', resolvedCachePath);119 FS.mkdirSync(resolvedCachePath);120 def.resolve();121 });122 return def.promise;123 }).then(function(){124 resolvedConfigPath = process.cwd()+'/'+ConfigController.FILENAME;125 if(argv.config){126 resolvedConfigPath = argv.config;127 if(argv.config.charAt(0) === '.'){128 resolvedConfigPath = process.cwd() + '/' + resolvedConfigPath;129 }130 }131 return FileUtil.checkFile(resolvedConfigPath);132 }).then(function(){133 var config = ConfigController.resolveConfig(resolvedConfigPath);134 CacheController.build(argv.source, resolvedCachePath, config);135 }).catch(function(e){136 console.log('Error',e);137 });138});139yargs.command('config [destination]', 'Create a configuration file for transformer.', function(yargs){140 yargs.positional('destination', {141 describe: 'Path to create configuration file template.',142 type: 'string',143 default: process.cwd()144 });145}, function(argv){146 FileUtil.checkFile(argv.destination, true).then(function(){147 ConfigController.createConfig(argv.destination);148 }).catch(function(e){149 console.log('Error', e);150 });151});152yargs.option('config', {153 alias: 'c',154 describe: 'Path to configuration file. If none is provided the current working directory will be used.'155});156yargs.option('cache', {157 alias: 'm',158 describe: 'Path to cache folder. If none is provided the current working directory will be used /__etlbotcache'159});...
load-file-config.js
Source: load-file-config.js
1const validateConfig = require('./validate-config');2const path = require('path');3const fs = require('fs');4const loadFileConfig = configPath => {5 if (!configPath) {6 return validateConfig({});7 }8 const resolvedConfigPath = path.isAbsolute(configPath) ?9 configPath :10 path.resolve(process.cwd(), configPath);11 if (!fs.existsSync(resolvedConfigPath)) {12 throw new Error(`Config file not found at "${configPath}"`);13 }14 const dsConfig = require(resolvedConfigPath);15 const fileConfig = validateConfig(dsConfig, resolvedConfigPath);16 const modules = fileConfig.modules17 .map(dsPath => {18 if (path.isAbsolute(dsPath)) {19 return dsPath;20 }21 if (/^.\//.test(dsPath)) {22 return path.resolve(process.cwd(), dsPath);23 }24 return require.resolve(dsPath, {25 paths: [26 ...require.resolve.paths(dsPath),27 path.join(process.cwd(), 'node_modules'),28 ],29 });30 });31 return {32 ...fileConfig,33 modules,34 };35};36module.exports = {37 loadFileConfig,...
configure.ts
Source: configure.ts
1import fs from 'fs';2import path from 'path';3function getConfigPathParts(configPath: string): string {4 const resolvedConfigPath = path.resolve(configPath);5 if (fs.lstatSync(resolvedConfigPath).isDirectory()) {6 return path.join(resolvedConfigPath, 'config');7 }8 return resolvedConfigPath;9}10function configure(options: { configPath?: string; config: any; storybook: any }): void {11 const { configPath = '.storybook', config, storybook } = options;12 if (config && typeof config === 'function') {13 config(storybook);14 return;15 }16 const resolvedConfigPath = getConfigPathParts(configPath);17 require.requireActual(resolvedConfigPath);18}...
Using AI Code Generation
1const configPath = require('storybook-root-config').resolvedConfigPath;2module.exports = {3 webpackFinal: async config => {4 const newConfig = { ...config };5 newConfig.module.rules.push({6 include: path.resolve(__dirname, '../'),7 });8 newConfig.module.rules.push({9 test: /\.(ts|tsx)$/,10 {11 loader: require.resolve('awesome-typescript-loader'),12 },13 {14 loader: require.resolve('react-docgen-typescript-loader'),15 },16 });17 newConfig.resolve.extensions.push('.ts', '.tsx');18 return newConfig;19 },20};
Using AI Code Generation
1const { resolvedConfigPath } = require('storybook-root-config');2module.exports = {3 stories: [resolvedConfigPath('stories/*.stories.js')],4};5import React from 'react';6import { storiesOf } from '@storybook/react';7import { withKnobs, text } from '@storybook/addon-knobs/react';8import Example from '../src/Example';9const stories = storiesOf('Example', module);10stories.addDecorator(withKnobs);11stories.add('with knobs', () => (12 <Example text={text('text', 'Hello Storybook')} />13));14import React from 'react';15const Example = ({ text }) => <div>{text}</div>;16export default Example;17import React from 'react';18import { shallow } from 'enzyme';19import Example from './Example';20describe('Example', () => {21 let wrapper;22 beforeEach(() => {23 wrapper = shallow(<Example text="Hello Storybook" />);24 });25 it('should render the text', () => {26 expect(wrapper.text()).toEqual('Hello Storybook');27 });28});29import React from 'react';30import { storiesOf } from '@storybook/react';31import { withKnobs, text } from '@storybook/addon-knobs/react';32import Example from './Example';33const stories = storiesOf('Example', module);34stories.addDecorator(withKnobs);35stories.add('with knobs', () => (36 <Example text={text('text', 'Hello Storybook')} />37));38import React from 'react';39import { shallow } from 'enzyme';40import Example from './Example';41describe('Example', () => {42 let wrapper;43 beforeEach(() => {44 wrapper = shallow(<Example text="Hello Storybook" />);45 });46 it('should render the text', () => {47 expect(wrapper.text()).toEqual('Hello Storybook');48 });49});50import React from 'react';51import { shallow } from 'enzyme';52import Example from './Example';53describe('Example', () => {54 let wrapper;55 beforeEach(() => {56 wrapper = shallow(<
Using AI Code Generation
1import { resolvedConfigPath } from 'storybook-root-config';2module.exports = {3 stories: [resolvedConfigPath('stories/**/*.stories.js')],4};5import React from 'react';6import { storiesOf } from '@storybook/react';7import Welcome from '../src/Welcome';8storiesOf('Welcome', module).add('to Storybook', () => <Welcome showApp={linkTo('Button')} />);9import React from 'react';10import PropTypes from 'prop-types';11import { Button } from 'storybook-root-config';12const Welcome = ({ showApp }) => (13 <Button onClick={showApp}>Show App</Button>14);15Welcome.propTypes = {16};17Welcome.defaultProps = {18};19export default Welcome;20import React from 'react';21import PropTypes from 'prop-types';22const Button = ({ onClick, children }) => (23 <button onClick={onClick} type="button">24 {children}25);26Button.propTypes = {27};28Button.defaultProps = {29};30export default Button;31import React from 'react';32import ReactDOM from 'react-dom';33import Welcome from './Welcome';34const rootEl = document.getElementById('root');35ReactDOM.render(<Welcome />, rootEl);36body {37 background-color: #f7f7f7;38 'Open Sans', 'Helvetica Neue', sans-serif;39 margin: 0;40}41#root {42 padding: 15px;43}44import { configure } from '@storybook/react';45const req = require.context('../stories', true, /.stories.js$/);46function loadStories() {47 req.keys().forEach(filename => req(filename));48}49configure(loadStories, module);50import '@storybook/addon-actions/register';
Using AI Code Generation
1const path = require("path");2const { resolvedConfigPath } = require("storybook-root-config");3const configPath = resolvedConfigPath("./.storybook");4module.exports = {5 stories: [`${configPath}/stories/*.stories.js`],6};7module.exports = {8};9import { addDecorator, addParameters } from "@storybook/react";10import { withA11y } from "@storybook/addon-a11y";11import { withKnobs } from "@storybook/addon-knobs";12import { withTests } from "@storybook/addon-jest";13import results from "../.jest-test-results.json";14import { withInfo } from "@storybook/addon-info";15import { withStorySource } from "@storybook/addon-storysource";16addDecorator(withA11y);17addDecorator(withKnobs);18addDecorator(withInfo);19addDecorator(withStorySource);20addDecorator(21 withTests({22 })23);24addParameters({25 viewport: {26 viewports: {27 extraSmall: {28 styles: {29 },30 },31 small: {32 styles: {33 },34 },35 medium: {36 styles: {37 },38 },39 large: {40 styles: {
Using AI Code Generation
1const configPath = require('storybook-root-require').resolve('path/to/config.js');2const configPath = require('storybook-root-require').resolve('path/to/config.js');3const configPath = require('storybook-root-require').resolvedConfigPath;4const configPath = require('storybook-root-require').resolve('path/to/config.js');5const configPath = require('storybook-root-require').resolve('path/to/config.js');6const configPath = require('storybook-root-require').resolve('path/to/config.js');7const configPath = require('storybook-root-require').resolve('path/to/config.js');8const configPath = require('storybook-root-require').resolve('path/to/config.js');9const configPath = require('storybook-root-require').resolve('path/to/config.js');
Using AI Code Generation
1const { resolvedConfigPath } = require('storybook-root-config');2const path = require('path');3const pathToConfig = path.resolve(resolvedConfigPath(), 'config.js');4module.exports = {5 webpackFinal: async (config) => {6 return config;7 },8};9module.exports = {10 webpackFinal: async (config) => {11 return config;12 },13};14module.exports = {15 webpackFinal: async (config) => {16 return config;17 },18};19The resolvedConfigPath method is also useful when you want to resolve the path to the config file in a story file. For example, if you want to import a component that is in the same directory as the config file, you can use the resolvedConfigPath method to resolve the path to the config file and then use the path to resolve the path to the component. See the example below:20const { resolvedConfigPath } = require('storybook-root-config');21const path = require('path');22const pathToConfig = path.resolve(resolvedConfigPath(), 'config.js');23const pathToComponent = path.resolve(pathToConfig, 'component.js');24module.exports = {
Using AI Code Generation
1const { resolveConfigPath } = require('storybook-root-config');2const configPath = resolveConfigPath('path/to/storybook/config.js');3module.exports = {4};5const { resolveConfigPath } = require('storybook-root-config');6const path = require('path');7module.exports = {8 stories: [path.resolve(resolveConfigPath('../stories'), '**/*.stories.js')],9};
Check out the latest blogs from LambdaTest on this topic:
Hey everyone! We hope you had a great Hacktober. At LambdaTest, we thrive to bring you the best with each update. Our engineering and tech teams work at lightning speed to deliver you a seamless testing experience.
In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.
When software developers took years to create and introduce new products to the market is long gone. Users (or consumers) today are more eager to use their favorite applications with the latest bells and whistles. However, users today don’t have the patience to work around bugs, errors, and design flaws. People have less self-control, and if your product or application doesn’t make life easier for users, they’ll leave for a better solution.
Estimates are critical if you want to be successful with projects. If you begin with a bad estimating approach, the project will almost certainly fail. To produce a much more promising estimate, direct each estimation-process issue toward a repeatable standard process. A smart approach reduces the degree of uncertainty. When dealing with presales phases, having the most precise estimation findings can assist you to deal with the project plan. This also helps the process to function more successfully, especially when faced with tight schedules and the danger of deviation.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!