Skip to content

Commit 500ecf6

Browse files
authored
Merge pull request #26 from PortalNetwork/dev
Release 0.0.7
2 parents 9e0d96c + aa9550e commit 500ecf6

22 files changed

+1616
-135
lines changed

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules
22
vue-mike
33
react-mike
44
docs/_build
5-
.DS_Store
5+
.DS_Store
6+
build

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
<h1 align=center>KAIZEN CLI</h1>
88
</p>
99

10+
<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>
1011
<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>
11-
<img src="https://img.shields.io/hackage-deps/v/lens.svg"/>
12+
<a href="#"><img src="https://img.shields.io/hackage-deps/v/lens.svg"/></a>
1213
<a target="_blank" href="#"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"/></a>
1314

1415
> One stop solution for dapp developers

Diff for: README_KR.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
<h1 align=center>KAIZEN CLI</h1>
88
</p>
99

10+
<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>
1011
<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>
11-
<img src="https://img.shields.io/hackage-deps/v/lens.svg"/>
12+
<a href="#"><img src="https://img.shields.io/hackage-deps/v/lens.svg"/></a>
1213
<a target="_blank" href="#"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"/></a>
1314

1415
> dapp 개발자들을 위한 원 스톱 솔루션

Diff for: README_ZH.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
<h1 align=center>KAIZEN CLI</h1>
88
</p>
99

10+
<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>
1011
<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>
11-
<img src="https://img.shields.io/hackage-deps/v/lens.svg"/>
12+
<a href="#"><img src="https://img.shields.io/hackage-deps/v/lens.svg"/></a>
1213
<a target="_blank" href="#"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"/></a>
1314

1415
> Kaizen是為dapp和dweb開發人員的一站式解決方案。

Diff for: config/kaizen.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"issued": "PortalNetwork",
3+
"provider": {
4+
"host": "ipfs.infura.io",
5+
"port": 5001,
6+
"protocol": "https"
7+
}
8+
}

Diff for: docs/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Welcome to KAIZEN's documentation!
1212

1313
introduction
1414
quickstart
15+
tutorial
1516

1617

1718

Diff for: docs/tutorial.rst

+59-15
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,79 @@
1-
**********
2-
KAIZEN
3-
**********
1+
======
2+
KAIZEN CLI
3+
======
44

5-
**$ kaizen new**
5+
----------------
6+
``kaizen new``
7+
----------------
68

7-
**To create the epic web3 integration project which is made by Portal Network**
9+
To create the epic web3 integration project which is made by Portal Network**
810

911
**Parameters:**
1012

1113
-n [project-name]: this parameter is required.
1214
__
13-
14-
-b [vue|react]: choose the front-end library you want, default is vue.
15-
15+
-b [vue|react]: choose the front-end boilerplate you want, default is vue.
1616

1717
**Output:**
1818

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

21+
--------------------------
22+
``kaizen plugin add noia``
23+
--------------------------
2124

22-
**$ kaizen plugin**
23-
24-
**To install plugin via kaizen**
25+
To install NOIA SDK plugin via kaizen in project, this project should be used `kaizen new` to created
2526

2627
**Parameters:**
2728

28-
add noia: kaizen will install NOIA SDK for you in your project. the project should be used `kaizen new` to created
29-
29+
no parameter required
30+
3031
**Output:**
3132

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

34-
35-
35+
------------------------------
36+
``kaizen plugin add bluzelle``
37+
------------------------------
38+
39+
To install Bluzelle SDK via kaizen in project, this project should be used `kaizen new` to created
40+
41+
**Parameters**
42+
43+
-b [vue|react]: choose the front-end boilerplate you want, default is vue.
44+
45+
**Usage**
46+
- react
47+
48+
In react, bluzelle's sdk will wrapped and pass down through component property.
49+
50+
.. image:: https://user-images.githubusercontent.com/11625554/45680786-6fb91f80-bb6e-11e8-82f9-6dd4de9352fc.png
51+
52+
- vue
53+
54+
In vue, bluzelle's sdk were wrapped into an object. Once you initialize bluzelle, it will be returned.
55+
Yout can use object spread syntax to replace them into your components, or just use them like a normal object.
56+
57+
.. image:: https://user-images.githubusercontent.com/11625554/45738864-17445980-bc24-11e8-912b-eedf4a97b3c6.png
58+
59+
----------------
60+
``kaizen build``
61+
----------------
62+
63+
To build the kaizen's dapp, and the built code will be output into the build folder
64+
65+
---------------
66+
``kaizen init``
67+
---------------
68+
69+
To setup the configuration you need, like IPFS provider.
70+
71+
----------------
72+
``kaizen publish``
73+
----------------
74+
75+
To upload your dapp to the IPFS. You shall execute `kaizen build` before publish
76+
77+
78+
79+

