@learnpack/learnpack 5.0.335 → 5.0.339

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 (48) hide show
  1. package/bin/run +17 -17
  2. package/lib/commands/init.js +41 -41
  3. package/lib/commands/serve.js +589 -126
  4. package/lib/creatorDist/assets/index-BhqDgBS9.js +8448 -78631
  5. package/lib/creatorDist/assets/index-CjddKHB_.css +1 -1688
  6. package/lib/managers/config/exercise.js +2 -14
  7. package/lib/managers/readmeHistoryService.js +3 -1
  8. package/lib/managers/server/routes.js +2 -1
  9. package/lib/utils/configBuilder.js +2 -1
  10. package/lib/utils/creatorUtilities.js +14 -14
  11. package/lib/utils/exerciseFileOrder.d.ts +20 -0
  12. package/lib/utils/exerciseFileOrder.js +49 -0
  13. package/lib/utils/export/epub.js +26 -26
  14. package/lib/utils/readmeSanitizer.d.ts +8 -0
  15. package/lib/utils/readmeSanitizer.js +13 -0
  16. package/lib/utils/templates/epub/epub.css +146 -146
  17. package/lib/utils/templates/scorm/config/api.js +175 -175
  18. package/package.json +1 -1
  19. package/src/commands/init.ts +655 -655
  20. package/src/commands/publish.ts +670 -670
  21. package/src/commands/serve.ts +5853 -5216
  22. package/src/creator/eslint.config.js +28 -28
  23. package/src/creator/src/index.css +227 -227
  24. package/src/creator/src/utils/lib.ts +471 -471
  25. package/src/creatorDist/assets/index-BhqDgBS9.js +8448 -78631
  26. package/src/creatorDist/assets/index-CjddKHB_.css +1 -1688
  27. package/src/managers/config/exercise.ts +3 -15
  28. package/src/managers/readmeHistoryService.ts +3 -1
  29. package/src/managers/server/routes.ts +15 -6
  30. package/src/managers/session.ts +184 -184
  31. package/src/ui/_app/app.css +1 -1
  32. package/src/ui/_app/app.js +1950 -1878
  33. package/src/ui/app.tar.gz +0 -0
  34. package/src/utils/api.ts +675 -675
  35. package/src/utils/configBuilder.ts +102 -100
  36. package/src/utils/creatorUtilities.ts +536 -536
  37. package/src/utils/errors.ts +108 -108
  38. package/src/utils/exerciseFileOrder.ts +50 -0
  39. package/src/utils/export/epub.ts +553 -553
  40. package/src/utils/export/index.ts +4 -4
  41. package/src/utils/export/scorm.ts +121 -121
  42. package/src/utils/export/shared.ts +61 -61
  43. package/src/utils/export/types.ts +25 -25
  44. package/src/utils/export/zip.ts +55 -55
  45. package/src/utils/readmeSanitizer.ts +10 -0
  46. package/src/utils/rigoActions.ts +642 -642
  47. package/src/utils/templates/epub/epub.css +146 -146
  48. package/src/utils/templates/scorm/config/api.js +175 -175
