How to use prettierConfig method in storybook-root

Best JavaScript code snippet using storybook-root

contracts-gen.ts

Source:contracts-gen.ts Github

copy

Full Screen

1#!/usr/bin/env node2import { NameResolver } from '@0x/sol-resolver';3import { PackageJSON } from '@0x/types';4import { logUtils } from '@0x/utils';5import { CompilerOptions } from 'ethereum-types';6import * as fs from 'fs';7import * as _ from 'lodash';8import * as path from 'path';9import * as prettier from 'prettier';10import toSnakeCase = require('to-snake-case');11const SOLIDITY_EXTENSION = '.sol';12const DEFAULT_ARTIFACTS_DIR = 'artifacts';13const DEFAULT_CONTRACTS_DIR = 'contracts';14const DEFAULT_WRAPPERS_DIR = 'generated-wrappers';15const AUTO_GENERATED_BANNER = `/*16* -----------------------------------------------------------------------------17* Warning: This file is auto-generated by contracts-gen. Don't edit manually.18* -----------------------------------------------------------------------------19*/`;20const AUTO_GENERATED_BANNER_FOR_LISTS = `This list is auto-generated by contracts-gen. Don't edit manually.`;21(async () => {22 const packageDir = process.cwd();23 const compilerJSON = readJSONFile<CompilerOptions>('compiler.json');24 const contracts = compilerJSON.contracts;25 const contractsDir = compilerJSON.contractsDir || DEFAULT_CONTRACTS_DIR;26 const artifactsDir = compilerJSON.artifactsDir || DEFAULT_ARTIFACTS_DIR;27 const wrappersDir = DEFAULT_WRAPPERS_DIR;28 if (!_.isArray(contracts)) {29 throw new Error('Unable to run the generator bacause contracts key in compiler.json is not of type array');30 }31 const prettierConfig = await prettier.resolveConfig(packageDir);32 generateCompilerJSONContractsList(contracts, contractsDir, prettierConfig);33 generateArtifactsTs(contracts, artifactsDir, prettierConfig);34 generateWrappersTs(contracts, wrappersDir, prettierConfig);35 generateTsConfigJSONFilesList(contracts, artifactsDir, prettierConfig);36 generatePackageJSONABIConfig(contracts, artifactsDir, prettierConfig);37 process.exit(0);38})().catch(err => {39 logUtils.log(err);40 process.exit(1);41});42function generateCompilerJSONContractsList(43 contracts: string[],44 contractsDir: string,45 prettierConfig: prettier.Options | null,46): void {47 const COMPILER_JSON_FILE_PATH = 'compiler.json';48 const compilerJSON = readJSONFile<CompilerOptions>(COMPILER_JSON_FILE_PATH);49 compilerJSON.contracts = _.map(contracts, contract => {50 if (contract.endsWith(SOLIDITY_EXTENSION)) {51 // If it's already a relative path - NO-OP.52 return contract;53 } else {54 // If it's just a contract name - resolve it and rewrite.55 return new NameResolver(contractsDir).resolve(contract).path;56 }57 });58 compilerJSON.contracts = _.sortBy(compilerJSON.contracts);59 const compilerJSONString = JSON.stringify(compilerJSON);60 const formattedCompilerJSON = prettier.format(compilerJSONString, {61 ...prettierConfig,62 filepath: COMPILER_JSON_FILE_PATH,63 });64 fs.writeFileSync(COMPILER_JSON_FILE_PATH, formattedCompilerJSON);65}66function generateArtifactsTs(contracts: string[], artifactsDir: string, prettierConfig: prettier.Options | null): void {67 const imports = _.map(contracts, contract => {68 const contractName = path.basename(contract, SOLIDITY_EXTENSION);69 const importPath = path.join('..', artifactsDir, `${contractName}.json`);70 return `import * as ${contractName} from '${importPath}';`;71 });72 const sortedImports = _.sortBy(imports);73 const artifacts = _.map(contracts, contract => {74 const contractName = path.basename(contract, SOLIDITY_EXTENSION);75 if (contractName === 'ZRXToken') {76 // HACK(albrow): "as any" hack still required here because ZRXToken does not77 // conform to the v2 artifact type.78 return `${contractName}: (${contractName} as any) as ContractArtifact,`;79 } else {80 return `${contractName}: ${contractName} as ContractArtifact,`;81 }82 });83 const artifactsTs = `84 ${AUTO_GENERATED_BANNER}85 import { ContractArtifact } from 'ethereum-types';86 ${sortedImports.join('\n')}87 export const artifacts = {${artifacts.join('\n')}};88 `;89 const ARTIFACTS_TS_FILE_PATH = 'src/artifacts.ts';90 const formattedArtifactsTs = prettier.format(artifactsTs, { ...prettierConfig, filepath: ARTIFACTS_TS_FILE_PATH });91 fs.writeFileSync(ARTIFACTS_TS_FILE_PATH, formattedArtifactsTs);92}93function generateWrappersTs(contracts: string[], wrappersDir: string, prettierConfig: prettier.Options | null): void {94 const imports = _.map(contracts, contract => {95 const contractName = path.basename(contract, SOLIDITY_EXTENSION);96 const outputFileName = makeOutputFileName(contractName);97 const exportPath = path.join('..', wrappersDir, outputFileName);98 return `export * from '${exportPath}';`;99 });100 const sortedImports = _.sortBy(imports);101 const wrappersTs = `102 ${AUTO_GENERATED_BANNER}103 ${sortedImports.join('\n')}104 `;105 const WRAPPERS_TS_FILE_PATH = 'src/wrappers.ts';106 const formattedArtifactsTs = prettier.format(wrappersTs, { ...prettierConfig, filepath: WRAPPERS_TS_FILE_PATH });107 fs.writeFileSync(WRAPPERS_TS_FILE_PATH, formattedArtifactsTs);108}109function generateTsConfigJSONFilesList(110 contracts: string[],111 artifactsDir: string,112 prettierConfig: prettier.Options | null,113): void {114 const TS_CONFIG_FILE_PATH = 'tsconfig.json';115 const tsConfig = readJSONFile<any>(TS_CONFIG_FILE_PATH);116 tsConfig.files = _.map(contracts, contract => {117 const contractName = path.basename(contract, SOLIDITY_EXTENSION);118 const artifactPath = path.join(artifactsDir, `${contractName}.json`);119 return artifactPath;120 });121 tsConfig.files = _.sortBy(tsConfig.files);122 const tsConfigString = JSON.stringify(tsConfig);123 const formattedTsConfig = prettier.format(tsConfigString, { ...prettierConfig, filepath: TS_CONFIG_FILE_PATH });124 fs.writeFileSync(TS_CONFIG_FILE_PATH, formattedTsConfig);125}126function generatePackageJSONABIConfig(127 contracts: string[],128 artifactsDir: string,129 prettierConfig: prettier.Options | null,130): void {131 let packageJSON = readJSONFile<PackageJSON>('package.json');132 const contractNames = _.map(contracts, contract => {133 const contractName = path.basename(contract, SOLIDITY_EXTENSION);134 return contractName;135 });136 const sortedContractNames = _.sortBy(contractNames);137 packageJSON = {138 ...packageJSON,139 config: {140 ...packageJSON.config,141 'abis:comment': AUTO_GENERATED_BANNER_FOR_LISTS,142 abis: `${artifactsDir}/@(${sortedContractNames.join('|')}).json`,143 },144 };145 const PACKAGE_JSON_FILE_PATH = 'package.json';146 const packageJSONString = JSON.stringify(packageJSON);147 const formattedPackageJSON = prettier.format(packageJSONString, {148 ...prettierConfig,149 filepath: PACKAGE_JSON_FILE_PATH,150 });151 fs.writeFileSync(PACKAGE_JSON_FILE_PATH, formattedPackageJSON);152}153function makeOutputFileName(name: string): string {154 let fileName = toSnakeCase(name);155 // HACK: Snake case doesn't make a lot of sense for abbreviated names but we can't reliably detect abbreviations156 // so we special-case the abbreviations we use.157 fileName = fileName.replace('z_r_x', 'zrx').replace('e_r_c', 'erc');158 return fileName;159}160function readJSONFile<T>(filePath: string): T {161 const JSONString = fs.readFileSync(filePath, 'utf8');162 const parsed: T = JSON.parse(JSONString);163 return parsed;...

