Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Edit truffle unbox #1471

Merged
merged 7 commits into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
265 changes: 0 additions & 265 deletions packages/truffle-box/.eslintrc.js

This file was deleted.

63 changes: 38 additions & 25 deletions packages/truffle-box/box.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var utils = require("./lib/utils");
var tmp = require("tmp");
var path = require("path");

var Config = require("truffle-config");
const utils = require("./lib/utils");
const tmp = require("tmp");
const path = require("path");
const Config = require("truffle-config");
const ora = require("ora");

function parseSandboxOptions(options) {
if (typeof options === "function") {
Expand All @@ -27,31 +27,44 @@ function parseSandboxOptions(options) {
}
}

var Box = {
unbox: function(url, destination, options) {
const Box = {
unbox: async (url, destination, options) => {
let tempDirCleanup;
options = options || {};
options.logger = options.logger || {log: () => {}};
const downloadBoxOptions = {
options.logger = options.logger || { log: () => {} };
const unpackBoxOptions = {
logger: options.logger,
force: options.force
};

return Promise.resolve()
.then(() => {
options.logger.log("Downloading...");
try {
options.logger.log("");
const tempDir = await utils.setUpTempDirectory();
tempDirPath = tempDir.path;
tempDirCleanup = tempDir.cleanupCallback;

await utils.downloadBox(url, tempDirPath);

const boxConfig = await utils.readBoxConfig(tempDirPath);

return utils.downloadBox(url, destination, downloadBoxOptions);
})
.then(() => {
options.logger.log("Unpacking...");
await utils.unpackBox(
tempDirPath,
destination,
boxConfig,
unpackBoxOptions
);

return utils.unpackBox(destination);
})
.then((boxConfig) => {
options.logger.log("Setting up...");
const cleanupSpinner = ora("Cleaning up temporary files").start();
tempDirCleanup();
cleanupSpinner.succeed();

return utils.setupBox(boxConfig, destination);
})
.then((boxConfig) => boxConfig);
await utils.setUpBox(boxConfig, destination);

return boxConfig;
} catch (error) {
if (tempDirCleanup) tempDirCleanup();
throw new Error(error);
}
},

// options.unsafeCleanup
Expand All @@ -61,7 +74,7 @@ var Box = {
sandbox: function(options, callback) {
var self = this;

const {name, unsafeCleanup, setGracefulCleanup} = parseSandboxOptions(
const { name, unsafeCleanup, setGracefulCleanup } = parseSandboxOptions(
options
);

Expand All @@ -73,7 +86,7 @@ var Box = {
tmp.setGracefulCleanup();
}

tmp.dir({unsafeCleanup}, function(err, dir) {
tmp.dir({ unsafeCleanup }, function(err, dir) {
if (err) {
return callback(err);
}
Expand Down
13 changes: 6 additions & 7 deletions packages/truffle-box/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ function setDefaults(config) {
return {
ignore: config.ignore || [],
commands: config.commands || {
"compile": "truffle compile",
"migrate": "truffle migrate",
"test": "truffle test"
compile: "truffle compile",
migrate: "truffle migrate",
test: "truffle test"
},
hooks: {
"post-unpack": hooks["post-unpack"] || ""
Expand All @@ -19,10 +19,9 @@ function setDefaults(config) {
}

function read(path) {
return fs.readFile(path)
.catch(function() {
return "{}";
})
return fs
.readFile(path)
.catch(() => "{}")
.then(JSON.parse)
.then(setDefaults);
}
Expand Down
Loading