@@ -1,100 +1,102 @@
1
- import { Bucket, File } from "@google-cloud/storage"
2
-
3
- type TFile = {
4
- name: string;
5
- slug: string;
6
- hidden: boolean;
7
- };
8
-
9
- export type Exercise = {
10
- title: string;
11
- slug: string;
12
- graded: boolean;
13
- files: TFile[];
14
- translations: Record<string, string>;
15
- position: number;
16
- };
17
-
18
- export type ConfigResponse = {
19
- config: any;
20
- exercises: Exercise[];
21
- };
22
-
23
- function naturalCompare(a: string, b: string): number {
24
- // Split by dots and hyphens, compare numbers as numbers
25
- const regex = /(\d+|\D+)/g
26
- const ax = a.match(regex)!
27
- const bx = b.match(regex)!
28
- for (let i = 0; i < Math.max(ax.length, bx.length); i++) {
29
- const an = parseInt(ax[i], 10)
30
- const bn = parseInt(bx[i], 10)
31
- if (!isNaN(an) && !isNaN(bn)) {
32
- if (an !== bn) return an - bn
33
- } else if (ax[i] !== bx[i]) return (ax[i] || "").localeCompare(bx[i] || "")
34
- }
35
-
36
- return 0
37
- }
38
-
39
- /**
40
- * Crea la configuración y lista de ejercicios para un curso.
41
- *
42
- * @param bucket - Instancia de GCS Bucket donde está el curso.
43
- * @param courseSlug - Slug del curso a procesar.
44
- * @returns Promise con objeto { config, exercises } listo para usar.
45
- */
46
- export async function buildConfig(
47
- bucket: Bucket,
48
- courseSlug: string
49
- ): Promise<ConfigResponse> {
50
- const prefix = `courses/${courseSlug}/`
51
- const [files] = await bucket.getFiles({ prefix })
52
-
53
- // 1) Leer learn.json
54
- const learnFile = files.find(f => f.name.endsWith("learn.json"))!
55
- const [learnBuf] = await learnFile.download()
56
- const learnJson = JSON.parse(learnBuf.toString())
57
-
58
- // 2) Agrupar ejercicios
59
- const map: Record<string, Omit<Exercise, "position">> = {}
60
- for (const file of files) {
61
- const parts = file.name.split("/")
62
- if (!parts.includes("exercises")) continue
63
-
64
- const slug = parts[parts.indexOf("exercises") + 1]
65
- if (!map[slug]) {
66
- map[slug] = {
67
- title: slug,
68
- slug,
69
- graded: false,
70
- files: [],
71
- translations: {},
72
- }
73
- }
74
-
75
- const fname = parts.pop()!
76
- const m = fname.match(/^readme(?:\.([a-z]{2}))?\.md$/i)
77
- if (m) {
78
- const lang = m[1] || "en"
79
- map[slug].translations[lang] = fname
80
- } else {
81
- map[slug].files.push({
82
- name: fname,
83
- slug: fname,
84
- hidden: false,
85
- })
86
- }
87
- }
88
-
89
- const exercises = Object.values(map)
90
- .sort((a, b) => naturalCompare(a.slug, b.slug))
91
- .map((ex, i) => ({
92
- ...ex,
93
- position: i,
94
- }))
95
-
96
- return {
97
- config: { ...learnJson },
98
- exercises,
99
- }
100
- }
1
+ import { Bucket, File } from "@google-cloud/storage"
2
+ import { sortExerciseFiles } from "./exerciseFileOrder"
3
+
4
+ type TFile = {
5
+ name: string;
6
+ slug: string;
7
+ hidden: boolean;
8
+ };
9
+
10
+ export type Exercise = {
11
+ title: string;
12
+ slug: string;
13
+ graded: boolean;
14
+ files: TFile[];
15
+ translations: Record<string, string>;
16
+ position: number;
17
+ };
18
+
19
+ export type ConfigResponse = {
20
+ config: any;
21
+ exercises: Exercise[];
22
+ };
23
+
24
+ function naturalCompare(a: string, b: string): number {
25
+ // Split by dots and hyphens, compare numbers as numbers
26
+ const regex = /(\d+|\D+)/g
27
+ const ax = a.match(regex)!
28
+ const bx = b.match(regex)!
29
+ for (let i = 0; i < Math.max(ax.length, bx.length); i++) {
30
+ const an = parseInt(ax[i], 10)
31
+ const bn = parseInt(bx[i], 10)
32
+ if (!isNaN(an) && !isNaN(bn)) {
33
+ if (an !== bn) return an - bn
34
+ } else if (ax[i] !== bx[i]) return (ax[i] || "").localeCompare(bx[i] || "")
35
+ }
36
+
37
+ return 0
38
+ }
39
+
40
+ /**
41
+ * Crea la configuración y lista de ejercicios para un curso.
42
+ *
43
+ * @param bucket - Instancia de GCS Bucket donde está el curso.
44
+ * @param courseSlug - Slug del curso a procesar.
45
+ * @returns Promise con objeto { config, exercises } listo para usar.
46
+ */
47
+ export async function buildConfig(
48
+ bucket: Bucket,
49
+ courseSlug: string
50
+ ): Promise<ConfigResponse> {
51
+ const prefix = `courses/${courseSlug}/`
52
+ const [files] = await bucket.getFiles({ prefix })
53
+
54
+ // 1) Leer learn.json
55
+ const learnFile = files.find(f => f.name.endsWith("learn.json"))!
56
+ const [learnBuf] = await learnFile.download()
57
+ const learnJson = JSON.parse(learnBuf.toString())
58
+
59
+ // 2) Agrupar ejercicios
60
+ const map: Record<string, Omit<Exercise, "position">> = {}
61
+ for (const file of files) {
62
+ const parts = file.name.split("/")
63
+ if (!parts.includes("exercises")) continue
64
+
65
+ const slug = parts[parts.indexOf("exercises") + 1]
66
+ if (!map[slug]) {
67
+ map[slug] = {
68
+ title: slug,
69
+ slug,
70
+ graded: false,
71
+ files: [],
72
+ translations: {},
73
+ }
74
+ }
75
+
76
+ const fname = parts.pop()!
77
+ const m = fname.match(/^readme(?:\.([a-z]{2}))?\.md$/i)
78
+ if (m) {
79
+ const lang = m[1] || "en"
80
+ map[slug].translations[lang] = fname
81
+ } else {
82
+ map[slug].files.push({
83
+ name: fname,
84
+ slug: fname,
85
+ hidden: false,
86
+ })
87
+ }
88
+ }
89
+
90
+ const exercises = Object.values(map)
91
+ .sort((a, b) => naturalCompare(a.slug, b.slug))
92
+ .map((ex, i) => ({
93
+ ...ex,
94
+ files: sortExerciseFiles(ex.files),
95
+ position: i,
96
+ }))
97
+
98
+ return {
99
+ config: { ...learnJson },
100
+ exercises,
101
+ }
102
+ }