Skip to content

Commit

Permalink
Merge pull request #56 from LimeChain/cli
Browse files Browse the repository at this point in the history
Cli
  • Loading branch information
bakasura980 authored May 21, 2020
2 parents bd4b8a8 + 3f89feb commit 56df355
Show file tree
Hide file tree
Showing 86 changed files with 1,070 additions and 334 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,48 @@ EOS development and deployment framework based on eosjs.js. The framework's main
Telegram - https://t.me/eoslime
Documentation - https://lyubo.gitbook.io/eoslime/

# Version 1.0.4 change log

* **eoslime nodeos**
* **eoslime nodeos start --path="Some path"**
Run local predefined single node chain
* **eoslime nodeos stop**
Stop single node chain started by **eoslime nodeos start**
* **eoslime nodeos accounts**
Show preloaded accounts on **eoslime nodeos start**
* **eoslime nodeos logs**
Show chain logs

* **Account.create(name, privateKey, ?creator)**
There are cases you have already generated your private key and you have a name for your account. You only need to create it on the chain.

* **Contract.deployRaw(rawWasm, abiJSON, ?options)**
Used for deploying a contract from WASM string and ABI in JSON format
A typical use case for `deployRaw` is in CI/CD. You don't want to compile your contract every time, however your tests needs WASM and ABI. A good approach is to deploy your contract on a test network like Jungle one and retrieve its WASM and ABI for your tests.
```javascript
const eoslime = eoslime.init('jungle');
const deployedContract = 'your_contract_name';
const contractA_ABI = await eoslime.Provider.getABI(deployedContract);
const contractA_WASM = await eoslime.Provider.getRawWASM(deployedContract);

const contractB = await eoslime.Contract.deployRaw(contractA_WASM, contractA_ABI);
```
* **Contract.deployRawOnAccount(rawWasm, abiJSON, account, ?options)**
Used for deploying a contract from WASM string and ABI in JSON format

* **Provider.getABI(contractName)**
Returns contract ABI in JSON format

* **Provider.getRawWASM(contractName)**
Returns raw WASM useful for deploying another contract directly

* **contractInstance.abi**
Returns contract ABI in JSON format

* **contractInstance.getRawWASM()**
Returns contract raw WASM


# Version 1.0.3 change log

* **eoslime shape --framework=react**
Expand Down
39 changes: 39 additions & 0 deletions cli-commands/command-definer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class CommandDefiner {
constructor(yargs) {
this.yargs = yargs;
}

define (command) {
return {
command: command.template,
description: command.description,
builder: this.build(command),
handler: this.handle(command)
}
}

build (command) {
return (yargs) => {
for (const subcommand of command.subcommands) {
yargs.command(this.define(subcommand));
}

for (const option of command.options) {
yargs = yargs.options(option.name, option.definition);
}

return yargs;
}
}

handle (command) {
return async (args) => {
const result = await command.execute(args);
if (!result) {
this.yargs.showHelp();
}
}
}
}

module.exports = CommandDefiner;
43 changes: 0 additions & 43 deletions cli-commands/command.js

This file was deleted.

28 changes: 28 additions & 0 deletions cli-commands/commands/command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Command {
constructor(commandDefinition) {
this.subcommands = [];
this.options = commandDefinition.options || [];
this.template = commandDefinition.template || '';
this.description = commandDefinition.description || '';
}

async processOptions (args) {
const optionResults = {};

for (let i = 0; i < this.options.length; i++) {
const option = this.options[i];

if (args.hasOwnProperty(option.name)) {
const result = await option.process(args[option.name], args);
optionResults[option.name] = result;
}
}

return optionResults;
}

execute (args) { }

}

module.exports = Command;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const pathOption = require('./options/path-option');

