How to use packageDir method in storybook-root

Best JavaScript code snippet using storybook-root

rollup.config.ts

Source:rollup.config.ts Github

copy

Full Screen

1import nodeResolve from "@rollup/plugin-node-resolve"2import visualizer from "rollup-plugin-visualizer"3import commonjs from "@rollup/plugin-commonjs"4import { terser } from "rollup-plugin-terser"5import replace from "@rollup/plugin-replace"6import svelte from "rollup-plugin-svelte"7import babel from "@rollup/plugin-babel"8import { RollupOptions } from "rollup"9import size from "rollup-plugin-size"10import dts from "rollup-plugin-dts"11import path from "path"12type Options = {13 input: string14 packageDir: string15 external: RollupOptions["external"]16 banner: string17 jsName: string18 outputFile: string19 globals: Record<string, string>20}21const umdDevPlugin = (type: "development" | "production") =>22 replace({23 "process.env.NODE_ENV": `"${type}"`,24 delimiters: ["", ""],25 preventAssignment: true,26 })27const babelPlugin = babel({28 babelHelpers: "bundled",29 exclude: /node_modules/,30 extensions: [".ts", ".tsx"],31})32export default function rollup(options: RollupOptions): RollupOptions[] {33 return [34 ...buildConfigs({35 name: "js-sdk",36 packageDir: "packages/js-sdk",37 jsName: "JsSDK",38 outputFile: "js-sdk",39 entryFile: "src/index.ts",40 globals: {},41 }),42 ...buildConfigs({43 name: "react-sdk",44 packageDir: "packages/react-sdk",45 jsName: "ReactSDK",46 outputFile: "react-sdk",47 entryFile: "src/index.tsx",48 globals: {49 react: "React",50 },51 }),52 ]53}54function buildConfigs(opts: {55 packageDir: string56 name: string57 jsName: string58 outputFile: string59 entryFile: string60 globals: Record<string, string>61}): RollupOptions[] {62 const input = path.resolve(opts.packageDir, opts.entryFile)63 const externalDeps = Object.keys(opts.globals)64 const external = (moduleName) => externalDeps.includes(moduleName)65 const banner = createBanner(opts.name)66 const options: Options = {67 input,68 jsName: opts.jsName,69 outputFile: opts.outputFile,70 packageDir: opts.packageDir,71 external,72 banner,73 globals: opts.globals,74 }75 return [76 esm(options),77 cjs(options),78 umdDev(options),79 umdProd(options),80 types(options),81 ]82}83function esm({ input, packageDir, external, banner }: Options): RollupOptions {84 return {85 // ESM86 external,87 input,88 output: {89 format: "esm",90 sourcemap: true,91 dir: `${packageDir}/build/esm`,92 banner,93 },94 plugins: [95 // svelte({96 // compilerOptions: {97 // hydratable: true,98 // },99 // }),100 commonjs(),101 babelPlugin,102 nodeResolve({ extensions: [".ts", ".tsx"] }),103 ],104 }105}106function cjs({ input, external, packageDir, banner }: Options): RollupOptions {107 return {108 // CJS109 external,110 input,111 output: {112 format: "cjs",113 sourcemap: true,114 dir: `${packageDir}/build/cjs`,115 preserveModules: true,116 exports: "named",117 banner,118 },119 plugins: [120 svelte(),121 commonjs(),122 babelPlugin,123 nodeResolve({ extensions: [".ts", ".tsx"] }),124 ],125 }126}127function umdDev({128 input,129 external,130 packageDir,131 outputFile,132 globals,133 banner,134 jsName,135}: Options): RollupOptions {136 return {137 // UMD (Dev)138 external,139 input,140 output: {141 format: "umd",142 sourcemap: true,143 file: `${packageDir}/build/umd/index.development.js`,144 name: jsName,145 globals,146 banner,147 },148 plugins: [149 svelte(),150 commonjs(),151 babelPlugin,152 nodeResolve({ extensions: [".ts", ".tsx"] }),153 umdDevPlugin("development"),154 ],155 }156}157function umdProd({158 input,159 external,160 packageDir,161 outputFile,162 globals,163 banner,164 jsName,165}: Options): RollupOptions {166 return {167 // UMD (Prod)168 external,169 input,170 output: {171 format: "umd",172 sourcemap: true,173 file: `${packageDir}/build/umd/index.production.js`,174 name: jsName,175 globals,176 banner,177 },178 plugins: [179 svelte(),180 babelPlugin,181 commonjs(),182 nodeResolve({ extensions: [".ts", ".tsx"] }),183 umdDevPlugin("production"),184 terser({185 mangle: true,186 compress: true,187 }),188 size({}),189 visualizer({190 filename: `${packageDir}/build/stats-html.html`,191 gzipSize: true,192 }),193 visualizer({194 filename: `${packageDir}/build/stats-react.json`,195 json: true,196 gzipSize: true,197 }),198 ],199 }200}201function types({202 input,203 packageDir,204 external,205 banner,206}: Options): RollupOptions {207 return {208 // TYPES209 external,210 input,211 output: {212 format: "es",213 file: `${packageDir}/build/types/index.d.ts`,214 banner,215 },216 plugins: [dts()],217 }218}219function createBanner(libraryName: string) {220 return `/**221 * ${libraryName}222 *223 * Copyright (c) Everfund224 *225 * This source code is licensed under the MIT license found in the226 * LICENSE.md file in the root directory of this source tree.227 *228 * @license MIT229 */`...

Full Screen

Full Screen

modules.ts

Source:modules.ts Github

copy

Full Screen

1import fs from 'fs'2import { resolve } from 'path'3import { extraModules, nuxtConfig, uiFrameworks } from './constants'4import type { Module } from './types'5import { installESLint, installJSHint, installTSLint } from './installers'6const extrasRoot = resolve(__dirname, '..', 'extras')7export function installUiFramework(packageDir: string, uiFramework: any) {8 const uiFrameworkModule = uiFrameworks.find(m => m.name === uiFramework)9 const packageJson = JSON.parse(fs.readFileSync(`${packageDir}/package.json`, 'utf8'))10 if (uiFrameworkModule?.isDev)11 packageJson.devDependencies[uiFrameworkModule.package] = '*'12 else if (uiFrameworkModule?.isDev === false)13 packageJson.dependencies[uiFrameworkModule.package] = '*'14 fs.writeFileSync(`${packageDir}/package.json`, JSON.stringify(packageJson, null, 2))15 sortPackageJson(packageDir)16}17export function addExtraModules(packageDir: string, selectedModules: any): void {18 const packageJson = JSON.parse(fs.readFileSync(`${packageDir}/package.json`, 'utf8'))19 for (const selectedModule of selectedModules) {20 const module: Module | undefined = extraModules.find(m => m.name === selectedModule.split(' | ')[0])21 if (module?.isDev)22 packageJson.devDependencies[module.name] = '*'23 // If you don't use it gives an error:24 // "TypeError: Object is possibly 'undefined'"25 else if (module?.isDev === false)26 packageJson.dependencies[module.name] = '*'27 if (module?.folder)28 fs.mkdirSync(`${packageDir}/${module.folder.name}`)29 if (module?.extra) {30 for (const extraModule of module.extra) {31 if (extraModule.isDev)32 packageJson.devDependencies[extraModule.name] = '*'33 else34 packageJson.dependencies[extraModule.name] = '*'35 }36 }37 }38 fs.writeFileSync(`${packageDir}/package.json`, JSON.stringify(packageJson, null, 2))39 sortPackageJson(packageDir)40}41export function installLinter(packageDir: string, linterModule: string) {42 // Compare linters and install the selected one43 switch (linterModule.toLowerCase()) {44 case 'eslint':45 installESLint(packageDir)46 break47 case 'jshint':48 installJSHint(packageDir)49 break50 case 'tslint':51 installTSLint(packageDir)52 break53 default:54 break55 }56 // Save package.json57 sortPackageJson(packageDir)58}59export function installPrettier(packageDir: string, hasEslint: boolean) {60 // Parse package.json, add prettier dependencies and scripts61 const packageJson = JSON.parse(fs.readFileSync(`${packageDir}/package.json`, 'utf8'))62 packageJson.devDependencies.prettier = '*'63 if (hasEslint)64 packageJson.devDependencies['eslint-config-prettier'] = '*'65 packageJson.devDependencies.typescript = '*'66 // Add prettier scripts67 packageJson.scripts.format = 'prettier .'68 packageJson.scripts['format:write'] = 'prettier --write .'69 // Save package.json and copy prettier configuration70 // And if .eslintrc exists, delete it and copy prettier configuration71 fs.copyFileSync(`${extrasRoot}/.prettierrc`, `${packageDir}/.prettierrc`)72 if (hasEslint && fs.existsSync(`${packageDir}/.eslintrc`))73 fs.unlinkSync(`${packageDir}/.eslintrc`)74 if (hasEslint)75 fs.copyFileSync(`${extrasRoot}/.eslintrc-prettier`, `${packageDir}/.eslintrc`)76 fs.writeFileSync(`${packageDir}/package.json`, JSON.stringify(packageJson, null, 2))77 sortPackageJson(packageDir)78}79export function updateNuxtConfig(packageDir: string, modules: any) {80 modules = modules.map((module: any) => `"${module.split(' | ')[0]}"`)81 const replacedNuxtConfig = nuxtConfig.replace('\nmodules:[]', `\nmodules: [${modules.join(', ')}]`)82 fs.writeFileSync(`${packageDir}/nuxt.config.ts`, replacedNuxtConfig)83}84function sortPackageJson(packageDir: string) {85 const packageJson = JSON.parse(fs.readFileSync(`${packageDir}/package.json`, 'utf8'))86 packageJson.devDependencies = Object.keys(packageJson.devDependencies).sort().reduce(87 (obj: any, key) => {88 obj[key] = packageJson.devDependencies[key]89 return obj90 },91 {},92 )93 packageJson.dependencies = Object.keys(packageJson.dependencies).sort().reduce(94 (obj: any, key) => {95 obj[key] = packageJson.dependencies[key]96 return obj97 },98 {},99 )100 fs.writeFileSync(`${packageDir}/package.json`, JSON.stringify(packageJson, null, 2))...

Full Screen

Full Screen

clean-up-package.js

Source:clean-up-package.js Github

copy

Full Screen

1const path = require('path'),2 fsUtil = require('../util/fs-util'),3 fsPromise = require('../util/fs-promise'),4 runNpm = require('../util/run-npm');5module.exports = function cleanUpPackage(packageDir, options, logger) {6 'use strict';7 const npmOptions = (options && options['npm-options']) ? options['npm-options'].split(' ') : [],8 dedupe = function () {9 return options['optional-dependencies'] === false10 ? runNpm(packageDir, ['dedupe', '-q', '--no-package-lock', '--production', '--no-optional'].concat(npmOptions), logger, true)11 : runNpm(packageDir, ['dedupe', '-q', '--no-package-lock'].concat(npmOptions), logger, true);12 },13 runPostPackageScript = function () {14 const script = options['post-package-script'];15 if (script) {16 return runNpm(packageDir, ['run', script].concat(npmOptions), logger, options && options.quiet);17 }18 },19 fixEntryPermissions = function (path) {20 return fsPromise.statAsync(path)21 .then(stats => {22 const requiredMode = stats.isDirectory() ? 0o755 : 0o644;23 return (stats.mode & 0o777) | requiredMode;24 })25 .then(mode => fsPromise.chmodAsync(path, mode));26 },27 fixFilePermissions = function () {28 return Promise.all(29 fsUtil.recursiveList(packageDir)30 .map(component => fixEntryPermissions(path.join(packageDir, component)))31 );32 },33 cleanUpDependencies = function () {34 if (options['optional-dependencies'] === false) {35 logger.logApiCall('removing optional dependencies');36 fsUtil.rmDir(path.join(packageDir, 'node_modules'));37 return runNpm(packageDir, ['install', '-q', '--no-package-lock', '--no-audit', '--production', '--no-optional'].concat(npmOptions), logger, options && options.quiet);38 }39 };40 return Promise.resolve()41 .then(() => fsUtil.silentRemove(path.join(packageDir, 'package-lock.json')))42 .then(cleanUpDependencies)43 .then(dedupe)44 .then(runPostPackageScript)45 .then(() => fsUtil.silentRemove(path.join(packageDir, '.npmrc')))46 .then(fixFilePermissions)47 .then(() => packageDir);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { addDecorator } from '@storybook/react';2import { withRootDir } from 'storybook-root-decorator';3import path from 'path';4const root = path.join(__dirname, '../');5addDecorator(withRootDir(root));6import { addDecorator } from '@storybook/react';7import { withRootDir } from 'storybook-root-decorator';8import path from 'path';9const root = path.join(__dirname, '../');10addDecorator(withRootDir(root));11import { addDecorator } from '@storybook/react';12import { withRootDir } from 'storybook-root-decorator';13import path from 'path';14const root = path.join(__dirname, '../');15addDecorator(withRootDir(root));16import { addDecorator } from '@storybook/react';17import { withRootDir } from 'storybook-root-decorator';18import path from 'path';19const root = path.join(__dirname, '../');20addDecorator(withRootDir(root));21import { addDecorator } from '@storybook/react';22import { withRootDir } from 'storybook-root-decorator';23import path from 'path';24const root = path.join(__dirname, '../');25addDecorator(withRootDir(root));26import { addDecorator } from '@storybook/react';27import { withRootDir } from 'storybook-root-decorator';28import path from 'path';29const root = path.join(__dirname, '../');30addDecorator(withRootDir(root));31import { addDecorator } from '@storybook/react';32import { withRootDir } from 'storybook-root-decorator';33import path from 'path';34const root = path.join(__

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = require('storybook-root');2storybookRoot.packageDir('my-package');3const storybookRoot = require('storybook-root');4storybookRoot.packageDir('my-package');5const storybookRoot = require('storybook-root');6storybookRoot.packageDir('my-package');7const storybookRoot = require('storybook-root');8storybookRoot.packageDir('my-package');9const storybookRoot = require('storybook-root');10storybookRoot.packageDir('my-package');11const storybookRoot = require('storybook-root');12storybookRoot.packageDir('my-package');13const storybookRoot = require('storybook-root');14storybookRoot.packageDir('my-package');15const storybookRoot = require('storybook-root');16storybookRoot.packageDir('my-package');17const storybookRoot = require('storybook-root');18storybookRoot.packageDir('my-package');19const storybookRoot = require('storybook-root');20storybookRoot.packageDir('my-package');21const storybookRoot = require('storybook-root');22storybookRoot.packageDir('my-package');23const storybookRoot = require('storybook-root');24storybookRoot.packageDir('my-package');

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const root = require('storybook-root');3const packageDir = root.packageDir;4console.log('packageDir', packageDir);5const root = require('storybook-root');6const packageDir = root.packageDir;7console.log('packageDir', packageDir);8const root = require('storybook-root');9const packageDir = root.packageDir;10console.log('packageDir', packageDir);11const root = require('storybook-root');12const packageDir = root.packageDir;13console.log('packageDir', packageDir);14const root = require('storybook-root');15const packageDir = root.packageDir;16console.log('packageDir', packageDir);17const root = require('storybook-root');18const packageDir = root.packageDir;19console.log('packageDir', packageDir);20const root = require('storybook-root');21const packageDir = root.packageDir;22console.log('packageDir', packageDir);23const root = require('storybook-root');24const packageDir = root.packageDir;25console.log('packageDir', packageDir);26const root = require('storybook-root');27const packageDir = root.packageDir;28console.log('packageDir', packageDir);29const root = require('storybook-root');30const packageDir = root.packageDir;31console.log('packageDir', packageDir);32const root = require('storybook-root');33const packageDir = root.packageDir;34console.log('packageDir', packageDir);35const root = require('storybook-root');36const packageDir = root.packageDir;37console.log('packageDir', packageDir);38const root = require('storybook-root');39const packageDir = root.packageDir;40console.log('packageDir', packageDir);41const root = require('storybook-root');

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const storybookRootRequire = require('storybook-root-require');3const packageDir = storybookRootRequire.packageDir;4const rootPath = packageDir('my-package');5const testPath = path.join(rootPath, 'test.js');6console.log(testPath);7const path = require('path');8const storybookRootRequire = require('storybook-root-require');9const packageDirSync = storybookRootRequire.packageDirSync;10const rootPath = packageDirSync('my-package');11const testPath = path.join(rootPath, 'test.js');12console.log(testPath);13const path = require('path');14const storybookRootRequire = require('storybook-root-require');15const packageDir = storybookRootRequire.packageDir;16const rootPath = packageDir('my-package');17const testPath = path.join(rootPath, 'test.js');18console.log(testPath);19const path = require('path');20const storybookRootRequire = require('storybook-root-require');21const packageDirSync = storybookRootRequire.packageDirSync;22const rootPath = packageDirSync('my-package');23const testPath = path.join(rootPath, 'test.js');24console.log(testPath);25const path = require('path');26const storybookRootRequire = require('storybook-root-require');27const packageDir = storybookRootRequire.packageDir;28const rootPath = packageDir('my-package');29const testPath = path.join(rootPath, 'test.js');30console.log(testPath);31const path = require('path');32const storybookRootRequire = require('storybook-root-require');33const packageDirSync = storybookRootRequire.packageDirSync;

Full Screen

Using AI Code Generation

copy

Full Screen

1import { configure, addDecorator } from '@storybook/react';2import { withRootDecorator } from 'storybook-root-decorator';3addDecorator(withRootDecorator(['src']));4configure(require.context('../src', true, /\.stories\.js$/), module);5import { configure, addDecorator } from '@storybook/react';6import { withRootDecorator } from 'storybook-root-decorator';7addDecorator(withRootDecorator(['src']));8configure(require.context('../src', true, /\.stories\.js$/), module);9import { configure, addDecorator } from '@storybook/react';10import { withRootDecorator } from 'storybook-root-decorator';11addDecorator(withRootDecorator(['src']));12configure(require.context('../src', true, /\.stories\.js$/), module);13import { configure, addDecorator } from '@storybook/react';14import { withRootDecorator } from 'storybook-root-decorator';15addDecorator(withRootDecorator(['src']));16configure(require.context('../src', true, /\.stories\.js$/), module);17import { configure, addDecorator } from '@storybook/react';18import { withRootDecorator } from 'storybook-root-decorator';19addDecorator(withRootDecorator(['src']));20configure(require.context('../src', true, /\.stories\.js$/), module);21import { configure, addDecorator } from '@storybook/react';22import { withRootDecorator } from 'storybook-root-decorator';23addDecorator(withRootDecorator(['src']));24configure(require.context('../src', true, /\.stories\.js$/

Full Screen

Using AI Code Generation

copy

Full Screen

1import { packageDir } from 'storybook-root';2const path = packageDir('my-package');3import { packageDir } from 'storybook-root';4const path = packageDir('my-package');5import { packageDir } from 'storybook-root';6const path = packageDir('my-package');7import { packageDir } from 'storybook-root';8const path = packageDir('my-package');9import { packageDir } from 'storybook-root';10const path = packageDir('my-package');11import { packageDir } from 'storybook-root';12const path = packageDir('my-package');13import { packageDir } from 'storybook-root';14const path = packageDir('my-package');15import { packageDir } from 'storybook-root';16const path = packageDir('my-package');17import { packageDir } from 'storybook-root';18const path = packageDir('my-package');19import { packageDir } from 'storybook-root';20const path = packageDir('my-package');

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const rootPath = require('storybook-root').packageDir(__dirname);3console.log('rootPath: ', rootPath);4const path = require('path');5const rootPath = require('storybook-root').packageDir(__dirname, 'my-package');6console.log('rootPath: ', rootPath);7const path = require('path');8const rootPath = require('storybook-root').packageDir(__dirname, 'my-package', 'src');9console.log('rootPath: ', rootPath);10const path = require('path');11const rootPath = require('storybook-root').packageDir(__dirname, 'my-package', 'src', 'my-file.js');12console.log('rootPath: ', rootPath);13const path = require('path');14const rootPath = require('storybook-root').packageDir(__dirname, 'my-package', 'src', 'my-file.js', 'my-sub-directory');15console.log('rootPath: ', rootPath);16const path = require('path');17const rootPath = require('storybook-root').packageDir(__dirname, 'my-package', 'src', 'my-file.js', 'my-sub-directory', 'my-file.js');18console.log('rootPath: ', rootPath);19const path = require('path');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { packageDir } from 'storybook-root';2const pathToPackage = packageDir('my-package');3console.log(pathToPackage);4import { packageDir } from 'storybook-root';5const pathToPackage = packageDir('my-package');6console.log(pathToPackage);7import { packageDir } from 'storybook-root';8const pathToPackage = packageDir('my-package');9console.log(pathToPackage);

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