🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

gitquiz

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gitquiz - npm Package Compare versions

Comparing version
0.0.1
to
0.0.2
+417
-126
build/index.js

@@ -10,2 +10,4 @@ #! /usr/bin/env node

var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));

@@ -59,3 +61,30 @@

function addQuestionToJson(_x, _x2) {
function writeJsonToQuizFile(_x) {
return _writeJsonToQuizFile.apply(this, arguments);
}
function _writeJsonToQuizFile() {
_writeJsonToQuizFile = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee3(json) {
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return _fsExtra["default"].outputJson(_paths.questionsJsonPath, json, {
spaces: 2
});
case 2:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
return _writeJsonToQuizFile.apply(this, arguments);
}
function addQuestionToJson(_x2, _x3) {
return _addQuestionToJson.apply(this, arguments);

@@ -67,6 +96,6 @@ }

/*#__PURE__*/
_regenerator["default"].mark(function _callee3(question, answer) {
return _regenerator["default"].wrap(function _callee3$(_context3) {
_regenerator["default"].mark(function _callee4(question, answer) {
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) {
switch (_context3.prev = _context3.next) {
switch (_context4.prev = _context4.next) {
case 0:

@@ -82,3 +111,3 @@ if (!quizJson.questions) {

});
_context3.next = 4;
_context4.next = 4;
return writeQuizJsonToFile();

@@ -88,6 +117,6 @@

case "end":
return _context3.stop();
return _context4.stop();
}
}
}, _callee3);
}, _callee4);
}));

@@ -120,22 +149,22 @@ return _addQuestionToJson.apply(this, arguments);

