Skip to content

Commit

Permalink
add new command for setting configuration about IPFS, Ethereum or NKN…
Browse files Browse the repository at this point in the history
… locally
  • Loading branch information
ahlumin committed Nov 20, 2018
1 parent 8e2a5fb commit ba1bc1e
Show file tree
Hide file tree
Showing 12 changed files with 398 additions and 0 deletions.
52 changes: 52 additions & 0 deletions build/components/Settings/Ethereum/index.js
@@ -0,0 +1,52 @@
"use strict";

var Log = require('../../../lib/Log');

var Spinner = require('../../../lib/Spinner');

var WriteKaizen = require('../WriteKaizen.js');

function builder(yargs) {
return yargs.option('network', {
type: 'string',
describe: 'network',
require: true
}).option('provider', {
type: 'string',
describe: 'provider',
require: true
}).option('port', {
type: 'string',
describe: 'port',
require: true
}).example('kaizen set-ethereum --network <net work id> --provider <provider> --port <port>');
}

function handler(argv) {
try {
Spinner.start();
var network = argv.network,
provider = argv.provider,
port = argv.port;
var settings = {
ethereum: {
network: network,
provider: provider,
port: port
}
};
WriteKaizen(settings);
Spinner.stop();
Log.SuccessLog('==== Ethereum configuration setting successfully ====');
} catch (error) {
Spinner.stop();
Log.ErrorLog('something went wrong!');
console.error(error);
}
}

module.exports = function (yargs) {
var command = 'set-ethereum';
var commandDescription = 'To set the configuration of Ethereum locally';
yargs.command(command, commandDescription, builder, handler);
};
52 changes: 52 additions & 0 deletions build/components/Settings/IPFS/index.js
@@ -0,0 +1,52 @@
"use strict";

var Log = require('../../../lib/Log');

var Spinner = require('../../../lib/Spinner');

var WriteKaizen = require('../WriteKaizen.js');

function builder(yargs) {
return yargs.option('host', {
type: 'string',
describe: 'host',
require: true
}).option('port', {
type: 'string',
describe: 'port',
require: true
}).option('protocol', {
type: 'string',
describe: 'protocol',
require: true
}).example('kaizen set-ipfs --host <host> --protocol <protocol> --port <port>');
}

function handler(argv) {
try {
Spinner.start();
var host = argv.host,
port = argv.port,
protocol = argv.protocol;
var settings = {
ipfs: {
host: host,
protocol: protocol,
port: port
}
};
WriteKaizen(settings);
Spinner.stop();
Log.SuccessLog('==== IPFS configuration setting successfully ====');
} catch (error) {
Spinner.stop();
Log.ErrorLog('something went wrong!');
console.error(error);
}
}

module.exports = function (yargs) {
var command = 'set-ipfs';
var commandDescription = 'To set the configuration of IPFS locally';
yargs.command(command, commandDescription, builder, handler);
};
52 changes: 52 additions & 0 deletions build/components/Settings/NKN/index.js
@@ -0,0 +1,52 @@
"use strict";

var Log = require('../../../lib/Log');

var Spinner = require('../../../lib/Spinner');

var WriteKaizen = require('../WriteKaizen.js');

function builder(yargs) {
return yargs.option('identifier', {
type: 'string',
describe: 'identifier',
require: true
}).option('private-key', {
type: 'string',
describe: 'private key',
require: true
}).option('rpc-server', {
type: 'string',
describe: 'seed RPC server address',
require: true
}).example('kaizen set-nkn --identifier <identifier> --private-key <private key> --rpc-server <seed RPC server address>');
}

function handler(argv) {
try {
Spinner.start();
var identifier = argv.identifier,
privateKey = argv.privateKey,
rpcServer = argv.rpcServer;
var settings = {
nkn: {
identifier: identifier,
privateKey: privateKey,
rpcServer: rpcServer
}
};
WriteKaizen(settings);
Spinner.stop();
Log.SuccessLog('==== NKN configuration setting successfully ====');
} catch (error) {
Spinner.stop();
Log.ErrorLog('something went wrong!');
console.error(error);
}
}

module.exports = function (yargs) {
var command = 'set-nkn';
var commandDescription = 'To set the configuration of NKN locally';
yargs.command(command, commandDescription, builder, handler);
};
26 changes: 26 additions & 0 deletions build/components/Settings/WriteKaizen.js
@@ -0,0 +1,26 @@
"use strict";

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var path = require('path');

var fsx = require('fs-extra');

module.exports = function (settings) {
var configPath = path.resolve('./', 'kaizen.json');
var kaizenConfiguration = retrieveKaizenConfiguration(configPath);

var newConfiguration = _objectSpread({}, kaizenConfiguration, settings);

fsx.writeJsonSync(configPath, newConfiguration);
};

