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