@learnpack/learnpack 5.0.21 → 5.0.23
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 +11 -11
- package/lib/commands/init.js +69 -33
- package/lib/utils/audit.d.ts +1 -1
- package/lib/utils/audit.js +67 -89
- package/lib/utils/rigoActions.d.ts +28 -1
- package/lib/utils/rigoActions.js +80 -26
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/src/commands/init.ts +97 -44
- package/src/commands/translate.ts +0 -1
- package/src/utils/audit.ts +372 -393
- package/src/utils/rigoActions.ts +137 -34
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.
|
24
|
+
@learnpack/learnpack/5.0.23 win32-x64 node-v20.16.0
|
25
25
|
$ learnpack --help [COMMAND]
|
26
26
|
USAGE
|
27
27
|
$ learnpack COMMAND
|
@@ -75,7 +75,7 @@ DESCRIPTION
|
|
75
75
|
12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)
|
76
76
|
```
|
77
77
|
|
78
|
-
_See code: [src\commands\audit.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
78
|
+
_See code: [src\commands\audit.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.23/src\commands\audit.ts)_
|
79
79
|
|
80
80
|
## `learnpack clean`
|
81
81
|
|
@@ -90,7 +90,7 @@ DESCRIPTION
|
|
90
90
|
Extra documentation goes here
|
91
91
|
```
|
92
92
|
|
93
|
-
_See code: [src\commands\clean.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
93
|
+
_See code: [src\commands\clean.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.23/src\commands\clean.ts)_
|
94
94
|
|
95
95
|
## `learnpack download [PACKAGE]`
|
96
96
|
|
@@ -108,7 +108,7 @@ DESCRIPTION
|
|
108
108
|
Extra documentation goes here
|
109
109
|
```
|
110
110
|
|
111
|
-
_See code: [src\commands\download.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
111
|
+
_See code: [src\commands\download.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.23/src\commands\download.ts)_
|
112
112
|
|
113
113
|
## `learnpack help [COMMAND]`
|
114
114
|
|
@@ -140,7 +140,7 @@ OPTIONS
|
|
140
140
|
-y, --yes Skip all prompts and initialize an empty project
|
141
141
|
```
|
142
142
|
|
143
|
-
_See code: [src\commands\init.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
143
|
+
_See code: [src\commands\init.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.23/src\commands\init.ts)_
|
144
144
|
|
145
145
|
## `learnpack login [PACKAGE]`
|
146
146
|
|
@@ -158,7 +158,7 @@ DESCRIPTION
|
|
158
158
|
Extra documentation goes here
|
159
159
|
```
|
160
160
|
|
161
|
-
_See code: [src\commands\login.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
161
|
+
_See code: [src\commands\login.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.23/src\commands\login.ts)_
|
162
162
|
|
163
163
|
## `learnpack logout [PACKAGE]`
|
164
164
|
|
@@ -176,7 +176,7 @@ DESCRIPTION
|
|
176
176
|
Extra documentation goes here
|
177
177
|
```
|
178
178
|
|
179
|
-
_See code: [src\commands\logout.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
179
|
+
_See code: [src\commands\logout.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.23/src\commands\logout.ts)_
|
180
180
|
|
181
181
|
## `learnpack plugins`
|
182
182
|
|
@@ -307,7 +307,7 @@ OPTIONS
|
|
307
307
|
-h, --help show CLI help
|
308
308
|
```
|
309
309
|
|
310
|
-
_See code: [src\commands\publish.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
310
|
+
_See code: [src\commands\publish.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.23/src\commands\publish.ts)_
|
311
311
|
|
312
312
|
## `learnpack start`
|
313
313
|
|
@@ -329,7 +329,7 @@ OPTIONS
|
|
329
329
|
-y, --yes Skip all prompts and initialize an empty project
|
330
330
|
```
|
331
331
|
|
332
|
-
_See code: [src\commands\start.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
332
|
+
_See code: [src\commands\start.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.23/src\commands\start.ts)_
|
333
333
|
|
334
334
|
## `learnpack test [EXERCISESLUG]`
|
335
335
|
|
@@ -346,7 +346,7 @@ OPTIONS
|
|
346
346
|
-y, --yes Skip all prompts and initialize an empty project
|
347
347
|
```
|
348
348
|
|
349
|
-
_See code: [src\commands\test.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
349
|
+
_See code: [src\commands\test.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.23/src\commands\test.ts)_
|
350
350
|
|
351
351
|
## `learnpack translate`
|
352
352
|
|
@@ -360,7 +360,7 @@ OPTIONS
|
|
360
360
|
-y, --yes Skip all prompts and initialize an empty project
|
361
361
|
```
|
362
362
|
|
363
|
-
_See code: [src\commands\translate.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
363
|
+
_See code: [src\commands\translate.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.23/src\commands\translate.ts)_
|
364
364
|
<!-- commandsstop -->
|
365
365
|
|
366
366
|
> > > > > > > 0cb3e56d84c197f9d008836bb573eade212b7e57
|
package/lib/commands/init.js
CHANGED
@@ -23,8 +23,23 @@ const slugify = (text) => {
|
|
23
23
|
.replace(/\s+/g, "-")
|
24
24
|
.replace(/[^\w-]+/g, "");
|
25
25
|
};
|
26
|
-
const
|
27
|
-
|
26
|
+
const getExInfo = (title) => {
|
27
|
+
// Example title: '1.0 - Introduction to AI [READ: Small introduction to important concepts such as AI, machine learning, and their applications]'
|
28
|
+
let [exNumber, exTitle] = title.split(" - ");
|
29
|
+
// Extract kind and description
|
30
|
+
const kindMatch = exTitle.match(/\[(.*?):(.*?)]/);
|
31
|
+
const kind = kindMatch ? kindMatch[1].trim().toLowerCase() : "read";
|
32
|
+
const description = kindMatch ? kindMatch[2].trim() : "";
|
33
|
+
exNumber = exNumber.trim();
|
34
|
+
// Clean title
|
35
|
+
exTitle = exTitle.replace((kindMatch === null || kindMatch === void 0 ? void 0 : kindMatch[0]) || "", "").trim();
|
36
|
+
exTitle = slugify(exTitle);
|
37
|
+
return {
|
38
|
+
exNumber,
|
39
|
+
kind,
|
40
|
+
description,
|
41
|
+
exTitle,
|
42
|
+
};
|
28
43
|
};
|
29
44
|
function extractImagesFromMarkdown(markdown) {
|
30
45
|
const imageRegex = /!\[([^\]]*)]\(([^)]+)\)/g;
|
@@ -66,6 +81,38 @@ async function createPreviewReadme(tutorialDir, packageInfo, rigoToken, readmeCo
|
|
66
81
|
});
|
67
82
|
fs.writeFileSync(path.join(tutorialDir, readmeFilename), readmeContent.answer);
|
68
83
|
}
|
84
|
+
const initializeInteractiveCreation = async (rigoToken, courseInfo) => {
|
85
|
+
let prevInteractions = "";
|
86
|
+
let isReady = false;
|
87
|
+
let currentSteps = [];
|
88
|
+
while (!isReady) {
|
89
|
+
// eslint-disable-next-line
|
90
|
+
const res = await (0, rigoActions_1.interactiveCreation)(rigoToken, {
|
91
|
+
courseInfo: courseInfo,
|
92
|
+
prevInteractions: prevInteractions,
|
93
|
+
});
|
94
|
+
currentSteps = res.parsed.listOfSteps;
|
95
|
+
isReady = res.parsed.ready;
|
96
|
+
if (!isReady) {
|
97
|
+
console.log(currentSteps);
|
98
|
+
console_1.default.info(`AI: ${res.parsed.aiMessage}`);
|
99
|
+
prevInteractions += `\nAI: ${res.parsed.aiMessage}`;
|
100
|
+
// eslint-disable-next-line
|
101
|
+
const userMessage = await prompts([
|
102
|
+
{
|
103
|
+
type: "text",
|
104
|
+
name: "userMessage",
|
105
|
+
message: "Your message: ",
|
106
|
+
},
|
107
|
+
]);
|
108
|
+
prevInteractions += `\nUser: ${userMessage.userMessage}`;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
return {
|
112
|
+
currentSteps,
|
113
|
+
prevInteractions,
|
114
|
+
};
|
115
|
+
};
|
69
116
|
const handleAILogic = async (tutorialDir, packageInfo) => {
|
70
117
|
console_1.default.info("Almost there! First you need to login with 4Geeks.com to use AI Generation tool for creators. You can create a new account here: https://4geeks.com/creators");
|
71
118
|
fs.removeSync(path.join(tutorialDir, "exercises", "01-hello-world"));
|
@@ -108,23 +155,6 @@ const handleAILogic = async (tutorialDir, packageInfo) => {
|
|
108
155
|
process.exit(1);
|
109
156
|
}
|
110
157
|
console_1.default.success("🎉 Let's begin this learning journey!");
|
111
|
-
const aiChoices = await prompts([
|
112
|
-
{
|
113
|
-
type: "text",
|
114
|
-
name: "tutorialAbout",
|
115
|
-
message: "What kind of tutorial do you want to create? Please expand a little on the content, the outcome and the goal of the tutorial",
|
116
|
-
initial: "",
|
117
|
-
},
|
118
|
-
{
|
119
|
-
type: "text",
|
120
|
-
name: "exercisesNumber",
|
121
|
-
message: "How many steps or exercises do you want? Please provide a number",
|
122
|
-
validate: (value) => {
|
123
|
-
const n = Math.floor(Number(value));
|
124
|
-
return n !== Number.POSITIVE_INFINITY && String(n) === value && n > 0;
|
125
|
-
},
|
126
|
-
},
|
127
|
-
]);
|
128
158
|
const packageContext = `
|
129
159
|
\n
|
130
160
|
The following information comes from user inputs
|
@@ -136,28 +166,34 @@ const handleAILogic = async (tutorialDir, packageInfo) => {
|
|
136
166
|
|
137
167
|
Use it to generate more relevant exercises
|
138
168
|
`;
|
139
|
-
const
|
140
|
-
tutorial_about: aiChoices.tutorialAbout + packageContext,
|
141
|
-
number_of_exercises: aiChoices.exercisesNumber,
|
142
|
-
};
|
143
|
-
console_1.default.info("Creating lessons...");
|
144
|
-
const res = await (0, rigoActions_1.getExercisesNames)(rigoToken, inputs);
|
169
|
+
const { currentSteps } = await initializeInteractiveCreation(rigoToken, packageContext);
|
145
170
|
const exercisesDir = path.join(tutorialDir, "exercises");
|
146
171
|
fs.ensureDirSync(exercisesDir);
|
147
|
-
|
148
|
-
|
172
|
+
console_1.default.info("Creating lessons...");
|
173
|
+
for (const [index, exercise] of currentSteps.entries()) {
|
174
|
+
const { exNumber, exTitle } = getExInfo(exercise);
|
175
|
+
const exerciseDir = path.join(exercisesDir, `${exNumber}-${exTitle}`);
|
149
176
|
fs.ensureDirSync(exerciseDir);
|
150
177
|
}
|
151
|
-
const exercisePromises =
|
152
|
-
const
|
153
|
-
const
|
154
|
-
|
178
|
+
const exercisePromises = currentSteps.map(async (exercise, index) => {
|
179
|
+
const { exNumber, exTitle, kind, description } = getExInfo(exercise);
|
180
|
+
const exerciseDir = path.join(exercisesDir, `${exNumber}-${exTitle}`);
|
181
|
+
const readme = await (0, rigoActions_1.readmeCreator)(rigoToken, {
|
182
|
+
title: `${exNumber} - ${exTitle}`,
|
155
183
|
output_lang: "en",
|
156
|
-
list_of_exercises:
|
157
|
-
tutorial_description:
|
184
|
+
list_of_exercises: currentSteps.join(","),
|
185
|
+
tutorial_description: packageContext,
|
186
|
+
lesson_description: description,
|
187
|
+
kind: kind.toLowerCase(),
|
158
188
|
});
|
159
189
|
const readmeFilename = "README.md";
|
160
190
|
fs.writeFileSync(path.join(exerciseDir, readmeFilename), readme.parsed.content);
|
191
|
+
if (kind.toLowerCase() === "code") {
|
192
|
+
const codeFile = await (0, rigoActions_1.createCodeFile)(rigoToken, {
|
193
|
+
readme: readme.parsed.content,
|
194
|
+
});
|
195
|
+
fs.writeFileSync(path.join(exerciseDir, `app.${codeFile.parsed.extension.replace(".", "")}`), codeFile.parsed.content);
|
196
|
+
}
|
161
197
|
return readme.parsed.content;
|
162
198
|
});
|
163
199
|
let imagesArray = [];
|
package/lib/utils/audit.d.ts
CHANGED
@@ -9,7 +9,7 @@ declare const _default: {
|
|
9
9
|
checkLearnpackClean: (configObj: IConfigObj, errors: IAuditErrors[]) => void;
|
10
10
|
findInFile: (types: string[], content: string) => IFindings;
|
11
11
|
checkUrl: (config: IConfigObj, filePath: string, fileName: string, exercise: IExercise | undefined, errors: IAuditErrors[], warnings: IAuditErrors[], counter: ICounter | undefined) => Promise<boolean>;
|
12
|
-
writeFile: (
|
12
|
+
writeFile: (filePath: string, content: string) => void;
|
13
13
|
showErrors: (errors: IAuditErrors[], counter: ICounter | undefined) => Promise<unknown>;
|
14
14
|
showWarnings: (warnings: IAuditErrors[]) => Promise<unknown>;
|
15
15
|
};
|
package/lib/utils/audit.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
"use strict";
|
2
|
+
/* eslint-disable no-await-in-loop, @typescript-eslint/no-non-null-asserted-optional-chain, no-promise-executor-return */
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
4
|
const console_1 = require("./console");
|
4
5
|
const fs = require("fs");
|
5
|
-
const path = require("path");
|
6
6
|
// eslint-disable-next-line
|
7
7
|
const fetch = require("node-fetch");
|
8
8
|
// eslint-disable-next-line
|
@@ -92,9 +92,34 @@ const findInFile = (types, content) => {
|
|
92
92
|
}
|
93
93
|
return findings;
|
94
94
|
};
|
95
|
-
|
95
|
+
const checkLinkWithRetry = async (url, retries = 3, delay = 1000) => {
|
96
|
+
for (let attempt = 1; attempt <= retries; attempt++) {
|
97
|
+
try {
|
98
|
+
let res = await fetch(url, { method: "HEAD" });
|
99
|
+
if (res.status === 429) {
|
100
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
101
|
+
delay *= 2; // Exponential backoff
|
102
|
+
continue;
|
103
|
+
}
|
104
|
+
if (res.status === 403) {
|
105
|
+
return { isValid: false, status: 403 };
|
106
|
+
}
|
107
|
+
if (!res.ok) {
|
108
|
+
res = await fetch(url, { method: "GET" });
|
109
|
+
if (!res.ok) {
|
110
|
+
return { isValid: false, status: res.status };
|
111
|
+
}
|
112
|
+
}
|
113
|
+
return { isValid: true };
|
114
|
+
}
|
115
|
+
catch (error) {
|
116
|
+
console.debug(`Error checking link ${url}:`, error);
|
117
|
+
return { isValid: false, status: 429 };
|
118
|
+
}
|
119
|
+
}
|
120
|
+
return { isValid: false, status: 429 };
|
121
|
+
};
|
96
122
|
const checkUrl = async (config, filePath, fileName, exercise, errors, warnings, counter) => {
|
97
|
-
var _a, _b, _c, _d;
|
98
123
|
if (!fs.existsSync(filePath))
|
99
124
|
return false;
|
100
125
|
const content = fs.readFileSync(filePath).toString();
|
@@ -109,95 +134,51 @@ const checkUrl = async (config, filePath, fileName, exercise, errors, warnings,
|
|
109
134
|
if (Object.prototype.hasOwnProperty.call(frontmatter.attributes, attribute) &&
|
110
135
|
(attribute === "intro" || attribute === "tutorial")) {
|
111
136
|
counter && counter.links.total++;
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
137
|
+
const url = frontmatter.attributes[attribute];
|
138
|
+
const { isValid, status } = await checkLinkWithRetry(url);
|
139
|
+
if (!isValid) {
|
140
|
+
if (status === 429 || status === 403) {
|
141
|
+
warnings.push({
|
142
|
+
exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
|
143
|
+
msg: `Warning: This link might be temporarily inaccessible (${status}): ${url}`,
|
144
|
+
});
|
145
|
+
}
|
146
|
+
else {
|
118
147
|
counter && counter.links.error++;
|
119
148
|
errors.push({
|
120
149
|
exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
|
121
|
-
msg: `This link is broken
|
150
|
+
msg: `This link is broken: ${url}`,
|
122
151
|
});
|
123
152
|
}
|
124
153
|
}
|
125
|
-
catch (_e) {
|
126
|
-
counter && counter.links.error++;
|
127
|
-
errors.push({
|
128
|
-
exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
|
129
|
-
msg: `This link is broken: ${frontmatter.attributes[attribute]}`,
|
130
|
-
});
|
131
|
-
}
|
132
154
|
}
|
133
155
|
}
|
134
|
-
// Check
|
156
|
+
// Check URLs in README files
|
135
157
|
const findings = findInFile(["relativeImages", "externalImages", "markdownLinks"], content);
|
136
158
|
for (const finding in findings) {
|
137
159
|
if (Object.prototype.hasOwnProperty.call(findings, finding)) {
|
138
160
|
const obj = findings[finding];
|
139
|
-
|
140
|
-
if (finding === "relativeImages" && Object.keys(obj).length > 0) {
|
141
|
-
for (const img in obj) {
|
142
|
-
if (Object.prototype.hasOwnProperty.call(obj, img)) {
|
143
|
-
// Validates if the image is in the assets folder.
|
144
|
-
counter && counter.images.total++;
|
145
|
-
const relativePath = path
|
146
|
-
.relative(exercise ? exercise.path.replace(/\\/gm, "/") : "./", `${(_a = config.config) === null || _a === void 0 ? void 0 : _a.dirPath}/assets/${obj[img].relUrl}`)
|
147
|
-
.replace(/\\/gm, "/");
|
148
|
-
if (relativePath !== obj[img].absUrl.split("?").shift()) {
|
149
|
-
counter && counter.images.error++;
|
150
|
-
errors.push({
|
151
|
-
exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
|
152
|
-
msg: `This relative path (${obj[img].relUrl}) is not pointing to the assets folder.`,
|
153
|
-
});
|
154
|
-
}
|
155
|
-
if (!fs.existsSync(`${(_b = config.config) === null || _b === void 0 ? void 0 : _b.dirPath}/assets/${obj[img].relUrl}`)) {
|
156
|
-
counter && counter.images.error++;
|
157
|
-
errors.push({
|
158
|
-
exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
|
159
|
-
msg: `The file ${obj[img].relUrl} doesn't exist in the assets folder.`,
|
160
|
-
});
|
161
|
-
}
|
162
|
-
}
|
163
|
-
}
|
164
|
-
}
|
165
|
-
else if (finding === "externalImages" && Object.keys(obj).length > 0) {
|
166
|
-
// Valdites all the aboslute path images.
|
161
|
+
if (finding === "externalImages" && Object.keys(obj).length > 0) {
|
167
162
|
for (const img in obj) {
|
168
163
|
if (Object.prototype.hasOwnProperty.call(obj, img)) {
|
169
164
|
counter && counter.images.total++;
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
.
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
}
|
181
|
-
try {
|
182
|
-
// eslint-disable-next-line
|
183
|
-
let res = await fetch(obj[img].absUrl, {
|
184
|
-
method: "HEAD",
|
185
|
-
});
|
186
|
-
if (!res.ok) {
|
165
|
+
const url = obj[img].absUrl;
|
166
|
+
const { isValid, status } = await checkLinkWithRetry(url);
|
167
|
+
if (!isValid) {
|
168
|
+
if (status === 429 || status === 403) {
|
169
|
+
warnings.push({
|
170
|
+
exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
|
171
|
+
msg: `Warning: This image link might be temporarily inaccessible (${status}): ${url}`,
|
172
|
+
});
|
173
|
+
}
|
174
|
+
else {
|
187
175
|
counter && counter.images.error++;
|
188
176
|
errors.push({
|
189
177
|
exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
|
190
|
-
msg: `This link is broken: ${
|
178
|
+
msg: `This image link is broken: ${url}`,
|
191
179
|
});
|
192
180
|
}
|
193
181
|
}
|
194
|
-
catch (_f) {
|
195
|
-
counter && counter.images.error++;
|
196
|
-
errors.push({
|
197
|
-
exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
|
198
|
-
msg: `This link is broken: ${obj[img].absUrl}`,
|
199
|
-
});
|
200
|
-
}
|
201
182
|
}
|
202
183
|
}
|
203
184
|
}
|
@@ -205,27 +186,24 @@ const checkUrl = async (config, filePath, fileName, exercise, errors, warnings,
|
|
205
186
|
for (const link in obj) {
|
206
187
|
if (Object.prototype.hasOwnProperty.call(obj, link)) {
|
207
188
|
counter && counter.links.total++;
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
189
|
+
const url = obj[link].mdUrl;
|
190
|
+
if (!url.includes("twitter")) {
|
191
|
+
const { isValid, status } = await checkLinkWithRetry(url);
|
192
|
+
if (!isValid) {
|
193
|
+
if (status === 429 || status === 403) {
|
194
|
+
warnings.push({
|
195
|
+
exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
|
196
|
+
msg: `Warning: This markdown link might be temporarily inaccessible (${status}): ${url}`,
|
197
|
+
});
|
198
|
+
}
|
199
|
+
else {
|
215
200
|
counter && counter.links.error++;
|
216
201
|
errors.push({
|
217
202
|
exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
|
218
|
-
msg: `This link is broken: ${
|
203
|
+
msg: `This markdown link is broken: ${url}`,
|
219
204
|
});
|
220
205
|
}
|
221
206
|
}
|
222
|
-
catch (_g) {
|
223
|
-
counter && counter.links.error++;
|
224
|
-
errors.push({
|
225
|
-
exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
|
226
|
-
msg: `This link is broken: ${obj[link].mdUrl}`,
|
227
|
-
});
|
228
|
-
}
|
229
207
|
}
|
230
208
|
}
|
231
209
|
}
|
@@ -234,10 +212,10 @@ const checkUrl = async (config, filePath, fileName, exercise, errors, warnings,
|
|
234
212
|
}
|
235
213
|
return true;
|
236
214
|
};
|
237
|
-
// This function writes a
|
238
|
-
const writeFile =
|
215
|
+
// This function writes a file in the given path.
|
216
|
+
const writeFile = (filePath, content) => {
|
239
217
|
try {
|
240
|
-
|
218
|
+
fs.writeFileSync(filePath, content);
|
241
219
|
}
|
242
220
|
catch (error) {
|
243
221
|
if (error)
|
@@ -1,9 +1,10 @@
|
|
1
|
-
export declare const getExercisesNames: (token: string, inputs: object) => Promise<any>;
|
2
1
|
type TCreateReadmeInputs = {
|
3
2
|
title: string;
|
4
3
|
output_lang: string;
|
5
4
|
list_of_exercises: string;
|
6
5
|
tutorial_description: string;
|
6
|
+
include_quiz: string;
|
7
|
+
lesson_description: string;
|
7
8
|
};
|
8
9
|
export declare const createReadme: (token: string, inputs: TCreateReadmeInputs) => Promise<any>;
|
9
10
|
export declare const hasCreatorPermission: (token: string) => Promise<boolean>;
|
@@ -22,4 +23,30 @@ type TGenerateCourseIntroductionInputs = {
|
|
22
23
|
lessons_context: string;
|
23
24
|
};
|
24
25
|
export declare const generateCourseIntroduction: (token: string, inputs: TGenerateCourseIntroductionInputs) => Promise<any>;
|
26
|
+
type TInteractiveCreationInputs = {
|
27
|
+
courseInfo: string;
|
28
|
+
prevInteractions: string;
|
29
|
+
};
|
30
|
+
export declare const interactiveCreation: (token: string, inputs: TInteractiveCreationInputs) => Promise<any>;
|
31
|
+
type TCreateCodeFileInputs = {
|
32
|
+
readme: string;
|
33
|
+
};
|
34
|
+
export declare const createCodeFile: (token: string, inputs: TCreateCodeFileInputs) => Promise<any>;
|
35
|
+
type TCreateCodingReadmeInputs = {
|
36
|
+
tutorial_description: string;
|
37
|
+
list_of_exercises: string;
|
38
|
+
output_lang: string;
|
39
|
+
title: string;
|
40
|
+
lesson_description: string;
|
41
|
+
};
|
42
|
+
export declare const createCodingReadme: (token: string, inputs: TCreateCodingReadmeInputs) => Promise<any>;
|
43
|
+
type TReadmeCreatorInputs = {
|
44
|
+
tutorial_description: string;
|
45
|
+
list_of_exercises: string;
|
46
|
+
output_lang: string;
|
47
|
+
title: string;
|
48
|
+
lesson_description: string;
|
49
|
+
kind: string;
|
50
|
+
};
|
51
|
+
export declare const readmeCreator: (token: string, inputs: TReadmeCreatorInputs) => Promise<any>;
|
25
52
|
export {};
|
package/lib/utils/rigoActions.js
CHANGED
@@ -1,37 +1,29 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.generateCourseIntroduction = exports.translateExercise = exports.generateImage = exports.hasCreatorPermission = exports.createReadme =
|
3
|
+
exports.readmeCreator = exports.createCodingReadme = exports.createCodeFile = exports.interactiveCreation = exports.generateCourseIntroduction = exports.translateExercise = exports.generateImage = exports.hasCreatorPermission = exports.createReadme = void 0;
|
4
4
|
exports.downloadImage = downloadImage;
|
5
5
|
const axios_1 = require("axios");
|
6
6
|
const fs_1 = require("fs");
|
7
7
|
const console_1 = require("../utils/console");
|
8
8
|
const RIGOBOT_HOST = "https://rigobot.herokuapp.com";
|
9
|
-
const getExercisesNames = async (token, inputs) => {
|
10
|
-
const response = await axios_1.default.post(`${RIGOBOT_HOST}/v1/prompting/completion/60/`, {
|
11
|
-
inputs: inputs,
|
12
|
-
include_purpose_objective: false,
|
13
|
-
execute_async: false,
|
14
|
-
}, {
|
15
|
-
headers: {
|
16
|
-
"Content-Type": "application/json",
|
17
|
-
Authorization: "Token " + token,
|
18
|
-
},
|
19
|
-
});
|
20
|
-
return response.data;
|
21
|
-
};
|
22
|
-
exports.getExercisesNames = getExercisesNames;
|
23
9
|
const createReadme = async (token, inputs) => {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
10
|
+
try {
|
11
|
+
const response = await axios_1.default.post(`${RIGOBOT_HOST}/v1/prompting/completion/423/`, {
|
12
|
+
inputs,
|
13
|
+
include_purpose_objective: false,
|
14
|
+
execute_async: false,
|
15
|
+
}, {
|
16
|
+
headers: {
|
17
|
+
"Content-Type": "application/json",
|
18
|
+
Authorization: "Token " + token,
|
19
|
+
},
|
20
|
+
});
|
21
|
+
return response.data;
|
22
|
+
}
|
23
|
+
catch (error) {
|
24
|
+
console.error(error);
|
25
|
+
return null;
|
26
|
+
}
|
35
27
|
};
|
36
28
|
exports.createReadme = createReadme;
|
37
29
|
const hasCreatorPermission = async (token) => {
|
@@ -110,3 +102,65 @@ const generateCourseIntroduction = async (token, inputs) => {
|
|
110
102
|
return response.data;
|
111
103
|
};
|
112
104
|
exports.generateCourseIntroduction = generateCourseIntroduction;
|
105
|
+
const interactiveCreation = async (token, inputs) => {
|
106
|
+
const response = await axios_1.default.post(`${RIGOBOT_HOST}/v1/prompting/completion/390/`, {
|
107
|
+
inputs: inputs,
|
108
|
+
include_purpose_objective: false,
|
109
|
+
execute_async: false,
|
110
|
+
}, {
|
111
|
+
headers: {
|
112
|
+
"Content-Type": "application/json",
|
113
|
+
Authorization: "Token " + token,
|
114
|
+
},
|
115
|
+
});
|
116
|
+
return response.data;
|
117
|
+
};
|
118
|
+
exports.interactiveCreation = interactiveCreation;
|
119
|
+
const createCodeFile = async (token, inputs) => {
|
120
|
+
const response = await axios_1.default.post(`${RIGOBOT_HOST}/v1/prompting/completion/456/`, {
|
121
|
+
inputs: inputs,
|
122
|
+
include_purpose_objective: false,
|
123
|
+
execute_async: false,
|
124
|
+
}, {
|
125
|
+
headers: {
|
126
|
+
"Content-Type": "application/json",
|
127
|
+
Authorization: "Token " + token,
|
128
|
+
},
|
129
|
+
});
|
130
|
+
return response.data;
|
131
|
+
};
|
132
|
+
exports.createCodeFile = createCodeFile;
|
133
|
+
const createCodingReadme = async (token, inputs) => {
|
134
|
+
const response = await axios_1.default.post(`${RIGOBOT_HOST}/v1/prompting/completion/489/`, { inputs, include_purpose_objective: false, execute_async: false }, {
|
135
|
+
headers: {
|
136
|
+
"Content-Type": "application/json",
|
137
|
+
Authorization: "Token " + token,
|
138
|
+
},
|
139
|
+
});
|
140
|
+
return response.data;
|
141
|
+
};
|
142
|
+
exports.createCodingReadme = createCodingReadme;
|
143
|
+
const readmeCreator = async (token, inputs) => {
|
144
|
+
if (inputs.kind === "quiz" || inputs.kind === "read") {
|
145
|
+
const createReadmeInputs = {
|
146
|
+
title: inputs.title,
|
147
|
+
output_lang: inputs.output_lang,
|
148
|
+
list_of_exercises: inputs.list_of_exercises,
|
149
|
+
tutorial_description: inputs.tutorial_description,
|
150
|
+
include_quiz: inputs.kind === "quiz" ? "true" : "false",
|
151
|
+
lesson_description: inputs.lesson_description,
|
152
|
+
};
|
153
|
+
return (0, exports.createReadme)(token, createReadmeInputs);
|
154
|
+
}
|
155
|
+
if (inputs.kind === "code") {
|
156
|
+
return (0, exports.createCodingReadme)(token, {
|
157
|
+
title: inputs.title,
|
158
|
+
output_lang: inputs.output_lang,
|
159
|
+
list_of_exercises: inputs.list_of_exercises,
|
160
|
+
tutorial_description: inputs.tutorial_description,
|
161
|
+
lesson_description: inputs.lesson_description,
|
162
|
+
});
|
163
|
+
}
|
164
|
+
throw new Error("Invalid kind of lesson");
|
165
|
+
};
|
166
|
+
exports.readmeCreator = readmeCreator;
|