Skip to content

Commit

Permalink
Merge pull request #26 from PortalNetwork/dev
Browse files Browse the repository at this point in the history
Release 0.0.7
  • Loading branch information
PhyrexTsai authored Sep 24, 2018
2 parents 9e0d96c + aa9550e commit 500ecf6
Show file tree
Hide file tree
Showing 22 changed files with 1,616 additions and 135 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
vue-mike
react-mike
docs/_build
.DS_Store
.DS_Store
build
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
<h1 align=center>KAIZEN CLI</h1>
</p>

<a target="_blank" href="https://circleci.com/gh/PhyrexTsai/kaizen-cli" title="CircleCI"><img src="https://circleci.com/gh/PhyrexTsai/kaizen-cli/tree/master.svg?style=shield"></a>
<a target="_blank" href="https://github.com/PortalNetwork/nifty-game/pulls" title="PRs Welcome"><img src="https://img.shields.io/badge/PRs-welcome-blue.svg"></a>
<img src="https://img.shields.io/hackage-deps/v/lens.svg"/>
<a href="#"><img src="https://img.shields.io/hackage-deps/v/lens.svg"/></a>
<a target="_blank" href="#"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"/></a>

> One stop solution for dapp developers
Expand Down
3 changes: 2 additions & 1 deletion README_KR.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
<h1 align=center>KAIZEN CLI</h1>
</p>

<a target="_blank" href="https://circleci.com/gh/PhyrexTsai/kaizen-cli" title="CircleCI"><img src="https://circleci.com/gh/PhyrexTsai/kaizen-cli/tree/master.svg?style=shield"></a>
<a target="_blank" href="https://github.com/PortalNetwork/nifty-game/pulls" title="PRs Welcome"><img src="https://img.shields.io/badge/PRs-welcome-blue.svg"></a>
<img src="https://img.shields.io/hackage-deps/v/lens.svg"/>
<a href="#"><img src="https://img.shields.io/hackage-deps/v/lens.svg"/></a>
<a target="_blank" href="#"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"/></a>

> dapp 개발자들을 위한 원 스톱 솔루션
Expand Down
3 changes: 2 additions & 1 deletion README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
<h1 align=center>KAIZEN CLI</h1>
</p>

<a target="_blank" href="https://circleci.com/gh/PhyrexTsai/kaizen-cli" title="CircleCI"><img src="https://circleci.com/gh/PhyrexTsai/kaizen-cli/tree/master.svg?style=shield"></a>
<a target="_blank" href="https://github.com/PortalNetwork/nifty-game/pulls" title="PRs Welcome"><img src="https://img.shields.io/badge/PRs-welcome-blue.svg"></a>
<img src="https://img.shields.io/hackage-deps/v/lens.svg"/>
<a href="#"><img src="https://img.shields.io/hackage-deps/v/lens.svg"/></a>
<a target="_blank" href="#"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"/></a>

> Kaizen是為dapp和dweb開發人員的一站式解決方案。
Expand Down
8 changes: 8 additions & 0 deletions config/kaizen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"issued": "PortalNetwork",
"provider": {
"host": "ipfs.infura.io",
"port": 5001,
"protocol": "https"
}
}
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Welcome to KAIZEN's documentation!

introduction
quickstart
tutorial



Expand Down
74 changes: 59 additions & 15 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
@@ -1,35 +1,79 @@
**********
KAIZEN
**********
======
KAIZEN CLI
======

**$ kaizen new**
----------------
``kaizen new``
----------------

**To create the epic web3 integration project which is made by Portal Network**
To create the epic web3 integration project which is made by Portal Network**

**Parameters:**

-n [project-name]: this parameter is required.
__

-b [vue|react]: choose the front-end library you want, default is vue.

-b [vue|react]: choose the front-end boilerplate you want, default is vue.

**Output:**

.. image:: https://user-images.githubusercontent.com/11625554/45541442-b42c7e80-b841-11e8-9c8a-218aff41ed45.png

--------------------------
``kaizen plugin add noia``
--------------------------

**$ kaizen plugin**

**To install plugin via kaizen**
To install NOIA SDK plugin via kaizen in project, this project should be used `kaizen new` to created

**Parameters:**

add noia: kaizen will install NOIA SDK for you in your project. the project should be used `kaizen new` to created

no parameter required
**Output:**

