How to use @storybook/node-logger - 10 common examples

To help you get started, we’ve selected a few @storybook/node-logger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github storybookjs / storybook / lib / core / src / server / build-dev.js View on Github external
}
  } catch (error) {
    // this is a weird bugfix, somehow 'node-pre-gyp' is polluting the npmLog header
    npmLog.heading = '';

    if (error instanceof Error) {
      if (error.error) {
        logger.error(error.error);
      } else if (error.stats && error.stats.compilation.errors) {
        error.stats.compilation.errors.forEach(e => logger.plain(e));
      } else {
        logger.error(error);
      }
    }
    logger.line();
    logger.warn(
      error.close
        ? dedent`
            FATAL broken build!, will close the process,
            Fix the error below and restart storybook.
          `
        : dedent`
            Broken build, fix the error above.
            You may need to refresh the browser.
          `
    );
    logger.line();

    if (options.smokeTest || (error && error.close)) {
      process.exit(1);
    }
  }
github storybookjs / storybook / lib / core / src / server / build-dev.js View on Github external
openInBrowser(address);
    }
  } catch (error) {
    // this is a weird bugfix, somehow 'node-pre-gyp' is polluting the npmLog header
    npmLog.heading = '';

    if (error instanceof Error) {
      if (error.error) {
        logger.error(error.error);
      } else if (error.stats && error.stats.compilation.errors) {
        error.stats.compilation.errors.forEach(e => logger.plain(e));
      } else {
        logger.error(error);
      }
    }
    logger.line();
    logger.warn(
      error.close
        ? dedent`
            FATAL broken build!, will close the process,
            Fix the error below and restart storybook.
          `
        : dedent`
            Broken build, fix the error above.
            You may need to refresh the browser.
          `
    );
    logger.line();

    if (options.smokeTest || (error && error.close)) {
      process.exit(1);
    }
github storybookjs / storybook / lib / core / src / server / build-dev.js View on Github external
serveMessage.push(
    ['Local:', chalk.cyan(address)],
    ['On your network:', chalk.cyan(networkAddress)]
  );

  const timeStatement = previewTotalTime
    ? `${chalk.underline(prettyTime(managerTotalTime))} for manager and ${chalk.underline(
        prettyTime(previewTotalTime)
      )} for preview`
    : `${chalk.underline(prettyTime(managerTotalTime))}`;

  // eslint-disable-next-line no-console
  console.log(
    boxen(
      dedent`
          ${colors.green(`Storybook ${chalk.bold(version)} started`)}
          ${chalk.gray(timeStatement)}

          ${serveMessage.toString()}${updateMessage ? `\n\n${updateMessage}` : ''}
        `,
      { borderStyle: 'round', padding: 1, borderColor: '#F1618C' }
    )
  );
}
github storybookjs / storybook / lib / server / src / http / middleware.ts View on Github external
const hasCustomFavicon = await list.reduce(async (acc, [route, location]) => {
    const fullLocation = path.resolve(location);

    if (!(await fs.pathExists(fullLocation))) {
      logger.error(`Error: no such directory to load static files: "${fullLocation}"`);
    } else {
      // TODO should be part of server
      progress.emit('server', {
        message: `adding static files from: "${location}", routing at "${route}"`,
        details: [location, route],
      });
    }

    app.use(express.static(fullLocation, { index: false }));

    // if route is root and we haven't found a favicon before and this one contains a favicon
    if (route === '/' && !(await acc) && (await containsFavicon(fullLocation))) {
      app.use(favicon(faviconLocation(fullLocation)));
      return true;
    }
    return acc;
  }, Promise.resolve(false));
