@jutge.org/toolkit 4.2.13 → 4.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4065,7 +4065,7 @@ User question: ${f}`,v=await ZK($,Z,q);await c.markdown(v),c.warning(`This answe
|
|
|
4065
4065
|
*
|
|
4066
4066
|
* Code licensed under MIT (https://github.com/dicebear/dicebear/blob/v4/packages/initials/LICENSE)
|
|
4067
4067
|
* Copyright (c) 2024 Florian Körner
|
|
4068
|
-
*/var Zs={};KZ(Zs,{schema:()=>Bx2,meta:()=>cf5,create:()=>Lf5});var RX1={};KZ(RX1,{ringTwo:()=>Sx2,ringThree:()=>bx2,ringOne:()=>gx2,ringFour:()=>ux2,ringFive:()=>yx2,ring:()=>Lx2});var Lx2={container:(f,$)=>{var Z,w,q,v,K,H,Y,P,M,W,J,X,O,G,V,N,E,j,g,k;return`${(w=(Z=f.ringOne)===null||Z===void 0?void 0:Z.value(f,$))!==null&&w!==void 0?w:""}${(v=(q=f.ringTwo)===null||q===void 0?void 0:q.value(f,$))!==null&&v!==void 0?v:""}${(H=(K=f.ringThree)===null||K===void 0?void 0:K.value(f,$))!==null&&H!==void 0?H:""}${(P=(Y=f.ringFour)===null||Y===void 0?void 0:Y.value(f,$))!==null&&P!==void 0?P:""}${(W=(M=f.ringFive)===null||M===void 0?void 0:M.value(f,$))!==null&&W!==void 0?W:""}<g transform="matrix(1 0 0 -1 0 100)">${(X=(J=f.ringOne)===null||J===void 0?void 0:J.value(f,$))!==null&&X!==void 0?X:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(G=(O=f.ringTwo)===null||O===void 0?void 0:O.value(f,$))!==null&&G!==void 0?G:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(N=(V=f.ringThree)===null||V===void 0?void 0:V.value(f,$))!==null&&N!==void 0?N:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(j=(E=f.ringFour)===null||E===void 0?void 0:E.value(f,$))!==null&&j!==void 0?j:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(k=(g=f.ringFive)===null||g===void 0?void 0:g.value(f,$))!==null&&k!==void 0?k:""}</g><circle cx="50" cy="50" r="45" stroke="#fff" stroke-opacity=".25" stroke-width="10" style="mix-blend-mode:lighten"/><circle cx="50" cy="50" r="25" stroke="#fff" stroke-opacity=".25" stroke-width="10" style="mix-blend-mode:lighten"/><circle cx="50" cy="50" r="10" fill="#fff" fill-opacity=".25" style="mix-blend-mode:lighten"/>`}};var gx2={half:(f,$)=>`<path d="M90 50h10c0-27.614-22.386-50-50-50S0 22.386 0 50h10c0-22.091 17.909-40 40-40s40 17.909 40 40Z" fill="${x1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 10V0C22.386 0 0 22.386 0 50h10c0-22.091 17.909-40 40-40Z" fill="${x1.xml(`${$.ring}`)}"/>`,eighth:(f,$)=>`<path d="M21.716 21.716C14.477 28.954 10 38.954 10 50H0c0-13.807 5.596-26.307 14.645-35.355l7.07 7.07Z" fill="${x1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="45" stroke="${x1.xml(`${$.ring}`)}" stroke-width="10"/>`};var Sx2={eighth:(f,$)=>`<path d="M20 50c0-8.284 3.358-15.784 8.787-21.213l-7.071-7.071C14.477 28.954 10 38.954 10 50h10Z" fill="${x1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 10c-22.091 0-40 17.909-40 40h10c0-16.569 13.431-30 30-30V10Z" fill="${x1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M90 50c0-22.091-17.909-40-40-40S10 27.909 10 50h10c0-16.569 13.431-30 30-30 16.569 0 30 13.431 30 30h10Z" fill="${x1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="35" stroke="${x1.xml(`${$.ring}`)}" stroke-width="10"/>`};var bx2={eighth:(f,$)=>`<path d="M30 50a19.937 19.937 0 0 1 5.858-14.142l-7.071-7.071C23.357 34.216 20 41.716 20 50h10Z" fill="${x1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 20c-16.569 0-30 13.431-30 30h10c0-11.046 8.954-20 20-20V20Z" fill="${x1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M80 50c0-16.569-13.431-30-30-30-16.569 0-30 13.431-30 30h10c0-11.046 8.954-20 20-20s20 8.954 20 20h10Z" fill="${x1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="25" stroke="${x1.xml(`${$.ring}`)}" stroke-width="10"/>`};var ux2={eighth:(f,$)=>`<path d="M40 50a9.97 9.97 0 0 1 2.929-7.071l-7.071-7.071A19.937 19.937 0 0 0 30 50h10Z" fill="${x1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 30c-11.046 0-20 8.954-20 20h10c0-5.523 4.477-10 10-10V30Z" fill="${x1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M70 50c0-11.046-8.954-20-20-20s-20 8.954-20 20h10c0-5.523 4.477-10 10-10s10 4.477 10 10h10Z" fill="${x1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="15" stroke="${x1.xml(`${$.ring}`)}" stroke-width="10"/>`};var yx2={eighth:(f,$)=>`<path d="m42.929 42.929 7.07 7.07H40a9.97 9.97 0 0 1 2.93-7.07Z" fill="${x1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 40v10H40c0-5.523 4.477-10 10-10Z" fill="${x1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M60 50c0-5.523-4.477-10-10-10s-10 4.477-10 10h20Z" fill="${x1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="10" fill="${x1.xml(`${$.ring}`)}"/>`};function HA({prng:f,group:$,width:Z,height:w,values:q=[],rotation:v,offsetX:K,offsetY:H}){let Y=RX1,P=f.pick(q),M=f.integer(Math.min(...v),Math.max(...v)),W=f.integer(Math.min(...K),Math.max(...K)),J=f.integer(Math.min(...H),Math.max(...H));if(P&&Y[$][P])return{name:P,value(X,O){var G,V,N;let E=Y[$][P](X,O);if(this.rotation||this.offsetX||this.offsetY)E=`<g transform="translate(${(G=this.offsetX)!==null&&G!==void 0?G:0}, ${(V=this.offsetY)!==null&&V!==void 0?V:0}) rotate(${(N=this.rotation)!==null&&N!==void 0?N:0} ${Z/2} ${w/2})">${E}</g>`;return E},rotation:M,offsetX:W,offsetY:J};else return}function kx2({prng:f,options:$}){var Z,w,q,v,K,H;let Y=HA({prng:f,group:"ring",values:$.ring,width:100,height:100,rotation:((Z=$.ringRotation)===null||Z===void 0?void 0:Z.length)?$.ringRotation:[0],offsetX:[0],offsetY:[0]}),P=HA({prng:f,group:"ringOne",values:$.ringOne,width:100,height:100,rotation:((w=$.ringOneRotation)===null||w===void 0?void 0:w.length)?$.ringOneRotation:[0],offsetX:[0],offsetY:[0]}),M=HA({prng:f,group:"ringTwo",values:$.ringTwo,width:100,height:100,rotation:((q=$.ringTwoRotation)===null||q===void 0?void 0:q.length)?$.ringTwoRotation:[0],offsetX:[0],offsetY:[0]}),W=HA({prng:f,group:"ringThree",values:$.ringThree,width:100,height:100,rotation:((v=$.ringThreeRotation)===null||v===void 0?void 0:v.length)?$.ringThreeRotation:[0],offsetX:[0],offsetY:[0]}),J=HA({prng:f,group:"ringFour",values:$.ringFour,width:100,height:100,rotation:((K=$.ringFourRotation)===null||K===void 0?void 0:K.length)?$.ringFourRotation:[0],offsetX:[0],offsetY:[0]}),X=HA({prng:f,group:"ringFive",values:$.ringFive,width:100,height:100,rotation:((H=$.ringFiveRotation)===null||H===void 0?void 0:H.length)?$.ringFiveRotation:[0],offsetX:[0],offsetY:[0]});return{ring:Y,ringOne:P,ringTwo:M,ringThree:W,ringFour:J,ringFive:X}}function mx2(f){return f==="transparent"?f:`#${f}`}function xx2({prng:f,options:$}){var Z;return{ring:mx2(f.pick((Z=$.ringColor)!==null&&Z!==void 0?Z:[],"transparent"))}}var Bx2={$schema:"http://json-schema.org/draft-07/schema#",properties:{ring:{type:"array",items:{type:"string",enum:["container"]},default:["container"]},ringColor:{type:"array",items:{type:"string",pattern:"^(transparent|[a-fA-F0-9]{6})$"},default:["ffd54f","64b5f6","4dd0e1","ff8a65","9575cd","81c784","7986cb","4fc3f7","aed581","dce775","ffb74d","f06292","ba68c8","e57373","4db6ac","fff176"]},ringFive:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["full"]},ringFiveRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringFour:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["quarter","half"]},ringFourRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringOne:{type:"array",items:{type:"string",enum:["half","quarter","eighth","full"]},default:["half","quarter"]},ringOneRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringThree:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["quarter","half"]},ringThreeRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringTwo:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["quarter","half"]},ringTwoRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]}}};var cf5={title:"Rings",creator:"DiceBear",source:"https://www.dicebear.com",homepage:"https://www.dicebear.com",license:{name:"CC0 1.0",url:"https://creativecommons.org/publicdomain/zero/1.0/"}},Lf5=({prng:f,options:$})=>{var Z,w;let q=kx2({prng:f,options:$}),v=xx2({prng:f,options:$});return{attributes:{viewBox:"0 0 100 100",fill:"none","shape-rendering":"crispEdges"},body:`${(w=(Z=q.ring)===null||Z===void 0?void 0:Z.value(q,v))!==null&&w!==void 0?w:""}`,extra:()=>({...Object.entries(q).reduce((K,[H,Y])=>{return K[H]=Y===null||Y===void 0?void 0:Y.name,K},{}),...Object.entries(v).reduce((K,[H,Y])=>{return K[`${H}Color`]=Y,K},{})})}};Xz();import{cp as cZ,exists as ws,glob as TK,mkdir as AW,rm as dx2,writeFile as mf5}from"fs/promises";import{join as x2}from"path";var Ux2=f4(qo(),1);class LX1{directory;problem_nm;workspace;workDir;stagingDir;stagingDirLang="to-be-set";workDirLang="to-be-set";problem_id="to-be-set";languages=[];original_language="";problem_ymls={};handlers={};author="";author_email="";problem_type="std";constructor(f,$){this.directory=f,this.problem_nm=$,this.workspace=x2(f,o0()+"-stage",XD()),this.workDir=x2(this.workspace,"work"),this.stagingDir=x2(this.workspace,"stage",this.problem_nm)}async stage(){await c.section(`Staging problem at ${this.directory}`,async()=>{await this.createWorkspace(),await this.separateByLanguages(),await this.readMetadata();for(let f of this.languages)await c.section(`Staging language ${f}`,async()=>{if(await this.setLanguage(f),this.problem_type==="std")await this.stageLanguage_Std(f);else if(this.problem_type==="game")await this.stageLanguage_Game(f);else if(this.problem_type==="quiz")await this.stageLanguage_Quizz(f)});await this.stageFirstToSolve(),await this.stageInformationYml(),await this.stageReadMd()}),await c.section("Summary",async()=>{let f=x2(this.stagingDir,"README.md");c.success("README.md content:"),await c.markdown(await V5(f)),c.success("Staging tree:"),c.print(Ux2.default(this.stagingDir))}),c.success(`Staging directory: ${c.hyperlink(this.stagingDir)}`)}async stageLanguage_Std(f){await this.prepareStatements_Std(f),await this.computeCodeMetrics(f),await this.stageProblemFiles_Std(f),await this.stageAwards(f),await this.stageStatements(f),await this.stageZip_Std(f)}async stageLanguage_Game(f){await this.prepareStatements_Game(f),await this.computeCodeMetrics(f),await this.stageProblemFiles_Game(f),await this.stageAwards(f),await this.stageStatements(f),await this.stageZip_Game(f),await this.stageViewer(f)}async stageLanguage_Quizz(f){await this.stageQuiz(f)}async setLanguage(f){this.workDirLang=x2(this.workDir,f),this.problem_id=`${this.problem_nm}_${f}`,this.stagingDirLang=x2(this.stagingDir,f),await AW(this.stagingDirLang,{recursive:!0})}async createWorkspace(){await c.section(`Creating workspace ${this.workspace}`,async()=>{if(await ws(this.workspace))throw Error(`Workspace directory ${this.workspace} already exists`);await AW(this.workspace,{recursive:!0}),await AW(this.workDir,{recursive:!0}),await AW(this.stagingDir,{recursive:!0}),c.directory(this.workspace)})}doNotCopy(f,$){if(f==="problem.yml")return!0;if(f.startsWith(o0()))return!0;let Z=f.match(/^problem\.([a-z][a-z])\.[a-z]*$/);if(Z&&Z[1]!==$)return!0;if(f===`problem.${$}.pdf`)return!0;return!1}async separateByLanguages(){await c.section("Detecting if there are language folders or not",async()=>{if((await Array.fromAsync(TK("handler.yml",{cwd:this.directory}))).length===0)await this.separateByLanguagesWithFolders();else await this.separateByLanguagesWithoutFolders()})}async separateByLanguagesWithoutFolders(){await c.section("Separating problem by languages without folders",async()=>{let $=(await Array.fromAsync(TK("problem.[a-z][a-z].yml",{cwd:this.directory}))).map((Z)=>{let w=Z.match(/^problem\.([a-z][a-z])\.yml$/);if(!w)throw Error(`Unexpected yml file name: ${Z}`);return w[1]});this.languages=$;for(let Z of $){let w=x2(this.workDir,Z);await AW(w,{recursive:!0});let q=await Array.fromAsync(TK("*",{cwd:this.directory}));for(let v of q){if(this.doNotCopy(v,Z))continue;await cZ(x2(this.directory,v),x2(w,v),{recursive:!0})}}c.success(`Found languages: ${$.join(", ")}`)})}async separateByLanguagesWithFolders(){await c.section("Separating problem by languages with folders",async()=>{let f=await Array.fromAsync(TK("[a-z][a-z]",{cwd:this.directory}));this.languages=f;for(let $ of f){let Z=x2(this.directory,$),w=x2(this.workDir,$);await AW(w,{recursive:!0});let q=await Array.fromAsync(TK("*",{cwd:Z}));for(let v of q){if(this.doNotCopy(v,$))continue;await cZ(x2(Z,v),x2(w,v),{recursive:!0})}}c.success(`Found languages: ${f.join(", ")}`)})}async readMetadata(){await c.section("Reading problem metadata",async()=>{for(let $ of this.languages){let Z=x2(this.workDir,$,`problem.${$}.yml`);this.problem_ymls[$]=await W_(Z)}for(let $ of this.languages){let Z=x2(this.workDir,$,"handler.yml");this.handlers[$]=await W_(Z)}for(let $ of this.languages){let Z=this.problem_ymls[$];if(Z.author)this.author=Z.author;if(Z.author)this.original_language=$;if(Z.email)this.author_email=Z.email}if(!this.original_language)throw Error("Original language not found in problem.<lang>.yml files");let f=this.handlers[this.original_language];if(f.handler==="game")this.problem_type="game";else if(f.handler==="quiz")this.problem_type="quiz";else this.problem_type="std";c.success(`Problem type: ${this.problem_type}`),c.success(`Original language: ${this.original_language}`),c.success(`Author: ${this.author} <${this.author_email}>`)})}async findGoldenSolution(f){return await c.section("Finding golden solution",async()=>{let $=this.handlers[f].handler,Z=this.handlers[f].compilers||"",w;if($==="circuits")w="solution.v";else if(Z==="RunPython")w="solution.py";else if(Z==="RunHaskell"||Z==="GHC")w="solution.hs";else if(Z==="RunClojure"||Z==="Clojure")w="solution.clj";else{let q=this.handlers[f].solution||"C++",v=xf5[q];if(!v)throw Error(`Unknown programming language ${q} for solution`);let K=x2(this.workDir,f,`solution.${v}`);if(!await ws(K))throw Error(`Golden solution file ${K} not found`);w=`solution.${v}`}return c.success(`Golden solution: ${w}`),w})}async prepareStatements_Std(f){await c.section("Preparing standard statements",async()=>{let $=x2(this.workDir,f);c.command(`jtk make pdf html md txt --problem_nm ${this.problem_nm}`),await c3({cwd:$,stdout:"inherit",stderr:"inherit"})`jtk make pdf html md txt --problem_nm ${this.problem_nm}`,await dx2(x2($,"jtk-pdf"),{recursive:!0,force:!0}),await dx2(x2($,"jtk-text"),{recursive:!0,force:!0}),c.success("Generated statements")})}async prepareStatements_Game(f){await c.section("Preparing game statements",async()=>{let $=x2(this.workDirLang,"Doc");await c.section("Generating PDF with xelatex",async()=>{c.command("xelatex -interaction=nonstopmode -file-line-error main.tex"),await c3({cwd:$})`xelatex -interaction=nonstopmode -file-line-error main.tex`,await c3({cwd:$})`xelatex -interaction=nonstopmode -file-line-error main.tex`,await cZ(x2($,"main.pdf"),x2(this.workDirLang,`problem.${f}.pdf`)),c.success(`Generated ${c.hyperlink(this.workDirLang,`problem.${f}.pdf`)}`)}),await c.section("Generating TXT with pandoc",async()=>{c.command("pandoc --quiet main.tex --to plain --output main.txt"),await c3({cwd:$})`pandoc --quiet main.tex --to plain --output main.txt`,await cZ(x2($,"main.txt"),x2(this.workDirLang,`problem.${f}.txt`)),c.success(`Generated ${c.hyperlink(this.workDirLang,`problem.${f}.txt`)}`),await cZ(x2($,"main.txt"),x2(this.workDirLang,`problem.${f}.short.txt`)),c.success(`Generated ${c.hyperlink(this.workDirLang,`problem.${f}.short.txt`)}`)}),await c.section("Generating Markdown with pandoc",async()=>{c.command("pandoc --quiet main.tex --to markdown --to markdown-header_attributes --output main.md"),await c3({cwd:$})`pandoc --quiet main.tex --to markdown --to markdown-header_attributes --output main.md`,await cZ(x2($,"main.md"),x2(this.workDirLang,`problem.${f}.md`)),c.success(`Generated ${c.hyperlink(this.workDirLang,`problem.${f}.md`)}`),await cZ(x2($,"main.md"),x2(this.workDirLang,`problem.${f}.short.md`)),c.success(`Generated ${c.hyperlink(this.workDirLang,`problem.${f}.short.md`)}`)}),await c.section("Generating HTML with pandoc",async()=>{c.command("pandoc --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html"),await c3({cwd:$})`pandoc --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html`,await cZ(x2($,"main.html"),x2(this.workDirLang,`problem.${f}.html`)),c.success(`Generated ${c.hyperlink(this.workDirLang,`problem.${f}.html`)}`),await cZ(x2($,"main.html"),x2(this.workDirLang,`problem.${f}.short.html`)),c.success(`Generated ${c.hyperlink(this.workDirLang,`problem.${f}.short.html`)}`)})})}async computeCodeMetrics(f){if(this.problem_type!=="std"){await c.section("Skipping code metrics",async()=>{await E5(),c.warning("Code metrics not applicable for this problem type")});return}await c.section("Computing code metrics",async()=>{let $=await this.findGoldenSolution(f);c.command(`jutge-code-metrics ${$}`);let{stdout:Z}=await c3({cwd:this.workDirLang})`jutge-code-metrics ${$}`;await m7(x2(this.stagingDirLang,"code-metrics.json"),Z),c.success(`Generated ${c.hyperlink(this.stagingDirLang,"code-metrics.json")}`)})}async stageProblemFiles_Std(f){let $=(v)=>{if(v==="handler.yml")return!0;for(let K of["inp","cor","ops"])if(v.endsWith(`.${K}`))return!0;for(let K of Fx2){if(v===`solution.${K}`)return!0;if(v===`main.${K}`)return!0}return!1},Z=x2(this.stagingDirLang,"problem.pbm");await AW(Z,{recursive:!0});let w=await Array.fromAsync(TK("*",{cwd:this.workDirLang})),q=0;for(let v of w)if($(v))await cZ(x2(this.workDirLang,v),x2(Z,v)),q++;c.success(`Staged ${q} files to ${c.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageProblemFiles_Game(f){let $=(K)=>{if(K==="handler.yml")return!0;if(K==="Makefile")return!0;if(K==="README.txt")return!0;if(K==="README.md")return!0;if(K.endsWith(".cc"))return!0;if(K.endsWith(".hh"))return!0;if(K.endsWith(".cnf"))return!0;return!1},Z=x2(this.workDirLang,"Runner"),w=x2(this.stagingDirLang,"problem.pbm");await AW(w,{recursive:!0});let q=await Array.fromAsync(TK("*",{cwd:Z})),v=0;for(let K of q)if($(K))await cZ(x2(Z,K),x2(w,K)),v++;c.success(`Staged ${v} files to ${c.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageAwards(f){await c.section("Staging awards",async()=>{let $=0;for(let Z of["award.png","award.txt"])if(await qx(this.workDirLang,Z))await cZ(x2(this.workDirLang,Z),x2(this.stagingDir,Z)),$++;if($>0)c.success(`Staged ${$} award file(s)`);else c.warning("No award files found")})}async stageStatements(f){await c.section("Staging statements",async()=>{let $=0;for(let Z of["pdf","html","md","txt","yml","short.html","short.md","short.txt"]){let w=`problem.${f}.${Z}`,q=`problem.${Z}`;if(await qx(this.workDirLang,w))await cZ(x2(this.workDirLang,w),x2(this.stagingDirLang,q)),$++}c.success(`Staged ${$} statement file(s)`)})}async stageFirstToSolve(){await c.section("Staging first-to-solve avatar",async()=>{let f=x2(this.stagingDir,"first-to-solve.svg"),Z=cx2(Zs,{seed:this.problem_nm}).toString();await m7(f,Z),c.success(`Generated ${c.hyperlink(this.stagingDir,"first-to-solve.svg")}`)})}async stageZip_Std(f){let $=(q)=>{for(let v of["pdf","html","md","txt"])if(q===`problem.${f}.${v}`)return!0;for(let v of Fx2){if(q===`main.${v}`)return!0;if(q===`code.${v}`)return!0}if(/^(sample|public).*\.(inp|cor)$/.test(q))return!0;return!1},Z=[],w=await Array.fromAsync(TK("*",{cwd:this.workDirLang}));for(let q of w)if($(q))Z.push({sourcePath:x2(this.workDirLang,q),archivePath:x2(`${this.problem_id}`,q)});await cb(Z,x2(this.stagingDirLang,"problem.zip")),c.success(`Created ${c.hyperlink(this.stagingDirLang,"problem.zip")} with ${Z.length} files`)}async stageZip_Game(f){let $=this.handlers[this.original_language].game.hide||["AIDummy.cc"],Z=(q)=>{if(q.endsWith(".cc")||q.endsWith(".hh"))return!$.includes(q);if(q.endsWith(".cnf"))return!0;if(q=="Makefile")return!0;if(q=="README.txt")return!0;if(q=="README.md")return!0;return!1},w=[];for(let q of["pdf","html","md","txt","short.html","short.md","short.txt"]){let v=`problem.${f}.${q}`;if(await qx(this.workDirLang,v))w.push({sourcePath:x2(this.workDirLang,v),archivePath:x2(`${this.problem_id}`,v)})}{let q=x2(this.workDirLang,"Runner"),v=await Array.fromAsync(TK("*",{cwd:q}));for(let K of v)if(Z(K))w.push({sourcePath:x2(q,K),archivePath:x2(`${this.problem_id}`,"src",K)})}{let q=x2(this.workDirLang,"Obj"),v=await Array.fromAsync(TK("*.o.*",{cwd:q}));for(let K of v)w.push({sourcePath:x2(q,K),archivePath:x2(`${this.problem_id}`,"src",K)})}{let q=x2(this.workDirLang,"Viewer"),v=await Array.fromAsync(TK("**/*",{cwd:q}));for(let K of v)w.push({sourcePath:x2(q,K),archivePath:x2(`${this.problem_id}`,"src","Viewer",K)})}await cb(w,x2(this.stagingDirLang,"problem.zip")),c.success(`Created ${c.hyperlink(this.stagingDirLang,"problem.zip")} with ${w.length} files`)}async stageViewer(f){await c.section("Staging viewer",async()=>{await cZ(x2(this.workDirLang,"Viewer"),x2(this.stagingDirLang,"viewer"),{recursive:!0}),c.success(`Staged ${c.hyperlink(this.stagingDirLang,"viewer")}`)})}async stageQuiz(f){await c.section("Staging quiz",async()=>{let $=El.parse(await W_(x2(this.workDirLang,"quiz.yml"))),Z=x2(this.stagingDirLang,"quiz.pbm");await AW(Z,{recursive:!0}),await hJ(x2(Z,"quiz.yml"),$);for(let w of $.questions){{let q=x2(this.workDirLang,`${w.file}.yml`),v=x2(Z,`${w.file}.yml`);if(await ws(q))await cZ(q,v);else throw Error(`Quiz question file ${w.file}.yml not found`)}{let q=x2(this.workDirLang,`${w.file}.py`),v=x2(Z,`${w.file}.py`);if(await ws(q))await cZ(q,v)}}c.success(`Staged ${c.hyperlink(this.stagingDirLang,"quiz")}`)})}async stageInformationYml(){await c.section("Staging information.yml",async()=>{let f={problem_nm:this.problem_nm,languages:this.languages,original_language:this.original_language,author:this.author,author_email:this.author_email,problems:this.problem_ymls,handlers:this.handlers},$=x2(this.stagingDir,"information.yml");await hJ($,f),c.success(`Generated ${c.hyperlink(this.stagingDir,"information.yml")}`)})}async stageReadMd(){await c.section("Staging README.md",async()=>{let f=JZ.version,$=this.languages.map((v)=>{let H=this.problem_ymls[v].title,Y=`- *${v}*: ${H}
|
|
4068
|
+
*/var Zs={};KZ(Zs,{schema:()=>Bx2,meta:()=>cf5,create:()=>Lf5});var RX1={};KZ(RX1,{ringTwo:()=>Sx2,ringThree:()=>bx2,ringOne:()=>gx2,ringFour:()=>ux2,ringFive:()=>yx2,ring:()=>Lx2});var Lx2={container:(f,$)=>{var Z,w,q,v,K,H,Y,P,M,W,J,X,O,G,V,N,E,j,g,k;return`${(w=(Z=f.ringOne)===null||Z===void 0?void 0:Z.value(f,$))!==null&&w!==void 0?w:""}${(v=(q=f.ringTwo)===null||q===void 0?void 0:q.value(f,$))!==null&&v!==void 0?v:""}${(H=(K=f.ringThree)===null||K===void 0?void 0:K.value(f,$))!==null&&H!==void 0?H:""}${(P=(Y=f.ringFour)===null||Y===void 0?void 0:Y.value(f,$))!==null&&P!==void 0?P:""}${(W=(M=f.ringFive)===null||M===void 0?void 0:M.value(f,$))!==null&&W!==void 0?W:""}<g transform="matrix(1 0 0 -1 0 100)">${(X=(J=f.ringOne)===null||J===void 0?void 0:J.value(f,$))!==null&&X!==void 0?X:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(G=(O=f.ringTwo)===null||O===void 0?void 0:O.value(f,$))!==null&&G!==void 0?G:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(N=(V=f.ringThree)===null||V===void 0?void 0:V.value(f,$))!==null&&N!==void 0?N:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(j=(E=f.ringFour)===null||E===void 0?void 0:E.value(f,$))!==null&&j!==void 0?j:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(k=(g=f.ringFive)===null||g===void 0?void 0:g.value(f,$))!==null&&k!==void 0?k:""}</g><circle cx="50" cy="50" r="45" stroke="#fff" stroke-opacity=".25" stroke-width="10" style="mix-blend-mode:lighten"/><circle cx="50" cy="50" r="25" stroke="#fff" stroke-opacity=".25" stroke-width="10" style="mix-blend-mode:lighten"/><circle cx="50" cy="50" r="10" fill="#fff" fill-opacity=".25" style="mix-blend-mode:lighten"/>`}};var gx2={half:(f,$)=>`<path d="M90 50h10c0-27.614-22.386-50-50-50S0 22.386 0 50h10c0-22.091 17.909-40 40-40s40 17.909 40 40Z" fill="${x1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 10V0C22.386 0 0 22.386 0 50h10c0-22.091 17.909-40 40-40Z" fill="${x1.xml(`${$.ring}`)}"/>`,eighth:(f,$)=>`<path d="M21.716 21.716C14.477 28.954 10 38.954 10 50H0c0-13.807 5.596-26.307 14.645-35.355l7.07 7.07Z" fill="${x1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="45" stroke="${x1.xml(`${$.ring}`)}" stroke-width="10"/>`};var Sx2={eighth:(f,$)=>`<path d="M20 50c0-8.284 3.358-15.784 8.787-21.213l-7.071-7.071C14.477 28.954 10 38.954 10 50h10Z" fill="${x1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 10c-22.091 0-40 17.909-40 40h10c0-16.569 13.431-30 30-30V10Z" fill="${x1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M90 50c0-22.091-17.909-40-40-40S10 27.909 10 50h10c0-16.569 13.431-30 30-30 16.569 0 30 13.431 30 30h10Z" fill="${x1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="35" stroke="${x1.xml(`${$.ring}`)}" stroke-width="10"/>`};var bx2={eighth:(f,$)=>`<path d="M30 50a19.937 19.937 0 0 1 5.858-14.142l-7.071-7.071C23.357 34.216 20 41.716 20 50h10Z" fill="${x1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 20c-16.569 0-30 13.431-30 30h10c0-11.046 8.954-20 20-20V20Z" fill="${x1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M80 50c0-16.569-13.431-30-30-30-16.569 0-30 13.431-30 30h10c0-11.046 8.954-20 20-20s20 8.954 20 20h10Z" fill="${x1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="25" stroke="${x1.xml(`${$.ring}`)}" stroke-width="10"/>`};var ux2={eighth:(f,$)=>`<path d="M40 50a9.97 9.97 0 0 1 2.929-7.071l-7.071-7.071A19.937 19.937 0 0 0 30 50h10Z" fill="${x1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 30c-11.046 0-20 8.954-20 20h10c0-5.523 4.477-10 10-10V30Z" fill="${x1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M70 50c0-11.046-8.954-20-20-20s-20 8.954-20 20h10c0-5.523 4.477-10 10-10s10 4.477 10 10h10Z" fill="${x1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="15" stroke="${x1.xml(`${$.ring}`)}" stroke-width="10"/>`};var yx2={eighth:(f,$)=>`<path d="m42.929 42.929 7.07 7.07H40a9.97 9.97 0 0 1 2.93-7.07Z" fill="${x1.xml(`${$.ring}`)}"/>`,quarter:(f,$)=>`<path d="M50 40v10H40c0-5.523 4.477-10 10-10Z" fill="${x1.xml(`${$.ring}`)}"/>`,half:(f,$)=>`<path d="M60 50c0-5.523-4.477-10-10-10s-10 4.477-10 10h20Z" fill="${x1.xml(`${$.ring}`)}"/>`,full:(f,$)=>`<circle cx="50" cy="50" r="10" fill="${x1.xml(`${$.ring}`)}"/>`};function HA({prng:f,group:$,width:Z,height:w,values:q=[],rotation:v,offsetX:K,offsetY:H}){let Y=RX1,P=f.pick(q),M=f.integer(Math.min(...v),Math.max(...v)),W=f.integer(Math.min(...K),Math.max(...K)),J=f.integer(Math.min(...H),Math.max(...H));if(P&&Y[$][P])return{name:P,value(X,O){var G,V,N;let E=Y[$][P](X,O);if(this.rotation||this.offsetX||this.offsetY)E=`<g transform="translate(${(G=this.offsetX)!==null&&G!==void 0?G:0}, ${(V=this.offsetY)!==null&&V!==void 0?V:0}) rotate(${(N=this.rotation)!==null&&N!==void 0?N:0} ${Z/2} ${w/2})">${E}</g>`;return E},rotation:M,offsetX:W,offsetY:J};else return}function kx2({prng:f,options:$}){var Z,w,q,v,K,H;let Y=HA({prng:f,group:"ring",values:$.ring,width:100,height:100,rotation:((Z=$.ringRotation)===null||Z===void 0?void 0:Z.length)?$.ringRotation:[0],offsetX:[0],offsetY:[0]}),P=HA({prng:f,group:"ringOne",values:$.ringOne,width:100,height:100,rotation:((w=$.ringOneRotation)===null||w===void 0?void 0:w.length)?$.ringOneRotation:[0],offsetX:[0],offsetY:[0]}),M=HA({prng:f,group:"ringTwo",values:$.ringTwo,width:100,height:100,rotation:((q=$.ringTwoRotation)===null||q===void 0?void 0:q.length)?$.ringTwoRotation:[0],offsetX:[0],offsetY:[0]}),W=HA({prng:f,group:"ringThree",values:$.ringThree,width:100,height:100,rotation:((v=$.ringThreeRotation)===null||v===void 0?void 0:v.length)?$.ringThreeRotation:[0],offsetX:[0],offsetY:[0]}),J=HA({prng:f,group:"ringFour",values:$.ringFour,width:100,height:100,rotation:((K=$.ringFourRotation)===null||K===void 0?void 0:K.length)?$.ringFourRotation:[0],offsetX:[0],offsetY:[0]}),X=HA({prng:f,group:"ringFive",values:$.ringFive,width:100,height:100,rotation:((H=$.ringFiveRotation)===null||H===void 0?void 0:H.length)?$.ringFiveRotation:[0],offsetX:[0],offsetY:[0]});return{ring:Y,ringOne:P,ringTwo:M,ringThree:W,ringFour:J,ringFive:X}}function mx2(f){return f==="transparent"?f:`#${f}`}function xx2({prng:f,options:$}){var Z;return{ring:mx2(f.pick((Z=$.ringColor)!==null&&Z!==void 0?Z:[],"transparent"))}}var Bx2={$schema:"http://json-schema.org/draft-07/schema#",properties:{ring:{type:"array",items:{type:"string",enum:["container"]},default:["container"]},ringColor:{type:"array",items:{type:"string",pattern:"^(transparent|[a-fA-F0-9]{6})$"},default:["ffd54f","64b5f6","4dd0e1","ff8a65","9575cd","81c784","7986cb","4fc3f7","aed581","dce775","ffb74d","f06292","ba68c8","e57373","4db6ac","fff176"]},ringFive:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["full"]},ringFiveRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringFour:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["quarter","half"]},ringFourRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringOne:{type:"array",items:{type:"string",enum:["half","quarter","eighth","full"]},default:["half","quarter"]},ringOneRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringThree:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["quarter","half"]},ringThreeRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]},ringTwo:{type:"array",items:{type:"string",enum:["eighth","quarter","half","full"]},default:["quarter","half"]},ringTwoRotation:{type:"array",items:{type:"integer",minimum:-180,maximum:180},maxItems:2,default:[-180,180]}}};var cf5={title:"Rings",creator:"DiceBear",source:"https://www.dicebear.com",homepage:"https://www.dicebear.com",license:{name:"CC0 1.0",url:"https://creativecommons.org/publicdomain/zero/1.0/"}},Lf5=({prng:f,options:$})=>{var Z,w;let q=kx2({prng:f,options:$}),v=xx2({prng:f,options:$});return{attributes:{viewBox:"0 0 100 100",fill:"none","shape-rendering":"crispEdges"},body:`${(w=(Z=q.ring)===null||Z===void 0?void 0:Z.value(q,v))!==null&&w!==void 0?w:""}`,extra:()=>({...Object.entries(q).reduce((K,[H,Y])=>{return K[H]=Y===null||Y===void 0?void 0:Y.name,K},{}),...Object.entries(v).reduce((K,[H,Y])=>{return K[`${H}Color`]=Y,K},{})})}};Xz();import{cp as cZ,exists as ws,glob as TK,mkdir as AW,rm as dx2,writeFile as mf5}from"fs/promises";import{join as x2}from"path";var Ux2=f4(qo(),1);class LX1{directory;problem_nm;workspace;workDir;stagingDir;stagingDirLang="to-be-set";workDirLang="to-be-set";problem_id="to-be-set";languages=[];original_language="";problem_ymls={};handlers={};author="";author_email="";problem_type="std";constructor(f,$){this.directory=f,this.problem_nm=$,this.workspace=x2(f,o0()+"-stage",XD()),this.workDir=x2(this.workspace,"work"),this.stagingDir=x2(this.workspace,"stage",this.problem_nm)}async stage(){await c.section(`Staging problem at ${this.directory}`,async()=>{await this.createWorkspace(),await this.separateByLanguages(),await this.readMetadata();for(let f of this.languages)await c.section(`Staging language ${f}`,async()=>{if(await this.setLanguage(f),this.problem_type==="std")await this.stageLanguage_Std(f);else if(this.problem_type==="game")await this.stageLanguage_Game(f);else if(this.problem_type==="quiz")await this.stageLanguage_Quizz(f)});await this.stageFirstToSolve(),await this.stageInformationYml(),await this.stageReadMd()}),await c.section("Summary",async()=>{let f=x2(this.stagingDir,"README.md");c.success("README.md content:"),await c.markdown(await V5(f)),c.success("Staging tree:"),c.print(Ux2.default(this.stagingDir))}),c.success(`Staging directory: ${c.hyperlink(this.stagingDir)}`)}async stageLanguage_Std(f){await this.prepareStatements_Std(f),await this.computeCodeMetrics(f),await this.stageProblemFiles_Std(f),await this.stageAwards(f),await this.stageStatements(f),await this.stageZip_Std(f)}async stageLanguage_Game(f){await this.prepareStatements_Game(f),await this.computeCodeMetrics(f),await this.stageProblemFiles_Game(f),await this.stageAwards(f),await this.stageStatements(f),await this.stageZip_Game(f),await this.stageViewer(f)}async stageLanguage_Quizz(f){await this.stageQuiz(f)}async setLanguage(f){this.workDirLang=x2(this.workDir,f),this.problem_id=`${this.problem_nm}_${f}`,this.stagingDirLang=x2(this.stagingDir,f),await AW(this.stagingDirLang,{recursive:!0})}async createWorkspace(){await c.section(`Creating workspace ${this.workspace}`,async()=>{if(await ws(this.workspace))throw Error(`Workspace directory ${this.workspace} already exists`);await AW(this.workspace,{recursive:!0}),await AW(this.workDir,{recursive:!0}),await AW(this.stagingDir,{recursive:!0}),c.directory(this.workspace)})}doNotCopy(f,$){if(f==="problem.yml")return!0;if(f.startsWith(o0()))return!0;let Z=f.match(/^problem\.([a-z][a-z])\.[a-z]*$/);if(Z&&Z[1]!==$)return!0;if(f===`problem.${$}.pdf`)return!0;return!1}async separateByLanguages(){await c.section("Detecting if there are language folders or not",async()=>{if((await Array.fromAsync(TK("handler.yml",{cwd:this.directory}))).length===0)await this.separateByLanguagesWithFolders();else await this.separateByLanguagesWithoutFolders()})}async separateByLanguagesWithoutFolders(){await c.section("Separating problem by languages without folders",async()=>{let $=(await Array.fromAsync(TK("problem.[a-z][a-z].yml",{cwd:this.directory}))).map((Z)=>{let w=Z.match(/^problem\.([a-z][a-z])\.yml$/);if(!w)throw Error(`Unexpected yml file name: ${Z}`);return w[1]});this.languages=$;for(let Z of $){let w=x2(this.workDir,Z);await AW(w,{recursive:!0});let q=await Array.fromAsync(TK("*",{cwd:this.directory}));for(let v of q){if(this.doNotCopy(v,Z))continue;await cZ(x2(this.directory,v),x2(w,v),{recursive:!0})}}c.success(`Found languages: ${$.join(", ")}`)})}async separateByLanguagesWithFolders(){await c.section("Separating problem by languages with folders",async()=>{let f=await Array.fromAsync(TK("[a-z][a-z]",{cwd:this.directory}));this.languages=f;for(let $ of f){let Z=x2(this.directory,$),w=x2(this.workDir,$);await AW(w,{recursive:!0});let q=await Array.fromAsync(TK("*",{cwd:Z}));for(let v of q){if(this.doNotCopy(v,$))continue;await cZ(x2(Z,v),x2(w,v),{recursive:!0})}}c.success(`Found languages: ${f.join(", ")}`)})}async readMetadata(){await c.section("Reading problem metadata",async()=>{for(let $ of this.languages){let Z=x2(this.workDir,$,`problem.${$}.yml`);this.problem_ymls[$]=await W_(Z)}for(let $ of this.languages){let Z=x2(this.workDir,$,"handler.yml");this.handlers[$]=await W_(Z)}for(let $ of this.languages){let Z=this.problem_ymls[$];if(Z.author)this.author=Z.author;if(Z.author)this.original_language=$;if(Z.email)this.author_email=Z.email}if(!this.original_language)throw Error("Original language not found in problem.<lang>.yml files");let f=this.handlers[this.original_language];if(f.handler==="game")this.problem_type="game";else if(f.handler==="quiz")this.problem_type="quiz";else this.problem_type="std";c.success(`Problem type: ${this.problem_type}`),c.success(`Original language: ${this.original_language}`),c.success(`Author: ${this.author} <${this.author_email}>`)})}async findGoldenSolution(f){return await c.section("Finding golden solution",async()=>{let $=this.handlers[f].handler,Z=this.handlers[f].compilers||"",w;if($==="circuits")w="solution.v";else if(Z==="RunPython")w="solution.py";else if(Z==="RunHaskell"||Z==="GHC")w="solution.hs";else if(Z==="RunClojure"||Z==="Clojure")w="solution.clj";else{let q=this.handlers[f].solution||"C++",v=xf5[q];if(!v)throw Error(`Unknown programming language ${q} for solution`);let K=x2(this.workDir,f,`solution.${v}`);if(!await ws(K))throw Error(`Golden solution file ${K} not found`);w=`solution.${v}`}return c.success(`Golden solution: ${w}`),w})}async prepareStatements_Std(f){await c.section("Preparing standard statements",async()=>{let $=x2(this.workDir,f);c.command(`jtk make pdf html md txt --problem_nm ${this.problem_nm}`),await c3({cwd:$,stdout:"inherit",stderr:"inherit"})`jtk make pdf html md txt --problem_nm ${this.problem_nm}`,await dx2(x2($,"jtk-pdf"),{recursive:!0,force:!0}),await dx2(x2($,"jtk-text"),{recursive:!0,force:!0}),c.success("Generated statements")})}async prepareStatements_Game(f){await c.section("Preparing game statements",async()=>{let $=x2(this.workDirLang,"Doc");await c.section("Generating PDF with xelatex",async()=>{c.command("xelatex -interaction=nonstopmode -file-line-error main.tex"),await c3({cwd:$})`xelatex -interaction=nonstopmode -file-line-error main.tex`,await c3({cwd:$})`xelatex -interaction=nonstopmode -file-line-error main.tex`,await cZ(x2($,"main.pdf"),x2(this.workDirLang,`problem.${f}.pdf`)),c.success(`Generated ${c.hyperlink(this.workDirLang,`problem.${f}.pdf`)}`)}),await c.section("Generating TXT with pandoc",async()=>{c.command("pandoc --quiet main.tex --to plain --output main.txt"),await c3({cwd:$})`pandoc --quiet main.tex --to plain --output main.txt`,await cZ(x2($,"main.txt"),x2(this.workDirLang,`problem.${f}.txt`)),c.success(`Generated ${c.hyperlink(this.workDirLang,`problem.${f}.txt`)}`),await cZ(x2($,"main.txt"),x2(this.workDirLang,`problem.${f}.short.txt`)),c.success(`Generated ${c.hyperlink(this.workDirLang,`problem.${f}.short.txt`)}`)}),await c.section("Generating Markdown with pandoc",async()=>{c.command("pandoc --quiet main.tex --to markdown --to markdown-header_attributes --output main.md"),await c3({cwd:$})`pandoc --quiet main.tex --to markdown --to markdown-header_attributes --output main.md`,await cZ(x2($,"main.md"),x2(this.workDirLang,`problem.${f}.md`)),c.success(`Generated ${c.hyperlink(this.workDirLang,`problem.${f}.md`)}`),await cZ(x2($,"main.md"),x2(this.workDirLang,`problem.${f}.short.md`)),c.success(`Generated ${c.hyperlink(this.workDirLang,`problem.${f}.short.md`)}`)}),await c.section("Generating HTML with pandoc",async()=>{c.command("pandoc --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html"),await c3({cwd:$})`pandoc --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html`,await cZ(x2($,"main.html"),x2(this.workDirLang,`problem.${f}.html`)),c.success(`Generated ${c.hyperlink(this.workDirLang,`problem.${f}.html`)}`),await cZ(x2($,"main.html"),x2(this.workDirLang,`problem.${f}.short.html`)),c.success(`Generated ${c.hyperlink(this.workDirLang,`problem.${f}.short.html`)}`)})})}async computeCodeMetrics(f){if(this.problem_type!=="std"){await c.section("Skipping code metrics",async()=>{await E5(),c.warning("Code metrics not applicable for this problem type")});return}await c.section("Computing code metrics",async()=>{let $=await this.findGoldenSolution(f);c.command(`jutge-code-metrics ${$}`);let{stdout:Z}=await c3({cwd:this.workDirLang})`jutge-code-metrics ${$}`;await m7(x2(this.stagingDirLang,"code-metrics.json"),Z),c.success(`Generated ${c.hyperlink(this.stagingDirLang,"code-metrics.json")}`)})}async stageProblemFiles_Std(f){let $=(v)=>{if(v==="handler.yml")return!0;for(let K of["inp","cor","ops"])if(v.endsWith(`.${K}`))return!0;for(let K of Fx2){if(v===`solution.${K}`)return!0;if(v===`main.${K}`)return!0}if(v==="checker.py")return!0;if(v==="checker.cc")return!0;return!1},Z=x2(this.stagingDirLang,"problem.pbm");await AW(Z,{recursive:!0});let w=await Array.fromAsync(TK("*",{cwd:this.workDirLang})),q=0;for(let v of w)if($(v))await cZ(x2(this.workDirLang,v),x2(Z,v)),q++;c.success(`Staged ${q} files to ${c.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageProblemFiles_Game(f){let $=(K)=>{if(K==="handler.yml")return!0;if(K==="Makefile")return!0;if(K==="README.txt")return!0;if(K==="README.md")return!0;if(K.endsWith(".cc"))return!0;if(K.endsWith(".hh"))return!0;if(K.endsWith(".cnf"))return!0;return!1},Z=x2(this.workDirLang,"Runner"),w=x2(this.stagingDirLang,"problem.pbm");await AW(w,{recursive:!0});let q=await Array.fromAsync(TK("*",{cwd:Z})),v=0;for(let K of q)if($(K))await cZ(x2(Z,K),x2(w,K)),v++;c.success(`Staged ${v} files to ${c.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageAwards(f){await c.section("Staging awards",async()=>{let $=0;for(let Z of["award.png","award.txt"])if(await qx(this.workDirLang,Z))await cZ(x2(this.workDirLang,Z),x2(this.stagingDir,Z)),$++;if($>0)c.success(`Staged ${$} award file(s)`);else c.warning("No award files found")})}async stageStatements(f){await c.section("Staging statements",async()=>{let $=0;for(let Z of["pdf","html","md","txt","yml","short.html","short.md","short.txt"]){let w=`problem.${f}.${Z}`,q=`problem.${Z}`;if(await qx(this.workDirLang,w))await cZ(x2(this.workDirLang,w),x2(this.stagingDirLang,q)),$++}c.success(`Staged ${$} statement file(s)`)})}async stageFirstToSolve(){await c.section("Staging first-to-solve avatar",async()=>{let f=x2(this.stagingDir,"first-to-solve.svg"),Z=cx2(Zs,{seed:this.problem_nm}).toString();await m7(f,Z),c.success(`Generated ${c.hyperlink(this.stagingDir,"first-to-solve.svg")}`)})}async stageZip_Std(f){let $=(q)=>{for(let v of["pdf","html","md","txt"])if(q===`problem.${f}.${v}`)return!0;for(let v of Fx2){if(q===`main.${v}`)return!0;if(q===`code.${v}`)return!0}if(/^(sample|public).*\.(inp|cor)$/.test(q))return!0;return!1},Z=[],w=await Array.fromAsync(TK("*",{cwd:this.workDirLang}));for(let q of w)if($(q))Z.push({sourcePath:x2(this.workDirLang,q),archivePath:x2(`${this.problem_id}`,q)});await cb(Z,x2(this.stagingDirLang,"problem.zip")),c.success(`Created ${c.hyperlink(this.stagingDirLang,"problem.zip")} with ${Z.length} files`)}async stageZip_Game(f){let $=this.handlers[this.original_language].game.hide||["AIDummy.cc"],Z=(q)=>{if(q.endsWith(".cc")||q.endsWith(".hh"))return!$.includes(q);if(q.endsWith(".cnf"))return!0;if(q=="Makefile")return!0;if(q=="README.txt")return!0;if(q=="README.md")return!0;return!1},w=[];for(let q of["pdf","html","md","txt","short.html","short.md","short.txt"]){let v=`problem.${f}.${q}`;if(await qx(this.workDirLang,v))w.push({sourcePath:x2(this.workDirLang,v),archivePath:x2(`${this.problem_id}`,v)})}{let q=x2(this.workDirLang,"Runner"),v=await Array.fromAsync(TK("*",{cwd:q}));for(let K of v)if(Z(K))w.push({sourcePath:x2(q,K),archivePath:x2(`${this.problem_id}`,"src",K)})}{let q=x2(this.workDirLang,"Obj"),v=await Array.fromAsync(TK("*.o.*",{cwd:q}));for(let K of v)w.push({sourcePath:x2(q,K),archivePath:x2(`${this.problem_id}`,"src",K)})}{let q=x2(this.workDirLang,"Viewer"),v=await Array.fromAsync(TK("**/*",{cwd:q}));for(let K of v)w.push({sourcePath:x2(q,K),archivePath:x2(`${this.problem_id}`,"src","Viewer",K)})}await cb(w,x2(this.stagingDirLang,"problem.zip")),c.success(`Created ${c.hyperlink(this.stagingDirLang,"problem.zip")} with ${w.length} files`)}async stageViewer(f){await c.section("Staging viewer",async()=>{await cZ(x2(this.workDirLang,"Viewer"),x2(this.stagingDirLang,"viewer"),{recursive:!0}),c.success(`Staged ${c.hyperlink(this.stagingDirLang,"viewer")}`)})}async stageQuiz(f){await c.section("Staging quiz",async()=>{let $=El.parse(await W_(x2(this.workDirLang,"quiz.yml"))),Z=x2(this.stagingDirLang,"quiz.pbm");await AW(Z,{recursive:!0}),await hJ(x2(Z,"quiz.yml"),$);for(let w of $.questions){{let q=x2(this.workDirLang,`${w.file}.yml`),v=x2(Z,`${w.file}.yml`);if(await ws(q))await cZ(q,v);else throw Error(`Quiz question file ${w.file}.yml not found`)}{let q=x2(this.workDirLang,`${w.file}.py`),v=x2(Z,`${w.file}.py`);if(await ws(q))await cZ(q,v)}}c.success(`Staged ${c.hyperlink(this.stagingDirLang,"quiz")}`)})}async stageInformationYml(){await c.section("Staging information.yml",async()=>{let f={problem_nm:this.problem_nm,languages:this.languages,original_language:this.original_language,author:this.author,author_email:this.author_email,problems:this.problem_ymls,handlers:this.handlers},$=x2(this.stagingDir,"information.yml");await hJ($,f),c.success(`Generated ${c.hyperlink(this.stagingDir,"information.yml")}`)})}async stageReadMd(){await c.section("Staging README.md",async()=>{let f=JZ.version,$=this.languages.map((v)=>{let H=this.problem_ymls[v].title,Y=`- *${v}*: ${H}
|
|
4069
4069
|
`;if(v!==this.original_language)Y+=` ${this.problem_ymls[v].translator} <${this.problem_ymls[v].translator_email}>`;else Y="";return Y}).join(`
|
|
4070
4070
|
`);if($.trim())$=`## Translations
|
|
4071
4071
|
|