@learnpack/learnpack 5.0.26 → 5.0.28
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 +15 -0
- package/lib/commands/init.js +64 -118
- package/lib/commands/publish.js +29 -2
- 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 +44 -0
- package/lib/utils/creatorUtilities.js +111 -0
- package/lib/utils/rigoActions.d.ts +3 -0
- package/lib/utils/rigoActions.js +11 -0
- package/oclif.manifest.json +1 -1
- package/package.json +3 -1
- package/src/commands/breakToken.ts +25 -0
- package/src/commands/init.ts +108 -179
- package/src/commands/publish.ts +34 -2
- 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 +147 -0
- package/src/utils/rigoActions.ts +22 -4
@@ -0,0 +1,111 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.makePackageInfo = exports.getExInfo = exports.estimateReadingTime = void 0;
|
4
|
+
exports.checkReadingTime = checkReadingTime;
|
5
|
+
exports.extractImagesFromMarkdown = extractImagesFromMarkdown;
|
6
|
+
exports.getFilenameFromUrl = getFilenameFromUrl;
|
7
|
+
// eslint-disable-next-line
|
8
|
+
const frontMatter = require("front-matter");
|
9
|
+
const path = require("path");
|
10
|
+
const yaml = require("js-yaml");
|
11
|
+
const estimateReadingTime = (text, wordsPerMinute = 150) => {
|
12
|
+
const words = text.trim().split(/\s+/).length;
|
13
|
+
const minutes = words / wordsPerMinute;
|
14
|
+
if (minutes < 1) {
|
15
|
+
if (words === 0)
|
16
|
+
return {
|
17
|
+
minutes: 1,
|
18
|
+
words,
|
19
|
+
};
|
20
|
+
}
|
21
|
+
else {
|
22
|
+
return {
|
23
|
+
minutes,
|
24
|
+
words,
|
25
|
+
};
|
26
|
+
}
|
27
|
+
return {
|
28
|
+
minutes: 1,
|
29
|
+
words,
|
30
|
+
};
|
31
|
+
};
|
32
|
+
exports.estimateReadingTime = estimateReadingTime;
|
33
|
+
function checkReadingTime(markdown, wordsPerMinute = 150) {
|
34
|
+
const parsed = frontMatter(markdown);
|
35
|
+
const readingTime = (0, exports.estimateReadingTime)(parsed.body, wordsPerMinute);
|
36
|
+
let attributes = parsed.attributes ? parsed.attributes : {};
|
37
|
+
if (typeof parsed.attributes !== "object") {
|
38
|
+
attributes = {};
|
39
|
+
}
|
40
|
+
const updatedAttributes = Object.assign(Object.assign({}, attributes), { readingTime });
|
41
|
+
// Convert the front matter back to a proper YAML string
|
42
|
+
const yamlFrontMatter = yaml.dump(updatedAttributes).trim();
|
43
|
+
// Reconstruct the markdown with the front matter
|
44
|
+
const newMarkdown = `---\n${yamlFrontMatter}\n---\n\n${parsed.body}`;
|
45
|
+
return {
|
46
|
+
newMarkdown,
|
47
|
+
exceedsThreshold: readingTime.minutes > wordsPerMinute,
|
48
|
+
};
|
49
|
+
}
|
50
|
+
const slugify = (text) => {
|
51
|
+
return text
|
52
|
+
.toString()
|
53
|
+
.normalize("NFD")
|
54
|
+
.replace(/[\u0300-\u036F]/g, "")
|
55
|
+
.toLowerCase()
|
56
|
+
.trim()
|
57
|
+
.replace(/\s+/g, "-")
|
58
|
+
.replace(/[^\w-]+/g, "");
|
59
|
+
};
|
60
|
+
const getExInfo = (title) => {
|
61
|
+
// Example title: '1.0 - Introduction to AI [READ: Small introduction to important concepts such as AI, machine learning, and their applications]'
|
62
|
+
let [exNumber, exTitle] = title.split(" - ");
|
63
|
+
// Extract kind and description
|
64
|
+
const kindMatch = exTitle.match(/\[(.*?):(.*?)]/);
|
65
|
+
const kind = kindMatch ? kindMatch[1].trim().toLowerCase() : "read";
|
66
|
+
const description = kindMatch ? kindMatch[2].trim() : "";
|
67
|
+
exNumber = exNumber.trim();
|
68
|
+
// Clean title
|
69
|
+
exTitle = exTitle.replace((kindMatch === null || kindMatch === void 0 ? void 0 : kindMatch[0]) || "", "").trim();
|
70
|
+
exTitle = slugify(exTitle);
|
71
|
+
return {
|
72
|
+
exNumber,
|
73
|
+
kind,
|
74
|
+
description,
|
75
|
+
exTitle,
|
76
|
+
};
|
77
|
+
};
|
78
|
+
exports.getExInfo = getExInfo;
|
79
|
+
function extractImagesFromMarkdown(markdown) {
|
80
|
+
const imageRegex = /!\[([^\]]*)]\(([^)]+)\)/g;
|
81
|
+
const images = [];
|
82
|
+
let match;
|
83
|
+
while ((match = imageRegex.exec(markdown)) !== null) {
|
84
|
+
const altText = match[1];
|
85
|
+
const url = match[2];
|
86
|
+
images.push({ alt: altText, url: url });
|
87
|
+
}
|
88
|
+
return images;
|
89
|
+
}
|
90
|
+
function getFilenameFromUrl(url) {
|
91
|
+
return path.basename(url);
|
92
|
+
}
|
93
|
+
const makePackageInfo = (choices) => {
|
94
|
+
const packageInfo = {
|
95
|
+
grading: choices.grading,
|
96
|
+
difficulty: choices.difficulty,
|
97
|
+
duration: parseInt(choices.duration),
|
98
|
+
description: {
|
99
|
+
us: choices.description,
|
100
|
+
},
|
101
|
+
title: {
|
102
|
+
us: choices.title,
|
103
|
+
},
|
104
|
+
slug: choices.title
|
105
|
+
.toLowerCase()
|
106
|
+
.replace(/ /g, "-")
|
107
|
+
.replace(/[^\w-]+/g, ""),
|
108
|
+
};
|
109
|
+
return packageInfo;
|
110
|
+
};
|
111
|
+
exports.makePackageInfo = makePackageInfo;
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { PackageInfo } from "./creatorUtilities";
|
1
2
|
type TCreateReadmeInputs = {
|
2
3
|
title: string;
|
3
4
|
output_lang: string;
|
@@ -30,6 +31,7 @@ type TInteractiveCreationInputs = {
|
|
30
31
|
export declare const interactiveCreation: (token: string, inputs: TInteractiveCreationInputs) => Promise<any>;
|
31
32
|
type TCreateCodeFileInputs = {
|
32
33
|
readme: string;
|
34
|
+
tutorial_info: string;
|
33
35
|
};
|
34
36
|
export declare const createCodeFile: (token: string, inputs: TCreateCodeFileInputs) => Promise<any>;
|
35
37
|
type TCreateCodingReadmeInputs = {
|
@@ -49,4 +51,5 @@ type TReadmeCreatorInputs = {
|
|
49
51
|
kind: string;
|
50
52
|
};
|
51
53
|
export declare const readmeCreator: (token: string, inputs: TReadmeCreatorInputs) => Promise<any>;
|
54
|
+
export declare function createPreviewReadme(tutorialDir: string, packageInfo: PackageInfo, rigoToken: string, readmeContents: string[]): Promise<void>;
|
52
55
|
export {};
|
package/lib/utils/rigoActions.js
CHANGED
@@ -2,9 +2,12 @@
|
|
2
2
|
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
|
+
exports.createPreviewReadme = createPreviewReadme;
|
5
6
|
const axios_1 = require("axios");
|
6
7
|
const fs_1 = require("fs");
|
7
8
|
const console_1 = require("../utils/console");
|
9
|
+
const fs = require("fs");
|
10
|
+
const path = require("path");
|
8
11
|
const RIGOBOT_HOST = "https://rigobot.herokuapp.com";
|
9
12
|
const createReadme = async (token, inputs) => {
|
10
13
|
try {
|
@@ -164,3 +167,11 @@ const readmeCreator = async (token, inputs) => {
|
|
164
167
|
throw new Error("Invalid kind of lesson");
|
165
168
|
};
|
166
169
|
exports.readmeCreator = readmeCreator;
|
170
|
+
async function createPreviewReadme(tutorialDir, packageInfo, rigoToken, readmeContents) {
|
171
|
+
const readmeFilename = `README.md`;
|
172
|
+
const readmeContent = await (0, exports.generateCourseIntroduction)(rigoToken, {
|
173
|
+
course_title: packageInfo.title.us,
|
174
|
+
lessons_context: readmeContents.join("\n"),
|
175
|
+
});
|
176
|
+
fs.writeFileSync(path.join(tutorialDir, readmeFilename), readmeContent.answer);
|
177
|
+
}
|
package/oclif.manifest.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":"5.0.
|
1
|
+
{"version":"5.0.28","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.28",
|
5
5
|
"author": "Alejandro Sanchez @alesanchezr",
|
6
6
|
"contributors": [
|
7
7
|
{
|
@@ -41,6 +41,7 @@
|
|
41
41
|
"eta": "^1.2.0",
|
42
42
|
"express": "^4.17.1",
|
43
43
|
"front-matter": "^4.0.2",
|
44
|
+
"js-yaml": "^4.1.0",
|
44
45
|
"moment": "^2.27.0",
|
45
46
|
"node-emoji": "^1.10.0",
|
46
47
|
"node-fetch": "^2.7.0",
|
@@ -60,6 +61,7 @@
|
|
60
61
|
"@types/debounce": "^1.2.1",
|
61
62
|
"@types/express": "^4.17.13",
|
62
63
|
"@types/fs-extra": "^8.1.0",
|
64
|
+
"@types/js-yaml": "^4.0.9",
|
63
65
|
"@types/mocha": "^5",
|
64
66
|
"@types/mock-fs": "^4.13.1",
|
65
67
|
"@types/node": "^10.17.60",
|
@@ -0,0 +1,25 @@
|
|
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
|
+
|
9
|
+
class BreakTokenCommand extends BaseCommand {
|
10
|
+
static description = "Break the token"
|
11
|
+
|
12
|
+
static flags = {
|
13
|
+
...BaseCommand.flags,
|
14
|
+
grading: flags.help({ char: "h" }),
|
15
|
+
}
|
16
|
+
|
17
|
+
async run() {
|
18
|
+
const { flags } = this.parse(BreakTokenCommand)
|
19
|
+
|
20
|
+
await SessionManager.breakToken()
|
21
|
+
process.exit(0)
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
export default BreakTokenCommand
|
package/src/commands/init.ts
CHANGED
@@ -15,128 +15,59 @@ import {
|
|
15
15
|
hasCreatorPermission,
|
16
16
|
generateImage,
|
17
17
|
downloadImage,
|
18
|
-
generateCourseIntroduction,
|
19
18
|
interactiveCreation,
|
20
19
|
createCodeFile,
|
21
20
|
readmeCreator,
|
21
|
+
createPreviewReadme,
|
22
22
|
} from "../utils/rigoActions"
|
23
|
-
import {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
.replace(/[^\w-]+/g, "")
|
34
|
-
}
|
35
|
-
|
36
|
-
const getExInfo = (title: string) => {
|
37
|
-
// Example title: '1.0 - Introduction to AI [READ: Small introduction to important concepts such as AI, machine learning, and their applications]'
|
38
|
-
let [exNumber, exTitle] = title.split(" - ")
|
39
|
-
|
40
|
-
// Extract kind and description
|
41
|
-
const kindMatch = exTitle.match(/\[(.*?):(.*?)]/)
|
42
|
-
const kind = kindMatch ? kindMatch[1].trim().toLowerCase() : "read"
|
43
|
-
const description = kindMatch ? kindMatch[2].trim() : ""
|
44
|
-
|
45
|
-
exNumber = exNumber.trim()
|
46
|
-
// Clean title
|
47
|
-
exTitle = exTitle.replace(kindMatch?.[0] || "", "").trim()
|
48
|
-
exTitle = slugify(exTitle)
|
49
|
-
|
50
|
-
return {
|
51
|
-
exNumber,
|
52
|
-
kind,
|
53
|
-
description,
|
54
|
-
exTitle,
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
function extractImagesFromMarkdown(markdown: string) {
|
59
|
-
const imageRegex = /!\[([^\]]*)]\(([^)]+)\)/g
|
60
|
-
const images = []
|
61
|
-
let match
|
62
|
-
|
63
|
-
while ((match = imageRegex.exec(markdown)) !== null) {
|
64
|
-
const altText = match[1]
|
65
|
-
const url = match[2]
|
66
|
-
images.push({ alt: altText, url: url })
|
67
|
-
}
|
68
|
-
|
69
|
-
return images
|
70
|
-
}
|
71
|
-
|
72
|
-
function getFilenameFromUrl(url: string) {
|
73
|
-
return path.basename(url)
|
74
|
-
}
|
75
|
-
|
76
|
-
const makePackageInfo = (choices: any) => {
|
77
|
-
const packageInfo = {
|
78
|
-
grading: choices.grading,
|
79
|
-
difficulty: choices.difficulty,
|
80
|
-
duration: parseInt(choices.duration),
|
81
|
-
description: {
|
82
|
-
us: choices.description,
|
83
|
-
},
|
84
|
-
title: {
|
85
|
-
us: choices.title,
|
86
|
-
},
|
87
|
-
slug: choices.title
|
88
|
-
.toLowerCase()
|
89
|
-
.replace(/ /g, "-")
|
90
|
-
.replace(/[^\w-]+/g, ""),
|
91
|
-
}
|
92
|
-
return packageInfo
|
93
|
-
}
|
94
|
-
|
95
|
-
async function createPreviewReadme(
|
96
|
-
tutorialDir: string,
|
97
|
-
packageInfo: PackageInfo,
|
98
|
-
rigoToken: string,
|
99
|
-
readmeContents: string[]
|
100
|
-
) {
|
101
|
-
const readmeFilename = `README.md`
|
102
|
-
|
103
|
-
const readmeContent = await generateCourseIntroduction(rigoToken, {
|
104
|
-
course_title: packageInfo.title.us,
|
105
|
-
lessons_context: readmeContents.join("\n"),
|
106
|
-
})
|
107
|
-
fs.writeFileSync(path.join(tutorialDir, readmeFilename), readmeContent.answer)
|
108
|
-
}
|
109
|
-
|
110
|
-
type PackageInfo = {
|
111
|
-
grading: string
|
112
|
-
difficulty: string
|
113
|
-
duration: number
|
114
|
-
description: {
|
115
|
-
us: string
|
116
|
-
}
|
117
|
-
title: {
|
118
|
-
us: string
|
119
|
-
}
|
120
|
-
}
|
23
|
+
import { getConsumable } from "../utils/api"
|
24
|
+
import {
|
25
|
+
checkReadingTime,
|
26
|
+
PackageInfo,
|
27
|
+
getExInfo,
|
28
|
+
extractImagesFromMarkdown,
|
29
|
+
getFilenameFromUrl,
|
30
|
+
makePackageInfo,
|
31
|
+
} from "../utils/creatorUtilities"
|
32
|
+
import SessionManager from "../managers/session"
|
121
33
|
|
122
34
|
const initializeInteractiveCreation = async (
|
123
35
|
rigoToken: string,
|
124
36
|
courseInfo: string
|
125
37
|
): Promise<{
|
126
|
-
|
127
|
-
|
38
|
+
steps: string[]
|
39
|
+
title: string
|
40
|
+
description: string
|
41
|
+
interactions: string
|
128
42
|
}> => {
|
129
43
|
let prevInteractions = ""
|
130
44
|
let isReady = false
|
131
45
|
let currentSteps = []
|
46
|
+
let currentTitle = ""
|
47
|
+
let currentDescription = ""
|
132
48
|
while (!isReady) {
|
49
|
+
let wholeInfo = courseInfo
|
50
|
+
wholeInfo += `
|
51
|
+
Current title: ${currentTitle}
|
52
|
+
Current description: ${currentDescription}
|
53
|
+
`
|
133
54
|
// eslint-disable-next-line
|
134
55
|
const res = await interactiveCreation(rigoToken, {
|
135
|
-
courseInfo:
|
56
|
+
courseInfo: wholeInfo,
|
136
57
|
prevInteractions: prevInteractions,
|
137
58
|
})
|
138
59
|
currentSteps = res.parsed.listOfSteps
|
139
60
|
isReady = res.parsed.ready
|
61
|
+
if (res.parsed.title && currentTitle !== res.parsed.title) {
|
62
|
+
currentTitle = res.parsed.title
|
63
|
+
}
|
64
|
+
|
65
|
+
if (
|
66
|
+
res.parsed.description &&
|
67
|
+
currentDescription !== res.parsed.description
|
68
|
+
) {
|
69
|
+
currentDescription = res.parsed.description
|
70
|
+
}
|
140
71
|
|
141
72
|
if (!isReady) {
|
142
73
|
console.log(currentSteps)
|
@@ -155,58 +86,43 @@ const initializeInteractiveCreation = async (
|
|
155
86
|
}
|
156
87
|
|
157
88
|
return {
|
158
|
-
currentSteps,
|
159
|
-
|
89
|
+
steps: currentSteps,
|
90
|
+
title: currentTitle,
|
91
|
+
description: currentDescription,
|
92
|
+
interactions: prevInteractions,
|
160
93
|
}
|
161
94
|
}
|
162
95
|
|
163
96
|
const handleAILogic = async (tutorialDir: string, packageInfo: PackageInfo) => {
|
164
|
-
Console.info(
|
165
|
-
"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"
|
166
|
-
)
|
167
|
-
|
168
97
|
fs.removeSync(path.join(tutorialDir, "exercises", "01-hello-world"))
|
169
98
|
|
170
|
-
|
171
|
-
{
|
172
|
-
type: "text",
|
173
|
-
name: "email",
|
174
|
-
message: "What's your email?",
|
175
|
-
validate: (value: string) => {
|
176
|
-
return value.length > 0 && value.includes("@")
|
177
|
-
},
|
178
|
-
},
|
179
|
-
{
|
180
|
-
type: "password",
|
181
|
-
name: "password",
|
182
|
-
message: "What's your password?",
|
183
|
-
validate: (value: string) => {
|
184
|
-
return value.length > 0
|
185
|
-
},
|
186
|
-
},
|
187
|
-
])
|
99
|
+
let sessionPayload = await SessionManager.getPayload()
|
188
100
|
|
189
|
-
|
190
|
-
|
191
|
-
sessionPayload
|
192
|
-
|
193
|
-
|
194
|
-
Console.
|
195
|
-
|
101
|
+
if (
|
102
|
+
!sessionPayload ||
|
103
|
+
!sessionPayload.rigobot ||
|
104
|
+
(sessionPayload.token && !(await api.validateToken(sessionPayload.token)))
|
105
|
+
) {
|
106
|
+
Console.info(
|
107
|
+
"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"
|
108
|
+
)
|
109
|
+
try {
|
110
|
+
sessionPayload = await SessionManager.login()
|
111
|
+
} catch (error) {
|
112
|
+
Console.error("Error trying to authenticate")
|
113
|
+
Console.error((error as TypeError).message || (error as string))
|
114
|
+
}
|
196
115
|
}
|
197
116
|
|
198
117
|
const rigoToken = sessionPayload.rigobot.key
|
199
118
|
|
200
|
-
const
|
201
|
-
sessionPayload.token,
|
202
|
-
"ai-generation"
|
203
|
-
)
|
119
|
+
const consumable = await getConsumable(sessionPayload.token, "ai-generation")
|
204
120
|
|
205
|
-
if (
|
121
|
+
if (consumable.count === 0) {
|
206
122
|
Console.error(
|
207
|
-
"It seems you cannot generate tutorials with AI. Make sure you creator subscription is up to date here: https://4geeks.com/profile/subscriptions
|
123
|
+
"It seems you cannot generate tutorials with AI. Make sure you creator subscription is up to date here: https://4geeks.com/profile/subscriptions. If you believe there is an issue you can always contact support@4geeks.com"
|
208
124
|
)
|
209
|
-
process.exit(1)
|
125
|
+
// process.exit(1)
|
210
126
|
}
|
211
127
|
|
212
128
|
const isCreator = await hasCreatorPermission(rigoToken)
|
@@ -219,71 +135,84 @@ const handleAILogic = async (tutorialDir: string, packageInfo: PackageInfo) => {
|
|
219
135
|
|
220
136
|
Console.success("🎉 Let's begin this learning journey!")
|
221
137
|
|
222
|
-
|
138
|
+
let packageContext = `
|
223
139
|
\n
|
224
|
-
The following information comes from user inputs
|
225
140
|
Title: ${packageInfo.title.us}
|
226
141
|
Description: ${packageInfo.description.us}
|
227
|
-
Grading: ${packageInfo.grading}
|
228
142
|
Difficulty: ${packageInfo.difficulty}
|
229
143
|
Duration: ${packageInfo.duration}
|
230
|
-
|
231
|
-
Use it to generate more relevant exercises
|
232
144
|
`
|
233
145
|
|
234
|
-
const {
|
146
|
+
const { steps, title, description } = await initializeInteractiveCreation(
|
235
147
|
rigoToken,
|
236
148
|
packageContext
|
237
149
|
)
|
150
|
+
packageInfo.title.us = title
|
151
|
+
packageInfo.description.us = description
|
238
152
|
|
153
|
+
packageContext = `
|
154
|
+
Title: ${title}
|
155
|
+
Description: ${description}
|
156
|
+
Difficulty: ${packageInfo.difficulty}
|
157
|
+
Estimated duration: ${packageInfo.duration}
|
158
|
+
List of exercises: ${steps.join(", ")}
|
159
|
+
`
|
239
160
|
const exercisesDir = path.join(tutorialDir, "exercises")
|
240
161
|
fs.ensureDirSync(exercisesDir)
|
241
162
|
|
242
163
|
Console.info("Creating lessons...")
|
243
|
-
for (const [index, exercise] of
|
164
|
+
for (const [index, exercise] of steps.entries()) {
|
244
165
|
const { exNumber, exTitle } = getExInfo(exercise)
|
245
166
|
const exerciseDir = path.join(exercisesDir, `${exNumber}-${exTitle}`)
|
246
167
|
fs.ensureDirSync(exerciseDir)
|
247
168
|
}
|
248
169
|
|
249
|
-
const exercisePromises =
|
250
|
-
|
251
|
-
|
252
|
-
const exerciseDir = path.join(exercisesDir, `${exNumber}-${exTitle}`)
|
253
|
-
|
254
|
-
const readme = await readmeCreator(rigoToken, {
|
255
|
-
title: `${exNumber} - ${exTitle}`,
|
256
|
-
output_lang: "en",
|
257
|
-
list_of_exercises: currentSteps.join(","),
|
258
|
-
tutorial_description: packageContext,
|
259
|
-
lesson_description: description,
|
260
|
-
kind: kind.toLowerCase(),
|
261
|
-
})
|
170
|
+
const exercisePromises = steps.map(async (exercise: any, index: number) => {
|
171
|
+
const { exNumber, exTitle, kind, description } = getExInfo(exercise)
|
172
|
+
const exerciseDir = path.join(exercisesDir, `${exNumber}-${exTitle}`)
|
262
173
|
|
263
|
-
|
174
|
+
const readme = await readmeCreator(rigoToken, {
|
175
|
+
title: `${exNumber} - ${exTitle}`,
|
176
|
+
output_lang: "en",
|
177
|
+
list_of_exercises: steps.join(","),
|
178
|
+
tutorial_description: packageContext,
|
179
|
+
lesson_description: description,
|
180
|
+
kind: kind.toLowerCase(),
|
181
|
+
})
|
264
182
|
|
265
|
-
|
266
|
-
|
267
|
-
|
183
|
+
const { exceedsThreshold, newMarkdown } = checkReadingTime(
|
184
|
+
readme.parsed.content,
|
185
|
+
200
|
186
|
+
)
|
187
|
+
|
188
|
+
if (exceedsThreshold) {
|
189
|
+
Console.error("The reading time exceeds the threshold")
|
190
|
+
Console.info(
|
191
|
+
`Please reduce the reading time of the lesson, current reading time is ${exceedsThreshold} minutes`
|
268
192
|
)
|
193
|
+
}
|
269
194
|
|
270
|
-
|
271
|
-
const codeFile = await createCodeFile(rigoToken, {
|
272
|
-
readme: readme.parsed.content,
|
273
|
-
})
|
274
|
-
|
275
|
-
fs.writeFileSync(
|
276
|
-
path.join(
|
277
|
-
exerciseDir,
|
278
|
-
`app.${codeFile.parsed.extension.replace(".", "")}`
|
279
|
-
),
|
280
|
-
codeFile.parsed.content
|
281
|
-
)
|
282
|
-
}
|
195
|
+
const readmeFilename = "README.md"
|
283
196
|
|
284
|
-
|
197
|
+
fs.writeFileSync(path.join(exerciseDir, readmeFilename), newMarkdown)
|
198
|
+
|
199
|
+
if (kind.toLowerCase() === "code") {
|
200
|
+
const codeFile = await createCodeFile(rigoToken, {
|
201
|
+
readme: readme.parsed.content,
|
202
|
+
tutorial_info: packageContext,
|
203
|
+
})
|
204
|
+
|
205
|
+
fs.writeFileSync(
|
206
|
+
path.join(
|
207
|
+
exerciseDir,
|
208
|
+
`app.${codeFile.parsed.extension.replace(".", "")}`
|
209
|
+
),
|
210
|
+
codeFile.parsed.content
|
211
|
+
)
|
285
212
|
}
|
286
|
-
|
213
|
+
|
214
|
+
return readme.parsed.content
|
215
|
+
})
|
287
216
|
|
288
217
|
let imagesArray: any[] = []
|
289
218
|
|
package/src/commands/publish.ts
CHANGED
@@ -15,6 +15,8 @@ import {
|
|
15
15
|
downloadEditor,
|
16
16
|
checkIfDirectoryExists,
|
17
17
|
} from "../managers/file"
|
18
|
+
import api, { TAcademy } from "../utils/api"
|
19
|
+
import * as prompts from "prompts"
|
18
20
|
|
19
21
|
const RIGOBOT_HOST = "https://rigobot.herokuapp.com"
|
20
22
|
// const RIGOBOT_HOST =
|
@@ -45,6 +47,29 @@ const runAudit = () => {
|
|
45
47
|
)
|
46
48
|
}
|
47
49
|
|
50
|
+
const selectAcademy = async (academies: TAcademy[]) => {
|
51
|
+
if (academies.length === 0) {
|
52
|
+
return null
|
53
|
+
}
|
54
|
+
|
55
|
+
if (academies.length === 1) {
|
56
|
+
return academies[0]
|
57
|
+
}
|
58
|
+
|
59
|
+
// prompts the user to select an academy to upload the assets
|
60
|
+
Console.info("In which academy do you want to publish the asset?")
|
61
|
+
const response = await prompts({
|
62
|
+
type: "select",
|
63
|
+
name: "academy",
|
64
|
+
message: "Select an academy",
|
65
|
+
choices: academies.map((academy) => ({
|
66
|
+
title: academy.name,
|
67
|
+
value: academy,
|
68
|
+
})),
|
69
|
+
})
|
70
|
+
return response.academy
|
71
|
+
}
|
72
|
+
|
48
73
|
export default class BuildCommand extends SessionCommand {
|
49
74
|
static description =
|
50
75
|
"Builds the project by copying necessary files and directories into a zip file"
|
@@ -65,7 +90,11 @@ export default class BuildCommand extends SessionCommand {
|
|
65
90
|
const configObject = this.configManager?.get()
|
66
91
|
|
67
92
|
let sessionPayload = await SessionManager.getPayload()
|
68
|
-
if (
|
93
|
+
if (
|
94
|
+
!sessionPayload ||
|
95
|
+
!sessionPayload.rigobot ||
|
96
|
+
(sessionPayload.token && !(await api.validateToken(sessionPayload.token)))
|
97
|
+
) {
|
69
98
|
Console.error("You must be logged in to upload a LearnPack package")
|
70
99
|
try {
|
71
100
|
sessionPayload = await SessionManager.login()
|
@@ -87,7 +116,10 @@ export default class BuildCommand extends SessionCommand {
|
|
87
116
|
this.configManager?.buildIndex()
|
88
117
|
}
|
89
118
|
|
90
|
-
// const
|
119
|
+
// const academies = await api.listUserAcademies(sessionPayload.token)
|
120
|
+
// console.log(academies, "academies")
|
121
|
+
// const academy = await selectAcademy(academies)
|
122
|
+
// console.log(academy, "academy")
|
91
123
|
|
92
124
|
// Read learn.json to get the slug
|
93
125
|
const learnJsonPath = path.join(process.cwd(), "learn.json")
|