@learnpack/learnpack 5.0.30 → 5.0.32
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 +12 -12
- package/lib/commands/audit.js +15 -15
- package/lib/commands/init.js +39 -15
- package/lib/commands/translate.js +2 -10
- package/lib/managers/server/routes.js +38 -0
- package/lib/managers/telemetry.d.ts +2 -0
- package/lib/managers/telemetry.js +7 -0
- package/lib/utils/creatorUtilities.d.ts +2 -0
- package/lib/utils/creatorUtilities.js +48 -7
- package/lib/utils/rigoActions.d.ts +1 -0
- package/lib/utils/rigoActions.js +13 -2
- package/oclif.manifest.json +1 -1
- package/package.json +2 -1
- package/src/commands/audit.ts +449 -449
- package/src/commands/breakToken.ts +36 -36
- package/src/commands/init.ts +48 -17
- package/src/commands/publish.ts +312 -312
- package/src/commands/start.ts +361 -361
- package/src/commands/translate.ts +1 -20
- package/src/managers/config/index.ts +1 -0
- package/src/managers/server/routes.ts +61 -1
- package/src/managers/socket.ts +274 -274
- package/src/managers/telemetry.ts +10 -0
- package/src/models/action.ts +12 -12
- package/src/utils/console.ts +24 -24
- package/src/utils/creatorUtilities.ts +66 -6
- package/src/utils/rigoActions.ts +13 -1
@@ -1,5 +1,6 @@
|
|
1
1
|
import { IFile } from "../models/file"
|
2
2
|
import API from "../utils/api"
|
3
|
+
const packageInfo = require("../../package.json")
|
3
4
|
import Console from "../utils/console"
|
4
5
|
|
5
6
|
const fs = require("fs")
|
@@ -77,6 +78,7 @@ type TStudent = {
|
|
77
78
|
|
78
79
|
export interface ITelemetryJSONSchema {
|
79
80
|
telemetry_id?: string
|
81
|
+
version: string
|
80
82
|
user_id?: number | string
|
81
83
|
slug: string
|
82
84
|
agent?: string
|
@@ -111,6 +113,7 @@ interface ITelemetryManager {
|
|
111
113
|
user: TUser
|
112
114
|
urls: TTelemetryUrls
|
113
115
|
started: boolean
|
116
|
+
version: string
|
114
117
|
salute: (message: string) => void
|
115
118
|
start: (
|
116
119
|
agent: string,
|
@@ -136,6 +139,7 @@ interface ITelemetryManager {
|
|
136
139
|
const TelemetryManager: ITelemetryManager = {
|
137
140
|
current: null,
|
138
141
|
urls: {},
|
142
|
+
version: packageInfo.version,
|
139
143
|
user: {
|
140
144
|
token: "",
|
141
145
|
id: "",
|
@@ -160,6 +164,8 @@ const TelemetryManager: ITelemetryManager = {
|
|
160
164
|
this.current = {
|
161
165
|
telemetry_id: createUUID(),
|
162
166
|
slug: tutorialSlug,
|
167
|
+
version: `CLI:${this.version}`,
|
168
|
+
user_id: 0,
|
163
169
|
agent,
|
164
170
|
tutorial_started_at: Date.now(),
|
165
171
|
last_interaction_at: Date.now(),
|
@@ -176,6 +182,10 @@ const TelemetryManager: ITelemetryManager = {
|
|
176
182
|
this.user.id = this.current.user_id.toString()
|
177
183
|
}
|
178
184
|
|
185
|
+
if (!this.current.version) {
|
186
|
+
this.current.version = `CLI:${this.version}`
|
187
|
+
}
|
188
|
+
|
179
189
|
this.save()
|
180
190
|
|
181
191
|
this.started = true
|
package/src/models/action.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
export type TAction =
|
2
|
-
| "test"
|
3
|
-
| "log"
|
4
|
-
| "reload"
|
5
|
-
| "ready"
|
6
|
-
| "clean"
|
7
|
-
| "ask"
|
8
|
-
| "file_change"
|
9
|
-
| "dialog"
|
10
|
-
| "session-refreshed"
|
11
|
-
|
12
|
-
export type ICallback = (...agrs: any[]) => any
|
1
|
+
export type TAction =
|
2
|
+
| "test"
|
3
|
+
| "log"
|
4
|
+
| "reload"
|
5
|
+
| "ready"
|
6
|
+
| "clean"
|
7
|
+
| "ask"
|
8
|
+
| "file_change"
|
9
|
+
| "dialog"
|
10
|
+
| "session-refreshed"
|
11
|
+
|
12
|
+
export type ICallback = (...agrs: any[]) => any
|
package/src/utils/console.ts
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
import * as chalk from "chalk"
|
2
|
-
|
3
|
-
export default {
|
4
|
-
// _debug: true,
|
5
|
-
_debug: process.env.DEBUG === "true",
|
6
|
-
startDebug: function () {
|
7
|
-
this._debug = true
|
8
|
-
},
|
9
|
-
log: (msg: string | Array<string>, ...args: Array<any>) =>
|
10
|
-
console.log(chalk.gray(msg), ...args),
|
11
|
-
error: (msg: string, ...args: Array<any>) =>
|
12
|
-
console.log(chalk.red("⨉ " + msg), ...args),
|
13
|
-
success: (msg: string, ...args: Array<any>) =>
|
14
|
-
console.log(chalk.green("✓ " + msg), ...args),
|
15
|
-
info: (msg: any, ...args: Array<any>) =>
|
16
|
-
console.log(chalk.blue("ⓘ " + msg), ...args),
|
17
|
-
help: (msg: string) =>
|
18
|
-
console.log(`${chalk.white.bold("⚠ help:")} ${chalk.white(msg)}`),
|
19
|
-
debug(...args: Array<any>) {
|
20
|
-
this._debug && console.log(chalk.magentaBright("⚠ debug: "), args)
|
21
|
-
},
|
22
|
-
warning: (msg: string) =>
|
23
|
-
console.log(`${chalk.yellow("⚠ warning:")} ${chalk.yellow(msg)}`),
|
24
|
-
}
|
1
|
+
import * as chalk from "chalk"
|
2
|
+
|
3
|
+
export default {
|
4
|
+
// _debug: true,
|
5
|
+
_debug: process.env.DEBUG === "true",
|
6
|
+
startDebug: function () {
|
7
|
+
this._debug = true
|
8
|
+
},
|
9
|
+
log: (msg: string | Array<string>, ...args: Array<any>) =>
|
10
|
+
console.log(chalk.gray(msg), ...args),
|
11
|
+
error: (msg: string, ...args: Array<any>) =>
|
12
|
+
console.log(chalk.red("⨉ " + msg), ...args),
|
13
|
+
success: (msg: string, ...args: Array<any>) =>
|
14
|
+
console.log(chalk.green("✓ " + msg), ...args),
|
15
|
+
info: (msg: any, ...args: Array<any>) =>
|
16
|
+
console.log(chalk.blue("ⓘ " + msg), ...args),
|
17
|
+
help: (msg: string) =>
|
18
|
+
console.log(`${chalk.white.bold("⚠ help:")} ${chalk.white(msg)}`),
|
19
|
+
debug(...args: Array<any>) {
|
20
|
+
this._debug && console.log(chalk.magentaBright("⚠ debug: "), args)
|
21
|
+
},
|
22
|
+
warning: (msg: string) =>
|
23
|
+
console.log(`${chalk.yellow("⚠ warning:")} ${chalk.yellow(msg)}`),
|
24
|
+
}
|
@@ -1,5 +1,6 @@
|
|
1
|
-
|
1
|
+
|
2
2
|
const frontMatter = require("front-matter")
|
3
|
+
|
3
4
|
import * as path from "path"
|
4
5
|
import * as fs from "fs"
|
5
6
|
import { homedir } from "os"
|
@@ -61,11 +62,13 @@ export function checkReadingTime(
|
|
61
62
|
exceedsThreshold: boolean
|
62
63
|
minutes: number
|
63
64
|
body: string
|
65
|
+
// readingEase: number
|
64
66
|
} {
|
65
67
|
const parsed = frontMatter(markdown)
|
66
68
|
|
67
69
|
const readingTime = estimateReadingTime(parsed.body, wordsPerMinute)
|
68
70
|
|
71
|
+
// const readingEase = estimateReadingEase(parsed.body)
|
69
72
|
let attributes = parsed.attributes ? parsed.attributes : {}
|
70
73
|
|
71
74
|
if (typeof parsed.attributes !== "object") {
|
@@ -75,6 +78,7 @@ export function checkReadingTime(
|
|
75
78
|
const updatedAttributes = {
|
76
79
|
...attributes,
|
77
80
|
readingTime,
|
81
|
+
// readingEase,
|
78
82
|
}
|
79
83
|
|
80
84
|
let yamlFrontMatter = ""
|
@@ -86,6 +90,7 @@ export function checkReadingTime(
|
|
86
90
|
exceedsThreshold: false,
|
87
91
|
minutes: 0,
|
88
92
|
body: "",
|
93
|
+
// readingEase: 0,
|
89
94
|
}
|
90
95
|
}
|
91
96
|
|
@@ -97,6 +102,7 @@ export function checkReadingTime(
|
|
97
102
|
exceedsThreshold: readingTime.minutes > maxMinutes,
|
98
103
|
minutes: readingTime.minutes,
|
99
104
|
body: parsed.body,
|
105
|
+
// readingEase: 0,
|
100
106
|
}
|
101
107
|
}
|
102
108
|
|
@@ -189,11 +195,13 @@ export function estimateDuration(listOfSteps: string[]): number {
|
|
189
195
|
const writeFilePromise = promisify(fs.writeFile)
|
190
196
|
const execPromise = promisify(exec)
|
191
197
|
|
192
|
-
const example_content = `
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
198
|
+
const example_content = `Write or paste your table of content below this line, each topic should be defined on a new line, here is an example:
|
199
|
+
|
200
|
+
Introduction to AI: Explain what is AI and its applications
|
201
|
+
Introduction to Machine Learning: Explain what is machine learning and its applications
|
202
|
+
What is an AI Model: Explain what is an AI model and its applications
|
203
|
+
How to use an AI Model: Different APIs, local models, etc.
|
204
|
+
How to build an AI Model: Fine-tuning, data collection, cleaning and more.
|
197
205
|
`
|
198
206
|
|
199
207
|
export async function createFileOnDesktop() {
|
@@ -239,3 +247,55 @@ export function getContentIndex() {
|
|
239
247
|
const content = fs.readFileSync(filePath, "utf8")
|
240
248
|
return content
|
241
249
|
}
|
250
|
+
|
251
|
+
// export function fleschKincaidReadingEase(text: string): number {
|
252
|
+
// const sentences = text.split(/[.!?]/).filter((s) => s.trim().length > 0)
|
253
|
+
// const words = text.split(/\s+/).filter((w) => w.trim().length > 0)
|
254
|
+
// const totalSyllables = words.reduce((sum, word) => sum + syllable(word), 0)
|
255
|
+
|
256
|
+
// const ASL = words.length / sentences.length // Average Sentence Length
|
257
|
+
// const ASW = totalSyllables / words.length // Average Syllables per Word
|
258
|
+
|
259
|
+
// return Math.round(206.835 - 1.015 * ASL - 84.6 * ASW)
|
260
|
+
// }
|
261
|
+
|
262
|
+
export function extractTextFromMarkdown(mdContent: string): string {
|
263
|
+
let content = mdContent.replace(/!\[.*?]\(.*?\)/g, "")
|
264
|
+
content = content.replace(/\[.*?]\(.*?\)/g, "")
|
265
|
+
content = content.replace(/`.*?`/g, "")
|
266
|
+
content = content.replace(/```[\S\s]*?```/g, "")
|
267
|
+
|
268
|
+
return content.trim()
|
269
|
+
}
|
270
|
+
|
271
|
+
// export const estimateReadingEase = async (text: string): Promise<number> => {
|
272
|
+
// const cleanedText = extractTextFromMarkdown(text)
|
273
|
+
// // @ts-ignore
|
274
|
+
// const rs = (await import("text-readability")).default;
|
275
|
+
// // return fleschKincaidReadingEase(cleanedText)
|
276
|
+
// // const score = readability(cleanedText)
|
277
|
+
// // console.log(score)
|
278
|
+
// // return score.fleschKincaid ?? 0
|
279
|
+
// const score = rs.fleschReadingEase(cleanedText)
|
280
|
+
// console.log(score, "SCORE FLESCH READING EASE")
|
281
|
+
// return score
|
282
|
+
// }
|
283
|
+
|
284
|
+
const cleanReadme = (readme: string) => {
|
285
|
+
// Replace <text> and </text> with nothing
|
286
|
+
return readme.replace(/<text>/g, "").replace(/<\/text>/g, "")
|
287
|
+
}
|
288
|
+
|
289
|
+
export const saveTranslatedReadme = async (
|
290
|
+
exercise: string,
|
291
|
+
languageCode: string,
|
292
|
+
readme: string
|
293
|
+
) => {
|
294
|
+
const readmePath = path.join(
|
295
|
+
process.cwd(),
|
296
|
+
"exercises",
|
297
|
+
exercise,
|
298
|
+
`README.${languageCode}.md`
|
299
|
+
)
|
300
|
+
fs.writeFileSync(readmePath, cleanReadme(readme))
|
301
|
+
}
|
package/src/utils/rigoActions.ts
CHANGED
@@ -62,7 +62,7 @@ return false
|
|
62
62
|
Console.debug("The user is a creator! 🎉")
|
63
63
|
return true
|
64
64
|
} catch (error) {
|
65
|
-
Console.
|
65
|
+
Console.error(error as string)
|
66
66
|
return false
|
67
67
|
}
|
68
68
|
}
|
@@ -323,3 +323,15 @@ export async function reduceReadme(
|
|
323
323
|
return null
|
324
324
|
}
|
325
325
|
}
|
326
|
+
|
327
|
+
export const isValidRigoToken = async (rigobotToken: string) => {
|
328
|
+
const rigoUrl = `${RIGOBOT_HOST}/v1/auth/token/${rigobotToken}`
|
329
|
+
const rigoResp = await fetch(rigoUrl)
|
330
|
+
if (!rigoResp.ok) {
|
331
|
+
Console.debug("Invalid Rigobot token", rigoResp.status)
|
332
|
+
Console.debug(rigoResp.statusText)
|
333
|
+
return false
|
334
|
+
}
|
335
|
+
|
336
|
+
return true
|
337
|
+
}
|