Skip to content

Commit

Permalink
feat: remove optional plugins from coming as default
Browse files Browse the repository at this point in the history
feat(@embark/utils): add method to verify if a plugin is installed & configured

feature(@embark/utils): add method to verify if a plugin is installed & configured

feature: warn about packages that will be independent plugins and are not configured

chore: update templates to specify plugins

refactor: add to plugin api params so that blockchain plugins no longer need to be passed options

address changes in code review

remove unneded space

Update packages/core/utils/src/index.ts

Co-Authored-By: Jonathan Rainville <rainville.jonathan@gmail.com>

Update packages/core/utils/src/index.ts

Co-Authored-By: Michael Bradley <michaelsbradleyjr@gmail.com>

fix linting issue

add missing import

remove optional plugins from coming as default

Revert "chore: update hooks examples to destructure dependencies object"

This reverts commit 448eab7.

remove trailing comma

fix linting issue

include tsconfig
  • Loading branch information
iurimatias committed Feb 28, 2020
1 parent 1675019 commit db10064
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 93 deletions.
5 changes: 1 addition & 4 deletions dapps/templates/simple/embark.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
"solc": "0.6.1"
},
"plugins": {
"embark-geth": {},
"embark-parity": {},
"embark-profiler": {},
"embark-graph": {}
"embark-geth": {}
},
"options": {
"solc": {
Expand Down
5 changes: 1 addition & 4 deletions dapps/templates/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@
},
"devDependencies": {
"embark": "^5.3.0-nightly.0",
"embark-geth": "^5.3.0-nightly.0",
"embark-graph": "^5.3.0-nightly.0",
"embark-parity": "^5.3.0-nightly.0",
"embark-profiler": "^5.3.0-nightly.0",
"embark-reset": "^5.2.3",
"embarkjs": "^5.2.3",
"embarkjs-ens": "^5.2.3",
"embarkjs-web3": "^5.2.3",
"embark-geth": "^5.3.0-nightly.0",
"rimraf": "3.0.0"
}
}
5 changes: 4 additions & 1 deletion packages/core/console/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import chalk from "chalk";
import { Embark, EmbarkEvents } from "embark-core";
import constants from "embark-core/constants.json";
import { __ } from "embark-i18n";
import { dappPath, escapeHtml, exit, jsonFunctionReplacer } from "embark-utils";
import { dappPath, escapeHtml, exit, jsonFunctionReplacer, warnIfPackageNotDefinedLocally } from "embark-utils";
import stringify from "json-stringify-safe";
import { dirname } from "path";
import util from "util";
Expand Down Expand Up @@ -169,6 +169,9 @@ export default class Console {
return this.ipc.request("console:executeCmd", cmd, callback);
}