module.exports = {
"template": "compile [path]",
"template": "compile",
"description": "Compile contract/s",
"options": [pathOption]
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const AsyncSoftExec = require('./../helpers/async-soft-exec');
const Command = require('./../command');
const AsyncSoftExec = require('../../helpers/async-soft-exec');
const Command = require('../command');

const commandMessages = require('./messages');
const compiledDirectories = require('./directories.json');
const compiledDirectories = require('./specific/directories.json');
const compileCommandDefinition = require('./definition');

const fileSysUtils = require('./../helpers/file-system-util');
const fileSysUtils = require('../../helpers/file-system-util');

// eoslime compile --path

Expand All @@ -15,7 +15,7 @@ class CompileCommand extends Command {
super(compileCommandDefinition);
}

async execute(args) {
async execute (args) {
try {
commandMessages.StartCompilation();

Expand All @@ -39,6 +39,7 @@ class CompileCommand extends Command {
} catch (error) {
commandMessages.UnsuccessfulCompilation(error);
}
return true;
}
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fileSystemUtil = require('./../../helpers/file-system-util');
const fileSystemUtil = require('../../../helpers/file-system-util');

const Option = require('./../../option');
const Option = require('../../option');

class PathOption extends Option {

Expand All @@ -15,7 +15,7 @@ class PathOption extends Option {
);
}

async process(optionValue) {
async process (optionValue) {
if (fileSystemUtil.isDir(optionValue)) {
const dirFiles = await fileSystemUtil.recursivelyReadDir(optionValue);
const contractsFiles = dirFiles.filter(dirFile => dirFile.fileName.endsWith('.cpp'));
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const networkOption = require('./options/network-option');
const deployerOption = require('./options/deployer-option');

module.exports = {
"template": "deploy [path] [network] [deployer]",
"description": "Run deployment script",
"template": "deploy",
"description": "Run deployment script/s",
options: [pathOption, networkOption, deployerOption]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Command = require('./../command');
const Command = require('../command');

const commandMessages = require('./messages');
const deployCommandDefinition = require('./definition');
Expand All @@ -10,14 +10,15 @@ class DeployCommand extends Command {
super(deployCommandDefinition);
}

async execute(args) {
async execute (args) {
try {
commandMessages.StartDeployment();
const optionsResults = await super.processOptions(args);
await runDeploymentScripts(optionsResults.path, optionsResults.network, optionsResults.deployer);
} catch (error) {
commandMessages.UnsuccessfulDeployment(error);
}
return true;
}
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const consoleInput = require('prompts');

const Option = require('../../option');
const AccountFactory = require('../../../src/account/normal-account/account-factory');
const AccountFactory = require('../../../../src/account/normal-account/account-factory');

class DeployerOption extends Option {
constructor() {
Expand All @@ -14,7 +14,7 @@ class DeployerOption extends Option {
);
}

async process(accountName, args) {
async process (accountName, args) {
const accountFactory = new AccountFactory(args.network);

const deployerAuth = await consoleInput({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
const Option = require('./../../option');
const eoslime = require('./../../../index');
const Option = require('../../option');
const eoslime = require('../../../../index');

class NetworkOption extends Option {
constructor() {
super(
'network',
{
"describe": "The blockchain network you are going to deploy on.\n\nParameters: \nNetwork name or in case of custom: \n{ url: custom url, chainId: custom chain id }\n",
"alias": "n",
"describe": "The blockchain network you are going to test on.\n \nNetwork name or in case of custom: \n\"eoslime deploy -n.url=\"custom url\" -n.chainId=\"custom chain id\"",
"type": "string",
"default": "local",
}
);
}

process(optionValue) {
process (optionValue) {
if (optionValue) {
return eoslime.init(optionValue);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const Option = require('./../../option');
const Option = require('../../option');

const fileSystemUtil = require('./../../helpers/file-system-util');
const fileSystemUtil = require('../../../helpers/file-system-util');

class PathOption extends Option {
constructor() {
Expand All @@ -15,7 +15,7 @@ class PathOption extends Option {
);
}

async process(optionValue) {
async process (optionValue) {
let deploymentFilesFunctions = [];
if (fileSystemUtil.isDir(optionValue)) {
const dirFiles = await fileSystemUtil.recursivelyReadDir(optionValue);
Expand Down
29 changes: 29 additions & 0 deletions cli-commands/commands/group-command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const Command = require('./command');

class GroupCommand extends Command {
constructor(commandDefinition) {
super(commandDefinition);
}

async execute (args) {
if (optionsProvided(args, this.options)) {
await super.processOptions(args);
return true;
}

return false;
}
}

const optionsProvided = function (args, commandOptions) {
for (let i = 0; i < commandOptions.length; i++) {
const option = commandOptions[i];
if (args[option.name]) {
return true;
}
}

return false;
}

module.exports = GroupCommand;
8 changes: 8 additions & 0 deletions cli-commands/commands/init/definition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const withExampleOption = require('./options/with-example/with-example-option');


module.exports = {
"template": "init",
"description": "Build a ready-to-use development structure",
"options": [withExampleOption]
}
19 changes: 8 additions & 11 deletions cli-commands/init/index.js → cli-commands/commands/init/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
const AsyncSoftExec = require('./../helpers/async-soft-exec');
const AsyncSoftExec = require('../../helpers/async-soft-exec');
const Command = require('../command');

const Command = require('./../command');

const initDirectories = require('./directories');
const initDirectories = require('./specific/directories.json');
const initCommandDefinition = require('./definition');

const commandMessages = require('./messages');
const fileSystemUtil = require('./../helpers/file-system-util');
const fileSystemUtil = require('../../helpers/file-system-util');

const defaultPackageJsonDestination = `${__dirname}/default-package.json`;
const defaultPackageJsonDestination = `${__dirname}/specific/default-package.json`;

// eoslime init --with-example

Expand All @@ -18,11 +17,7 @@ class InitCommand extends Command {
super(initCommandDefinition);
}

defineOptions(yargs) {
super.defineOptions(yargs, initCommandDefinition.options);
}

async execute(args) {
async execute (args) {
try {
commandMessages.Installation();

Expand All @@ -41,6 +36,8 @@ class InitCommand extends Command {
asyncSoftExec.onSuccess(() => { commandMessages.SuccessfulInstallation(); });

await asyncSoftExec.exec();

return true;
}
}

Expand Down
File renamed without changes.
Loading

0 comments on commit 56df355

Please sign in to comment.