@learnpack/learnpack 5.0.290 → 5.0.291
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/lib/commands/serve.js +13 -3
- package/lib/creatorDist/assets/{index-7zTdUX04.js → index-wLKEQIG6.js} +2 -2
- package/lib/creatorDist/index.html +1 -1
- package/lib/utils/configBuilder.js +20 -1
- package/package.json +1 -1
- package/src/commands/serve.ts +71 -58
- package/src/creator/src/App.tsx +1 -2
- package/src/creatorDist/assets/{index-7zTdUX04.js → index-wLKEQIG6.js} +2 -2
- package/src/creatorDist/index.html +1 -1
- package/src/ui/_app/app.js +397 -397
- package/src/ui/app.tar.gz +0 -0
- package/src/utils/configBuilder.ts +100 -82
package/src/ui/app.tar.gz
CHANGED
Binary file
|
@@ -1,82 +1,100 @@
|
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
+
}
|