UNPKG

@applitools/eyes-storybook

Version:
33 lines (28 loc) 1.36 kB
const {resolve} = require('path'); const {execSync} = require('child_process'); const fs = require('fs'); const findNpmModuleCommandPath = require('../findNpmModuleCommandPath'); async function determineStorybookVersion({packagePath, isWindows}) { let sbArg, storybookPath; const commandV6 = 'start-storybook' + (isWindows ? '.cmd' : ''); const commandV7 = 'sb' + (isWindows ? '.cmd' : ''); const storybookPathV6 = resolve(packagePath, 'node_modules/.bin', commandV6); const storybookPathV7 = resolve(packagePath, 'node_modules/.bin', commandV7); // first we look for the binaries in the local node_modules/.bin folder in case there are multiple versions of storybook installed if (fs.existsSync(storybookPathV6)) { storybookPath = storybookPathV6; } else if (fs.existsSync(storybookPathV7)) { storybookPath = storybookPathV7; sbArg = 'dev'; } else { // the binary is not in the local node_modules/.bin folder, so we need to find it storybookPath = await findNpmModuleCommandPath(commandV6, packagePath); if (!storybookPath) { storybookPath = await findNpmModuleCommandPath(commandV7, packagePath); sbArg = 'dev'; } } const sbVersion = execSync(`"${storybookPath}" ${sbArg ?? ''} --version`).toString(); return {storybookPath, sbVersion, sbArg}; } module.exports = determineStorybookVersion;