<commit_before>var validate = require('./validate');
var Runner = require('screener-runner');
var cloneDeep = require('lodash/cloneDeep');
var omit = require('lodash/omit');
var url = require('url');

// transform storybook object into screener states
var transformToStates = function(storybook, baseUrl) {
  // clean baseUrl. remove query/hash/trailing-slash
  var urlObj = url.parse(baseUrl);
  urlObj = omit(urlObj, 'hash', 'search', 'query');
  urlObj.pathname = urlObj.pathname.replace(/\/$/, '');
  baseUrl = url.format(urlObj);
  // transform into states
  var states = [];
  storybook.forEach(function(component) {
    component.stories.forEach(function(story) {
      var iframeUrl = baseUrl + '/iframe.html?dataId=0&selectedKind=' + encodeURIComponent(component.kind) + '&selectedStory=' + encodeURIComponent(story.name);
      var state = {
        url: iframeUrl,
        name: component.kind + ': ' + story.name
      };
      if (story.steps) {
        state.steps = story.steps;
      }
      states.push(state);
    });
  });
  return states;
};

exports.run = function(config, options) {
  // create copy of config
  config = cloneDeep(config);
  return validate.storybookConfig(config)
    .then(function() {
      var host = 'localhost:' + config.storybookPort;
      var localUrl = 'http://' + host;
      // add tunnel details
      config.tunnel = {
        host: host,
        gzip: true,
        cache: true
      };
      // generate config format expected by screener-runner
      config.states = transformToStates(config.storybook, localUrl);
      // remove storybook-specific fields
      config = omit(config, ['storybook', 'storybookConfigDir', 'storybookStaticDir', 'storybookPort', 'storybookApp', 'storybookVersion', 'storybookBinPath']);
      if (options && options.debug) {
        console.log('DEBUG: config', JSON.stringify(config, null, 2));
      }
      // send storybook states to screener-runner
      return Runner.run(config);
    });
};<commit_msg>add screener-storybook version to meta<commit_after>var validate = require('./validate');
var Runner = require('screener-runner');
var cloneDeep = require('lodash/cloneDeep');
var omit = require('lodash/omit');
var url = require('url');
var pkg = require('../package.json');

// transform storybook object into screener states
var transformToStates = function(storybook, baseUrl) {
  // clean baseUrl. remove query/hash/trailing-slash
  var urlObj = url.parse(baseUrl);
  urlObj = omit(urlObj, 'hash', 'search', 'query');
  urlObj.pathname = urlObj.pathname.replace(/\/$/, '');
  baseUrl = url.format(urlObj);
  // transform into states
  var states = [];
  storybook.forEach(function(component) {
    component.stories.forEach(function(story) {
      var iframeUrl = baseUrl + '/iframe.html?dataId=0&selectedKind=' + encodeURIComponent(component.kind) + '&selectedStory=' + encodeURIComponent(story.name);
      var state = {
        url: iframeUrl,
        name: component.kind + ': ' + story.name
      };
      if (story.steps) {
        state.steps = story.steps;
      }
      states.push(state);
    });
  });
  return states;
};

exports.run = function(config, options) {
  // create copy of config
  config = cloneDeep(config);
  return validate.storybookConfig(config)
    .then(function() {
      // add package version
      config.meta = {
        'screener-storybook': pkg.version
      };
      var host = 'localhost:' + config.storybookPort;
      var localUrl = 'http://' + host;
      // add tunnel details
      config.tunnel = {
        host: host,
        gzip: true,
        cache: true
      };
      // generate config format expected by screener-runner
      config.states = transformToStates(config.storybook, localUrl);
      // remove storybook-specific fields
      config = omit(config, ['storybook', 'storybookConfigDir', 'storybookStaticDir', 'storybookPort', 'storybookApp', 'storybookVersion', 'storybookBinPath']);
      if (options && options.debug) {
        console.log('DEBUG: config', JSON.stringify(config, null, 2));
      }
      // send storybook states to screener-runner
      return Runner.run(config);
    });
};
{'fraction_non_alphanumeric': 0.14271961492178098, 'fraction_numerical': 0.0009626955475330926, 'mean_word_length': 3.168505516549649, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2678053', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1217, 'n_words': 283}