.. image:: https://user-images.githubusercontent.com/11625554/45541315-5dbf4000-b841-11e8-9f0c-35b1674aed99.png



------------------------------
``kaizen plugin add bluzelle``
------------------------------

To install Bluzelle SDK via kaizen in project, this project should be used `kaizen new` to created

**Parameters**

-b [vue|react]: choose the front-end boilerplate you want, default is vue.

**Usage**
- react

In react, bluzelle's sdk will wrapped and pass down through component property.

.. image:: https://user-images.githubusercontent.com/11625554/45680786-6fb91f80-bb6e-11e8-82f9-6dd4de9352fc.png

- vue

In vue, bluzelle's sdk were wrapped into an object. Once you initialize bluzelle, it will be returned.
Yout can use object spread syntax to replace them into your components, or just use them like a normal object.

.. image:: https://user-images.githubusercontent.com/11625554/45738864-17445980-bc24-11e8-912b-eedf4a97b3c6.png

----------------
``kaizen build``
----------------

To build the kaizen's dapp, and the built code will be output into the build folder

---------------
``kaizen init``
---------------

To setup the configuration you need, like IPFS provider.

----------------
``kaizen publish``
----------------

To upload your dapp to the IPFS. You shall execute `kaizen build` before publish




67 changes: 20 additions & 47 deletions kaizen
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
const clear = require('clear');
const chalk = require('chalk');
const figlet = require('figlet');
const newDapp = require("./lib/NewDapp");
const {
add: pluginAdd,
build: build,
} = require('./lib/plugin');
const plugin = require('./lib/plugin');
const initialization = require('./lib/initialization');
const build = require('./lib/build');
const ipfs = require('./lib/ipfs');
const kaizenNew = require('./lib/new');