function retrieveKaizenConfiguration(configPath) {
if (fsx.existsSync(configPath) === false) {
return {};
}

return fsx.readJsonSync(configPath);
}
13 changes: 13 additions & 0 deletions build/components/Settings/index.js
@@ -0,0 +1,13 @@
"use strict";

var IPFS_Setting = require('./IPFS');

var Ethereum_Setting = require('./Ethereum');

var NKN_Setting = require('./NKN');

module.exports = function (yargs) {
IPFS_Setting(yargs);
Ethereum_Setting(yargs);
NKN_Setting(yargs);
};
2 changes: 2 additions & 0 deletions build/components/index.js
Expand Up @@ -20,4 +20,6 @@ require('./CompileContracts')(yargs);

require('./DeployContracts')(yargs);

require('./Settings')(yargs);

module.exports = yargs;
56 changes: 56 additions & 0 deletions src/components/Settings/Ethereum/index.js
@@ -0,0 +1,56 @@
const Log = require('../../../lib/Log');
const Spinner = require('../../../lib/Spinner');
const WriteKaizen = require('../WriteKaizen.js');

function builder(yargs) {
return yargs
.option('network', {
type: 'string',
describe: 'network',
require: true
})
.option('provider', {
type: 'string',
describe: 'provider',
require: true
})
.option('port', {
type: 'string',
describe: 'port',
require: true
})
.example('kaizen set-ethereum --network <net work id> --provider <provider> --port <port>');
}

function handler(argv) {
try {
Spinner.start();
const {
network,
provider,
port
} = argv;

const settings = {
ethereum: {
network,
provider,
port
}
};

WriteKaizen(settings);
Spinner.stop();
Log.SuccessLog('==== Ethereum configuration setting successfully ====')
} catch (error) {
Spinner.stop();
Log.ErrorLog('something went wrong!');
console.error(error);
}
}

module.exports = function (yargs) {
const command = 'set-ethereum';
const commandDescription = 'To set the configuration of Ethereum locally';
yargs.command(command, commandDescription, builder, handler);
}
56 changes: 56 additions & 0 deletions src/components/Settings/IPFS/index.js
@@ -0,0 +1,56 @@
const Log = require('../../../lib/Log');
const Spinner = require('../../../lib/Spinner');
const WriteKaizen = require('../WriteKaizen.js');

function builder(yargs) {
return yargs
.option('host', {
type: 'string',
describe: 'host',
require: true
})
.option('port', {
type: 'string',
describe: 'port',
require: true
})
.option('protocol', {
type: 'string',
describe: 'protocol',
require: true
})
.example('kaizen set-ipfs --host <host> --protocol <protocol> --port <port>');
}

function handler(argv) {
try {
Spinner.start();
const {
host,
port,
protocol
} = argv;

const settings = {
ipfs : {
host,
protocol,
port
}
};

WriteKaizen(settings);
Spinner.stop();
Log.SuccessLog('==== IPFS configuration setting successfully ====')
} catch (error) {
Spinner.stop();
Log.ErrorLog('something went wrong!');
console.error(error);
}
}

module.exports = function (yargs) {
const command = 'set-ipfs';
const commandDescription = 'To set the configuration of IPFS locally';
yargs.command(command, commandDescription, builder, handler);
}
56 changes: 56 additions & 0 deletions src/components/Settings/NKN/index.js
@@ -0,0 +1,56 @@
const Log = require('../../../lib/Log');
const Spinner = require('../../../lib/Spinner');
const WriteKaizen = require('../WriteKaizen.js');

function builder(yargs) {
return yargs
.option('identifier', {
type: 'string',
describe: 'identifier',
require: true
})
.option('private-key', {
type: 'string',
describe: 'private key',
require: true
})
.option('rpc-server', {
type: 'string',
describe: 'seed RPC server address',
require: true
})
.example('kaizen set-nkn --identifier <identifier> --private-key <private key> --rpc-server <seed RPC server address>');
}

function handler(argv) {
try {
Spinner.start();
const {
identifier,
privateKey,
rpcServer
} = argv;

const settings = {
nkn: {
identifier,
privateKey,
rpcServer
}
};

WriteKaizen(settings);
Spinner.stop();
Log.SuccessLog('==== NKN configuration setting successfully ====')
} catch (error) {
Spinner.stop();
Log.ErrorLog('something went wrong!');
console.error(error);
}
}

module.exports = function (yargs) {
const command = 'set-nkn';
const commandDescription = 'To set the configuration of NKN locally';
yargs.command(command, commandDescription, builder, handler);
}

0 comments on commit ba1bc1e

Please sign in to comment.