mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-22 10:28:34 +00:00
refactor(@embark) add fs to plugin api; change (most) modules to use it instead of coupling them with require
refactor(@embark) add fs to plugin api; change (most) modules to use it instead of coupling them with require refactor(@embark) add fs to plugin api; change (most) modules to use it instead of coupling them with require refactor(@embark) add fs to plugin api; change (most) modules to use it instead of coupling them with require refactor(@embark) add fs to plugin api; change (most) modules to use it instead of coupling them with require refactor(@embark) add fs to plugin api; change (most) modules to use it instead of coupling them with require refactor(@embark) add fs to plugin api; change (most) modules to use it instead of coupling them with require
This commit is contained in:
parent
f0605bed2b
commit
c1d84fe8d8
1
packages/embark-typings/src/embark.d.ts
vendored
1
packages/embark-typings/src/embark.d.ts
vendored
@ -13,6 +13,7 @@ export interface Embark {
|
||||
registerAPICall: any;
|
||||
registerConsoleCommand: any;
|
||||
logger: Logger;
|
||||
fs: any;
|
||||
config: {
|
||||
contractsFiles: any[];
|
||||
embarkConfig: {
|
||||
|
@ -1,4 +1,3 @@
|
||||
const fs = require('./fs.js');
|
||||
const utils = require('../utils/utils.js');
|
||||
const constants = require('../constants');
|
||||
|
||||
@ -38,6 +37,7 @@ var Plugin = function(options) {
|
||||
this.events = options.events;
|
||||
this.config = options.config;
|
||||
this.plugins = options.plugins;
|
||||
this.fs = options.fs;
|
||||
this.env = options.env;
|
||||
this.loaded = false;
|
||||
this.currentContext = options.context;
|
||||
@ -102,7 +102,7 @@ Plugin.prototype.loadInternalPlugin = function() {
|
||||
};
|
||||
|
||||
Plugin.prototype.loadPluginFile = function(filename) {
|
||||
return fs.readFileSync(this.pathToFile(filename)).toString();
|
||||
return this.fs.readFileSync(this.pathToFile(filename)).toString();
|
||||
};
|
||||
|
||||
Plugin.prototype.pathToFile = function(filename) {
|
||||
|
@ -11,6 +11,7 @@ var Plugins = function(options) {
|
||||
this.events = options.events;
|
||||
this.config = options.config;
|
||||
this.context = options.context;
|
||||
this.fs = fs;
|
||||
this.env = options.env;
|
||||
this.version = options.version;
|
||||
};
|
||||
@ -45,6 +46,7 @@ Plugins.prototype.createPlugin = function(pluginName, pluginConfig) {
|
||||
events: this.events,
|
||||
config: this.config,
|
||||
plugins: this.plugins,
|
||||
fs: this.fs,
|
||||
isInternal: true,
|
||||
context: this.context
|
||||
});
|
||||
@ -58,7 +60,7 @@ Plugins.prototype.loadInternalPlugin = function(pluginName, pluginConfig, isPack
|
||||
pluginPath = pluginName;
|
||||
plugin = require(pluginName);
|
||||
} else {
|
||||
pluginPath = fs.embarkPath('dist/lib/modules/' + pluginName);
|
||||
pluginPath = this.fs.embarkPath('dist/lib/modules/' + pluginName);
|
||||
plugin = require(pluginPath);
|
||||
}
|
||||
|
||||
@ -76,6 +78,7 @@ Plugins.prototype.loadInternalPlugin = function(pluginName, pluginConfig, isPack
|
||||
events: this.events,
|
||||
config: this.config,
|
||||
plugins: this.plugins,
|
||||
fs: this.fs,
|
||||
isInternal: true,
|
||||
context: this.context,
|
||||
env: this.env
|
||||
@ -85,7 +88,7 @@ Plugins.prototype.loadInternalPlugin = function(pluginName, pluginConfig, isPack
|
||||
};
|
||||
|
||||
Plugins.prototype.loadPlugin = function(pluginName, pluginConfig) {
|
||||
var pluginPath = fs.dappPath('node_modules', pluginName);
|
||||
var pluginPath = this.fs.dappPath('node_modules', pluginName);
|
||||
var plugin = require(pluginPath);
|
||||
|
||||
var pluginWrapper = new Plugin({
|
||||
@ -98,6 +101,7 @@ Plugins.prototype.loadPlugin = function(pluginName, pluginConfig) {
|
||||
events: this.events,
|
||||
config: this.config,
|
||||
plugins: this.plugins,
|
||||
fs: this.fs,
|
||||
isInternal: false,
|
||||
context: this.context,
|
||||
version: this.version
|
||||
|
@ -6,7 +6,6 @@ const ethUtil = require('ethereumjs-util');
|
||||
const utils = require('../../utils/utils');
|
||||
const constants = require('../../constants');
|
||||
const embarkJsUtils = require('embarkjs').Utils;
|
||||
const fs = require('../../core/fs');
|
||||
|
||||
const WEB3_READY = 'blockchain:ready';
|
||||
|
||||
@ -28,7 +27,8 @@ class BlockchainConnector {
|
||||
this.wait = options.wait;
|
||||
this.contractsSubscriptions = [];
|
||||
this.contractsEvents = [];
|
||||
this.logFile = fs.dappPath(".embark", "contractEvents.json");
|
||||
this.fs = embark.fs;
|
||||
this.logFile = this.fs.dappPath(".embark", "contractEvents.json");
|
||||
|
||||
this.writeLogFile = async.cargo((tasks, callback) => {
|
||||
const data = this._readEvents();
|
||||
@ -37,7 +37,7 @@ class BlockchainConnector {
|
||||
data[new Date().getTime()] = task;
|
||||
});
|
||||
|
||||
fs.writeJson(this.logFile, data, err => {
|
||||
this.fs.writeJson(this.logFile, data, err => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
@ -218,7 +218,7 @@ class BlockchainConnector {
|
||||
|
||||
addWeb3ToEmbarkJS() {
|
||||
let code = '';
|
||||
code += fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString();
|
||||
code += this.fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString();
|
||||
code += "\nEmbarkJS.Blockchain.registerProvider('web3', __embarkWeb3);";
|
||||
|
||||
// TODO when we refactor code generator, refactor this to actually do something like connect
|
||||
@ -774,9 +774,9 @@ class BlockchainConnector {
|
||||
}
|
||||
|
||||
_readEvents() {
|
||||
fs.ensureFileSync(this.logFile);
|
||||
this.fs.ensureFileSync(this.logFile);
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(this.logFile));
|
||||
return JSON.parse(this.fs.readFileSync(this.logFile));
|
||||
} catch(_error) {
|
||||
return {};
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
let async = require('async');
|
||||
let fs = require('../../core/fs.js');
|
||||
const utils = require('../../utils/utils.js');
|
||||
const constants = require('../../constants');
|
||||
|
||||
@ -20,6 +19,7 @@ class CodeGenerator {
|
||||
constructor(embark, options) {
|
||||
this.blockchainConfig = embark.config.blockchainConfig || {};
|
||||
this.embarkConfig = embark.config.embarkConfig;
|
||||
this.fs = embark.fs;
|
||||
this.dappConfigs = {};
|
||||
this.logger = embark.logger;
|
||||
this.rpcHost = this.blockchainConfig.rpcHost || '';
|
||||
@ -46,7 +46,7 @@ class CodeGenerator {
|
||||
this.events.on('config:load:storage', this.generateStorageConfig.bind(this));
|
||||
this.events.on('config:load:communication', this.generateCommunicationConfig.bind(this));
|
||||
|
||||
this.events.setCommandHandler('code', function(cb) {
|
||||
this.events.setCommandHandler('code', (cb) => {
|
||||
this.events.request("contracts:list", (_err, contractsList) => {
|
||||
let embarkJSABI = this.generateABI(contractsList, {useEmbarkJS: true});
|
||||
let contractsJSON = this.generateContractsJSON(contractsList);
|
||||
@ -134,7 +134,7 @@ class CodeGenerator {
|
||||
}
|
||||
|
||||
checkIfNeedsUpdate(file, newOutput, callback) {
|
||||
fs.readFile(file, (err, content) => {
|
||||
this.fs.readFile(file, (err, content) => {
|
||||
if (err) {
|
||||
return callback(null, true);
|
||||
}
|
||||
@ -174,7 +174,7 @@ class CodeGenerator {
|
||||
}
|
||||
async.waterfall([
|
||||
(next) => {
|
||||
fs.mkdirp(dir, next);
|
||||
this.fs.mkdirp(dir, next);
|
||||
},
|
||||
(_dir, next) => {
|
||||
this.checkIfNeedsUpdate(filePath, artifactInput, next);
|
||||
@ -183,7 +183,7 @@ class CodeGenerator {
|
||||
if (!needsUpdate) {
|
||||
return next();
|
||||
}
|
||||
fs.writeFile(filePath, artifactInput, next);
|
||||
this.fs.writeFile(filePath, artifactInput, next);
|
||||
}
|
||||
], (err) => {
|
||||
if (err) {
|
||||
@ -302,10 +302,10 @@ class CodeGenerator {
|
||||
function getWeb3Location(next) {
|
||||
self.events.request("version:get:web3", function(web3Version) {
|
||||
if (web3Version === "1.0.0-beta") {
|
||||
return next(null, require.resolve("web3", {paths: [fs.embarkPath("node_modules")]}));
|
||||
return next(null, require.resolve("web3", {paths: [self.fs.embarkPath("node_modules")]}));
|
||||
}
|
||||
self.events.request("version:getPackageLocation", "web3", web3Version, function(err, location) {
|
||||
return next(null, fs.dappPath(location));
|
||||
return next(null, self.fs.dappPath(location));
|
||||
});
|
||||
});
|
||||
},
|
||||
@ -337,7 +337,7 @@ class CodeGenerator {
|
||||
}
|
||||
|
||||
getReloadPageCode() {
|
||||
return this.env === 'development' ? fs.readFileSync(require('path').join(__dirname,'/code/reload-on-change.js'), 'utf8') : '';
|
||||
return this.env === 'development' ? this.fs.readFileSync(require('path').join(__dirname,'/code/reload-on-change.js'), 'utf8') : '';
|
||||
}
|
||||
|
||||
getEmbarkJsProviderCode() {
|
||||
@ -388,10 +388,10 @@ class CodeGenerator {
|
||||
function getWeb3Location(next) {
|
||||
self.events.request("version:get:web3", function(web3Version) {
|
||||
if (web3Version === "1.0.0-beta") {
|
||||
return next(null, require.resolve("web3", {paths: [fs.embarkPath("node_modules")]}));
|
||||
return next(null, require.resolve("web3", {paths: [self.fs.embarkPath("node_modules")]}));
|
||||
}
|
||||
self.events.request("version:getPackageLocation", "web3", web3Version, function(err, location) {
|
||||
return next(null, fs.dappPath(location));
|
||||
return next(null, self.fs.dappPath(location));
|
||||
});
|
||||
});
|
||||
},
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*globals __*/
|
||||
const env = require("../../core/env");
|
||||
const fs = require("../../core/fs");
|
||||
const utils = require("../../utils/utils");
|
||||
const EmbarkJS = require("embarkjs");
|
||||
const IpfsApi = require("ipfs-api");
|
||||
@ -24,6 +23,7 @@ class Console {
|
||||
private version: string;
|
||||
private logger: any;
|
||||
private ipc: any;
|
||||
private fs: any;
|
||||
private config: any;
|
||||
private history: string[];
|
||||
private cmdHistoryFile: string;
|
||||
@ -37,11 +37,12 @@ class Console {
|
||||
this.plugins = options.plugins;
|
||||
this.version = options.version;
|
||||
this.logger = options.logger;
|
||||
this.fs = embark.fs;
|
||||
this.ipc = options.ipc;
|
||||
this.config = options.config;
|
||||
this.forceRegister = options.forceRegister;
|
||||
this.history = [];
|
||||
this.cmdHistoryFile = options.cmdHistoryFile || fs.dappPath(".embark", "cmd_history");
|
||||
this.cmdHistoryFile = options.cmdHistoryFile || this.fs.dappPath(".embark", "cmd_history");
|
||||
this.providerReady = false;
|
||||
this.loadHistory();
|
||||
|
||||
@ -209,8 +210,8 @@ class Console {
|
||||
}
|
||||
|
||||
private loadHistory() {
|
||||
if (fs.existsSync(this.cmdHistoryFile)) {
|
||||
fs.readFileSync(this.cmdHistoryFile)
|
||||
if (this.fs.existsSync(this.cmdHistoryFile)) {
|
||||
this.fs.readFileSync(this.cmdHistoryFile)
|
||||
.toString()
|
||||
.split("\n")
|
||||
.reverse()
|
||||
@ -248,8 +249,8 @@ class Console {
|
||||
this.ipc.client.emit("console:history:save", cmd);
|
||||
}
|
||||
|
||||
if (fs.existsSync(utils.dirname(this.cmdHistoryFile))) {
|
||||
fs.writeFileSync(
|
||||
if (this.fs.existsSync(utils.dirname(this.cmdHistoryFile))) {
|
||||
this.fs.writeFileSync(
|
||||
this.cmdHistoryFile,
|
||||
history
|
||||
.slice(Math.max(0, history.length - this.cmdHistorySize()))
|
||||
|
@ -1,6 +1,5 @@
|
||||
const async = require('async');
|
||||
const utils = require('../../utils/utils.js');
|
||||
const fs = require('../../core/fs');
|
||||
|
||||
class ConsoleListener {
|
||||
constructor(embark, options) {
|
||||
@ -8,11 +7,12 @@ class ConsoleListener {
|
||||
this.logger = embark.logger;
|
||||
this.ipc = options.ipc;
|
||||
this.events = embark.events;
|
||||
this.fs = embark.fs;
|
||||
this.addressToContract = [];
|
||||
this.contractsConfig = embark.config.contractsConfig;
|
||||
this.contractsDeployed = false;
|
||||
this.outputDone = false;
|
||||
this.logFile = fs.dappPath(".embark", "contractLogs.json");
|
||||
this.logFile = this.fs.dappPath(".embark", "contractLogs.json");
|
||||
|
||||
if (this.ipc.ipcRole === 'server') {
|
||||
this._listenForLogRequests();
|
||||
@ -38,7 +38,7 @@ class ConsoleListener {
|
||||
data[new Date().getTime()] = task;
|
||||
});
|
||||
|
||||
fs.writeJson(this.logFile, data, err => {
|
||||
this.fs.writeJson(this.logFile, data, err => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
@ -182,9 +182,9 @@ class ConsoleListener {
|
||||
}
|
||||
|
||||
_readLogs() {
|
||||
fs.ensureFileSync(this.logFile);
|
||||
this.fs.ensureFileSync(this.logFile);
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(this.logFile));
|
||||
return JSON.parse(this.fs.readFileSync(this.logFile));
|
||||
} catch (_error) {
|
||||
return {};
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ let async = require('async');
|
||||
const cloneDeep = require('clone-deep');
|
||||
|
||||
const utils = require('../../utils/utils.js');
|
||||
const fs = require('../../core/fs');
|
||||
const constants = require('../../constants');
|
||||
|
||||
// TODO: create a contract object
|
||||
@ -12,6 +11,7 @@ class ContractsManager {
|
||||
const self = this;
|
||||
this.logger = embark.logger;
|
||||
this.events = embark.events;
|
||||
this.fs = embark.fs;
|
||||
this.plugins = options.plugins;
|
||||
|
||||
this.contracts = {};
|
||||
@ -289,11 +289,11 @@ class ContractsManager {
|
||||
});
|
||||
},
|
||||
function allContractsCompiled(callback) {
|
||||
const allContractsCompiled =
|
||||
self.compiledContracts &&
|
||||
self.contractsFiles &&
|
||||
self.contractsFiles.every(contractFile =>
|
||||
Object.values(self.compiledContracts).find(contract =>
|
||||
const allContractsCompiled =
|
||||
self.compiledContracts &&
|
||||
self.contractsFiles &&
|
||||
self.contractsFiles.every(contractFile =>
|
||||
Object.values(self.compiledContracts).find(contract =>
|
||||
contract.originalFilename === contractFile.filename
|
||||
)
|
||||
);
|
||||
@ -327,7 +327,7 @@ class ContractsManager {
|
||||
return eachCb();
|
||||
}
|
||||
|
||||
fs.readFile(fs.dappPath(contract.artifact), (err, artifactBuf) => {
|
||||
self.fs.readFile(self.fs.dappPath(contract.artifact), (err, artifactBuf) => {
|
||||
if (err) {
|
||||
self.logger.error(__('Error while reading the artifact for "{{className}}" at {{path}}', {className, path: contract.artifact}));
|
||||
return eachCb(err);
|
||||
@ -362,7 +362,7 @@ class ContractsManager {
|
||||
contract.abiDefinition = compiledContract.abiDefinition;
|
||||
contract.filename = compiledContract.filename;
|
||||
contract.originalFilename = compiledContract.originalFilename || ("contracts/" + contract.filename);
|
||||
contract.path = fs.dappPath(contract.originalFilename);
|
||||
contract.path = self.fs.dappPath(contract.originalFilename);
|
||||
|
||||
contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas || 'auto';
|
||||
|
||||
|
@ -8,16 +8,16 @@ import { ContractEnhanced } from "./contractEnhanced";
|
||||
import { coverageContractsPath } from "./path";
|
||||
import { Coverage as ICoverage } from "./types";
|
||||
|
||||
const fs = require("../../core/fs");
|
||||
|
||||
export default class Coverage {
|
||||
private contracts: ContractEnhanced[];
|
||||
private deployedContracts: Contract[] = [];
|
||||
private web3Contracts: Web3Contract[] = [];
|
||||
private contractsDir: string[] = [];
|
||||
private fs: any;
|
||||
|
||||
constructor(private embark: Embark, options: any) {
|
||||
fs.ensureDirSync(coverageContractsPath());
|
||||
this.fs = embark.fs;
|
||||
this.fs.ensureDirSync(coverageContractsPath());
|
||||
const contractsDirConfig = this.embark.config.embarkConfig.contracts;
|
||||
this.contractsDir = Array.isArray(contractsDirConfig) ? contractsDirConfig : [contractsDirConfig];
|
||||
|
||||
@ -37,10 +37,10 @@ export default class Coverage {
|
||||
private getContracts() {
|
||||
const solcVersion = this.embark.config.embarkConfig.versions.solc;
|
||||
const filepaths = this.contractsDir.reduce((acc: string[], pattern: string) => (
|
||||
acc.concat(globule.find(pattern, { prefixBase: false, srcBase: fs.dappPath() }))
|
||||
acc.concat(globule.find(pattern, { prefixBase: false, srcBase: this.fs.dappPath() }))
|
||||
), []);
|
||||
|
||||
return filepaths.filter((filepath) => fs.statSync(filepath).isFile())
|
||||
return filepaths.filter((filepath) => this.fs.statSync(filepath).isFile())
|
||||
.map((filepath) => new ContractEnhanced(filepath, solcVersion));
|
||||
}
|
||||
|
||||
@ -73,15 +73,15 @@ export default class Coverage {
|
||||
}
|
||||
|
||||
private writeCoverageReport(cb: () => void) {
|
||||
fs.ensureDirSync(path.join(fs.dappPath(), ".embark"));
|
||||
const coveragePath = path.join(fs.dappPath(), ".embark", "coverage.json");
|
||||
this.fs.ensureDirSync(path.join(this.fs.dappPath(), ".embark"));
|
||||
const coveragePath = path.join(this.fs.dappPath(), ".embark", "coverage.json");
|
||||
|
||||
const coverageReport = this.contracts.reduce((acc: {[name: string]: ICoverage}, contract) => {
|
||||
acc[contract.filepath] = contract.coverage;
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
fs.writeFile(coveragePath, JSON.stringify(coverageReport, null, 2), cb);
|
||||
this.fs.writeFile(coveragePath, JSON.stringify(coverageReport, null, 2), cb);
|
||||
}
|
||||
|
||||
private collectEvents(web3Contracts: Web3Contract[]) {
|
||||
|
@ -1,5 +1,4 @@
|
||||
let utils = require('../../utils/utils.js');
|
||||
let fs = require('../../core/fs.js');
|
||||
|
||||
class DeployTracker {
|
||||
|
||||
@ -7,6 +6,7 @@ class DeployTracker {
|
||||
this.logger = embark.logger;
|
||||
this.events = embark.events;
|
||||
this.embark = embark;
|
||||
this.fs = embark.fs;
|
||||
this.trackContracts = (options.trackContracts !== false);
|
||||
|
||||
// TODO: unclear where it comes from
|
||||
@ -20,13 +20,13 @@ class DeployTracker {
|
||||
loadChainTrackerFile() {
|
||||
if (this.chainFile === false) return;
|
||||
if (this.chainFile === undefined) this.chainFile = ".embark/chains.json";
|
||||
this.chainFile = fs.dappPath(this.chainFile);
|
||||
if (!fs.existsSync(this.chainFile)) {
|
||||
this.chainFile = this.fs.dappPath(this.chainFile);
|
||||
if (!this.fs.existsSync(this.chainFile)) {
|
||||
this.logger.info(this.chainFile + ' ' + __('file not found, creating it...'));
|
||||
fs.outputJSONSync(this.chainFile, {});
|
||||
this.fs.outputJSONSync(this.chainFile, {});
|
||||
}
|
||||
|
||||
this.chainConfig = fs.readJSONSync(this.chainFile);
|
||||
this.chainConfig = this.fs.readJSONSync(this.chainFile);
|
||||
}
|
||||
|
||||
registerEvents() {
|
||||
@ -105,7 +105,7 @@ class DeployTracker {
|
||||
if (this.chainConfig === false) {
|
||||
return;
|
||||
}
|
||||
fs.writeJSONSync(this.chainFile, this.chainConfig, {spaces: 2});
|
||||
this.fs.writeJSONSync(this.chainFile, this.chainConfig, {spaces: 2});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
const fs = require('../../core/fs.js');
|
||||
const utils = require('../../utils/utils.js');
|
||||
const namehash = require('eth-ens-namehash');
|
||||
const async = require('async');
|
||||
@ -62,6 +61,7 @@ class ENS {
|
||||
this.env = embark.env;
|
||||
this.logger = embark.logger;
|
||||
this.events = embark.events;
|
||||
this.fs = embark.fs;
|
||||
this.namesConfig = embark.config.namesystemConfig;
|
||||
this.enabled = false;
|
||||
this.registration = this.namesConfig.register || {};
|
||||
@ -373,13 +373,13 @@ class ENS {
|
||||
let currentEnsNamehashVersion = require('../../../../package.json').dependencies["eth-ens-namehash"];
|
||||
if (EnsNamehashVersion !== currentEnsNamehashVersion) {
|
||||
self.events.request("version:getPackageLocation", "eth-ens-namehash", EnsNamehashVersion, function (err, location) {
|
||||
self.embark.registerImportFile("eth-ens-namehash", fs.dappPath(location));
|
||||
self.embark.registerImportFile("eth-ens-namehash", self.fs.dappPath(location));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
let code = fs.readFileSync(utils.joinPath(__dirname, 'ENSFunctions.js')).toString();
|
||||
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString();
|
||||
let code = self.fs.readFileSync(utils.joinPath(__dirname, 'ENSFunctions.js')).toString();
|
||||
code += "\n" + self.fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString();
|
||||
code += "\nEmbarkJS.Names.registerProvider('ens', __embarkENS);";
|
||||
|
||||
this.embark.addCodeToEmbarkJS(code);
|
||||
|
@ -1,6 +1,5 @@
|
||||
const UploadIPFS = require('./upload.js');
|
||||
const utils = require('../../utils/utils.js');
|
||||
const fs = require('../../core/fs.js');
|
||||
const IpfsApi = require('ipfs-api');
|
||||
// TODO: not great, breaks module isolation
|
||||
const StorageProcessesLauncher = require('../storage/storageProcessesLauncher');
|
||||
@ -15,6 +14,7 @@ class IPFS {
|
||||
this.storageConfig = embark.config.storageConfig;
|
||||
this.namesystemConfig = embark.config.namesystemConfig;
|
||||
this.embark = embark;
|
||||
this.fs = embark.fs;
|
||||
|
||||
this.webServerConfig = embark.config.webServerConfig;
|
||||
this.blockchainConfig = embark.config.blockchainConfig;
|
||||
@ -49,7 +49,7 @@ class IPFS {
|
||||
let currentIpfsApiVersion = require('../../../../package.json').dependencies["ipfs-api"];
|
||||
if (ipfsApiVersion !== currentIpfsApiVersion) {
|
||||
self.events.request("version:getPackageLocation", "ipfs-api", ipfsApiVersion, function(err, location) {
|
||||
self.embark.registerImportFile("ipfs-api", fs.dappPath(location));
|
||||
self.embark.registerImportFile("ipfs-api", self.fs.dappPath(location));
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -101,7 +101,7 @@ class IPFS {
|
||||
|
||||
addStorageProviderToEmbarkJS() {
|
||||
let code = "";
|
||||
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString();
|
||||
code += "\n" + this.fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString();
|
||||
code += "\nEmbarkJS.Storage.registerProvider('ipfs', __embarkIPFS);";
|
||||
|
||||
this.embark.addCodeToEmbarkJS(code);
|
||||
|
@ -1,4 +1,3 @@
|
||||
const fs = require('../../core/fs.js');
|
||||
const path = require('path');
|
||||
const async = require('async');
|
||||
const utils = require('../../utils/utils.js');
|
||||
@ -18,6 +17,7 @@ class Pipeline {
|
||||
this.events = embark.events;
|
||||
this.logger = embark.config.logger;
|
||||
this.plugins = embark.config.plugins;
|
||||
this.fs = embark.fs;
|
||||
this.webpackConfigName = options.webpackConfigName;
|
||||
this.pipelinePlugins = this.plugins.getPluginsFor('pipeline');
|
||||
this.pipelineConfig = embark.config.pipelineConfig;
|
||||
@ -26,7 +26,7 @@ class Pipeline {
|
||||
|
||||
this.events.setCommandHandler('pipeline:build', (options, callback) => this.build(options, callback));
|
||||
this.events.setCommandHandler('pipeline:build:contracts', callback => this.buildContracts(callback));
|
||||
fs.removeSync(this.buildDir);
|
||||
this.fs.removeSync(this.buildDir);
|
||||
|
||||
let plugin = this.plugins.createPlugin('deployment', {});
|
||||
plugin.registerAPICall(
|
||||
@ -40,7 +40,7 @@ class Pipeline {
|
||||
}
|
||||
|
||||
const name = path.basename(req.query.path);
|
||||
const content = fs.readFileSync(req.query.path, 'utf8');
|
||||
const content = this.fs.readFileSync(req.query.path, 'utf8');
|
||||
res.send({name, content, path: req.query.path});
|
||||
|
||||
}
|
||||
@ -56,7 +56,7 @@ class Pipeline {
|
||||
return res.send({error: error.message});
|
||||
}
|
||||
|
||||
fs.mkdirpSync(req.body.path);
|
||||
this.fs.mkdirpSync(req.body.path);
|
||||
const name = path.basename(req.body.path);
|
||||
res.send({name, path: req.body.path});
|
||||
}
|
||||
@ -72,7 +72,7 @@ class Pipeline {
|
||||
return res.send({error: error.message});
|
||||
}
|
||||
|
||||
fs.writeFileSync(req.body.path, req.body.content, {encoding: 'utf8'});
|
||||
this.fs.writeFileSync(req.body.path, req.body.content, {encoding: 'utf8'});
|
||||
const name = path.basename(req.body.path);
|
||||
res.send({name, path: req.body.path, content: req.body.content});
|
||||
}
|
||||
@ -87,7 +87,7 @@ class Pipeline {
|
||||
} catch (error) {
|
||||
return res.send({error: error.message});
|
||||
}
|
||||
fs.removeSync(req.query.path);
|
||||
this.fs.removeSync(req.query.path);
|
||||
res.send();
|
||||
}
|
||||
);
|
||||
@ -96,11 +96,11 @@ class Pipeline {
|
||||
'get',
|
||||
'/embark-api/files',
|
||||
(req, res) => {
|
||||
const rootPath = fs.dappPath();
|
||||
const rootPath = this.fs.dappPath();
|
||||
|
||||
const walk = (dir, filelist = []) => fs.readdirSync(dir).map(name => {
|
||||
const walk = (dir, filelist = []) => this.fs.readdirSync(dir).map(name => {
|
||||
let isRoot = rootPath === dir;
|
||||
if (fs.statSync(path.join(dir, name)).isDirectory()) {
|
||||
if (this.fs.statSync(path.join(dir, name)).isDirectory()) {
|
||||
return {
|
||||
isRoot,
|
||||
name,
|
||||
@ -118,7 +118,7 @@ class Pipeline {
|
||||
isHidden: name.indexOf('.') === 0
|
||||
};
|
||||
});
|
||||
const files = utils.fileTreeSort(walk(fs.dappPath()));
|
||||
const files = utils.fileTreeSort(walk(this.fs.dappPath()));
|
||||
res.send(files);
|
||||
}
|
||||
);
|
||||
@ -127,10 +127,10 @@ class Pipeline {
|
||||
apiGuardBadFile(pathToCheck, options = {ensureExists: false}) {
|
||||
const dir = path.dirname(pathToCheck);
|
||||
const error = new Error('Path is invalid');
|
||||
if (options.ensureExists && !fs.existsSync(pathToCheck)) {
|
||||
if (options.ensureExists && !this.fs.existsSync(pathToCheck)) {
|
||||
throw error;
|
||||
}
|
||||
if (!dir.startsWith(fs.dappPath())) {
|
||||
if (!dir.startsWith(this.fs.dappPath())) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@ -139,7 +139,7 @@ class Pipeline {
|
||||
let self = this;
|
||||
const importsList = {};
|
||||
let placeholderPage;
|
||||
const contractsDir = fs.dappPath(self.embarkConfig.generationDir, constants.dappConfig.contractsJs);
|
||||
const contractsDir = this.fs.dappPath(self.embarkConfig.generationDir, constants.dappConfig.contractsJs);
|
||||
|
||||
if (!self.assetFiles || !Object.keys(self.assetFiles).length) {
|
||||
return self.buildContracts(callback);
|
||||
@ -156,8 +156,8 @@ class Pipeline {
|
||||
(next) => self.buildContracts(next),
|
||||
(next) => self.buildWeb3JS(next),
|
||||
function createImportList(next) {
|
||||
importsList["Embark/EmbarkJS"] = fs.dappPath(self.embarkConfig.generationDir, constants.dappConfig.embarkjs);
|
||||
importsList["Embark/web3"] = fs.dappPath(".embark", 'web3_instance.js');
|
||||
importsList["Embark/EmbarkJS"] = self.fs.dappPath(self.embarkConfig.generationDir, constants.dappConfig.embarkjs);
|
||||
importsList["Embark/web3"] = self.fs.dappPath(".embark", 'web3_instance.js');
|
||||
importsList["Embark/contracts"] = contractsDir;
|
||||
|
||||
self.plugins.getPluginsProperty('imports', 'imports').forEach(importObject => {
|
||||
@ -168,14 +168,14 @@ class Pipeline {
|
||||
},
|
||||
function writeContracts(next) {
|
||||
self.events.request('contracts:list', (_err, contracts) => {
|
||||
fs.mkdirp(contractsDir, err => {
|
||||
self.fs.mkdirp(contractsDir, err => {
|
||||
if (err) return next(err);
|
||||
|
||||
// Create a file index.js that requires all contract files
|
||||
// Used to enable alternate import syntax:
|
||||
// e.g. import {Token} from 'Embark/contracts'
|
||||
// e.g. import * as Contracts from 'Embark/contracts'
|
||||
let importsHelperFile = fs.createWriteStream(utils.joinPath(contractsDir, 'index.js'));
|
||||
let importsHelperFile = self.fs.createWriteStream(utils.joinPath(contractsDir, 'index.js'));
|
||||
importsHelperFile.write('module.exports = {\n');
|
||||
|
||||
async.eachOf(contracts, (contract, idx, eachCb) => {
|
||||
@ -302,7 +302,7 @@ class Pipeline {
|
||||
}
|
||||
let dir = targetFile.split('/').slice(0, -1).join('/');
|
||||
self.logger.trace(`${'Pipeline:'.cyan} creating dir ` + utils.joinPath(self.buildDir, dir));
|
||||
fs.mkdirpSync(utils.joinPath(self.buildDir, dir));
|
||||
self.fs.mkdirpSync(utils.joinPath(self.buildDir, dir));
|
||||
|
||||
// if it's a directory
|
||||
if (isDir) {
|
||||
@ -316,7 +316,7 @@ class Pipeline {
|
||||
let filename = file.path.replace(file.basedir + '/', '');
|
||||
self.logger.info(`${'Pipeline:'.cyan} writing file ` + (utils.joinPath(self.buildDir, targetDir, filename)).bold.dim);
|
||||
|
||||
fs.copy(file.path, utils.joinPath(self.buildDir, targetDir, filename), {overwrite: true}, eachCb);
|
||||
self.fs.copy(file.path, utils.joinPath(self.buildDir, targetDir, filename), {overwrite: true}, eachCb);
|
||||
}, cb);
|
||||
return;
|
||||
}
|
||||
@ -332,7 +332,7 @@ class Pipeline {
|
||||
targetFile = targetFile.replace('index', 'index-temp');
|
||||
placeholderPage = targetFile;
|
||||
}
|
||||
fs.writeFile(utils.joinPath(self.buildDir, targetFile), content, cb);
|
||||
self.fs.writeFile(utils.joinPath(self.buildDir, targetFile), content, cb);
|
||||
}
|
||||
);
|
||||
},
|
||||
@ -341,12 +341,12 @@ class Pipeline {
|
||||
},
|
||||
function removePlaceholderPage(next) {
|
||||
let placeholderFile = utils.joinPath(self.buildDir, placeholderPage);
|
||||
fs.access(utils.joinPath(self.buildDir, placeholderPage), (err) => {
|
||||
self.fs.access(utils.joinPath(self.buildDir, placeholderPage), (err) => {
|
||||
if (err) return next(); // index-temp doesn't exist, do nothing
|
||||
|
||||
// rename index-temp.htm/l to index.htm/l, effectively replacing our placeholder page
|
||||
// with the contents of the built index.html page
|
||||
fs.move(placeholderFile, placeholderFile.replace('index-temp', 'index'), {overwrite: true}, next);
|
||||
self.fs.move(placeholderFile, placeholderFile.replace('index-temp', 'index'), {overwrite: true}, next);
|
||||
});
|
||||
}
|
||||
], callback);
|
||||
@ -356,14 +356,14 @@ class Pipeline {
|
||||
const self = this;
|
||||
async.waterfall([
|
||||
function makeDirectory(next) {
|
||||
fs.mkdirp(fs.dappPath(self.buildDir, 'contracts'), err => next(err));
|
||||
self.fs.mkdirp(self.fs.dappPath(self.buildDir, 'contracts'), err => next(err));
|
||||
},
|
||||
function getContracts(next) {
|
||||
self.events.request('contracts:list', next);
|
||||
},
|
||||
function writeContractsJSON(contracts, next) {
|
||||
async.each(contracts, (contract, eachCb) => {
|
||||
fs.writeJson(fs.dappPath(
|
||||
self.fs.writeJson(self.fs.dappPath(
|
||||
self.buildDir,
|
||||
'contracts', contract.className + '.json'
|
||||
), contract, {spaces: 2}, eachCb);
|
||||
@ -376,13 +376,13 @@ class Pipeline {
|
||||
const self = this;
|
||||
async.waterfall([
|
||||
function makeDirectory(next) {
|
||||
fs.mkdirp(fs.dappPath(".embark"), err => next(err));
|
||||
self.fs.mkdirp(self.fs.dappPath(".embark"), err => next(err));
|
||||
},
|
||||
function getWeb3Code(next) {
|
||||
self.events.request('code-generator:web3js', next);
|
||||
},
|
||||
function writeFile(code, next) {
|
||||
fs.writeFile(fs.dappPath(".embark", 'web3_instance.js'), code, next);
|
||||
self.fs.writeFile(self.fs.dappPath(".embark", 'web3_instance.js'), code, next);
|
||||
}
|
||||
], cb);
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
const fs = require('./../../core/fs.js');
|
||||
const utils = require('./../../utils/utils.js');
|
||||
const async = require('async');
|
||||
|
||||
class PluginCommand {
|
||||
constructor(embark) {
|
||||
this.embark = embark;
|
||||
this.fs = embark.fs;
|
||||
this.config = this.embark.pluginConfig;
|
||||
this.embarkConfig = this.config.embarkConfig;
|
||||
this.registerCommand();
|
||||
@ -50,11 +50,11 @@ class PluginCommand {
|
||||
},
|
||||
function addToEmbarkConfig(cb) {
|
||||
// get the installed package from package.json
|
||||
let packageFile = fs.readJSONSync(self.config.packageFile);
|
||||
let packageFile = self.fs.readJSONSync(self.config.packageFile);
|
||||
let dependencies = Object.keys(packageFile.dependencies);
|
||||
let installedPackage = dependencies.filter((dep) => npmPackage.indexOf(dep) >= 0);
|
||||
self.embarkConfig.plugins[installedPackage[0]] = {};
|
||||
fs.writeFile(self.config.embarkConfigFile, JSON.stringify(self.embarkConfig, null, 2), cb);
|
||||
self.fs.writeFile(self.config.embarkConfigFile, JSON.stringify(self.embarkConfig, null, 2), cb);
|
||||
}
|
||||
], (err) => {
|
||||
if (err) {
|
||||
|
@ -6,7 +6,6 @@ import { Builder } from "../../builder";
|
||||
import { CommandOptions } from "../../commandOptions";
|
||||
import { SmartContractsRecipe } from "../../smartContractsRecipe";
|
||||
|
||||
const fs = require("../../../../core/fs");
|
||||
require("../../handlebarHelpers");
|
||||
|
||||
const templatePath = path.join(__dirname, "templates", "contract.sol.hbs");
|
||||
@ -27,7 +26,7 @@ export class SolidityBuilder implements Builder {
|
||||
}
|
||||
|
||||
private generateCode(contractName: string) {
|
||||
const source = fs.readFileSync(templatePath, "utf-8");
|
||||
const source = this.embark.fs.readFileSync(templatePath, "utf-8");
|
||||
const template = Handlebars.compile(source);
|
||||
|
||||
const attributes = this.description.standardAttributes(contractName);
|
||||
@ -49,13 +48,13 @@ export class SolidityBuilder implements Builder {
|
||||
const filename = `${contractName}.sol`;
|
||||
const contractDirs = this.embark.config.embarkConfig.contracts;
|
||||
const contractDir = Array.isArray(contractDirs) ? contractDirs[0] : contractDirs;
|
||||
const filePath = fs.dappPath(contractDir.replace(/\*/g, ""), filename);
|
||||
if (!this.options.overwrite && fs.existsSync(filePath)) {
|
||||
const filePath = this.embark.fs.dappPath(contractDir.replace(/\*/g, ""), filename);
|
||||
if (!this.options.overwrite && this.embark.fs.existsSync(filePath)) {
|
||||
this.embark.logger.error(__(`The contract ${contractName} already exists, skipping.`));
|
||||
return;
|
||||
}
|
||||
|
||||
fs.writeFileSync(filePath, code);
|
||||
this.embark.fs.writeFileSync(filePath, code);
|
||||
return filePath;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ import { Builder } from "../../builder";
|
||||
import { CommandOptions } from "../../commandOptions";
|
||||
import { SmartContractsRecipe } from "../../smartContractsRecipe";
|
||||
|
||||
const fs = require("../../../../core/fs");
|
||||
const utils = require("../../../../utils/utils");
|
||||
require("../../handlebarHelpers");
|
||||
|
||||
@ -46,17 +45,17 @@ export class ReactBuilder implements Builder {
|
||||
}
|
||||
|
||||
private updateEmbarkJson(contractName: string, files: string[]) {
|
||||
const embarkJsonPath = path.join(fs.dappPath(), "embark.json");
|
||||
const embarkJson = fs.readJSONSync(embarkJsonPath);
|
||||
const embarkJsonPath = path.join(this.embark.fs.dappPath(), "embark.json");
|
||||
const embarkJson = this.embark.fs.readJSONSync(embarkJsonPath);
|
||||
embarkJson.app[`js/${contractName}.js`] = `app/${contractName}.js`;
|
||||
embarkJson.app[`${contractName}.html`] = `app/${contractName}.html`;
|
||||
|
||||
fs.writeFileSync(embarkJsonPath, JSON.stringify(embarkJson, null, 2));
|
||||
this.embark.fs.writeFileSync(embarkJsonPath, JSON.stringify(embarkJson, null, 2));
|
||||
}
|
||||
|
||||
private generateCodes(contractName: string) {
|
||||
const indexSource = fs.readFileSync(indexTemplatePath, "utf-8");
|
||||
const dappSource = fs.readFileSync(dappTemplatePath, "utf-8");
|
||||
const indexSource = this.embark.fs.readFileSync(indexTemplatePath, "utf-8");
|
||||
const dappSource = this.embark.fs.readFileSync(dappTemplatePath, "utf-8");
|
||||
|
||||
const indexTemplate = Handlebars.compile(indexSource);
|
||||
const dappTemplate = Handlebars.compile(dappSource);
|
||||
@ -129,15 +128,15 @@ export class ReactBuilder implements Builder {
|
||||
}
|
||||
|
||||
private saveFiles(contractName: string, indexCode: string, dappCode: string) {
|
||||
const indexFilePath = path.join(fs.dappPath(), "app", `${contractName}.html`);
|
||||
const dappFilePath = path.join(fs.dappPath(), "app", `${contractName}.js`);
|
||||
const indexFilePath = path.join(this.embark.fs.dappPath(), "app", `${contractName}.html`);
|
||||
const dappFilePath = path.join(this.embark.fs.dappPath(), "app", `${contractName}.js`);
|
||||
|
||||
if (!this.options.overwrite && (fs.existsSync(indexFilePath) || fs.existsSync(dappFilePath))) {
|
||||
if (!this.options.overwrite && (this.embark.fs.existsSync(indexFilePath) || this.embark.fs.existsSync(dappFilePath))) {
|
||||
return [];
|
||||
}
|
||||
|
||||
fs.writeFileSync(indexFilePath, indexCode);
|
||||
fs.writeFileSync(dappFilePath, dappCode);
|
||||
this.embark.fs.writeFileSync(indexFilePath, indexCode);
|
||||
this.embark.fs.writeFileSync(dappFilePath, dappCode);
|
||||
|
||||
this.embark.logger.info(__(`${indexFilePath} generated`));
|
||||
this.embark.logger.info(__(`${dappFilePath} generated`));
|
||||
|
@ -1,5 +1,4 @@
|
||||
let utils = require('../../utils/utils.js');
|
||||
let fs = require('../../core/fs.js');
|
||||
let currentSolcVersion = require('../../../../package.json').dependencies.solc;
|
||||
const ProcessLauncher = require('../../core/processes/processLauncher.js');
|
||||
const uuid = require('uuid/v1');
|
||||
@ -59,7 +58,7 @@ class SolcW {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
let requirePath = fs.dappPath(path);
|
||||
let requirePath = self.embark.fs.dappPath(path);
|
||||
self.solcProcess.send({action: 'installAndLoadCompiler', solcVersion: solcVersion, packagePath: requirePath});
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,3 @@
|
||||
const fs = require('../../core/fs');
|
||||
const shellJs = require('shelljs');
|
||||
const utils = require('../../utils/utils');
|
||||
const ProcessLauncher = require('../../core/processes/processLauncher');
|
||||
@ -97,7 +96,7 @@ class StorageProcessesLauncher {
|
||||
return callback(__('Storage process already started'));
|
||||
}
|
||||
const filePath = utils.joinPath(__dirname, `../${storageName}/process.js`);
|
||||
fs.access(filePath, (err) => {
|
||||
this.embark.fs.access(filePath, (err) => {
|
||||
if (err) {
|
||||
return callback(__('No process file for this storage type (%s) exists. Please start the process locally.', storageName));
|
||||
}
|
||||
@ -138,7 +137,7 @@ class StorageProcessesLauncher {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
self.processes[storageName].on('result', constants.storage.initiated, (msg) => {
|
||||
if (msg.error) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
const UploadSwarm = require('./upload.js');
|
||||
const utils = require('../../utils/utils.js');
|
||||
const fs = require('../../core/fs.js');
|
||||
const SwarmAPI = require('swarm-api');
|
||||
// TODO: not great, breaks module isolation
|
||||
const StorageProcessesLauncher = require('../storage/storageProcessesLauncher');
|
||||
@ -17,6 +16,7 @@ class Swarm {
|
||||
this.host = this.storageConfig.host;
|
||||
this.port = this.storageConfig.port;
|
||||
this.embark = embark;
|
||||
this.fs = embark.fs;
|
||||
|
||||
this.webServerConfig = embark.config.webServerConfig;
|
||||
this.blockchainConfig = embark.config.blockchainConfig;
|
||||
@ -99,7 +99,7 @@ class Swarm {
|
||||
|
||||
addProviderToEmbarkJS() {
|
||||
let code = "";
|
||||
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString();
|
||||
code += "\n" + this.fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString();
|
||||
code += "\nEmbarkJS.Storage.registerProvider('swarm', __embarkSwarm);";
|
||||
|
||||
this.embark.addCodeToEmbarkJS(code);
|
||||
|
@ -2,7 +2,6 @@ const async = require('async');
|
||||
const Mocha = require('mocha');
|
||||
const path = require('path');
|
||||
const {runCmd} = require('../../utils/utils');
|
||||
const fs = require('../../core/fs');
|
||||
const assert = require('assert');
|
||||
const Test = require('./test');
|
||||
const {EmbarkSpec, EmbarkApiSpec} = require('./reporter');
|
||||
@ -14,6 +13,7 @@ class TestRunner {
|
||||
this.embark = embark;
|
||||
this.logger = embark.logger;
|
||||
this.events = embark.events;
|
||||
this.fs = embark.fs;
|
||||
this.ipc = options.ipc;
|
||||
this.runResults = [];
|
||||
|
||||
@ -84,18 +84,18 @@ class TestRunner {
|
||||
}
|
||||
|
||||
global.embark.events.emit('tests:finished', function() {
|
||||
runCmd(`${fs.embarkPath('node_modules/.bin/istanbul')} report --root .embark --format html`,
|
||||
runCmd(`${self.fs.embarkPath('node_modules/.bin/istanbul')} report --root .embark --format html`,
|
||||
{silent: false, exitOnError: false}, (err) => {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
console.info(`Coverage report created. You can find it here: ${fs.dappPath('coverage/index.html')}\n`);
|
||||
console.info(`Coverage report created. You can find it here: ${self.fs.dappPath('coverage/index.html')}\n`);
|
||||
const opn = require('opn');
|
||||
const _next = () => { next(null, results); };
|
||||
if (options.noBrowser) {
|
||||
return next(null, results);
|
||||
}
|
||||
opn(fs.dappPath('coverage/index.html'), {wait: false})
|
||||
opn(self.fs.dappPath('coverage/index.html'), {wait: false})
|
||||
.then(() => new Promise(resolve => setTimeout(resolve, 1000)))
|
||||
.then(_next, _next);
|
||||
});
|
||||
@ -118,14 +118,14 @@ class TestRunner {
|
||||
getFilesFromDir(filePath, cb) {
|
||||
const self = this;
|
||||
|
||||
fs.stat(filePath, (err, fileStat) => {
|
||||
self.fs.stat(filePath, (err, fileStat) => {
|
||||
const errorMessage = `File "${filePath}" doesn't exist or you don't have permission to it`.red;
|
||||
if (err) {
|
||||
return cb(errorMessage);
|
||||
}
|
||||
let isDirectory = fileStat.isDirectory();
|
||||
if (isDirectory) {
|
||||
return fs.readdir(filePath, (err, files) => {
|
||||
return self.fs.readdir(filePath, (err, files) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
@ -217,7 +217,7 @@ class TestRunner {
|
||||
return cb(err);
|
||||
}
|
||||
let failures = runs.reduce((acc, val) => acc + val, 0);
|
||||
fs.remove('.embark/contracts', (_err) => {
|
||||
self.fs.remove('.embark/contracts', (_err) => {
|
||||
cb(null, {failures});
|
||||
});
|
||||
});
|
||||
|
@ -1,8 +1,6 @@
|
||||
let chokidar = require('chokidar');
|
||||
let path = require('path');
|
||||
|
||||
let fs = require('../../core/fs.js');
|
||||
|
||||
const DAPP_PIPELINE_CONFIG_FILE = 'pipeline.js';
|
||||
const DAPP_WEBPACK_CONFIG_FILE = 'webpack.config.js';
|
||||
const DAPP_BABEL_LOADER_OVERRIDES_CONFIG_FILE = 'babel-loader-overrides.js';
|
||||
@ -13,6 +11,7 @@ class Watcher {
|
||||
constructor(embark) {
|
||||
this.logger = embark.logger;
|
||||
this.events = embark.events;
|
||||
this.fs = embark.fs;
|
||||
this.fileWatchers = [];
|
||||
|
||||
this.events.setCommandHandler('watcher:start', () => this.start());
|
||||
@ -24,7 +23,7 @@ class Watcher {
|
||||
let self = this;
|
||||
// TODO: should come from the config object instead of reading the file
|
||||
// directly
|
||||
let embarkConfig = fs.readJSONSync("embark.json");
|
||||
let embarkConfig = this.fs.readJSONSync("embark.json");
|
||||
|
||||
this.watchAssets(embarkConfig, function () {
|
||||
self.logger.trace('ready to watch asset changes');
|
||||
@ -164,14 +163,14 @@ class Watcher {
|
||||
|
||||
watchPipelineConfig(embarkConfig, callback) {
|
||||
let filesToWatch = [
|
||||
fs.dappPath('', DAPP_WEBPACK_CONFIG_FILE),
|
||||
fs.dappPath('', DAPP_BABEL_LOADER_OVERRIDES_CONFIG_FILE)
|
||||
this.fs.dappPath('', DAPP_WEBPACK_CONFIG_FILE),
|
||||
this.fs.dappPath('', DAPP_BABEL_LOADER_OVERRIDES_CONFIG_FILE)
|
||||
];
|
||||
|
||||
if (typeof embarkConfig.config === 'object' && embarkConfig.config.pipeline) {
|
||||
filesToWatch.push(embarkConfig.config.pipeline);
|
||||
} else if (typeof embarkConfig.config === 'string') {
|
||||
filesToWatch.push(fs.dappPath(embarkConfig.config, DAPP_PIPELINE_CONFIG_FILE));
|
||||
filesToWatch.push(this.fs.dappPath(embarkConfig.config, DAPP_PIPELINE_CONFIG_FILE));
|
||||
}
|
||||
|
||||
this.watchFiles(filesToWatch, (eventName, path) => {
|
||||
|
@ -1,12 +1,10 @@
|
||||
import {findNextPort} from "../../utils/network";
|
||||
|
||||
const fs = require('../../core/fs.js');
|
||||
var {canonicalHost} = require('../../utils/host.js');
|
||||
var utils = require('../../utils/utils.js');
|
||||
var Server = require('./server.js');
|
||||
const opn = require('opn');
|
||||
|
||||
|
||||
require('ejs');
|
||||
const Templates = {
|
||||
embark_building_placeholder: require('./templates/embark-building-placeholder.html.ejs')
|
||||
@ -17,6 +15,7 @@ class WebServer {
|
||||
this.embark = embark;
|
||||
this.logger = embark.logger;
|
||||
this.events = embark.events;
|
||||
this.fs = embark.fs;
|
||||
this.buildDir = embark.config.buildDir;
|
||||
this.webServerConfig = embark.config.webServerConfig;
|
||||
if (!this.webServerConfig.enabled) {
|
||||
@ -151,8 +150,8 @@ class WebServer {
|
||||
|
||||
buildPlaceholderPage(cb) {
|
||||
let html = Templates.embark_building_placeholder({buildingMsg: __('Embark is building, please wait...')});
|
||||
fs.mkdirpSync(this.buildDir); // create buildDir if it does not exist
|
||||
fs.writeFile(utils.joinPath(this.buildDir, 'index.html'), html, cb);
|
||||
this.fs.mkdirpSync(this.buildDir); // create buildDir if it does not exist
|
||||
this.fs.writeFile(utils.joinPath(this.buildDir, 'index.html'), html, cb);
|
||||
}
|
||||
|
||||
openBrowser(cb) {
|
||||
|
@ -1,5 +1,4 @@
|
||||
let utils = require('../../utils/utils.js');
|
||||
let fs = require('../../core/fs.js');
|
||||
let Web3 = require('web3');
|
||||
const {parallel} = require('async');
|
||||
const {sendMessage, listenTo} = require('./js/communicationFunctions');
|
||||
@ -13,6 +12,7 @@ class Whisper {
|
||||
constructor(embark, options) {
|
||||
this.logger = embark.logger;
|
||||
this.events = embark.events;
|
||||
this.fs = embark.fs;
|
||||
this.communicationConfig = embark.config.communicationConfig;
|
||||
this.web3 = new Web3();
|
||||
this.embark = embark;
|
||||
@ -119,15 +119,15 @@ class Whisper {
|
||||
// TODO: possible race condition could be a concern
|
||||
this.events.request("version:get:web3", function(web3Version) {
|
||||
let code = "";
|
||||
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'message_events.js')).toString();
|
||||
code += "\n" + self.fs.readFileSync(utils.joinPath(__dirname, 'js', 'message_events.js')).toString();
|
||||
|
||||
if (web3Version[0] === "0") {
|
||||
self.isOldWeb3 = true;
|
||||
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'embarkjs_old_web3.js')).toString();
|
||||
code += "\n" + self.fs.readFileSync(utils.joinPath(__dirname, 'js', 'embarkjs_old_web3.js')).toString();
|
||||
code += "\nEmbarkJS.Messages.registerProvider('whisper', __embarkWhisperOld);";
|
||||
} else {
|
||||
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'communicationFunctions.js')).toString();
|
||||
code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'js', 'embarkjs.js')).toString();
|
||||
code += "\n" + self.fs.readFileSync(utils.joinPath(__dirname, 'js', 'communicationFunctions.js')).toString();
|
||||
code += "\n" + self.fs.readFileSync(utils.joinPath(__dirname, 'js', 'embarkjs.js')).toString();
|
||||
code += "\nEmbarkJS.Messages.registerProvider('whisper', __embarkWhisperNewWeb3);";
|
||||
}
|
||||
self.embark.addCodeToEmbarkJS(code);
|
||||
|
@ -13,6 +13,10 @@ describe('embark.Console', function() {
|
||||
registerAPICall: () => {},
|
||||
events: events,
|
||||
logger: plugins.logger,
|
||||
fs: {
|
||||
existsSync: () => { return false },
|
||||
dappPath: () => { return "ok" }
|
||||
},
|
||||
registerConsoleCommand: (cmd, opt) => {},
|
||||
embarkConfig: {
|
||||
options: {
|
||||
|
@ -51,6 +51,10 @@ describe('embark.Contracts', function() {
|
||||
let embarkObject = {
|
||||
registerAPICall: () => {},
|
||||
events: events,
|
||||
fs: {
|
||||
existsSync: () => { return false },
|
||||
dappPath: () => { return "ok" }
|
||||
},
|
||||
logger: plugins.logger,
|
||||
embarkConfig: {
|
||||
options: {
|
||||
@ -111,6 +115,10 @@ describe('embark.Contracts', function() {
|
||||
|
||||
let embarkObj = {
|
||||
registerAPICall: () => {},
|
||||
fs: {
|
||||
existsSync: () => { return false },
|
||||
dappPath: () => { return "ok" }
|
||||
},
|
||||
logger: new Logger({}),
|
||||
events: events
|
||||
};
|
||||
@ -238,6 +246,10 @@ describe('embark.Contracts', function() {
|
||||
|
||||
let embarkObj = {
|
||||
registerAPICall: () => {},
|
||||
fs: {
|
||||
existsSync: () => { return false },
|
||||
dappPath: () => { return "ok" }
|
||||
},
|
||||
logger: new Logger({}),
|
||||
events: events
|
||||
};
|
||||
|
@ -98,6 +98,10 @@ function resetTest() {
|
||||
embark = {
|
||||
events,
|
||||
logger,
|
||||
fs: {
|
||||
existsSync: () => { return false },
|
||||
dappPath: () => { return "ok" }
|
||||
},
|
||||
config: {
|
||||
contractsConfig: {}
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user