Best JavaScript code snippet using storybook-root
create_packages.js
Source:create_packages.js
1#!/usr/bin/env node2/*3 * @copyright (c) 2018, Philipp Thuerwaechter & Pattrick Hueper4 * @license BSD-3-Clause (see LICENSE.md in the root directory of this source tree)5 */6const path = require('path');7const fs = require('fs');8const yargsPkg = require('yargs');9const { packages: prebuiltPackages } = require('../prebuilt-packages.json');10// this file will create npm (sub-) packages, build_package is used to create a js-joda-locale bundled packages in each package dir11const yargs = yargsPkg12 .options({13 packagesDir: {14 alias: 'p',15 string: true,16 default: path.resolve(__dirname, '../packages'),17 description: 'packages directory, where the package(s) are generated, can be absolute or relative (to cwd)'18 },19 prebuiltDir: {20 alias: 'b',21 string: true,22 default: path.resolve(__dirname, '../dist/prebuilt'),23 description: 'prebuilt directory, where the package(s) are bundled from a previous step. Can be absolute or relative (to cwd)'24 },25 packages: {26 description: 'define several packages that will be created',27 default: prebuiltPackages,28 },29 debug: {30 boolean: true,31 default: false,32 description: 'output debug infos'33 },34 })35 .wrap(Math.min(120, yargsPkg.terminalWidth()))36 .help();37const argv = yargs.parse();38if (argv.debug) {39 /* eslint-disable no-console */40 console.log('create_packages parsed argument', argv);41 console.log('create_packages cwd', process.cwd());42 /* eslint-enable no-console */43}44const mainPackageJSON = JSON.parse(fs.readFileSync(path.resolve(__dirname, '..', 'package.json')));45const packageTemplate = {46 name: '<will be overridden>',47 version: '<will be overridden>',48 description: '<will be overridden>',49 repository: {50 type: 'git',51 url: 'https://github.com/js-joda/js-joda-locale.git'52 },53 main: 'dist/index.js',54 typings: 'dist/js-joda-locale.d.ts',55 keywords: [56 'date',57 'time',58 'locale'59 ],60 author: 'phueper',61 contributors: [62 'pithu',63 'phueper'64 ],65 license: 'BSD-3-Clause',66 bugs: {67 url: 'https://github.com/js-joda/js-joda-locale/issues'68 },69 homepage: 'https://github.com/js-joda/js-joda-locale#readme',70 peerDependencies: {71 '@js-joda/core': mainPackageJSON.peerDependencies['@js-joda/core'],72 '@js-joda/timezone': mainPackageJSON.peerDependencies['@js-joda/timezone'],73 },74 dependencies: {},75 devDependencies: {}76};77const readmeTemplate = fs.readFileSync(path.resolve(__dirname, 'README_package.template.md'),78 'utf8');79const readmeLocaleRegex = /{{locale}}/g;80Object.keys(argv.packages).forEach((packageName) => {81 // eslint-disable-next-line no-console82 console.info('creating', packageName);83 const packageDir = path.resolve(argv.packagesDir, packageName);84 if (!fs.existsSync(packageDir)) {85 fs.mkdirSync(packageDir);86 }87 const distDir = path.resolve(argv.packagesDir, packageName, 'dist');88 if (!fs.existsSync(distDir)) {89 fs.mkdirSync(distDir);90 }91 const prebuiltDir = path.resolve(argv.prebuiltDir, packageName);92 if (!fs.existsSync(prebuiltDir)) {93 throw new Error(`prebuilt bundle not found for package ${packageName}.\nDid you forget to run "npm run build-prebuilt" ?`);94 }95 // create package.json96 packageTemplate.version = mainPackageJSON.version;97 packageTemplate.name = `@js-joda/locale_${packageName}`;98 packageTemplate.description = `prebuilt js-joda locale package for locales: ${argv.packages[packageName]}`;99 fs.writeFileSync(path.resolve(packageDir, 'package.json'),100 JSON.stringify(packageTemplate, null, 4));101 fs.writeFileSync(path.resolve(packageDir, 'README.md'),102 readmeTemplate.replace(readmeLocaleRegex, argv.packages[packageName].join(',')));103 fs.copyFileSync(path.resolve(__dirname, '..', 'typings', 'js-joda-locale.d.ts'),104 path.resolve(packageDir, 'dist', 'js-joda-locale.d.ts'));105 for (const file of ['index.js', 'index.js.map', 'index.min.js', 'index.esm.js']) {106 fs.copyFileSync(107 path.resolve(prebuiltDir, file),108 path.resolve(packageDir, 'dist', file));109 }...
prebuilt-manager.ts
Source:prebuilt-manager.ts
1import { logger } from '@storybook/node-logger';2import { pathExists } from 'fs-extra';3import path from 'path';4import {5 getInterpretedFile,6 loadManagerOrAddonsFile,7 serverRequire,8 Options,9} from '@storybook/core-common';10import { getAutoRefs } from '../manager/manager-config';11// Addons automatically installed when running `sb init` (see baseGenerator.ts)12export const DEFAULT_ADDONS = ['@storybook/addon-links', '@storybook/addon-essentials'];13// Addons we can safely ignore because they don't affect the manager14export const IGNORED_ADDONS = [15 '@storybook/preset-create-react-app',16 '@storybook/preset-scss',17 '@storybook/preset-typescript',18 ...DEFAULT_ADDONS,19];20export const getPrebuiltDir = async (options: Options): Promise<string | false> => {21 const { configDir, smokeTest, managerCache } = options;22 if (managerCache === false || smokeTest) return false;23 const prebuiltDir = path.join(__dirname, '../../../prebuilt');24 const hasPrebuiltManager = await pathExists(path.join(prebuiltDir, 'index.html'));25 if (!hasPrebuiltManager) return false;26 const hasManagerConfig = !!loadManagerOrAddonsFile({ configDir });27 if (hasManagerConfig) return false;28 const mainConfigFile = getInterpretedFile(path.resolve(configDir, 'main'));29 if (!mainConfigFile) return false;30 const { addons, refs, managerBabel, managerWebpack } = serverRequire(mainConfigFile);31 if (!addons || refs || managerBabel || managerWebpack) return false;32 if (DEFAULT_ADDONS.some((addon) => !addons.includes(addon))) return false;33 if (addons.some((addon: string) => !IGNORED_ADDONS.includes(addon))) return false;34 // Auto refs will not be listed in the config, so we have to verify there aren't any35 const autoRefs = await getAutoRefs(options);36 if (autoRefs.length > 0) return false;37 logger.info('=> Using prebuilt manager');38 return prebuiltDir;...
build-node-binding.js
Source:build-node-binding.js
1const helpers = require("./helpers");2const cp = require("child_process");3const fs = require("fs");4// Read arguments from command line5function processArgs(args = process.argv.slice(2)) {6 return {7 sourceDir: helpers.sanitizePath(args[0]),8 buildDir: helpers.sanitizePath(args[1]),9 installDir: helpers.sanitizePath(args[2]),10 bindingDir: helpers.sanitizePath(args[3]),11 };12}13// Start building14const { sourceDir, buildDir, installDir, bindingDir } = processArgs();15try {16 const prebuiltDir = `dist/${17 process.platform === "win32" ? "win32-x64" : "linux-x64"18 }`;19 const configArgs = helpers.makeCmakeConfigArgs({20 sourceDir,21 buildDir,22 installDir,23 });24 const buildArgs = helpers.makeCmakeBuildArgs({ buildDir });25 helpers.spawn("cmake", configArgs);26 helpers.spawn("cmake", buildArgs);27 helpers.spawn("yarn", ["node-gyp", "configure"]);28 helpers.spawn("yarn", ["node-gyp", "build"]);29 helpers.spawn("yarn", ["tsc", "-p", bindingDir]);30 if (!fs.existsSync(prebuiltDir)) fs.mkdirSync(prebuiltDir);31 fs.copyFileSync("./package.json", "dist/package.json");32 fs.copyFileSync("./build/Release/linq.node", `dist/src/linq.node`);33 fs.copyFileSync("./build/Release/linq.node", `${prebuiltDir}/linq.node`);34 fs.copyFileSync("./scripts/postinstall.js", "dist/postinstall.js");35} catch (e) {36 helpers.error(`${e}`);37 process.exit(-1);...
Using AI Code Generation
1module.exports = {2 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx|mdx)'],3 {4 options: {5 },6 },7 webpackFinal: async (config) => {8 config.resolve.alias = {9 '@storybook/react': path.resolve(__dirname, 'node_modules/@storybook/react'),10 '@storybook/addon-docs': path.resolve(__dirname, 'node_modules/@storybook/addon-docs'),11 '@storybook/addon-essentials': path.resolve(__dirname, 'node_modules/@storybook/addon-essentials'),12 };13 return config;14 },15};16module.exports = {17 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx|mdx)'],18 {19 options: {20 },21 },22 webpackFinal: async (config) => {23 config.resolve.alias = {24 '@storybook/react': path.resolve(__dirname, 'node_modules/@storybook/react'),25 '@storybook/addon-docs': path.resolve(__dirname, 'node_modules/@storybook/addon-docs'),26 '@storybook/addon-essentials': path.resolve(__dirname, 'node_modules/@storybook/addon-essentials'),27 };28 return config;29 },30};31const path = require('path');32module.exports = async ({ config, mode }) => {33 config.resolve.alias = {34 '@storybook/react': path.resolve(__dirname, 'node_modules/@storybook/react'),35 '@storybook/addon-docs': path.resolve(__dirname, 'node_modules/@storybook/addon-docs'),36 '@storybook/addon-essentials': path.resolve(__dirname, 'node_modules/@storybook/addon-essentials'),37 };38 return config;39};
Using AI Code Generation
1const path = require('path');2module.exports = {3 stories: ['../stories/**/*.stories.(js|mdx)'],4 webpackFinal: async (config) => {5 config.module.rules.push({6 include: path.resolve(__dirname, '../'),7 });8 return config;9 },10};11const path = require('path');12module.exports = {13 stories: ['../stories/**/*.stories.(js|mdx)'],14 webpackFinal: async (config) => {15 config.module.rules.push({16 include: path.resolve(__dirname, '../'),17 });18 return config;19 },20};21import { addDecorator } from '@storybook/react';22import { withA11y } from '@storybook/addon-a11y';23import { withKnobs } from '@storybook/addon-knobs';24import { withContexts } from '@storybook/addon-contexts/react';25import { withTests } from '@storybook/addon-jest';26import { with
Using AI Code Generation
1const storybookRoot = require('storybook-root');2const prebuiltDir = storybookRoot.prebuiltDir();3console.log(prebuiltDir);4const storybookRoot = require('storybook-root');5const prebuiltDir = storybookRoot.prebuiltDir();6console.log(prebuiltDir);7const storybookRoot = require('storybook-root');8const prebuiltDir = storybookRoot.prebuiltDir();9console.log(prebuiltDir);10const storybookRoot = require('storybook-root');11const prebuiltDir = storybookRoot.prebuiltDir();12console.log(prebuiltDir);13const storybookRoot = require('storybook-root');14const prebuiltDir = storybookRoot.prebuiltDir();15console.log(prebuiltDir);16const storybookRoot = require('storybook-root');17const prebuiltDir = storybookRoot.prebuiltDir();18console.log(prebuiltDir);19const storybookRoot = require('storybook-root');20const prebuiltDir = storybookRoot.prebuiltDir();21console.log(prebuiltDir);22const storybookRoot = require('storybook-root');23const prebuiltDir = storybookRoot.prebuiltDir();24console.log(prebuiltDir);25const storybookRoot = require('storybook-root');26const prebuiltDir = storybookRoot.prebuiltDir();27console.log(prebuiltDir);28const storybookRoot = require('storybook-root');29const prebuiltDir = storybookRoot.prebuiltDir();30console.log(prebuiltDir);31const storybookRoot = require('storybook-root');32const prebuiltDir = storybookRoot.prebuiltDir();33console.log(prebuiltDir);
Using AI Code Generation
1const prebuiltDir = require("storybook-root-dir").prebuiltDir;2const path = require("path");3module.exports = {4 stories: [path.join(prebuiltDir, "stories/*.stories.js")],5};6const prebuiltDir = require("storybook-root-dir").prebuiltDir;7const path = require("path");8module.exports = (baseConfig, env, config) => {9 config.module.rules.push({10 test: /\.(ts|tsx)$/,11 {12 loader: require.resolve("ts-loader")13 },14 {15 loader: require.resolve("react-docgen-typescript-loader")16 }17 });18 config.module.rules.push({19 test: /\.(stories|story)\.js?$/,20 {21 loader: require.resolve("@storybook/addon-storysource/loader"),22 options: { parser: "javascript" }23 }24 });25 config.resolve.extensions.push(".ts", ".tsx");26 return config;27};28import "@storybook/addon-actions/register";29import "@storybook/addon-links/register";30import "@storybook/addon-knobs/register";31import "@storybook/addon-notes/register";32import "@storybook/addon-storysource/register";33import "@storybook/addon-viewport/register";34import "@storybook/addon-backgrounds/register";35import "@storybook/addon-a11y/register";36import { configure } from "@storybook/react";37import { setOptions } from "@storybook/addon-options";38setOptions({
Using AI Code Generation
1import { prebuiltDir } from 'storybook-root';2const path = require('path');3module.exports = {4 stories: [path.join(prebuiltDir, 'stories/**/*.stories.@(js|jsx|ts|tsx)')],5};6{7 "compilerOptions": {8 "paths": {9 }10 },11}12{13 "scripts": {14 },15 "devDependencies": {
Using AI Code Generation
1const path = require('path');2const prebuiltDir = path.resolve(__dirname, '../../dist');3module.exports = (baseConfig, env, defaultConfig) => {4 defaultConfig.resolve.modules.push(prebuiltDir);5 return defaultConfig;6};7import { configure } from '@storybook/react';8const req = require.context('../../dist', true, /\.stories\.js$/);9function loadStories() {10 req.keys().forEach(filename => req(filename));11}12configure(loadStories, module);13import '@storybook/addon-actions/register';14import '@storybook/addon-links/register';15import '@storybook/addon-knobs/register';16import 'storybook-addon-jsx/register';17import 'storybook-addon-react-docgen/register';18import '@storybook/addon-storysource/register';19import React from 'react';20import { addParameters } from '@storybook/react';21import { DocsPage, DocsContainer } from '@storybook/addon-docs/blocks';22import { ThemeProvider } from 'styled-components';23import { theme } from '../../dist/theme';24addParameters({25 options: {26 },27 docs: {28 },29});30 Story => (31 <ThemeProvider theme={theme}>32];33import { addons } from '@storybook/addons';34import { themes } from '@storybook/theming';35addons.setConfig({36});37{38 "compilerOptions": {39 "paths": {40 }41 },42}
Using AI Code Generation
1const storybookRoot = require('./storybook-root').prebuiltDir(__dirname);2module.exports = {3 stories: [`${storybookRoot}/stories/**/*.stories.(js|jsx|ts|tsx)`],4 addons: [`${storybookRoot}/addons`],5};6const storybookRoot = require('../storybook-root').prebuiltDir(__dirname);7module.exports = {8 stories: [`${storybookRoot}/stories/**/*.stories.(js|jsx|ts|tsx)`],9 addons: [`${storybookRoot}/addons`],10};11const storybookRoot = require('../storybook-root').prebuiltDir(__dirname);12module.exports = {13 stories: [`${storybookRoot}/stories/**/*.stories.(js|jsx|ts|tsx)`],14 addons: [`${storybookRoot}/addons`],15};16const storybookRoot = require('../storybook-root').prebuiltDir(__dirname);17module.exports = {18 stories: [`${storybookRoot}/stories/**/*.stories.(js|jsx|ts|tsx)`],19 addons: [`${storybookRoot}/addons`],20};21const storybookRoot = require('../storybook-root').prebuiltDir(__dirname);22module.exports = {23 stories: [`${storybookRoot}/stories/**/*.stories.(js|jsx|ts|tsx)`],24 addons: [`${storybookRoot}/addons`],25};26const storybookRoot = require('../storybook-root').prebuiltDir(__dirname);27module.exports = {28 stories: [`${storybookRoot}/stories/**/*.stories.(js|jsx|ts|tsx)`],29 addons: [`${storybookRoot}/addons`],30};31const storybookRoot = require('../storybook-root').prebuiltDir(__dirname);32module.exports = {33 stories: [`${storybookRoot}/stories/**/*.stories.(js|jsx|ts|tsx)`],34 addons: [`${storybookRoot}/
Using AI Code Generation
1const root = require('storybook-root');2const prebuiltDir = root.prebuiltDir();3console.log(prebuiltDir);4const root = require('storybook-root');5const prebuiltDir = root.prebuiltDir();6console.log(prebuiltDir);7const root = require('storybook-root');8const prebuiltDir = root.prebuiltDir();9console.log(prebuiltDir);10const root = require('storybook-root');11const prebuiltDir = root.prebuiltDir();12console.log(prebuiltDir);13const root = require('storybook-root');14const prebuiltDir = root.prebuiltDir();15console.log(prebuiltDir);16const root = require('storybook-root');17const prebuiltDir = root.prebuiltDir();18console.log(prebuiltDir);19const root = require('storybook-root');20const prebuiltDir = root.prebuiltDir();21console.log(prebuiltDir);22const root = require('storybook-root');23const prebuiltDir = root.prebuiltDir();24console.log(prebuiltDir);25const root = require('storybook-root');26const prebuiltDir = root.prebuiltDir();27console.log(prebuiltDir);
Using AI Code Generation
1const root = require('storybook-root')2console.log(root.prebuiltDir())3const root = require('storybook-root')4console.log(root.prebuiltDir())5const root = require('storybook-root')6console.log(root.prebuiltDir())7const root = require('storybook-root')8console.log(root.prebuiltDir())9const root = require('storybook-root')10console.log(root.prebuiltDir())11const root = require('storybook-root')12console.log(root.prebuiltDir())13const root = require('storybook-root')14console.log(root.prebuiltDir())15const root = require('storybook-root')16console.log(root.prebuiltDir())17const root = require('storybook-root')18console.log(root.prebuiltDir())19const root = require('storybook-root')20console.log(root.prebuiltDir())
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!!