2017-12-19 12:57:03 -05:00
|
|
|
const parseJson = require('parse-json');
|
2017-03-30 02:50:05 +09:00
|
|
|
let fs = require('fs-extra');
|
|
|
|
let utils = require('../utils/utils.js');
|
2017-12-19 12:57:03 -05:00
|
|
|
require('colors');
|
2017-02-19 11:37:54 -05:00
|
|
|
|
|
|
|
function mkdirpSync() {
|
|
|
|
return fs.mkdirpSync.apply(fs.mkdirpSync, arguments);
|
|
|
|
}
|
|
|
|
|
2018-04-17 16:34:37 -04:00
|
|
|
function mkdirp() {
|
|
|
|
return fs.mkdirp.apply(fs.mkdirp, arguments);
|
|
|
|
}
|
|
|
|
|
2018-09-13 14:30:15 -04:00
|
|
|
function readdir() {
|
|
|
|
return fs.readdir.apply(fs.readdir, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
function stat() {
|
|
|
|
return fs.stat.apply(fs.stat, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove() {
|
|
|
|
return fs.remove.apply(fs.remove, arguments);
|
|
|
|
}
|
|
|
|
|
2018-05-08 09:02:46 -04:00
|
|
|
function copy() {
|
|
|
|
return fs.copy.apply(fs.copy, arguments);
|
|
|
|
}
|
|
|
|
|
2017-02-19 11:37:54 -05:00
|
|
|
function copySync() {
|
|
|
|
return fs.copySync.apply(fs.copySync, arguments);
|
|
|
|
}
|
|
|
|
|
2018-05-22 15:15:34 +10:00
|
|
|
function move(){
|
|
|
|
return fs.move.apply(fs.move, arguments);
|
|
|
|
}
|
|
|
|
|
2018-08-12 14:08:37 -05:00
|
|
|
function moveSync() {
|
|
|
|
return fs.moveSync.apply(fs.moveSync, arguments);
|
|
|
|
}
|
|
|
|
|
2018-03-10 13:45:56 -05:00
|
|
|
function appendFileSync() {
|
|
|
|
return fs.appendFileSync.apply(fs.writeFileSync, arguments);
|
|
|
|
}
|
|
|
|
|
2018-05-07 15:48:01 -04:00
|
|
|
function writeFile() {
|
|
|
|
return fs.writeFile.apply(fs.writeFileSync, arguments);
|
|
|
|
}
|
|
|
|
|
2017-02-19 12:51:32 -05:00
|
|
|
function writeFileSync() {
|
|
|
|
return fs.writeFileSync.apply(fs.writeFileSync, arguments);
|
|
|
|
}
|
|
|
|
|
2018-04-18 12:09:42 -04:00
|
|
|
function readFile() {
|
|
|
|
return fs.readFile.apply(fs.readFile, arguments);
|
|
|
|
}
|
|
|
|
|
2017-02-19 11:37:54 -05:00
|
|
|
function readFileSync() {
|
|
|
|
return fs.readFileSync.apply(fs.readFileSync, arguments);
|
|
|
|
}
|
|
|
|
|
2018-08-30 13:13:37 +01:00
|
|
|
function readdirSync() {
|
|
|
|
return fs.readdirSync.apply(fs.readdirSync, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
function statSync() {
|
|
|
|
return fs.statSync.apply(fs.statSync, arguments);
|
|
|
|
}
|
|
|
|
|
2017-02-19 11:37:54 -05:00
|
|
|
function readJSONSync() {
|
2017-12-19 12:57:03 -05:00
|
|
|
let content = readFileSync.apply(readFileSync, arguments);
|
|
|
|
try {
|
|
|
|
return parseJson(content);
|
|
|
|
} catch(e) {
|
|
|
|
console.error("error: ".red + arguments[0].green.underline + " " + e.message.green);
|
|
|
|
process.exit(0);
|
|
|
|
}
|
2017-02-19 11:37:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function writeJSONSync() {
|
|
|
|
return fs.writeJSONSync.apply(fs.writeJSONSync, arguments);
|
|
|
|
}
|
|
|
|
|
2018-05-08 09:36:50 -04:00
|
|
|
function writeJson() {
|
|
|
|
return fs.writeJson.apply(fs.writeJson, arguments);
|
|
|
|
}
|
|
|
|
|
2017-03-30 20:12:39 +09:00
|
|
|
function existsSync() {
|
2017-02-21 15:45:10 -05:00
|
|
|
return fs.existsSync.apply(fs.existsSync, arguments);
|
|
|
|
}
|
|
|
|
|
2018-05-08 08:54:10 -04:00
|
|
|
function access() {
|
|
|
|
return fs.access.apply(fs.access, arguments);
|
|
|
|
}
|
|
|
|
|
2018-01-11 09:22:58 -05:00
|
|
|
function removeSync() {
|
|
|
|
return fs.removeSync.apply(fs.removeSync, arguments);
|
|
|
|
}
|
|
|
|
|
2018-08-17 17:55:39 -05:00
|
|
|
function anchoredPath(envAnchor, ...args) {
|
|
|
|
const anchor = process.env[envAnchor];
|
|
|
|
if (!anchor) {
|
|
|
|
console.error(`process.env.${envAnchor} was not set`.bold.red);
|
2018-08-17 12:37:49 -05:00
|
|
|
process.exit(1);
|
|
|
|
}
|
2018-08-17 17:55:39 -05:00
|
|
|
return utils.joinPath(anchor, ...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
function embarkPath() {
|
|
|
|
return anchoredPath('EMBARK_PATH', ...arguments);
|
2017-02-19 19:44:16 -05:00
|
|
|
}
|
|
|
|
|
2018-04-02 15:30:16 -04:00
|
|
|
function dappPath() {
|
2018-08-17 17:55:39 -05:00
|
|
|
return anchoredPath('DAPP_PATH', ...arguments);
|
2017-07-05 08:35:51 -04:00
|
|
|
}
|
|
|
|
|
2018-04-17 16:34:37 -04:00
|
|
|
function createWriteStream() {
|
|
|
|
return fs.createWriteStream.apply(fs.createWriteStream, arguments);
|
|
|
|
}
|
|
|
|
|
2018-07-06 11:38:09 +03:00
|
|
|
function tmpDir() {
|
|
|
|
let os = require('os');
|
|
|
|
return utils.joinPath(os.tmpdir(), ...arguments);
|
|
|
|
}
|
|
|
|
|
2017-02-19 11:37:54 -05:00
|
|
|
module.exports = {
|
2018-05-07 15:48:01 -04:00
|
|
|
mkdirpSync,
|
2018-04-17 16:34:37 -04:00
|
|
|
mkdirp,
|
2018-09-13 14:30:15 -04:00
|
|
|
readdir,
|
|
|
|
stat,
|
|
|
|
remove,
|
2018-05-08 09:02:46 -04:00
|
|
|
copy,
|
2018-05-07 15:48:01 -04:00
|
|
|
copySync,
|
2018-05-22 15:15:34 +10:00
|
|
|
move,
|
2018-08-12 14:08:37 -05:00
|
|
|
moveSync,
|
2018-04-18 12:09:42 -04:00
|
|
|
readFile,
|
2018-05-07 15:48:01 -04:00
|
|
|
readFileSync,
|
2018-08-30 13:13:37 +01:00
|
|
|
readdirSync,
|
|
|
|
statSync,
|
2018-05-07 15:48:01 -04:00
|
|
|
appendFileSync,
|
|
|
|
writeFile,
|
|
|
|
writeFileSync,
|
|
|
|
readJSONSync,
|
2018-05-08 09:36:50 -04:00
|
|
|
writeJson,
|
2018-05-07 15:48:01 -04:00
|
|
|
writeJSONSync,
|
2018-05-08 08:54:10 -04:00
|
|
|
access,
|
2018-05-07 15:48:01 -04:00
|
|
|
existsSync,
|
|
|
|
removeSync,
|
|
|
|
embarkPath,
|
|
|
|
dappPath,
|
2018-07-06 11:38:09 +03:00
|
|
|
createWriteStream,
|
|
|
|
tmpDir
|
2017-02-19 11:37:54 -05:00
|
|
|
};
|