@jutge.org/toolkit 4.4.55 → 4.4.58
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 +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -879,7 +879,7 @@ Translate the given problem statement to ${mi[n]}.
|
|
|
879
879
|
The translation must be accurate and use proper technical terminology.
|
|
880
880
|
Maintain the LaTeX formatting and macros.
|
|
881
881
|
The texts that the program must read and write should not be translated.
|
|
882
|
-
`,o=Yo(await jd(e,t,"add-statement-translation",a,s)),l={title:tN(o)||"Error translating title",translator:ds.name,translator_email:ds.email,model:t};await Os(r.directory,`problem.${n}.tex`,o),await ec(r.directory,`problem.${n}.yml`,l),I.success(`Translation completed: files problem.${n}.tex and problem.${n}.yml created`),I.warning("Please review the generated translation")})}async function h0t(e,t,r,n){if(!r.goldenSolution)throw Error("No golden solution defined");let i=r.goldenSolution.split(".").pop();if(!i)throw Error("Invalid golden solution filename");if(!C0.includes(n))throw Error(`Extension ${n} is not supported`);if(r.solutions.includes(`solution.${n}`))throw Error("Solution already exists");let s=Ws[n];if(!s)throw Error(`Programming language for extension ${n} not found`);let a=Ws[i],o=await aa(r.directory,r.goldenSolution),l=await Bpe(s),c=`
|
|
882
|
+
`,o=Yo(await jd(e,t,"add-statement-translation",a,s)),l={title:tN(o)||"Error translating title",translator:ds.name,translator_email:ds.email,original_language:i,model:t};await Os(r.directory,`problem.${n}.tex`,o),await ec(r.directory,`problem.${n}.yml`,l),I.success(`Translation completed: files problem.${n}.tex and problem.${n}.yml created`),I.warning("Please review the generated translation")})}async function h0t(e,t,r,n){if(!r.goldenSolution)throw Error("No golden solution defined");let i=r.goldenSolution.split(".").pop();if(!i)throw Error("Invalid golden solution filename");if(!C0.includes(n))throw Error(`Extension ${n} is not supported`);if(r.solutions.includes(`solution.${n}`))throw Error("Solution already exists");let s=Ws[n];if(!s)throw Error(`Programming language for extension ${n} not found`);let a=Ws[i],o=await aa(r.directory,r.goldenSolution),l=await Bpe(s),c=`
|
|
883
883
|
Convert the given program in ${a} to ${s}.
|
|
884
884
|
|
|
885
885
|
The translation must be accurate and follow the structure and logic of the original program.
|
|
@@ -1052,7 +1052,7 @@ User question: ${e}`,a=await jd(r,t,"ask",n,s);await I.markdown(a),I.warning(`Th
|
|
|
1052
1052
|
*
|
|
1053
1053
|
* Code licensed under MIT (https://github.com/dicebear/dicebear/blob/main/LICENSE)
|
|
1054
1054
|
* Copyright (c) 2024 Florian Körner
|
|
1055
|
-
*/var Ewt={half:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,quarter:(e,t)=>`<path d="M50 10V0C22.386 0 0 22.386 0 50h10c0-22.091 17.909-40 40-40Z" fill="${hs(`${t.ring}`)}"/>`,eighth:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,full:(e,t)=>`<circle cx="50" cy="50" r="45" stroke="${hs(`${t.ring}`)}" stroke-width="10"/>`};var ywt={eighth:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,quarter:(e,t)=>`<path d="M50 10c-22.091 0-40 17.909-40 40h10c0-16.569 13.431-30 30-30V10Z" fill="${hs(`${t.ring}`)}"/>`,half:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,full:(e,t)=>`<circle cx="50" cy="50" r="35" stroke="${hs(`${t.ring}`)}" stroke-width="10"/>`};var bwt={eighth:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,quarter:(e,t)=>`<path d="M50 20c-16.569 0-30 13.431-30 30h10c0-11.046 8.954-20 20-20V20Z" fill="${hs(`${t.ring}`)}"/>`,half:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,full:(e,t)=>`<circle cx="50" cy="50" r="25" stroke="${hs(`${t.ring}`)}" stroke-width="10"/>`};var Swt={eighth:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,quarter:(e,t)=>`<path d="M50 30c-11.046 0-20 8.954-20 20h10c0-5.523 4.477-10 10-10V30Z" fill="${hs(`${t.ring}`)}"/>`,half:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,full:(e,t)=>`<circle cx="50" cy="50" r="15" stroke="${hs(`${t.ring}`)}" stroke-width="10"/>`};var xwt={eighth:(e,t)=>`<path d="m42.929 42.929 7.07 7.07H40a9.97 9.97 0 0 1 2.93-7.07Z" fill="${hs(`${t.ring}`)}"/>`,quarter:(e,t)=>`<path d="M50 40v10H40c0-5.523 4.477-10 10-10Z" fill="${hs(`${t.ring}`)}"/>`,half:(e,t)=>`<path d="M60 50c0-5.523-4.477-10-10-10s-10 4.477-10 10h20Z" fill="${hs(`${t.ring}`)}"/>`,full:(e,t)=>`<circle cx="50" cy="50" r="10" fill="${hs(`${t.ring}`)}"/>`};function lv({prng:e,group:t,width:r,height:n,values:i=[],rotation:s,offsetX:a,offsetY:o}){let l=kge,c=e.pick(i),u=e.integer(Math.min(...s),Math.max(...s)),d=e.integer(Math.min(...a),Math.max(...a)),f=e.integer(Math.min(...o),Math.max(...o));if(c&&l[t][c])return{name:c,value(p,h){var _,g,S;let v=l[t][c](p,h);if(this.rotation||this.offsetX||this.offsetY)v=`<g transform="translate(${(_=this.offsetX)!==null&&_!==void 0?_:0}, ${(g=this.offsetY)!==null&&g!==void 0?g:0}) rotate(${(S=this.rotation)!==null&&S!==void 0?S:0} ${r/2} ${n/2})">${v}</g>`;return v},rotation:u,offsetX:d,offsetY:f};else return}function Twt({prng:e,options:t}){var r,n,i,s,a,o;let l=lv({prng:e,group:"ring",values:t.ring,width:100,height:100,rotation:((r=t.ringRotation)===null||r===void 0?void 0:r.length)?t.ringRotation:[0],offsetX:[0],offsetY:[0]}),c=lv({prng:e,group:"ringOne",values:t.ringOne,width:100,height:100,rotation:((n=t.ringOneRotation)===null||n===void 0?void 0:n.length)?t.ringOneRotation:[0],offsetX:[0],offsetY:[0]}),u=lv({prng:e,group:"ringTwo",values:t.ringTwo,width:100,height:100,rotation:((i=t.ringTwoRotation)===null||i===void 0?void 0:i.length)?t.ringTwoRotation:[0],offsetX:[0],offsetY:[0]}),d=lv({prng:e,group:"ringThree",values:t.ringThree,width:100,height:100,rotation:((s=t.ringThreeRotation)===null||s===void 0?void 0:s.length)?t.ringThreeRotation:[0],offsetX:[0],offsetY:[0]}),f=lv({prng:e,group:"ringFour",values:t.ringFour,width:100,height:100,rotation:((a=t.ringFourRotation)===null||a===void 0?void 0:a.length)?t.ringFourRotation:[0],offsetX:[0],offsetY:[0]}),p=lv({prng:e,group:"ringFive",values:t.ringFive,width:100,height:100,rotation:((o=t.ringFiveRotation)===null||o===void 0?void 0:o.length)?t.ringFiveRotation:[0],offsetX:[0],offsetY:[0]});return{ring:l,ringOne:c,ringTwo:u,ringThree:d,ringFour:f,ringFive:p}}function vwt(e){return e==="transparent"?e:`#${e}`}function wwt({prng:e,options:t}){var r;return{ring:vwt(e.pick((r=t.ringColor)!==null&&r!==void 0?r:[],"transparent"))}}var Cwt={$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 Bln={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/"}},Fln=({prng:e,options:t})=>{var r,n;let i=Twt({prng:e,options:t}),s=wwt({prng:e,options:t});return{attributes:{viewBox:"0 0 100 100",fill:"none","shape-rendering":"crispEdges"},body:`${(n=(r=i.ring)===null||r===void 0?void 0:r.value(i,s))!==null&&n!==void 0?n:""}`,extra:()=>({...Object.entries(i).reduce((a,[o,l])=>(a[o]=l===null||l===void 0?void 0:l.name,a),{}),...Object.entries(s).reduce((a,[o,l])=>(a[`${o}Color`]=l,a),{})})}};var rI=Pt(xW(),1),Nwt=Pt(TW(),1),Iwt=Pt(Awt(),1);import{cp as Ka,exists as Vj,glob as Oc,mkdir as Y0,rm as Rwt,stat as Pge,writeFile as Uln}from"fs/promises";Xf();import tI from"os";import{join as at,resolve as Gln}from"path";rI.default.extend(Nwt.default);rI.default.extend(Iwt.default);class Bge{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(e,t){if(this.directory=Gln(e),!this.directory.endsWith(".pbm"))throw Error(`Directory ${this.directory} is not a problem root directory (missing .pbm suffix)`);this.problem_nm=t,this.workspace=at(e,Ns()+"-stage",od()),this.workDir=at(this.workspace,"work.pbm"),this.stagingDir=at(this.workspace,"stage",this.problem_nm)}async stage(){await I.section(`Staging problem at ${I.hyperlink(this.directory)}`,async()=>{await this.createWorkspace(),await this.separateByLanguages(),await this.readMetadata();for(let e of this.languages)await I.section(`Staging language ${e}`,async()=>{if(await this.setLanguage(e),this.problem_type==="std")await this.stageLanguage_Std(e);else if(this.problem_type==="game")await this.stageLanguage_Game(e);else if(this.problem_type==="quiz")await this.stageLanguage_Quizz(e)});await this.stageFirstToSolve(),await this.stageInformationYml(),await this.stageReadMd()}),await I.section("Summary",async()=>{let e=at(this.stagingDir,"README.md");I.success("README.md content:"),await I.markdown(await qr(e)),I.success("Staging tree:"),I.print(Jf(this.stagingDir))}),I.success(`Problem successfully staged at directory ${I.hyperlink(this.stagingDir)}`),await cN(this.stagingDir)}async stageLanguage_Std(e){await this.prepareStatements_Std(e),await this.computeCodeMetrics(e),await this.makeTarFiles_Std(e),await this.stageProblemFiles_Std(e),await this.stageAwards(e),await this.stageStatements(e),await this.stageZip_Std(e)}async stageLanguage_Game(e){await this.prepareStatements_Game(e),await this.computeCodeMetrics(e),await this.stageProblemFiles_Game(e),await this.stageAwards(e),await this.stageStatements(e),await this.stageZip_Game(e),await this.stageViewer(e)}async stageLanguage_Quizz(e){await this.stageQuiz(e)}async setLanguage(e){this.workDirLang=at(this.workDir,e),this.problem_id=`${this.problem_nm}_${e}`,this.stagingDirLang=at(this.stagingDir,e),await Y0(this.stagingDirLang,{recursive:!0})}async createWorkspace(){await I.section(`Creating workspace ${this.workspace}`,async()=>{if(await Vj(this.workspace))throw Error(`Workspace directory ${this.workspace} already exists`);await Y0(this.workspace,{recursive:!0}),await Y0(this.workDir,{recursive:!0}),await Y0(this.stagingDir,{recursive:!0}),I.directory(this.workspace)})}doNotCopy(e,t){if(e==="problem.yml")return!0;if(e.startsWith(Ns()))return!0;let r=e.match(/^problem\.([a-z][a-z])\.[a-z]*$/);if(r&&r[1]!==t)return!0;if(e===`problem.${t}.pdf`)return!0;return!1}async separateByLanguages(){await I.section("Detecting if there are language folders or not",async()=>{if((await Array.fromAsync(Oc("handler.yml",{cwd:this.directory}))).length===0)await this.separateByLanguagesWithFolders();else await this.separateByLanguagesWithoutFolders()})}async separateByLanguagesWithoutFolders(){await I.section("Separating problem by languages without folders",async()=>{let t=(await Array.fromAsync(Oc("problem.[a-z][a-z].yml",{cwd:this.directory}))).map((r)=>{let n=r.match(/^problem\.([a-z][a-z])\.yml$/);if(!n)throw Error(`Unexpected yml file name: ${r}`);return n[1]});this.languages=t;for(let r of t){let n=at(this.workDir,r);await Y0(n,{recursive:!0});let i=await Array.fromAsync(Oc("{*,.vscode,.clang-format}",{cwd:this.directory}));for(let s of i){if(this.doNotCopy(s,r))continue;await Ka(at(this.directory,s),at(n,s),{recursive:!0,preserveTimestamps:!0})}}I.success(`Found languages: ${t.join(", ")}`)})}async separateByLanguagesWithFolders(){await I.section("Separating problem by languages with folders",async()=>{let e=await Array.fromAsync(Oc("[a-z][a-z]",{cwd:this.directory}));this.languages=e;for(let t of e){let r=at(this.directory,t),n=at(this.workDir,t);await Y0(n,{recursive:!0});let i=await Array.fromAsync(Oc("{*,.vscode,.clang-format}",{cwd:r}));for(let s of i){if(this.doNotCopy(s,t))continue;await Ka(at(r,s),at(n,s),{recursive:!0,preserveTimestamps:!0})}}I.success(`Found languages: ${e.join(", ")}`)})}async readMetadata(){await I.section("Reading problem metadata",async()=>{for(let t of this.languages){let r=at(this.workDir,t,`problem.${t}.yml`);this.problem_ymls[t]=await Xo(r),Tw.parse(this.problem_ymls[t])}for(let t of this.languages){let r=at(this.workDir,t,"handler.yml");this.handlers[t]=await Xo(r)}for(let t of this.languages){let r=this.problem_ymls[t];if(r.author)this.author=r.author;if(r.author)this.original_language=t;if(r.email)this.author_email=r.email}if(!this.original_language)throw Error("Original language not found in problem.<lang>.yml files");let{handler:e}=this.handlers[this.original_language];if(e==="game")this.problem_type="game";else if(e==="quiz")this.problem_type="quiz";else this.problem_type="std";I.success(`Problem type: ${this.problem_type}`),I.success(`Original language: ${this.original_language}`),I.success(`Author: ${this.author} <${this.author_email}>`)})}async findGoldenSolution(e){return await I.section("Finding golden solution",async()=>{let t=this.handlers[e].handler,r=this.handlers[e].compilers||"",n=this.handlers[e].solution,i;if(t==="circuits")i="solution.v";else if(r==="RunPython")i="solution.py";else if(r==="RunHaskell"||r==="GHC"||n==="Haskell"||n==="GHC")i="solution.hs";else if(r==="RunClojure"||r==="Clojure")i="solution.clj";else if(r==="PRO2"||r==="MakePRO2"){let s=await Array.fromAsync(Oc("solution.{cc,hh,tar}",{cwd:this.directory}));if(s.length!==1)throw Error(`Expected exactly one PRO2/MakePRO2 solution file, but got ${s.join(", ")}`);i=s[0]}else{let s=this.handlers[e].solution||"C++";if(s==="C++"){let c=await Array.fromAsync(Oc("solution.*",{cwd:this.directory}));if(I.print(c.join(", ")),c.length===1){let u=c[0].split(".").pop();s=Fge[u]}}let a=zln[s];if(!a)throw Error(`Unknown programming language ${s} for solution`);let o=at(this.workDir,e,`solution.${a}`);if(!await Vj(o))throw Error(`Golden solution file ${o} not found`);i=`solution.${a}`}return I.success(`Golden solution: ${i}`),i})}formatTimeMismatch(e,t,r,n){let i=n-t,s=rI.default.duration(i).humanize();return[`- ${r} is ${s} newer than ${e}`]}async checkMTimes_Std(e){await I.section("Checking test cases (.inp/.cor pairing and .cor after .inp and solution)",async()=>{let t=this.workDirLang,r=await this.findGoldenSolution(e),n=at(t,r),i=await Array.fromAsync(Oc("*.cor",{cwd:t})),s=await Array.fromAsync(Oc("*.inp",{cwd:t})),a=[],o=new Set(i.map((c)=>c.replace(/\.cor$/,"")));for(let c of s){let u=c.replace(/\.inp$/,"");if(!o.has(u))a.push(`- ${c}: no corresponding .cor file found`)}let l;try{l=(await Pge(n)).mtimeMs}catch{a.push(`- Golden solution not found or not readable: ${n}`),l=0}for(let c of i){let d=`${c.replace(/\.cor$/,"")}.inp`,f=at(t,c),p=at(t,d),h;try{h=(await Pge(f)).mtimeMs}catch{a.push(`- ${c}: could not stat`);continue}try{let _=(await Pge(p)).mtimeMs;if(h<=_)a.push(...this.formatTimeMismatch(c,h,d,_))}catch{a.push(`${c}: corresponding input ${d} not found or not readable`)}if(l>0&&h<=l)a.push(...this.formatTimeMismatch(c,h,r,l))}if(a.length>0){I.error("Check failed: each .inp must have a .cor, and .cor files must be generated after their .inp and the golden solution.");for(let c of a)I.error(c);throw I.warning("Suggestion: Use `jtk make cor` to generate the .cor files again."),Error("File order check failed. See report above.")}I.success("All .inp have a .cor and all .cor files seem newer than their .inp and the golden solution")})}async prepareStatements_Std(e){await I.section("Preparing statements",async()=>{let t=at(this.workDir,e);I.command(`jtk make pdf html md txt --problem_nm ${this.problem_nm}`),await er({cwd:t,stdout:"inherit",stderr:"inherit",env:{JUTGE_INDENTATION_LEVEL:I.getIndentationLevelAsString()}})`jtk make pdf html md txt --problem_nm ${this.problem_nm}`,await Rwt(at(t,"jtk-pdf"),{recursive:!0,force:!0}),await Rwt(at(t,"jtk-text"),{recursive:!0,force:!0}),I.success("Generated statements")})}async prepareStatements_Game(e){await I.section("Preparing game statements",async()=>{let t=at(this.workDirLang,"Doc");await I.section("Generating PDF with xelatex",async()=>{I.command("xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex"),await er({cwd:t})`xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex`,await er({cwd:t})`xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex`,await Ka(at(t,"main.pdf"),at(this.workDirLang,`problem.${e}.pdf`)),I.success(`Generated ${I.hyperlink(this.workDirLang,`problem.${e}.pdf`)}`)}),await I.section("Generating TXT with pandoc",async()=>{I.command("pandoc --quiet main.tex --to plain --output main.txt"),await er({cwd:t})`pandoc --quiet main.tex --to plain --output main.txt`,await Ka(at(t,"main.txt"),at(this.workDirLang,`problem.${e}.txt`)),I.success(`Generated ${I.hyperlink(this.workDirLang,`problem.${e}.txt`)}`),await Ka(at(t,"main.txt"),at(this.workDirLang,`problem.${e}.short.txt`)),I.success(`Generated ${I.hyperlink(this.workDirLang,`problem.${e}.short.txt`)}`)}),await I.section("Generating Markdown with pandoc",async()=>{I.command("pandoc --quiet main.tex --to markdown --to markdown-header_attributes --output main.md"),await er({cwd:t})`pandoc --quiet main.tex --to markdown --to markdown-header_attributes --output main.md`,await Ka(at(t,"main.md"),at(this.workDirLang,`problem.${e}.md`)),I.success(`Generated ${I.hyperlink(this.workDirLang,`problem.${e}.md`)}`),await Ka(at(t,"main.md"),at(this.workDirLang,`problem.${e}.short.md`)),I.success(`Generated ${I.hyperlink(this.workDirLang,`problem.${e}.short.md`)}`)}),await I.section("Generating HTML with pandoc",async()=>{I.command("pandoc --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html"),await er({cwd:t})`pandoc --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html`,await Ka(at(t,"main.html"),at(this.workDirLang,`problem.${e}.html`)),I.success(`Generated ${I.hyperlink(this.workDirLang,`problem.${e}.html`)}`),await Ka(at(t,"main.html"),at(this.workDirLang,`problem.${e}.short.html`)),I.success(`Generated ${I.hyperlink(this.workDirLang,`problem.${e}.short.html`)}`)})})}async computeCodeMetrics(e){if(!await Xpt()){I.warning("jutge-code-metrics not installed, skipping code metrics");return}if(this.problem_type!=="std"){await I.section("Skipping code metrics",async()=>{await li(),I.warning("Code metrics not applicable for this problem type")});return}await I.section("Computing code metrics",async()=>{let t=await this.findGoldenSolution(e);I.command(`jutge-code-metrics ${t}`);try{let{stdout:r}=await er({cwd:this.workDirLang})`jutge-code-metrics ${t}`;await Ja(at(this.stagingDirLang,"code-metrics.json"),r),I.success(`Generated ${I.hyperlink(this.stagingDirLang,"code-metrics.json")}`)}catch(r){I.warning("Failed to compute code metrics")}})}async makeTarFiles_Std(e){let t=this.handlers[e]?.compilers||"";if(t!=="PRO2"&&t!=="MakePRO2")return;await I.section("Making `.tar` files for PRO2/MakePRO2",async()=>{for(let r of["public","private","solution"])if(await zs(this.workDirLang,r)){let{exitCode:n}=await er({reject:!1,stderr:"inherit",stdout:"inherit",cwd:at(this.workDirLang,r)})`tar cf ../${r}.tar .`;if(n!==0)throw Error(`Error making ${r}.tar`);I.success(`Created ${r}.tar`)}})}async stageProblemFiles_Std(e){let t=(i)=>{if(i==="handler.yml")return!0;for(let s of["inp","cor","ops"])if(i.endsWith(`.${s}`))return!0;for(let s of Owt){if(i===`solution.${s}`)return!0;if(i===`main.${s}`)return!0;if(i===`code.${s}`)return!0}if(i==="scores.yml")return!0;if(i==="checker.py")return!0;if(i==="checker.cc")return!0;if(i==="private.tar")return!0;if(i==="public.tar")return!0;if(i==="solution.tar")return!0;if(i==="solution.cc")return!0;if(i==="solution.hh")return!0;if(i==="sample.dt")return!0;return!1},r=at(this.stagingDirLang,"problem.pbm");await Y0(r,{recursive:!0});let n=await Array.fromAsync(Oc("*",{cwd:this.workDirLang}));for(let i of n)if(t(i))await Ka(at(this.workDirLang,i),at(r,i),{preserveTimestamps:!0});await Ka(at(this.workDirLang,`problem.${e}.yml`),at(r,"problem.yml")),I.success(`Problem staged to ${I.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageProblemFiles_Game(e){let t=(s)=>{if(s==="handler.yml")return!0;if(s==="Makefile")return!0;if(s==="README.txt")return!0;if(s==="README.md")return!0;if(s.endsWith(".cc"))return!0;if(s.endsWith(".hh"))return!0;if(s.endsWith(".cnf"))return!0;return!1},r=at(this.workDirLang,"Runner"),n=at(this.stagingDirLang,"problem.pbm");await Y0(n,{recursive:!0});let i=await Array.fromAsync(Oc("*",{cwd:r}));for(let s of i)if(t(s))await Ka(at(r,s),at(n,s));await Ka(at(this.workDirLang,"handler.yml"),at(n,"handler.yml")),await Ka(at(this.workDirLang,`problem.${e}.yml`),at(n,"problem.yml")),I.success(`Problem staged to ${I.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageAwards(e){await I.section("Staging awards",async()=>{let t=0;for(let r of["award.png","award.txt"])if(await zs(this.workDirLang,r))await Ka(at(this.workDirLang,r),at(this.stagingDir,r)),t++;if(t>0)I.success(`Staged ${t} award file(s)`);else I.warning("No award files found")})}async stageStatements(e){await I.section("Staging statements",async()=>{let t=0;for(let r of["pdf","html","md","txt","yml","short.html","short.md","short.txt"]){let n=`problem.${e}.${r}`,i=`problem.${r}`;if(await zs(this.workDirLang,n))await Ka(at(this.workDirLang,n),at(this.stagingDirLang,i)),t++}I.success(`Staged ${t} statement file(s)`)})}async stageFirstToSolve(){await I.section("Staging first-to-solve avatar",async()=>{let e=at(this.stagingDir,"first-to-solve.svg"),r=gwt(Yj,{seed:this.problem_nm}).toString();await Ja(e,r),I.success(`Generated ${I.hyperlink(this.stagingDir,"first-to-solve.svg")}`)})}async stageZip_Std(e){let t=(i)=>{for(let s of["pdf","html","md","txt"])if(i===`problem.${e}.${s}`)return!0;for(let s of Owt){if(i===`main.${s}`)return!0;if(i===`code.${s}`)return!0}if((i.includes("sample")||i.startsWith("public")||i.startsWith("hint")||i.startsWith("distilled"))&&(i.endsWith(".inp")||i.endsWith(".cor")))return!0;if(i==="sample.dt")return!0;return!1},r=[],n=await Array.fromAsync(Oc("*",{cwd:this.workDirLang}));for(let i of n)if(t(i))r.push({sourcePath:at(this.workDirLang,i),archivePath:at(`${this.problem_id}`,i)});await jB(r,at(this.stagingDirLang,"problem.zip")),I.success(`Created ${I.hyperlink(this.stagingDirLang,"problem.zip")} with ${r.length} files`)}async stageZip_Game(e){let t=this.handlers[this.original_language].game.hide||["AIDummy.cc"],r=(i)=>{if(i.endsWith(".cc")||i.endsWith(".hh"))return!t.includes(i);if(i.endsWith(".cnf"))return!0;if(i=="Makefile")return!0;if(i=="README.txt")return!0;if(i=="README.md")return!0;return!1},n=[];for(let i of["pdf","html","md","txt","short.html","short.md","short.txt"]){let s=`problem.${e}.${i}`;if(await zs(this.workDirLang,s))n.push({sourcePath:at(this.workDirLang,s),archivePath:at(`${this.problem_id}`,s)})}{let i=at(this.workDirLang,"Runner"),s=await Array.fromAsync(Oc("*",{cwd:i}));for(let a of s)if(r(a))n.push({sourcePath:at(i,a),archivePath:at(`${this.problem_id}`,"src",a)})}{let i=at(this.workDirLang,"Obj"),s=await Array.fromAsync(Oc("*.o.*",{cwd:i}));for(let a of s)n.push({sourcePath:at(i,a),archivePath:at(`${this.problem_id}`,"src",a)})}{let i=at(this.workDirLang,"Viewer"),s=await Array.fromAsync(Oc("**/*",{cwd:i}));for(let a of s)n.push({sourcePath:at(i,a),archivePath:at(`${this.problem_id}`,"src","Viewer",a)})}await jB(n,at(this.stagingDirLang,"problem.zip")),I.success(`Created ${I.hyperlink(this.stagingDirLang,"problem.zip")} with ${n.length} files`)}async stageViewer(e){await I.section("Staging viewer",async()=>{await Ka(at(this.workDirLang,"Viewer"),at(this.stagingDirLang,"viewer"),{recursive:!0}),I.success(`Staged ${I.hyperlink(this.stagingDirLang,"viewer")}`)})}async stageQuiz(e){await I.section("Staging quiz",async()=>{let t=$D.parse(await Xo(at(this.workDirLang,"quiz.yml"))),r=at(this.stagingDirLang,"quiz.pbm");await Y0(r,{recursive:!0}),await th(at(r,"quiz.yml"),t),await Ka(at(this.workDirLang,"handler.yml"),at(r,"handler.yml")),await Ka(at(this.workDirLang,`problem.${e}.yml`),at(r,"problem.yml")),await Ka(at(this.workDirLang,`problem.${e}.yml`),at(r,"..","problem.yml"));for(let i of t.questions){{let s=at(this.workDirLang,`${i.file}.yml`),a=at(r,`${i.file}.yml`);if(await Vj(s))await Ka(s,a);else throw Error(`Quiz question file ${i.file}.yml not found`)}{let s=at(this.workDirLang,`${i.file}.py`),a=at(r,`${i.file}.py`);if(await Vj(s))await Ka(s,a)}}let n=await Array.fromAsync(Oc("*.{png,svg}",{cwd:this.workDirLang}));for(let i of n)await Ka(at(this.workDirLang,i),at(r,i));I.success(`Staged ${I.hyperlink(this.stagingDirLang,"quiz")}`)})}async stageInformationYml(){await I.section("Staging information.yml",async()=>{let e={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},t=at(this.stagingDir,"information.yml");await th(t,e),I.success(`Generated ${I.hyperlink(this.stagingDir,"information.yml")}`)})}async stageReadMd(){await I.section("Staging README.md",async()=>{let e=Sc.version,t=this.languages.map((s)=>{let o=this.problem_ymls[s].title,l=`- *${s}*: ${o}
|
|
1055
|
+
*/var Ewt={half:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,quarter:(e,t)=>`<path d="M50 10V0C22.386 0 0 22.386 0 50h10c0-22.091 17.909-40 40-40Z" fill="${hs(`${t.ring}`)}"/>`,eighth:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,full:(e,t)=>`<circle cx="50" cy="50" r="45" stroke="${hs(`${t.ring}`)}" stroke-width="10"/>`};var ywt={eighth:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,quarter:(e,t)=>`<path d="M50 10c-22.091 0-40 17.909-40 40h10c0-16.569 13.431-30 30-30V10Z" fill="${hs(`${t.ring}`)}"/>`,half:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,full:(e,t)=>`<circle cx="50" cy="50" r="35" stroke="${hs(`${t.ring}`)}" stroke-width="10"/>`};var bwt={eighth:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,quarter:(e,t)=>`<path d="M50 20c-16.569 0-30 13.431-30 30h10c0-11.046 8.954-20 20-20V20Z" fill="${hs(`${t.ring}`)}"/>`,half:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,full:(e,t)=>`<circle cx="50" cy="50" r="25" stroke="${hs(`${t.ring}`)}" stroke-width="10"/>`};var Swt={eighth:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,quarter:(e,t)=>`<path d="M50 30c-11.046 0-20 8.954-20 20h10c0-5.523 4.477-10 10-10V30Z" fill="${hs(`${t.ring}`)}"/>`,half:(e,t)=>`<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="${hs(`${t.ring}`)}"/>`,full:(e,t)=>`<circle cx="50" cy="50" r="15" stroke="${hs(`${t.ring}`)}" stroke-width="10"/>`};var xwt={eighth:(e,t)=>`<path d="m42.929 42.929 7.07 7.07H40a9.97 9.97 0 0 1 2.93-7.07Z" fill="${hs(`${t.ring}`)}"/>`,quarter:(e,t)=>`<path d="M50 40v10H40c0-5.523 4.477-10 10-10Z" fill="${hs(`${t.ring}`)}"/>`,half:(e,t)=>`<path d="M60 50c0-5.523-4.477-10-10-10s-10 4.477-10 10h20Z" fill="${hs(`${t.ring}`)}"/>`,full:(e,t)=>`<circle cx="50" cy="50" r="10" fill="${hs(`${t.ring}`)}"/>`};function lv({prng:e,group:t,width:r,height:n,values:i=[],rotation:s,offsetX:a,offsetY:o}){let l=kge,c=e.pick(i),u=e.integer(Math.min(...s),Math.max(...s)),d=e.integer(Math.min(...a),Math.max(...a)),f=e.integer(Math.min(...o),Math.max(...o));if(c&&l[t][c])return{name:c,value(p,h){var _,g,S;let v=l[t][c](p,h);if(this.rotation||this.offsetX||this.offsetY)v=`<g transform="translate(${(_=this.offsetX)!==null&&_!==void 0?_:0}, ${(g=this.offsetY)!==null&&g!==void 0?g:0}) rotate(${(S=this.rotation)!==null&&S!==void 0?S:0} ${r/2} ${n/2})">${v}</g>`;return v},rotation:u,offsetX:d,offsetY:f};else return}function Twt({prng:e,options:t}){var r,n,i,s,a,o;let l=lv({prng:e,group:"ring",values:t.ring,width:100,height:100,rotation:((r=t.ringRotation)===null||r===void 0?void 0:r.length)?t.ringRotation:[0],offsetX:[0],offsetY:[0]}),c=lv({prng:e,group:"ringOne",values:t.ringOne,width:100,height:100,rotation:((n=t.ringOneRotation)===null||n===void 0?void 0:n.length)?t.ringOneRotation:[0],offsetX:[0],offsetY:[0]}),u=lv({prng:e,group:"ringTwo",values:t.ringTwo,width:100,height:100,rotation:((i=t.ringTwoRotation)===null||i===void 0?void 0:i.length)?t.ringTwoRotation:[0],offsetX:[0],offsetY:[0]}),d=lv({prng:e,group:"ringThree",values:t.ringThree,width:100,height:100,rotation:((s=t.ringThreeRotation)===null||s===void 0?void 0:s.length)?t.ringThreeRotation:[0],offsetX:[0],offsetY:[0]}),f=lv({prng:e,group:"ringFour",values:t.ringFour,width:100,height:100,rotation:((a=t.ringFourRotation)===null||a===void 0?void 0:a.length)?t.ringFourRotation:[0],offsetX:[0],offsetY:[0]}),p=lv({prng:e,group:"ringFive",values:t.ringFive,width:100,height:100,rotation:((o=t.ringFiveRotation)===null||o===void 0?void 0:o.length)?t.ringFiveRotation:[0],offsetX:[0],offsetY:[0]});return{ring:l,ringOne:c,ringTwo:u,ringThree:d,ringFour:f,ringFive:p}}function vwt(e){return e==="transparent"?e:`#${e}`}function wwt({prng:e,options:t}){var r;return{ring:vwt(e.pick((r=t.ringColor)!==null&&r!==void 0?r:[],"transparent"))}}var Cwt={$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 Bln={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/"}},Fln=({prng:e,options:t})=>{var r,n;let i=Twt({prng:e,options:t}),s=wwt({prng:e,options:t});return{attributes:{viewBox:"0 0 100 100",fill:"none","shape-rendering":"crispEdges"},body:`${(n=(r=i.ring)===null||r===void 0?void 0:r.value(i,s))!==null&&n!==void 0?n:""}`,extra:()=>({...Object.entries(i).reduce((a,[o,l])=>(a[o]=l===null||l===void 0?void 0:l.name,a),{}),...Object.entries(s).reduce((a,[o,l])=>(a[`${o}Color`]=l,a),{})})}};var rI=Pt(xW(),1),Nwt=Pt(TW(),1),Iwt=Pt(Awt(),1);import{cp as Ka,exists as Vj,glob as Oc,mkdir as Y0,rm as Rwt,stat as Pge,writeFile as Uln}from"fs/promises";Xf();import tI from"os";import{join as at,resolve as Gln}from"path";rI.default.extend(Nwt.default);rI.default.extend(Iwt.default);class Bge{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(e,t){if(this.directory=Gln(e),!this.directory.endsWith(".pbm"))throw Error(`Directory ${this.directory} is not a problem root directory (missing .pbm suffix)`);this.problem_nm=t,this.workspace=at(e,Ns()+"-stage",od()),this.workDir=at(this.workspace,"work.pbm"),this.stagingDir=at(this.workspace,"stage",this.problem_nm)}async stage(){await I.section(`Staging problem at ${I.hyperlink(this.directory)}`,async()=>{await this.createWorkspace(),await this.separateByLanguages(),await this.readMetadata();for(let e of this.languages)await I.section(`Staging language ${e}`,async()=>{if(await this.setLanguage(e),this.problem_type==="std")await this.stageLanguage_Std(e);else if(this.problem_type==="game")await this.stageLanguage_Game(e);else if(this.problem_type==="quiz")await this.stageLanguage_Quizz(e)});await this.stageFirstToSolve(),await this.stageInformationYml(),await this.stageReadMd()}),await I.section("Summary",async()=>{let e=at(this.stagingDir,"README.md");I.success("README.md content:"),await I.markdown(await qr(e)),I.success("Staging tree:"),I.print(Jf(this.stagingDir))}),I.success(`Problem successfully staged at directory ${I.hyperlink(this.stagingDir)}`),await cN(this.stagingDir)}async stageLanguage_Std(e){await this.prepareStatements_Std(e),await this.computeCodeMetrics(e),await this.makeTarFiles_Std(e),await this.stageProblemFiles_Std(e),await this.stageAwards(e),await this.stageStatements(e),await this.stageZip_Std(e)}async stageLanguage_Game(e){await this.prepareStatements_Game(e),await this.computeCodeMetrics(e),await this.stageProblemFiles_Game(e),await this.stageAwards(e),await this.stageStatements(e),await this.stageZip_Game(e),await this.stageViewer(e)}async stageLanguage_Quizz(e){await this.stageQuiz(e)}async setLanguage(e){this.workDirLang=at(this.workDir,e),this.problem_id=`${this.problem_nm}_${e}`,this.stagingDirLang=at(this.stagingDir,e),await Y0(this.stagingDirLang,{recursive:!0})}async createWorkspace(){await I.section(`Creating workspace ${this.workspace}`,async()=>{if(await Vj(this.workspace))throw Error(`Workspace directory ${this.workspace} already exists`);await Y0(this.workspace,{recursive:!0}),await Y0(this.workDir,{recursive:!0}),await Y0(this.stagingDir,{recursive:!0}),I.directory(this.workspace)})}doNotCopy(e,t){if(e==="problem.yml")return!0;if(e.startsWith(Ns()))return!0;let r=e.match(/^problem\.([a-z][a-z])\.[a-z]*$/);if(r&&r[1]!==t)return!0;if(e===`problem.${t}.pdf`)return!0;return!1}async separateByLanguages(){await I.section("Detecting if there are language folders or not",async()=>{if((await Array.fromAsync(Oc("handler.yml",{cwd:this.directory}))).length===0)await this.separateByLanguagesWithFolders();else await this.separateByLanguagesWithoutFolders()})}async separateByLanguagesWithoutFolders(){await I.section("Separating problem by languages without folders",async()=>{let t=(await Array.fromAsync(Oc("problem.[a-z][a-z].yml",{cwd:this.directory}))).map((r)=>{let n=r.match(/^problem\.([a-z][a-z])\.yml$/);if(!n)throw Error(`Unexpected yml file name: ${r}`);return n[1]});this.languages=t;for(let r of t){let n=at(this.workDir,r);await Y0(n,{recursive:!0});let i=await Array.fromAsync(Oc("{*,.vscode,.clang-format}",{cwd:this.directory}));for(let s of i){if(this.doNotCopy(s,r))continue;await Ka(at(this.directory,s),at(n,s),{recursive:!0,preserveTimestamps:!0})}}I.success(`Found languages: ${t.join(", ")}`)})}async separateByLanguagesWithFolders(){await I.section("Separating problem by languages with folders",async()=>{let e=await Array.fromAsync(Oc("[a-z][a-z]",{cwd:this.directory}));this.languages=e;for(let t of e){let r=at(this.directory,t),n=at(this.workDir,t);await Y0(n,{recursive:!0});let i=await Array.fromAsync(Oc("{*,.vscode,.clang-format}",{cwd:r}));for(let s of i){if(this.doNotCopy(s,t))continue;await Ka(at(r,s),at(n,s),{recursive:!0,preserveTimestamps:!0})}}I.success(`Found languages: ${e.join(", ")}`)})}async readMetadata(){await I.section("Reading problem metadata",async()=>{for(let t of this.languages){let r=at(this.workDir,t,`problem.${t}.yml`);this.problem_ymls[t]=await Xo(r),Tw.parse(this.problem_ymls[t])}for(let t of this.languages){let r=at(this.workDir,t,"handler.yml");this.handlers[t]=await Xo(r)}for(let t of this.languages){let r=this.problem_ymls[t];if(r.author)this.author=r.author;if(r.author)this.original_language=t;if(r.email)this.author_email=r.email}if(!this.original_language)throw Error("Original language not found in problem.<lang>.yml files");let{handler:e}=this.handlers[this.original_language];if(e==="game")this.problem_type="game";else if(e==="quiz")this.problem_type="quiz";else this.problem_type="std";I.success(`Problem type: ${this.problem_type}`),I.success(`Original language: ${this.original_language}`),I.success(`Author: ${this.author} <${this.author_email}>`)})}async findGoldenSolution(e){return await I.section("Finding golden solution",async()=>{let t=this.handlers[e].handler,r=this.handlers[e].compilers||"",n=this.handlers[e].solution,i;if(t==="circuits")i="solution.v";else if(r==="RunPython")i="solution.py";else if(r==="RunHaskell"||r==="GHC"||n==="Haskell"||n==="GHC")i="solution.hs";else if(r==="RunClojure"||r==="Clojure")i="solution.clj";else if(r==="PRO2"||r==="MakePRO2"){let s=await Array.fromAsync(Oc("solution.{cc,hh,tar}",{cwd:this.directory}));if(s.length!==1)throw Error(`Expected exactly one PRO2/MakePRO2 solution file, but got ${s.join(", ")}`);i=s[0]}else{let s=this.handlers[e].solution||"C++";if(s==="C++"){let c=await Array.fromAsync(Oc("solution.*",{cwd:this.directory}));if(I.print(c.join(", ")),c.length===1){let u=c[0].split(".").pop();s=Fge[u]}}let a=zln[s];if(!a)throw Error(`Unknown programming language ${s} for solution`);let o=at(this.workDir,e,`solution.${a}`);if(!await Vj(o))throw Error(`Golden solution file ${o} not found`);i=`solution.${a}`}return I.success(`Golden solution: ${i}`),i})}formatTimeMismatch(e,t,r,n){let i=n-t,s=rI.default.duration(i).humanize();return[`- ${r} is ${s} newer than ${e}`]}async checkMTimes_Std(e){await I.section("Checking test cases (.inp/.cor pairing and .cor after .inp and solution)",async()=>{let t=this.workDirLang,r=await this.findGoldenSolution(e),n=at(t,r),i=await Array.fromAsync(Oc("*.cor",{cwd:t})),s=await Array.fromAsync(Oc("*.inp",{cwd:t})),a=[],o=new Set(i.map((c)=>c.replace(/\.cor$/,"")));for(let c of s){let u=c.replace(/\.inp$/,"");if(!o.has(u))a.push(`- ${c}: no corresponding .cor file found`)}let l;try{l=(await Pge(n)).mtimeMs}catch{a.push(`- Golden solution not found or not readable: ${n}`),l=0}for(let c of i){let d=`${c.replace(/\.cor$/,"")}.inp`,f=at(t,c),p=at(t,d),h;try{h=(await Pge(f)).mtimeMs}catch{a.push(`- ${c}: could not stat`);continue}try{let _=(await Pge(p)).mtimeMs;if(h<=_)a.push(...this.formatTimeMismatch(c,h,d,_))}catch{a.push(`${c}: corresponding input ${d} not found or not readable`)}if(l>0&&h<=l)a.push(...this.formatTimeMismatch(c,h,r,l))}if(a.length>0){I.error("Check failed: each .inp must have a .cor, and .cor files must be generated after their .inp and the golden solution.");for(let c of a)I.error(c);throw I.warning("Suggestion: Use `jtk make cor` to generate the .cor files again."),Error("File order check failed. See report above.")}I.success("All .inp have a .cor and all .cor files seem newer than their .inp and the golden solution")})}async prepareStatements_Std(e){await I.section("Preparing statements",async()=>{let t=at(this.workDir,e);I.command(`jtk make pdf html md txt --problem_nm ${this.problem_nm}`),await er({cwd:t,stdout:"inherit",stderr:"inherit",env:{JUTGE_INDENTATION_LEVEL:I.getIndentationLevelAsString()}})`jtk make pdf html md txt --problem_nm ${this.problem_nm}`,await Rwt(at(t,"jtk-pdf"),{recursive:!0,force:!0}),await Rwt(at(t,"jtk-text"),{recursive:!0,force:!0}),I.success("Generated statements")})}async prepareStatements_Game(e){await I.section("Preparing game statements",async()=>{let t=at(this.workDirLang,"Doc");await I.section("Generating PDF with xelatex",async()=>{I.command("xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex"),await er({cwd:t})`xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex`,await er({cwd:t})`xelatex -no-shell-escape -interaction=nonstopmode -file-line-error main.tex`,await Ka(at(t,"main.pdf"),at(this.workDirLang,`problem.${e}.pdf`)),I.success(`Generated ${I.hyperlink(this.workDirLang,`problem.${e}.pdf`)}`)}),await I.section("Generating TXT with pandoc",async()=>{I.command("pandoc --quiet main.tex --to plain --output main.txt"),await er({cwd:t})`pandoc --quiet main.tex --to plain --output main.txt`,await Ka(at(t,"main.txt"),at(this.workDirLang,`problem.${e}.txt`)),I.success(`Generated ${I.hyperlink(this.workDirLang,`problem.${e}.txt`)}`),await Ka(at(t,"main.txt"),at(this.workDirLang,`problem.${e}.short.txt`)),I.success(`Generated ${I.hyperlink(this.workDirLang,`problem.${e}.short.txt`)}`)}),await I.section("Generating Markdown with pandoc",async()=>{I.command("pandoc --quiet main.tex --to markdown --to markdown-header_attributes --output main.md"),await er({cwd:t})`pandoc --quiet main.tex --to markdown --to markdown-header_attributes --output main.md`,await Ka(at(t,"main.md"),at(this.workDirLang,`problem.${e}.md`)),I.success(`Generated ${I.hyperlink(this.workDirLang,`problem.${e}.md`)}`),await Ka(at(t,"main.md"),at(this.workDirLang,`problem.${e}.short.md`)),I.success(`Generated ${I.hyperlink(this.workDirLang,`problem.${e}.short.md`)}`)}),await I.section("Generating HTML with pandoc",async()=>{I.command("pandoc --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html"),await er({cwd:t})`pandoc --quiet main.tex --to html --mathml --embed-resources --standalone --output main.html`,await Ka(at(t,"main.html"),at(this.workDirLang,`problem.${e}.html`)),I.success(`Generated ${I.hyperlink(this.workDirLang,`problem.${e}.html`)}`),await Ka(at(t,"main.html"),at(this.workDirLang,`problem.${e}.short.html`)),I.success(`Generated ${I.hyperlink(this.workDirLang,`problem.${e}.short.html`)}`)})})}async computeCodeMetrics(e){if(!await Xpt()){I.warning("jutge-code-metrics not installed, skipping code metrics");return}if(this.problem_type!=="std"){await I.section("Skipping code metrics",async()=>{await li(),I.warning("Code metrics not applicable for this problem type")});return}await I.section("Computing code metrics",async()=>{let t=await this.findGoldenSolution(e);I.command(`jutge-code-metrics ${t}`);try{let{stdout:r}=await er({cwd:this.workDirLang})`jutge-code-metrics ${t}`;await Ja(at(this.stagingDirLang,"code-metrics.json"),r),I.success(`Generated ${I.hyperlink(this.stagingDirLang,"code-metrics.json")}`)}catch(r){I.warning("Failed to compute code metrics")}})}async makeTarFiles_Std(e){let t=this.handlers[e]?.compilers||"";if(t!=="PRO2"&&t!=="MakePRO2")return;await I.section("Making `.tar` files for PRO2/MakePRO2",async()=>{for(let r of["public","private","solution"])if(await zs(this.workDirLang,r)){let{exitCode:n}=await er({reject:!1,stderr:"inherit",stdout:"inherit",cwd:at(this.workDirLang,r)})`tar cf ../${r}.tar .`;if(n!==0)throw Error(`Error making ${r}.tar`);I.success(`Created ${r}.tar`)}})}async stageProblemFiles_Std(e){let t=(i)=>{if(i==="handler.yml")return!0;for(let s of["inp","cor","ops"])if(i.endsWith(`.${s}`))return!0;for(let s of Owt){if(i===`solution.${s}`)return!0;if(i===`main.${s}`)return!0;if(i===`code.${s}`)return!0}if(i==="scores.yml")return!0;if(i==="checker.py")return!0;if(i==="checker.cc")return!0;if(i==="private.tar")return!0;if(i==="public.tar")return!0;if(i==="solution.tar")return!0;if(i==="solution.cc")return!0;if(i==="solution.hh")return!0;if(i==="sample.dt")return!0;return!1},r=at(this.stagingDirLang,"problem.pbm");await Y0(r,{recursive:!0});let n=await Array.fromAsync(Oc("*",{cwd:this.workDirLang}));for(let i of n)if(t(i))await Ka(at(this.workDirLang,i),at(r,i),{preserveTimestamps:!0});await Ka(at(this.workDirLang,`problem.${e}.yml`),at(r,"problem.yml")),I.success(`Problem staged to ${I.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageProblemFiles_Game(e){let t=(s)=>{if(s==="handler.yml")return!0;if(s==="Makefile")return!0;if(s==="README.txt")return!0;if(s==="README.md")return!0;if(s.endsWith(".cc"))return!0;if(s.endsWith(".hh"))return!0;if(s.endsWith(".cnf"))return!0;return!1},r=at(this.workDirLang,"Runner"),n=at(this.stagingDirLang,"problem.pbm");await Y0(n,{recursive:!0});let i=await Array.fromAsync(Oc("*",{cwd:r}));for(let s of i)if(t(s))await Ka(at(r,s),at(n,s));await Ka(at(this.workDirLang,"handler.yml"),at(n,"handler.yml")),await Ka(at(this.workDirLang,`problem.${e}.yml`),at(n,"problem.yml")),I.success(`Problem staged to ${I.hyperlink(this.stagingDirLang,"problem.pbm")}`)}async stageAwards(e){await I.section("Staging awards",async()=>{let t=0;for(let r of["award.png","award.txt"])if(await zs(this.workDirLang,r))await Ka(at(this.workDirLang,r),at(this.stagingDir,r)),t++;if(t>0)I.success(`Staged ${t} award file(s)`);else I.warning("No award files found")})}async stageStatements(e){await I.section("Staging statements",async()=>{let t=0;for(let r of["pdf","html","md","txt","yml","short.html","short.md","short.txt"]){let n=`problem.${e}.${r}`,i=`problem.${r}`;if(await zs(this.workDirLang,n))await Ka(at(this.workDirLang,n),at(this.stagingDirLang,i)),t++}I.success(`Staged ${t} statement file(s)`)})}async stageFirstToSolve(){await I.section("Staging first-to-solve avatar",async()=>{let e=at(this.stagingDir,"first-to-solve.svg"),r=gwt(Yj,{seed:this.problem_nm}).toString();await Ja(e,r),I.success(`Generated ${I.hyperlink(this.stagingDir,"first-to-solve.svg")}`)})}async stageZip_Std(e){let t=(i)=>{for(let s of["pdf","html","md","txt"])if(i===`problem.${e}.${s}`)return!0;for(let s of Owt){if(i===`main.${s}`)return!0;if(i===`code.${s}`)return!0}if((i.includes("sample")||i.startsWith("public")||i.startsWith("hint")||i.startsWith("distilled"))&&(i.endsWith(".inp")||i.endsWith(".cor")))return!0;if(i==="sample.dt")return!0;return!1},r=[],n=await Array.fromAsync(Oc("*",{cwd:this.workDirLang}));for(let i of n)if(t(i))r.push({sourcePath:at(this.workDirLang,i),archivePath:at(`${this.problem_id}`,i)});await jB(r,at(this.stagingDirLang,"problem.zip")),I.success(`Created ${I.hyperlink(this.stagingDirLang,"problem.zip")} with ${r.length} files`)}async stageZip_Game(e){let t=this.handlers[this.original_language].game.hide||[],r=["AIDummy.cc","SecGame.cc","SecGame.hh","SecMain.cc"],n=[...t,...r],i=(a)=>{if(a.endsWith(".cc")||a.endsWith(".hh"))return!n.includes(a);if(a.endsWith(".cnf"))return!0;if(a=="Makefile")return!0;if(a=="README.txt")return!0;if(a=="README.md")return!0;return!1},s=[];for(let a of["pdf","html","md","txt","short.html","short.md","short.txt"]){let o=`problem.${e}.${a}`;if(await zs(this.workDirLang,o))s.push({sourcePath:at(this.workDirLang,o),archivePath:at(`${this.problem_id}`,o)})}{let a=at(this.workDirLang,"Runner"),o=await Array.fromAsync(Oc("*",{cwd:a}));for(let l of o)if(i(l))s.push({sourcePath:at(a,l),archivePath:at(`${this.problem_id}`,"src",l)})}{let a=at(this.workDirLang,"Obj"),o=await Array.fromAsync(Oc("*.o.*",{cwd:a}));for(let l of o)s.push({sourcePath:at(a,l),archivePath:at(`${this.problem_id}`,"src",l)})}{let a=at(this.workDirLang,"Viewer"),o=await Array.fromAsync(Oc("**/*",{cwd:a}));for(let l of o)s.push({sourcePath:at(a,l),archivePath:at(`${this.problem_id}`,"src","Viewer",l)})}await jB(s,at(this.stagingDirLang,"problem.zip")),I.success(`Created ${I.hyperlink(this.stagingDirLang,"problem.zip")} with ${s.length} files`)}async stageViewer(e){await I.section("Staging viewer",async()=>{await Ka(at(this.workDirLang,"Viewer"),at(this.stagingDirLang,"viewer"),{recursive:!0}),I.success(`Staged ${I.hyperlink(this.stagingDirLang,"viewer")}`)})}async stageQuiz(e){await I.section("Staging quiz",async()=>{let t=$D.parse(await Xo(at(this.workDirLang,"quiz.yml"))),r=at(this.stagingDirLang,"quiz.pbm");await Y0(r,{recursive:!0}),await th(at(r,"quiz.yml"),t),await Ka(at(this.workDirLang,"handler.yml"),at(r,"handler.yml")),await Ka(at(this.workDirLang,`problem.${e}.yml`),at(r,"problem.yml")),await Ka(at(this.workDirLang,`problem.${e}.yml`),at(r,"..","problem.yml"));for(let i of t.questions){{let s=at(this.workDirLang,`${i.file}.yml`),a=at(r,`${i.file}.yml`);if(await Vj(s))await Ka(s,a);else throw Error(`Quiz question file ${i.file}.yml not found`)}{let s=at(this.workDirLang,`${i.file}.py`),a=at(r,`${i.file}.py`);if(await Vj(s))await Ka(s,a)}}let n=await Array.fromAsync(Oc("*.{png,svg}",{cwd:this.workDirLang}));for(let i of n)await Ka(at(this.workDirLang,i),at(r,i));I.success(`Staged ${I.hyperlink(this.stagingDirLang,"quiz")}`)})}async stageInformationYml(){await I.section("Staging information.yml",async()=>{let e={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},t=at(this.stagingDir,"information.yml");await th(t,e),I.success(`Generated ${I.hyperlink(this.stagingDir,"information.yml")}`)})}async stageReadMd(){await I.section("Staging README.md",async()=>{let e=Sc.version,t=this.languages.map((s)=>{let o=this.problem_ymls[s].title,l=`- *${s}*: ${o}
|
|
1056
1056
|
`;if(s!==this.original_language)l+=` ${this.problem_ymls[s].translator} <${this.problem_ymls[s].translator_email}>`;else l="";return l}).join(`
|
|
1057
1057
|
`);if(t.trim())t=`## Translations
|
|
1058
1058
|
|