/*#__PURE__*/
_regenerator["default"].mark(function _callee4() {
var _ref2, question, _ref3, answer;
_regenerator["default"].mark(function _callee5() {
var _ref4, question, _ref5, answer;
return _regenerator["default"].wrap(function _callee4$(_context4) {
return _regenerator["default"].wrap(function _callee5$(_context5) {
while (1) {
switch (_context4.prev = _context4.next) {
switch (_context5.prev = _context5.next) {
case 0:
_context4.next = 2;
_context5.next = 2;
return collectQuestion();
case 2:
_ref2 = _context4.sent;
question = _ref2.question;
_context4.next = 6;
_ref4 = _context5.sent;
question = _ref4.question;
_context5.next = 6;
return collectAnswer();
case 6:
_ref3 = _context4.sent;
answer = _ref3.answer;
return _context4.abrupt("return", {
_ref5 = _context5.sent;
answer = _ref5.answer;
return _context5.abrupt("return", {
question: question,

@@ -147,6 +176,6 @@ answer: answer

case "end":
return _context4.stop();
return _context5.stop();
}
}
}, _callee4);
}, _callee5);
}));

@@ -163,17 +192,17 @@ return _collectQuestionAndAnswer.apply(this, arguments);

/*#__PURE__*/
_regenerator["default"].mark(function _callee5() {
var _ref4, question, answer;
_regenerator["default"].mark(function _callee6() {
var _ref6, question, answer;
return _regenerator["default"].wrap(function _callee5$(_context5) {
return _regenerator["default"].wrap(function _callee6$(_context6) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context6.prev = _context6.next) {
case 0:
_context5.next = 2;
_context6.next = 2;
return collectQuestionAndAnswer();
case 2:
_ref4 = _context5.sent;
question = _ref4.question;
answer = _ref4.answer;
_context5.next = 7;
_ref6 = _context6.sent;
question = _ref6.question;
answer = _ref6.answer;
_context6.next = 7;
return addQuestionToJson(question, (0, _encrypt["default"])(answer));

@@ -183,6 +212,6 @@

case "end":
return _context5.stop();
return _context6.stop();
}
}
}, _callee5);
}, _callee6);
}));

@@ -193,3 +222,12 @@ return _handleAddQuestion.apply(this, arguments);

function getQuestions() {
return quizJson.questions || [];
var json = JSON.parse(_fs["default"].readFileSync(_paths.questionsJsonPath, 'utf8'));
var q = json.questions || [];
var questions = q.reduce(function (acc, curr) {
if (curr.group) {
return acc.concat(curr.questions);
}
return acc.concat(curr);
}, []);
return questions;
}

@@ -204,3 +242,3 @@

function editQuestionJsonById(_x3, _x4, _x5) {
function editQuestionJsonById(_x4, _x5, _x6) {
return _editQuestionJsonById.apply(this, arguments);

@@ -212,7 +250,7 @@ }

/*#__PURE__*/
_regenerator["default"].mark(function _callee6(questionId, newQuestion, newAnswer) {
_regenerator["default"].mark(function _callee7(questionId, newQuestion, newAnswer) {
var question;
return _regenerator["default"].wrap(function _callee6$(_context6) {
return _regenerator["default"].wrap(function _callee7$(_context7) {
while (1) {
switch (_context6.prev = _context6.next) {
switch (_context7.prev = _context7.next) {
case 0:

@@ -222,3 +260,3 @@ question = getQuestionById(questionId);

if (question) {
_context6.next = 4;
_context7.next = 4;
break;

@@ -228,3 +266,3 @@ }

console.log('Question with that ID does not exist');
return _context6.abrupt("return");
return _context7.abrupt("return");

@@ -240,3 +278,3 @@ case 4:

_context6.next = 8;
_context7.next = 8;
return writeQuizJsonToFile();

@@ -246,6 +284,6 @@

case "end":
return _context6.stop();
return _context7.stop();
}
}
}, _callee6);
}, _callee7);
}));

@@ -255,3 +293,3 @@ return _editQuestionJsonById.apply(this, arguments);

function handleEditQuestion(_x6) {
function handleEditQuestion() {
return _handleEditQuestion.apply(this, arguments);

@@ -263,13 +301,24 @@ }

/*#__PURE__*/
_regenerator["default"].mark(function _callee7(questionId) {
var question, editTypePromt, editType, _ref5, newQuestion, _ref6, answer;
_regenerator["default"].mark(function _callee8() {
var _ref7,
_ref8,
questionId,
question,
editTypePromt,
editType,
_ref9,
newQuestion,
_ref10,
answer,
_args8 = arguments;
return _regenerator["default"].wrap(function _callee7$(_context7) {
return _regenerator["default"].wrap(function _callee8$(_context8) {
while (1) {
switch (_context7.prev = _context7.next) {
switch (_context8.prev = _context8.next) {
case 0:
_ref7 = _args8.length > 0 && _args8[0] !== undefined ? _args8[0] : [], _ref8 = (0, _slicedToArray2["default"])(_ref7, 1), questionId = _ref8[0];
question = getQuestionById(questionId);
if (question) {
_context7.next = 4;
_context8.next = 5;
break;

@@ -279,5 +328,5 @@ }

console.log('Question with that ID does not exist');
return _context7.abrupt("return");
return _context8.abrupt("return");
case 4:
case 5:
editTypePromt = new _enquirer.Select({

@@ -288,43 +337,43 @@ name: 'editType',

});
_context7.next = 7;
_context8.next = 8;
return editTypePromt.run();
case 7:
editType = _context7.sent;
case 8:
editType = _context8.sent;
if (!(editType === 'Question')) {
_context7.next = 16;
_context8.next = 17;
break;
}
_context7.next = 11;
_context8.next = 12;
return collectQuestion();
case 11:
_ref5 = _context7.sent;
newQuestion = _ref5.question;
case 12:
_ref9 = _context8.sent;
newQuestion = _ref9.question;
editQuestionJsonById(questionId, newQuestion);
_context7.next = 22;
_context8.next = 23;
break;
case 16:
case 17:
if (!(editType === 'Answer')) {
_context7.next = 22;
_context8.next = 23;
break;
}
_context7.next = 19;
_context8.next = 20;
return collectAnswer();
case 19:
_ref6 = _context7.sent;
answer = _ref6.answer;
case 20:
_ref10 = _context8.sent;
answer = _ref10.answer;
editQuestionJsonById(questionId, null, answer);
case 22:
case 23:
case "end":
return _context7.stop();
return _context8.stop();
}
}
}, _callee7);
}, _callee8);
}));

@@ -341,7 +390,7 @@ return _handleEditQuestion.apply(this, arguments);

/*#__PURE__*/
_regenerator["default"].mark(function _callee8(questionId) {
_regenerator["default"].mark(function _callee9(questionId) {
var question;
return _regenerator["default"].wrap(function _callee8$(_context8) {
return _regenerator["default"].wrap(function _callee9$(_context9) {
while (1) {
switch (_context8.prev = _context8.next) {
switch (_context9.prev = _context9.next) {
case 0:

@@ -351,3 +400,3 @@ question = getQuestionById(questionId);

if (question) {
_context8.next = 4;
_context9.next = 4;
break;

@@ -357,3 +406,3 @@ }

console.log('Question with that ID does not exist');
return _context8.abrupt("return");
return _context9.abrupt("return");

@@ -366,3 +415,3 @@ case 4:

});
_context8.next = 7;
_context9.next = 7;
return writeQuizJsonToFile();

@@ -372,6 +421,6 @@

case "end":
return _context8.stop();
return _context9.stop();
}
}
}, _callee8);
}, _callee9);
}));

@@ -381,3 +430,7 @@ return _removeQuestionJsonById.apply(this, arguments);

function handleRemoveQuestion(questionId) {
function handleRemoveQuestion() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [],
_ref2 = (0, _slicedToArray2["default"])(_ref, 1),
questionId = _ref2[0];
var question = getQuestionById(questionId);

@@ -394,8 +447,30 @@

function handleHelp() {
var commands = ['init', 'add', 'edit [id]', 'rm [id]', 'ls'];
var commands = ['init', 'add', // 'edit [id]',
// 'rm [id]',
// 'ls',
'preview', 'encrypt', 'id', 'groups add', 'validate'];
console.log("".concat(commands.join('\n')));
}
function arrayDiff(a, b) {
return a.filter(function (x) {
return !b.includes(x);
});
}
function validateQuizItem(item) {
if (arrayDiff(Object.keys(item), ['answer', 'id', 'question']).length) {
console.log("ID: ".concat(item.id, "\nQ: ").concat(item.question));
console.log('Error: Quiz items must only have `answer`, `id` and `question` keys\n\n');
return false;
}
return true;
}
function validateQuizJson() {
var valid = true;
if (!_fs["default"].existsSync(_paths.questionsJsonPath)) {
console.log("No quiz.json at ".concat(_paths.questionsJsonPath));
return true;

@@ -412,2 +487,3 @@ }

if (!(parsedJson.questions && Array.isArray(parsedJson.questions))) {
console.log('Must have top-level `questions` array');
return false;

@@ -418,6 +494,34 @@ }

if (keys.length && keys[0] !== 'questions') {
if (keys.length > 1) {
console.log('Must only have top-level `questions` array');
return false;
}
parsedJson.questions.forEach(function (q) {
if (q.group) {
if (arrayDiff(Object.keys(q), ['group', 'questions']).length) {
console.log('Groups must only have `group` and `questions` keys');
valid = false;
}
if (!Array.isArray(q.questions)) {
console.log('Group questions must be an array');
valid = false;
}
q.questions.forEach(function (question) {
if (!validateQuizItem(question)) {
valid = false;
}
});
} else if (!validateQuizItem(q)) {
valid = false;
}
});
if (!valid) {
return false;
}
} catch (err) {
console.log('Error parsing JSON', err);
return false;

@@ -441,10 +545,10 @@ }

/*#__PURE__*/
_regenerator["default"].mark(function _callee9() {
var _ref7, key, beginText, endText, keyBegin, keyEnd, keyContents;
_regenerator["default"].mark(function _callee10() {
var _ref11, key, beginText, endText, keyBegin, keyEnd, keyContents;
return _regenerator["default"].wrap(function _callee9$(_context9) {
return _regenerator["default"].wrap(function _callee10$(_context10) {
while (1) {
switch (_context9.prev = _context9.next) {
switch (_context10.prev = _context10.next) {
case 0:
_context9.next = 2;
_context10.next = 2;
return (0, _enquirer.prompt)({

@@ -457,4 +561,4 @@ type: 'input',

case 2:
_ref7 = _context9.sent;
key = _ref7.key;
_ref11 = _context10.sent;
key = _ref11.key;
beginText = '-----BEGIN PUBLIC KEY-----';

@@ -466,3 +570,3 @@ endText = '-----END PUBLIC KEY-----';

if (keyBegin === beginText && keyEnd === endText) {
_context9.next = 11;
_context10.next = 11;
break;

@@ -472,7 +576,7 @@ }

console.log('Invalid key');
return _context9.abrupt("return");
return _context10.abrupt("return");
case 11:
keyContents = key.replace(beginText, '').replace(endText, '');
_context9.next = 14;
_context10.next = 14;
return writeKeyToFile("".concat(keyBegin, "\n").concat(keyContents, "\n").concat(keyEnd));

@@ -482,6 +586,6 @@

case "end":
return _context9.stop();
return _context10.stop();
}
}
}, _callee9);
}, _callee10);
}));

@@ -493,12 +597,16 @@ return _handleInit.apply(this, arguments);

return _handleList.apply(this, arguments);
}
} // function getQuestions() {
// const json = quizJson || {};
// return json.questions || [];
// }
function _handleList() {
_handleList = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee10() {
_regenerator["default"].mark(function _callee11() {
var questions, questionsToLog;
return _regenerator["default"].wrap(function _callee10$(_context10) {
return _regenerator["default"].wrap(function _callee11$(_context11) {
while (1) {
switch (_context10.prev = _context10.next) {
switch (_context11.prev = _context11.next) {
case 0:

@@ -508,7 +616,7 @@ questions = getQuestions();

if (questions.length) {
_context10.next = 3;
_context11.next = 3;
break;
}
return _context10.abrupt("return");
return _context11.abrupt("return");

@@ -523,6 +631,6 @@ case 3:

case "end":
return _context10.stop();
return _context11.stop();
}
}
}, _callee10);
}, _callee11);
}));

@@ -532,2 +640,165 @@ return _handleList.apply(this, arguments);

function handleEncrypt() {
return _handleEncrypt.apply(this, arguments);
}
function _handleEncrypt() {
_handleEncrypt = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee12() {
var _ref12, text, encrypted;
return _regenerator["default"].wrap(function _callee12$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
_context12.next = 2;
return (0, _enquirer.prompt)({
type: 'input',
name: 'text',
message: 'Enter text to encrypt:'
});
case 2:
_ref12 = _context12.sent;
text = _ref12.text;
encrypted = (0, _encrypt["default"])(text);
console.log(encrypted);
case 6:
case "end":
return _context12.stop();
}
}
}, _callee12);
}));
return _handleEncrypt.apply(this, arguments);
}
function handlePreview() {
return _handlePreview.apply(this, arguments);
}
function _handlePreview() {
_handlePreview = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee13() {
var questions, preview;
return _regenerator["default"].wrap(function _callee13$(_context13) {
while (1) {
switch (_context13.prev = _context13.next) {
case 0:
questions = quizJson.questions || [];
preview = '';
questions.forEach(function (q) {
if (q.group) {
preview += "(".concat(q.group, ")");
preview += '\n';
q.questions.forEach(function (groupQ) {
preview += '|';
preview += '--';
preview += groupQ.question;
preview += '\n';
});
} else {
preview += q.question;
preview += '\n';
}
});
console.log(preview.trim());
case 4:
case "end":
return _context13.stop();
}
}
}, _callee13);
}));
return _handlePreview.apply(this, arguments);
}
function handleId() {
return _handleId.apply(this, arguments);
}
function _handleId() {
_handleId = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee14() {
return _regenerator["default"].wrap(function _callee14$(_context14) {
while (1) {
switch (_context14.prev = _context14.next) {
case 0:
console.log(_nodeUuid["default"].v4());
case 1:
case "end":
return _context14.stop();
}
}
}, _callee14);
}));
return _handleId.apply(this, arguments);
}
function getJson() {
var json = quizJson || {};
json.questions = json.questions || [];
return json;
}
function handleGroups() {
return _handleGroups.apply(this, arguments);
}
function _handleGroups() {
_handleGroups = (0, _asyncToGenerator2["default"])(
/*#__PURE__*/
_regenerator["default"].mark(function _callee15() {
var _ref13,
_ref14,
action,
_ref15,
groupName,
json,
_args15 = arguments;
return _regenerator["default"].wrap(function _callee15$(_context15) {
while (1) {
switch (_context15.prev = _context15.next) {
case 0:
_ref13 = _args15.length > 0 && _args15[0] !== undefined ? _args15[0] : [], _ref14 = (0, _slicedToArray2["default"])(_ref13, 1), action = _ref14[0];
if (!(action === 'add')) {
_context15.next = 9;
break;
}
_context15.next = 4;
return (0, _enquirer.prompt)({
type: 'input',
name: 'groupName',
message: 'Group name:'
});
case 4:
_ref15 = _context15.sent;
groupName = _ref15.groupName;
json = getJson();
json.questions.push({
group: groupName,
questions: []
});
writeJsonToQuizFile(json);
case 9:
case "end":
return _context15.stop();
}
}
}, _callee15);
}));
return _handleGroups.apply(this, arguments);
}
function handleCommand(_x8, _x9) {

@@ -540,39 +811,51 @@ return _handleCommand.apply(this, arguments);

/*#__PURE__*/
_regenerator["default"].mark(function _callee11(command, args) {
return _regenerator["default"].wrap(function _callee11$(_context11) {
_regenerator["default"].mark(function _callee16(command, args) {
return _regenerator["default"].wrap(function _callee16$(_context16) {
while (1) {
switch (_context11.prev = _context11.next) {
switch (_context16.prev = _context16.next) {
case 0:
_context11.t0 = command;
_context11.next = _context11.t0 === 'add' ? 3 : _context11.t0 === 'edit' ? 4 : _context11.t0 === 'rm' ? 5 : _context11.t0 === 'help' ? 6 : _context11.t0 === 'init' ? 7 : _context11.t0 === 'ls' ? 8 : 9;
_context16.t0 = command;
_context16.next = _context16.t0 === 'add' ? 3 : _context16.t0 === 'edit' ? 4 : _context16.t0 === 'rm' ? 5 : _context16.t0 === 'help' ? 6 : _context16.t0 === 'init' ? 7 : _context16.t0 === 'ls' ? 8 : _context16.t0 === 'preview' ? 9 : _context16.t0 === 'encrypt' ? 10 : _context16.t0 === 'id' ? 11 : _context16.t0 === 'groups' ? 12 : 13;
break;
case 3:
return _context11.abrupt("return", handleAddQuestion());
return _context16.abrupt("return", handleAddQuestion());
case 4:
return _context11.abrupt("return", handleEditQuestion(args));
return _context16.abrupt("return", handleEditQuestion(args));
case 5:
return _context11.abrupt("return", handleRemoveQuestion(args));
return _context16.abrupt("return", handleRemoveQuestion(args));
case 6:
return _context11.abrupt("return", handleHelp(command));
return _context16.abrupt("return", handleHelp(command));
case 7:
return _context11.abrupt("return", handleInit());
return _context16.abrupt("return", handleInit());
case 8:
return _context11.abrupt("return", handleList());
return _context16.abrupt("return", handleList());
case 9:
return _context16.abrupt("return", handlePreview());
case 10:
return _context16.abrupt("return", handleEncrypt());
case 11:
return _context16.abrupt("return", handleId());
case 12:
return _context16.abrupt("return", handleGroups(args));
case 13:
console.log('Invalid command');
return _context11.abrupt("return", null);
return _context16.abrupt("return", null);
case 11:
case 15:
case "end":
return _context11.stop();
return _context16.stop();
}
}
}, _callee11);
}, _callee16);
}));

@@ -591,27 +874,35 @@ return _handleCommand.apply(this, arguments);

case 0:
_argv$_ = (0, _slicedToArray2["default"])(argv._, 2), command = _argv$_[0], commandArgs = _argv$_[1];
_argv$_ = (0, _toArray2["default"])(argv._), command = _argv$_[0], commandArgs = _argv$_.slice(1);
if (validateQuizJson()) {
_context.next = 4;
_context.next = 3;
break;
}
console.log('Invalid json');
return _context.abrupt("return");
case 4:
_context.prev = 4;
_context.next = 7;
case 3:
if (!(command === 'validate')) {
_context.next = 6;
break;
}
console.log('Valid quiz.json');
return _context.abrupt("return");
case 6:
_context.prev = 6;
_context.next = 9;
return handleCommand(command, commandArgs);
case 7:
_context.next = 12;
case 9:
_context.next = 14;
break;
case 9:
_context.prev = 9;
_context.t0 = _context["catch"](4);
case 11:
_context.prev = 11;
_context.t0 = _context["catch"](6);
console.log('bye', _context.t0);
case 12:
case 14:
case "end":

@@ -621,3 +912,3 @@ return _context.stop();

}
}, _callee, null, [[4, 9]]);
}, _callee, null, [[6, 11]]);
}))();
{
"name": "gitquiz",
"version": "0.0.1",
"version": "0.0.2",
"main": "index.js",

@@ -5,0 +5,0 @@ "license": "MIT",