@learnpack/learnpack 5.0.130 → 5.0.134

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/README.md CHANGED
@@ -21,7 +21,7 @@ $ npm install -g @learnpack/learnpack
21
21
  $ learnpack COMMAND
22
22
  running command...
23
23
  $ learnpack (-v|--version|version)
24
- @learnpack/learnpack/5.0.130 win32-x64 node-v22.15.0
24
+ @learnpack/learnpack/5.0.134 win32-x64 node-v22.15.0
25
25
  $ learnpack --help [COMMAND]
26
26
  USAGE
27
27
  $ learnpack COMMAND
@@ -80,7 +80,7 @@ DESCRIPTION
80
80
  12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)
81
81
  ```
82
82
 
83
- _See code: [src\commands\audit.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.130/src\commands\audit.ts)_
83
+ _See code: [src\commands\audit.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.134/src\commands\audit.ts)_
84
84
 
85
85
  ## `learnpack breakToken`
86
86
 
@@ -95,7 +95,7 @@ OPTIONS
95
95
  -y, --yes Skip all prompts and initialize an empty project
96
96
  ```
97
97
 
98
- _See code: [src\commands\breakToken.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.130/src\commands\breakToken.ts)_
98
+ _See code: [src\commands\breakToken.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.134/src\commands\breakToken.ts)_
99
99
 
100
100
  ## `learnpack clean`
101
101
 
@@ -110,7 +110,7 @@ DESCRIPTION
110
110
  Extra documentation goes here
111
111
  ```
112
112
 
113
- _See code: [src\commands\clean.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.130/src\commands\clean.ts)_
113
+ _See code: [src\commands\clean.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.134/src\commands\clean.ts)_
114
114
 
115
115
  ## `learnpack download [PACKAGE]`
116
116
 
@@ -128,7 +128,7 @@ DESCRIPTION
128
128
  Extra documentation goes here
129
129
  ```
130
130
 
131
- _See code: [src\commands\download.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.130/src\commands\download.ts)_
131
+ _See code: [src\commands\download.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.134/src\commands\download.ts)_
132
132
 
133
133
  ## `learnpack help [COMMAND]`
134
134
 
@@ -160,7 +160,7 @@ OPTIONS
160
160
  -y, --yes Skip all prompts and initialize an empty project
161
161
  ```
162
162
 
163
- _See code: [src\commands\init.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.130/src\commands\init.ts)_
163
+ _See code: [src\commands\init.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.134/src\commands\init.ts)_
164
164
 
165
165
  ## `learnpack login [PACKAGE]`
166
166
 
@@ -178,7 +178,7 @@ DESCRIPTION
178
178
  Extra documentation goes here
179
179
  ```
180
180
 
181
- _See code: [src\commands\login.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.130/src\commands\login.ts)_
181
+ _See code: [src\commands\login.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.134/src\commands\login.ts)_
182
182
 
183
183
  ## `learnpack logout [PACKAGE]`
184
184
 
@@ -196,7 +196,7 @@ DESCRIPTION
196
196
  Extra documentation goes here
197
197
  ```
198
198
 
199
- _See code: [src\commands\logout.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.130/src\commands\logout.ts)_
199
+ _See code: [src\commands\logout.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.134/src\commands\logout.ts)_
200
200
 
201
201
  ## `learnpack plugins`
202
202
 
@@ -328,7 +328,7 @@ OPTIONS
328
328
  -s, --strict strict mode
329
329
  ```
330
330
 
331
- _See code: [src\commands\publish.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.130/src\commands\publish.ts)_
331
+ _See code: [src\commands\publish.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.134/src\commands\publish.ts)_
332
332
 
333
333
  ## `learnpack serve`
334
334
 
@@ -345,7 +345,7 @@ OPTIONS
345
345
  -y, --yes Skip all prompts and initialize an empty project
346
346
  ```
347
347
 
348
- _See code: [src\commands\serve.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.130/src\commands\serve.ts)_
348
+ _See code: [src\commands\serve.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.134/src\commands\serve.ts)_
349
349
 
350
350
  ## `learnpack start`
351
351
 
@@ -367,7 +367,7 @@ OPTIONS
367
367
  -y, --yes Skip all prompts and initialize an empty project
368
368
  ```
369
369
 
