All files / builds/1000i100/quiz-maker/src buildResultViewers.js

0% Statements 0/34
0% Branches 0/1
0% Functions 0/1
0% Lines 0/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                                                                     
const fs = require("fs");
const ejs = require('ejs');

let str = `const resultViewers = {};
`;
function splitNameExt(fileName){
	const pathParts = fileName.split('/');
	const fileNameParts = pathParts.pop().split('.');
	let path = pathParts.join('/');
	if(path) path+='/';
	let ext = '.'+fileNameParts.pop();
	let name = fileNameParts.join('.');
	return {path,name,ext}
}
fs.readdirSync('./src/resultViewer').forEach((fileName)=>{
	const filePath = `./src/resultViewer/${fileName}`;
	let f = splitNameExt(filePath);
	if(f.ext==='.html') return;
  if(f.ext ==='.mjs') f.path = '../../src/resultViewer/';
  if(f.ext==='.ejs'){
		f = splitNameExt(f.path+f.name);
		f.path = './rv.';
		fs.writeFileSync(`./generated/tmp/${f.path+f.name+f.ext}`, ejs.render(fs.readFileSync(filePath, 'utf8'),{},{filename:filePath}));
	}
	str+=`
import ${f.name==='default'?'defaultView':f.name} from "${f.path+f.name+f.ext}";
resultViewers['${f.name}'] = ${f.name==='default'?'defaultView':f.name};
`;
});
str+=`
export default resultViewers;
`;

fs.writeFileSync(`./generated/tmp/importAll.mjs`, str);