trufflesuite / truffle-core

Core code for Truffle command line tool
MIT License
93 stars 93 forks source link

[TEST] Provide Functionality to Create Sandbox from Local Source #108

Closed ghost closed 6 years ago

ghost commented 6 years ago

Box.sandbox() is directly coupled to github, the "boxes" (project templates) are downloaded from there.

It should be possibly to load boxes from the local file-system (e.g. offline-work, test-sequences etc.).

This should be either implemented directly into truffle-box, or as a quick workaround for the current problems within #87.

ghost commented 6 years ago

Quick Workaround

Locate the relevant box.js file, for example:

P:\sand\truffle\dependencies\truffle-core\node_modules\truffle-box\box.js

Replace unbox/sanbox code with this one:

  unbox: function(sourceDir, destination, options) {
    options = options || {};
    options.logger = options.logger || {log: function() {}}

    return Promise.resolve()
      .then(function() {
        options.logger.log("Copy " + sourceDir + ' ==> ' + destination);
        //return utils.downloadBox(url, destination)
        var unbox = require('./lib/utils/unbox');
        return unbox.copyTempIntoDestination(sourceDir, destination);
      })
      .then(function() {
        options.logger.log("Unpacking...");
        return utils.unpackBox(destination);
      })
      .then(function(boxConfig) {
        options.logger.log("Setting up...");
        return utils.setupBox(boxConfig, destination)
      })
      .then(function(boxConfig) {
        return boxConfig;
      });
  },

  sandbox: function(name, callback) {
    var self = this;
    if (typeof name === "function") {
      callback = name;
      name = "default";
    }

    tmp.dir(function(err, dir, cleanupCallback) {
      if (err) {
        return callback(err);
      }

      self.unbox("../truffle-init-" + name, dir)
        .then(function() {
          var config = Config.load(path.join(dir, "truffle.js"), {});
          callback(null, config);
        })
        .catch(callback);
    });
  }  

Get a local copy of the truffle-init-default

cd truffle\dependencies
git clone https://github.com/trufflesuite/truffle-init-default.git

run the truffle-core test as usual, no changes needed.

ghost commented 6 years ago

follow-up: #117