Best JavaScript code snippet using storybook-root
templates.js
Source:templates.js
1/**2 * Copyright (c) 2015-present, Facebook, Inc.3 * All rights reserved.4 *5 * This source code is licensed under the BSD-style license found in the6 * LICENSE file in the root directory of this source tree. An additional grant7 * of patent rights can be found in the PATENTS file in the same directory.8 */9'use strict';10const copyProjectTemplateAndReplace = require('./copyProjectTemplateAndReplace');11const execSync = require('child_process').execSync;12const fs = require('fs');13const path = require('path');14/**15 * Templates released as part of react-native in local-cli/templates.16 */17const builtInTemplates = {18 navigation: 'HelloNavigation',19};20function listTemplatesAndExit(newProjectName, options) {21 if (options.template === true) {22 // Just listing templates using 'react-native init --template'.23 // Not creating a new app.24 // Print available templates and exit.25 const templateKeys = Object.keys(builtInTemplates);26 if (templateKeys.length === 0) {27 // Just a guard, should never happen as long builtInTemplates28 // above is defined correctly :)29 console.log(30 'There are no templates available besides ' +31 'the default "Hello World" one.'32 );33 } else {34 console.log(35 'The available templates are:\n' +36 templateKeys.join('\n') +37 '\nYou can use these to create an app based on a template, for example: ' +38 'you could run: ' +39 'react-native init ' + newProjectName + ' --template ' + templateKeys[0]40 );41 }42 // Exit 'react-native init'43 return true;44 }45 // Continue 'react-native init'46 return false;47}48/**49 * @param destPath Create the new project at this path.50 * @param newProjectName For example 'AwesomeApp'.51 * @param template Template to use, for example 'navigation'.52 * @param yarnVersion Version of yarn available on the system, or null if53 * yarn is not available. For example '0.18.1'.54 */55function createProjectFromTemplate(destPath, newProjectName, template, yarnVersion) {56 // Expand the basic 'HelloWorld' template57 copyProjectTemplateAndReplace(58 path.resolve('node_modules', 'react-native', 'local-cli', 'templates', 'HelloWorld'),59 destPath,60 newProjectName61 );62 if (template === undefined) {63 // No specific template, use just the HelloWorld template above64 return;65 }66 // Keep the files from the 'HelloWorld' template, and overwrite some of them67 // with the specified project template.68 // The 'HelloWorld' template contains the native files (these are used by69 // all templates) and every other template only contains additional JS code.70 // Reason:71 // This way we don't have to duplicate the native files in every template.72 // If we duplicated them we'd make RN larger and risk that people would73 // forget to maintain all the copies so they would go out of sync.74 const builtInTemplateName = builtInTemplates[template];75 if (builtInTemplateName) {76 // template is e.g. 'navigation',77 // use the built-in local-cli/templates/HelloNavigation folder78 createFromBuiltInTemplate(builtInTemplateName, destPath, newProjectName, yarnVersion);79 } else {80 // template is e.g. 'ignite',81 // use the template react-native-template-ignite from npm82 createFromRemoteTemplate(template, destPath, newProjectName, yarnVersion);83 }84}85// (We might want to get rid of built-in templates in the future -86// publish them to npm and install from there.)87function createFromBuiltInTemplate(templateName, destPath, newProjectName, yarnVersion) {88 const templatePath = path.resolve(89 'node_modules', 'react-native', 'local-cli', 'templates', templateName90 );91 copyProjectTemplateAndReplace(92 templatePath,93 destPath,94 newProjectName,95 );96 installTemplateDependencies(templatePath, yarnVersion);97}98/**99 * The following formats are supported for the template:100 * - 'demo' -> Fetch the package react-native-template-demo from npm101 * - git://..., http://..., file://... or any other URL supported by npm102 */103function createFromRemoteTemplate(template, destPath, newProjectName, yarnVersion) {104 let installPackage;105 let templateName;106 if (template.includes('://')) {107 // URL, e.g. git://, file://108 installPackage = template;109 templateName = template.substr(template.lastIndexOf('/') + 1);110 } else {111 // e.g 'demo'112 installPackage = 'react-native-template-' + template;113 templateName = installPackage;114 }115 // Check if the template exists116 console.log(`Fetching template ${installPackage}...`);117 try {118 if (yarnVersion) {119 execSync(`yarn add ${installPackage} --ignore-scripts`, {stdio: 'inherit'});120 } else {121 execSync(`npm install ${installPackage} --save --save-exact --ignore-scripts`, {stdio: 'inherit'});122 }123 const templatePath = path.resolve(124 'node_modules', templateName125 );126 copyProjectTemplateAndReplace(127 templatePath,128 destPath,129 newProjectName,130 {131 // Every template contains a dummy package.json file included132 // only for publishing the template to npm.133 // We want to ignore this dummy file, otherwise it would overwrite134 // our project's package.json file.135 ignorePaths: ['package.json', 'dependencies.json'],136 }137 );138 installTemplateDependencies(templatePath, yarnVersion);139 } finally {140 // Clean up the temp files141 try {142 if (yarnVersion) {143 execSync(`yarn remove ${templateName} --ignore-scripts`);144 } else {145 execSync(`npm uninstall ${templateName} --ignore-scripts`);146 }147 } catch (err) {148 // Not critical but we still want people to know and report149 // if this the clean up fails.150 console.warn(151 `Failed to clean up template temp files in node_modules/${templateName}. ` +152 'This is not a critical error, you can work on your app.'153 );154 }155 }156}157function installTemplateDependencies(templatePath, yarnVersion) {158 // dependencies.json is a special file that lists additional dependencies159 // that are required by this template160 const dependenciesJsonPath = path.resolve(161 templatePath, 'dependencies.json'162 );163 console.log('Adding dependencies for the project...');164 if (!fs.existsSync(dependenciesJsonPath)) {165 console.log('No additional dependencies.');166 return;167 }168 let dependencies;169 try {170 dependencies = JSON.parse(fs.readFileSync(dependenciesJsonPath));171 } catch (err) {172 throw new Error(173 'Could not parse the template\'s dependencies.json: ' + err.message174 );175 }176 for (let depName in dependencies) {177 const depVersion = dependencies[depName];178 const depToInstall = depName + '@' + depVersion;179 console.log('Adding ' + depToInstall + '...');180 if (yarnVersion) {181 execSync(`yarn add ${depToInstall}`, {stdio: 'inherit'});182 } else {183 execSync(`npm install ${depToInstall} --save --save-exact`, {stdio: 'inherit'});184 }185 }186 console.log('Linking native dependencies into the project\'s build files...');187 execSync('react-native link', {stdio: 'inherit'});188}189module.exports = {190 listTemplatesAndExit,191 createProjectFromTemplate,...
JsPackageManagerFactory.ts
Source:JsPackageManagerFactory.ts
1import { sync as spawnSync } from 'cross-spawn';2import { sync as findUpSync } from 'find-up';3import { NPMProxy } from './NPMProxy';4import { JsPackageManager } from './JsPackageManager';5import { Yarn2Proxy } from './Yarn2Proxy';6import { Yarn1Proxy } from './Yarn1Proxy';7export class JsPackageManagerFactory {8 public static getPackageManager(forceNpmUsage = false): JsPackageManager {9 if (forceNpmUsage) {10 return new NPMProxy();11 }12 const yarnVersion = getYarnVersion();13 const hasYarnLockFile = findUpSync('yarn.lock');14 const hasNPMCommand = hasNPM();15 if (yarnVersion && (hasYarnLockFile || !hasNPMCommand)) {16 return yarnVersion === 1 ? new Yarn1Proxy() : new Yarn2Proxy();17 }18 if (hasNPMCommand) {19 return new NPMProxy();20 }21 throw new Error('Unable to find a usable package manager within NPM, Yarn and Yarn 2');22 }23}24function hasNPM() {25 const npmVersionCommand = spawnSync('npm', ['--version']);26 return npmVersionCommand.status === 0;27}28function getYarnVersion(): 1 | 2 | undefined {29 const yarnVersionCommand = spawnSync('yarn', ['--version']);30 if (yarnVersionCommand.status !== 0) {31 return undefined;32 }33 const yarnVersion = yarnVersionCommand.output.toString().replace(/,/g, '').replace(/"/g, '');34 return /^1\.+/.test(yarnVersion) ? 1 : 2;...
Using AI Code Generation
1const storybookRoot = require('storybook-root');2const version = storybookRoot.yarnVersion();3const storybookRoot = require('storybook-root');4const version = storybookRoot.npmVersion();5const storybookRoot = require('storybook-root');6const version = storybookRoot.version();7const storybookRoot = require('storybook-root');8const version = storybookRoot.yarnVersion();9const storybookRoot = require('storybook-root');10const version = storybookRoot.npmVersion();11const storybookRoot = require('storybook-root');12const version = storybookRoot.version();13const storybookRoot = require('storybook-root');14const version = storybookRoot.yarnVersion();15const storybookRoot = require('storybook-root');16const version = storybookRoot.npmVersion();17const storybookRoot = require('storybook-root');18const version = storybookRoot.version();19const storybookRoot = require('storybook-root');20const version = storybookRoot.yarnVersion();21const storybookRoot = require('storybook-root');22const version = storybookRoot.npmVersion();23const storybookRoot = require('storybook-root');24const version = storybookRoot.version();25const storybookRoot = require('storybook-root');26const version = storybookRoot.yarnVersion();27const storybookRoot = require('storybook-root');28const version = storybookRoot.npmVersion();29const storybookRoot = require('storybook-root');30const version = storybookRoot.version();31const storybookRoot = require('storybook-root');
Using AI Code Generation
1const { yarnVersion } = require('@storybook/root');2console.log(yarnVersion);3{4 "dependencies": {5 }6}
Using AI Code Generation
1import { yarnVersion } from 'storybook-root';2console.log(yarnVersion);3import { yarnVersion } from 'storybook-root';4console.log(yarnVersion);5import { yarnVersion } from 'storybook-root';6console.log(yarnVersion);7import { yarnVersion } from 'storybook-root';8console.log(yarnVersion);9import { yarnVersion } from 'storybook-root';10console.log(yarnVersion);11import { yarnVersion } from 'storybook-root';12console.log(yarnVersion);13import { yarnVersion } from 'storybook-root';14console.log(yarnVersion);15import { yarnVersion } from 'storybook-root';16console.log(yarnVersion);17import { yarnVersion } from 'storybook-root';18console.log(yarnVersion);19import { yarnVersion } from 'storybook-root';20console.log(yarnVersion);21import { yarnVersion } from 'storybook-root';22console.log(yarnVersion);23import { yarnVersion } from 'storybook-root';24console.log(yarnVersion);25import { yarnVersion } from 'storybook-root';26console.log(yarnVersion);27import { yarnVersion } from 'storybook-root';28console.log(yarnVersion);29import { yarnVersion } from 'storybook-root';30console.log(yarnVersion);31import { yarnVersion } from 'storybook-root';32console.log(yarnVersion);33import { yarn
Using AI Code Generation
1import storybookRoot from 'storybook-root';2storybookRoot.yarnVersion();3import { yarnVersion } from 'storybook-root';4yarnVersion();5import { yarnVersion } from 'storybook-root/lib/yarnVersion';6yarnVersion();7import { yarnVersion } from 'storybook-root/yarnVersion';8yarnVersion();9import { yarnVersion } from 'storybook-root/yarnVersion.js';10yarnVersion();11import { yarnVersion } from 'storybook-root/yarnVersion.json';12yarnVersion();13import { yarnVersion } from 'storybook-root/yarnVersion.node';14yarnVersion();15import { yarnVersion } from 'storybook-root/yarnVersion.ts';16yarnVersion();17import { yarnVersion } from 'storybook-root/yarnVersion.tsx';18yarnVersion();19import { yarnVersion } from 'storybook-root/yarnVersion.mjs';20yarnVersion();21import { yarnVersion } from 'storybook-root/yarnVersion.cjs';22yarnVersion();23import { yarnVersion } from 'storybook-root/yarnVersion.coffee';24yarnVersion();25import { yarnVersion } from 'storybook-root/yarnVersion.cjsx';26yarnVersion();27import { yarnVersion } from 'storybook-root/yarnVersion.coffee.md';28yarnVersion();29import { yarnVersion } from 'storybook-root/yarnVersion.coffee.mdx';30yarnVersion();31import { yarnVersion } from 'storybook-root/yarnVersion.coffee.mdx';32yarnVersion();
Using AI Code Generation
1const root = require('storybook-root');2const { yarnVersion } = root;3console.log(yarnVersion);4const root = require('storybook-root');5const { yarnVersion } = root;6console.log(yarnVersion);7const root = require('storybook-root');8const { yarnVersion } = root;9console.log(yarnVersion);10const root = require('storybook-root');11const { yarnVersion } = root;12console.log(yarnVersion);13const root = require('storybook-root');14const { yarnVersion } = root;15console.log(yarnVersion);16const root = require('storybook-root');17const { yarnVersion } = root;18console.log(yarnVersion);19const root = require('storybook-root');20const { yarnVersion } = root;21console.log(yarnVersion);22const root = require('storybook-root');23const { yarnVersion } = root;24console.log(yarnVersion);25const root = require('storybook-root');26const { yarnVersion } = root;27console.log(yarnVersion);28const root = require('storybook-root');29const { yarnVersion } = root;30console.log(yarnVersion);31const root = require('storybook-root');32const { yarnVersion } = root;33console.log(yarnVersion);34const root = require('storybook-root');35const { yarnVersion } = root;36console.log(yarnVersion);37const root = require('storybook-root
Using AI Code Generation
1const storybookRoot = require('storybook-root');2storybookRoot.yarnVersion();3const storybookRoot = require('storybook-root');4storybookRoot.yarnVersion();5const storybookRoot = require('storybook-root');6storybookRoot.yarnVersion();7const storybookRoot = require('storybook-root');8storybookRoot.yarnVersion();9const storybookRoot = require('storybook-root');10storybookRoot.yarnVersion();11const storybookRoot = require('storybook-root');12storybookRoot.yarnVersion();13const storybookRoot = require('storybook-root');14storybookRoot.yarnVersion();15const storybookRoot = require('storybook-root');16storybookRoot.yarnVersion();17const storybookRoot = require('storybook-root');18storybookRoot.yarnVersion();19const storybookRoot = require('storybook-root');20storybookRoot.yarnVersion();21const storybookRoot = require('storybook-root');22storybookRoot.yarnVersion();
Using AI Code Generation
1const yarnVersion = require('storybook-root').yarnVersion;2console.log(yarnVersion);3{4 "scripts": {5 }6}
Using AI Code Generation
1import { yarnVersion } from 'storybook-root';2console.log(yarnVersion());3import { yarnVersion } from 'storybook-root';4console.log(yarnVersion());5import { yarnVersion } from 'storybook-root';6console.log(yarnVersion());7import { yarnVersion } from 'storybook-root';8console.log(yarnVersion());9import { yarnVersion } from 'storybook-root';10console.log(yarnVersion());11import { yarnVersion } from 'storybook-root';12console.log(yarnVersion());13import { yarnVersion } from 'storybook-root';14console.log(yarnVersion());15import { yarnVersion } from 'storybook-root';16console.log(yarnVersion());17import { yarnVersion } from 'storybook-root';18console.log(yarnVersion());19import { yarnVersion } from 'storybook-root';20console.log(yarnVersion());
Using AI Code Generation
1const { yarnVersion } = require('storybook-root-deps');2yarnVersion('react');3yarnVersion('@storybook/react');4yarnVersion('@storybook/react', '3.4.8');5yarnVersion('react', '16.2.0');6yarnVersion('@storybook/react', '3.4.8', '16.2.0');7yarnVersion('react', '16.2.0', '3.4.8');8yarnVersion('@storybook/react', '16.2.0', '3.4.8');9yarnVersion('react', '3.4.8', '16.2.0');10yarnVersion('@storybook/react', '16.2.0', '3.4.8');11yarnVersion('react', '3.4.8', '16.2.0');12yarnVersion('react', 'react-dom', '16.2.0', '16.2.0');13yarnVersion('react', 'react-dom', '16.2.0', '16.2.0', '16.2.0');14yarnVersion('react', 'react-dom', '16.2.0', '16.2.0', '16.2.0', '16.2.0');
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!!