Skip to content
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

improve user experience #64

Merged
merged 7 commits into from
Nov 30, 2018
7 changes: 4 additions & 3 deletions build/components/AddPlugin/bluzelle.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports =
_asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee() {
var sourceConfig, userConfig;
var configPath, sourceConfig, userConfig;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
Expand All @@ -43,8 +43,9 @@ regeneratorRuntime.mark(function _callee() {

case 4:
// update user's kaizen config
configPath = path.resolve('./', 'kaizen.json');
sourceConfig = fsx.readJsonSync(path.resolve(__dirname, '../../../config', 'kaizen.json'));
userConfig = fsx.readJsonSync(path.resolve('./', 'kaizen.json'));
userConfig = fsx.existsSync(configPath) ? fsx.readJsonSync(configPath) : {};
userConfig.bluzelle = sourceConfig.bluzelle;

if (!userConfig.plugins) {
Expand All @@ -57,7 +58,7 @@ regeneratorRuntime.mark(function _callee() {

fsx.outputJsonSync(path.resolve('./', 'kaizen.json'), userConfig);

case 10:
case 11:
case "end":
return _context.stop();
}
Expand Down
74 changes: 74 additions & 0 deletions build/components/AddPlugin/boilerplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"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 cmd = require('node-cmd');

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

module.exports =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee(name, library) {
var projectName;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
projectName = name || 'new-boilerplate';
_context.t0 = library;
_context.next = _context.t0 === 'vue' ? 4 : _context.t0 === 'react' ? 8 : 12;
break;

case 4:
_context.next = 6;
return cloneProjectFromGithub('https://github.com/PortalNetwork/vue-truffle.git', projectName);

case 6:
fsx.removeSync("./".concat(projectName, "/.git"));
return _context.abrupt("break", 16);

case 8:
_context.next = 10;
return cloneProjectFromGithub('https://github.com/PortalNetwork/react-truffle.git', projectName);

case 10:
fsx.removeSync("./".concat(projectName, "/.git"));
return _context.abrupt("break", 16);

case 12:
_context.next = 14;
return cloneProjectFromGithub('https://github.com/PortalNetwork/kaizen-boilerplate.git', projectName);

case 14:
fsx.removeSync("./".concat(projectName, "/.git"));
return _context.abrupt("break", 16);

case 16:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));

return function (_x, _x2) {
return _ref.apply(this, arguments);
};
}();

function cloneProjectFromGithub(repoURL, projectName) {
return new Promise(function (resolve, reject) {
cmd.get("git clone ".concat(repoURL, " ").concat(projectName), function (error) {
if (error) {
reject(error);
} else {
resolve(true);
}
});
});
}
46 changes: 31 additions & 15 deletions build/components/AddPlugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ var bluzelleHandler = require('./bluzelle.js');

var nknHandler = require('./nkn.js');

var boilerplateHandler = require('./boilerplate.js');

function builder(yargs) {
return yargs.option('package', {
return yargs.positional('package', {
alias: 'p',
type: 'string',
describe: 'plugin name',
require: true
}).example('kaizen add --package bluzelle');
}).option('name', {
alias: 'n',
type: 'string',
describe: 'your name of project'
}).option('library', {
type: 'string',
describe: 'react or vue, or simple without any libraries'
}).example('kaizen add bluzelle').example('kaizen add nkn');
}

function handler(_x) {
Expand All @@ -33,15 +42,15 @@ function _handler() {
_handler = _asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee(argv) {
var packageName;
var packageName, name, library;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
packageName = argv.package;
packageName = argv.package, name = argv.name, library = argv.library;

if (!(fs.existsSync(path.resolve('./', 'package.json')) === false)) {
if (!(fs.existsSync(path.resolve('./', 'package.json')) === false && packageName != 'boilerplate')) {
_context.next = 5;
break;
}
Expand All @@ -52,48 +61,55 @@ function _handler() {
case 5:
Spinner.start();
_context.t0 = packageName;
_context.next = _context.t0 === 'bluzelle' ? 9 : _context.t0 === 'nkn' ? 12 : 15;
_context.next = _context.t0 === 'bluzelle' ? 9 : _context.t0 === 'nkn' ? 12 : _context.t0 === 'boilerplate' ? 15 : 18;
break;

case 9:
_context.next = 11;
return bluzelleHandler();

case 11:
return _context.abrupt("break", 15);
return _context.abrupt("break", 18);

case 12:
_context.next = 14;
return nknHandler();

case 14:
return _context.abrupt("break", 15);
return _context.abrupt("break", 18);

case 15:
_context.next = 17;
return boilerplateHandler(name, library);

case 17:
return _context.abrupt("break", 18);

case 18:
Spinner.stop();
Log.SuccessLog("==== Install package ".concat(packageName, " Successfully ===="));
_context.next = 24;
_context.next = 27;
break;

case 19:
_context.prev = 19;
case 22:
_context.prev = 22;
_context.t1 = _context["catch"](0);
Spinner.stop();
Log.ErrorLog('something went wrong!');
console.error(_context.t1);

case 24:
case 27:
case "end":
return _context.stop();
}
}
}, _callee, this, [[0, 19]]);
}, _callee, this, [[0, 22]]);
}));
return _handler.apply(this, arguments);
}

module.exports = function (yargs) {
var command = 'add';
var commandDescription = 'To install kaizen plugin in your project';
var command = 'add <package>';
var commandDescription = 'To install kaizen package in your project';
yargs.command(command, commandDescription, builder, handler);
};
7 changes: 4 additions & 3 deletions build/components/AddPlugin/nkn.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports =
_asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee() {
var userConfig;
var configPath, userConfig;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
Expand All @@ -25,7 +25,8 @@ regeneratorRuntime.mark(function _callee() {

case 2:
// update user's kaizen config
userConfig = fsx.readJsonSync(path.resolve('./', 'kaizen.json'));
configPath = path.resolve('./', 'kaizen.json');
userConfig = fsx.existsSync(configPath) ? fsx.readJsonSync(configPath) : {};

if (!userConfig.plugins) {
userConfig.plugins = [];
Expand All @@ -37,7 +38,7 @@ regeneratorRuntime.mark(function _callee() {

fsx.outputJsonSync(path.resolve('./', 'kaizen.json'), userConfig);

case 6:
case 7:
case "end":
return _context.stop();
}
Expand Down