@jutge.org/toolkit 4.4.3 → 4.4.5
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
|
@@ -690,7 +690,7 @@ User question: ${f}`,h=await i9(l,v,"ask",c,Z);await O.markdown(h),O.warning(`Th
|
|
|
690
690
|
*
|
|
691
691
|
* Code licensed under MIT (https://github.com/dicebear/dicebear/blob/v4/packages/initials/LICENSE)
|
|
692
692
|
* Copyright (c) 2024 Florian Körner
|
|
693
|
-
*/var RO={};Q5(RO,{schema:()=>$j1,meta:()=>px2,create:()=>xx2});var xI={};Q5(xI,{ringTwo:()=>Qi1,ringThree:()=>si1,ringOne:()=>Ui1,ringFour:()=>fj1,ringFive:()=>_j1,ring:()=>ei1});var ei1={container:(f,v)=>{var l,c,$,Z,h,w,q,K,u,H,m,a,D,J,W,X,j,k,N,y;return`${(c=(l=f.ringOne)===null||l===void 0?void 0:l.value(f,v))!==null&&c!==void 0?c:""}${(Z=($=f.ringTwo)===null||$===void 0?void 0:$.value(f,v))!==null&&Z!==void 0?Z:""}${(w=(h=f.ringThree)===null||h===void 0?void 0:h.value(f,v))!==null&&w!==void 0?w:""}${(K=(q=f.ringFour)===null||q===void 0?void 0:q.value(f,v))!==null&&K!==void 0?K:""}${(H=(u=f.ringFive)===null||u===void 0?void 0:u.value(f,v))!==null&&H!==void 0?H:""}<g transform="matrix(1 0 0 -1 0 100)">${(a=(m=f.ringOne)===null||m===void 0?void 0:m.value(f,v))!==null&&a!==void 0?a:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(J=(D=f.ringTwo)===null||D===void 0?void 0:D.value(f,v))!==null&&J!==void 0?J:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(X=(W=f.ringThree)===null||W===void 0?void 0:W.value(f,v))!==null&&X!==void 0?X:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(k=(j=f.ringFour)===null||j===void 0?void 0:j.value(f,v))!==null&&k!==void 0?k:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(y=(N=f.ringFive)===null||N===void 0?void 0:N.value(f,v))!==null&&y!==void 0?y:""}</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 Ui1={half:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,quarter:(f,v)=>`<path d="M50 10V0C22.386 0 0 22.386 0 50h10c0-22.091 17.909-40 40-40Z" fill="${H1.xml(`${v.ring}`)}"/>`,eighth:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,full:(f,v)=>`<circle cx="50" cy="50" r="45" stroke="${H1.xml(`${v.ring}`)}" stroke-width="10"/>`};var Qi1={eighth:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,quarter:(f,v)=>`<path d="M50 10c-22.091 0-40 17.909-40 40h10c0-16.569 13.431-30 30-30V10Z" fill="${H1.xml(`${v.ring}`)}"/>`,half:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,full:(f,v)=>`<circle cx="50" cy="50" r="35" stroke="${H1.xml(`${v.ring}`)}" stroke-width="10"/>`};var si1={eighth:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,quarter:(f,v)=>`<path d="M50 20c-16.569 0-30 13.431-30 30h10c0-11.046 8.954-20 20-20V20Z" fill="${H1.xml(`${v.ring}`)}"/>`,half:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,full:(f,v)=>`<circle cx="50" cy="50" r="25" stroke="${H1.xml(`${v.ring}`)}" stroke-width="10"/>`};var fj1={eighth:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,quarter:(f,v)=>`<path d="M50 30c-11.046 0-20 8.954-20 20h10c0-5.523 4.477-10 10-10V30Z" fill="${H1.xml(`${v.ring}`)}"/>`,half:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,full:(f,v)=>`<circle cx="50" cy="50" r="15" stroke="${H1.xml(`${v.ring}`)}" stroke-width="10"/>`};var _j1={eighth:(f,v)=>`<path d="m42.929 42.929 7.07 7.07H40a9.97 9.97 0 0 1 2.93-7.07Z" fill="${H1.xml(`${v.ring}`)}"/>`,quarter:(f,v)=>`<path d="M50 40v10H40c0-5.523 4.477-10 10-10Z" fill="${H1.xml(`${v.ring}`)}"/>`,half:(f,v)=>`<path d="M60 50c0-5.523-4.477-10-10-10s-10 4.477-10 10h20Z" fill="${H1.xml(`${v.ring}`)}"/>`,full:(f,v)=>`<circle cx="50" cy="50" r="10" fill="${H1.xml(`${v.ring}`)}"/>`};function yl({prng:f,group:v,width:l,height:c,values:$=[],rotation:Z,offsetX:h,offsetY:w}){let q=xI,K=f.pick($),u=f.integer(Math.min(...Z),Math.max(...Z)),H=f.integer(Math.min(...h),Math.max(...h)),m=f.integer(Math.min(...w),Math.max(...w));if(K&&q[v][K])return{name:K,value(a,D){var J,W,X;let j=q[v][K](a,D);if(this.rotation||this.offsetX||this.offsetY)j=`<g transform="translate(${(J=this.offsetX)!==null&&J!==void 0?J:0}, ${(W=this.offsetY)!==null&&W!==void 0?W:0}) rotate(${(X=this.rotation)!==null&&X!==void 0?X:0} ${l/2} ${c/2})">${j}</g>`;return j},rotation:u,offsetX:H,offsetY:m};else return}function vj1({prng:f,options:v}){var l,c,$,Z,h,w;let q=yl({prng:f,group:"ring",values:v.ring,width:100,height:100,rotation:((l=v.ringRotation)===null||l===void 0?void 0:l.length)?v.ringRotation:[0],offsetX:[0],offsetY:[0]}),K=yl({prng:f,group:"ringOne",values:v.ringOne,width:100,height:100,rotation:((c=v.ringOneRotation)===null||c===void 0?void 0:c.length)?v.ringOneRotation:[0],offsetX:[0],offsetY:[0]}),u=yl({prng:f,group:"ringTwo",values:v.ringTwo,width:100,height:100,rotation:(($=v.ringTwoRotation)===null||$===void 0?void 0:$.length)?v.ringTwoRotation:[0],offsetX:[0],offsetY:[0]}),H=yl({prng:f,group:"ringThree",values:v.ringThree,width:100,height:100,rotation:((Z=v.ringThreeRotation)===null||Z===void 0?void 0:Z.length)?v.ringThreeRotation:[0],offsetX:[0],offsetY:[0]}),m=yl({prng:f,group:"ringFour",values:v.ringFour,width:100,height:100,rotation:((h=v.ringFourRotation)===null||h===void 0?void 0:h.length)?v.ringFourRotation:[0],offsetX:[0],offsetY:[0]}),a=yl({prng:f,group:"ringFive",values:v.ringFive,width:100,height:100,rotation:((w=v.ringFiveRotation)===null||w===void 0?void 0:w.length)?v.ringFiveRotation:[0],offsetX:[0],offsetY:[0]});return{ring:q,ringOne:K,ringTwo:u,ringThree:H,ringFour:m,ringFive:a}}function lj1(f){return f==="transparent"?f:`#${f}`}function cj1({prng:f,options:v}){var l;return{ring:lj1(f.pick((l=v.ringColor)!==null&&l!==void 0?l:[],"transparent"))}}var $j1={$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 px2={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/"}},xx2=({prng:f,options:v})=>{var l,c;let $=vj1({prng:f,options:v}),Z=cj1({prng:f,options:v});return{attributes:{viewBox:"0 0 100 100",fill:"none","shape-rendering":"crispEdges"},body:`${(c=(l=$.ring)===null||l===void 0?void 0:l.value($,Z))!==null&&c!==void 0?c:""}`,extra:()=>({...Object.entries($).reduce((h,[w,q])=>{return h[w]=q===null||q===void 0?void 0:q.name,h},{}),...Object.entries(Z).reduce((h,[w,q])=>{return h[`${w}Color`]=q,h},{})})}};var ah=m2(ob(),1),qj1=m2(Fb(),1),Kj1=m2(Zj1(),1);r7();var Pj1=m2(mD(),1);import{cp as A4,exists as SO,glob as r5,mkdir as y9,rm as hj1,stat as tI,writeFile as Ux2}from"fs/promises";import Yh from"os";import{join as g1,resolve as Qx2}from"path";ah.default.extend(qj1.default);ah.default.extend(Kj1.default);class BI{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,v){if(this.directory=Qx2(f),!this.directory.endsWith(".pbm"))throw Error(`Directory ${this.directory} is not a problem root directory (missing .pbm suffix)`);this.problem_nm=v,this.workspace=g1(f,K3()+"-stage",x0()),this.workDir=g1(this.workspace,"work.pbm"),this.stagingDir=g1(this.workspace,"stage",this.problem_nm)}async stage(){await O.section(`Staging problem at ${O.hyperlink(this.directory)}`,async()=>{await this.createWorkspace(),await this.separateByLanguages(),await this.readMetadata();for(let f of this.languages)await O.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 O.section("Summary",async()=>{let f=g1(this.stagingDir,"README.md");O.success("README.md content:"),await O.markdown(await p2(f)),O.success("Staging tree:"),O.print(Pj1.default(this.stagingDir))}),O.success(`Problem successfully staged at directory ${O.hyperlink(this.stagingDir)}`),await bO(this.stagingDir)}async stageLanguage_Std(f){await this.checkMTimes_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=g1(this.workDir,f),this.problem_id=`${this.problem_nm}_${f}`,this.stagingDirLang=g1(this.stagingDir,f),await y9(this.stagingDirLang,{recursive:!0})}async createWorkspace(){await O.section(`Creating workspace ${this.workspace}`,async()=>{if(await SO(this.workspace))throw Error(`Workspace directory ${this.workspace} already exists`);await y9(this.workspace,{recursive:!0}),await y9(this.workDir,{recursive:!0}),await y9(this.stagingDir,{recursive:!0}),O.directory(this.workspace)})}doNotCopy(f,v){if(f==="problem.yml")return!0;if(f.startsWith(K3()))return!0;let l=f.match(/^problem\.([a-z][a-z])\.[a-z]*$/);if(l&&l[1]!==v)return!0;if(f===`problem.${v}.pdf`)return!0;return!1}async separateByLanguages(){await O.section("Detecting if there are language folders or not",async()=>{if((await Array.fromAsync(r5("handler.yml",{cwd:this.directory}))).length===0)await this.separateByLanguagesWithFolders();else await this.separateByLanguagesWithoutFolders()})}async separateByLanguagesWithoutFolders(){await O.section("Separating problem by languages without folders",async()=>{let v=(await Array.fromAsync(r5("problem.[a-z][a-z].yml",{cwd:this.directory}))).map((l)=>{let c=l.match(/^problem\.([a-z][a-z])\.yml$/);if(!c)throw Error(`Unexpected yml file name: ${l}`);return c[1]});this.languages=v;for(let l of v){let c=g1(this.workDir,l);await y9(c,{recursive:!0});let $=await Array.fromAsync(r5("*",{cwd:this.directory}));for(let Z of $){if(this.doNotCopy(Z,l))continue;await A4(g1(this.directory,Z),g1(c,Z),{recursive:!0,preserveTimestamps:!0})}}O.success(`Found languages: ${v.join(", ")}`)})}async separateByLanguagesWithFolders(){await O.section("Separating problem by languages with folders",async()=>{let f=await Array.fromAsync(r5("[a-z][a-z]",{cwd:this.directory}));this.languages=f;for(let v of f){let l=g1(this.directory,v),c=g1(this.workDir,v);await y9(c,{recursive:!0});let $=await Array.fromAsync(r5("*",{cwd:l}));for(let Z of $){if(this.doNotCopy(Z,v))continue;await A4(g1(l,Z),g1(c,Z),{recursive:!0,preserveTimestamps:!0})}}O.success(`Found languages: ${f.join(", ")}`)})}async readMetadata(){await O.section("Reading problem metadata",async()=>{for(let v of this.languages){let l=g1(this.workDir,v,`problem.${v}.yml`);this.problem_ymls[v]=await k5(l),m$.parse(this.problem_ymls[v])}for(let v of this.languages){let l=g1(this.workDir,v,"handler.yml");this.handlers[v]=await k5(l)}for(let v of this.languages){let l=this.problem_ymls[v];if(l.author)this.author=l.author;if(l.author)this.original_language=v;if(l.email)this.author_email=l.email}if(!this.original_language)throw Error("Original language not found in problem.<lang>.yml files");let{handler:f}=this.handlers[this.original_language];if(f==="game")this.problem_type="game";else if(f==="quiz")this.problem_type="quiz";else this.problem_type="std";O.success(`Problem type: ${this.problem_type}`),O.success(`Original language: ${this.original_language}`),O.success(`Author: ${this.author} <${this.author_email}>`)})}async findGoldenSolution(f){return await O.section("Finding golden solution",async()=>{let v=this.handlers[f].handler,l=this.handlers[f].compilers||"",c=this.handlers[f].solution,$;if(v==="circuits")$="solution.v";else if(l==="RunPython")$="solution.py";else if(l==="RunHaskell"||l==="GHC"||c==="Haskell"||c==="GHC")$="solution.hs";else if(l==="RunClojure"||l==="Clojure")$="solution.clj";else if(l==="PRO2"||l==="MakePRO2"){let Z=await Array.fromAsync(r5("solution.{cc,hh,tar}",{cwd:this.directory}));if(Z.length!==1)throw Error(`Expected exactly one PRO2/MakePRO2 solution file, but got ${Z.join(", ")}`);$=Z[0]}else{let Z=this.handlers[f].solution||"C++";if(Z==="C++"){let K=await Array.fromAsync(r5("solution.*",{cwd:this.directory}));if(O.print(K.join(", ")),K.length===1){let u=K[0].split(".").pop();Z=FI[u]}}let h=sx2[Z];if(!h)throw Error(`Unknown programming language ${Z} for solution`);let w=g1(this.workDir,f,`solution.${h}`);if(!await SO(w))throw Error(`Golden solution file ${w} not found`);$=`solution.${h}`}return O.success(`Golden solution: ${$}`),$})}formatTimeMismatch(f,v,l,c){let $=c-v,Z=ah.default.duration($).humanize();return[`- ${l} is ${Z} newer than ${f}`]}async checkMTimes_Std(f){await O.section("Checking test cases (.inp/.cor pairing and .cor after .inp and solution)",async()=>{let v=this.workDirLang,l=await this.findGoldenSolution(f),c=g1(v,l),$=await Array.fromAsync(r5("*.cor",{cwd:v})),Z=await Array.fromAsync(r5("*.inp",{cwd:v})),h=[],w=new Set($.map((K)=>K.replace(/\.cor$/,"")));for(let K of Z){let u=K.replace(/\.inp$/,"");if(!w.has(u))h.push(`- ${K}: no corresponding .cor file found`)}let q;try{q=(await tI(c)).mtimeMs}catch{h.push(`- Golden solution not found or not readable: ${c}`),q=0}for(let K of $){let H=`${K.replace(/\.cor$/,"")}.inp`,m=g1(v,K),a=g1(v,H),D;try{D=(await tI(m)).mtimeMs}catch{h.push(`- ${K}: could not stat`);continue}try{let J=(await tI(a)).mtimeMs;if(D<=J)h.push(...this.formatTimeMismatch(K,D,H,J))}catch{h.push(`${K}: corresponding input ${H} not found or not readable`)}if(q>0&&D<=q)h.push(...this.formatTimeMismatch(K,D,l,q))}if(h.length>0){O.error("Check failed: each .inp must have a .cor, and .cor files must be generated after their .inp and the golden solution.");for(let K of h)O.error(K);throw O.warning("Suggestion: Use `jtk make cor` to generate the .cor files again."),Error("File order check failed. See report above.")}O.success("All .inp have a .cor and all .cor files seem newer than their .inp and the golden solution")})}async prepareStatements_Std(f){await O.section("Preparing statements",async()=>{let v=g1(this.workDir,f);O.command(`jtk make pdf html md txt --problem_nm ${this.problem_nm}`),await t1({cwd:v,stdout:"inherit",stderr:"inherit",env:{JUTGE_INDENTATION_LEVEL:O.getIndentationLevelAsString()}})`jtk make pdf html md txt --problem_nm ${this.problem_nm}`,await hj1(g1(v,"jtk-pdf"),{recursive:!0,force:!0}),await hj1(g1(v,"jtk-text"),{recursive:!0,force:!0}),O.success("Generated statements")})}async prepareStatements_Game(f){await O.section("Preparing game statements",async()=>{let v=g1(this.workDirLang,"Doc");await O.section("Generating PDF with xelatex",async()=>{O.command("xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex"),await t1({cwd:v})`xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex`,await t1({cwd:v})`xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex`,await A4(g1(v,"main.pdf"),g1(this.workDirLang,`problem.${f}.pdf`)),O.success(`Generated ${O.hyperlink(this.workDirLang,`problem.${f}.pdf`)}`)}),await O.section("Generating TXT with pandoc",async()=>{O.command("pandoc --quiet main.tex --to plain --output main.txt"),await t1({cwd:v})`pandoc --quiet main.tex --to plain --output main.txt`,await A4(g1(v,"main.txt"),g1(this.workDirLang,`problem.${f}.txt`)),O.success(`Generated ${O.hyperlink(this.workDirLang,`problem.${f}.txt`)}`),await A4(g1(v,"main.txt"),g1(this.workDirLang,`problem.${f}.short.txt`)),O.success(`Generated ${O.hyperlink(this.workDirLang,`problem.${f}.short.txt`)}`)}),await O.section("Generating Markdown with pandoc",async()=>{O.command("pandoc --quiet main.tex --to markdown --to markdown-header_attributes --output main.md"),await t1({cwd:v})`pandoc --quiet main.tex --to markdown --to markdown-header_attributes --output main.md`,await A4(g1(v,"main.md"),g1(this.workDirLang,`problem.${f}.md`)),O.success(`Generated ${O.hyperlink(this.workDirLang,`problem.${f}.md`)}`),await A4(g1(v,"main.md"),g1(this.workDirLang,`problem.${f}.short.md`)),O.success(`Generated ${O.hyperlink(this.workDirLang,`problem.${f}.short.md`)}`)}),await O.section("Generating HTML with pandoc",async()=>{O.command("pandoc --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html"),await t1({cwd:v})`pandoc --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html`,await A4(g1(v,"main.html"),g1(this.workDirLang,`problem.${f}.html`)),O.success(`Generated ${O.hyperlink(this.workDirLang,`problem.${f}.html`)}`),await A4(g1(v,"main.html"),g1(this.workDirLang,`problem.${f}.short.html`)),O.success(`Generated ${O.hyperlink(this.workDirLang,`problem.${f}.short.html`)}`)})})}async computeCodeMetrics(f){if(!await e$1()){O.warning("jutge-code-metrics not installed, skipping code metrics");return}if(this.problem_type!=="std"){await O.section("Skipping code metrics",async()=>{await S2(),O.warning("Code metrics not applicable for this problem type")});return}await O.section("Computing code metrics",async()=>{let v=await this.findGoldenSolution(f);O.command(`jutge-code-metrics ${v}`);try{let{stdout:l}=await t1({cwd:this.workDirLang})`jutge-code-metrics ${v}`;await f4(g1(this.stagingDirLang,"code-metrics.json"),l),O.success(`Generated ${O.hyperlink(this.stagingDirLang,"code-metrics.json")}`)}catch(l){O.warning("Failed to compute code metrics")}})}async stageProblemFiles_Std(f){let v=($)=>{if($==="handler.yml")return!0;for(let Z of["inp","cor","ops"])if($.endsWith(`.${Z}`))return!0;for(let Z of wj1){if($===`solution.${Z}`)return!0;if($===`main.${Z}`)return!0}if($==="scores.yml")return!0;if($==="checker.py")return!0;if($==="checker.cc")return!0;if($==="private.tar")return!0;if($==="public.tar")return!0;if($==="solution.tar")return!0;if($==="solution.cc")return!0;if($==="solution.hh")return!0;return!1},l=g1(this.stagingDirLang,"problem.pbm");await y9(l,{recursive:!0});let c=await Array.fromAsync(r5("*",{cwd:this.workDirLang}));for(let $ of c)if(v($))await A4(g1(this.workDirLang,$),g1(l,$),{preserveTimestamps:!0});await A4(g1(this.workDirLang,`problem.${f}.yml`),g1(l,"problem.yml")),O.success(`Problem staged to ${O.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageProblemFiles_Game(f){let v=(Z)=>{if(Z==="handler.yml")return!0;if(Z==="Makefile")return!0;if(Z==="README.txt")return!0;if(Z==="README.md")return!0;if(Z.endsWith(".cc"))return!0;if(Z.endsWith(".hh"))return!0;if(Z.endsWith(".cnf"))return!0;return!1},l=g1(this.workDirLang,"Runner"),c=g1(this.stagingDirLang,"problem.pbm");await y9(c,{recursive:!0});let $=await Array.fromAsync(r5("*",{cwd:l}));for(let Z of $)if(v(Z))await A4(g1(l,Z),g1(c,Z));await A4(g1(this.workDirLang,`problem.${f}.yml`),g1(c,"problem.yml")),O.success(`Problem staged to ${O.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageAwards(f){await O.section("Staging awards",async()=>{let v=0;for(let l of["award.png","award.txt"])if(await J4(this.workDirLang,l))await A4(g1(this.workDirLang,l),g1(this.stagingDir,l)),v++;if(v>0)O.success(`Staged ${v} award file(s)`);else O.warning("No award files found")})}async stageStatements(f){await O.section("Staging statements",async()=>{let v=0;for(let l of["pdf","html","md","txt","yml","short.html","short.md","short.txt"]){let c=`problem.${f}.${l}`,$=`problem.${l}`;if(await J4(this.workDirLang,c))await A4(g1(this.workDirLang,c),g1(this.stagingDirLang,$)),v++}O.success(`Staged ${v} statement file(s)`)})}async stageFirstToSolve(){await O.section("Staging first-to-solve avatar",async()=>{let f=g1(this.stagingDir,"first-to-solve.svg"),l=Fi1(RO,{seed:this.problem_nm}).toString();await f4(f,l),O.success(`Generated ${O.hyperlink(this.stagingDir,"first-to-solve.svg")}`)})}async stageZip_Std(f){let v=($)=>{for(let Z of["pdf","html","md","txt"])if($===`problem.${f}.${Z}`)return!0;for(let Z of wj1){if($===`main.${Z}`)return!0;if($===`code.${Z}`)return!0}if(($.includes("sample")||$.startsWith("public")||$.startsWith("hint")||$.startsWith("distilled"))&&($.endsWith(".inp")||$.endsWith(".cor")))return!0;if($==="sample.dt")return!0;return!1},l=[],c=await Array.fromAsync(r5("*",{cwd:this.workDirLang}));for(let $ of c)if(v($))l.push({sourcePath:g1(this.workDirLang,$),archivePath:g1(`${this.problem_id}`,$)});await hu(l,g1(this.stagingDirLang,"problem.zip")),O.success(`Created ${O.hyperlink(this.stagingDirLang,"problem.zip")} with ${l.length} files`)}async stageZip_Game(f){let v=this.handlers[this.original_language].game.hide||["AIDummy.cc"],l=($)=>{if($.endsWith(".cc")||$.endsWith(".hh"))return!v.includes($);if($.endsWith(".cnf"))return!0;if($=="Makefile")return!0;if($=="README.txt")return!0;if($=="README.md")return!0;return!1},c=[];for(let $ of["pdf","html","md","txt","short.html","short.md","short.txt"]){let Z=`problem.${f}.${$}`;if(await J4(this.workDirLang,Z))c.push({sourcePath:g1(this.workDirLang,Z),archivePath:g1(`${this.problem_id}`,Z)})}{let $=g1(this.workDirLang,"Runner"),Z=await Array.fromAsync(r5("*",{cwd:$}));for(let h of Z)if(l(h))c.push({sourcePath:g1($,h),archivePath:g1(`${this.problem_id}`,"src",h)})}{let $=g1(this.workDirLang,"Obj"),Z=await Array.fromAsync(r5("*.o.*",{cwd:$}));for(let h of Z)c.push({sourcePath:g1($,h),archivePath:g1(`${this.problem_id}`,"src",h)})}{let $=g1(this.workDirLang,"Viewer"),Z=await Array.fromAsync(r5("**/*",{cwd:$}));for(let h of Z)c.push({sourcePath:g1($,h),archivePath:g1(`${this.problem_id}`,"src","Viewer",h)})}await hu(c,g1(this.stagingDirLang,"problem.zip")),O.success(`Created ${O.hyperlink(this.stagingDirLang,"problem.zip")} with ${c.length} files`)}async stageViewer(f){await O.section("Staging viewer",async()=>{await A4(g1(this.workDirLang,"Viewer"),g1(this.stagingDirLang,"viewer"),{recursive:!0}),O.success(`Staged ${O.hyperlink(this.stagingDirLang,"viewer")}`)})}async stageQuiz(f){await O.section("Staging quiz",async()=>{let v=Tq.parse(await k5(g1(this.workDirLang,"quiz.yml"))),l=g1(this.stagingDirLang,"quiz.pbm");await y9(l,{recursive:!0}),await Nf(g1(l,"quiz.yml"),v),await A4(g1(this.workDirLang,`problem.${f}.yml`),g1(l,"problem.yml")),await A4(g1(this.workDirLang,`problem.${f}.yml`),g1(l,"..","problem.yml"));for(let c of v.questions){{let $=g1(this.workDirLang,`${c.file}.yml`),Z=g1(l,`${c.file}.yml`);if(await SO($))await A4($,Z);else throw Error(`Quiz question file ${c.file}.yml not found`)}{let $=g1(this.workDirLang,`${c.file}.py`),Z=g1(l,`${c.file}.py`);if(await SO($))await A4($,Z)}}O.success(`Staged ${O.hyperlink(this.stagingDirLang,"quiz")}`)})}async stageInformationYml(){await O.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},v=g1(this.stagingDir,"information.yml");await Nf(v,f),O.success(`Generated ${O.hyperlink(this.stagingDir,"information.yml")}`)})}async stageReadMd(){await O.section("Staging README.md",async()=>{let f=m5.version,v=this.languages.map((Z)=>{let w=this.problem_ymls[Z].title,q=`- *${Z}*: ${w}
|
|
693
|
+
*/var RO={};Q5(RO,{schema:()=>$j1,meta:()=>px2,create:()=>xx2});var xI={};Q5(xI,{ringTwo:()=>Qi1,ringThree:()=>si1,ringOne:()=>Ui1,ringFour:()=>fj1,ringFive:()=>_j1,ring:()=>ei1});var ei1={container:(f,v)=>{var l,c,$,Z,h,w,q,K,u,H,m,a,D,J,W,X,j,k,N,y;return`${(c=(l=f.ringOne)===null||l===void 0?void 0:l.value(f,v))!==null&&c!==void 0?c:""}${(Z=($=f.ringTwo)===null||$===void 0?void 0:$.value(f,v))!==null&&Z!==void 0?Z:""}${(w=(h=f.ringThree)===null||h===void 0?void 0:h.value(f,v))!==null&&w!==void 0?w:""}${(K=(q=f.ringFour)===null||q===void 0?void 0:q.value(f,v))!==null&&K!==void 0?K:""}${(H=(u=f.ringFive)===null||u===void 0?void 0:u.value(f,v))!==null&&H!==void 0?H:""}<g transform="matrix(1 0 0 -1 0 100)">${(a=(m=f.ringOne)===null||m===void 0?void 0:m.value(f,v))!==null&&a!==void 0?a:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(J=(D=f.ringTwo)===null||D===void 0?void 0:D.value(f,v))!==null&&J!==void 0?J:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(X=(W=f.ringThree)===null||W===void 0?void 0:W.value(f,v))!==null&&X!==void 0?X:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(k=(j=f.ringFour)===null||j===void 0?void 0:j.value(f,v))!==null&&k!==void 0?k:""}</g><g transform="matrix(1 0 0 -1 0 100)">${(y=(N=f.ringFive)===null||N===void 0?void 0:N.value(f,v))!==null&&y!==void 0?y:""}</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 Ui1={half:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,quarter:(f,v)=>`<path d="M50 10V0C22.386 0 0 22.386 0 50h10c0-22.091 17.909-40 40-40Z" fill="${H1.xml(`${v.ring}`)}"/>`,eighth:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,full:(f,v)=>`<circle cx="50" cy="50" r="45" stroke="${H1.xml(`${v.ring}`)}" stroke-width="10"/>`};var Qi1={eighth:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,quarter:(f,v)=>`<path d="M50 10c-22.091 0-40 17.909-40 40h10c0-16.569 13.431-30 30-30V10Z" fill="${H1.xml(`${v.ring}`)}"/>`,half:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,full:(f,v)=>`<circle cx="50" cy="50" r="35" stroke="${H1.xml(`${v.ring}`)}" stroke-width="10"/>`};var si1={eighth:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,quarter:(f,v)=>`<path d="M50 20c-16.569 0-30 13.431-30 30h10c0-11.046 8.954-20 20-20V20Z" fill="${H1.xml(`${v.ring}`)}"/>`,half:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,full:(f,v)=>`<circle cx="50" cy="50" r="25" stroke="${H1.xml(`${v.ring}`)}" stroke-width="10"/>`};var fj1={eighth:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,quarter:(f,v)=>`<path d="M50 30c-11.046 0-20 8.954-20 20h10c0-5.523 4.477-10 10-10V30Z" fill="${H1.xml(`${v.ring}`)}"/>`,half:(f,v)=>`<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="${H1.xml(`${v.ring}`)}"/>`,full:(f,v)=>`<circle cx="50" cy="50" r="15" stroke="${H1.xml(`${v.ring}`)}" stroke-width="10"/>`};var _j1={eighth:(f,v)=>`<path d="m42.929 42.929 7.07 7.07H40a9.97 9.97 0 0 1 2.93-7.07Z" fill="${H1.xml(`${v.ring}`)}"/>`,quarter:(f,v)=>`<path d="M50 40v10H40c0-5.523 4.477-10 10-10Z" fill="${H1.xml(`${v.ring}`)}"/>`,half:(f,v)=>`<path d="M60 50c0-5.523-4.477-10-10-10s-10 4.477-10 10h20Z" fill="${H1.xml(`${v.ring}`)}"/>`,full:(f,v)=>`<circle cx="50" cy="50" r="10" fill="${H1.xml(`${v.ring}`)}"/>`};function yl({prng:f,group:v,width:l,height:c,values:$=[],rotation:Z,offsetX:h,offsetY:w}){let q=xI,K=f.pick($),u=f.integer(Math.min(...Z),Math.max(...Z)),H=f.integer(Math.min(...h),Math.max(...h)),m=f.integer(Math.min(...w),Math.max(...w));if(K&&q[v][K])return{name:K,value(a,D){var J,W,X;let j=q[v][K](a,D);if(this.rotation||this.offsetX||this.offsetY)j=`<g transform="translate(${(J=this.offsetX)!==null&&J!==void 0?J:0}, ${(W=this.offsetY)!==null&&W!==void 0?W:0}) rotate(${(X=this.rotation)!==null&&X!==void 0?X:0} ${l/2} ${c/2})">${j}</g>`;return j},rotation:u,offsetX:H,offsetY:m};else return}function vj1({prng:f,options:v}){var l,c,$,Z,h,w;let q=yl({prng:f,group:"ring",values:v.ring,width:100,height:100,rotation:((l=v.ringRotation)===null||l===void 0?void 0:l.length)?v.ringRotation:[0],offsetX:[0],offsetY:[0]}),K=yl({prng:f,group:"ringOne",values:v.ringOne,width:100,height:100,rotation:((c=v.ringOneRotation)===null||c===void 0?void 0:c.length)?v.ringOneRotation:[0],offsetX:[0],offsetY:[0]}),u=yl({prng:f,group:"ringTwo",values:v.ringTwo,width:100,height:100,rotation:(($=v.ringTwoRotation)===null||$===void 0?void 0:$.length)?v.ringTwoRotation:[0],offsetX:[0],offsetY:[0]}),H=yl({prng:f,group:"ringThree",values:v.ringThree,width:100,height:100,rotation:((Z=v.ringThreeRotation)===null||Z===void 0?void 0:Z.length)?v.ringThreeRotation:[0],offsetX:[0],offsetY:[0]}),m=yl({prng:f,group:"ringFour",values:v.ringFour,width:100,height:100,rotation:((h=v.ringFourRotation)===null||h===void 0?void 0:h.length)?v.ringFourRotation:[0],offsetX:[0],offsetY:[0]}),a=yl({prng:f,group:"ringFive",values:v.ringFive,width:100,height:100,rotation:((w=v.ringFiveRotation)===null||w===void 0?void 0:w.length)?v.ringFiveRotation:[0],offsetX:[0],offsetY:[0]});return{ring:q,ringOne:K,ringTwo:u,ringThree:H,ringFour:m,ringFive:a}}function lj1(f){return f==="transparent"?f:`#${f}`}function cj1({prng:f,options:v}){var l;return{ring:lj1(f.pick((l=v.ringColor)!==null&&l!==void 0?l:[],"transparent"))}}var $j1={$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 px2={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/"}},xx2=({prng:f,options:v})=>{var l,c;let $=vj1({prng:f,options:v}),Z=cj1({prng:f,options:v});return{attributes:{viewBox:"0 0 100 100",fill:"none","shape-rendering":"crispEdges"},body:`${(c=(l=$.ring)===null||l===void 0?void 0:l.value($,Z))!==null&&c!==void 0?c:""}`,extra:()=>({...Object.entries($).reduce((h,[w,q])=>{return h[w]=q===null||q===void 0?void 0:q.name,h},{}),...Object.entries(Z).reduce((h,[w,q])=>{return h[`${w}Color`]=q,h},{})})}};var ah=m2(ob(),1),qj1=m2(Fb(),1),Kj1=m2(Zj1(),1);import{cp as A4,exists as SO,glob as r5,mkdir as y9,rm as hj1,stat as tI,writeFile as Ux2}from"fs/promises";r7();var Pj1=m2(mD(),1);import Yh from"os";import{join as g1,resolve as Qx2}from"path";ah.default.extend(qj1.default);ah.default.extend(Kj1.default);class BI{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,v){if(this.directory=Qx2(f),!this.directory.endsWith(".pbm"))throw Error(`Directory ${this.directory} is not a problem root directory (missing .pbm suffix)`);this.problem_nm=v,this.workspace=g1(f,K3()+"-stage",x0()),this.workDir=g1(this.workspace,"work.pbm"),this.stagingDir=g1(this.workspace,"stage",this.problem_nm)}async stage(){await O.section(`Staging problem at ${O.hyperlink(this.directory)}`,async()=>{await this.createWorkspace(),await this.separateByLanguages(),await this.readMetadata();for(let f of this.languages)await O.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 O.section("Summary",async()=>{let f=g1(this.stagingDir,"README.md");O.success("README.md content:"),await O.markdown(await p2(f)),O.success("Staging tree:"),O.print(Pj1.default(this.stagingDir))}),O.success(`Problem successfully staged at directory ${O.hyperlink(this.stagingDir)}`),await bO(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=g1(this.workDir,f),this.problem_id=`${this.problem_nm}_${f}`,this.stagingDirLang=g1(this.stagingDir,f),await y9(this.stagingDirLang,{recursive:!0})}async createWorkspace(){await O.section(`Creating workspace ${this.workspace}`,async()=>{if(await SO(this.workspace))throw Error(`Workspace directory ${this.workspace} already exists`);await y9(this.workspace,{recursive:!0}),await y9(this.workDir,{recursive:!0}),await y9(this.stagingDir,{recursive:!0}),O.directory(this.workspace)})}doNotCopy(f,v){if(f==="problem.yml")return!0;if(f.startsWith(K3()))return!0;let l=f.match(/^problem\.([a-z][a-z])\.[a-z]*$/);if(l&&l[1]!==v)return!0;if(f===`problem.${v}.pdf`)return!0;return!1}async separateByLanguages(){await O.section("Detecting if there are language folders or not",async()=>{if((await Array.fromAsync(r5("handler.yml",{cwd:this.directory}))).length===0)await this.separateByLanguagesWithFolders();else await this.separateByLanguagesWithoutFolders()})}async separateByLanguagesWithoutFolders(){await O.section("Separating problem by languages without folders",async()=>{let v=(await Array.fromAsync(r5("problem.[a-z][a-z].yml",{cwd:this.directory}))).map((l)=>{let c=l.match(/^problem\.([a-z][a-z])\.yml$/);if(!c)throw Error(`Unexpected yml file name: ${l}`);return c[1]});this.languages=v;for(let l of v){let c=g1(this.workDir,l);await y9(c,{recursive:!0});let $=await Array.fromAsync(r5("*",{cwd:this.directory}));for(let Z of $){if(this.doNotCopy(Z,l))continue;await A4(g1(this.directory,Z),g1(c,Z),{recursive:!0,preserveTimestamps:!0})}}O.success(`Found languages: ${v.join(", ")}`)})}async separateByLanguagesWithFolders(){await O.section("Separating problem by languages with folders",async()=>{let f=await Array.fromAsync(r5("[a-z][a-z]",{cwd:this.directory}));this.languages=f;for(let v of f){let l=g1(this.directory,v),c=g1(this.workDir,v);await y9(c,{recursive:!0});let $=await Array.fromAsync(r5("*",{cwd:l}));for(let Z of $){if(this.doNotCopy(Z,v))continue;await A4(g1(l,Z),g1(c,Z),{recursive:!0,preserveTimestamps:!0})}}O.success(`Found languages: ${f.join(", ")}`)})}async readMetadata(){await O.section("Reading problem metadata",async()=>{for(let v of this.languages){let l=g1(this.workDir,v,`problem.${v}.yml`);this.problem_ymls[v]=await k5(l),m$.parse(this.problem_ymls[v])}for(let v of this.languages){let l=g1(this.workDir,v,"handler.yml");this.handlers[v]=await k5(l)}for(let v of this.languages){let l=this.problem_ymls[v];if(l.author)this.author=l.author;if(l.author)this.original_language=v;if(l.email)this.author_email=l.email}if(!this.original_language)throw Error("Original language not found in problem.<lang>.yml files");let{handler:f}=this.handlers[this.original_language];if(f==="game")this.problem_type="game";else if(f==="quiz")this.problem_type="quiz";else this.problem_type="std";O.success(`Problem type: ${this.problem_type}`),O.success(`Original language: ${this.original_language}`),O.success(`Author: ${this.author} <${this.author_email}>`)})}async findGoldenSolution(f){return await O.section("Finding golden solution",async()=>{let v=this.handlers[f].handler,l=this.handlers[f].compilers||"",c=this.handlers[f].solution,$;if(v==="circuits")$="solution.v";else if(l==="RunPython")$="solution.py";else if(l==="RunHaskell"||l==="GHC"||c==="Haskell"||c==="GHC")$="solution.hs";else if(l==="RunClojure"||l==="Clojure")$="solution.clj";else if(l==="PRO2"||l==="MakePRO2"){let Z=await Array.fromAsync(r5("solution.{cc,hh,tar}",{cwd:this.directory}));if(Z.length!==1)throw Error(`Expected exactly one PRO2/MakePRO2 solution file, but got ${Z.join(", ")}`);$=Z[0]}else{let Z=this.handlers[f].solution||"C++";if(Z==="C++"){let K=await Array.fromAsync(r5("solution.*",{cwd:this.directory}));if(O.print(K.join(", ")),K.length===1){let u=K[0].split(".").pop();Z=FI[u]}}let h=sx2[Z];if(!h)throw Error(`Unknown programming language ${Z} for solution`);let w=g1(this.workDir,f,`solution.${h}`);if(!await SO(w))throw Error(`Golden solution file ${w} not found`);$=`solution.${h}`}return O.success(`Golden solution: ${$}`),$})}formatTimeMismatch(f,v,l,c){let $=c-v,Z=ah.default.duration($).humanize();return[`- ${l} is ${Z} newer than ${f}`]}async checkMTimes_Std(f){await O.section("Checking test cases (.inp/.cor pairing and .cor after .inp and solution)",async()=>{let v=this.workDirLang,l=await this.findGoldenSolution(f),c=g1(v,l),$=await Array.fromAsync(r5("*.cor",{cwd:v})),Z=await Array.fromAsync(r5("*.inp",{cwd:v})),h=[],w=new Set($.map((K)=>K.replace(/\.cor$/,"")));for(let K of Z){let u=K.replace(/\.inp$/,"");if(!w.has(u))h.push(`- ${K}: no corresponding .cor file found`)}let q;try{q=(await tI(c)).mtimeMs}catch{h.push(`- Golden solution not found or not readable: ${c}`),q=0}for(let K of $){let H=`${K.replace(/\.cor$/,"")}.inp`,m=g1(v,K),a=g1(v,H),D;try{D=(await tI(m)).mtimeMs}catch{h.push(`- ${K}: could not stat`);continue}try{let J=(await tI(a)).mtimeMs;if(D<=J)h.push(...this.formatTimeMismatch(K,D,H,J))}catch{h.push(`${K}: corresponding input ${H} not found or not readable`)}if(q>0&&D<=q)h.push(...this.formatTimeMismatch(K,D,l,q))}if(h.length>0){O.error("Check failed: each .inp must have a .cor, and .cor files must be generated after their .inp and the golden solution.");for(let K of h)O.error(K);throw O.warning("Suggestion: Use `jtk make cor` to generate the .cor files again."),Error("File order check failed. See report above.")}O.success("All .inp have a .cor and all .cor files seem newer than their .inp and the golden solution")})}async prepareStatements_Std(f){await O.section("Preparing statements",async()=>{let v=g1(this.workDir,f);O.command(`jtk make pdf html md txt --problem_nm ${this.problem_nm}`),await t1({cwd:v,stdout:"inherit",stderr:"inherit",env:{JUTGE_INDENTATION_LEVEL:O.getIndentationLevelAsString()}})`jtk make pdf html md txt --problem_nm ${this.problem_nm}`,await hj1(g1(v,"jtk-pdf"),{recursive:!0,force:!0}),await hj1(g1(v,"jtk-text"),{recursive:!0,force:!0}),O.success("Generated statements")})}async prepareStatements_Game(f){await O.section("Preparing game statements",async()=>{let v=g1(this.workDirLang,"Doc");await O.section("Generating PDF with xelatex",async()=>{O.command("xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex"),await t1({cwd:v})`xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex`,await t1({cwd:v})`xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex`,await A4(g1(v,"main.pdf"),g1(this.workDirLang,`problem.${f}.pdf`)),O.success(`Generated ${O.hyperlink(this.workDirLang,`problem.${f}.pdf`)}`)}),await O.section("Generating TXT with pandoc",async()=>{O.command("pandoc --quiet main.tex --to plain --output main.txt"),await t1({cwd:v})`pandoc --quiet main.tex --to plain --output main.txt`,await A4(g1(v,"main.txt"),g1(this.workDirLang,`problem.${f}.txt`)),O.success(`Generated ${O.hyperlink(this.workDirLang,`problem.${f}.txt`)}`),await A4(g1(v,"main.txt"),g1(this.workDirLang,`problem.${f}.short.txt`)),O.success(`Generated ${O.hyperlink(this.workDirLang,`problem.${f}.short.txt`)}`)}),await O.section("Generating Markdown with pandoc",async()=>{O.command("pandoc --quiet main.tex --to markdown --to markdown-header_attributes --output main.md"),await t1({cwd:v})`pandoc --quiet main.tex --to markdown --to markdown-header_attributes --output main.md`,await A4(g1(v,"main.md"),g1(this.workDirLang,`problem.${f}.md`)),O.success(`Generated ${O.hyperlink(this.workDirLang,`problem.${f}.md`)}`),await A4(g1(v,"main.md"),g1(this.workDirLang,`problem.${f}.short.md`)),O.success(`Generated ${O.hyperlink(this.workDirLang,`problem.${f}.short.md`)}`)}),await O.section("Generating HTML with pandoc",async()=>{O.command("pandoc --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html"),await t1({cwd:v})`pandoc --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html`,await A4(g1(v,"main.html"),g1(this.workDirLang,`problem.${f}.html`)),O.success(`Generated ${O.hyperlink(this.workDirLang,`problem.${f}.html`)}`),await A4(g1(v,"main.html"),g1(this.workDirLang,`problem.${f}.short.html`)),O.success(`Generated ${O.hyperlink(this.workDirLang,`problem.${f}.short.html`)}`)})})}async computeCodeMetrics(f){if(!await e$1()){O.warning("jutge-code-metrics not installed, skipping code metrics");return}if(this.problem_type!=="std"){await O.section("Skipping code metrics",async()=>{await S2(),O.warning("Code metrics not applicable for this problem type")});return}await O.section("Computing code metrics",async()=>{let v=await this.findGoldenSolution(f);O.command(`jutge-code-metrics ${v}`);try{let{stdout:l}=await t1({cwd:this.workDirLang})`jutge-code-metrics ${v}`;await f4(g1(this.stagingDirLang,"code-metrics.json"),l),O.success(`Generated ${O.hyperlink(this.stagingDirLang,"code-metrics.json")}`)}catch(l){O.warning("Failed to compute code metrics")}})}async stageProblemFiles_Std(f){let v=($)=>{if($==="handler.yml")return!0;for(let Z of["inp","cor","ops"])if($.endsWith(`.${Z}`))return!0;for(let Z of wj1){if($===`solution.${Z}`)return!0;if($===`main.${Z}`)return!0}if($==="scores.yml")return!0;if($==="checker.py")return!0;if($==="checker.cc")return!0;if($==="private.tar")return!0;if($==="public.tar")return!0;if($==="solution.tar")return!0;if($==="solution.cc")return!0;if($==="solution.hh")return!0;return!1},l=g1(this.stagingDirLang,"problem.pbm");await y9(l,{recursive:!0});let c=await Array.fromAsync(r5("*",{cwd:this.workDirLang}));for(let $ of c)if(v($))await A4(g1(this.workDirLang,$),g1(l,$),{preserveTimestamps:!0});await A4(g1(this.workDirLang,`problem.${f}.yml`),g1(l,"problem.yml")),O.success(`Problem staged to ${O.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageProblemFiles_Game(f){let v=(Z)=>{if(Z==="handler.yml")return!0;if(Z==="Makefile")return!0;if(Z==="README.txt")return!0;if(Z==="README.md")return!0;if(Z.endsWith(".cc"))return!0;if(Z.endsWith(".hh"))return!0;if(Z.endsWith(".cnf"))return!0;return!1},l=g1(this.workDirLang,"Runner"),c=g1(this.stagingDirLang,"problem.pbm");await y9(c,{recursive:!0});let $=await Array.fromAsync(r5("*",{cwd:l}));for(let Z of $)if(v(Z))await A4(g1(l,Z),g1(c,Z));await A4(g1(this.workDirLang,`problem.${f}.yml`),g1(c,"problem.yml")),O.success(`Problem staged to ${O.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageAwards(f){await O.section("Staging awards",async()=>{let v=0;for(let l of["award.png","award.txt"])if(await J4(this.workDirLang,l))await A4(g1(this.workDirLang,l),g1(this.stagingDir,l)),v++;if(v>0)O.success(`Staged ${v} award file(s)`);else O.warning("No award files found")})}async stageStatements(f){await O.section("Staging statements",async()=>{let v=0;for(let l of["pdf","html","md","txt","yml","short.html","short.md","short.txt"]){let c=`problem.${f}.${l}`,$=`problem.${l}`;if(await J4(this.workDirLang,c))await A4(g1(this.workDirLang,c),g1(this.stagingDirLang,$)),v++}O.success(`Staged ${v} statement file(s)`)})}async stageFirstToSolve(){await O.section("Staging first-to-solve avatar",async()=>{let f=g1(this.stagingDir,"first-to-solve.svg"),l=Fi1(RO,{seed:this.problem_nm}).toString();await f4(f,l),O.success(`Generated ${O.hyperlink(this.stagingDir,"first-to-solve.svg")}`)})}async stageZip_Std(f){let v=($)=>{for(let Z of["pdf","html","md","txt"])if($===`problem.${f}.${Z}`)return!0;for(let Z of wj1){if($===`main.${Z}`)return!0;if($===`code.${Z}`)return!0}if(($.includes("sample")||$.startsWith("public")||$.startsWith("hint")||$.startsWith("distilled"))&&($.endsWith(".inp")||$.endsWith(".cor")))return!0;if($==="sample.dt")return!0;return!1},l=[],c=await Array.fromAsync(r5("*",{cwd:this.workDirLang}));for(let $ of c)if(v($))l.push({sourcePath:g1(this.workDirLang,$),archivePath:g1(`${this.problem_id}`,$)});await hu(l,g1(this.stagingDirLang,"problem.zip")),O.success(`Created ${O.hyperlink(this.stagingDirLang,"problem.zip")} with ${l.length} files`)}async stageZip_Game(f){let v=this.handlers[this.original_language].game.hide||["AIDummy.cc"],l=($)=>{if($.endsWith(".cc")||$.endsWith(".hh"))return!v.includes($);if($.endsWith(".cnf"))return!0;if($=="Makefile")return!0;if($=="README.txt")return!0;if($=="README.md")return!0;return!1},c=[];for(let $ of["pdf","html","md","txt","short.html","short.md","short.txt"]){let Z=`problem.${f}.${$}`;if(await J4(this.workDirLang,Z))c.push({sourcePath:g1(this.workDirLang,Z),archivePath:g1(`${this.problem_id}`,Z)})}{let $=g1(this.workDirLang,"Runner"),Z=await Array.fromAsync(r5("*",{cwd:$}));for(let h of Z)if(l(h))c.push({sourcePath:g1($,h),archivePath:g1(`${this.problem_id}`,"src",h)})}{let $=g1(this.workDirLang,"Obj"),Z=await Array.fromAsync(r5("*.o.*",{cwd:$}));for(let h of Z)c.push({sourcePath:g1($,h),archivePath:g1(`${this.problem_id}`,"src",h)})}{let $=g1(this.workDirLang,"Viewer"),Z=await Array.fromAsync(r5("**/*",{cwd:$}));for(let h of Z)c.push({sourcePath:g1($,h),archivePath:g1(`${this.problem_id}`,"src","Viewer",h)})}await hu(c,g1(this.stagingDirLang,"problem.zip")),O.success(`Created ${O.hyperlink(this.stagingDirLang,"problem.zip")} with ${c.length} files`)}async stageViewer(f){await O.section("Staging viewer",async()=>{await A4(g1(this.workDirLang,"Viewer"),g1(this.stagingDirLang,"viewer"),{recursive:!0}),O.success(`Staged ${O.hyperlink(this.stagingDirLang,"viewer")}`)})}async stageQuiz(f){await O.section("Staging quiz",async()=>{let v=Tq.parse(await k5(g1(this.workDirLang,"quiz.yml"))),l=g1(this.stagingDirLang,"quiz.pbm");await y9(l,{recursive:!0}),await Nf(g1(l,"quiz.yml"),v),await A4(g1(this.workDirLang,`problem.${f}.yml`),g1(l,"problem.yml")),await A4(g1(this.workDirLang,`problem.${f}.yml`),g1(l,"..","problem.yml"));for(let c of v.questions){{let $=g1(this.workDirLang,`${c.file}.yml`),Z=g1(l,`${c.file}.yml`);if(await SO($))await A4($,Z);else throw Error(`Quiz question file ${c.file}.yml not found`)}{let $=g1(this.workDirLang,`${c.file}.py`),Z=g1(l,`${c.file}.py`);if(await SO($))await A4($,Z)}}O.success(`Staged ${O.hyperlink(this.stagingDirLang,"quiz")}`)})}async stageInformationYml(){await O.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},v=g1(this.stagingDir,"information.yml");await Nf(v,f),O.success(`Generated ${O.hyperlink(this.stagingDir,"information.yml")}`)})}async stageReadMd(){await O.section("Staging README.md",async()=>{let f=m5.version,v=this.languages.map((Z)=>{let w=this.problem_ymls[Z].title,q=`- *${Z}*: ${w}
|
|
694
694
|
`;if(Z!==this.original_language)q+=` ${this.problem_ymls[Z].translator} <${this.problem_ymls[Z].translator_email}>`;else q="";return q}).join(`
|
|
695
695
|
`);if(v.trim())v=`## Translations
|
|
696
696
|
|