Full Screen

Full Screen

formatCode.js

Source:formatCode.js Github

copy

Full Screen

1import prettier from 'prettier/standalone'2import babel from 'prettier/parser-babel'3import prettierConfig from '../../../.prettierrc.json'4import isBrowser from '../../../src/lib/isBrowser'5const { printWidth } = prettierConfig.overrides.find(6 ({ files }) => files === 'docs/src/examples/**/*.js',7).options8delete prettierConfig.$schema9delete prettierConfig.overrides10// Heads up!11// Please use this function directly and don't reexport it in utils.12// https://github.com/prettier/prettier/issues/495913const formatCode = isBrowser()14 ? (code, parser = 'babel') => {15 if (!code) return ''16 const formatted = prettier.format(code, {17 ...prettierConfig,18 printWidth,19 parser,20 plugins: { babel },21 })22 return formatted.replace(/^;</, '<') // remove beginning semi in JSX/HTML23 }24 : (x) => x...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { prettierConfig } = require('@storybook/root-config');2module.exports = prettierConfig;3module.exports = {4 stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],5 webpackFinal: async (config) => {6 config.module.rules.push({7 include: path.resolve(__dirname, '../'),8 });9 return config;10 },11 typescript: {12 reactDocgenTypescriptOptions: {13 propFilter: (prop) => {14 if (prop.parent) {15 return !prop.parent.fileName.includes('node_modules');16 }17 return true;18 },19 },20 },21};

