How to use findEslintFile method in storybook-root

Best JavaScript code snippet using storybook-root

index.js

Source:index.js Github

copy

Full Screen

1#!/usr/bin/env node2const yargs = require('yargs');3const inquirer = require('inquirer');4const fs = require('fs');5const fse = require('fs-extra');6const { COPYFILE_EXCL } = fs.constants;7const path = require('path');8const aliasDescriptions = require('./descriptions');9const { info, err } = require('./utils/loggers');10const { listUI, listTitleUI } = require('./utils/ui');11ensureESLintFilesDirExists();12const esLintPickerSourceDir = __dirname;13const esLintFilesDirName = 'esLintFiles';14const savedFilesDirArray = fs.readdirSync(15 path.join(esLintPickerSourceDir, esLintFilesDirName)16);17const options = {18 aliasRequired: {19 describe: 'Nickname for ESLint file',20 alias: 'a',21 demandOption: true,22 default: undefined,23 },24 describe: {25 describe: 'Description of Alias file',26 alias: 'd',27 demandOption: false,28 },29 list: {30 type: 'boolean',31 alias: 'l',32 describe: 'list saved ESLint files',33 },34 faq: {35 type: 'boolean', 36 describe: 'Frequently asked questions how eslintpicker works'37 },38 hidden: {39 version: { hidden: true },40 list: { hidden: true },41 help: { hidden: true },42 },43};44const argv = yargs45 .scriptName('eslp')46 .usage('eslp <command> <Alias>')47 .usage('eslp --help <command>')48 .usage('eslp [options]')49 .command(50 'save',51 'save .eslintrc.* in current working directory under an alias',52 {53 alias: options.aliasRequired,54 ...options.hidden,55 describe: options.describe,56 },57 function (argv) {58 try {59 const esLintFileExists = findESLintFile();60 if (esLintFileExists) {61 info.log(62 `Attempting to Save .eslintrc${info.fileFormatColor(63 findFileFormat(findESLintFile())64 )} file as ${info.aliasNameColor(argv.alias)}...`65 );66 saveFile(argv, findESLintFile, findFileFormat);67 overWriteDescripJSON(68 createNewDescriptionObject,69 argv.alias,70 argv.describe,71 aliasDescriptions72 );73 info.log('File Saved!');74 return;75 } else {76 throw { code: 'ESLF_DOES_NOT_EXIST' };77 }78 } catch (exception) {79 err.catchExceptionOutput(exception.code);80 }81 }82 )83 .command(84 'import',85 'import saved ESLint file',86 {87 alias: options.aliasRequired,88 ...options.hidden,89 },90 function (argv) {91 try {92 info.log(93 `Attempting to import ${info.aliasNameColor(argv.alias)}...`94 );95 importFile(argv.alias);96 info.log('File has been imported!');97 } catch (exception) {98 err.catchExceptionOutput(exception.code);99 }100 }101 )102 .command(103 'update',104 'overwrite saved file with same alias',105 {106 alias: options.aliasRequired,107 ...options.hidden,108 describe: options.describe,109 },110 argv => {111 try {112 const aliasObject = checkForAlias(argv.alias);113 if (aliasObject) {114 const isFileFormatSame = compareFileFormat(aliasObject);115 if (isFileFormatSame) {116 info.log(117 `updating ${info.aliasNameColor(118 argv.alias119 )} file...`120 );121 updateFile(aliasObject);122 info.log(123 `${info.aliasNameColor(argv.alias)} file updated!`124 );125 if (126 argv.describe &&127 typeof argv.describe === 'string'128 ) {129 updateDescription(130 aliasObject.name,131 argv.describe,132 aliasDescriptions133 );134 info.log(135 `${info.aliasNameColor(136 argv.alias137 )} description has been updated!`138 );139 }140 } else {141 const originFile = findESLintFile();142 const esLintFileFormat = findFileFormat(originFile);143 fileFormatConfirm(esLintFileFormat, aliasObject);144 if (argv.describe) {145 updateDescription(146 aliasObject.name,147 argv.describe,148 aliasDescriptions149 );150 info.log(151 `${info.aliasNameColor(152 argv.alias153 )} description has been updated!`154 );155 }156 }157 } else {158 throw { code: 'DOES_NOT_EXIST' };159 }160 } catch (exception) {161 err.catchExceptionOutput(exception.code);162 }163 }164 )165 .command(166 'delete',167 'delete saved file',168 {169 alias: options.aliasRequired,170 ...options.hidden,171 },172 argv => {173 try {174 const aliasObject = checkForAlias(argv.alias);175 if (aliasObject) {176 info.log(177 `Deleting ${info.aliasNameColor(argv.alias)} file...`178 );179 deleteFile(aliasObject);180 info.log(181 `${info.aliasNameColor(argv.alias)} file deleted!`182 );183 const descriptionExists = descripExists(184 aliasObject.name,185 aliasDescriptions186 );187 if (descriptionExists) {188 deleteDescription(aliasObject.name, aliasDescriptions);189 }190 } else {191 throw { code: 'DOES_NOT_EXIST' };192 }193 } catch (exception) {194 err.catchExceptionOutput(exception.code);195 }196 }197 )198 .command(199 'info',200 'alias name, file format, and description',201 {202 alias: options.aliasRequired,203 ...options.hidden,204 },205 argv => {206 const aliasObject = checkForAlias(argv.alias);207 console.log(aliasObject);208 if (aliasObject) {209 aliasInfoOutput(aliasObject, aliasDescriptions);210 }211 }212 )213 .options({214 list: options.list,215 })216 .options({ 217 faq: options.faq,218 })219 .help()220 .alias('help', 'h')221 .alias('version', 'v')222 .argv;223if (argv.list) {224 aliasListOutput(generateAliasList, findFileFormat, aliasDescriptions);225}226if (argv.faq) {227 // insert FAQ UI here228}229function generateAliasList(fileFormatFunc) {230 const aliasNameArray = savedFilesDirArray.map(alias => {231 const fileFormat = fileFormatFunc(alias);232 const name = alias.split(fileFormat)[0];233 return { name, fileFormat };234 });235 return aliasNameArray;236}237function aliasInfoOutput(aliasObject, aliasDescriptions) {238 if (aliasDescriptions[aliasObject.name] === undefined) {239 aliasDescriptions[aliasObject.name] = '';240 }241 info.log(listTitleUI('Alias', 'Description'));242 info.log(243 listUI(244 aliasObject.name,245 aliasDescriptions[aliasObject.name],246 aliasObject.fileFormat247 )248 );249}250function aliasListOutput(251 generateAliasListFunc,252 findFileFormatFunc,253 aliasDescriptions254) {255 const list = generateAliasListFunc(findFileFormatFunc);256 if (list.length === 0) {257 info.log('No Saved ESLint files.');258 } else {259 info.log(listTitleUI('Alias', 'Description'));260 let ui = null;261 list.forEach(alias => {262 if (aliasDescriptions[alias.name] === undefined) {263 aliasDescriptions[alias.name] = '';264 }265 ui = listUI(266 alias.name,267 aliasDescriptions[alias.name],268 alias.fileFormat269 );270 });271 info.log(ui);272 }273}274function findESLintFile() {275 const fileInPWD = fs.readdirSync(process.cwd());276 const esLintFile = fileInPWD.find(file => file.startsWith('.eslintrc'));277 if (esLintFile) return esLintFile;278 return false;279}280function findFileFormat(file) {281 const json = /(.json)/i;282 const yaml = /(.yaml)/i;283 const js = /(.js)/i;284 const fileTypes = [json, yaml, js];285 const fileType = fileTypes.find(type => type.test(file));286 switch (fileType) {287 case json:288 return '.json';289 case yaml:290 return '.yaml';291 case js:292 return '.js';293 default:294 // FIX - USE ERROR LOGGER HERE (develop error function for proper log out?)295 err.logRed(296 'Error: file type is not correct; must be .json, .yaml, or .js.'297 );298 }299}300function saveFile(argv, findESLintFunc, fileFormatFunc) {301 const originFile = findESLintFunc();302 const fileFormat = fileFormatFunc(originFile);303 const alias = `${argv.alias}${fileFormat}`;304 const destPath = path.join(__dirname, esLintFilesDirName, alias);305 const aliasExists = checkForAlias(argv.alias);306 if (aliasExists) {307 throw { code: 'EEXIST' };308 } else {309 fs.copyFileSync(originFile, destPath, COPYFILE_EXCL, err => {310 if (err) throw err;311 return;312 });313 }314}315function createNewDescriptionObject(alias, description, descriptionsObject) {316 const newDescriptionsObject = {317 [alias]: description,318 ...descriptionsObject,319 };320 return newDescriptionsObject;321}322function overWriteDescripJSON(323 createNewDescriptionObject,324 alias,325 description,326 descriptionsObject327) {328 const newJsonObj = JSON.stringify(329 createNewDescriptionObject(alias, description, descriptionsObject),330 null331 );332 const destPath = path.join(__dirname, 'descriptions.json');333 fs.writeFileSync(destPath, newJsonObj, err => {334 // FIX - pass to error logger and return with proper err335 if (err) throw err;336 return;337 });338}339function updateDescription(alias, newDescription, descriptionsObject) {340 descriptionsObject[alias] = newDescription;341 const newJsonObject = JSON.stringify(descriptionsObject);342 const destPath = path.join(__dirname, 'descriptions.json');343 fs.writeFileSync(destPath, newJsonObject, err => {344 // FIX - pass to error logger and return with proper err345 if (err) throw err;346 return;347 });348}349function importFile(alias) {350 const aliasObject = checkForAlias(alias);351 if (aliasObject) {352 const esLintFile = `.eslintrc${aliasObject.fileFormat}`;353 const cwd = process.cwd();354 const destPath = path.join(cwd, esLintFile);355 const aliasFile = `${aliasObject.name}${aliasObject.fileFormat}`;356 const originPath = path.join(357 esLintPickerSourceDir,358 esLintFilesDirName,359 aliasFile360 );361 fs.copyFileSync(originPath, destPath, COPYFILE_EXCL, err => {362 if (err) throw '.eslintrc.* already exists in your file. Please delete this file in order to import alias.';363 return;364 });365 } else {366 throw { code: 'DOES_NOT_EXIST' };367 }368}369function updateFile(aliasObject) {370 const originFile = findESLintFile();371 const alias = `${aliasObject.name}${aliasObject.fileFormat}`;372 const destPath = path.join(__dirname, esLintFilesDirName, alias);373 fs.copyFileSync(originFile, destPath, err => {374 if (err) throw err;375 });376}377function deleteFile(aliasObject) {378 const alias = `${aliasObject.name}${aliasObject.fileFormat}`;379 const aliasPath = path.join(__dirname, esLintFilesDirName, alias);380 fs.unlinkSync(aliasPath, err => {381 throw err;382 });383}384function descripExists(alias, aliasDescriptions) {385 if (aliasDescriptions[alias]) return true;386 return false;387}388function deleteDescription(alias, descriptionsObject) {389 const toBeDeletedDescrip = descriptionsObject[alias];390 const newDescripObject = {};391 for (const alias in descriptionsObject) {392 descriptionsObject[alias] != toBeDeletedDescrip393 ? (newDescripObject[alias] = descriptionsObject[alias])394 : null;395 }396 const newJsonObject = JSON.stringify(newDescripObject);397 const destPath = path.join(__dirname, 'descriptions.json');398 fs.writeFileSync(destPath, newJsonObject, err => {399 if (err) throw err;400 return;401 });402}403function checkForAlias(alias) {404 if (alias) {405 const aliasList = generateAliasList(findFileFormat);406 for (const aliasObject of aliasList) {407 if (aliasObject.name.toLowerCase() === alias.toLowerCase()) {408 return aliasObject;409 }410 }411 }412 return false;413}414function compareFileFormat(aliasObject) {415 const originFile = findESLintFile();416 const fileFormat = findFileFormat(originFile);417 if (fileFormat === aliasObject.fileFormat) {418 return true;419 }420 return false;421}422function fileFormatConfirm(esLintFileFormat, aliasObject) {423 inquirer424 .prompt([425 {426 type: 'confirm',427 name: 'formatUpdateConfirmation',428 message: `ESLint file in current project dir has format ${info.fileFormatColor(429 esLintFileFormat430 )}. Alias ${info.aliasNameColor(431 aliasObject.name432 )} format is ${info.fileFormatColor(433 aliasObject.fileFormat434 )}. Do you want to save as current alias format? (if no, please save under new alias)`,435 },436 ])437 .then(answer => {438 if (answer.formatUpdateConfirmation) {439 info.log(`updating ${info.aliasNameColor(argv.alias)} file...`);440 updateFile(aliasObject);441 } else {442 info.log(443 `Use 'eslp save --alias ${info.aliasNameColor(444 '<aliasName>'445 )} --describe ${info.descripColor(446 '"description"'447 )} ' to save .eslintrc${findFileFormat(findESLintFile())}`448 );449 return false;450 }451 });452}453function ensureESLintFilesDirExists() {454 const esLintFilesPath = path.join(__dirname, 'esLintFiles');455 fse.ensureDirSync(esLintFilesPath);...

