How to use builderOptions method in storybook-root

Best JavaScript code snippet using storybook-root

build.ts

Source:build.ts Github

copy

Full Screen

1/**2 * Created by user on 2019/6/7.3 */4import _methodBuilder, {5 IHandleDescriptor,6 ConstructorLikeType,7 IMemberMethods,8 IHandleDescriptor2, IHandleDescriptor3, IHandleDescriptorReturn2,9} from '../../decorators/build';10import subobject, { IMethod } from '../../helper/subobject';11import { AbstractHttpClient } from '../abstract';12import { AxiosRequestConfig } from 'axios';13import { IParamMetadata } from '../../decorators/body';14import Bluebird from 'bluebird';15import { resultToURL } from 'get-http-result-url';16export interface IMethodBuilderCache17{18 requestConfig: AxiosRequestConfig,19 bool: boolean,20 requestConfigNew: AxiosRequestConfig,21 paramMetadata: IParamMetadata,22 autoRequest?: boolean,23 requested?: boolean,24 disableFallbackReturnValue?: boolean,25}26export interface IMethodBuilderOptions<T extends object, R>27{28 handler?: IHandleDescriptor3<T, R & IMethodBuilderCache>29 /**30 * @default true31 */32 autoRequest?: boolean;33 /**34 * 當 autoRequest 啟用時 會自動將回傳內容改為 response.data35 * @default true36 */37 returnData?: boolean;38 /**39 * 禁用當 returnValue == null 時回傳未處理的原始 value40 */41 disableFallbackReturnValue?: boolean,42}43/**44 * preset type for methodBuilder45 */46export function createMethodBuilder<T extends AbstractHttpClient, R = {}>(wrapFn?: IHandleDescriptor2<T, R & IMethodBuilderCache>)47{48 return function (handler?: IHandleDescriptor3<T, R & IMethodBuilderCache> | IMethodBuilderOptions<T, R>,49 builderOptions: IMethodBuilderOptions<T, R> | boolean = true,50 )51 {52 if (handler && typeof handler === 'object' && (builderOptions == null || builderOptions === true))53 {54 ([builderOptions, handler] = [handler, null]);55 }56 if (typeof builderOptions === 'boolean')57 {58 builderOptions = {59 autoRequest: builderOptions,60 } as IMethodBuilderOptions<T, R>61 }62 builderOptions ||= {} as IMethodBuilderOptions<T, R>;63 builderOptions.autoRequest ??= true;64 if (builderOptions.autoRequest)65 {66 builderOptions.returnData ??= true;67 }68 if (builderOptions.handler)69 {70 handler = builderOptions.handler71 }72 if (handler && typeof handler !== 'function')73 {74 throw new TypeError(`typeof handler != 'function'`)75 }76 let { autoRequest, disableFallbackReturnValue } = builderOptions;77 const old = handler as IHandleDescriptor3<T, R & IMethodBuilderCache>;78 handler = ((data: IHandleDescriptorReturn2<T, R & IMethodBuilderCache>) =>79 {80 const oldThis = data.thisArgv;81 data.autoRequest ??= autoRequest;82 data.disableFallbackReturnValue ??= disableFallbackReturnValue;83 if (wrapFn)84 {85 data = wrapFn.call(data.thisArgv, data as any);86 data.autoRequest ??= autoRequest;87 data.disableFallbackReturnValue ??= disableFallbackReturnValue;88 }89 if (old)90 {91 const { thisArgv = data.thisArgv, method = data.method, argv = data.argv } = old.call(oldThis, data as any) || data;92 data.autoRequest ??= autoRequest;93 data.disableFallbackReturnValue ??= disableFallbackReturnValue;94 data = {95 ...data,96 thisArgv,97 method,98 argv,99 };100 }101 (builderOptions as IMethodBuilderOptions<T, R>).autoRequest = data.autoRequest;102 (builderOptions as IMethodBuilderOptions<T, R>).disableFallbackReturnValue = data.disableFallbackReturnValue;103 if (data.autoRequest && !data.requested)104 {105 data.requested = true;106 //console.dir(data.thisArgv);107 return {108 ...data,109 builderOptions: builderOptions as IMethodBuilderOptions<T, R>,110 returnValue: Bluebird111 .resolve(data.thisArgv.$http(data.requestConfig))112 .then(function (ret)113 {114 // @ts-ignore115 data.thisArgv.$returnValue = ret;116 data.thisArgv.$response = ret;117 /*118 // @ts-ignore119 if (ret?.request?.res?.responseUrl)120 {121 // @ts-ignore122 data.thisArgv.$responseUrl = ret.request.res.responseUrl;123 }124 */125 data.thisArgv.$responseUrl = resultToURL(ret, {126 ignoreError: true,127 })?.href ?? data.thisArgv.$responseUrl;128 if ((builderOptions as IMethodBuilderOptions<T, R>).returnData)129 {130 // @ts-ignore131 data.thisArgv.$returnValueSource = data.thisArgv.$returnValue;132 return data.thisArgv.$returnValue = ret.data;133 }134 return ret;135 })136 ,137 };138 }139 return {140 ...data,141 builderOptions: builderOptions as IMethodBuilderOptions<T, R>,142 };143 });144 return _methodBuilder<T>(handler as any);145 };146}...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1"use strict";2var __importDefault = (this && this.__importDefault) || function (mod) {3 return (mod && mod.__esModule) ? mod : { "default": mod };4};5Object.defineProperty(exports, "__esModule", { value: true });6var webpack_1 = __importDefault(require("webpack"));7var builder_1 = __importDefault(require("./builder"));8var config_1 = __importDefault(require("./config"));9var server_1 = __importDefault(require("./server"));10var util_1 = require("./util");11var builderOptions = config_1.default.getBuildConfig();12// let devConfig: BaseConfig = {};13// let prodConfig: BaseConfig = {};14// builderOptions.envs = {15// // 环境变量配置16// dev: {17// envObj: {18// NODE_ENV: '"development"',19// API_HOST: '"/"',20// },21// },22// prod: {23// envObj: {24// NODE_ENV: '"production"',25// API_HOST: '""',26// },27// },28// }29builderOptions.currentEnv = 'dev';30var devConfig = builder_1.default.createDevConfig(builderOptions);31var prodConfig = builder_1.default.createProdConfig(builderOptions);32function builderWebpack4(cmd) {33 console.log(cmd);34 // 开发环境35 if (cmd === 'dev') {36 builderOptions.currentEnv = 'dev';37 devConfig = builder_1.default.createDevConfig(builderOptions);38 server_1.default(devConfig);39 }40 // 开发测试环境41 if (cmd === 'test') {42 builderOptions.currentEnv = 'test';43 prodConfig = builder_1.default.createProdConfig(builderOptions);44 build();45 }46 // 正式测试环境47 if (cmd === 'formalTest') {48 builderOptions.currentEnv = 'formalTest';49 prodConfig = builder_1.default.createProdConfig(builderOptions);50 build();51 }52 // 演示环境53 if (cmd === 'demo') {54 builderOptions.currentEnv = 'demo';55 prodConfig = builder_1.default.createProdConfig(builderOptions);56 build();57 }58 // 生产环境59 if (cmd === 'build') {60 builderOptions.currentEnv = 'prod';61 prodConfig = builder_1.default.createProdConfig(builderOptions);62 build();63 }64}65function build() {66 webpack_1.default(prodConfig, function (err, stats) {67 if (err) {68 console.log(err);69 util_1.postMessage.error(util_1.BuilderType.build, err);70 process.exit(2);71 }72 util_1.postMessage.success(util_1.BuilderType.build);73 console.log(stats &&74 stats.toString({75 chunks: false,76 colors: true,77 children: false,78 }));79 });80}81exports.default = builderWebpack4;82exports.default.devConfig = devConfig;83exports.default.prodConfig = prodConfig;...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

1import webpack from 'webpack';2import Builder from './builder';3import Config from './config';4import Server from './server';5import { postMessage, BuilderType } from "./util";6export interface BaseConfig {7 [propName: string]: any;8}9const builderOptions = Config.getBuildConfig();10// let devConfig: BaseConfig = {};11// let prodConfig: BaseConfig = {};12// builderOptions.envs = {13// // 环境变量配置14// dev: {15// envObj: {16// NODE_ENV: '"development"',17// API_HOST: '"/"',18// },19// },20// prod: {21// envObj: {22// NODE_ENV: '"production"',23// API_HOST: '""',24// },25// },26// }27builderOptions.currentEnv = 'dev';28let devConfig: BaseConfig = Builder.createDevConfig(builderOptions);29let prodConfig: BaseConfig = Builder.createProdConfig(builderOptions);30function builderWebpack4(cmd: string) {31 console.log(cmd);32 33 // 开发环境34 if (cmd === 'dev') {35 builderOptions.currentEnv = 'dev'36 devConfig = Builder.createDevConfig(builderOptions)37 Server(devConfig)38 }39 // 开发测试环境40 if (cmd === 'test') {41 builderOptions.currentEnv = 'test'42 prodConfig = Builder.createProdConfig(builderOptions)43 build()44 }45 // 正式测试环境46 if (cmd === 'formalTest') {47 builderOptions.currentEnv = 'formalTest'48 prodConfig = Builder.createProdConfig(builderOptions)49 build()50 }51 // 演示环境52 if (cmd === 'demo') {53 builderOptions.currentEnv = 'demo'54 prodConfig = Builder.createProdConfig(builderOptions)55 build()56 }57 // 生产环境58 if (cmd === 'build') {59 builderOptions.currentEnv = 'prod'60 prodConfig = Builder.createProdConfig(builderOptions)61 build()62 }63}64function build() {65 webpack(prodConfig, (err: any, stats: any) => {66 if (err) {67 console.log(err);68 postMessage.error(BuilderType.build, err);69 process.exit(2);70 }71 postMessage.success(BuilderType.build);72 console.log(73 stats &&74 stats.toString({75 chunks: false,76 colors: true,77 children: false,78 })79 );80 });81}82export default builderWebpack4;83exports.default.devConfig = devConfig;84exports.default.prodConfig = prodConfig;...

Full Screen

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