Full Screen

Using AI Code Generation

copy

Full Screen

1const prettierConfig = require('storybook-root/prettier.config.js')2const prettierIgnore = require('storybook-root/prettierIgnore.js')3const prettierIgnore = require('storybook-root/prettierIgnore.js')4const prettierIgnore = require('storybook-root/prettierIgnore.js')5const prettierIgnore = require('storybook-root/prettierIgnore.js')6const prettierIgnore = require('storybook-root/prettierIgnore.js')7const prettierIgnore = require('storybook-root/prettierIgnore.js')8const prettierIgnore = require('storybook-root/prettierIgnore.js')9const prettierIgnore = require('storybook-root/prettierIgnore.js')10const prettierIgnore = require('storybook-root/prettierIgnore.js')11const prettierIgnore = require('storybook-root/prettierIgnore.js')12const prettierIgnore = require('storybook-root/prettierIgnore.js')

Full Screen

Using AI Code Generation

copy

Full Screen

1import prettierConfig from 'storybook-root-configuration/prettier';2import webpackConfig from 'storybook-root-configuration/webpack';3import jestConfig from 'storybook-root-configuration/jest';4module.exports = {5 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],6};

Full Screen

Using AI Code Generation

copy

Full Screen

1const prettierConfig = require('./.storybook/prettierConfig');2module.exports = prettierConfig;3const prettierConfig = require('./test');4module.exports = prettierConfig;5const prettierConfig = require('./.storybook/prettierConfig');6module.exports = prettierConfig;7const prettierConfig = require('./.storybook/prettierConfig');8module.exports = prettierConfig.ignore;9const prettierConfig = require('./.storybook/prettierConfig');10module.exports = prettierConfig.ignore;11const prettierConfig = require('./.storybook/prettierConfig');12module.exports = prettierConfig.ignore;13const prettierConfig = require('./.storybook/prettierConfig');14module.exports = prettierConfig.ignore;15const prettierConfig = require('./.storybook/prettierConfig');16module.exports = prettierConfig.ignore;17const prettierConfig = require('./.storybook/prettierConfig');18module.exports = prettierConfig.ignore;19const prettierConfig = require('./.storybook/prettierConfig');20module.exports = prettierConfig.ignore;21const prettierConfig = require('./.storybook/prettierConfig');22module.exports = prettierConfig.ignore;23const prettierConfig = require('./.storybook/prettierConfig');24module.exports = prettierConfig.ignore;

Full Screen

Using AI Code Generation

copy

Full Screen

1import { prettierConfig } from '@storybook/addon-docs/blocks';2const prettierOptions = prettierConfig();3prettierOptions.tabWidth = 2;4export const parameters = {5 docs: {6 transformSource: (src, { kind, story }) => {7 const transformed = prettier.format(src, prettierOptions);8 return transformed;9 },10 },11};12module.exports = {13 stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],14 core: {15 },16};

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