Full Screen

Full Screen

eslint-file.spec.ts

Source:eslint-file.spec.ts Github

copy

Full Screen

...24 });25 });26 describe('findEslintFile', () => {27 it('should return default name when calling findEslintFile when no eslint is found', () => {28 expect(findEslintFile(tree)).toBe('.eslintrc.json');29 });30 it('should return the name of the eslint config when calling findEslintFile', () => {31 tree.write('.eslintrc.json', '{}');32 expect(findEslintFile(tree)).toBe('.eslintrc.json');33 });34 it('should return the name of the eslint config when calling findEslintFile', () => {35 tree.write('.eslintrc.js', '{}');36 expect(findEslintFile(tree)).toBe('.eslintrc.js');37 });38 it('should return default name when calling findEslintFile when no eslint is found', () => {39 tree.write('.eslintrc.yaml', '{}');40 expect(findEslintFile(tree)).toBe('.eslintrc.json');41 });42 });...

Full Screen

Full Screen

webpack.config.js

Source:webpack.config.js Github

copy

Full Screen

...36 enforce: 'pre',37 exclude: /node_modules/,38 loader: require.resolve('eslint-loader'),39 options: {40 configFile: findEslintFile(options)41 }42 },43 {44 test: /\.(js|jsx)$/,45 loader: require.resolve('babel-loader'),46 options: {47 presets: [48 [49 require.resolve('@babel/preset-env'),50 {51 loose: true,52 modules: false,53 targets: '> 0.25%, not dead'54 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const findEslintFile = require('storybook-root').findEslintFile;2const findEslintFile = require('storybook-root').findEslintFile;3const findEslintFile = require('storybook-root').findEslintFile;4const findEslintFile = require('storybook-root').findEslintFile;5const findEslintFile = require('storybook-root').findEslintFile;6const findEslintFile = require('storybook-root').findEslintFile;7const findEslintFile = require('storybook-root').findEslintFile;8const findEslintFile = require('storybook-root').findEslintFile;9const findEslintFile = require('storybook-root').findEslintFile;10const findEslintFile = require('storybook-root').findEslintFile;11const findEslintFile = require('storybook-root').findEslintFile;12const findEslintFile = require('storybook-root').findEslintFile;

Full Screen

Using AI Code Generation

copy

Full Screen

1const findEslintFile = require('storybook-root').findEslintFile;2const findEslintFile = require('storybook-root').findEslintFile;3const findEslintFile = require('storybook-root').findEslintFile;4const findEslintFile = require('storybook-root').findEslintFile;5const findEslintFile = require('storybook-root').findEslintFile;6const findEslintFile = require('storybook-root').findEslintFile;7const findEslintFile = require('storybook-root').findEslintFile;8const findEslintFile = require('storybook-root').findEslintFile;9const findEslintFile = require('storybook-root').findEslintFile;10const findEslintFile = require('storybook-root').findEslintFile;11const findEslintFile = require('storybook-root').findEslintFile;12const findEslintFile = require('storybook-root').findEslintFile;13const findEslintFile = require('storybook-root').findEslintFile;14const findEslintFile = require('storybook-root').findEslintFile;15const findEslintFile = require('storybook-root').findEslintFile;

Full Screen

Using AI Code Generation

copy

Full Screen

1import { findEslintFile } from 'storybook-root';2describe('findEslintFile', () => {3 it('should find the .eslintrc file', () => {4 const eslintPath = findEslintFile();5 expect(eslintPath).toBe('/path/to/.eslintrc');6 });7});8 ✓ should find the .eslintrc file (1ms)

Full Screen

Using AI Code Generation

copy

Full Screen

1const findEslintFile = require('storybook-root/findEslintFile');2console.log(findEslintFile());3module.exports = {4 stories: ['../src/**/*.stories.@(js|jsx|ts|tsx)'],5 webpackFinal: async (config) => {6 config.module.rules.push({7 exclude: findEslintFile(),8 {9 loader: require.resolve('babel-loader'),10 options: {11 presets: [require.resolve('babel-preset-react-app')],12 },13 },14 });15 return config;16 },17};

Full Screen

Using AI Code Generation

copy

Full Screen

1const findEslintFile = require('storybook-root-require').findEslintFile;2const path = require('path');3const getEslintConfig = () => {4 const eslintConfig = findEslintFile();5 return eslintConfig;6};7const getEslintConfigPath = () => {8 const eslintConfigPath = path.dirname(getEslintConfig());9 return eslintConfigPath;10};11module.exports = {12};13const path = require('path');14const { getEslintConfigPath } = require('./test');15module.exports = {16 webpackFinal: async (config) => {17 config.module.rules.push({18 test: /\.(ts|tsx)$/,19 include: [path.resolve(__dirname, '../src')],20 loader: require.resolve('babel-loader'),21 options: {22 require.resolve('babel-preset-react-app/dependencies'),23 { helpers: true },24 require.resolve('babel-plugin-named-asset-import'),25 {26 loaderMap: {27 svg: {28 },29 },30 },31 require.resolve('babel-plugin-react-docgen'),32 },33 });34 config.module.rules.push({35 test: /\.(ts|tsx)$/,36 include: [path.resolve(__dirname, '../src')],37 {38 loader: require.resolve('ts-loader'),39 options: {40 configFile: path.resolve(__dirname, '../tsconfig.json'),41 },42 },43 });44 config.module.rules.push({45 test: /\.(js|jsx)$/,46 include: [path.resolve(__dirname, '../src')],47 {48 loader: require.resolve('eslint-loader'),49 options: {50 configFile: path.resolve(__dirname, '../.eslintrc.js'),51 eslintPath: require.resolve('eslint'),52 },53 },

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const findEslintFile = require('storybook-root').findEslintFile;3const eslintFile = findEslintFile(path.resolve(__dirname, './'));4const findStorybookConfig = require('storybook-root').findStorybookConfig;5const storybookConfig = findStorybookConfig(path.resolve(__dirname, './'));6const findWebpackConfig = require('storybook-root').findWebpackConfig;7const webpackConfig = findWebpackConfig(path.resolve(__dirname, './'));8const findBabelConfig = require('storybook-root').findBabelConfig;9const babelConfig = findBabelConfig(path.resolve(__dirname, './'));10const findPackageJson = require('storybook-root').findPackageJson;11const packageJson = findPackageJson(path.resolve(__dirname, './'));12const findStorybookConfig = require('storybook-root').findStorybookConfig;13const storybookConfig = findStorybookConfig(path.resolve(__dirname, './'));14const findStorybookConfig = require('storybook-root').findStorybookConfig;15const storybookConfig = findStorybookConfig(path.resolve(__dirname, './'));16const findStorybookConfig = require('storybook-root').findStorybookConfig;17const storybookConfig = findStorybookConfig(path.resolve(__dirname, './'));18const findStorybookConfig = require('storybook-root').findStorybookConfig;19const storybookConfig = findStorybookConfig(path.resolve(__dirname, './'));20const findStorybookConfig = require('storybook-root').findStorybookConfig;21const storybookConfig = findStorybookConfig(path.resolve(__dirname, './'));22const findStorybookConfig = require('storybook-root').findStorybookConfig;23const storybookConfig = findStorybookConfig(path.resolve(__dirname, './'));

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const { findEslintFile } = require('@storybook/react/dist/server/options');3console.log(findEslintFile(path.join(__dirname, 'node_modules', '@storybook', 'react')));4const path = require('path');5const { findEslintFile } = require('@storybook/react/dist/server/options');6console.log(findEslintFile(path.join(__dirname, 'node_modules', '@storybook', 'react')));

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