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'; const csv = require('csv-parser'),
import fs from 'fs'; fs = require('fs');
const readCSV = async function(scope) { const readCSV = async function(scope) {
const {fileName, types, keys, index} = scope, const {fileName, types, keys, index} = scope,
...@@ -31,7 +31,7 @@ const readCSV = async function(scope) { ...@@ -31,7 +31,7 @@ const readCSV = async function(scope) {
const connections = JSON.parse(fs.readFileSync('./data/connections.json')+''); const connections = JSON.parse(fs.readFileSync('./data/connections.json')+'');
const tags = JSON.parse(fs.readFileSync('./data/tags.json')+''); const tags = JSON.parse(fs.readFileSync('./data/tags.json')+'');
export const data = {tags, connections}; data = {tags, connections};
(async()=>{ (async()=>{
data.components = await readCSV({ data.components = await readCSV({
fileName: './data/components.csv', fileName: './data/components.csv',
...@@ -69,7 +69,7 @@ export const data = {tags, connections}; ...@@ -69,7 +69,7 @@ export const data = {tags, connections};
}, },
index: 'id' index: 'id'
}); });
data.after && data.after(data);
})(); })();
...@@ -82,3 +82,4 @@ const mapper = { ...@@ -82,3 +82,4 @@ const mapper = {
name: String 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"; ...@@ -4,9 +4,9 @@ const APP_HOST = env.APP_HOST || "127.0.0.1";
const APP_PORT = env.APP_PORT || 4000; const APP_PORT = env.APP_PORT || 4000;
const DB_PATH = env.DB_PATH || "./db/users.json"; const DB_PATH = env.DB_PATH || "./db/users.json";
import {data} from "./db.js"; const data = require("./db.js");
import App from 'express'; const App = require('express');
import Router from 'node-async-router'; const Router = require('node-async-router');
const app = App(), const app = App(),
router = Router(); router = Router();
...@@ -14,7 +14,7 @@ const app = App(), ...@@ -14,7 +14,7 @@ const app = App(),
import fs from 'fs'; const fs = require( 'fs' );
const tpls = { const tpls = {
index: fs.readFileSync('./index.html')+'' index: fs.readFileSync('./index.html')+''
......
{ {
"type": "module", "name": "kus-quizard",
"version": "0.1.0",
"main": "bin/index.js",
"dependencies": { "dependencies": {
"csv-parser": "^2.3.2", "csv-parser": "^2.3.2",
"express": "^4.17.1", "express": "^4.17.1",
"node-async-router": "^0.0.2" "node-async-router": "^0.0.2",
"yargs": "^15.1.0"
}, },
"scripts": { "scripts": {
"start": "node --experimental-modules index.js" "start": "node --experimental-modules index.js"
},
"bin": {
"kus-quizard": "./bin/index.js"
} }
} }
...@@ -168,8 +168,6 @@ quizTypes.radio = [ ...@@ -168,8 +168,6 @@ quizTypes.radio = [
if(may.length<2) if(may.length<2)
return false; return false;
//console.clear()
//const addAnswersCount = Math.min(rand(this.answers.from, this.answers.to)-out.length, may.length);
const answer = rand(may); const answer = rand(may);
...@@ -181,18 +179,6 @@ quizTypes.radio = [ ...@@ -181,18 +179,6 @@ quizTypes.radio = [
log.push('\n << '+ answer.text); 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; return out;
} }
}]; }];
\ No newline at end of file
...@@ -50,7 +50,7 @@ const shuffle = function (a) { ...@@ -50,7 +50,7 @@ const shuffle = function (a) {
[a[i], a[j]] = [a[j], a[i]]; [a[i], a[j]] = [a[j], a[i]];
} }
return a; return a;
} };
const quizGenerator = function(type, photo, subType) { const quizGenerator = function(type, photo, subType) {
return _quizGenerator(type, photo, subType); return _quizGenerator(type, photo, subType);
}, },
...@@ -91,7 +91,7 @@ const quizGenerator = function(type, photo, subType) { ...@@ -91,7 +91,7 @@ const quizGenerator = function(type, photo, subType) {
// давай по новой // давай по новой
return _quizGenerator( type, photo, subType, attempt + 1 ); 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) { ...@@ -161,9 +161,8 @@ const textFormat = function(text, html) {
out = out.trim(); out = out.trim();
if(out.length>70) if(out.length>70)
out = out[0].toUpperCase()+out.substr(1); out = out[0].toUpperCase()+out.substr(1);
console.log(income); /*console.log(income);
console.log(out);*/
console.log(out);
return out; return out;
}; };
\ No newline at end of file
...@@ -16,7 +16,7 @@ const store = new Store({ ...@@ -16,7 +16,7 @@ const store = new Store({
try{ try{
var data = JSON.parse( localStorage.getItem( 'store' ) ); var data = JSON.parse( localStorage.getItem( 'store' ) );
console.log(data) window.addEventListener && console.log(data)
for(var k in data){ for(var k in data){
store.set(k, data[k]); 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