if (cmd.indexOf("profile") === 0 && warnIfPackageNotDefinedLocally("embark-profiler", this.embark.logger.warn) !== true) {
return callback(null, "please install embark-profiler plugin");
}
if (!(cmd.split(" ")[0] === "history" || cmd === __("history"))) {
this.saveHistory(cmd);
}
Expand Down
8 changes: 1 addition & 7 deletions packages/core/engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,28 @@
"embark-ethereum-blockchain-client": "^5.3.0-nightly.0",
"embark-ganache": "^5.3.0-nightly.0",
"embark-geth": "^5.3.0-nightly.0",
"embark-ipfs": "^5.3.0-nightly.0",
"embark-library-manager": "^5.3.0-nightly.0",
"embark-logger": "^5.3.0-nightly.0",
"embark-mocha-tests": "^5.3.0-nightly.0",
"embark-namesystem": "^5.3.0-nightly.0",
"embark-parity": "^5.3.0-nightly.0",
"embark-pipeline": "^5.3.0-nightly.0",
"embark-plugin-cmd": "^5.3.0-nightly.0",
"embark-process-logs-api-manager": "^5.3.0-nightly.0",
"embark-profiler": "^5.3.0-nightly.0",
"embark-proxy": "^5.3.0-nightly.0",
"embark-rpc-manager": "^5.3.0-nightly.0",
"embark-scaffolding": "^5.3.0-nightly.0",
"embark-solidity": "^5.3.0-nightly.0",
"embark-solidity-tests": "^5.3.0-nightly.0",
"embark-specialconfigs": "^5.3.0-nightly.0",
"embark-storage": "^5.3.0-nightly.0",
"embark-swarm": "^5.3.0-nightly.0",
"embark-test-runner": "^5.3.0-nightly.0",
"embark-transaction-logger": "^5.3.0-nightly.0",
"embark-transaction-tracker": "^5.2.3",
"embark-utils": "^5.3.0-nightly.0",
"embark-vyper": "^5.2.3",
"embark-watcher": "^5.3.0-nightly.0",
"embark-web3": "^5.3.0-nightly.0",
"embark-webserver": "^5.3.0-nightly.0",
"embark-whisper-geth": "^5.3.0-nightly.0",
"embark-whisper-parity": "^5.3.0-nightly.0"
"embark-webserver": "^5.3.0-nightly.0"
},
"devDependencies": {
"embark-solo": "^5.2.3",
Expand Down
21 changes: 0 additions & 21 deletions packages/core/engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export class Engine {
const options = _options || {};

const groups = {
blockchain: this.blockchainComponents,
coreComponents: this.coreComponents,
stackComponents: this.stackComponents,
serviceMonitor: this.serviceMonitor,
Expand All @@ -162,8 +161,6 @@ export class Engine {
contracts: this.contractsComponents,
pipeline: this.pipelineService,
webserver: this.webserverService,
storage: this.storageComponent,
communication: this.communicationComponents,
namesystem: this.namesystemComponents,
filewatcher: this.filewatcherService,
tests: this.testComponents,
Expand Down Expand Up @@ -263,13 +260,6 @@ export class Engine {
this.registerModulePackage('embark-embarkjs', { plugins: this.plugins });
}

blockchainComponents() {
// plugins
this.registerModulePackage('embark-ganache');
this.registerModulePackage('embark-geth');
this.registerModulePackage('embark-parity');
}

testComponents(options) {
this.registerModulePackage('embark-test-runner', { plugins: this.plugins, ipc: this.ipc });
this.registerModulePackage('embark-coverage', { plugins: this.plugins, coverage: options.coverage });
Expand All @@ -291,17 +281,6 @@ export class Engine {
this.registerModulePackage('embark-specialconfigs', { plugins: this.plugins });
this.registerModulePackage('embark-transaction-logger');
this.registerModulePackage('embark-transaction-tracker');
this.registerModulePackage('embark-profiler');
}

storageComponent() {
this.registerModulePackage('embark-ipfs');
this.registerModulePackage('embark-swarm');
}

communicationComponents() {
this.registerModulePackage('embark-whisper-geth');
this.registerModulePackage('embark-whisper-parity');
}

namesystemComponents() {
Expand Down
18 changes: 0 additions & 18 deletions packages/core/engine/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,12 @@
{
"path": "../../plugins/geth"
},
{
"path": "../../plugins/ipfs"
},
{
"path": "../../plugins/mocha-tests"
},
{
"path": "../../plugins/parity"
},
{
"path": "../../plugins/plugin-cmd"
},
{
"path": "../../plugins/profiler"
},
{
"path": "../../plugins/rpc-manager"
},
Expand All @@ -64,9 +55,6 @@
{
"path": "../../plugins/specialconfigs"
},
{
"path": "../../plugins/swarm"
},
{
"path": "../../plugins/transaction-logger"
},
Expand All @@ -79,12 +67,6 @@
{
"path": "../../plugins/web3"
},
{
"path": "../../plugins/whisper-geth"
},
{
"path": "../../plugins/whisper-parity"
},
{
"path": "../../stack/api"
},
Expand Down
1 change: 0 additions & 1 deletion packages/embark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
"embark-core": "^5.3.0-nightly.0",
"embark-deploy-tracker": "^5.3.0-nightly.0",
"embark-engine": "^5.3.0-nightly.0",
"embark-graph": "^5.3.0-nightly.0",
"embark-i18n": "^5.2.3",
"embark-logger": "^5.3.0-nightly.0",
"embark-reset": "^5.2.3",
Expand Down
28 changes: 9 additions & 19 deletions packages/embark/src/cmd/cmd_controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Config, Events, fs, TemplateGenerator } from 'embark-core';
import { Engine } from 'embark-engine';
import { __ } from 'embark-i18n';
import { dappPath, joinPath, setUpEnv } from 'embark-utils';
import { dappPath, joinPath, setUpEnv, warnIfPackageNotDefinedLocally } from 'embark-utils';
import { Logger, LogLevels } from 'embark-logger';
let async = require('async');
const constants = require('embark-core/constants');
Expand Down Expand Up @@ -63,7 +63,6 @@ class EmbarkController {
engine.registerModuleGroup("coreComponents");
engine.registerModuleGroup("serviceMonitor");
engine.registerModuleGroup("blockchainStackComponents");
engine.registerModuleGroup("blockchain");

// load custom plugins
engine.loadDappPlugins();
Expand Down Expand Up @@ -167,14 +166,11 @@ class EmbarkController {

// TODO: replace with individual plugins
engine.registerModuleGroup("namesystem");
engine.registerModuleGroup("communication");
engine.registerModuleGroup("blockchain");
engine.registerModuleGroup("compiler");
engine.registerModuleGroup("contracts");
engine.registerModuleGroup("pipeline");
engine.registerModuleGroup("webserver");
engine.registerModuleGroup("filewatcher");
engine.registerModuleGroup("storage");
engine.registerModuleGroup("cockpit");
engine.registerModulePackage('embark-deploy-tracker', { plugins: engine.plugins });
engine.registerModulePackage("embark-debugger");
Expand Down Expand Up @@ -293,11 +289,11 @@ class EmbarkController {
engine.registerModuleGroup("contracts");

if (!options.onlyCompile) {
engine.registerModuleGroup("blockchain");
engine.registerModuleGroup("namesystem");
engine.registerModuleGroup("storage");
engine.registerModuleGroup("communication");
// engine.registerModuleGroup("blockchain");
// engine.registerModuleGroup("storage");
// engine.registerModuleGroup("communication");
engine.registerModuleGroup("pipeline");
engine.registerModuleGroup("namesystem");
engine.registerModulePackage('embark-deploy-tracker', { plugins: engine.plugins });
}

Expand Down Expand Up @@ -423,14 +419,11 @@ class EmbarkController {

// TODO: replace with individual plugins
engine.registerModuleGroup("namesystem");
engine.registerModuleGroup("communication");
engine.registerModuleGroup("blockchain");
engine.registerModuleGroup("compiler");
engine.registerModuleGroup("contracts");
engine.registerModuleGroup("pipeline");
engine.registerModuleGroup("webserver");
engine.registerModuleGroup("filewatcher");
engine.registerModuleGroup("storage");
if (!isSecondaryProcess(engine)) {
engine.registerModuleGroup("cockpit");
}
Expand Down Expand Up @@ -528,7 +521,6 @@ class EmbarkController {

engine.registerModuleGroup("compiler");
engine.registerModuleGroup("contracts");
engine.registerModulePackage("embark-graph");

// load custom plugins
engine.loadDappPlugins();
Expand All @@ -537,6 +529,10 @@ class EmbarkController {
engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", "));
}

if (warnIfPackageNotDefinedLocally("embark-graph", engine.logger.error) !== true) {
process.exit(1);
}

engine.startEngine(async () => {
let contractsFiles = await engine.events.request2("config:contractsFiles");
let compiledContracts = await engine.events.request2("compiler:contracts:compile", contractsFiles);
Expand Down Expand Up @@ -744,14 +740,11 @@ class EmbarkController {
engine.registerModuleGroup("stackComponents");

engine.registerModuleGroup("namesystem");
engine.registerModuleGroup("communication");
engine.registerModuleGroup("blockchain");
engine.registerModuleGroup("compiler");
engine.registerModuleGroup("contracts");
engine.registerModuleGroup("pipeline");
engine.registerModuleGroup("webserver");
engine.registerModuleGroup("filewatcher");
engine.registerModuleGroup("storage");
engine.registerModulePackage('embark-deploy-tracker', { plugins: engine.plugins });

// load custom plugins
Expand Down Expand Up @@ -828,7 +821,6 @@ class EmbarkController {
engine.registerModuleGroup("coreComponents");
engine.registerModuleGroup("stackComponents");

engine.registerModuleGroup("blockchain");
engine.registerModuleGroup("compiler");
engine.registerModulePackage('embark-ganache');
engine.registerModulePackage('embark-ethereum-blockchain-client');
Expand All @@ -840,8 +832,6 @@ class EmbarkController {
engine.registerModuleGroup("tests", options);
engine.registerModulePackage('embark-deploy-tracker', { plugins: engine.plugins, trackContracts: false });
engine.registerModuleGroup("namesystem");
engine.registerModuleGroup("storage");
engine.registerModuleGroup("communication");
next();
},
function loadDappPlugins(next) {
Expand Down
3 changes: 0 additions & 3 deletions packages/embark/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
{
"path": "../plugins/deploy-tracker"
},
{
"path": "../plugins/graph"
},
{
"path": "../plugins/solidity"
},
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/graph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"dependencies": {
"@babel/runtime-corejs3": "7.7.4",
"async": "2.6.1",
"embark-utils": "^5.1.0-nightly.1",
"core-js": "3.4.3",
"embark-utils": "^5.3.0-nightly.0",
"viz.js": "1.8.2"
Expand Down
3 changes: 0 additions & 3 deletions packages/plugins/profiler/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { warnIfPackageNotDefinedLocally } from 'embark-utils';

const asciiTable = require('ascii-table');
import { GasEstimator, GAS_ERROR, EVENT_NO_GAS } from './gasEstimator';

Expand All @@ -12,7 +10,6 @@ class Profiler {

this.registerConsoleCommand();
this.registerApi();
warnIfPackageNotDefinedLocally("embark-profiler", this.embark.logger.warn.bind(this.embark.logger));
}

profileJSON(contractName, returnCb) {
Expand Down
24 changes: 12 additions & 12 deletions site/source/docs/contracts_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ We can specify a condition that decides whether a contract should be deployed by
...
deploy: {
ERC20: {
deployIf: async ({contracts, web3, logger}) => {
return await contracts.Manager.methods.isUpdateApproved().call();
deployIf: async (dependencies) => {
return await dependencies.contracts.Manager.methods.isUpdateApproved().call();
},
deps: ['Manager']
},
Expand Down Expand Up @@ -534,8 +534,8 @@ We can specify the `onDeploy` hook to execute code, right after a contract has b
deploy: {
SimpleStorage: {
args: [100],
onDeploy: async ({contracts, web3, logger}) => {
await contracts.SimpleStorage.methods.set(150).send({from: web3.eth.defaultAccount});
onDeploy: async (dependencies) => {
await dependencies.contracts.SimpleStorage.methods.set(150).send({from: dependencies.web3.eth.defaultAccount});
}
}
}
Expand All @@ -550,8 +550,8 @@ Also, as mentioned above, every deployment hook works with plain promises as wel
...
SimpleStorage: {
args: [100],
onDeploy: ({contracts, web3, logger}) => {
return contracts.SimpleStorage.methods.set(150).send();
onDeploy: (dependencies) => {
return dependencies.contracts.SimpleStorage.methods.set(150).send();
}
}
...
Expand All @@ -568,8 +568,8 @@ deploy: {
args: [100]
},
},
afterDeploy: ({contracts, web3, logger}) => {
contracts.SimpleStorage.methods.set(150).send({from: web3.eth.defaultAccount});
afterDeploy: (dependencies) => {
dependencies.contracts.SimpleStorage.methods.set(150).send({from: dependencies.web3.eth.defaultAccount});
}
...
```
Expand All @@ -579,9 +579,9 @@ afterDeploy: ({contracts, web3, logger}) => {
Since we use functions for these deployment hooks, we have to manage errors ourselves. We skipped that step in the above examples to save space, but here is an easy example on how you can do it:

```
onDeploy: async ({contracts, web3, logger}) => {
onDeploy: async (dependencies) => {
try {
await contracts.SimpleStorage.methods.set(85).send({from: web3.eth.defaultAccount});
await dependencies.contracts.SimpleStorage.methods.set(85).send({from: dependencies.web3.eth.defaultAccount});
} catch (e) {
console.error('Error during onDeploy', e);
}
Expand Down Expand Up @@ -616,8 +616,8 @@ The `logger` is injected as part of the `dependencies` object, so we can use it
```
deploy: {
SimpleStorage: {
onDeploy: async ({contracts, web3, logger}) => {
logger.info('Hello from onDeploy!');
onDeploy: async (dependencies) => {
dependencies.logger.info('Hello from onDeploy!');
}
}
}
Expand Down

0 comments on commit db10064

Please sign in to comment.