// to clear terminal screen
clear();
Expand All @@ -25,47 +25,11 @@ console.log(

const argv = require('yargs')
.usage('Kaizen - a dapp framework for Blockchain\n\nUsage: $0 <command> [options]')
.command('new', 'create a dapp with boilerplate', (yargs) => {
return yargs
.option('n', {
alias: 'name',
describe: 'clone a file'
})
.option('b', {
alias: 'boilerplate',
describe: 'dapp boilerplate of vue or react',
choices: ['vue', 'react'],
default: 'vue'
})
.demandOption(['name'], 'Please enter your project name')
.example(
'kaizen new -n <package name> -b <vue or react>'
)
}, (argv) => {
const { name, boilerplate } = argv;
newDapp({ name, boilerplate });
})
.command('config', 'environment variables of dapps')
// .command('build', 'scripts used to pack dapp')
.command('plugin', 'list all the plugin to dapp')
.command('plugin add [plugin-name]', pluginAdd.description, (yargs) => pluginAdd.yargs(yargs), (argv) => pluginAdd.argv(argv))
.command('plugin:remove', 'remove an plugin to dapp', (yargs) => {
return yargs
.demandOption(['name'], 'Please enter a plugin name')
.example(
'kaizen plugin:remove <plugin name>'
)
})
.command('publish', 'scripts used to publish dapp', (yargs) => {
return yargs
.demandCommand(['storage'], 'Please enter a file storage')
.example(
'kaizen publish '
)
})
.command('build', 'build dapp package', (yargs) => {
build.build(yargs);
})
.command('init', initialization.init.description, initialization.init.yargs, initialization.init.argv)
.command('new', kaizenNew.create.description, kaizenNew.create.yargs, kaizenNew.create.argv)
.command('plugin add [plugin-name]', plugin.add.description, plugin.add.yargs, plugin.add.argv)
.command('publish', ipfs.publish.description, ipfs.publish.yargs)
.command('build', build.description, build.yargs, build.argv)
.demandCommand(1, 'You need at least one command before moving on')
.options({
'v': {
Expand All @@ -78,4 +42,13 @@ const argv = require('yargs')
}
})
.epilog('copyright Portal Network 2018')
.argv;
.argv;



/**
* TODO: kaizen new with choose blockchain e.g. ethereum, wanchain
*/



File renamed without changes.
1 change: 1 addition & 0 deletions lib/initialization/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.init = require('./init.js');
26 changes: 26 additions & 0 deletions lib/initialization/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const fs = require('fs');
const path = require('path');
const Log = require('../Log');
const KAIZEN_CONFIG_FILE = "kaizen.json";

exports.description = 'initialize kaizen environment';

exports.yargs = function(yargs) {
yargs.example('kaizen init');
}

exports.argv = function (argv) {
const targetPath = path.resolve('./', KAIZEN_CONFIG_FILE);

if(fs.existsSync(targetPath) === false) {
console.error('[ERROR]: please use kaizen new to create new project first.');
return;
}

const sourcePath = path.resolve(__dirname, '../../config/', KAIZEN_CONFIG_FILE);
const sourceConfig = JSON.parse(fs.readFileSync(sourcePath));
const targetConfig = JSON.parse(fs.readFileSync(targetPath));
const newConfig = Object.assign({}, targetConfig, sourceConfig);
fs.writeFileSync(targetPath, JSON.stringify(newConfig));
Log.SuccessLog("complete initialization");
}
1 change: 1 addition & 0 deletions lib/ipfs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.publish = require('./publish.js');
69 changes: 69 additions & 0 deletions lib/ipfs/publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const fs = require('fs');
const path = require('path');
const Log = require('../Log');
const ipfsAPI = require('ipfs-api');
const JSONFile = require('jsonfile');
const openBrowser = require('opn');
const BuildPath = 'build';
const kaizenfile = "kaizen.json";

function fsExistsSync() {
try {
fs.accessSync(BuildPath, fs.constants.R_OK | fs.constants.W_OK);
return true;
} catch (err) {
return false;
}
}

function loopFilesInFolder(path, files) {
const readdirSyncs = fs.readdirSync(path);
readdirSyncs.forEach(item => {
if (item.includes('.DS_Store')) return;
switch (fs.statSync(`${path}/${item}`).isDirectory()) {
case true:
files = loopFilesInFolder(`${path}/${item}`, files);
break;
case false:
files.push(`${path}/${item}`);
break
}
});

return files;
}

function getIPFSContentObject(filePath, targetPath) {
return ({
path: `public${filePath.replace(targetPath, '')}`,
content: fs.readFileSync(filePath)
});
}

exports.description = 'publish you app to the IPFS';

exports.yargs = function (yargs) {
if (!fsExistsSync()) {
Log.ErrorLog("Build This folder does not exist");
}

const targetPath = `${path.resolve('./', BuildPath)}`;

try {
(async function(yargs, targetPath) {
const kaizenConfig = await JSONFile.readFile(kaizenfile)
const ipfs = ipfsAPI(kaizenConfig.provider);
console.log('=== uploading to the IPFS ===')
const files = loopFilesInFolder(targetPath, []).map(item => getIPFSContentObject(item, targetPath));
const hashes = await ipfs.files.add(files, { recursive: false });
const { hash, } = hashes[hashes.length - 1];
const iphsUrl = `https://ipfs.infura.io/ipfs/${hash}`;
openBrowser(iphsUrl);
Log.SuccessLog(`ipfs url => ${iphsUrl}`)
process.exit();
})(yargs, targetPath);
} catch (err) {
Log.ErrorLog(err)
}
}

25 changes: 22 additions & 3 deletions lib/NewDapp.js → lib/new/create.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
const cmd = require('node-cmd');
const fs = require("fs");
const del = require('del');
const Log = require('./plugin/Log');
const Log = require('../Log');

module.exports = (argv) => {
exports.description = 'create a dapp with boilerplate';

exports.yargs = function (yargs) {
yargs
.option('n', {
alias: 'name',
describe: 'clone a file'
})
.option('b', {
alias: 'boilerplate',
describe: 'dapp boilerplate of vue or react',
choices: ['vue', 'react'],
default: 'vue'
})
.demandOption(['name'], 'Please enter your project name')
.example(
'kaizen new -n <package name> -b <vue or react>'
)
}

exports.argv = function (argv) {
let f2eFramework = '';
let rename = '';
switch (argv.boilerplate) {
case 'vue':
f2eFramework = 'https://github.com/PortalNetwork/vue-truffle.git';
rename = 'vue-truffle';
break;

case 'react':
f2eFramework = 'https://github.com/PortalNetwork/react-truffle-metamask.git';
rename = 'react-truffle-metamask';
Expand Down
1 change: 1 addition & 0 deletions lib/new/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.create = require('./create.js');
Loading

0 comments on commit 500ecf6

Please sign in to comment.