370
- _See code: [src\commands\start.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.130/src\commands\start.ts)_
370
+ _See code: [src\commands\start.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.134/src\commands\start.ts)_
371
371
 
372
372
  ## `learnpack test [EXERCISESLUG]`
373
373
 
@@ -384,7 +384,7 @@ OPTIONS
384
384
  -y, --yes Skip all prompts and initialize an empty project
385
385
  ```
386
386
 
387
- _See code: [src\commands\test.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.130/src\commands\test.ts)_
387
+ _See code: [src\commands\test.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.134/src\commands\test.ts)_
388
388
 
389
389
  ## `learnpack translate`
390
390
 
@@ -398,7 +398,7 @@ OPTIONS
398
398
  -y, --yes Skip all prompts and initialize an empty project
399
399
  ```
400
400
 
401
- _See code: [src\commands\translate.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.130/src\commands\translate.ts)_
401
+ _See code: [src\commands\translate.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.134/src\commands\translate.ts)_
402
402
  <!-- commandsstop -->
403
403
 
404
404
  > > > > > > > 0cb3e56d84c197f9d008836bb573eade212b7e57
@@ -1,7 +1,58 @@
1
1
  import SessionCommand from "../utils/SessionCommand";
2
+ import { Bucket } from "@google-cloud/storage";
3
+ export declare const createLearnJson: (courseInfo: FormState) => {
4
+ slug: string;
5
+ title: {
6
+ us: string;
7
+ };
8
+ technologies: string[];
9
+ difficulty: string;
10
+ description: {
11
+ us: string;
12
+ };
13
+ grading: string;
14
+ telemetry: {
15
+ batch: string;
16
+ };
17
+ preview: string;
18
+ };
19
+ export declare const processImage: (bucket: Bucket, tutorialDir: string, url: string, description: string, rigoToken: string) => Promise<boolean>;
20
+ export declare function processExercise(bucket: Bucket, rigoToken: string, steps: Lesson[], packageContext: string, exercise: Lesson, exercisesDir: string): Promise<string>;
21
+ interface Lesson {
22
+ id: string;
23
+ uid: string;
24
+ title: string;
25
+ type: "READ" | "CODE" | "QUIZ";
26
+ description: string;
27
+ duration?: number;
28
+ }
29
+ interface ParsedLink {
30
+ url: string;
31
+ title?: string;
32
+ text?: string;
33
+ transcript?: string;
34
+ description?: string;
35
+ author?: string;
36
+ duration?: number;
37
+ thumbnail?: string;
38
+ }
39
+ type FormState = {
40
+ description: string;
41
+ duration: number;
42
+ targetAudience: string;
43
+ hasContentIndex: boolean;
44
+ contentIndex: string;
45
+ sources: ParsedLink[];
46
+ isCompleted: boolean;
47
+ variables: string[];
48
+ currentStep: string;
49
+ title: string;
50
+ technologies?: string[];
51
+ };
2
52
  export default class ServeCommand extends SessionCommand {
3
53
  static description: string;
4
54
  static flags: any;
5
55
  init(): Promise<void>;
6
56
  run(): Promise<void>;
7
57
  }
58
+ export {};
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processImage = exports.createLearnJson = void 0;
4
+ exports.processExercise = processExercise;
3
5
  const command_1 = require("@oclif/command");
4
6
  // import * as ytdl from "ytdl-core"
5
7
  const youtube_transcript_1 = require("youtube-transcript");
@@ -17,14 +19,128 @@ const file_1 = require("../managers/file");
17
19
  const fs = require("fs");
18
20
  const rigoActions_1 = require("../utils/rigoActions");
19
21
  const dotenv = require("dotenv");
22
+ const creatorUtilities_1 = require("../utils/creatorUtilities");
20
23
  // import { handleAssetCreation } from "./publish"
21
24
  const axios_1 = require("axios");
22
25
  const FormData = require("form-data");
23
26
  const api_1 = require("../utils/api");
24
27
  const misc_1 = require("../utils/misc");
25
28
  const configBuilder_1 = require("../utils/configBuilder");
26
- dotenv.config();
29
+ const creatorUtilities_2 = require("../utils/creatorUtilities");
27
30
  const frontMatter = require("front-matter");
