@learnpack/learnpack 5.0.27 → 5.0.29
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 +27 -11
- package/lib/commands/breakToken.d.ts +10 -0
- package/lib/commands/breakToken.js +23 -0
- package/lib/commands/init.js +78 -44
- package/lib/commands/publish.js +29 -2
- package/lib/commands/start.js +9 -12
- package/lib/managers/config/index.js +77 -77
- package/lib/managers/server/routes.js +1 -5
- package/lib/managers/session.js +8 -0
- package/lib/models/session.d.ts +1 -0
- package/lib/utils/api.d.ts +11 -1
- package/lib/utils/api.js +49 -11
- package/lib/utils/creatorUtilities.d.ts +7 -2
- package/lib/utils/creatorUtilities.js +88 -6
- package/lib/utils/rigoActions.d.ts +6 -0
- package/lib/utils/rigoActions.js +16 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/src/commands/breakToken.ts +36 -0
- package/src/commands/init.ts +113 -55
- package/src/commands/publish.ts +34 -2
- package/src/commands/start.ts +10 -14
- package/src/managers/config/index.ts +715 -715
- package/src/managers/server/routes.ts +1 -3
- package/src/managers/session.ts +11 -0
- package/src/models/session.ts +1 -0
- package/src/utils/api.ts +60 -12
- package/src/utils/creatorUtilities.ts +101 -7
- package/src/utils/rigoActions.ts +30 -0
@@ -423,66 +423,66 @@ function deepMerge(...sources) {
|
|
423
423
|
return acc;
|
424
424
|
}
|
425
425
|
const buildAgentWarning = (current, suggested) => {
|
426
|
-
const message = `# Agent mismatch!\n
|
427
|
-
|
428
|
-
In LearnPack, the agent is in charge of running the LearnPack interface.
|
429
|
-
|
430
|
-
You're currently using LearnPack through \`${current}\` but the suggested agent is \`${suggested}\`.
|
431
|
-
|
432
|
-
We recommend strongly recommend changing your agent.
|
433
|
-
|
434
|
-
${stepsToChangeAgent(suggested)}
|
426
|
+
const message = `# Agent mismatch!\n
|
427
|
+
|
428
|
+
In LearnPack, the agent is in charge of running the LearnPack interface.
|
429
|
+
|
430
|
+
You're currently using LearnPack through \`${current}\` but the suggested agent is \`${suggested}\`.
|
431
|
+
|
432
|
+
We recommend strongly recommend changing your agent.
|
433
|
+
|
434
|
+
${stepsToChangeAgent(suggested)}
|
435
435
|
`;
|
436
436
|
return message;
|
437
437
|
};
|
438
438
|
const stepsToChangeAgent = (agent) => {
|
439
439
|
if (agent === "vscode") {
|
440
|
-
return `
|
441
|
-
# Steps to Change Agent to VSCode
|
442
|
-
|
443
|
-
1. **Install VSCode**:
|
444
|
-
- Visit the [VSCode website](https://code.visualstudio.com/Download) and download the latest version.
|
445
|
-
- Follow the installation instructions for your operating system.
|
446
|
-
|
447
|
-
2. **Install LearnPack VSCode Extension**:
|
448
|
-
- Open VSCode.
|
449
|
-
- Go to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window or by pressing \`Ctrl+Shift+X\`.
|
450
|
-
- Search for "LearnPack" and click "Install".
|
451
|
-
- If the extension is already installed but disabled, enable it.
|
452
|
-
|
453
|
-
3. **Run LearnPack in VSCode**:
|
454
|
-
- Open your terminal in VSCode.
|
455
|
-
- Navigate to your LearnPack project directory.
|
456
|
-
- Run the following command:
|
457
|
-
\`\`\`sh
|
458
|
-
learnpack start
|
459
|
-
\`\`\`
|
460
|
-
|
461
|
-
We strongly recommend using VSCode for a better learning experience.
|
440
|
+
return `
|
441
|
+
# Steps to Change Agent to VSCode
|
442
|
+
|
443
|
+
1. **Install VSCode**:
|
444
|
+
- Visit the [VSCode website](https://code.visualstudio.com/Download) and download the latest version.
|
445
|
+
- Follow the installation instructions for your operating system.
|
446
|
+
|
447
|
+
2. **Install LearnPack VSCode Extension**:
|
448
|
+
- Open VSCode.
|
449
|
+
- Go to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window or by pressing \`Ctrl+Shift+X\`.
|
450
|
+
- Search for "LearnPack" and click "Install".
|
451
|
+
- If the extension is already installed but disabled, enable it.
|
452
|
+
|
453
|
+
3. **Run LearnPack in VSCode**:
|
454
|
+
- Open your terminal in VSCode.
|
455
|
+
- Navigate to your LearnPack project directory.
|
456
|
+
- Run the following command:
|
457
|
+
\`\`\`sh
|
458
|
+
learnpack start
|
459
|
+
\`\`\`
|
460
|
+
|
461
|
+
We strongly recommend using VSCode for a better learning experience.
|
462
462
|
`;
|
463
463
|
}
|
464
464
|
if (agent === "os") {
|
465
|
-
return `
|
466
|
-
# Steps to Change Agent to OS
|
467
|
-
|
468
|
-
This learning package was designed to run outside of VSCode. We strongly recommend closing VSCode and running the package independently.
|
469
|
-
|
470
|
-
1. **Close VSCode**:
|
471
|
-
- Save your work and close the VSCode application.
|
472
|
-
|
473
|
-
2. **Open a New Terminal**:
|
474
|
-
- Open a terminal or command prompt on your operating system.
|
475
|
-
|
476
|
-
3. **Navigate to Your LearnPack Project Directory**:
|
477
|
-
- Use the \`cd\` command to navigate to the directory where your LearnPack project is located.
|
478
|
-
|
479
|
-
4. **Run LearnPack**:
|
480
|
-
- Run the following command to start LearnPack:
|
481
|
-
\`\`\`sh
|
482
|
-
learnpack start
|
483
|
-
\`\`\`
|
484
|
-
|
485
|
-
We strongly recommend running the package independently for a better learning experience.
|
465
|
+
return `
|
466
|
+
# Steps to Change Agent to OS
|
467
|
+
|
468
|
+
This learning package was designed to run outside of VSCode. We strongly recommend closing VSCode and running the package independently.
|
469
|
+
|
470
|
+
1. **Close VSCode**:
|
471
|
+
- Save your work and close the VSCode application.
|
472
|
+
|
473
|
+
2. **Open a New Terminal**:
|
474
|
+
- Open a terminal or command prompt on your operating system.
|
475
|
+
|
476
|
+
3. **Navigate to Your LearnPack Project Directory**:
|
477
|
+
- Use the \`cd\` command to navigate to the directory where your LearnPack project is located.
|
478
|
+
|
479
|
+
4. **Run LearnPack**:
|
480
|
+
- Run the following command to start LearnPack:
|
481
|
+
\`\`\`sh
|
482
|
+
learnpack start
|
483
|
+
\`\`\`
|
484
|
+
|
485
|
+
We strongly recommend running the package independently for a better learning experience.
|
486
486
|
`;
|
487
487
|
}
|
488
488
|
return "";
|
@@ -508,31 +508,31 @@ const isExtensionInstalled = (extensionName) => {
|
|
508
508
|
const result = shell.exec("code --list-extensions", { silent: true });
|
509
509
|
return result.stdout.split("\n").includes(extensionName);
|
510
510
|
};
|
511
|
-
const EXTENSION_INSTALLATION_STEPS = `
|
512
|
-
# Steps to Install LearnPack VSCode Extension
|
513
|
-
|
514
|
-
1. **Open VSCode**:
|
515
|
-
- Launch the Visual Studio Code application on your computer.
|
516
|
-
|
517
|
-
2. **Go to Extensions View**:
|
518
|
-
- Click on the Extensions icon in the Activity Bar on the side of the window.
|
519
|
-
- Alternatively, you can open the Extensions view by pressing \`Ctrl+Shift+X\`.
|
520
|
-
|
521
|
-
3. **Search for LearnPack**:
|
522
|
-
- In the Extensions view, type "LearnPack" into the search bar.
|
523
|
-
|
524
|
-
4. **Install the Extension**:
|
525
|
-
- Find the "LearnPack" extension in the search results and click the "Install" button.
|
526
|
-
- If the extension is already installed but disabled, click the "Enable" button.
|
527
|
-
|
528
|
-
5. **Verify Installation**:
|
529
|
-
- Once installed, you can verify the installation by running the following command in the terminal:
|
530
|
-
\`\`\`sh
|
531
|
-
code --list-extensions | grep learn-pack.learnpack-vscode
|
532
|
-
\`\`\`
|
533
|
-
- If the extension is listed, it means the installation was successful.
|
534
|
-
|
535
|
-
We strongly recommend using the LearnPack extension in VSCode for a better learning experience.
|
511
|
+
const EXTENSION_INSTALLATION_STEPS = `
|
512
|
+
# Steps to Install LearnPack VSCode Extension
|
513
|
+
|
514
|
+
1. **Open VSCode**:
|
515
|
+
- Launch the Visual Studio Code application on your computer.
|
516
|
+
|
517
|
+
2. **Go to Extensions View**:
|
518
|
+
- Click on the Extensions icon in the Activity Bar on the side of the window.
|
519
|
+
- Alternatively, you can open the Extensions view by pressing \`Ctrl+Shift+X\`.
|
520
|
+
|
521
|
+
3. **Search for LearnPack**:
|
522
|
+
- In the Extensions view, type "LearnPack" into the search bar.
|
523
|
+
|
524
|
+
4. **Install the Extension**:
|
525
|
+
- Find the "LearnPack" extension in the search results and click the "Install" button.
|
526
|
+
- If the extension is already installed but disabled, click the "Enable" button.
|
527
|
+
|
528
|
+
5. **Verify Installation**:
|
529
|
+
- Once installed, you can verify the installation by running the following command in the terminal:
|
530
|
+
\`\`\`sh
|
531
|
+
code --list-extensions | grep learn-pack.learnpack-vscode
|
532
|
+
\`\`\`
|
533
|
+
- If the extension is listed, it means the installation was successful.
|
534
|
+
|
535
|
+
We strongly recommend using the LearnPack extension in VSCode for a better learning experience.
|
536
536
|
`;
|
537
537
|
/**
|
538
538
|
* Installs the LearnPack VSCode extension if the 'code' command is available.
|
@@ -11,7 +11,6 @@ const fileQueue_1 = require("../../utils/fileQueue");
|
|
11
11
|
const exercise_1 = require("../config/exercise");
|
12
12
|
const session_1 = require("../../managers/session");
|
13
13
|
const telemetry_1 = require("../telemetry");
|
14
|
-
const osOperations_1 = require("../../utils/osOperations");
|
15
14
|
const withHandler = (func) => (req, res) => {
|
16
15
|
try {
|
17
16
|
func(req, res);
|
@@ -200,10 +199,7 @@ async function default_1(app, configObject, configManager) {
|
|
200
199
|
if (exercise.position) {
|
201
200
|
telemetry_1.default.registerStepEvent(exercise.position, "open_step", {});
|
202
201
|
}
|
203
|
-
if (((_a = configObject.config) === null || _a === void 0 ? void 0 : _a.editor.agent)
|
204
|
-
osOperations_1.eventManager.enqueue(dispatcher.events.START_EXERCISE, exercise);
|
205
|
-
}
|
206
|
-
else {
|
202
|
+
if (((_a = configObject.config) === null || _a === void 0 ? void 0 : _a.editor.agent) !== "os") {
|
207
203
|
dispatcher.enqueue(dispatcher.events.START_EXERCISE, req.params.slug);
|
208
204
|
}
|
209
205
|
const entries = new Set(Object.keys(config === null || config === void 0 ? void 0 : config.entries).map(lang => config === null || config === void 0 ? void 0 : config.entries[lang]));
|
package/lib/managers/session.js
CHANGED
@@ -138,5 +138,13 @@ const Session = {
|
|
138
138
|
this.token = null;
|
139
139
|
console_1.default.success("You have logged out");
|
140
140
|
},
|
141
|
+
breakToken: async function () {
|
142
|
+
const payload = await this.getPayload();
|
143
|
+
if (payload) {
|
144
|
+
this.token = "asdasdasdasd";
|
145
|
+
await storage.setItem("bc-payload", Object.assign(Object.assign({}, payload), { token: "asdasdsad" }));
|
146
|
+
console_1.default.success("Token broken successfully");
|
147
|
+
}
|
148
|
+
},
|
141
149
|
};
|
142
150
|
exports.default = Session;
|
package/lib/models/session.d.ts
CHANGED
package/lib/utils/api.d.ts
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
type TConsumableSlug = "ai-conversation-message" | "ai-compilation" | "ai-tutorial-generation" | "ai-generation";
|
2
2
|
export declare const countConsumables: (consumables: any, consumableSlug?: TConsumableSlug) => any;
|
3
|
-
export declare const
|
3
|
+
export declare const getConsumable: (token: string, consumableSlug?: TConsumableSlug) => Promise<any>;
|
4
|
+
export interface TAcademy {
|
5
|
+
id: number;
|
6
|
+
name: string;
|
7
|
+
slug: string;
|
8
|
+
timezone: string;
|
9
|
+
}
|
10
|
+
export declare const listUserAcademies: (breathecodeToken: string) => Promise<TAcademy[]>;
|
11
|
+
export declare const validateToken: (token: string) => Promise<any>;
|
4
12
|
declare const _default: {
|
5
13
|
login: (identification: string, password: string) => Promise<any>;
|
6
14
|
publish: (config: any) => Promise<any>;
|
@@ -13,5 +21,7 @@ declare const _default: {
|
|
13
21
|
}) => Promise<any>;
|
14
22
|
sendBatchTelemetry: (url: string, body: any) => Promise<void>;
|
15
23
|
sendStreamTelemetry: (url: string, body: object) => Promise<void>;
|
24
|
+
listUserAcademies: (breathecodeToken: string) => Promise<TAcademy[]>;
|
25
|
+
validateToken: (token: string) => Promise<any>;
|
16
26
|
};
|
17
27
|
export default _default;
|
package/lib/utils/api.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.validateToken = exports.listUserAcademies = exports.getConsumable = exports.countConsumables = void 0;
|
4
4
|
const console_1 = require("../utils/console");
|
5
5
|
const storage = require("node-persist");
|
6
6
|
const cli_ux_1 = require("cli-ux");
|
@@ -63,13 +63,11 @@ const login = async (identification, password) => {
|
|
63
63
|
cli_ux_1.default.action.start(`Looking for credentials with ${identification}`);
|
64
64
|
await cli_ux_1.default.wait(1000);
|
65
65
|
const url = `${HOST}/v1/auth/login/`;
|
66
|
-
const
|
67
|
-
|
68
|
-
|
69
|
-
password: password,
|
70
|
-
}),
|
71
|
-
method: "post",
|
66
|
+
const res = await axios_1.default.post(url, {
|
67
|
+
email: identification,
|
68
|
+
password: password,
|
72
69
|
});
|
70
|
+
const data = res.data;
|
73
71
|
cli_ux_1.default.action.stop("ready");
|
74
72
|
let rigoPayload = null;
|
75
73
|
try {
|
@@ -258,22 +256,60 @@ const countConsumables = (consumables, consumableSlug = "ai-tutorial-generation"
|
|
258
256
|
return consumable ? consumable.balance.unit : 0;
|
259
257
|
};
|
260
258
|
exports.countConsumables = countConsumables;
|
261
|
-
const
|
259
|
+
const getConsumable = async (token, consumableSlug = "ai-generation") => {
|
262
260
|
const url = `${HOST}/v1/payments/me/service/consumable?virtual=true`;
|
263
261
|
const headers = {
|
264
262
|
Authorization: `Token ${token}`,
|
265
263
|
};
|
266
264
|
try {
|
267
265
|
const response = await axios_1.default.get(url, { headers });
|
268
|
-
const
|
269
|
-
return {
|
266
|
+
const count = (0, exports.countConsumables)(response.data, consumableSlug);
|
267
|
+
return { count };
|
270
268
|
}
|
271
269
|
catch (error) {
|
272
270
|
console.error("Error fetching consumables:", error);
|
273
271
|
throw error;
|
274
272
|
}
|
275
273
|
};
|
276
|
-
exports.
|
274
|
+
exports.getConsumable = getConsumable;
|
275
|
+
const listUserAcademies = async (breathecodeToken) => {
|
276
|
+
const url = "https://breathecode.herokuapp.com/v1/auth/user/me";
|
277
|
+
try {
|
278
|
+
const response = await axios_1.default.get(url, {
|
279
|
+
headers: {
|
280
|
+
Authorization: `Token ${breathecodeToken}`,
|
281
|
+
},
|
282
|
+
});
|
283
|
+
const data = response.data;
|
284
|
+
const academiesMap = new Map();
|
285
|
+
for (const role of data.roles) {
|
286
|
+
const academy = role.academy;
|
287
|
+
if (!academiesMap.has(academy.id)) {
|
288
|
+
academiesMap.set(academy.id, academy);
|
289
|
+
}
|
290
|
+
}
|
291
|
+
return [...academiesMap.values()];
|
292
|
+
}
|
293
|
+
catch (error) {
|
294
|
+
console.error("Failed to fetch user academies:", error);
|
295
|
+
return [];
|
296
|
+
}
|
297
|
+
};
|
298
|
+
exports.listUserAcademies = listUserAcademies;
|
299
|
+
const validateToken = async (token) => {
|
300
|
+
const url = "https://breathecode.herokuapp.com/v1/auth/user/me";
|
301
|
+
const headers = {
|
302
|
+
Authorization: `Token ${token}`,
|
303
|
+
};
|
304
|
+
try {
|
305
|
+
const response = await axios_1.default.get(url, { headers });
|
306
|
+
return response.data;
|
307
|
+
}
|
308
|
+
catch (_a) {
|
309
|
+
return false;
|
310
|
+
}
|
311
|
+
};
|
312
|
+
exports.validateToken = validateToken;
|
277
313
|
exports.default = {
|
278
314
|
login,
|
279
315
|
publish,
|
@@ -283,4 +319,6 @@ exports.default = {
|
|
283
319
|
getAllPackages,
|
284
320
|
sendBatchTelemetry,
|
285
321
|
sendStreamTelemetry,
|
322
|
+
listUserAcademies: exports.listUserAcademies,
|
323
|
+
validateToken: exports.validateToken,
|
286
324
|
};
|
@@ -14,9 +14,11 @@ export type PackageInfo = {
|
|
14
14
|
us: string;
|
15
15
|
};
|
16
16
|
};
|
17
|
-
export declare function checkReadingTime(markdown: string, wordsPerMinute?: number): {
|
17
|
+
export declare function checkReadingTime(markdown: string, wordsPerMinute?: number, maxMinutes?: number): {
|
18
18
|
newMarkdown: string;
|
19
19
|
exceedsThreshold: boolean;
|
20
|
+
minutes: number;
|
21
|
+
body: string;
|
20
22
|
};
|
21
23
|
export declare const getExInfo: (title: string) => {
|
22
24
|
exNumber: string;
|
@@ -31,7 +33,7 @@ export declare function extractImagesFromMarkdown(markdown: string): {
|
|
31
33
|
export declare function getFilenameFromUrl(url: string): string;
|
32
34
|
export declare const makePackageInfo: (choices: any) => {
|
33
35
|
grading: any;
|
34
|
-
difficulty:
|
36
|
+
difficulty: string;
|
35
37
|
duration: number;
|
36
38
|
description: {
|
37
39
|
us: any;
|
@@ -41,4 +43,7 @@ export declare const makePackageInfo: (choices: any) => {
|
|
41
43
|
};
|
42
44
|
slug: any;
|
43
45
|
};
|
46
|
+
export declare function estimateDuration(listOfSteps: string[]): number;
|
47
|
+
export declare function createFileOnDesktop(): Promise<void>;
|
48
|
+
export declare function getContentIndex(): string;
|
44
49
|
export {};
|
@@ -4,9 +4,17 @@ exports.makePackageInfo = exports.getExInfo = exports.estimateReadingTime = void
|
|
4
4
|
exports.checkReadingTime = checkReadingTime;
|
5
5
|
exports.extractImagesFromMarkdown = extractImagesFromMarkdown;
|
6
6
|
exports.getFilenameFromUrl = getFilenameFromUrl;
|
7
|
+
exports.estimateDuration = estimateDuration;
|
8
|
+
exports.createFileOnDesktop = createFileOnDesktop;
|
9
|
+
exports.getContentIndex = getContentIndex;
|
7
10
|
// eslint-disable-next-line
|
8
11
|
const frontMatter = require("front-matter");
|
9
12
|
const path = require("path");
|
13
|
+
const fs = require("fs");
|
14
|
+
const os_1 = require("os");
|
15
|
+
const path_1 = require("path");
|
16
|
+
const child_process_1 = require("child_process");
|
17
|
+
const util_1 = require("util");
|
10
18
|
const yaml = require("js-yaml");
|
11
19
|
const estimateReadingTime = (text, wordsPerMinute = 150) => {
|
12
20
|
const words = text.trim().split(/\s+/).length;
|
@@ -30,7 +38,7 @@ const estimateReadingTime = (text, wordsPerMinute = 150) => {
|
|
30
38
|
};
|
31
39
|
};
|
32
40
|
exports.estimateReadingTime = estimateReadingTime;
|
33
|
-
function checkReadingTime(markdown, wordsPerMinute =
|
41
|
+
function checkReadingTime(markdown, wordsPerMinute = 200, maxMinutes = 1) {
|
34
42
|
const parsed = frontMatter(markdown);
|
35
43
|
const readingTime = (0, exports.estimateReadingTime)(parsed.body, wordsPerMinute);
|
36
44
|
let attributes = parsed.attributes ? parsed.attributes : {};
|
@@ -38,13 +46,25 @@ function checkReadingTime(markdown, wordsPerMinute = 150) {
|
|
38
46
|
attributes = {};
|
39
47
|
}
|
40
48
|
const updatedAttributes = Object.assign(Object.assign({}, attributes), { readingTime });
|
41
|
-
|
42
|
-
|
49
|
+
let yamlFrontMatter = "";
|
50
|
+
try {
|
51
|
+
yamlFrontMatter = yaml.dump(updatedAttributes).trim();
|
52
|
+
}
|
53
|
+
catch (_a) {
|
54
|
+
return {
|
55
|
+
newMarkdown: "",
|
56
|
+
exceedsThreshold: false,
|
57
|
+
minutes: 0,
|
58
|
+
body: "",
|
59
|
+
};
|
60
|
+
}
|
43
61
|
// Reconstruct the markdown with the front matter
|
44
62
|
const newMarkdown = `---\n${yamlFrontMatter}\n---\n\n${parsed.body}`;
|
45
63
|
return {
|
46
64
|
newMarkdown,
|
47
|
-
exceedsThreshold: readingTime.minutes >
|
65
|
+
exceedsThreshold: readingTime.minutes > maxMinutes,
|
66
|
+
minutes: readingTime.minutes,
|
67
|
+
body: parsed.body,
|
48
68
|
};
|
49
69
|
}
|
50
70
|
const slugify = (text) => {
|
@@ -93,8 +113,8 @@ function getFilenameFromUrl(url) {
|
|
93
113
|
const makePackageInfo = (choices) => {
|
94
114
|
const packageInfo = {
|
95
115
|
grading: choices.grading,
|
96
|
-
difficulty:
|
97
|
-
duration:
|
116
|
+
difficulty: "beginner",
|
117
|
+
duration: 5,
|
98
118
|
description: {
|
99
119
|
us: choices.description,
|
100
120
|
},
|
@@ -109,3 +129,65 @@ const makePackageInfo = (choices) => {
|
|
109
129
|
return packageInfo;
|
110
130
|
};
|
111
131
|
exports.makePackageInfo = makePackageInfo;
|
132
|
+
function estimateDuration(listOfSteps) {
|
133
|
+
let duration = 0;
|
134
|
+
for (const step of listOfSteps) {
|
135
|
+
if (step.includes("[READ:")) {
|
136
|
+
duration += 1;
|
137
|
+
}
|
138
|
+
else if (step.includes("[QUIZ:")) {
|
139
|
+
duration += 2;
|
140
|
+
}
|
141
|
+
else if (step.includes("[CODE:")) {
|
142
|
+
duration += 3;
|
143
|
+
}
|
144
|
+
}
|
145
|
+
return duration;
|
146
|
+
}
|
147
|
+
const writeFilePromise = (0, util_1.promisify)(fs.writeFile);
|
148
|
+
const execPromise = (0, util_1.promisify)(child_process_1.exec);
|
149
|
+
const example_content = `
|
150
|
+
00.1 - Introduction to AI [READ: Small introduction to important concepts such as AI, machine learning, and their applications]
|
151
|
+
01.1 - Introduction to Machine Learning [READ: Small introduction to important concepts such as AI, machine learning, and their applications]
|
152
|
+
01.2 - Introduction to Deep Learning [QUIZ: Small introduction to important concepts such as AI, machine learning, and their applications]
|
153
|
+
02.1 - Test your knowledge [CODE: Code problem to solve]
|
154
|
+
`;
|
155
|
+
async function createFileOnDesktop() {
|
156
|
+
try {
|
157
|
+
const desktopPath = (0, path_1.join)((0, os_1.homedir)(), "Desktop");
|
158
|
+
const filePath = (0, path_1.join)(desktopPath, "content_index.txt");
|
159
|
+
const content = example_content.trim();
|
160
|
+
await writeFilePromise(filePath, content);
|
161
|
+
console.log(`File created successfully at: ${filePath}`);
|
162
|
+
await openFile(filePath);
|
163
|
+
}
|
164
|
+
catch (error) {
|
165
|
+
console.error("Error:", error);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
async function openFile(filePath) {
|
169
|
+
const platform = process.platform;
|
170
|
+
let command;
|
171
|
+
if (platform === "win32") {
|
172
|
+
command = `start "" "${filePath}"`;
|
173
|
+
}
|
174
|
+
else if (platform === "darwin") {
|
175
|
+
command = `open "${filePath}"`;
|
176
|
+
}
|
177
|
+
else {
|
178
|
+
command = `xdg-open "${filePath}"`;
|
179
|
+
}
|
180
|
+
try {
|
181
|
+
await execPromise(command);
|
182
|
+
console.log("File opened successfully.");
|
183
|
+
}
|
184
|
+
catch (error) {
|
185
|
+
console.error("Error opening the file:", error);
|
186
|
+
}
|
187
|
+
}
|
188
|
+
function getContentIndex() {
|
189
|
+
const desktopPath = (0, path_1.join)((0, os_1.homedir)(), "Desktop");
|
190
|
+
const filePath = (0, path_1.join)(desktopPath, "content_index.txt");
|
191
|
+
const content = fs.readFileSync(filePath, "utf8");
|
192
|
+
return content;
|
193
|
+
}
|
@@ -52,4 +52,10 @@ type TReadmeCreatorInputs = {
|
|
52
52
|
};
|
53
53
|
export declare const readmeCreator: (token: string, inputs: TReadmeCreatorInputs) => Promise<any>;
|
54
54
|
export declare function createPreviewReadme(tutorialDir: string, packageInfo: PackageInfo, rigoToken: string, readmeContents: string[]): Promise<void>;
|
55
|
+
type TReduceReadmeInputs = {
|
56
|
+
lesson: string;
|
57
|
+
number_of_words: string;
|
58
|
+
expected_number_words: string;
|
59
|
+
};
|
60
|
+
export declare function reduceReadme(rigoToken: string, inputs: TReduceReadmeInputs): Promise<any>;
|
55
61
|
export {};
|
package/lib/utils/rigoActions.js
CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
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
|
exports.createPreviewReadme = createPreviewReadme;
|
6
|
+
exports.reduceReadme = reduceReadme;
|
6
7
|
const axios_1 = require("axios");
|
7
8
|
const fs_1 = require("fs");
|
8
9
|
const console_1 = require("../utils/console");
|
@@ -175,3 +176,18 @@ async function createPreviewReadme(tutorialDir, packageInfo, rigoToken, readmeCo
|
|
175
176
|
});
|
176
177
|
fs.writeFileSync(path.join(tutorialDir, readmeFilename), readmeContent.answer);
|
177
178
|
}
|
179
|
+
async function reduceReadme(rigoToken, inputs) {
|
180
|
+
try {
|
181
|
+
const response = await axios_1.default.post(`${RIGOBOT_HOST}/v1/prompting/completion/588/`, { inputs, include_purpose_objective: false, execute_async: false }, {
|
182
|
+
headers: {
|
183
|
+
"Content-Type": "application/json",
|
184
|
+
Authorization: "Token " + rigoToken,
|
185
|
+
},
|
186
|
+
});
|
187
|
+
return response.data;
|
188
|
+
}
|
189
|
+
catch (error) {
|
190
|
+
console_1.default.debug(error);
|
191
|
+
return null;
|
192
|
+
}
|
193
|
+
}
|
package/oclif.manifest.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":"5.0.
|
1
|
+
{"version":"5.0.29","commands":{"audit":{"id":"audit","description":"learnpack audit is the command in charge of creating an auditory of the repository\n...\nlearnpack audit checks for the following information in a repository:\n 1. The configuration object has slug, repository and description. (Error)\n 2. The command learnpack clean has been run. (Error)\n 3. If a markdown or test file doesn't have any content. (Error)\n 4. The links are accessing to valid servers. (Error)\n 5. The relative images are working (If they have the shortest path to the image or if the images exists in the assets). (Error)\n 6. The external images are working (If they are pointing to a valid server). (Error)\n 7. The exercises directory names are valid. (Error)\n 8. If an exercise doesn't have a README file. (Error)\n 9. The exercises array (Of the config file) has content. (Error)\n 10. The exercses have the same translations. (Warning)\n 11. The .gitignore file exists. (Warning)\n 12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[]},"breakToken":{"id":"breakToken","description":"Break the token","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"grading":{"name":"grading","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"clean":{"id":"clean","description":"Clean the configuration object\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[]},"download":{"id":"download","description":"Describe the command here\n...\nExtra documentation goes here\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"init":{"id":"init","description":"Create a new learning package: Book, Tutorial or Exercise","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"grading":{"name":"grading","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"login":{"id":"login","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"logout":{"id":"logout","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"publish":{"id":"publish","description":"Builds the project by copying necessary files and directories into a zip file","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"start":{"id":"start","description":"Runs a small server with all the exercise instructions","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"port":{"name":"port","type":"option","char":"p","description":"server port"},"host":{"name":"host","type":"option","char":"h","description":"server host"},"disableGrading":{"name":"disableGrading","type":"boolean","char":"D","description":"disble grading functionality","allowNo":false},"watch":{"name":"watch","type":"boolean","char":"w","description":"Watch for file changes","allowNo":false},"editor":{"name":"editor","type":"option","char":"e","description":"[preview, extension]","options":["extension","preview"]},"version":{"name":"version","type":"option","char":"v","description":"E.g: 1.0.1"},"grading":{"name":"grading","type":"option","char":"g","description":"[isolated, incremental]","options":["isolated","incremental"]},"debug":{"name":"debug","type":"boolean","char":"d","description":"debugger mode for more verbage","allowNo":false}},"args":[]},"test":{"id":"test","description":"Test exercises","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false}},"args":[{"name":"exerciseSlug","description":"The name of the exercise to test","required":false,"hidden":false}]},"translate":{"id":"translate","description":"List all the lessons, the user is able of select many of them to translate to the given languages","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false}},"args":[]}}}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@learnpack/learnpack",
|
3
3
|
"description": "Seamlessly build, sell and/or take interactive & auto-graded tutorials, start learning now or build a new tutorial to your audience.",
|
4
|
-
"version": "5.0.
|
4
|
+
"version": "5.0.29",
|
5
5
|
"author": "Alejandro Sanchez @alesanchezr",
|
6
6
|
"contributors": [
|
7
7
|
{
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { flags } from "@oclif/command"
|
2
|
+
import BaseCommand from "../utils/BaseCommand"
|
3
|
+
// eslint-disable-next-line
|
4
|
+
import * as fs from "fs-extra"
|
5
|
+
import Console from "../utils/console"
|
6
|
+
|
7
|
+
import SessionManager from "../managers/session"
|
8
|
+
import { createFileOnDesktop, getContentIndex } from "../utils/creatorUtilities"
|
9
|
+
|
10
|
+
class BreakTokenCommand extends BaseCommand {
|
11
|
+
static description = "Break the token"
|
12
|
+
|
13
|
+
static flags = {
|
14
|
+
...BaseCommand.flags,
|
15
|
+
grading: flags.help({ char: "h" }),
|
16
|
+
}
|
17
|
+
|
18
|
+
async run() {
|
19
|
+
const { flags } = this.parse(BreakTokenCommand)
|
20
|
+
|
21
|
+
// await SessionManager.breakToken()
|
22
|
+
await createFileOnDesktop()
|
23
|
+
Console.info(
|
24
|
+
"File created on desktop, please make the necessary changes and continue when ready"
|
25
|
+
)
|
26
|
+
|
27
|
+
// Wait for user to press enter
|
28
|
+
process.stdin.once("data", () => {
|
29
|
+
Console.info("File content:")
|
30
|
+
Console.info(getContentIndex())
|
31
|
+
process.exit(0)
|
32
|
+
})
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
export default BreakTokenCommand
|