<commit_before>/* global process */
var Q          = require('q');
var fs         = require('q-io/fs');

var path       = require('path');
var bodyParser = require('body-parser');
var express    = require('express');
var tinylr     = require('tiny-lr');
var app        = express();

var util       = require('./lib/util.js');
var apiFactory = require('./lib/api.js').factory;
var render     = require('./lib/render.js');
var deps       = require('./lib/deps.js');

// Start a tiny-lr server as well.
tinylr().listen(35729, function() {
  console.log('... Listening on 35729 ...');
});

if (process.argv.length < 4) {
  console.log('Usage:\n     node diversity-server.js <webshop-id> <theme-id|theme-name> [<auth>]');
  process.exit();
}

var webshopUid = process.argv[2];
var webshopUrl;
var themeUid = process.argv[3];
var auth = process.argv[4];

var api = apiFactory(webshopUid, 'sv', auth);


//ZGF2aWRAdGV4dGFsay5zZTsxNDEyMzIyNTIyO2EwOTJkOTJiNDlkNGYzN2I0ZmMxMjI2ZGI2NmU5MTg3

app.use(bodyParser.json());
app.use(express.static('.'));

Q.all([
  //deps.updateDeps('tws-admin-schema-form').fail(function(err) {
  //  console.log(err);
  //}),

  deps.updateDeps({
    name: 'jquery.jsonrpcclient.js',
    url: 'https://github.com/Textalk/jquery.jsonrpcclient.js.git'
  }),


  //deps.updateDeps({
  //  name: 'aficionado',
  //  url: 'http://git.diversity.io/shop-themes/aficionado.git'
  //}),

  api('Webshop.get', [webshopUid, {url:'sv'}]).then(function(result) {
    webshopUrl = result.url.sv;
  })
]).then(function() {

  // app.get('/reset', function(req, res) {
  //   // Reset skip list
  //   deps.reset();
  //   deps.updateDeps({ //update aficionado
  //     name: 'aficionado',
  //     url: 'http://git.diversity.io/shop-themes/aficionado.git'
  //   }).then(function(){
  //     res.send('OK');
  //   }, function() {
  //     res.send(500);
  //   })
  //
  // });

  app.get('/*', function(req, res, next) {

    // Skip /deps, those are files
    if (req.url.indexOf('/deps') === 0) {
      return next();
    }

    // FIXME: unclutter this ugly mess
    // Calculate settings and fetch the theme component
    var fetchThemeCompAndJson = function(name) {
      return deps.updateDeps({ // Since its not under webshop components we must give an url.
        name: name,
        url: 'http://git.diversity.io/shop-themes/' + name + '.git'
        // The second updateDeps actually loads diversity.json
      }).then(deps.updateDeps);
    };

    var tid = parseInt(themeUid, 10);<commit_msg>Changed path to aficionado<commit_after>/* global process */
var Q          = require('q');
var fs         = require('q-io/fs');

var path       = require('path');
var bodyParser = require('body-parser');
var express    = require('express');
var tinylr     = require('tiny-lr');
var app        = express();

var util       = require('./lib/util.js');
var apiFactory = require('./lib/api.js').factory;
var render     = require('./lib/render.js');
var deps       = require('./lib/deps.js');

// Start a tiny-lr server as well.
tinylr().listen(35729, function() {
  console.log('... Listening on 35729 ...');
});

if (process.argv.length < 4) {
  console.log('Usage:\n     node diversity-server.js <webshop-id> <theme-id|theme-name> [<auth>]');
  process.exit();
}

var webshopUid = process.argv[2];
var webshopUrl;
var themeUid = process.argv[3];
var auth = process.argv[4];

var api = apiFactory(webshopUid, 'sv', auth);


//<KEY>

app.use(bodyParser.json());
app.use(express.static('.'));

Q.all([
  //deps.updateDeps('tws-admin-schema-form').fail(function(err) {
  //  console.log(err);
  //}),

  deps.updateDeps({
    name: 'jquery.jsonrpcclient.js',
    url: 'https://github.com/Textalk/jquery.jsonrpcclient.js.git'
  }),


  //deps.updateDeps({
  //  name: 'aficionado',
  //  url: 'http://git.diversity.io/themes/aficionado.git'
  //}),

  api('Webshop.get', [webshopUid, {url:'sv'}]).then(function(result) {
    webshopUrl = result.url.sv;
  })
]).then(function() {

  // app.get('/reset', function(req, res) {
  //   // Reset skip list
  //   deps.reset();
  //   deps.updateDeps({ //update aficionado
  //     name: 'aficionado',
  //     url: 'http://git.diversity.io/themes/aficionado.git'
  //   }).then(function(){
  //     res.send('OK');
  //   }, function() {
  //     res.send(500);
  //   })
  //
  // });

  app.get('/*', function(req, res, next) {

    // Skip /deps, those are files
    if (req.url.indexOf('/deps') === 0) {
      return next();
    }

    // FIXME: unclutter this ugly mess
    // Calculate settings and fetch the theme component
    var fetchThemeCompAndJson = function(name) {
      return deps.updateDeps({ // Since its not under webshop components we must give an url.
        name: name,
        url: 'http://git.diversity.io/themes/' + name + '.git'
        // The second updateDeps actually loads diversity.json
      }).then(deps.updateDeps);
    };

    var tid = parseInt(themeUid, 10);
{'fraction_non_alphanumeric': 0.195067717808773, 'fraction_numerical': 0.01010713563776026, 'mean_word_length': 2.723100075244545, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 10, 'https://': 2, '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': '4582797', 'n_tokens_mistral': 1811, 'n_tokens_neox': 1742, 'n_words': 348}