31
+ dotenv.config();
32
+ const createLearnJson = (courseInfo) => {
33
+ console.log("courseInfo to create learn json", courseInfo);
34
+ const learnJson = {
35
+ slug: (0, creatorUtilities_2.slugify)(courseInfo.title),
36
+ title: {
37
+ us: courseInfo.title,
38
+ },
39
+ technologies: courseInfo.technologies || [],
40
+ difficulty: "beginner",
41
+ description: {
42
+ us: courseInfo.description,
43
+ },
44
+ grading: "isolated",
45
+ telemetry: {
46
+ batch: "https://breathecode.herokuapp.com/v1/assignment/me/telemetry",
47
+ },
48
+ preview: "preview.png",
49
+ };
50
+ return learnJson;
51
+ };
52
+ exports.createLearnJson = createLearnJson;
53
+ const uploadFileToBucket = async (bucket, file, path) => {
54
+ const fileRef = bucket.file(path);
55
+ await fileRef.save(file);
56
+ };
57
+ const uploadImageToBucket = async (bucket, url, path) => {
58
+ const response = await fetch(url);
59
+ if (!response.ok) {
60
+ throw new Error(`Failed to download image: ${response.statusText}`);
61
+ }
62
+ const contentType = response.headers.get("content-type") || "application/octet-stream";
63
+ const buffer = await response.arrayBuffer();
64
+ const fileRef = bucket.file(path);
65
+ await fileRef.save(Buffer.from(buffer), {
66
+ resumable: false,
67
+ contentType,
68
+ });
69
+ };
70
+ const PARAMS = {
71
+ expected_grade_level: "7",
72
+ max_fkgl: 9,
73
+ max_words: 200,
74
+ max_rewrite_attempts: 2,
75
+ max_title_length: 50,
76
+ };
77
+ const processImage = async (bucket, tutorialDir, url, description, rigoToken) => {
78
+ try {
79
+ const filename = (0, creatorUtilities_1.getFilenameFromUrl)(url);
80
+ const imagePath = `${tutorialDir}/.learn/assets/${filename}`;
81
+ console.log("🖼️ Generating image", imagePath);
82
+ const res = await (0, rigoActions_1.generateImage)(rigoToken, { prompt: description });
83
+ await uploadImageToBucket(bucket, res.image_url, imagePath);
84
+ console.log("✅ Image", imagePath, "generated successfully!");
85
+ return true;
86
+ }
87
+ catch (_a) {
88
+ return false;
89
+ }
90
+ };
91
+ exports.processImage = processImage;
92
+ async function processExercise(bucket, rigoToken, steps, packageContext, exercise, exercisesDir) {
93
+ // const tid = toast.loading("Generating lesson...")
94
+ const exSlug = (0, creatorUtilities_2.slugify)(exercise.id + "-" + exercise.title);
95
+ const readmeFilename = "README.md";
96
+ const targetDir = `${exercisesDir}/${exSlug}`;
97
+ console.log("✍🏻 Generating lesson", exercise.id, exercise.title);
98
+ const isGeneratingText = `The lesson ${exercise.id} - ${exercise.title} is being generated by Rigobot, wait a sec!
99
+
100
+ \`\`\`loader slug="${exSlug}"
101
+ # This lesson is being generated by Rigobot, wait a sec!
102
+ \`\`\`
103
+ `;
104
+ await uploadFileToBucket(bucket, isGeneratingText, `${targetDir}/${readmeFilename}`);
105
+ const readme = await (0, rigoActions_1.readmeCreator)(rigoToken, {
106
+ title: `${exercise.id} - ${exercise.title}`,
107
+ output_lang: "en",
108
+ list_of_exercises: JSON.stringify(steps),
109
+ tutorial_description: packageContext,
110
+ lesson_description: exercise.description,
111
+ kind: exercise.type.toLowerCase(),
112
+ });
113
+ const duration = exercise.duration;
114
+ let attempts = 0;
115
+ let readability = (0, creatorUtilities_2.checkReadability)(readme.parsed.content, 200, duration || 1);
116
+ while (readability.fkglResult.fkgl > PARAMS.max_fkgl &&
117
+ attempts < PARAMS.max_rewrite_attempts) {
118
+ console.log("🔄 The lesson", exercise.id, exercise.title, "has a readability score of", readability.fkglResult.fkgl);
119
+ // eslint-disable-next-line
120
+ const reducedReadme = await (0, rigoActions_1.makeReadmeReadable)(rigoToken, {
121
+ lesson: readability.body,
122
+ number_of_words: readability.minutes.toString(),
123
+ expected_number_words: PARAMS.max_words.toString(),
124
+ fkgl_results: JSON.stringify(readability.fkglResult),
125
+ expected_grade_level: PARAMS.expected_grade_level,
126
+ });
127
+ if (!reducedReadme)
128
+ break;
129
+ readability = (0, creatorUtilities_2.checkReadability)(reducedReadme.parsed.content, PARAMS.max_words, duration || 1);
130
+ attempts++;
131
+ }
132
+ console.log(`✅ After ${attempts} attempts, the lesson ${exercise.title} has a readability score of ${readability.fkglResult.fkgl} using FKGL. And it has ${readability.minutes.toFixed(2)} minutes of reading time.`);
133
+ await uploadFileToBucket(bucket, readability.newMarkdown, `${targetDir}/${readmeFilename}`);
134
+ if (exercise.type.toLowerCase() === "code") {
135
+ console.log("🔍 Creating code file for", exercise.title);
136
+ const codeFile = await (0, rigoActions_1.createCodeFile)(rigoToken, {
137
+ readme: readability.newMarkdown,
138
+ tutorial_info: packageContext,
139
+ });
140
+ await uploadFileToBucket(bucket, codeFile.parsed.content, `${targetDir}/index.${codeFile.parsed.extension.replace(".", "")}`);
141
+ }
142
+ return readability.newMarkdown;
143
+ }
28
144
  const fixPreviewUrl = (slug, previewUrl) => {
29
145
  if (!previewUrl) {
30
146
  return null;
@@ -105,7 +221,7 @@ class ServeCommand extends SessionCommand_1.default {
105
221
  });
106
222
  stream.end(buffer);
107
223
  });