Diff for: kaizen

+20-47
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
const clear = require('clear');
44
const chalk = require('chalk');
55
const figlet = require('figlet');
6-
const newDapp = require("./lib/NewDapp");
7-
const {
8-
add: pluginAdd,
9-
build: build,
10-
} = require('./lib/plugin');
6+
const plugin = require('./lib/plugin');
7+
const initialization = require('./lib/initialization');
8+
const build = require('./lib/build');
9+
const ipfs = require('./lib/ipfs');
10+
const kaizenNew = require('./lib/new');
1111

1212
// to clear terminal screen
1313
clear();
@@ -25,47 +25,11 @@ console.log(
2525

2626
const argv = require('yargs')
2727
.usage('Kaizen - a dapp framework for Blockchain\n\nUsage: $0 <command> [options]')
28-
.command('new', 'create a dapp with boilerplate', (yargs) => {
29-
return yargs
30-
.option('n', {
31-
alias: 'name',
32-
describe: 'clone a file'
33-
})
34-
.option('b', {
35-
alias: 'boilerplate',
36-
describe: 'dapp boilerplate of vue or react',
37-
choices: ['vue', 'react'],
38-
default: 'vue'
39-
})
40-
.demandOption(['name'], 'Please enter your project name')
41-
.example(
42-
'kaizen new -n <package name> -b <vue or react>'
43-
)
44-
}, (argv) => {
45-
const { name, boilerplate } = argv;
46-
newDapp({ name, boilerplate });
47-
})
48-
.command('config', 'environment variables of dapps')
49-
// .command('build', 'scripts used to pack dapp')
50-
.command('plugin', 'list all the plugin to dapp')
51-
.command('plugin add [plugin-name]', pluginAdd.description, (yargs) => pluginAdd.yargs(yargs), (argv) => pluginAdd.argv(argv))
52-
.command('plugin:remove', 'remove an plugin to dapp', (yargs) => {
53-
return yargs
54-
.demandOption(['name'], 'Please enter a plugin name')
55-
.example(
56-
'kaizen plugin:remove <plugin name>'
57-
)
58-
})
59-
.command('publish', 'scripts used to publish dapp', (yargs) => {
60-
return yargs
61-
.demandCommand(['storage'], 'Please enter a file storage')
62-
.example(
63-
'kaizen publish '
64-
)
65-
})
66-
.command('build', 'build dapp package', (yargs) => {
67-
build.build(yargs);
68-
})
28+
.command('init', initialization.init.description, initialization.init.yargs, initialization.init.argv)
29+
.command('new', kaizenNew.create.description, kaizenNew.create.yargs, kaizenNew.create.argv)
30+
.command('plugin add [plugin-name]', plugin.add.description, plugin.add.yargs, plugin.add.argv)
31+
.command('publish', ipfs.publish.description, ipfs.publish.yargs)
32+
.command('build', build.description, build.yargs, build.argv)
6933
.demandCommand(1, 'You need at least one command before moving on')
7034
.options({
7135
'v': {
@@ -78,4 +42,13 @@ const argv = require('yargs')
7842
}
7943
})
8044
.epilog('copyright Portal Network 2018')
81-
.argv;
45+
.argv;
46+
47+
48+
49+
/**
50+
* TODO: kaizen new with choose blockchain e.g. ethereum, wanchain
51+
*/
52+
53+
54+

Diff for: lib/plugin/Log.js renamed to lib/Log.js

File renamed without changes.

Diff for: lib/initialization/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.init = require('./init.js');

Diff for: lib/initialization/init.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const Log = require('../Log');
4+
const KAIZEN_CONFIG_FILE = "kaizen.json";
5+
6+
exports.description = 'initialize kaizen environment';
7+
8+
exports.yargs = function(yargs) {
9+
yargs.example('kaizen init');
10+
}
11+
12+
exports.argv = function (argv) {
13+
const targetPath = path.resolve('./', KAIZEN_CONFIG_FILE);
14+
15+
if(fs.existsSync(targetPath) === false) {
16+
console.error('[ERROR]: please use kaizen new to create new project first.');
17+
return;
18+
}
19+
20+
const sourcePath = path.resolve(__dirname, '../../config/', KAIZEN_CONFIG_FILE);
21+
const sourceConfig = JSON.parse(fs.readFileSync(sourcePath));
22+
const targetConfig = JSON.parse(fs.readFileSync(targetPath));
23+
const newConfig = Object.assign({}, targetConfig, sourceConfig);
24+
fs.writeFileSync(targetPath, JSON.stringify(newConfig));
25+
Log.SuccessLog("complete initialization");
26+
}

Diff for: lib/ipfs/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.publish = require('./publish.js');

Diff for: lib/ipfs/publish.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const Log = require('../Log');
4+
const ipfsAPI = require('ipfs-api');
5+
const JSONFile = require('jsonfile');
6+
const openBrowser = require('opn');
7+
const BuildPath = 'build';
8+
const kaizenfile = "kaizen.json";
9+
10+
function fsExistsSync() {
11+
try {
12+
fs.accessSync(BuildPath, fs.constants.R_OK | fs.constants.W_OK);
13+
return true;
14+
} catch (err) {
15+
return false;
16+
}
17+
}
18+
19+
function loopFilesInFolder(path, files) {
20+
const readdirSyncs = fs.readdirSync(path);
21+
readdirSyncs.forEach(item => {
22+
if (item.includes('.DS_Store')) return;
23+
switch (fs.statSync(`${path}/${item}`).isDirectory()) {
24+
case true:
25+
files = loopFilesInFolder(`${path}/${item}`, files);
26+
break;
27+
case false:
28+
files.push(`${path}/${item}`);
29+
break
30+
}
31+
});
32+
33+
return files;
34+
}
35+
36+
function getIPFSContentObject(filePath, targetPath) {
37+
return ({
38+
path: `public${filePath.replace(targetPath, '')}`,
39+
content: fs.readFileSync(filePath)
40+
});
41+
}
42+
43+
exports.description = 'publish you app to the IPFS';
44+
45+
exports.yargs = function (yargs) {
46+
if (!fsExistsSync()) {
47+
Log.ErrorLog("Build This folder does not exist");
48+
}
49+
50+
const targetPath = `${path.resolve('./', BuildPath)}`;
51+
52+
try {
53+
(async function(yargs, targetPath) {
54+
const kaizenConfig = await JSONFile.readFile(kaizenfile)
55+
const ipfs = ipfsAPI(kaizenConfig.provider);
56+
console.log('=== uploading to the IPFS ===')
57+
const files = loopFilesInFolder(targetPath, []).map(item => getIPFSContentObject(item, targetPath));
58+
const hashes = await ipfs.files.add(files, { recursive: false });
59+
const { hash, } = hashes[hashes.length - 1];
60+
const iphsUrl = `https://ipfs.infura.io/ipfs/${hash}`;
61+
openBrowser(iphsUrl);
62+
Log.SuccessLog(`ipfs url => ${iphsUrl}`)
63+
process.exit();
64+
})(yargs, targetPath);
65+
} catch (err) {
66+
Log.ErrorLog(err)
67+
}
68+
}
69+

Diff for: lib/NewDapp.js renamed to lib/new/create.js

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
11
const cmd = require('node-cmd');
22
const fs = require("fs");
33
const del = require('del');
4-
const Log = require('./plugin/Log');
4+
const Log = require('../Log');
55

6-
module.exports = (argv) => {
6+
exports.description = 'create a dapp with boilerplate';
7+
8+
exports.yargs = function (yargs) {
9+
yargs
10+
.option('n', {
11+
alias: 'name',
12+
describe: 'clone a file'
13+
})
14+
.option('b', {
15+
alias: 'boilerplate',
16+
describe: 'dapp boilerplate of vue or react',
17+
choices: ['vue', 'react'],
18+
default: 'vue'
19+
})
20+
.demandOption(['name'], 'Please enter your project name')
21+
.example(
22+
'kaizen new -n <package name> -b <vue or react>'
23+
)
24+
}
25+
26+
exports.argv = function (argv) {
727
let f2eFramework = '';
828
let rename = '';
929
switch (argv.boilerplate) {
1030
case 'vue':
1131
f2eFramework = 'https://github.com/PortalNetwork/vue-truffle.git';
1232
rename = 'vue-truffle';
1333
break;
14-
1534
case 'react':
1635
f2eFramework = 'https://github.com/PortalNetwork/react-truffle-metamask.git';
1736
rename = 'react-truffle-metamask';

Diff for: lib/new/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports.create = require('./create.js');

0 commit comments

Comments
 (0)