@learnpack/learnpack 5.0.288 → 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 +62 -76
- package/lib/creatorDist/assets/{index-BjO3hUuz.js → index-wLKEQIG6.js} +4470 -4491
- package/lib/creatorDist/index.html +1 -1
- package/lib/utils/configBuilder.js +20 -1
- package/lib/utils/export/index.d.ts +1 -0
- package/lib/utils/export/index.js +3 -1
- package/lib/utils/export/types.d.ts +1 -1
- package/lib/utils/export/zip.d.ts +2 -0
- package/lib/utils/export/zip.js +46 -0
- package/package.json +1 -1
- package/src/commands/serve.ts +75 -88
- package/src/creator/src/App.tsx +59 -43
- package/src/creator/src/components/syllabus/SyllabusEditor.tsx +1 -21
- package/src/creator/src/utils/lib.ts +468 -477
- package/src/creator/src/utils/store.ts +222 -223
- package/src/creatorDist/assets/{index-BjO3hUuz.js → index-wLKEQIG6.js} +4470 -4491
- 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/utils/export/index.ts +1 -0
- package/src/utils/export/types.ts +1 -1
- package/src/utils/export/zip.ts +55 -0
- package/src/creator/src/components/PassphraseValidator.tsx +0 -47
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
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import * as path from "path";
|
2
|
+
import * as fs from "fs";
|
3
|
+
import * as archiver from "archiver";
|
4
|
+
import * as mkdirp from "mkdirp";
|
5
|
+
import * as rimraf from "rimraf";
|
6
|
+
import { v4 as uuidv4 } from "uuid";
|
7
|
+
import { ExportOptions } from "./types";
|
8
|
+
import { downloadS3Folder, getCourseMetadata } from "./shared";
|
9
|
+
|
10
|
+
export async function exportToZip(options: ExportOptions): Promise<string> {
|
11
|
+
const { courseSlug, bucket, outDir } = options;
|
12
|
+
|
13
|
+
// 1. Create temporary folder
|
14
|
+
const tmpName = uuidv4();
|
15
|
+
const zipOutDir = path.join(outDir, tmpName);
|
16
|
+
rimraf.sync(zipOutDir);
|
17
|
+
mkdirp.sync(zipOutDir);
|
18
|
+
|
19
|
+
// 2. Download all course files from bucket to temporary directory
|
20
|
+
await downloadS3Folder(bucket, `courses/${courseSlug}/`, zipOutDir);
|
21
|
+
|
22
|
+
// 3. Create ZIP file
|
23
|
+
const zipName = `${courseSlug}.zip`;
|
24
|
+
const zipPath = path.join(outDir, zipName);
|
25
|
+
|
26
|
+
// Remove existing zip file if it exists
|
27
|
+
if (fs.existsSync(zipPath)) {
|
28
|
+
fs.unlinkSync(zipPath);
|
29
|
+
}
|
30
|
+
|
31
|
+
const output = fs.createWriteStream(zipPath);
|
32
|
+
const archive = archiver("zip", { zlib: { level: 9 } });
|
33
|
+
|
34
|
+
return new Promise((resolve, reject) => {
|
35
|
+
output.on("close", () => {
|
36
|
+
console.log(`✅ ZIP export completed: ${archive.pointer()} total bytes`);
|
37
|
+
// Clean up temporary directory
|
38
|
+
rimraf.sync(zipOutDir);
|
39
|
+
resolve(zipPath);
|
40
|
+
});
|
41
|
+
|
42
|
+
archive.on("error", (err) => {
|
43
|
+
console.error("❌ ZIP creation error:", err);
|
44
|
+
rimraf.sync(zipOutDir);
|
45
|
+
reject(err);
|
46
|
+
});
|
47
|
+
|
48
|
+
archive.pipe(output);
|
49
|
+
|
50
|
+
// Add all files from the temporary directory to the ZIP
|
51
|
+
archive.directory(zipOutDir, false);
|
52
|
+
|
53
|
+
archive.finalize();
|
54
|
+
});
|
55
|
+
}
|
@@ -1,47 +0,0 @@
|
|
1
|
-
import React, { useEffect } from 'react';
|
2
|
-
import { RIGOBOT_HOST } from '../utils/constants';
|
3
|
-
|
4
|
-
interface PassphraseValidatorProps {
|
5
|
-
onSuccess?: (response: any) => void;
|
6
|
-
onError?: (error: any) => void;
|
7
|
-
}
|
8
|
-
|
9
|
-
const PassphraseValidator: React.FC<PassphraseValidatorProps> = ({
|
10
|
-
onSuccess,
|
11
|
-
onError
|
12
|
-
}) => {
|
13
|
-
useEffect(() => {
|
14
|
-
const validatePassphrase = async () => {
|
15
|
-
try {
|
16
|
-
const response = await fetch(`${RIGOBOT_HOST}/v1/auth/public/token`, {
|
17
|
-
method: 'POST',
|
18
|
-
headers: {
|
19
|
-
'Content-Type': 'application/json',
|
20
|
-
},
|
21
|
-
body: JSON.stringify({
|
22
|
-
passphrase: 'bm29vnv4h43n'
|
23
|
-
})
|
24
|
-
});
|
25
|
-
|
26
|
-
const data = await response.json();
|
27
|
-
|
28
|
-
if (response.ok) {
|
29
|
-
onSuccess?.(data);
|
30
|
-
} else {
|
31
|
-
onError?.(data);
|
32
|
-
}
|
33
|
-
} catch (error) {
|
34
|
-
onError?.(error);
|
35
|
-
}
|
36
|
-
};
|
37
|
-
|
38
|
-
validatePassphrase();
|
39
|
-
}, [onSuccess, onError]);
|
40
|
-
|
41
|
-
return (
|
42
|
-
<div>
|
43
|
-
</div>
|
44
|
-
);
|
45
|
-
};
|
46
|
-
|
47
|
-
export default PassphraseValidator;
|