Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import findCacheDir from 'find-cache-dir';
import open from 'open';
import boxen from 'boxen';
import semver from 'semver';
import dedent from 'ts-dedent';
import Table from 'cli-table3';
import prettyTime from 'pretty-hrtime';
import inquirer from 'inquirer';
import detectFreePort from 'detect-port';
import storybook from './dev-server';
import { getDevCli } from './cli';
const defaultFavIcon = require.resolve('./public/favicon.ico');
const cacheDir = findCacheDir({ name: 'storybook' });
const cache = Cache({
basePath: cacheDir,
ns: 'storybook', // Optional. A grouping namespace for items.
});
const writeStats = async (name, stats) => {
await fs.writeFile(
path.join(cacheDir, `${name}-stats.json`),
JSON.stringify(stats.toJson(), null, 2),
'utf8'
);
};
const getFreePort = port =>
detectFreePort(port).catch(error => {
logger.error(error);
process.exit(-1);
export async function cachedStorybookMetadata() {
const cacheDir = findCacheDir({ name: 'storybook' });
const cache = Cache({
basePath: cacheDir,
ns: 'storybook', // Optional. A grouping namespace for items.
});
const packagePath = await findUp('package.json');
if (!packagePath) {
throw new Error('No package.json');
}
const packageJson = JSON.parse(await fs.readFile(packagePath, 'utf-8'));
const metadataCache = await cache.get('storybookMetadata', {});
const storybookMetadata = await loadStorybookMetadata(packageJson, {
cache: metadataCache,
getPackageJson: async packageName => {
const packageFile = require.resolve(`${packageName}/package.json`);
return JSON.parse(await fs.readFile(packageFile, 'utf8'));
},