@learnpack/learnpack 5.0.14 → 5.0.16
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 +19 -11
- package/lib/commands/init.d.ts +1 -0
- package/lib/commands/init.js +122 -102
- package/lib/utils/BaseCommand.d.ts +3 -0
- package/lib/utils/BaseCommand.js +7 -0
- package/lib/utils/api.d.ts +3 -0
- package/lib/utils/api.js +25 -0
- package/lib/utils/checkNotInstalled.js +7 -1
- package/oclif.manifest.json +1 -1
- package/package.json +152 -152
- package/src/commands/init.ts +144 -106
- package/src/utils/BaseCommand.ts +56 -48
- package/src/utils/api.ts +42 -0
- package/src/utils/checkNotInstalled.ts +8 -1
- package/src/utils/incrementVersion.js +65 -0
package/src/utils/BaseCommand.ts
CHANGED
@@ -1,48 +1,56 @@
|
|
1
|
-
import { Command } from "@oclif/command"
|
2
|
-
import Console from "./console"
|
3
|
-
import { createInterface } from "readline"
|
4
|
-
// import SessionManager from '../managers/session'
|
5
|
-
|
6
|
-
class BaseCommand extends Command {
|
7
|
-
async catch(err: any) {
|
8
|
-
Console.debug("COMMAND CATCH", err)
|
9
|
-
|
10
|
-
throw err
|
11
|
-
}
|
12
|
-
|
13
|
-
async init() {
|
14
|
-
const { flags, args } = this.parse(BaseCommand)
|
15
|
-
Console.debug("COMMAND INIT")
|
16
|
-
Console.debug("These are your flags: ", flags)
|
17
|
-
Console.debug("These are your args: ", args)
|
18
|
-
|
19
|
-
// quick fix for listening to the process termination on windows
|
20
|
-
if (process.platform === "win32") {
|
21
|
-
const rl = createInterface({
|
22
|
-
input: process.stdin,
|
23
|
-
output: process.stdout,
|
24
|
-
})
|
25
|
-
|
26
|
-
rl.on("SIGINT", function () {
|
27
|
-
// process.emit('SIGINT')
|
28
|
-
// process.emit('SIGINT')
|
29
|
-
})
|
30
|
-
}
|
31
|
-
|
32
|
-
process.on("SIGINT", function () {
|
33
|
-
Console.debug("Terminated (SIGINT)")
|
34
|
-
process.exit()
|
35
|
-
})
|
36
|
-
}
|
37
|
-
|
38
|
-
async finally() {
|
39
|
-
Console.debug("COMMAND FINALLY")
|
40
|
-
// called after run and catch regardless of whether or not the command errored
|
41
|
-
}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
1
|
+
import { Command, flags } from "@oclif/command"
|
2
|
+
import Console from "./console"
|
3
|
+
import { createInterface } from "readline"
|
4
|
+
// import SessionManager from '../managers/session'
|
5
|
+
|
6
|
+
class BaseCommand extends Command {
|
7
|
+
async catch(err: any) {
|
8
|
+
Console.debug("COMMAND CATCH", err)
|
9
|
+
|
10
|
+
throw err
|
11
|
+
}
|
12
|
+
|
13
|
+
async init() {
|
14
|
+
const { flags, args } = this.parse(BaseCommand)
|
15
|
+
Console.debug("COMMAND INIT")
|
16
|
+
Console.debug("These are your flags: ", flags)
|
17
|
+
Console.debug("These are your args: ", args)
|
18
|
+
|
19
|
+
// quick fix for listening to the process termination on windows
|
20
|
+
if (process.platform === "win32") {
|
21
|
+
const rl = createInterface({
|
22
|
+
input: process.stdin,
|
23
|
+
output: process.stdout,
|
24
|
+
})
|
25
|
+
|
26
|
+
rl.on("SIGINT", function () {
|
27
|
+
// process.emit('SIGINT')
|
28
|
+
// process.emit('SIGINT')
|
29
|
+
})
|
30
|
+
}
|
31
|
+
|
32
|
+
process.on("SIGINT", function () {
|
33
|
+
Console.debug("Terminated (SIGINT)")
|
34
|
+
process.exit()
|
35
|
+
})
|
36
|
+
}
|
37
|
+
|
38
|
+
async finally() {
|
39
|
+
Console.debug("COMMAND FINALLY")
|
40
|
+
// called after run and catch regardless of whether or not the command errored
|
41
|
+
}
|
42
|
+
|
43
|
+
static flags = {
|
44
|
+
yes: flags.boolean({
|
45
|
+
char: "y",
|
46
|
+
description: "Skip all prompts and initialize an empty project",
|
47
|
+
default: false,
|
48
|
+
}),
|
49
|
+
}
|
50
|
+
|
51
|
+
async run() {
|
52
|
+
// console.log('running my command')
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
export default BaseCommand
|
package/src/utils/api.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import Console from "../utils/console"
|
2
2
|
import * as storage from "node-persist"
|
3
3
|
import cli from "cli-ux"
|
4
|
+
import axios from "axios"
|
4
5
|
const HOST = "https://breathecode.herokuapp.com"
|
5
6
|
const RIGOBOT_HOST = "https://rigobot.herokuapp.com"
|
6
7
|
// const RIGOBOT_HOST = "https://8000-charlytoc-rigobot-bmwdeam7cev.ws-us116.gitpod.io"
|
@@ -299,6 +300,47 @@ const sendStreamTelemetry = async function (url: string, body: object) {
|
|
299
300
|
})
|
300
301
|
}
|
301
302
|
|
303
|
+
type TConsumableSlug =
|
304
|
+
| "ai-conversation-message"
|
305
|
+
| "ai-compilation"
|
306
|
+
| "ai-tutorial-generation"
|
307
|
+
|
308
|
+
export const countConsumables = (
|
309
|
+
consumables: any,
|
310
|
+
consumableSlug: TConsumableSlug = "ai-tutorial-generation"
|
311
|
+
) => {
|
312
|
+
// Find the void that matches the consumableSlug
|
313
|
+
|
314
|
+
const consumable = consumables.voids.find(
|
315
|
+
(voidItem: any) => voidItem.slug === consumableSlug
|
316
|
+
)
|
317
|
+
|
318
|
+
// Return the available units or 0 if not found
|
319
|
+
return consumable ? consumable.balance.unit : 0
|
320
|
+
}
|
321
|
+
|
322
|
+
export const getConsumables = async (token: string): Promise<any> => {
|
323
|
+
const url = `${HOST}/v1/payments/me/service/consumable?virtual=true`
|
324
|
+
|
325
|
+
const headers = {
|
326
|
+
Authorization: `Token ${token}`,
|
327
|
+
}
|
328
|
+
|
329
|
+
try {
|
330
|
+
const response = await axios.get(url, { headers })
|
331
|
+
|
332
|
+
const ai_tutorial_generation = countConsumables(
|
333
|
+
response.data,
|
334
|
+
"ai-tutorial-generation"
|
335
|
+
)
|
336
|
+
|
337
|
+
return { ai_tutorial_generation }
|
338
|
+
} catch (error) {
|
339
|
+
console.error("Error fetching consumables:", error)
|
340
|
+
throw error
|
341
|
+
}
|
342
|
+
}
|
343
|
+
|
302
344
|
export default {
|
303
345
|
login,
|
304
346
|
publish,
|
@@ -222,7 +222,14 @@ return true
|
|
222
222
|
}
|
223
223
|
|
224
224
|
if (pytestNeeded) {
|
225
|
-
|
225
|
+
try {
|
226
|
+
await exec("python -m pip install --upgrade pip")
|
227
|
+
} catch (error) {
|
228
|
+
Console.error(
|
229
|
+
"Error upgrading pip. Please install pip manually, run: pip install --upgrade pip"
|
230
|
+
)
|
231
|
+
Console.debug(error)
|
232
|
+
}
|
226
233
|
|
227
234
|
const { stdout, stderr } = await exec("pip list")
|
228
235
|
if (stderr) {
|
@@ -0,0 +1,65 @@
|
|
1
|
+
const fs = require("fs")
|
2
|
+
const path = require("path")
|
3
|
+
const readline = require("readline")
|
4
|
+
|
5
|
+
const packagePath = path.resolve(process.cwd(), "package.json")
|
6
|
+
|
7
|
+
try {
|
8
|
+
// Lee el archivo package.json
|
9
|
+
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"))
|
10
|
+
|
11
|
+
// Verifica que exista un campo "version"
|
12
|
+
if (!packageJson.version) {
|
13
|
+
throw new Error(
|
14
|
+
'El archivo package.json no contiene una propiedad "version".'
|
15
|
+
)
|
16
|
+
}
|
17
|
+
|
18
|
+
const [major, minor, patch] = packageJson.version.split(".").map(Number)
|
19
|
+
|
20
|
+
// Crear la interfaz para leer desde la terminal
|
21
|
+
const rl = readline.createInterface({
|
22
|
+
input: process.stdin,
|
23
|
+
output: process.stdout,
|
24
|
+
})
|
25
|
+
|
26
|
+
// Pregunta al usuario qué parte de la versión desea incrementar
|
27
|
+
rl.question(
|
28
|
+
"¿Qué parte de la versión deseas incrementar? (major, minor, patch): ",
|
29
|
+
answer => {
|
30
|
+
let newVersion
|
31
|
+
|
32
|
+
switch (answer.toLowerCase()) {
|
33
|
+
case "major":
|
34
|
+
newVersion = `${major + 1}.0.0`
|
35
|
+
break
|
36
|
+
case "minor":
|
37
|
+
newVersion = `${major}.${minor + 1}.0`
|
38
|
+
break
|
39
|
+
case "patch":
|
40
|
+
newVersion = `${major}.${minor}.${patch + 1}`
|
41
|
+
break
|
42
|
+
default:
|
43
|
+
console.error("Opción no válida. Usa: major, minor o patch.")
|
44
|
+
rl.close()
|
45
|
+
process.exit(1)
|
46
|
+
}
|
47
|
+
|
48
|
+
// Actualiza el archivo package.json
|
49
|
+
packageJson.version = newVersion
|
50
|
+
fs.writeFileSync(
|
51
|
+
packagePath,
|
52
|
+
JSON.stringify(packageJson, null, 2),
|
53
|
+
"utf8"
|
54
|
+
)
|
55
|
+
|
56
|
+
console.log(
|
57
|
+
`Versión actualizada: ${packageJson.version} -> ${newVersion}`
|
58
|
+
)
|
59
|
+
rl.close()
|
60
|
+
}
|
61
|
+
)
|
62
|
+
} catch (error) {
|
63
|
+
console.error(`Error: ${error.message}`)
|
64
|
+
process.exit(1)
|
65
|
+
}
|