108
- app.post("/upload-image", express.json({ limit: "20mb" }), async (req, res) => {
224
+ app.post("/upload-image", express.json({ limit: 20000000 }), async (req, res) => {
109
225
  const { image_url, destination } = req.body;
110
226
  if (!image_url || !destination) {
111
227
  return res
@@ -326,6 +442,33 @@ class ServeCommand extends SessionCommand_1.default {
326
442
  const file = path.join(distPath, "assets", req.params.file);
327
443
  res.sendFile(file);
328
444
  });
445
+ app.post("/actions/create-course", async (req, res) => {
446
+ console.log("POST /actions/create-course");
447
+ const { syllabus } = req.body;
448
+ const rigoToken = req.header("x-rigo-token");
449
+ const bcToken = req.header("x-breathecode-token");
450
+ if (!rigoToken || !bcToken) {
451
+ return res.status(400).json({ error: "Missing tokens" });
452
+ }
453
+ const tutorialDir = "courses/" + (0, creatorUtilities_2.slugify)(syllabus.courseInfo.title);
454
+ const learnJson = (0, exports.createLearnJson)(syllabus.courseInfo);
455
+ await uploadFileToBucket(bucket, JSON.stringify(learnJson), `courses/${(0, creatorUtilities_2.slugify)(syllabus.courseInfo.title)}/learn.json`);
456
+ const lessonsPromises = syllabus.lessons.map(lesson => processExercise(bucket, rigoToken, syllabus.lessons, JSON.stringify(syllabus.courseInfo), lesson, tutorialDir + "/exercises"));
457
+ const readmeContents = await Promise.all(lessonsPromises);
458
+ let imagesArray = [];
459
+ for (const content of readmeContents) {
460
+ imagesArray = [...imagesArray, ...(0, creatorUtilities_1.extractImagesFromMarkdown)(content)];
461
+ }
462
+ console.log("📷 Generating images...");
463
+ const imagePromises = imagesArray.map(async (image) => {
464
+ return (0, exports.processImage)(bucket, tutorialDir, image.url, image.alt, rigoToken);
465
+ });
466
+ await Promise.all(imagePromises);
467
+ return res.json({
468
+ message: "Course created",
469
+ slug: (0, creatorUtilities_2.slugify)(syllabus.courseInfo.title),
470
+ });
471
+ });
329
472
  app.post("/actions/publish/:slug", async (req, res) => {
330
473
  try {
331
474
  const { slug } = req.params;