Best JavaScript code snippet using storybook-root
ts-default-options.js
Source:ts-default-options.js
1"use strict";2exports.__esModule = true;3var logger_impl_1 = require("./logger-impl");4var out_path_process_1 = require("./out-path-process");5var DefaultOptionsHolder = /** @class */ (function () {6 function DefaultOptionsHolder(defaultOptions, ts_impl, pluginState) {7 this.openConfigProject = true;8 this.defaultOptions = defaultOptions;9 this.pluginState = pluginState;10 if (defaultOptions && defaultOptions.project) {11 var configOptions = this.getConfigOptions(ts_impl, defaultOptions);12 this.options = configOptions.commonDefaultOptions;13 this.configFileName = configOptions.configFileName;14 }15 else {16 this.configFileName = pluginState.defaultConfig;17 this.openConfigProject = false;18 if (defaultOptions) {19 this.options = defaultOptions;20 }21 else if (this.configFileName) {22 var parsedInfo = this.getConfigOptionsForFile(ts_impl, this.configFileName);23 this.options = parsedInfo != null ? parsedInfo.commonDefaultOptions : null;24 }25 }26 if (pluginState.hasManualParams) {27 if (pluginState.mainFilePath) {28 this.mainFile = pluginState.mainFilePath;29 }30 if (pluginState.outPath) {31 this.pathProcessor = out_path_process_1.getPathProcessor(ts_impl, pluginState);32 }33 }34 }35 DefaultOptionsHolder.prototype.isUseSingleInferredProject = function () {36 if (this.pluginState) {37 if (this.pluginState.isUseSingleInferredProject != null) {38 return this.pluginState.isUseSingleInferredProject;39 }40 }41 return true;42 };43 DefaultOptionsHolder.prototype.isOpenConfigProject = function () {44 return this.openConfigProject;45 };46 DefaultOptionsHolder.prototype.showParentConfigWarning = function () {47 return this.options == null && !(this.pluginState.hasManualParams);48 };49 DefaultOptionsHolder.prototype.hasConfig = function () {50 return this.configFileName != null;51 };52 DefaultOptionsHolder.prototype.watchConfig = function (callback, ts_impl) {53 var _this = this;54 if (!this.hasConfig())55 return;56 this.updateConfigCallback = callback;57 ts_impl.sys.watchFile(this.configFileName, function (file, isRemoved) {58 _this.refresh(ts_impl);59 });60 };61 DefaultOptionsHolder.prototype.refresh = function (ts_impl) {62 if (!this.hasConfig())63 return;64 try {65 var configOptions = this.defaultOptions ?66 this.getConfigOptions(ts_impl, this.defaultOptions) :67 this.getConfigOptionsForFile(ts_impl, this.configFileName);68 if (configOptions == null)69 return;70 this.options = configOptions.commonDefaultOptions;71 var rawOptions = this.options;72 if (rawOptions.compileOnSave == null) {73 rawOptions.compileOnSave = true;74 }75 if (rawOptions.compilerOptions) {76 rawOptions.compilerOptions.___processed_marker = true;77 }78 this.configFileName = configOptions.configFileName;79 if (this.updateConfigCallback) {80 this.updateConfigCallback();81 }82 }83 catch (err) {84 if (logger_impl_1.isLogEnabled)85 throw err;86 logger_impl_1.serverLogger("Error refreshing tsconfig.json " + this.configFileName + ' ' + err.message + '\n' + err.stack, true);87 }88 };89 DefaultOptionsHolder.prototype.getConfigOptionsForFile = function (ts_impl, configName) {90 try {91 var sys = ts_impl.sys;92 //ok, lets parse typescript config93 var cachedConfigFileText = sys.readFile(configName);94 if (cachedConfigFileText) {95 var result = ts_impl.parseConfigFileTextToJson(configName, cachedConfigFileText);96 var configObject = result.config;97 if (configObject) {98 var cwd = sys.getCurrentDirectory();99 var configParseResult = ts_impl.parseJsonConfigFileContent(configObject, sys, ts_impl.getNormalizedAbsolutePath(ts_impl.getDirectoryPath(configName), cwd), {}, ts_impl.getNormalizedAbsolutePath(configName, cwd));100 if (configParseResult) {101 return { commonDefaultOptions: configParseResult.options, configFileName: configName };102 }103 else if (logger_impl_1.isLogEnabled) {104 throw new Error("Cannot parse config " + configName);105 }106 }107 }108 }109 catch (err) {110 logger_impl_1.serverLogger("Error parsing tsconfig.json " + configName + ' ' + err.message + '\n' + err.stack, true);111 }112 return null;113 };114 DefaultOptionsHolder.prototype.getConfigOptions = function (ts_impl, commonDefaultOptions) {115 try {116 var sys = ts_impl.sys;117 var fileOrDirectory = ts_impl.normalizePath(commonDefaultOptions.project);118 var configFileName = null;119 if (!fileOrDirectory || sys.directoryExists(fileOrDirectory)) {120 configFileName = ts_impl.combinePaths(fileOrDirectory, "tsconfig.json");121 if (!sys.fileExists(configFileName)) {122 if (logger_impl_1.isLogEnabled) {123 throw new Error("Config file doesn't exist " + configFileName);124 }125 return { commonDefaultOptions: commonDefaultOptions };126 }127 }128 else {129 configFileName = fileOrDirectory;130 if (!sys.fileExists(configFileName)) {131 if (logger_impl_1.isLogEnabled) {132 throw new Error("Config file doesn't exist " + configFileName);133 }134 return { commonDefaultOptions: commonDefaultOptions };135 }136 }137 if (!configFileName && logger_impl_1.isLogEnabled) {138 throw new Error("Config file doesn't exist " + fileOrDirectory);139 }140 var candidate = this.getConfigOptionsForFile(ts_impl, configFileName);141 if (candidate != null)142 return candidate;143 }144 catch (err) {145 if (logger_impl_1.isLogEnabled) {146 throw err;147 }148 }149 return { commonDefaultOptions: commonDefaultOptions };150 };151 return DefaultOptionsHolder;152}());...
basic.js
Source:basic.js
1const fs = require('fs');2const path = require('path');3const sqlite3 = require('sqlite3');4const express = require('express');5const router = express.Router();6const sql_get_gameserver_by_Id = 'SELECT * FROM GameServer WHERE Id = ?';7var db = new sqlite3.Database('./db/ssm.db');8router.get('/gameservers/:id/config/basic/:filename', (req, res) =>9{10 if (req.user)11 {12 var ConfigFileName = '';13 switch (req.params.filename.toLowerCase())14 {15 case "admins": ConfigFileName = 'Admins'; break;16 case "bans": ConfigFileName = 'Bans'; break;17 case "license": ConfigFileName = 'License'; break;18 case "maprotation": ConfigFileName = 'MapRotation'; break;19 case "motd": ConfigFileName = 'MOTD'; break;20 case "rcon": ConfigFileName = 'Rcon'; break;21 case "remoteadminlisthosts": ConfigFileName = 'RemoteAdminListHosts'; break;22 case "remotebanlisthosts": ConfigFileName = 'RemoteBanListHosts'; break;23 case "server": ConfigFileName = 'Server'; break;24 case "servermessages": ConfigFileName = 'ServerMessages'; break;25 default: ConfigFileName = '';26 }27 if (ConfigFileName != '')28 {29 db.get(sql_get_gameserver_by_Id, req.params.id, function (err, Row)30 {31 if (err) { throw err; }32 if (typeof Row !== 'undefined')33 {34 var FileContents = fs.readFileSync(path.join(Row.InstallationRoute, '/SquadGame/ServerConfig/' + ConfigFileName + '.cfg'), "utf8");35 res.render('gameservers/config/basic', {36 GameServer: Row,37 ConfigFileName: ConfigFileName,38 FileContents: FileContents39 });40 }41 });42 }43 }44 else res.render('login');45});46router.post('/gameservers/:id/config/basic/:filename', (req, res) =>47{48 if (req.user)49 {50 var ConfigFileName = '';51 switch (req.params.filename.toLowerCase())52 {53 case "admins": ConfigFileName = 'Admins'; break;54 case "bans": ConfigFileName = 'Bans'; break;55 case "license": ConfigFileName = 'License'; break;56 case "maprotation": ConfigFileName = 'MapRotation'; break;57 case "motd": ConfigFileName = 'MOTD'; break;58 case "rcon": ConfigFileName = 'Rcon'; break;59 case "remoteadminlisthosts": ConfigFileName = 'RemoteAdminListHosts'; break;60 case "remotebanlisthosts": ConfigFileName = 'RemoteBanListHosts'; break;61 case "server": ConfigFileName = 'Server'; break;62 case "servermessages": ConfigFileName = 'ServerMessages'; break;63 default: ConfigFileName = '';64 }65 if (ConfigFileName != '')66 {67 db.get(sql_get_gameserver_by_Id, req.params.id, function (err, Row)68 {69 if (err) throw err;70 fs.writeFileSync(path.join(Row.InstallationRoute, '/SquadGame/ServerConfig/' + ConfigFileName + '.cfg'), req.body.textarea, "utf8");71 res.render('gameservers/view', {72 gameserver: Row,73 });74 });75 }76 }77 else res.render('login');78});...
config.ts
Source:config.ts
1import { findUpSync } from 'find-up'2import { existsSync, readFileSync, statSync } from 'fs'3import yaml from 'js-yaml'4import { pathToFileURL } from 'node:url'5import path from 'path'6import { UI } from './cli.js'7import { findPackageJson, getHomePath, getPackageJson } from './platform.js'8export const ctx = {9 getHomePath,10 findPackageJson,11 getPackageJson12}13export async function loadConfig({ cwd, ui }: {14 cwd: string,15 ui: Pick<UI, 'info' | 'debug' | 'warn'>16}, configName: string) {17 const home = ctx.getHomePath()18 const configFileNames = getConfigFilenames(configName)19 const configFilePath = resolveConfigFilenames(cwd, home, configFileNames)20 if (configFilePath) {21 ui.debug(`load config from: ${configFilePath}`)22 const cfg = await readConfig(configFilePath)23 ui.debug(`config: ${JSON.stringify(cfg, undefined, 2)}`)24 return cfg25 }26 else {27 const pjsonPath = ctx.findPackageJson(cwd)28 if (pjsonPath) {29 ui.debug(`load config from package.json: ${pjsonPath}`)30 const pjson = ctx.getPackageJson(pjsonPath)31 if (pjson[configName]) return pjson[configName]32 }33 }34 ui.warn(`no config found under '${cwd}':\n ${configFileNames.join('\n ')}`)35}36function getConfigFilenames(configFileName: string) {37 const names = [38 configFileName,39 `${configFileName}.cjs`,40 `${configFileName}.mjs`,41 `${configFileName}.js`,42 `${configFileName}.json`,43 `${configFileName}.yml`,44 `${configFileName}.yaml`,45 `${configFileName}rc.cjs`,46 `${configFileName}rc.mjs`,47 `${configFileName}rc.js`,48 `${configFileName}rc.json`,49 `${configFileName}rc.yml`,50 `${configFileName}rc.yaml`,51 `${configFileName}rc`,52 ]53 return configFileName.startsWith('.') ? names : names.flatMap(n => [n, `.${n}`])54}55function resolveConfigFilenames(cwd: string, home: string, filenames: string[]) {56 for (const filename of filenames) {57 const filePath = findUpSync(filename, { cwd })58 if (filePath) return filePath59 }60 for (const filename of filenames) {61 const filePath = path.join(home, filename)62 // istanbul ignore next63 if (existsSync(filePath) && statSync(filePath).isFile()) return filePath64 }65}66// ignoring coverage. Test are done through `@unional/fixture` `execCommand()`67// istanbul ignore next68async function readConfig(configFilePath: string) {69 const content = readFileSync(configFilePath, 'utf-8')70 try {71 return JSON.parse(content)72 }73 catch {74 try {75 return yaml.load(content)76 }77 catch {78 const m = await import(pathToFileURL(configFilePath).href)79 if (m.activate) return m80 return m.default81 }82 }...
transform-typescript.js
Source:transform-typescript.js
1'use strict';2const Ts = require('typescript');3const cache = new Map();4const tsify = function (content, fileName) {5 const searchPath = Ts.normalizePath(Ts.sys.getCurrentDirectory());6 const configFileName = process.env.TSCONFIG || Ts.findConfigFile(searchPath, Ts.sys.fileExists);7 const compilerOptions = getCompilerOptionsViaCache(configFileName);8 compilerOptions.sourceMap = false;9 compilerOptions.inlineSourceMap = true;10 const { outputText/*, diagnostics*/ } = Ts.transpileModule(content, {11 fileName,12 compilerOptions,13 reportDiagnostics: false14 });15 const splicePoint = outputText.indexOf('Object.defineProperty(exports, "__esModule", { value: true })');16 if (splicePoint !== -1) {17 return '/* $lab:coverage:off$ */' + outputText.slice(0, splicePoint) + '/* $lab:coverage:on$ */' + outputText.slice(splicePoint);18 }19 return outputText;20};21const getCompilerOptionsViaCache = function (configFileName) {22 let options;23 if (!(options = cache[configFileName])) {24 options = cache[configFileName] = getCompilerOptions(configFileName);25 }26 return options;27};28const getCompilerOptions = function (configFileName) {29 const { config, error } = Ts.readConfigFile(configFileName, Ts.sys.readFile);30 if (error) {31 throw new Error(`TS config error in ${configFileName}: ${error.messageText}`);32 }33 const { options } = Ts.parseJsonConfigFileContent(34 config,35 Ts.sys,36 Ts.getDirectoryPath(configFileName),37 {},38 configFileName);39 return options;40};41module.exports = [{42 ext: '.ts',43 transform: tsify...
Using AI Code Generation
1const configFileName = require('storybook-root-config').configFileName;2module.exports = {3 '../src/**/*.stories.@(js|jsx|ts|tsx)',4 configFileName('.storybook/addons.js'),5};6const configFileName = require('storybook-root-config').configFileName;7 configFileName('.storybook/main.js'),8];9const configFileName = require('storybook-root-config').configFileName;10module.exports = {11 '../src/**/*.stories.@(js|jsx|ts|tsx)',12 configFileName('.storybook/addons.js'),13};14const configFileName = require('storybook-root-config').configFileName;15module.exports = {16 configFileName('.storybook/addons.js'),17};18const configFileName = require('storybook-root-config').configFileName;19module.exports = {20 configFileName('.storybook/addons.js'),21};22const configFileName = require('storybook-root-config').configFileName;23module.exports = {24 configFileName('.storybook/addons.js'),25};
Using AI Code Generation
1const configFileName = require('storybook-root-config').configFileName;2module.exports = {3 stories: [configFileName('stories')],4 configFileName('addons'),5 configFileName('addons', 'actions'),6 configFileName('addons', 'links'),7 configFileName('addons', 'notes'),8};9const configFileName = require('storybook-root-config').configFileName;10require(configFileName('addons', 'actions'));11require(configFileName('addons', 'links'));12require(configFileName('addons', 'notes'));13const configFileName = require('storybook-root-config').configFileName;14require(configFileName('addons', 'notes', 'register'));15const configFileName = require('storybook-root-config').configFileName;16require(configFileName('addons', 'notes', 'register'));17const configFileName = require('storybook-root-config').configFileName;18require(configFileName('addons', 'notes', 'register'));19const configFileName = require('storybook-root-config').configFileName;20module.exports = (baseConfig, env, defaultConfig) => {21 defaultConfig.module.rules.push({22 {23 },24 {25 },26 });27 return defaultConfig;28};29const configFileName = require('storybook-root-config').configFileName;30module.exports = (baseConfig, env, defaultConfig) => {31 defaultConfig.module.rules.push({32 {33 },34 {35 },36 });37 return defaultConfig;38};39const configFileName = require('storybook-root-config').config
Using AI Code Generation
1const configFileName = require('storybook-root-config').configFileName;2console.log(configFileName);3{4 "scripts": {5 },6 "devDependencies": {7 }8}9const rootPath = require('storybook-root-config').rootPath;10console.log(rootPath);
Using AI Code Generation
1import { configFileName } from 'storybook-root-config';2module.exports = {3 stories: [configFileName('stories/**/*.stories.js')],4};5import { configFileName } from 'storybook-root-config';6module.exports = {7 stories: [configFileName('stories/**/*.stories.js')],8};
Using AI Code Generation
1const { configFileName } = require('storybook-root-dir');2const path = require('path');3const configPath = path.join(configFileName, 'path', 'to', 'config.js');4module.exports = {5}6const path = require('path');7const configFileName = path.join('path', 'to', 'config.js');8module.exports = {9}
Using AI Code Generation
1const config = require('storybook-root-config').configFileName('path/to/config.js');2module.exports = config;3"scripts": {4}5const config = require('storybook-root-config').configFileName('path/to/config.js');6module.exports = config;7"scripts": {8}9const config = require('storybook-root-config').configFileName('path/to/config.js');10module.exports = config;11"scripts": {12}13const config = require('storybook-root-config').configFileName('path/to/config.js');14module.exports = config;15"scripts": {16}17const config = require('storybook-root-config').configFileName('path/to/config.js');18module.exports = config;19"scripts": {20}21const config = require('storybook-root-config').configFileName('path/to/config.js');22module.exports = config;23"scripts": {24}25const config = require('storybook-root-config').configFileName('path/to/config.js');26module.exports = config;27"scripts": {28}29const config = require('storybook-root-config
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!!