@jutge.org/toolkit 4.4.16 → 4.4.19

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 (40) hide show
  1. package/README.md +1 -0
  2. package/assets/problems/quizzes/demo-quiz.pbm/README.md +1 -0
  3. package/assets/problems/quizzes/demo-quiz.pbm/ca/award.png +0 -0
  4. package/assets/problems/quizzes/demo-quiz.pbm/ca/quiz.yml +1 -1
  5. package/assets/problems/quizzes/demo-quiz.pbm/ca/single-choice.yml +9 -1
  6. package/assets/problems/quizzes/demo-quiz.pbm/ca/some-drawing.svg +150 -0
  7. package/assets/problems/quizzes/demo-quiz.pbm/ca/some-image.png +0 -0
  8. package/assets/problems/quizzes/demo-quiz.pbm/en/quiz.yml +1 -1
  9. package/assets/problems/quizzes/demo-quiz.pbm/en/single-choice.yml +9 -1
  10. package/assets/problems/quizzes/demo-quiz.pbm/en/some-drawing.svg +150 -0
  11. package/assets/problems/quizzes/demo-quiz.pbm/en/some-image.png +0 -0
  12. package/assets/problems/quizzes/heroes-of-computation.pbm/README.md +11 -0
  13. package/assets/problems/quizzes/heroes-of-computation.pbm/en/handler.yml +1 -0
  14. package/assets/problems/quizzes/heroes-of-computation.pbm/en/q01.yml +14 -0
  15. package/assets/problems/quizzes/heroes-of-computation.pbm/en/q02.yml +14 -0
  16. package/assets/problems/quizzes/heroes-of-computation.pbm/en/q03.yml +14 -0
  17. package/assets/problems/quizzes/heroes-of-computation.pbm/en/q04.yml +15 -0
  18. package/assets/problems/quizzes/heroes-of-computation.pbm/en/q05.yml +32 -0
  19. package/assets/problems/quizzes/heroes-of-computation.pbm/en/q06.yml +12 -0
  20. package/assets/problems/quizzes/heroes-of-computation.pbm/en/q07.yml +23 -0
  21. package/assets/problems/quizzes/heroes-of-computation.pbm/en/q08.yml +14 -0
  22. package/assets/problems/quizzes/heroes-of-computation.pbm/en/q09.yml +14 -0
  23. package/assets/problems/quizzes/heroes-of-computation.pbm/en/q10.yml +23 -0
  24. package/assets/problems/quizzes/heroes-of-computation.pbm/en/quiz.yml +48 -0
  25. package/assets/problems/quizzes/the-answer-is-42.pbm/en/quiz.yml +2 -0
  26. package/assets/python/pyexec.py +9 -2
  27. package/dist/index.js +479 -471
  28. package/docs/getting-started-guide.md +1 -1
  29. package/docs/login.md +0 -1
  30. package/docs/problem-anatomy.md +1 -1
  31. package/docs/quiz-anatomy.md +382 -0
  32. package/package.json +2 -1
  33. package/toolkit/ask.ts +1 -1
  34. package/toolkit/dummies.ts +5 -4
  35. package/toolkit/generate.ts +19 -16
  36. package/toolkit/lint.ts +3 -4
  37. package/toolkit/make.ts +20 -23
  38. package/toolkit/quiz.ts +49 -14
  39. package/toolkit/share.ts +5 -4
  40. package/toolkit/submit.ts +4 -1
package/toolkit/quiz.ts CHANGED
@@ -1,44 +1,79 @@
1
1
  import { Command } from '@commander-js/extra-typings'
2
- import { makeQuiz, validateQuiz } from '../lib/quiz'
2
+ import { runQuiz, lintQuiz } from '../lib/quiz'
3
+ import {
4
+ loadQuizTestInput,
5
+ playQuiz,
6
+ writeQuizTestOutput,
7
+ } from '../lib/play-quiz'
3
8
  import tui from '../lib/tui'
4
9
  import { findRealDirectories } from '../lib/helpers'
5
10
  import { random } from 'radash'
6
11
 
7
12
  export const quizCmd = new Command('quiz')
8
- .description('Commands related to quizzes')
13
+ .summary('Commands related to quizzes')
9
14
 
10
15
  .action(() => {
11
16
  quizCmd.help()
12
17
  })
13
18
 
14
19
  quizCmd
15
- .command('validate')
16
- .description('Validate a quiz problem')
20
+ .command('lint')
21
+ .summary('Lint a quiz problem')
17
22
 
18
23
  .option('-d, --directory <directory>', 'problem directory', '.')
19
24
 
