<commit_before>"use strict";

var fs = require('fs'),
  path = require('path'),
  mkdirp = require('mkdirp'),
  derp = require('./derp'),
  options = require('./options'),
  debug = require('debug')('lone:configure');


// Build some config strings and make sure directories exist so we can build
// node from source and do a little validation on package.json.
module.exports = function(config){
  return function configure(fn){
    config.node = config.node || {version: config.node || options.node.default};

    var filename = 'node-v' + config.node.version + '.tar.gz';

    derp.extend(config, {
      cache: derp.resolve(config.cache || options.cache.default),
      src: derp.resolve(config.src || process.cwd())
    });

    derp.extend(config.node, {
      filename: filename,
      url: 'http://nodejs.org/dist/latest/' + filename,
      dest: config.cache + '/source/' + filename,
      working: config.cache + '/' + filename.replace('.tar.gz', '')
    });

    config.node.out = config.node.working + '/out/Release/node';

    config.app = {
      name: null,
      bin: null,
      dependencies: {},
      devDependencies: {}
    };

    fs.readFile(config.src + '/package.json', function(err, data){
      if(err) return fn(new Error('typo or no package.json for your app? looked in: ' + config.src));

      var pkg = JSON.parse(data);

      // @note: Yep this is pretty dogmatic, but the idea is have the same
      // experience with module, just running alone.  We want the user to have
      // the same experience whether they're running a standalone or installed
      // from npm.
      if(!pkg.bin || !pkg.bin[pkg.name]){
        return fn(new Error('you have no `bin` for ' + pkg.name + ' in package.json.\nrun lone --setup for help'));
      }

      config.out = config.src + '/.dist/' + pkg.name;
      config.bundle = config.src + '/.build/' + pkg.name + '.zip';

      config.app.bin = derp.resolve(config.src, pkg.bin[pkg.name]);

      ['name', 'dependencies', 'devDependencies'].map(function(key){
        if(pkg[key]){
          config.app[key] = pkg[key];
        }
      });

      fs.exists(config.app.bin, function(exists){
        if(!exists) return fn(new Error(config.app.bin + ' does not exist'));

        debug('configured', config.app.name);
        debug('- out', derp.relativity(config.out));
        debug('- src', derp.relativity(config.src));
        debug('- bundle', derp.relativity(config.bundle));


        derp.directory(config, config.src + '/.dist', config.src + '/.build',
          path.dirname(config.node.dest), fn);
      });
    });
  };
};<commit_msg>new ignore option<commit_after>"use strict";

var fs = require('fs'),
  path = require('path'),
  mkdirp = require('mkdirp'),
  derp = require('./derp'),
  options = require('./options'),
  debug = require('debug')('lone:configure');


// Build some config strings and make sure directories exist so we can build
// node from source and do a little validation on package.json.
module.exports = function(config){
  return function configure(fn){
    config.node = config.node || {version: config.node || options.node.default};

    var filename = 'node-v' + config.node.version + '.tar.gz';

    derp.extend(config, {
      cache: derp.resolve(config.cache || options.cache.default),
      src: derp.resolve(config.src || process.cwd()),
      ignore: config.ignore || []
    });

    if(!Array.isArray(config.ignore)) config.ignore = [config.ignore];

    derp.extend(config.node, {
      filename: filename,
      url: 'http://nodejs.org/dist/latest/' + filename,
      dest: config.cache + '/source/' + filename,
      working: config.cache + '/' + filename.replace('.tar.gz', '')
    });

    config.node.out = config.node.working + '/out/Release/node';

    config.app = {
      name: null,
      bin: null,
      dependencies: {},
      devDependencies: {}
    };

    fs.readFile(config.src + '/package.json', function(err, data){
      if(err) return fn(new Error('typo or no package.json for your app? looked in: ' + config.src));

      var pkg = JSON.parse(data);

      // @note: Yep this is pretty dogmatic, but the idea is have the same
      // experience with module, just running alone.  We want the user to have
      // the same experience whether they're running a standalone or installed
      // from npm.
      if(!pkg.bin || !pkg.bin[pkg.name]){
        return fn(new Error('you have no `bin` for ' + pkg.name + ' in package.json.\nrun lone --setup for help'));
      }

      config.out = config.src + '/.dist/' + pkg.name;
      config.bundle = config.src + '/.build/' + pkg.name + '.zip';

      config.app.bin = derp.resolve(config.src, pkg.bin[pkg.name]);

      ['name', 'dependencies', 'devDependencies'].map(function(key){
        if(pkg[key]){
          config.app[key] = pkg[key];
        }
      });

      fs.exists(config.app.bin, function(exists){
        if(!exists) return fn(new Error(config.app.bin + ' does not exist'));

        debug('configured', config.app.name);
        debug('- out', derp.relativity(config.out));
        debug('- src', derp.relativity(config.src));
        debug('- bundle', derp.relativity(config.bundle));
        debug('- ignore', config.ignore);


        derp.directory(config, config.src + '/.dist', config.src + '/.build',
          path.dirname(config.node.dest), fn);
      });
    });
  };
};
{'fraction_non_alphanumeric': 0.16973073351903437, 'fraction_numerical': 0.0, 'mean_word_length': 2.6739427012278307, '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': '458967', 'n_tokens_mistral': 1681, 'n_tokens_neox': 1616, 'n_words': 412}