<commit_before> 'use strict';

var build       = exports;
var fs          = require('fs');
var fse         = require('fs-extra');
var expand      = require('fs-expand');
var node_path   = require('path');
var semver      = require('semver');
var async       = require('async');
var cortex_json   = require('read-cortex-json');
var semver_helper = require('../util/semver');
var lang        = require('../util/lang');
var spawns      = require('spawns');
var builder     = require('neuron-builder');
var ntree       = require('neuron-tree');
var neuron      = require('neuronjs');
var util        = require('util');

// @param {Object} options
//      see ./lib/option/build.js for details
build.run = function(options, callback) {
  this.MESSAGE = this.locale.require('command-build');
  options.install = options['install-build'];

  var self = this;
  async.eachSeries([
    'read_cortex_json',
    'run_preinstall_script',
    'run_prebuild_script',
    'build_process',
    'server_link'
  ], function (task, done) {
    self[task](options, done);
  }, callback);
};


build.read_cortex_json = function(options, callback) {
  function cb (err, json) {
    if (options.install && !json.main && !json.css.length) {
      return callback({
        code: 'REFUSE_INSTALL',
        message: 'Refuses to install a package without {{bold BOTH}} `cortex.main` and `cortex.css`'
      });
    }

    options.pkg = json;
    callback(err);
  }

  if (options.install) {
    // If install from cache, cortex.json will be enhanced json.
    var file = node_path.join(options.cwd, 'cortex.json');
    fse.readJson(file, function (err, json) {
      if (err) {
        return cb(err);
      }
      
      cortex_json.clean(options.cwd, json, cb);
    }.bind(this));
  } else {
    cortex_json.enhanced(options.cwd, cb);
  }
};


// Run custom build scripts, such as 'grunt'
build.run_preinstall_script = function(options, callback) {
  if (!options.preinstall) {
    return callback(null);
  }
  this.run_script('preinstall', options, callback);
};


// Run custom build scripts, such as 'grunt'
build.run_prebuild_script = function(options, callback) {
  if (!options.prebuild) {
    return callback(null);
  }
  this.run_script('prebuild', options, callback);
};<commit_msg>command/build: if build when install, it should not run scripts.prebuild; fixes #437<commit_after> 'use strict';

var build       = exports;
var fs          = require('fs');
var fse         = require('fs-extra');
var expand      = require('fs-expand');
var node_path   = require('path');
var semver      = require('semver');
var async       = require('async');
var cortex_json   = require('read-cortex-json');
var semver_helper = require('../util/semver');
var lang        = require('../util/lang');
var spawns      = require('spawns');
var builder     = require('neuron-builder');
var ntree       = require('neuron-tree');
var neuron      = require('neuronjs');
var util        = require('util');

// @param {Object} options
//      see ./lib/option/build.js for details
build.run = function(options, callback) {
  this.MESSAGE = this.locale.require('command-build');
  options.install = options['install-build'];

  var self = this;
  async.eachSeries([
    'read_cortex_json',
    'run_preinstall_script',
    'run_prebuild_script',
    'build_process',
    'server_link'
  ], function (task, done) {
    self[task](options, done);
  }, callback);
};


build.read_cortex_json = function(options, callback) {
  function cb (err, json) {
    if (options.install && !json.main && !json.css.length) {
      return callback({
        code: 'REFUSE_INSTALL',
        message: 'Refuses to install a package without {{bold BOTH}} `cortex.main` and `cortex.css`'
      });
    }

    options.pkg = json;
    callback(err);
  }

  if (options.install) {
    // If install from cache, cortex.json will be enhanced json.
    var file = node_path.join(options.cwd, 'cortex.json');
    fse.readJson(file, function (err, json) {
      if (err) {
        return cb(err);
      }
      
      cortex_json.clean(options.cwd, json, cb);
    }.bind(this));
  } else {
    cortex_json.enhanced(options.cwd, cb);
  }
};


// Run custom build scripts, such as 'grunt'
build.run_preinstall_script = function(options, callback) {
  if (!options.preinstall) {
    return callback(null);
  }
  this.run_script('preinstall', options, callback);
};


// Run custom build scripts, such as 'grunt'
build.run_prebuild_script = function(options, callback) {
  // #436: if build when install, it should not run scripts.prebuild
  if (!options.prebuild || options.install) {
    return callback(null);
  }
  this.run_script('prebuild', options, callback);
};
{'fraction_non_alphanumeric': 0.15192840400596633, 'fraction_numerical': 0.0012784998934583422, 'mean_word_length': 3.165039929015084, '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': '1637891', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1481, 'n_words': 364}