UNPKG

truffle

Version:

Truffle - Simple development framework for Ethereum

33 lines (29 loc) 899 B
const tmp = require("tmp"); const fse = require("fs-extra"); const Config = require("@truffle/config"); const path = require("path"); module.exports = { async create(source, subPath = "") { if (!fse.existsSync(source)) { throw new Error(`Sandbox failed: source: ${source} does not exist`); } const tempDir = tmp.dirSync({ unsafeCleanup: true }); fse.copySync(source, tempDir.name); const config = Config.load( path.join(tempDir.name, subPath, "truffle-config.js"), {} ); return { config, cleanupSandboxDir: tempDir.removeCallback, tempDirPath: path.join(tempDir.name, subPath) }; }, async load(source) { if (!fse.existsSync(source)) { throw new Error(`Sandbox failed: source: ${source} does not exist`); } const config = Config.load(path.join(source, "truffle-config.js"), {}); return config; } };