How to use normalizeAssetPatterns method in storybook-root

Best JavaScript code snippet using storybook-root

sass-build-task.ts

Source:sass-build-task.ts Github

copy

Full Screen

...29 const syncHost = new virtualFs.SyncDelegateHost<FS.Stats>(host);30 if (!options.tasks.data.sassBundle) {31 return;32 }33 const assets = normalizeAssetPatterns(34 options.tasks.data.sassBundle.entries,35 syncHost as any,36 root,37 projectRoot,38 sourceRoot,39 );40 const copyPatterns = buildCopyPatterns(root, assets);41 const copyOptions = { ignore: ['.gitkeep', '**/.DS_Store', '**/Thumbs.db'] };42 log.info('Bundling a sass bundles...');43 const promises = copyPatterns.map( pattern => {44 const fullPattern = pattern.context + pattern.from.glob;45 const opts = { ...copyOptions, dot: pattern.from.dot };46 return globby(fullPattern, opts)47 .then(entries => {48 const entryPromises = entries.map( entry => {49 const cleanFilePath = entry.replace(pattern.context, '');50 const to = Path.resolve(root, pattern.to, cleanFilePath);51 const pathToFolder = Path.dirname(to);52 pathToFolder.split('/').reduce((p, folder) => {53 p += folder + '/';54 if (!FS.existsSync(p)) {55 FS.mkdirSync(p);56 }57 return p;58 }, '');59 return bundleScss(root, entry, to);60 });61 return Promise.all(entryPromises);62 });63 });64 try {65 await Promise.all(promises);66 } catch (err) {67 builderContext.logger.error(err.toString());68 throw err;69 }70}71async function sassCompileTask(context: EntryPointTaskContext) {72 const globalContext = context.context();73 if (context.epNode.data.entryPoint.isSecondaryEntryPoint) {74 return;75 }76 const { builderContext, workspace, root, projectRoot, sourceRoot, options } = globalContext;77 const host = new virtualFs.AliasHost(workspace.host as virtualFs.Host<FS.Stats>);78 const syncHost = new virtualFs.SyncDelegateHost<FS.Stats>(host);79 if (!options.tasks.data.sassCompile) {80 return;81 }82 const assets = normalizeAssetPatterns(83 options.tasks.data.sassCompile.entries,84 syncHost as any,85 root,86 projectRoot,87 sourceRoot,88 );89 const copyPatterns = buildCopyPatterns(root, assets);90 log.info('Compiling sass bundles...');91 const destPath = Path.join(root, copyPatterns[0].to);92 const taskName = context.epNode.data.entryPoint.moduleId + ':css';93 task(taskName, () => {94 return buildScssPipeline(copyPatterns[0].context, [ Path.join(root, 'node_modules/') ], true).pipe(dest(destPath));95 });96 try {...

Full Screen

Full Screen

normalize-asset-patterns.js

Source:normalize-asset-patterns.js Github

copy

Full Screen

...15 super(`The ${path} asset path must start with the project source root.`);16 }17}18exports.MissingAssetSourceRootException = MissingAssetSourceRootException;19function normalizeAssetPatterns(assetPatterns, root, projectRoot, maybeSourceRoot) {20 // When sourceRoot is not available, we default to ${projectRoot}/src.21 const sourceRoot = maybeSourceRoot || (0, core_1.join)(projectRoot, 'src');22 const resolvedSourceRoot = (0, core_1.resolve)(root, sourceRoot);23 if (assetPatterns.length === 0) {24 return [];25 }26 return assetPatterns.map((assetPattern) => {27 // Normalize string asset patterns to objects.28 if (typeof assetPattern === 'string') {29 const assetPath = (0, core_1.normalize)(assetPattern);30 const resolvedAssetPath = (0, core_1.resolve)(root, assetPath);31 // Check if the string asset is within sourceRoot.32 if (!resolvedAssetPath.startsWith(resolvedSourceRoot)) {33 throw new MissingAssetSourceRootException(assetPattern);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { normalizeAssetPatterns } = require('storybook-root-config');2module.exports = {3 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],4 webpackFinal: async (config) => {5 config.module.rules = normalizeAssetPatterns(config.module.rules);6 return config;7 },8};9const path = require('path');10const fs = require('fs');11const glob = require('glob');12const { getBabelLoader } = require('react-app-rewired');13const root = process.cwd();14module.exports = {15};16function normalizeAssetPatterns(rules) {17 const fileLoaderRule = rules.find((rule) => rule.test && rule.test.test('.svg'));18 fileLoaderRule.exclude = /\.svg$/;19 const svgRule = {20 include: [path.resolve(root, 'src')],21 };22 const babelLoader = getBabelLoader(rules);23 const include = babelLoader.include || [];24 babelLoader.include = [...include, path.resolve(root, 'src')];25 return [...rules, svgRule];26}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { normalizeAssetPatterns } = require('../node_modules/@storybook/core/dist/server/utils');2module.exports = {3 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],4 webpackFinal: async (config) => {5 return config;6 },7 core: {8 },9 typescript: {10 checkOptions: {},11 reactDocgenTypescriptOptions: {12 propFilter: (prop) =>13 (prop.parent ? !/node_modules/.test(prop.parent.fileName) : true) &&14 (prop.parent ? !/node_modules/.test(prop.parent.fileName) : true),15 },16 },17};18const path = require('path');19const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');20const { normalizeAssetPatterns } = require('../node_modules/@storybook/core/dist/server/utils');21module.exports = async ({ config }) => {22 config.resolve.plugins = config.resolve.plugins || [];23 config.resolve.plugins.push(new TsconfigPathsPlugin());24 config.resolve.alias = {25 '@storybook/core': path.resolve(__dirname, '../node_modules/@storybook/core'),26 '@storybook/core-server': path.resolve(__dirname, '../node_modules/@storybook/core-server'),27 };28 config.module.rules.push({29 test: /\.(ts|tsx)$/,30 loader: require.resolve('babel-loader'),31 options: {32 presets: [['react-app', { flow: false, typescript: true }]],33 },34 });35 config.module.rules.push({36 test: /\.(scss|sass|css)$/,37 include: path.resolve(__dirname, '../'),38 });39 config.resolve.extensions.push('.ts', '.tsx');40 config.resolve.extensions.push('.scss', '.sass', '.css');41 config.resolve.extensions.push('.json');42 return config;43};

Full Screen

Using AI Code Generation

copy

Full Screen

1const { normalizeAssetPatterns } = require('@storybook/core-common');2const assetPatterns = normalizeAssetPatterns([3 { from: 'src/assets', to: 'assets' },4 { from: 'src/fonts', to: 'fonts' },5]);6module.exports = {7 stories: ['../src/**/*.stories.@(js|mdx)'],8 webpackFinal: async (config) => {9 config.module.rules.push({10 include: path.resolve(__dirname, '../'),11 });12 config.module.rules.push({13 include: path.resolve(__dirname, '../'),14 });15 config.module.rules.push({16 include: path.resolve(__dirname, '../'),17 });18 config.module.rules.push({19 test: /\.(woff|woff2|eot|ttf|otf)$/,20 include: path.resolve(__dirname, '../'),21 });22 config.module.rules.push({23 test: /\.(png|jpg|gif)$/,24 {25 options: {26 },27 },28 include: path.resolve(__dirname, '../'),29 });30 config.module.rules.push({31 test: /\.(ts|tsx)$/,32 {33 loader: require.resolve('ts-loader'),34 options: {35 configFile: path.resolve(__dirname, '../tsconfig.json'),36 },37 },38 {39 loader: require.resolve('react-docgen-typescript-loader'),40 options: {41 tsconfigPath: path.resolve(__dirname, '../tsconfig.json'),42 },43 },44 });45 config.resolve.extensions.push('.ts', '.tsx');46 config.resolve.alias = {47 '@components': path.resolve(__dirname, '../src/components'),48 '@pages': path.resolve(__dirname, '../src/pages'),

Full Screen

Using AI Code Generation

copy

Full Screen

1const { normalizeAssetPatterns } = require('path/to/storybook/root');2const { getWebpackConfig } = require('@storybook/core/server');3module.exports = async (baseConfig, env) => {4 const config = await getWebpackConfig({ configDir: __dirname, ...env });5 const assetPatterns = normalizeAssetPatterns(config.module.rules);6 return config;7};8module.exports = async (baseConfig, env) => {9 const config = await require('path/to/test.js')(baseConfig, env);10 return config;11};

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const { normalizeAssetPatterns } = require('storybook-root-config');3module.exports = {4 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],5 webpackFinal: async (config) => {6 normalizeAssetPatterns(config.module.rules);7 return config;8 },9};

Full Screen

Using AI Code Generation

copy

Full Screen

1const {normalizeAssetPatterns} = require('storybook-root');2];3const normalizedAssetPatterns = normalizeAssetPatterns(assetPatterns);4console.log(normalizedAssetPatterns);5const {getPreviewHeadHtml} = require('storybook-root');6const html = getPreviewHeadHtml();7console.log(html);8const {getManagerHeadHtml} = require('storybook-root');9const html = getManagerHeadHtml();10console.log(html);11const {getPreviewBodyHtml} = require('storybook-root');12const html = getPreviewBodyHtml();13console.log(html);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { normalizeAssetPatterns } = require('@storybook/core/server');2const path = require('path');3const config = require('../.storybook/main.js');4const { configDir } = config;5const storybookStaticDir = path.join(configDir, '../public');6const appStaticDir = path.join(configDir, '../public');7 {8 },9 {10 },11];12const normalizedAssetPatterns = normalizeAssetPatterns(13);14console.log(normalizedAssetPatterns);15 {16 globOptions: { ignore: [ '**/.DS_Store' ] }17 },18 {19 globOptions: { ignore: [ '**/.DS_Store' ] }20 }21const path = require('path');22const configDir = path.resolve(__dirname);23module.exports = {24 webpackFinal: async (config) => {25 return config;26 },27};

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const { normalizeAssetPatterns } = require('@storybook/core-common');3const glob = require('glob');4const storybookAssets = normalizeAssetPatterns(5 {6 from: path.resolve(__dirname, '../storybook'),7 to: path.resolve(__dirname, '../storybook-dist'),8 globOptions: {9 },10 },11 path.resolve(__dirname, '../')12);13const files = storybookAssets.map((asset) => {14 return glob.sync(asset.from, asset.globOptions);15});16console.log(files);17const path = require('path');18module.exports = {19 entry: {20 },21 output: {22 path: path.resolve(__dirname, '../'),23 },24};

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