-
Notifications
You must be signed in to change notification settings - Fork 11
Refactor dev and fix bugs #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
500ecf6
f7c3ebe
cff3411
accd64d
dc99f19
b5f5056
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["@babel/preset-env"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,4 @@ node_modules | |
vue-mike | ||
react-mike | ||
docs/_build | ||
.DS_Store | ||
build | ||
.DS_Store |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"use strict"; | ||
|
||
require("@babel/polyfill"); | ||
|
||
exports.build = require('./lib/build'); | ||
exports.helper = require('./lib/helper'); | ||
exports.initialization = require('./lib/initialization'); | ||
exports.ipfs = require('./lib/ipfs'); | ||
exports.new = require('./lib/new'); | ||
exports.plugin = require('./lib/plugin'); | ||
exports.Log = require('./lib/Log'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"use strict"; | ||
|
||
var chalk = require('chalk'); | ||
|
||
var Log = console.log; | ||
module.exports = { | ||
SuccessLog: function SuccessLog(log) { | ||
Log(chalk.green.bold(log)); | ||
}, | ||
ErrorLog: function ErrorLog(log) { | ||
Log(chalk.white.bgRed.bold(log)); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"use strict"; | ||
|
||
var cmd = require('node-cmd'); | ||
|
||
var path = require('path'); | ||
|
||
var fs = require('fs'); | ||
|
||
var Log = require('../Log'); | ||
|
||
var ProgressBar = require('progress'); | ||
|
||
var KAIZEN_CONFIG_FILE = "kaizen.json"; | ||
exports.description = 'build dapp package'; | ||
|
||
exports.yargs = function (yargs) { | ||
yargs.example('kaizen build'); | ||
}; | ||
|
||
exports.argv = function (argv) { | ||
var targetPath = path.resolve('./', KAIZEN_CONFIG_FILE); | ||
|
||
if (fs.existsSync(targetPath) === false) { | ||
Log.ErrorLog("Kaizen.json this file does not exist"); | ||
return; | ||
} | ||
|
||
var targetConfig = JSON.parse(fs.readFileSync(targetPath, 'utf-8')); | ||
|
||
if (targetConfig.issued !== 'PortalNetwork') { | ||
Log.ErrorLog("Kaizen.json profile error"); | ||
return; | ||
} | ||
|
||
Log.SuccessLog('==== Please wait in the build ===='); | ||
var green = "\x1B[42m \x1B[0m"; | ||
var red = "\x1B[41m \x1B[0m"; | ||
var total = 40; | ||
var isLoad = false; | ||
var bar = new ProgressBar(' [:bar]', { | ||
complete: green, | ||
incomplete: red, | ||
total: total | ||
}); | ||
var barLoad = setInterval(function () { | ||
bar.tick(); | ||
bar.curr += 1; | ||
|
||
if (bar.curr >= total) { | ||
bar.curr = 0; | ||
} | ||
|
||
if (isLoad) { | ||
clearInterval(barLoad); | ||
Log.SuccessLog("==== build carry out ===="); | ||
} | ||
}, 100); | ||
cmd.get("npm run build", function (err) { | ||
bar.curr = total; | ||
isLoad = true; | ||
if (err) return Log.ErrorLog("[ERROR] build: ".concat(err)); | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use strict"; | ||
|
||
var fs = require('fs'); | ||
|
||
var fse = require('fs-extra'); | ||
|
||
function existsSync(path) { | ||
return fs.existsSync(path); | ||
} | ||
|
||
function readFileSync(path) { | ||
return fs.readFileSync(path); | ||
} | ||
|
||
function readJSONSync(path) { | ||
return JSON.parse(readFileSync(path)); | ||
} | ||
|
||
function updateFileSync(path, content) { | ||
fs.writeFileSync(path, content); | ||
} | ||
|
||
function removeSync(path) { | ||
fse.remove(path); | ||
} | ||
|
||
exports.existsSync = existsSync; | ||
exports.readFileSync = readFileSync; | ||
exports.readJSONSync = readJSONSync; | ||
exports.updateFileSync = updateFileSync; | ||
exports.removeSync = removeSync; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"use strict"; | ||
|
||
exports.fsHelper = require('./fsHelper.js'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"use strict"; | ||
|
||
exports.init = require('./init.js'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use strict"; | ||
|
||
var fs = require('fs'); | ||
|
||
var path = require('path'); | ||
|
||
var Log = require('../Log'); | ||
|
||
var KAIZEN_CONFIG_FILE = "kaizen.json"; | ||
exports.description = 'initialize kaizen environment'; | ||
|
||
exports.yargs = function (yargs) { | ||
yargs.example('kaizen init'); | ||
}; | ||
|
||
exports.argv = function (argv) { | ||
var targetPath = path.resolve('./', KAIZEN_CONFIG_FILE); | ||
|
||
if (fs.existsSync(targetPath) === false) { | ||
console.error('[ERROR]: please use kaizen new to create new project first.'); | ||
return; | ||
} | ||
|
||
var sourcePath = path.resolve(__dirname, '../../../config/', KAIZEN_CONFIG_FILE); | ||
var sourceConfig = JSON.parse(fs.readFileSync(sourcePath)); | ||
var targetConfig = JSON.parse(fs.readFileSync(targetPath)); | ||
var newConfig = Object.assign({}, targetConfig, sourceConfig); | ||
fs.writeFileSync(targetPath, JSON.stringify(newConfig)); | ||
Log.SuccessLog("complete initialization"); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"use strict"; | ||
|
||
exports.publish = require('./publish.js'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
"use strict"; | ||
|
||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
|
||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
|
||
var fs = require('fs'); | ||
|
||
var path = require('path'); | ||
|
||
var Log = require('../Log'); | ||
|
||
var ipfsAPI = require('ipfs-api'); | ||
|
||
var JSONFile = require('jsonfile'); | ||
|
||
var openBrowser = require('opn'); | ||
|
||
var BuildPath = 'build'; | ||
var 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) { | ||
var readdirSyncs = fs.readdirSync(path); | ||
readdirSyncs.forEach(function (item) { | ||
if (item.includes('.DS_Store')) return; | ||
|
||
switch (fs.statSync("".concat(path, "/").concat(item)).isDirectory()) { | ||
case true: | ||
files = loopFilesInFolder("".concat(path, "/").concat(item), files); | ||
break; | ||
|
||
case false: | ||
files.push("".concat(path, "/").concat(item)); | ||
break; | ||
} | ||
}); | ||
return files; | ||
} | ||
|
||
function getIPFSContentObject(filePath, targetPath) { | ||
return { | ||
path: "public".concat(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"); | ||
} | ||
|
||
var targetPath = "".concat(path.resolve('./', BuildPath)); | ||
|
||
try { | ||
(function () { | ||
var _ref = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(yargs, targetPath) { | ||
var kaizenConfig, ipfs, files, hashes, hash, iphsUrl; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return JSONFile.readFile(kaizenfile); | ||
|
||
case 2: | ||
kaizenConfig = _context.sent; | ||
ipfs = ipfsAPI(kaizenConfig.provider); | ||
console.log('=== uploading to the IPFS ==='); | ||
files = loopFilesInFolder(targetPath, []).map(function (item) { | ||
return getIPFSContentObject(item, targetPath); | ||
}); | ||
_context.next = 8; | ||
return ipfs.files.add(files, { | ||
recursive: false | ||
}); | ||
|
||
case 8: | ||
hashes = _context.sent; | ||
hash = hashes[hashes.length - 1].hash; | ||
iphsUrl = "https://ipfs.infura.io/ipfs/".concat(hash); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iphsUrl typo, please change to ipfsUrl |
||
openBrowser(iphsUrl); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iphsUrl typo, please change to ipfsUrl |
||
Log.SuccessLog("ipfs url => ".concat(iphsUrl)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iphsUrl typo, please change to ipfsUrl |
||
process.exit(); | ||
|
||
case 14: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
|
||
return function (_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
})()(yargs, targetPath); | ||
} catch (err) { | ||
Log.ErrorLog(err); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"use strict"; | ||
|
||
var cmd = require('node-cmd'); | ||
|
||
var fs = require("fs"); | ||
|
||
var del = require('del'); | ||
|
||
var Log = require('../Log'); | ||
|
||
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) { | ||
var f2eFramework = ''; | ||
var 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'; | ||
break; | ||
} | ||
|
||
cmd.get("git clone ".concat(f2eFramework), clone); | ||
|
||
function clone(err) { | ||
Log.SuccessLog('==== Clone from remote source ===='); | ||
if (err) return Log.ErrorLog('[ERROR] git clone!'); | ||
fs.rename(rename, "".concat(argv.name), fsRename); | ||
} | ||
|
||
function fsRename(err) { | ||
if (err == 'null') return Log.ErrorLog('[ERROR] create project!'); | ||
del(["./".concat(argv.boilerplate, "-").concat(argv.name, "/.git")]).then(unlink); | ||
Log.SuccessLog("==== Create project ".concat(argv.boilerplate, "-").concat(argv.name, " ====")); | ||
} | ||
|
||
function unlink(err) { | ||
if (err == 'null') return Log.ErrorLog('[ERROR] unlink file!'); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"use strict"; | ||
|
||
exports.create = require('./create.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iphsUrl typo, please change to ipfsUrl