mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-02 18:34:09 +00:00
async buildContracts
This commit is contained in:
parent
2dd9e8f2ea
commit
4ec7fbb9db
@ -53,6 +53,10 @@ function writeJSONSync() {
|
|||||||
return fs.writeJSONSync.apply(fs.writeJSONSync, arguments);
|
return fs.writeJSONSync.apply(fs.writeJSONSync, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function writeJson() {
|
||||||
|
return fs.writeJson.apply(fs.writeJson, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
function existsSync() {
|
function existsSync() {
|
||||||
return fs.existsSync.apply(fs.existsSync, arguments);
|
return fs.existsSync.apply(fs.existsSync, arguments);
|
||||||
}
|
}
|
||||||
@ -89,6 +93,7 @@ module.exports = {
|
|||||||
writeFile,
|
writeFile,
|
||||||
writeFileSync,
|
writeFileSync,
|
||||||
readJSONSync,
|
readJSONSync,
|
||||||
|
writeJson,
|
||||||
writeJSONSync,
|
writeJSONSync,
|
||||||
access,
|
access,
|
||||||
existsSync,
|
existsSync,
|
||||||
|
@ -53,146 +53,146 @@ class Pipeline {
|
|||||||
|
|
||||||
build(abi, contractsJSON, path, callback) {
|
build(abi, contractsJSON, path, callback) {
|
||||||
let self = this;
|
let self = this;
|
||||||
|
const importsList = {};
|
||||||
|
|
||||||
this.buildContracts(contractsJSON);
|
async.waterfall([
|
||||||
|
function buildTheContracts(next) {
|
||||||
|
self.buildContracts(contractsJSON, next);
|
||||||
|
},
|
||||||
|
function buildWeb3(next) {
|
||||||
|
self.buildWeb3JS(next);
|
||||||
|
},
|
||||||
|
function createImportList(next) {
|
||||||
|
importsList["Embark/EmbarkJS"] = fs.dappPath(".embark", 'embark.js');
|
||||||
|
importsList["Embark/web3"] = fs.dappPath(".embark", 'web3_instance.js');
|
||||||
|
|
||||||
self.buildWeb3JS(function (err) {
|
self.pluginImports.forEach(function (importObject) {
|
||||||
if (err) {
|
let [importName, importLocation] = importObject;
|
||||||
return callback(err);
|
importsList[importName] = importLocation;
|
||||||
}
|
});
|
||||||
|
|
||||||
let importsList = {};
|
next();
|
||||||
|
},
|
||||||
|
function writeContracts(next) {
|
||||||
|
async.each(Object.keys(contractsJSON), (contractName, eachCb) => {
|
||||||
|
let contractCode = self.buildContractJS(contractName);
|
||||||
|
let filePath = fs.dappPath(".embark", contractName + '.js');
|
||||||
|
importsList["Embark/contracts/" + contractName] = filePath;
|
||||||
|
fs.writeFile(filePath, contractCode, eachCb);
|
||||||
|
}, next);
|
||||||
|
},
|
||||||
|
function assetFileWrite(next) {
|
||||||
|
// limit:1 due to issues when downloading required files such as web3.js
|
||||||
|
async.eachOfLimit(self.assetFiles, 1, function (files, targetFile, cb) {
|
||||||
|
// limit:1 due to issues when downloading required files such as web3.js
|
||||||
|
async.mapLimit(files, 1,
|
||||||
|
function (file, fileCb) {
|
||||||
|
file = new File(file); // Re-instantiate a File as through the process, we lose its prototype
|
||||||
|
self.log("reading " + file.filename);
|
||||||
|
|
||||||
importsList["Embark/EmbarkJS"] = fs.dappPath(".embark", 'embark.js');
|
if (file.filename.indexOf('.js') < 0) {
|
||||||
importsList["Embark/web3"] = fs.dappPath(".embark", 'web3_instance.js');
|
return file.content(function (fileContent) {
|
||||||
|
self.runPlugins(file, fileContent, fileCb);
|
||||||
self.pluginImports.forEach(function (importObject) {
|
|
||||||
let [importName, importLocation] = importObject;
|
|
||||||
importsList[importName] = importLocation;
|
|
||||||
});
|
|
||||||
|
|
||||||
async.waterfall([
|
|
||||||
function writeContracts(next) {
|
|
||||||
async.each(Object.keys(contractsJSON), (contractName, eachCb) => {
|
|
||||||
let contractCode = self.buildContractJS(contractName);
|
|
||||||
let filePath = fs.dappPath(".embark", contractName + '.js');
|
|
||||||
importsList["Embark/contracts/" + contractName] = filePath;
|
|
||||||
fs.writeFile(filePath, contractCode, eachCb);
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
function assetFileWrite(next) {
|
|
||||||
// limit:1 due to issues when downloading required files such as web3.js
|
|
||||||
async.eachOfLimit(self.assetFiles, 1, function (files, targetFile, cb) {
|
|
||||||
// limit:1 due to issues when downloading required files such as web3.js
|
|
||||||
async.mapLimit(files, 1,
|
|
||||||
function (file, fileCb) {
|
|
||||||
file = new File(file); // Re-instantiate a File as through the process, we lose its prototype
|
|
||||||
self.log("reading " + file.filename);
|
|
||||||
|
|
||||||
if (file.filename.indexOf('.js') < 0) {
|
|
||||||
return file.content(function (fileContent) {
|
|
||||||
self.runPlugins(file, fileContent, fileCb);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// JS files
|
|
||||||
let realCwd;
|
|
||||||
|
|
||||||
async.waterfall([
|
|
||||||
|
|
||||||
function findImports(next) {
|
|
||||||
self.webpackRun(file.filename, {}, false, importsList, false, next);
|
|
||||||
},
|
|
||||||
|
|
||||||
function changeCwd(next) {
|
|
||||||
realCwd = utils.pwd();
|
|
||||||
process.chdir(fs.embarkPath(''));
|
|
||||||
next();
|
|
||||||
},
|
|
||||||
|
|
||||||
function runWebpack(next) {
|
|
||||||
self.webpackRun(file.filename, {}, true, importsList, true, next);
|
|
||||||
},
|
|
||||||
|
|
||||||
function changeCwdBack(next) {
|
|
||||||
process.chdir(realCwd);
|
|
||||||
next();
|
|
||||||
},
|
|
||||||
|
|
||||||
function checkFile(next) {
|
|
||||||
fs.access('./.embark/' + file.filename, (err) => {
|
|
||||||
if (err) {
|
|
||||||
self.log("couldn't find file: " + file.filename);
|
|
||||||
return next("couldn't find file: " + file.filename);
|
|
||||||
}
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
function readFile(next) {
|
|
||||||
fs.readFile('./.embark/' + file.filename, (err, data) => {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
next(null, data.toString());
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
function runPluginsOnContent(fileContent, next) {
|
|
||||||
self.runPlugins(file, fileContent, next);
|
|
||||||
}
|
|
||||||
|
|
||||||
], function (err, contentFile) {
|
|
||||||
if (err) {
|
|
||||||
process.chdir(realCwd);
|
|
||||||
self.log(err);
|
|
||||||
return fileCb(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
fileCb(null, contentFile);
|
|
||||||
});
|
});
|
||||||
},
|
|
||||||
function (err, contentFiles) {
|
|
||||||
if (err) {
|
|
||||||
self.log('errors found while generating ' + targetFile);
|
|
||||||
}
|
|
||||||
let dir = targetFile.split('/').slice(0, -1).join('/');
|
|
||||||
self.log("creating dir " + self.buildDir + dir);
|
|
||||||
fs.mkdirpSync(self.buildDir + dir);
|
|
||||||
|
|
||||||
// if it's a directory
|
|
||||||
if (targetFile.slice(-1) === '/' || targetFile.indexOf('.') === -1) {
|
|
||||||
let targetDir = targetFile;
|
|
||||||
|
|
||||||
if (targetDir.slice(-1) !== '/') {
|
|
||||||
targetDir = targetDir + '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
async.each(contentFiles, function (file, mapCb) {
|
|
||||||
let filename = file.filename.replace(file.basedir + '/', '');
|
|
||||||
self.log("writing file " + (self.buildDir + targetDir + filename).bold.dim);
|
|
||||||
|
|
||||||
fs.copy(file.path, self.buildDir + targetDir + filename, {overwrite: true}, mapCb);
|
|
||||||
}, cb);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let content = contentFiles.map(function (file) {
|
|
||||||
if (file === undefined) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return file.content;
|
|
||||||
}).join("\n");
|
|
||||||
|
|
||||||
self.log("writing file " + (self.buildDir + targetFile).bold.dim);
|
|
||||||
fs.writeFile(self.buildDir + targetFile, content, cb);
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
},
|
// JS files
|
||||||
next);
|
let realCwd;
|
||||||
}
|
|
||||||
], callback);
|
async.waterfall([
|
||||||
});
|
|
||||||
|
function findImports(next) {
|
||||||
|
self.webpackRun(file.filename, {}, false, importsList, false, next);
|
||||||
|
},
|
||||||
|
|
||||||
|
function changeCwd(next) {
|
||||||
|
realCwd = utils.pwd();
|
||||||
|
process.chdir(fs.embarkPath(''));
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
|
||||||
|
function runWebpack(next) {
|
||||||
|
self.webpackRun(file.filename, {}, true, importsList, true, next);
|
||||||
|
},
|
||||||
|
|
||||||
|
function changeCwdBack(next) {
|
||||||
|
process.chdir(realCwd);
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
|
||||||
|
function checkFile(next) {
|
||||||
|
fs.access('./.embark/' + file.filename, (err) => {
|
||||||
|
if (err) {
|
||||||
|
self.log("couldn't find file: " + file.filename);
|
||||||
|
return next("couldn't find file: " + file.filename);
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
function readFile(next) {
|
||||||
|
fs.readFile('./.embark/' + file.filename, (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
next(null, data.toString());
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
function runPluginsOnContent(fileContent, next) {
|
||||||
|
self.runPlugins(file, fileContent, next);
|
||||||
|
}
|
||||||
|
|
||||||
|
], function (err, contentFile) {
|
||||||
|
if (err) {
|
||||||
|
process.chdir(realCwd);
|
||||||
|
self.log(err);
|
||||||
|
return fileCb(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
fileCb(null, contentFile);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
function (err, contentFiles) {
|
||||||
|
if (err) {
|
||||||
|
self.log('errors found while generating ' + targetFile);
|
||||||
|
}
|
||||||
|
let dir = targetFile.split('/').slice(0, -1).join('/');
|
||||||
|
self.log("creating dir " + self.buildDir + dir);
|
||||||
|
fs.mkdirpSync(self.buildDir + dir);
|
||||||
|
|
||||||
|
// if it's a directory
|
||||||
|
if (targetFile.slice(-1) === '/' || targetFile.indexOf('.') === -1) {
|
||||||
|
let targetDir = targetFile;
|
||||||
|
|
||||||
|
if (targetDir.slice(-1) !== '/') {
|
||||||
|
targetDir = targetDir + '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
async.each(contentFiles, function (file, mapCb) {
|
||||||
|
let filename = file.filename.replace(file.basedir + '/', '');
|
||||||
|
self.log("writing file " + (self.buildDir + targetDir + filename).bold.dim);
|
||||||
|
|
||||||
|
fs.copy(file.path, self.buildDir + targetDir + filename, {overwrite: true}, mapCb);
|
||||||
|
}, cb);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let content = contentFiles.map(function (file) {
|
||||||
|
if (file === undefined) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return file.content;
|
||||||
|
}).join("\n");
|
||||||
|
|
||||||
|
self.log("writing file " + (self.buildDir + targetFile).bold.dim);
|
||||||
|
fs.writeFile(self.buildDir + targetFile, content, cb);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
next);
|
||||||
|
}
|
||||||
|
], callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
runPlugins(file, fileContent, fileCb) {
|
runPlugins(file, fileContent, fileCb) {
|
||||||
@ -298,13 +298,16 @@ class Pipeline {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
buildContracts(contractsJSON) {
|
buildContracts(contractsJSON, callback) {
|
||||||
fs.mkdirpSync(fs.dappPath(this.buildDir, 'contracts'));
|
fs.mkdirp(fs.dappPath(this.buildDir, 'contracts'), (err) => {
|
||||||
|
if (err) {
|
||||||
for (let className in contractsJSON) {
|
return callback(err);
|
||||||
let contract = contractsJSON[className];
|
}
|
||||||
fs.writeJSONSync(fs.dappPath(this.buildDir, 'contracts', className + ".json"), contract, {spaces: 2});
|
async.each(Object.keys(contractsJSON), (className, eachCb) => {
|
||||||
}
|
let contract = contractsJSON[className];
|
||||||
|
fs.writeJson(fs.dappPath(this.buildDir, 'contracts', className + ".json"), contract, {spaces: 2}, eachCb);
|
||||||
|
}, callback);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
buildContractJS(contractName) {
|
buildContractJS(contractName) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user