@jutge.org/toolkit 4.0.3 → 4.0.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.
Files changed (2) hide show
  1. package/dist/index.js +2 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3961,8 +3961,8 @@ main = do
3961
3961
  `)[0].trim();if($)console.log(Y);return q.startsWith("The Glorious Glasgow Haskell Compilation System")}async function Gv9($=!1){if($)J8.command("clj --version");let{stdout:q}=await q$({reject:!1})`clj --version`,Y=q.split(`
3962
3962
  `)[0].trim();if($)console.log(Y);return q.startsWith("Clojure")}async function Dv9($=!1){if($)J8.command("javac -version");let{stdout:q}=await q$({reject:!1})`javac -version`,Y=q.split(`
3963
3963
  `)[0].trim();if($)console.log(Y);return q.startsWith("javac")}async function Ov9($=!1){if($)J8.command("rustc --version");let{stdout:q}=await q$({reject:!1})`rustc --version`,Y=q.split(`
3964
- `)[0].trim();if($)console.log(Y);return q.startsWith("rustc")}async function Ar8($=!1){if($)J8.command("xelatex --version");let{stdout:q}=await q$({reject:!1})`xelatex --version`,Y=q.split(`
3965
- `)[0].trim();if($)console.log(Y);return q.startsWith("XeTeX")}async function Mr8($=!1){if($)J8.command("pandoc --version");let{stdout:q}=await q$({reject:!1})`pandoc --version`,Y=q.split(`
3964
+ `)[0].trim();if($)console.log(Y);return q.startsWith("rustc")}async function Ar8($=!1){if(console.log("SOMHI"),$)J8.command("xelatex --version");let{stdout:q}=await q$({reject:!1})`xelatex --version`;console.log("OUTPUT:",q);let Y=q.split(`
3965
+ `)[0].trim();if($)console.log(Y);return!0}async function Mr8($=!1){if($)J8.command("pandoc --version");let{stdout:q}=await q$({reject:!1})`pandoc --version`,Y=q.split(`
3966
3966
  `)[0].trim();if($)console.log(Y);return q.startsWith("pandoc")&&q.includes("+lua")}async function Nr8($=!1){if($)J8.command("magick --version");let{stdout:q}=await q$({reject:!1})`magick --version`,Y=q.split(`