github storybookjs / storybook / lib / core / src / server / build-static.js View on Github external
function prepareFilesStructure(outputDir, defaultFavIcon) {
  // clear the output dir
  logger.info('clean outputDir..');
  shelljs.rm('-rf', outputDir);

  // create output directory if not exists
  shelljs.mkdir('-p', outputDir);
  shelljs.mkdir('-p', path.join(outputDir, 'sb_dll'));

  shelljs.cp(defaultFavIcon, outputDir);
}
github storybookjs / storybook / lib / core / src / server / preview / custom-webpack-preset.js View on Github external
// Check whether user has a custom webpack config file and
  // return the (extended) base configuration if it's not available.
  const customConfig = loadCustomWebpackConfig(configDir);

  if (customConfig === null) {
    logger.info('=> Using default Webpack setup.');
    return createFinalDefaultConfig(presets, config, options);
  }

  if (typeof customConfig === 'function') {
    logger.info('=> Loading custom Webpack config (full-control mode).');
    const finalDefaultConfig = await createFinalDefaultConfig(presets, config, options);
    return customConfig({ config: finalDefaultConfig, mode: configType });
  }

  logger.info('=> Loading custom webpack config (extending mode).');

  // Restore 4.x behavior, but deprecate this mode of extending webpack
  const finalConfig = await presets.apply('webpackFinal', config, options);
  return deprecate(
    () => mergeConfigs(finalConfig, customConfig),
    stripIndents`
      Extend-mode configuration is deprecated, please use full-control mode instead.
      
      See https://storybook.js.org/docs/configurations/custom-webpack-config/#full-control-mode
    `
  )();
}
github storybookjs / storybook / lib / server / src / builder / commands / watch.ts View on Github external
const watcherHandler: webpack.ICompiler.Handler = (err, stats) => {
  if (err) {
    logger.error(err.toString());
    reportError(err);
  }

  if (stats) {
    const { errors, warnings, ...displayStats } = stats.toJson({
      errorDetails: true,
      errors: true,
      warnings: true,
      entrypoints: false,
      modules: false,
      assets: false,
      reasons: false,
      source: false,
      chunks: false,
      children: false,
      // @ts-ignore
github storybookjs / storybook / app / mithril / src / server / babel_config.js View on Github external
function loadFromPath(babelConfigPath) {
  let config;
  if (fs.existsSync(babelConfigPath)) {
    const content = fs.readFileSync(babelConfigPath, 'utf-8');
    try {
      config = JSON5.parse(content);
      config.babelrc = false;
      logger.info('=> Loading custom .babelrc');
    } catch (e) {
      logger.error(`=> Error parsing .babelrc file: ${e.message}`);
      throw e;
    }
  }

  if (!config) return null;

  // Remove react-hmre preset.
  // It causes issues with react-storybook.
  // We don't really need it.
  // Earlier, we fix this by running storybook in the production mode.
  // But, that hide some useful debug messages.
  if (config.presets) {
    removeReactHmre(config.presets);
  }

  if (config.env && config.env.development && config.env.development.presets) {
github storybookjs / storybook / lib / core / src / server / utils / load-custom-babel-config.js View on Github external
function loadFromPath(babelConfigPath) {
  let config;
  if (fs.existsSync(babelConfigPath)) {
    const content = fs.readFileSync(babelConfigPath, 'utf-8');
    try {
      config = JSON5.parse(content);
      config.babelrc = false;
      logger.info('=> Loading custom .babelrc');
    } catch (e) {
      logger.error(`=> Error parsing .babelrc file: ${e.message}`);
      throw e;
    }
  }

  if (!config) return null;

  // Remove react-hmre preset.
  // It causes issues with react-storybook.
  // We don't really need it.
  // Earlier, we fix this by running storybook in the production mode.
  // But, that hide some useful debug messages.
  if (config.presets) {
    removeReactHmre(config.presets);
  }

  if (config.env && config.env.development && config.env.development.presets) {
github storybookjs / storybook / addons / storyshots / storyshots-puppeteer / src / imageSnapshot.ts View on Github external
const testFn = async ({ context }: any) => {
    const { kind, framework, name } = context;
    if (framework === 'react-native') {
      // Skip tests since we de not support RN image snapshots.
      logger.error(
        "It seems you are running imageSnapshot on RN app and it's not supported. Skipping test."
      );

      return;
    }
    const url = constructUrl(storybookUrl, kind, name);

    if (!browser || !page) {
      logger.error(
        `Error when generating image snapshot for test ${kind} - ${name} : It seems the headless browser is not running.`
      );

      throw new Error('no-headless-browser-running');
    }

    expect.assertions(1);