20
25
  .action(async ({ directory }) => {
21
26
  const realDirectories = await findRealDirectories([directory])
22
27
  for (const directory of realDirectories) {
23
- await tui.section(`Validating quiz in directory ${tui.hyperlink(directory)}`, async () => {
24
- await validateQuiz(directory)
28
+ await tui.section(`Linting quiz in directory ${tui.hyperlink(directory)}`, async () => {
29
+ await lintQuiz(directory)
25
30
  })
26
31
  }
27
32
  })
28
33
 
29
34
  quizCmd
30
- .command('make')
31
- .description('Make a quiz problem')
35
+ .command('run')
36
+ .summary('Run a quiz problem')
37
+ .description(
38
+ `Run a quiz problem.
39
+
40
+ This command will run the quiz problem and print the resulting object to stdout.
41
+ A random seed will be generated if not provided.
42
+ `)
32
43
 
33
44
  .option('-d, --directory <directory>', 'problem directory', '.')
34
45
  .option('-s, --seed <seed>', 'random seed')
46
+ .option('-f, --format <format>', 'output format (json|yaml)', 'json')
35
47
 
36
- .action(async ({ directory, seed }) => {
37
- tui.warning('The quiz make command is work-in-progress and may not work as expected yet.')
38
- const realDirectories = await findRealDirectories([directory])
48
+ .action(async ({ directory, seed, format }) => {
39
49
  const seedValue = seed ? parseInt(seed, 10) : random(1000000, 9999999)
40
- for (const directory of realDirectories) {
41
- await makeQuiz(directory, seedValue)
42
- return // in this case we only process one directory as quizzes should only have one language
50
+ const object = await runQuiz(directory, seedValue)
51
+ if (format === 'json') {
52
+ tui.json(object)
53
+ } else {
54
+ tui.yaml(object)
55
+ }
56
+ })
57
+
58
+
59
+ quizCmd
60
+ .command('play')
61
+ .summary('Play a quiz problem')
62
+ .description(
63
+ `Play an interactive quiz test. Questions are shown in sequence; you can review and change answers before submitting.
64
+ Input is a JSON file from \`quiz run\`; if --input is omitted, a run is generated with a random seed from the given directory.
65
+ If --output is given, the results (your answers, correct answers, and score per question) are written to that file.`)
66
+
67
+ .option('-i, --input <input>', 'input JSON file from quiz run')
68
+ .option('-o, --output <output>', 'output file for results')
69
+ .option('-d, --directory <directory>', 'problem directory (used when --input is not provided)', '.')
70
+ .option('-s, --seed <seed>', 'random seed (used when --input is not provided)')
71
+
72
+ .action(async ({ input, output, directory, seed }) => {
73
+ const seedValue = seed !== undefined ? parseInt(seed, 10) : undefined
74
+ const quizInput = await loadQuizTestInput(input, directory, seedValue)
75
+ const results = await playQuiz(quizInput)
76
+ if (output !== undefined) {
77
+ await writeQuizTestOutput(output, results)
43
78
  }
44
79
  })
package/toolkit/share.ts CHANGED
@@ -2,11 +2,11 @@ import { password } from '@inquirer/prompts'
2
2
  import { Command } from '@commander-js/extra-typings'
3
3
  import { updateSharingSettings } from '../lib/share'
4
4
 
5
-
6
5
  export const cmdShare = new Command('share')
7
6
  .summary('Update and show sharing settings')
8
7
 
9
- .description(`Update and show sharing settings
8
+ .description(
9
+ `Update and show sharing settings
10
10
 
11
11
  First, this command updates the sharing settings in problem.yml file with the ones on Jutge.org to ensure they are consistent.
12
12
 
@@ -18,7 +18,8 @@ Then, it updates the sharing settings in Jutge.org with the requested changes. T
18
18
  --solutions Share solutions
19
19
  --no-solutions Stop sharing solutions
20
20
 
21
- Finally, it updates problem.yml file with the current sharing settings and shows them.`)
21
+ Finally, it updates problem.yml file with the current sharing settings and shows them.`,
22
+ )
22
23
 
23
24
  .option('-d, --directory <directory>', 'problem directory', '.')
24
25
  .option('--passcode [code]', 'Set a passcode (prompted if omitted)')
@@ -46,4 +47,4 @@ Finally, it updates problem.yml file with the current sharing settings and shows
46
47
  const solutions = this.getOptionValueSource('solutions') !== 'default' ? opts.solutions : undefined
47
48
 
48
49
  await updateSharingSettings(opts.directory, { passcode, testcases, solutions })
49
- })
50
+ })
package/toolkit/submit.ts CHANGED
@@ -10,7 +10,10 @@ export const submitCmd = new Command('submit')
10
10
  .option('-c, --compiler <id>', 'compiler to use (default: auto-detect from file extension)', 'auto')
11
11
  .option('-l, --language <code>', 'language code (ca, es, en, ...)', 'en')
12
12
  .option('-n, --no-wait', 'do not wait for submissions to be judged')
13
- .option('--no-browser', 'do not open the submission URL in the browser (only print URL and/or wait for verdict in terminal)')
13
+ .option(
14
+ '--no-browser',
15
+ 'do not open the submission URL in the browser (only print URL and/or wait for verdict in terminal)',
16
+ )
14
17
  .option('-a, --annotation <annotation>', "annotation for the submission (default: 'jtk-submit-<nanoid16>')")
15
18
 
16
19
  .action(async (programs, { directory, compiler, language, wait, browser, annotation }) => {