3967
3967
  `)[0].trim();if($)console.log(Y);return q.startsWith("Version: ImageMagick")}async function ME1(){if(await Hv9(!0)){J8.success("Python3 seems installed");let $="turtle-pil yogi easyinput".split(" ");for(let q of $)await Wv9(!0,q)}else J8.warning("Python3 does not appear to be installed"),J8.print("This is not a problem if you do not plan to use Python solutions"),J8.print("See https://www.python.org/downloads/")}async function NE1(){if(await Xv9(!0))J8.success("C/C++ seems installed");else J8.warning("C/C++ does not appear to be installed"),J8.print("This is not a problem if you do not plan to use C or C++ solutions"),J8.print("Please install GCC or Clang")}async function jE1(){if(await zv9(!0))J8.success("Haskell seems installed");else J8.warning("Haskell does not appear to be installed"),J8.print("This is not a problem if you do not plan to use Haskell solutions"),J8.print("See https://www.haskell.org/ghc/download.html")}async function vE1(){if(await Gv9(!0))J8.success("Clojure seems installed");else J8.warning("Clojure does not appear to be installed"),J8.print("This is not a problem if you do not plan to use Clojure solutions"),J8.print("See https://clojure.org/guides/getting_started")}async function EE1(){if(await Dv9(!0))J8.success("Java seems installed");else J8.warning("Java does not appear to be installed"),J8.print("You will not be able to compile/execute Java solutions"),J8.print("See https://www.oracle.com/java/technologies/javase-jdk11-downloads.html")}async function fE1(){if(await Ov9(!0))J8.success("Rust seems installed");else J8.warning("Rust does not appear to be installed"),J8.print("You will not be able to compile/execute Rust solutions"),J8.print("See https://www.rust-lang.org/tools/install")}async function CE1(){if(await Ar8(!0))J8.success("XeLaTeX seems installed");else J8.warning("XeLaTeX does not appear to be installed"),J8.print("You will not be able to generate PDF statements with Unicode support"),J8.print("TODO: Provide instructions for installing XeLaTeX")}async function TE1(){if(await Mr8(!0))J8.success("Pandoc with Lua support seems installed");else J8.warning("Pandoc with Lua support does not appear to be installed"),J8.print("You will not be able to generate text statements (HTML, TXT, MD)"),J8.print("See https://pandoc.org/installing.html")}async function RE1(){if(await Nr8(!0))J8.success("ImageMagick seems installed");else J8.warning("ImageMagick does not appear to be installed"),J8.print("You will not be able to convert images for text statements"),J8.print("See https://imagemagick.org/script/download.php")}async function LE1(){await r2();let $=["OPENAI_API_KEY","GEMINI_API_KEY"];for(let q of $)if(process.env[q])J8.success(`${q} environment variable is set`);else J8.warning(`${q} environment variable is not set`),J8.print("You will not be able to use related AI models")}async function SE1(){if(await r2(),process.stdout.isTTY)J8.success("Terminal supports TTY");else J8.warning("Terminal does not support TTY"),J8.print("Some output features may not work as expected");if(nG.isSupported)J8.success("Terminal supports hyperlinks");else J8.warning("Terminal does not support hyperlinks"),J8.print("Links to files may not be clickable");let $=["EDITOR","VISUAL"];for(let q of $)if(process.env[q])J8.success(`${q} environment variable is set to "${process.env[q]}"`);else J8.warning(`${q} environment variable is not set`)}async function IM8($){let q=await mP($);return new hE1(q)}class hE1{problem;constructor($){this.problem=$}async showDirectory(){await J8.section("Directory",async()=>{await r2(),J8.directory(bE1(this.problem.directory));let $=Mv9(bE1(this.problem.directory));if(!$.endsWith(".pbm")){let q=Pv9($),Y=Av9($);if(!Object.keys(D_).includes(q)||!Y.endsWith(".pbm"))throw Error("The problem directory should end with .pbm or be a language id inside a .pbm directory")}})}async makeProblem(){await this.makeGoldenExecutable(),await this.makeCorrects(),await this.checkSolutions(),await this.makePdfStatements(),await this.makeTextualStatements()}async makeExecutable($){let q=this.selectCompiler(),Y=`${cY()}-${$}`;await J8.section(`Copying ${J8.hyperlink(this.problem.directory,$)} to ${J8.hyperlink(this.problem.directory,Y)}`,async()=>{await lP(u$(this.problem.directory,$),u$(this.problem.directory,Y))}),await J8.section(`Compiling ${J8.hyperlink(this.problem.directory,Y)} with ${q.name()} (${this.problem.handler.source_modifier})`,async()=>{try{let w;if(this.problem.handler.source_modifier==="none")w=await q.compileNormal(this.problem.handler,this.problem.directory,Y);else if(this.problem.handler.source_modifier==="no_main")w=await q.compileWithMain(this.problem.handler,this.problem.directory,Y);else throw Error(`Unknown source modifier: ${this.problem.handler.source_modifier}`);if(!await IE1(u$(this.problem.directory,w)))throw Error(`Compilation failed for ${Y}`);J8.success(`Compiled ${Y} to ${w}`)}catch(w){throw Error("Compilation failed")}})}async makeExecutables(){await J8.section("Compiling solutions",async()=>{for(let $ of this.problem.solutions)await this.makeExecutable($)})}async makeGoldenExecutable(){await J8.section(`Compiling golden solution from ${J8.hyperlink(this.problem.directory,this.problem.goldenSolution)}`,async()=>{if(!this.problem.goldenSolution)throw Error("Golden solution not set");await this.makeExecutable(this.problem.goldenSolution)})}async checkSolutions(){for(let $ of this.problem.solutions)if($!==this.problem.goldenSolution)await this.verifyCandidate($)}async makeCorrect($,q,Y){return await this.runTestcase($,`${$}.inp`,`${$}.cor`,q,cY()+"-"+Y)}async runTestcase($,q,Y,w,J){let K=!1,H=Date.now();try{await w.execute(this.problem.handler,this.problem.directory,J,q,Y)}catch(D){J8.error(`Execution failed for testcase '${$}'`),K=!0}let X=Date.now()-H;if(this.problem.handler.handler==="graphic")await Vv9(u$(this.problem.directory,"output.png"),u$(this.problem.directory,Y));let z=await Mk8(u$(this.problem.directory,q)),G=await Mk8(u$(this.problem.directory,Y));return{testcase:$,error:K,time:X,inputSize:z,outputSize:G}}selectCompiler(){if(this.problem.handler.compilers==="RunPython")return E$8("RunPython");else if(this.problem.handler.compilers==="RunHaskell")return E$8("RunHaskell");else if(this.problem.handler.compilers==="RunClojure")return E$8("RunClojure");else{let $=this.problem.goldenSolution.split(".").pop();return Wr8($)}}async makeCorrects(){let $=this.selectCompiler();await J8.section("Making correct outputs with golden solution",async()=>{await J8.section(`Executing testcases using ${$.name()}`,async()=>{let q=[];for(let w of this.problem.testcases)q.push(await this.makeCorrect(w,$,this.problem.goldenSolution));console.log(),console.log("testcase time input output");for(let w of q){let J=gF(w.time),K=MM8(w.inputSize).replace(" ",""),H=MM8(w.outputSize).replace(" ","");console.log((w.error?M9.red:M9.green)(`${w.testcase.padEnd(12)} ${J.padStart(10)} ${K.padStart(10)} ${H.padStart(10)}`))}let Y=q.filter((w)=>w.error).length;if(Y>0)throw console.log(),Error(`${Y} errors occurred while making correct answers`)})})}async makePdfStatements(){await J8.section("Making PDF statements",async()=>{let $=u$(this.problem.directory,cY()+"-pdf",ya());await ZM8($,{recursive:!0}),await J8.section("Creating working directory",async()=>{await r2(),J8.directory($)});for(let q of this.problem.languages)if(this.problem.structure==="multi"||this.problem.structure==="single"&&q===this.problem.language)await J8.section(`Making PDF statement for ${D_[q]}`,async()=>{await this.makePdfStatement($,q)})})}async makeSamples($,q){let Y=this.problem.handler.handler==="graphic",w=[],J=[],K=1;for(let H of this.problem.testcases)if(H.startsWith("sample")){let W="";if(Y){await lP(u$(this.problem.directory,`${H}.cor`),u$($,`${H}.cor.png`));let X=await AM8(u$($,`${H}.cor.png`));W=`(${X.width}$\\times$${X.height})`}w.push(`
3968
3968
  \\SampleOneColInputOutput[${W}]{${H}}{${K}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jutge.org/toolkit",
3
3
  "description": "Toolkit to prepare problems for Jutge.org",
4
- "version": "4.0.3",
4
+ "version": "4.0.5",
5
5
  "homepage": "https://jutge.org",
6
6
  "author": {
7
7
  "name": "Jutge.org",