Best JavaScript code snippet using storybook-root
bundle-package.ts
Source:bundle-package.ts
1import path, { resolve } from 'path';2import { bold, gray, greenBright } from 'chalk';3import execa from 'execa';4import { rollup, OutputOptions, watch, RollupOptions } from 'rollup';5import readPkgUp from 'read-pkg-up';6import fs from 'fs-extra';7import rollupTypescript from '@rollup/plugin-typescript';8import { nodeResolve } from '@rollup/plugin-node-resolve';9import commonjs from '@rollup/plugin-commonjs';10import json from '@rollup/plugin-json';11import { babel, getBabelOutputPlugin } from '@rollup/plugin-babel';12import { terser } from 'rollup-plugin-terser';13import { generateDtsBundle } from 'dts-bundle-generator';14import * as dtsLozalize from './dts-localize';15interface Options {16 input: string;17 externals: string[];18 cwd: string;19 optimized?: boolean;20 watch?: boolean;21}22async function build(options: Options) {23 const { input, externals, cwd, optimized } = options;24 const setting: RollupOptions = {25 input,26 external: externals,27 plugins: [28 nodeResolve({29 browser: true,30 preferBuiltins: true,31 }),32 commonjs(),33 babel({34 babelHelpers: 'external',35 skipPreflightCheck: true,36 }),37 json(),38 rollupTypescript({ lib: ['es2015', 'dom', 'esnext'], target: 'es6' }),39 ],40 };41 const outputs: OutputOptions[] = [42 {43 dir: resolve(cwd, './dist/modern'),44 format: 'es',45 sourcemap: optimized,46 preferConst: true,47 plugins: [48 getBabelOutputPlugin({49 presets: [50 [51 '@babel/preset-env',52 {53 shippedProposals: true,54 useBuiltIns: 'usage',55 corejs: '3',56 modules: false,57 targets: { chrome: '94' },58 },59 ],60 ],61 }),62 optimized ? terser({ output: { comments: false }, module: true }) : null,63 ].filter(Boolean),64 },65 {66 dir: resolve(cwd, './dist/esm'),67 format: 'es',68 sourcemap: optimized,69 plugins: [70 getBabelOutputPlugin({71 presets: [72 [73 '@babel/preset-env',74 {75 shippedProposals: true,76 useBuiltIns: 'usage',77 modules: false,78 corejs: '3',79 },80 ],81 ],82 }),83 optimized ? terser({ output: { comments: false }, module: true }) : null,84 ].filter(Boolean),85 },86 {87 dir: resolve(cwd, './dist/cjs'),88 format: 'commonjs',89 plugins: [90 getBabelOutputPlugin({91 presets: [92 [93 '@babel/preset-env',94 {95 shippedProposals: true,96 useBuiltIns: 'usage',97 corejs: '3',98 modules: false,99 targets: { node: '14' },100 },101 ],102 ],103 }),104 optimized ? terser({ output: { comments: false }, module: true }) : null,105 ].filter(Boolean),106 },107 ];108 if (options.watch) {109 const watcher = watch({ ...setting, output: outputs });110 watcher.on('change', (event) => {111 console.log(`${greenBright('changed')}: ${event.replace(path.resolve(cwd, '../..'), '.')}`);112 dts(options);113 });114 } else {115 const bundler = await rollup(setting);116 await Promise.all(outputs.map((config) => bundler.write(config)));117 await bundler.close();118 }119}120async function dts({ input, externals, cwd, ...options }: Options) {121 if (options.watch) {122 try {123 const [out] = await generateDtsBundle(124 [125 {126 filePath: input,127 output: { inlineDeclareGlobals: false, sortNodes: true, noBanner: true },128 },129 ],130 { followSymlinks: false }131 );132 await fs.outputFile('dist/ts3.9/index.d.ts', out);133 } catch (e) {134 console.log(e.message);135 }136 } else {137 const [out] = await generateDtsBundle(138 [139 {140 filePath: input,141 output: { inlineDeclareGlobals: false, sortNodes: true, noBanner: true },142 },143 ],144 { followSymlinks: false }145 );146 const bundledDTSfile = path.join(cwd, 'dist/ts-tmp/index.d.ts');147 const localizedDTSout = path.join(cwd, 'dist/ts3.9');148 await fs.outputFile(bundledDTSfile, out);149 await dtsLozalize.run([bundledDTSfile], localizedDTSout, { externals, cwd });150 // await fs.remove(path.join(cwd, 'dist/ts-tmp'));151 await execa('node', [152 path.join(__dirname, '../node_modules/.bin/downlevel-dts'),153 'dist/ts3.9',154 'dist/ts3.4',155 ]);156 }157}158async function removeDist() {159 await fs.remove('dist');160}161export async function run({ cwd, flags }: { cwd: string; flags: string[] }) {162 const { packageJson: pkg } = await readPkgUp({ cwd });163 const message = gray(`Built: ${bold(`${pkg.name}@${pkg.version}`)}`);164 console.time(message);165 if (flags.includes('--reset')) {166 await removeDist();167 }168 const input = path.join(cwd, pkg.bundlerEntrypoint);169 const externals = Object.keys({ ...pkg.dependencies, ...pkg.peerDependencies });170 const options: Options = {171 cwd,172 externals,173 input,174 optimized: flags.includes('--optimized'),175 watch: flags.includes('--watch'),176 };177 await Promise.all([178 //179 build(options),180 dts(options),181 ]);182 console.timeEnd(message);...
Using AI Code Generation
1var storybookRoot = require('storybook-root');2storybookRoot.localizedDTSout("Hello World");3var storybookRoot = require('storybook-root');4storybookRoot.localizedDTSout("Hello World");5var storybookRoot = require('storybook-root');6storybookRoot.localizedDTSout("Hello World");7var storybookRoot = require('storybook-root');8storybookRoot.localizedDTSout("Hello World");9var storybookRoot = require('storybook-root');10storybookRoot.localizedDTSout("Hello World");11var storybookRoot = require('storybook-root');12storybookRoot.localizedDTSout("Hello World");13var storybookRoot = require('storybook-root');14storybookRoot.localizedDTSout("Hello World");15var storybookRoot = require('storybook-root');16storybookRoot.localizedDTSout("Hello World");17var storybookRoot = require('storybook-root');18storybookRoot.localizedDTSout("Hello World");19var storybookRoot = require('storybook-root');20storybookRoot.localizedDTSout("Hello World");21var storybookRoot = require('storybook-root');22storybookRoot.localizedDTSout("Hello World");23var storybookRoot = require('storybook-root');24storybookRoot.localizedDTSout("Hello World");25var storybookRoot = require('storybook-root');26storybookRoot.localizedDTSout("Hello World
Using AI Code Generation
1import { localizedDTSout } from 'storybook-root';2const story = () => {3 const myLocalizedDTSout = localizedDTSout();4 return (5 <h1>{myLocalizedDTSout}</h1>6 );7};8export default story;9import { addDecorator } from '@storybook/react';10import { withInfo } from '@storybook/addon-info';11import { withKnobs } from '@storybook/addon-knobs';12import { addLocaleData } from 'react-intl';13import * as en from 'react-intl/locale-data/en';14import * as fr from 'react-intl/locale-data/fr';15import { setIntlConfig, withIntl } from 'storybook-addon-intl';16import { addParameters } from '@storybook/react';17import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';18import { themes } from '@storybook/theming';19import { withA11y } from '@storybook/addon-a11y';20addLocaleData([...en, ...fr]);21const getMessages = (locale) => {22 switch (locale) {23 return require('../src/i18n/en.json');24 return require('../src/i18n/fr.json');25 return require('../src/i18n/en.json');26 }27};28const intlConfig = {29};30setIntlConfig(intlConfig);31addDecorator(withInfo);32addDecorator(withKnobs);33addDecorator(withIntl);34addDecorator(withA11y);35addParameters({36 options: {37 },38 viewport: {39 },40});41const path = require('path');42module.exports = async ({ config }) => {43 config.module.rules.push({44 include: path.resolve(__dirname, '../'),45 loader: require.resolve('babel-loader'),46 options: {47 presets: [['react-app', { flow: false, typescript: true }]],48 },49 });50 config.resolve.modules.push(path.resolve(__dirname, '../'));51 return config;52};53import { addons } from '@storybook/addons';
Using AI Code Generation
1import { localizedDTSout } from 'storybook-root';2import { localizedDTSout } from 'storybook-root';3import { localizedDTSout } from 'storybook-root';4import { localizedDTSout } from 'storybook-root';5import { localizedDTSout } from 'storybook-root';6import { localizedDTSout } from 'storybook-root';7import { localizedDTSout }
Using AI Code Generation
1import React from 'react';2import { addDecorator } from '@storybook/react';3import { withInfo } from '@storybook/addon-info';4import { ThemeProvider } from 'styled-components';5import { theme } from '../src/theme';6import { Header } from '../src/components/header';7import logo from '../src/assets/images/logo.png';8addDecorator(withInfo);9addDecorator(story => (10 <ThemeProvider theme={theme}>11 <Header logo={logo} />12 {story()}13));
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!!