Commit d5737799 by Иван Кубота

bin cli tool

parent b67d20f2
Pipeline #519 canceled with stage
#!/usr/bin/env node --experimental-modules
const yargs = require("yargs"),
fs = require('fs');
const options = yargs
.usage("Usage: -n <name>")
.option("r", { alias: "random", describe: "full random photo and multiple generator", type: "boolean"})
.option("m", { alias: "multiple", describe: "multiple answers", type: "boolean"})
.option("p", { alias: "photo", describe: "quiz with photo", type: "boolean"})
.option("s", { alias: "seed", describe: "random seed", type: "string"})
.option("v", { alias: "verbose", describe: "print log", type: "string"})
.option("n", { alias: "nolog", describe: "no text log in object", type: "boolean"})
.argv;
const greeting = `Hello, ${options.name}!`;
const sources = [
"js/releasable-observer.js",
"js/pcg-base.js",
"js/pcg-dom-util.js",
"js/helpers/rand.js",
"js/model/store.js",
"js/model/data.js",
"js/model/provider.js",
"js/model/slice/productTable.js",
"js/model/tag.js",
"js/model/product.js",
"js/helpers/textFilter.js",
"js/helpers/answer.js",
"js/controller/quizBits/main.js",
"js/controller/quizGenerator.js",
"js/controller/quizBits/checkbox.js",
"js/controller/quizBits/radio.js"
];
var js = sources.map(a=>'./public/'+a).map(n=>fs.readFileSync(n)+'').join('\n\n');
const data = require("../db.js");
const body = 'const window = {};'+js+'; return {quizGenerator, initDataProvider, seeded: Math.random.seeded}';
var ctx = new Function('',body)();
//console.log(options);
data.after = function() {
ctx.initDataProvider( data );
if(options.seed)
ctx.seeded.setStringSeed(options.seed);
const result = ctx.quizGenerator( options.multiple?'checkbox':'radio', options.photo);
if(options.verbose){
console.log( result.log.join( '\n' ) )
}else{
if(options.nolog)
delete result.log;
console.log('--- START ---\n\n'+JSON.stringify(result,null,2)+'\n\n--- END ---')
}
};
//console.log(greeting);
/*const fs = require('fs');
fs.readFileSync()*/
/*
*/
\ No newline at end of file
import csv from 'csv-parser';
import fs from 'fs';
const csv = require('csv-parser'),
fs = require('fs');
const readCSV = async function(scope) {
const {fileName, types, keys, index} = scope,
......@@ -31,7 +31,7 @@ const readCSV = async function(scope) {
const connections = JSON.parse(fs.readFileSync('./data/connections.json')+'');
const tags = JSON.parse(fs.readFileSync('./data/tags.json')+'');
export const data = {tags, connections};
data = {tags, connections};
(async()=>{
data.components = await readCSV({
fileName: './data/components.csv',
......@@ -69,7 +69,7 @@ export const data = {tags, connections};
},
index: 'id'
});
data.after && data.after(data);
})();
......@@ -82,3 +82,4 @@ const mapper = {
name: String
};
module.exports = data;
\ No newline at end of file
......@@ -4,9 +4,9 @@ const APP_HOST = env.APP_HOST || "127.0.0.1";
const APP_PORT = env.APP_PORT || 4000;
const DB_PATH = env.DB_PATH || "./db/users.json";
import {data} from "./db.js";
import App from 'express';
import Router from 'node-async-router';
const data = require("./db.js");
const App = require('express');
const Router = require('node-async-router');
const app = App(),
router = Router();
......@@ -14,7 +14,7 @@ const app = App(),
import fs from 'fs';
const fs = require( 'fs' );
const tpls = {
index: fs.readFileSync('./index.html')+''
......
{
"type": "module",
"name": "kus-quizard",
"version": "0.1.0",
"main": "bin/index.js",
"dependencies": {
"csv-parser": "^2.3.2",
"express": "^4.17.1",
"node-async-router": "^0.0.2"
"node-async-router": "^0.0.2",
"yargs": "^15.1.0"
},
"scripts": {
"start": "node --experimental-modules index.js"
},
"bin": {
"kus-quizard": "./bin/index.js"
}
}
......@@ -168,8 +168,6 @@ quizTypes.radio = [
if(may.length<2)
return false;
//console.clear()
//const addAnswersCount = Math.min(rand(this.answers.from, this.answers.to)-out.length, may.length);
const answer = rand(may);
......@@ -181,18 +179,6 @@ quizTypes.radio = [
log.push('\n << '+ answer.text);
/*
for(let i = 0; i < addAnswersCount; i++){
if(may.length-i<0)
break;
const idx = Math.random()*(may.length-i)|0;
if(idx>=may.length || idx < 0)debugger
console.log(i, may[idx], may)
out.push({correct: true, text: may[idx]});
may[idx] = may[may.length - 1 - i]
}*/
console.log(dP.Product.getTags(product), donors)
return out;
}
}];
\ No newline at end of file
......@@ -50,7 +50,7 @@ const shuffle = function (a) {
[a[i], a[j]] = [a[j], a[i]];
}
return a;
}
};
const quizGenerator = function(type, photo, subType) {
return _quizGenerator(type, photo, subType);
},
......@@ -91,7 +91,7 @@ const quizGenerator = function(type, photo, subType) {
// давай по новой
return _quizGenerator( type, photo, subType, attempt + 1 );
}
return {question: cfg.question.call(cfg, source, log), answers, log}
return {question: cfg.question.call(cfg, source, log), answers, log, type, image: !photo?'':true, category: 1}
};
......
......@@ -161,9 +161,8 @@ const textFormat = function(text, html) {
out = out.trim();
if(out.length>70)
out = out[0].toUpperCase()+out.substr(1);
console.log(income);
console.log(out);
/*console.log(income);
console.log(out);*/
return out;
};
\ No newline at end of file
......@@ -16,7 +16,7 @@ const store = new Store({
try{
var data = JSON.parse( localStorage.getItem( 'store' ) );
console.log(data)
window.addEventListener && console.log(data)
for(var k in data){
store.set(k, data[k]);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment