@learnpack/learnpack 5.0.110 → 5.0.112

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 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.110 win32-x64 node-v22.15.0
24
+ @learnpack/learnpack/5.0.112 win32-x64 node-v22.15.0
25
25
  $ learnpack --help [COMMAND]
26
26
  USAGE
27
27
  $ learnpack COMMAND
@@ -80,7 +80,7 @@ DESCRIPTION
80
80
  12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)
81
81
  ```
82
82
 
83
- _See code: [src\commands\audit.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.110/src\commands\audit.ts)_
83
+ _See code: [src\commands\audit.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.112/src\commands\audit.ts)_
84
84
 
85
85
  ## `learnpack breakToken`
86
86
 
@@ -95,7 +95,7 @@ OPTIONS
95
95
  -y, --yes Skip all prompts and initialize an empty project
96
96
  ```
97
97
 
98
- _See code: [src\commands\breakToken.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.110/src\commands\breakToken.ts)_
98
+ _See code: [src\commands\breakToken.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.112/src\commands\breakToken.ts)_
99
99
 
100
100
  ## `learnpack clean`
101
101
 
@@ -110,7 +110,7 @@ DESCRIPTION
110
110
  Extra documentation goes here
111
111
  ```
112
112
 
113
- _See code: [src\commands\clean.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.110/src\commands\clean.ts)_
113
+ _See code: [src\commands\clean.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.112/src\commands\clean.ts)_
114
114
 
115
115
  ## `learnpack download [PACKAGE]`
116
116
 
@@ -128,7 +128,7 @@ DESCRIPTION
128
128
  Extra documentation goes here
129
129
  ```
130
130
 
131
- _See code: [src\commands\download.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.110/src\commands\download.ts)_
131
+ _See code: [src\commands\download.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.112/src\commands\download.ts)_
132
132
 
133
133
  ## `learnpack help [COMMAND]`
134
134
 
@@ -160,7 +160,7 @@ OPTIONS
160
160
  -y, --yes Skip all prompts and initialize an empty project
161
161
  ```
162
162
 
163
- _See code: [src\commands\init.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.110/src\commands\init.ts)_
163
+ _See code: [src\commands\init.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.112/src\commands\init.ts)_
164
164
 
165
165
  ## `learnpack login [PACKAGE]`
166
166
 
@@ -178,7 +178,7 @@ DESCRIPTION
178
178
  Extra documentation goes here
179
179
  ```
180
180
 
181
- _See code: [src\commands\login.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.110/src\commands\login.ts)_
181
+ _See code: [src\commands\login.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.112/src\commands\login.ts)_
182
182
 
183
183
  ## `learnpack logout [PACKAGE]`
184
184
 
@@ -196,7 +196,7 @@ DESCRIPTION
196
196
  Extra documentation goes here
197
197
  ```
198
198
 
199
- _See code: [src\commands\logout.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.110/src\commands\logout.ts)_
199
+ _See code: [src\commands\logout.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.112/src\commands\logout.ts)_
200
200
 
201
201
  ## `learnpack plugins`
202
202
 
@@ -328,7 +328,7 @@ OPTIONS
328
328
  -s, --strict strict mode
329
329
  ```
330
330
 
331
- _See code: [src\commands\publish.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.110/src\commands\publish.ts)_
331
+ _See code: [src\commands\publish.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.112/src\commands\publish.ts)_
332
332
 
333
333
  ## `learnpack serve`
334
334
 
@@ -345,7 +345,7 @@ OPTIONS
345
345
  -y, --yes Skip all prompts and initialize an empty project
346
346
  ```
347
347
 
348
- _See code: [src\commands\serve.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.110/src\commands\serve.ts)_
348
+ _See code: [src\commands\serve.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.112/src\commands\serve.ts)_
349
349
 
350
350
  ## `learnpack start`
351
351
 
@@ -367,7 +367,7 @@ OPTIONS
367
367
  -y, --yes Skip all prompts and initialize an empty project
368
368
  ```
369
369
 
370
- _See code: [src\commands\start.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.110/src\commands\start.ts)_
370
+ _See code: [src\commands\start.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.112/src\commands\start.ts)_
371
371
 
372
372
  ## `learnpack test [EXERCISESLUG]`
373
373
 
@@ -384,7 +384,7 @@ OPTIONS
384
384
  -y, --yes Skip all prompts and initialize an empty project
385
385
  ```
386
386
 
387
- _See code: [src\commands\test.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.110/src\commands\test.ts)_
387
+ _See code: [src\commands\test.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.112/src\commands\test.ts)_
388
388
 
389
389
  ## `learnpack translate`
390
390
 
@@ -398,7 +398,7 @@ OPTIONS
398
398
  -y, --yes Skip all prompts and initialize an empty project
399
399
  ```
400
400
 
401
- _See code: [src\commands\translate.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.110/src\commands\translate.ts)_
401
+ _See code: [src\commands\translate.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.112/src\commands\translate.ts)_
402
402
  <!-- commandsstop -->
403
403
 
404
404
  > > > > > > > 0cb3e56d84c197f9d008836bb573eade212b7e57
@@ -134,7 +134,7 @@ class BuildCommand extends SessionCommand_1.default {
134
134
  await api_1.default.validateToken(sessionPayload.token) :
135
135
  false;
136
136
  if (!sessionExists || !isValidBreathecodeToken || !isValidToken) {
137
- 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/checkout?plan=4geeks-creator");
137
+ 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/checkout?plan=learnpack-creator");
138
138
  try {
139
139
  sessionPayload = await session_1.default.login();
140
140
  }
@@ -88683,7 +88683,7 @@ function Jfe({ onFinish: n }) {
88683
88683
  children: "You don't have an account?",
88684
88684
  }),
88685
88685
  fe.jsx("a", {
88686
- href: "https://4geeks.com/checkout?plan=4geeks-creator",
88686
+ href: "https://4geeks.com/checkout?plan=learnpack-creator",
88687
88687
  target: "_blank",
88688
88688
  className: "text-blue-600 font-medium",
88689
88689
  children: "Register here.",
@@ -10,7 +10,7 @@
10
10
  />
11
11
 
12
12
  <title>Learnpack Creator: Craft tutorials in seconds!</title>
13
- <script type="module" crossorigin src="/creator/assets/index-D386iq2u.js"></script>
13
+ <script type="module" crossorigin src="/creator/assets/index-Bw3XbAoy.js"></script>
14
14
  <link rel="stylesheet" crossorigin href="/creator/assets/index-VqUlNIHR.css">
15
15
  </head>
16
16
  <body>
@@ -1 +1 @@
1
- {"version":"5.0.110","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":{"strict":{"name":"strict","type":"boolean","char":"s","description":"strict mode","allowNo":false}},"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":{"strict":{"name":"strict","type":"boolean","char":"s","description":"strict mode","allowNo":false},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"serve":{"id":"serve","description":"Runs a small server to build tutorials","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"},"debug":{"name":"debug","type":"boolean","char":"d","description":"debugger mode for more verbage","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":[]}}}
1
+ {"version":"5.0.112","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":{"strict":{"name":"strict","type":"boolean","char":"s","description":"strict mode","allowNo":false}},"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":{"strict":{"name":"strict","type":"boolean","char":"s","description":"strict mode","allowNo":false},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"serve":{"id":"serve","description":"Runs a small server to build tutorials","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"},"debug":{"name":"debug","type":"boolean","char":"d","description":"debugger mode for more verbage","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.110",
4
+ "version": "5.0.112",
5
5
  "author": "Alejandro Sanchez @alesanchezr",
6
6
  "contributors": [
7
7
  {
@@ -1,495 +1,495 @@
1
- /* eslint-disable arrow-parens */
2
- /* eslint-disable unicorn/no-array-for-each */
3
- import { execSync } from "child_process"
4
- import { flags } from "@oclif/command"
5
- import SessionCommand from "../utils/SessionCommand"
6
- import SessionManager from "../managers/session"
7
- import * as fs from "fs"
8
- import * as path from "path"
9
- import * as archiver from "archiver"
10
- import axios from "axios"
11
- import FormData = require("form-data")
12
- import Console from "../utils/console"
13
- import {
14
- decompress,
15
- downloadEditor,
16
- checkIfDirectoryExists,
17
- } from "../managers/file"
18
- import api, { getConsumable, RIGOBOT_HOST, TAcademy } from "../utils/api"
19
- import * as prompts from "prompts"
20
- import { generateCourseShortName, isValidRigoToken } from "../utils/rigoActions"
21
- import { minutesToISO8601Duration } from "../utils/misc"
22
-
23
- const uploadZipEndpont = RIGOBOT_HOST + "/v1/learnpack/upload"
24
-
25
- export const handleAssetCreation = async (
26
- sessionPayload: any,
27
- academy: TAcademy,
28
- learnJson: any,
29
- learnpackDeployUrl: string,
30
- category: number
31
- ) => {
32
- try {
33
- const { exists, academyId } = await api.doesAssetExists(
34
- sessionPayload.token,
35
- learnJson.slug
36
- )
37
-
38
- if (!exists) {
39
- Console.info("Asset does not exist in this academy, creating it")
40
- const asset = await api.createAsset(sessionPayload.token, academy.id, {
41
- slug: learnJson.slug,
42
- title: learnJson.title.us,
43
- lang: "us",
44
- description: learnJson.description.us,
45
- learnpack_deploy_url: learnpackDeployUrl,
46
- technologies: ["node", "bash"],
47
- url: "https://4geeksacademy.com",
48
- category: category,
49
- owner: sessionPayload.id,
50
- author: sessionPayload.id,
51
- })
52
- Console.info("Asset created with id", asset.id)
53
- } else {
54
- Console.info("Asset exists, updating it")
55
- const asset = await api.updateAsset(
56
- sessionPayload.token,
57
- academyId as number,
58
- learnJson.slug,
59
- {
60
- learnpack_deploy_url: learnpackDeployUrl,
61
- title: learnJson.title.us,
62
- description: learnJson.description.us,
63
- }
64
- )
65
- Console.info("Asset updated with id", asset.id)
66
- }
67
- } catch (error) {
68
- Console.error("Error updating or creating asset:", error)
69
- }
70
- }
71
-
72
- const runAudit = (strict: boolean) => {
73
- try {
74
- Console.info("Running learnpack audit before publishing...")
75
- execSync(`learnpack audit ${strict ? "--strict" : ""}`, {
76
- stdio: "inherit",
77
- })
78
- } catch (error) {
79
- Console.error("Failed to audit with learnpack")
80
-
81
- // Si `execSync` lanza un error, capturamos el mensaje de error
82
- if (error instanceof Error) {
83
- Console.error(error.message)
84
- } else {
85
- Console.error("Unknown error occurred")
86
- }
87
-
88
- // Detener la ejecución del comando si `learnpack publish` falla
89
- process.exit(1)
90
- }
91
-
92
- // Continuar con el proceso de build solo si `learnpack publish` fue exitoso
93
- Console.info(
94
- "Learnpack publish completed successfully. Proceeding with build..."
95
- )
96
- }
97
-
98
- type Academy = {
99
- id: number
100
- name: string
101
- slug?: string
102
- timezone?: string
103
- }
104
-
105
- type Category = {
106
- id: number
107
- slug: string
108
- title: string
109
- lang: string
110
- academy: Academy
111
- }
112
-
113
- function getCategoriesByAcademy(
114
- categories: Category[],
115
- academy: Academy
116
- ): Category[] {
117
- return categories.filter((cat) => cat.academy.id === academy.id)
118
- }
119
-
120
- const selectAcademy = async (
121
- academies: TAcademy[],
122
- bcToken: string
123
- ): Promise<{ academy: TAcademy | null; category: number }> => {
124
- if (academies.length === 0) {
125
- return { academy: null, category: 0 }
126
- }
127
-
128
- if (academies.length === 1) {
129
- return { academy: academies[0], category: 0 }
130
- }
131
-
132
- // prompts the user to select an academy to upload the assets
133
- Console.info("In which academy do you want to publish the asset?")
134
- const response = await prompts({
135
- type: "select",
136
- name: "academy",
137
- message: "Select an academy",
138
- choices: academies.map((academy) => ({
139
- title: academy.name,
140
- value: academy,
141
- })),
142
- })
143
-
144
- const categories: Category[] = await api.getCategories(bcToken)
145
- const categoriesByAcademy = getCategoriesByAcademy(
146
- categories,
147
- response.academy
148
- )
149
-
150
- const categoriesPrompt = await prompts({
151
- type: "select",
152
- name: "category",
153
- message: "Select a category",
154
- choices: categoriesByAcademy.map((category) => ({
155
- title: category.title,
156
- value: category.id,
157
- })),
158
- })
159
-
160
- return {
161
- academy: response.academy,
162
- category: categoriesPrompt.category,
163
- }
164
- }
165
-
166
- class BuildCommand extends SessionCommand {
167
- static description =
168
- "Builds the project by copying necessary files and directories into a zip file"
169
-
170
- static flags = {
171
- help: flags.help({ char: "h" }),
172
- strict: flags.boolean({
173
- char: "s",
174
- description: "strict mode",
175
- default: false,
176
- }),
177
- }
178
-
179
- async init() {
180
- const { flags } = this.parse(BuildCommand)
181
- await this.initSession(flags)
182
- }
183
-
184
- async run() {
185
- const buildDir = path.join(process.cwd(), "build")
186
-
187
- const { flags }: { flags: { strict: boolean } } = this.parse(BuildCommand)
188
- const strict = flags.strict
189
- Console.debug("Strict mode: ", strict)
190
- // this.configManager?.clean()
191
-
192
- const configObject = this.configManager?.get()
193
-
194
- let sessionPayload = await SessionManager.getPayload()
195
-
196
- const sessionExists = sessionPayload && sessionPayload.rigobot
197
-
198
- const isValidToken =
199
- sessionExists && sessionPayload.rigobot.key ?
200
- await isValidRigoToken(sessionPayload.rigobot.key) :
201
- false
202
-
203
- const isValidBreathecodeToken =
204
- sessionExists && sessionPayload.token ?
205
- await api.validateToken(sessionPayload.token) :
206
- false
207
-
208
- if (!sessionExists || !isValidBreathecodeToken || !isValidToken) {
209
- Console.info(
210
- "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/checkout?plan=4geeks-creator"
211
- )
212
- try {
213
- sessionPayload = await SessionManager.login()
214
- } catch (error) {
215
- Console.error("Error trying to authenticate")
216
- Console.error((error as TypeError).message || (error as string))
217
- }
218
- }
219
-
220
- const rigoToken = sessionPayload.rigobot.key
221
-
222
- const consumable = await getConsumable(
223
- sessionPayload.token,
224
- "learnpack-publish"
225
- )
226
-
227
- if (consumable.count === 0) {
228
- Console.error(
229
- "It seems you cannot publish tutorials. 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"
230
- )
231
- process.exit(1)
232
- }
233
-
234
- if (configObject) {
235
- Console.info("Cleaning configuration files")
236
- this.configManager?.clean()
237
- // build exerises
238
- runAudit(strict)
239
-
240
- Console.debug("Building exercises")
241
- this.configManager?.buildIndex()
242
- }
243
-
244
- const academies = await api.listUserAcademies(sessionPayload.token)
245
-
246
- if (academies.length === 0) {
247
- Console.error(
248
- "It seems you cannot publish tutorials. 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"
249
- )
250
- process.exit(1)
251
- }
252
-
253
- const { academy, category } = await selectAcademy(
254
- academies,
255
- sessionPayload.token
256
- )
257
-
258
- const learnJsonPath = path.join(process.cwd(), "learn.json")
259
- if (!fs.existsSync(learnJsonPath)) {
260
- this.error("learn.json not found")
261
- }
262
-
263
- const learnJson = JSON.parse(fs.readFileSync(learnJsonPath, "utf-8"))
264
-
265
- const zipFilePath = path.join(process.cwd(), `${learnJson.slug}.zip`)
266
-
267
- // Ensure build directory exists
268
- if (!fs.existsSync(buildDir)) {
269
- fs.mkdirSync(buildDir)
270
- }
271
-
272
- if (configObject) {
273
- const { config } = configObject
274
- const appAlreadyExists = checkIfDirectoryExists(`${config?.dirPath}/_app`)
275
-
276
- if (!appAlreadyExists) {
277
- // download app and decompress
278
- await downloadEditor(
279
- config?.editor.version,
280
- `${config?.dirPath}/app.tar.gz`
281
- )
282
-
283
- Console.info("Decompressing LearnPack UI, this may take a minute...")
284
- await decompress(
285
- `${config?.dirPath}/app.tar.gz`,
286
- `${config?.dirPath}/_app/`
287
- )
288
- }
289
- }
290
-
291
- // Copy config.json
292
- const configPath = path.join(process.cwd(), ".learn", "config.json")
293
- if (fs.existsSync(configPath)) {
294
- fs.copyFileSync(configPath, path.join(buildDir, "config.json"))
295
- } else {
296
- this.error("config.json not found")
297
- }
298
-
299
- // Copy .learn/assets directory, if it exists else create it
300
- const assetsDir = path.join(process.cwd(), ".learn", "assets")
301
- if (fs.existsSync(assetsDir)) {
302
- this.copyDirectory(assetsDir, path.join(buildDir, ".learn", "assets"))
303
- } else {
304
- fs.mkdirSync(path.join(buildDir, ".learn", "assets"), { recursive: true })
305
- }
306
-
307
- // Copy .learn/_app directory files to the same level as config.json
308
- const appDir = path.join(process.cwd(), ".learn", "_app")
309
- if (fs.existsSync(appDir)) {
310
- this.copyDirectory(appDir, buildDir)
311
- } else {
312
- this.error(".learn/_app directory not found")
313
- }
314
-
315
- // After copying the _app directory
316
- const indexHtmlPath = path.join(appDir, "index.html")
317
- const buildIndexHtmlPath = path.join(buildDir, "index.html")
318
- const manifestPWA = path.join(appDir, "manifest.webmanifest")
319
- const buildManifestPWA = path.join(buildDir, "manifest.webmanifest")
320
-
321
- if (fs.existsSync(indexHtmlPath)) {
322
- let indexHtmlContent = fs.readFileSync(indexHtmlPath, "utf-8")
323
-
324
- const description = learnJson.description.us || "LearnPack is awesome!"
325
- const title =
326
- learnJson.title.us || "LearnPack: Interactive Learning as a Service"
327
-
328
- const previewUrl =
329
- learnJson.preview ||
330
- "https://raw.githubusercontent.com/learnpack/ide/refs/heads/master/public/learnpack.svg"
331
- // Replace placeholders and the <title>Old title </title> tag for a new tag with the title
332
- indexHtmlContent = indexHtmlContent
333
- .replace(/{{description}}/g, description)
334
- .replace(/<title>.*<\/title>/, `<title>${title}</title>`)
335
- .replace(/{{title}}/g, title)
336
- .replace(/{{preview}}/g, previewUrl)
337
- .replace(/{{slug}}/g, learnJson.slug)
338
- .replace(/{{duration}}/g, minutesToISO8601Duration(learnJson.duration))
339
-
340
- // Write the modified content to the build directory
341
- fs.writeFileSync(buildIndexHtmlPath, indexHtmlContent)
342
- } else {
343
- this.error("index.html not found in _app directory")
344
- }
345
-
346
- if (fs.existsSync(manifestPWA)) {
347
- let manifestPWAContent = fs.readFileSync(manifestPWA, "utf-8")
348
- manifestPWAContent = manifestPWAContent.replace(
349
- "{{course_title}}",
350
- learnJson.title.us
351
- )
352
-
353
- const courseShortName = { answer: "testing-tutorial" }
354
- // const courseShortName = await generateCourseShortName(rigoToken, {
355
- // learnJSON: JSON.stringify(learnJson),
356
- // })
357
-
358
- manifestPWAContent = manifestPWAContent.replace(
359
- "{{course_app_name}}",
360
- courseShortName.answer
361
- )
362
- fs.writeFileSync(buildManifestPWA, manifestPWAContent)
363
- } else {
364
- this.error("manifest.webmanifest not found in _app directory")
365
- }
366
-
367
- // Copy exercises directory
368
- const exercisesDir = path.join(process.cwd(), "exercises")
369
- const learnExercisesDir = path.join(process.cwd(), ".learn", "exercises")
370
-
371
- if (fs.existsSync(exercisesDir)) {
372
- this.copyDirectory(exercisesDir, path.join(buildDir, "exercises"))
373
- } else if (fs.existsSync(learnExercisesDir)) {
374
- this.copyDirectory(learnExercisesDir, path.join(buildDir, "exercises"))
375
- } else {
376
- this.error("exercises directory not found in either location")
377
- }
378
-
379
- fs.copyFileSync(learnJsonPath, path.join(buildDir, "learn.json"))
380
- const sidebarPath = path.join(process.cwd(), ".learn", "sidebar.json")
381
- if (fs.existsSync(sidebarPath)) {
382
- fs.copyFileSync(sidebarPath, path.join(buildDir, "sidebar.json"))
383
- } else {
384
- this.error("sidebar.json not found in .learn directory")
385
- }
386
-
387
- const output = fs.createWriteStream(zipFilePath)
388
- const archive = archiver("zip", {
389
- zlib: { level: 9 },
390
- })
391
-
392
- output.on("close", async () => {
393
- this.log(
394
- `Build completed: ${zipFilePath} (${archive.pointer()} total bytes)`
395
- )
396
- // Remove build directory after zip is created
397
-
398
- Console.debug("Zip file saved in project root")
399
-
400
- const formData = new FormData()
401
- formData.append("file", fs.createReadStream(zipFilePath))
402
- formData.append("config", JSON.stringify(learnJson))
403
-
404
- try {
405
- const res = await axios.post(uploadZipEndpont, formData, {
406
- headers: {
407
- ...formData.getHeaders(),
408
- Authorization: `Token ${rigoToken}`,
409
- },
410
- })
411
- console.log(res.data)
412
-
413
- fs.unlinkSync(zipFilePath)
414
- this.removeDirectory(buildDir)
415
-
416
- if (academy) {
417
- await handleAssetCreation(
418
- sessionPayload,
419
- academy,
420
- learnJson,
421
- res.data.url,
422
- category
423
- )
424
- }
425
- } catch (error) {
426
- if (axios.isAxiosError(error)) {
427
- if (error.response && error.response.status === 403) {
428
- console.error("Error 403:", error.response.data.error)
429
- } else if (error.response && error.response.status === 400) {
430
- console.error(error.response.data.error)
431
- } else {
432
- console.error("Error uploading file:", error)
433
- }
434
- } else {
435
- console.error("Error uploading file:", error)
436
- }
437
-
438
- // fs.unlinkSync(zipFilePath)
439
- // this.removeDirectory(buildDir)
440
- }
441
- })
442
-
443
- archive.on("error", (err: any) => {
444
- throw err
445
- })
446
-
447
- archive.pipe(output)
448
- archive.directory(buildDir, false)
449
- await archive.finalize()
450
- }
451
-
452
- copyDirectory(src: string, dest: string) {
453
- if (!fs.existsSync(dest)) {
454
- fs.mkdirSync(dest, { recursive: true })
455
- }
456
-
457
- const entries = fs.readdirSync(src, { withFileTypes: true })
458
-
459
- for (const entry of entries) {
460
- const srcPath = path.join(src, entry.name)
461
- const destPath = path.join(dest, entry.name)
462
-
463
- if (entry.isDirectory()) {
464
- this.copyDirectory(srcPath, destPath)
465
- } else {
466
- fs.copyFileSync(srcPath, destPath)
467
- }
468
- }
469
- }
470
-
471
- removeDirectory(dir: string) {
472
- if (fs.existsSync(dir)) {
473
- fs.readdirSync(dir).forEach((file) => {
474
- const currentPath = path.join(dir, file)
475
- if (fs.lstatSync(currentPath).isDirectory()) {
476
- this.removeDirectory(currentPath)
477
- } else {
478
- fs.unlinkSync(currentPath)
479
- }
480
- })
481
- fs.rmdirSync(dir)
482
- }
483
- }
484
- }
485
-
486
- BuildCommand.flags = {
487
- strict: flags.boolean({
488
- char: "s",
489
- description: "strict mode",
490
- default: false,
491
- }),
492
- help: flags.help({ char: "h" }),
493
- }
494
-
495
- export default BuildCommand
1
+ /* eslint-disable arrow-parens */
2
+ /* eslint-disable unicorn/no-array-for-each */
3
+ import { execSync } from "child_process"
4
+ import { flags } from "@oclif/command"
5
+ import SessionCommand from "../utils/SessionCommand"
6
+ import SessionManager from "../managers/session"
7
+ import * as fs from "fs"
8
+ import * as path from "path"
9
+ import * as archiver from "archiver"
10
+ import axios from "axios"
11
+ import FormData = require("form-data")
12
+ import Console from "../utils/console"
13
+ import {
14
+ decompress,
15
+ downloadEditor,
16
+ checkIfDirectoryExists,
17
+ } from "../managers/file"
18
+ import api, { getConsumable, RIGOBOT_HOST, TAcademy } from "../utils/api"
19
+ import * as prompts from "prompts"
20
+ import { generateCourseShortName, isValidRigoToken } from "../utils/rigoActions"
21
+ import { minutesToISO8601Duration } from "../utils/misc"
22
+
23
+ const uploadZipEndpont = RIGOBOT_HOST + "/v1/learnpack/upload"
24
+
25
+ export const handleAssetCreation = async (
26
+ sessionPayload: any,
27
+ academy: TAcademy,
28
+ learnJson: any,
29
+ learnpackDeployUrl: string,
30
+ category: number
31
+ ) => {
32
+ try {
33
+ const { exists, academyId } = await api.doesAssetExists(
34
+ sessionPayload.token,
35
+ learnJson.slug
36
+ )
37
+
38
+ if (!exists) {
39
+ Console.info("Asset does not exist in this academy, creating it")
40
+ const asset = await api.createAsset(sessionPayload.token, academy.id, {
41
+ slug: learnJson.slug,
42
+ title: learnJson.title.us,
43
+ lang: "us",
44
+ description: learnJson.description.us,
45
+ learnpack_deploy_url: learnpackDeployUrl,
46
+ technologies: ["node", "bash"],
47
+ url: "https://4geeksacademy.com",
48
+ category: category,
49
+ owner: sessionPayload.id,
50
+ author: sessionPayload.id,
51
+ })
52
+ Console.info("Asset created with id", asset.id)
53
+ } else {
54
+ Console.info("Asset exists, updating it")
55
+ const asset = await api.updateAsset(
56
+ sessionPayload.token,
57
+ academyId as number,
58
+ learnJson.slug,
59
+ {
60
+ learnpack_deploy_url: learnpackDeployUrl,
61
+ title: learnJson.title.us,
62
+ description: learnJson.description.us,
63
+ }
64
+ )
65
+ Console.info("Asset updated with id", asset.id)
66
+ }
67
+ } catch (error) {
68
+ Console.error("Error updating or creating asset:", error)
69
+ }
70
+ }
71
+
72
+ const runAudit = (strict: boolean) => {
73
+ try {
74
+ Console.info("Running learnpack audit before publishing...")
75
+ execSync(`learnpack audit ${strict ? "--strict" : ""}`, {
76
+ stdio: "inherit",
77
+ })
78
+ } catch (error) {
79
+ Console.error("Failed to audit with learnpack")
80
+
81
+ // Si `execSync` lanza un error, capturamos el mensaje de error
82
+ if (error instanceof Error) {
83
+ Console.error(error.message)
84
+ } else {
85
+ Console.error("Unknown error occurred")
86
+ }
87
+
88
+ // Detener la ejecución del comando si `learnpack publish` falla
89
+ process.exit(1)
90
+ }
91
+
92
+ // Continuar con el proceso de build solo si `learnpack publish` fue exitoso
93
+ Console.info(
94
+ "Learnpack publish completed successfully. Proceeding with build..."
95
+ )
96
+ }
97
+
98
+ type Academy = {
99
+ id: number
100
+ name: string
101
+ slug?: string
102
+ timezone?: string
103
+ }
104
+
105
+ type Category = {
106
+ id: number
107
+ slug: string
108
+ title: string
109
+ lang: string
110
+ academy: Academy
111
+ }
112
+
113
+ function getCategoriesByAcademy(
114
+ categories: Category[],
115
+ academy: Academy
116
+ ): Category[] {
117
+ return categories.filter((cat) => cat.academy.id === academy.id)
118
+ }
119
+
120
+ const selectAcademy = async (
121
+ academies: TAcademy[],
122
+ bcToken: string
123
+ ): Promise<{ academy: TAcademy | null; category: number }> => {
124
+ if (academies.length === 0) {
125
+ return { academy: null, category: 0 }
126
+ }
127
+
128
+ if (academies.length === 1) {
129
+ return { academy: academies[0], category: 0 }
130
+ }
131
+
132
+ // prompts the user to select an academy to upload the assets
133
+ Console.info("In which academy do you want to publish the asset?")
134
+ const response = await prompts({
135
+ type: "select",
136
+ name: "academy",
137
+ message: "Select an academy",
138
+ choices: academies.map((academy) => ({
139
+ title: academy.name,
140
+ value: academy,
141
+ })),
142
+ })
143
+
144
+ const categories: Category[] = await api.getCategories(bcToken)
145
+ const categoriesByAcademy = getCategoriesByAcademy(
146
+ categories,
147
+ response.academy
148
+ )
149
+
150
+ const categoriesPrompt = await prompts({
151
+ type: "select",
152
+ name: "category",
153
+ message: "Select a category",
154
+ choices: categoriesByAcademy.map((category) => ({
155
+ title: category.title,
156
+ value: category.id,
157
+ })),
158
+ })
159
+
160
+ return {
161
+ academy: response.academy,
162
+ category: categoriesPrompt.category,
163
+ }
164
+ }
165
+
166
+ class BuildCommand extends SessionCommand {
167
+ static description =
168
+ "Builds the project by copying necessary files and directories into a zip file"
169
+
170
+ static flags = {
171
+ help: flags.help({ char: "h" }),
172
+ strict: flags.boolean({
173
+ char: "s",
174
+ description: "strict mode",
175
+ default: false,
176
+ }),
177
+ }
178
+
179
+ async init() {
180
+ const { flags } = this.parse(BuildCommand)
181
+ await this.initSession(flags)
182
+ }
183
+
184
+ async run() {
185
+ const buildDir = path.join(process.cwd(), "build")
186
+
187
+ const { flags }: { flags: { strict: boolean } } = this.parse(BuildCommand)
188
+ const strict = flags.strict
189
+ Console.debug("Strict mode: ", strict)
190
+ // this.configManager?.clean()
191
+
192
+ const configObject = this.configManager?.get()
193
+
194
+ let sessionPayload = await SessionManager.getPayload()
195
+
196
+ const sessionExists = sessionPayload && sessionPayload.rigobot
197
+
198
+ const isValidToken =
199
+ sessionExists && sessionPayload.rigobot.key ?
200
+ await isValidRigoToken(sessionPayload.rigobot.key) :
201
+ false
202
+
203
+ const isValidBreathecodeToken =
204
+ sessionExists && sessionPayload.token ?
205
+ await api.validateToken(sessionPayload.token) :
206
+ false
207
+
208
+ if (!sessionExists || !isValidBreathecodeToken || !isValidToken) {
209
+ Console.info(
210
+ "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/checkout?plan=learnpack-creator"
211
+ )
212
+ try {
213
+ sessionPayload = await SessionManager.login()
214
+ } catch (error) {
215
+ Console.error("Error trying to authenticate")
216
+ Console.error((error as TypeError).message || (error as string))
217
+ }
218
+ }
219
+
220
+ const rigoToken = sessionPayload.rigobot.key
221
+
222
+ const consumable = await getConsumable(
223
+ sessionPayload.token,
224
+ "learnpack-publish"
225
+ )
226
+
227
+ if (consumable.count === 0) {
228
+ Console.error(
229
+ "It seems you cannot publish tutorials. 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"
230
+ )
231
+ process.exit(1)
232
+ }
233
+
234
+ if (configObject) {
235
+ Console.info("Cleaning configuration files")
236
+ this.configManager?.clean()
237
+ // build exerises
238
+ runAudit(strict)
239
+
240
+ Console.debug("Building exercises")
241
+ this.configManager?.buildIndex()
242
+ }
243
+
244
+ const academies = await api.listUserAcademies(sessionPayload.token)
245
+
246
+ if (academies.length === 0) {
247
+ Console.error(
248
+ "It seems you cannot publish tutorials. 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"
249
+ )
250
+ process.exit(1)
251
+ }
252
+
253
+ const { academy, category } = await selectAcademy(
254
+ academies,
255
+ sessionPayload.token
256
+ )
257
+
258
+ const learnJsonPath = path.join(process.cwd(), "learn.json")
259
+ if (!fs.existsSync(learnJsonPath)) {
260
+ this.error("learn.json not found")
261
+ }
262
+
263
+ const learnJson = JSON.parse(fs.readFileSync(learnJsonPath, "utf-8"))
264
+
265
+ const zipFilePath = path.join(process.cwd(), `${learnJson.slug}.zip`)
266
+
267
+ // Ensure build directory exists
268
+ if (!fs.existsSync(buildDir)) {
269
+ fs.mkdirSync(buildDir)
270
+ }
271
+
272
+ if (configObject) {
273
+ const { config } = configObject
274
+ const appAlreadyExists = checkIfDirectoryExists(`${config?.dirPath}/_app`)
275
+
276
+ if (!appAlreadyExists) {
277
+ // download app and decompress
278
+ await downloadEditor(
279
+ config?.editor.version,
280
+ `${config?.dirPath}/app.tar.gz`
281
+ )
282
+
283
+ Console.info("Decompressing LearnPack UI, this may take a minute...")
284
+ await decompress(
285
+ `${config?.dirPath}/app.tar.gz`,
286
+ `${config?.dirPath}/_app/`
287
+ )
288
+ }
289
+ }
290
+
291
+ // Copy config.json
292
+ const configPath = path.join(process.cwd(), ".learn", "config.json")
293
+ if (fs.existsSync(configPath)) {
294
+ fs.copyFileSync(configPath, path.join(buildDir, "config.json"))
295
+ } else {
296
+ this.error("config.json not found")
297
+ }
298
+
299
+ // Copy .learn/assets directory, if it exists else create it
300
+ const assetsDir = path.join(process.cwd(), ".learn", "assets")
301
+ if (fs.existsSync(assetsDir)) {
302
+ this.copyDirectory(assetsDir, path.join(buildDir, ".learn", "assets"))
303
+ } else {
304
+ fs.mkdirSync(path.join(buildDir, ".learn", "assets"), { recursive: true })
305
+ }
306
+
307
+ // Copy .learn/_app directory files to the same level as config.json
308
+ const appDir = path.join(process.cwd(), ".learn", "_app")
309
+ if (fs.existsSync(appDir)) {
310
+ this.copyDirectory(appDir, buildDir)
311
+ } else {
312
+ this.error(".learn/_app directory not found")
313
+ }
314
+
315
+ // After copying the _app directory
316
+ const indexHtmlPath = path.join(appDir, "index.html")
317
+ const buildIndexHtmlPath = path.join(buildDir, "index.html")
318
+ const manifestPWA = path.join(appDir, "manifest.webmanifest")
319
+ const buildManifestPWA = path.join(buildDir, "manifest.webmanifest")
320
+
321
+ if (fs.existsSync(indexHtmlPath)) {
322
+ let indexHtmlContent = fs.readFileSync(indexHtmlPath, "utf-8")
323
+
324
+ const description = learnJson.description.us || "LearnPack is awesome!"
325
+ const title =
326
+ learnJson.title.us || "LearnPack: Interactive Learning as a Service"
327
+
328
+ const previewUrl =
329
+ learnJson.preview ||
330
+ "https://raw.githubusercontent.com/learnpack/ide/refs/heads/master/public/learnpack.svg"
331
+ // Replace placeholders and the <title>Old title </title> tag for a new tag with the title
332
+ indexHtmlContent = indexHtmlContent
333
+ .replace(/{{description}}/g, description)
334
+ .replace(/<title>.*<\/title>/, `<title>${title}</title>`)
335
+ .replace(/{{title}}/g, title)
336
+ .replace(/{{preview}}/g, previewUrl)
337
+ .replace(/{{slug}}/g, learnJson.slug)
338
+ .replace(/{{duration}}/g, minutesToISO8601Duration(learnJson.duration))
339
+
340
+ // Write the modified content to the build directory
341
+ fs.writeFileSync(buildIndexHtmlPath, indexHtmlContent)
342
+ } else {
343
+ this.error("index.html not found in _app directory")
344
+ }
345
+
346
+ if (fs.existsSync(manifestPWA)) {
347
+ let manifestPWAContent = fs.readFileSync(manifestPWA, "utf-8")
348
+ manifestPWAContent = manifestPWAContent.replace(
349
+ "{{course_title}}",
350
+ learnJson.title.us
351
+ )
352
+
353
+ const courseShortName = { answer: "testing-tutorial" }
354
+ // const courseShortName = await generateCourseShortName(rigoToken, {
355
+ // learnJSON: JSON.stringify(learnJson),
356
+ // })
357
+
358
+ manifestPWAContent = manifestPWAContent.replace(
359
+ "{{course_app_name}}",
360
+ courseShortName.answer
361
+ )
362
+ fs.writeFileSync(buildManifestPWA, manifestPWAContent)
363
+ } else {
364
+ this.error("manifest.webmanifest not found in _app directory")
365
+ }
366
+
367
+ // Copy exercises directory
368
+ const exercisesDir = path.join(process.cwd(), "exercises")
369
+ const learnExercisesDir = path.join(process.cwd(), ".learn", "exercises")
370
+
371
+ if (fs.existsSync(exercisesDir)) {
372
+ this.copyDirectory(exercisesDir, path.join(buildDir, "exercises"))
373
+ } else if (fs.existsSync(learnExercisesDir)) {
374
+ this.copyDirectory(learnExercisesDir, path.join(buildDir, "exercises"))
375
+ } else {
376
+ this.error("exercises directory not found in either location")
377
+ }
378
+
379
+ fs.copyFileSync(learnJsonPath, path.join(buildDir, "learn.json"))
380
+ const sidebarPath = path.join(process.cwd(), ".learn", "sidebar.json")
381
+ if (fs.existsSync(sidebarPath)) {
382
+ fs.copyFileSync(sidebarPath, path.join(buildDir, "sidebar.json"))
383
+ } else {
384
+ this.error("sidebar.json not found in .learn directory")
385
+ }
386
+
387
+ const output = fs.createWriteStream(zipFilePath)
388
+ const archive = archiver("zip", {
389
+ zlib: { level: 9 },
390
+ })
391
+
392
+ output.on("close", async () => {
393
+ this.log(
394
+ `Build completed: ${zipFilePath} (${archive.pointer()} total bytes)`
395
+ )
396
+ // Remove build directory after zip is created
397
+
398
+ Console.debug("Zip file saved in project root")
399
+
400
+ const formData = new FormData()
401
+ formData.append("file", fs.createReadStream(zipFilePath))
402
+ formData.append("config", JSON.stringify(learnJson))
403
+
404
+ try {
405
+ const res = await axios.post(uploadZipEndpont, formData, {
406
+ headers: {
407
+ ...formData.getHeaders(),
408
+ Authorization: `Token ${rigoToken}`,
409
+ },
410
+ })
411
+ console.log(res.data)
412
+
413
+ fs.unlinkSync(zipFilePath)
414
+ this.removeDirectory(buildDir)
415
+
416
+ if (academy) {
417
+ await handleAssetCreation(
418
+ sessionPayload,
419
+ academy,
420
+ learnJson,
421
+ res.data.url,
422
+ category
423
+ )
424
+ }
425
+ } catch (error) {
426
+ if (axios.isAxiosError(error)) {
427
+ if (error.response && error.response.status === 403) {
428
+ console.error("Error 403:", error.response.data.error)
429
+ } else if (error.response && error.response.status === 400) {
430
+ console.error(error.response.data.error)
431
+ } else {
432
+ console.error("Error uploading file:", error)
433
+ }
434
+ } else {
435
+ console.error("Error uploading file:", error)
436
+ }
437
+
438
+ // fs.unlinkSync(zipFilePath)
439
+ // this.removeDirectory(buildDir)
440
+ }
441
+ })
442
+
443
+ archive.on("error", (err: any) => {
444
+ throw err
445
+ })
446
+
447
+ archive.pipe(output)
448
+ archive.directory(buildDir, false)
449
+ await archive.finalize()
450
+ }
451
+
452
+ copyDirectory(src: string, dest: string) {
453
+ if (!fs.existsSync(dest)) {
454
+ fs.mkdirSync(dest, { recursive: true })
455
+ }
456
+
457
+ const entries = fs.readdirSync(src, { withFileTypes: true })
458
+
459
+ for (const entry of entries) {
460
+ const srcPath = path.join(src, entry.name)
461
+ const destPath = path.join(dest, entry.name)
462
+
463
+ if (entry.isDirectory()) {
464
+ this.copyDirectory(srcPath, destPath)
465
+ } else {
466
+ fs.copyFileSync(srcPath, destPath)
467
+ }
468
+ }
469
+ }
470
+
471
+ removeDirectory(dir: string) {
472
+ if (fs.existsSync(dir)) {
473
+ fs.readdirSync(dir).forEach((file) => {
474
+ const currentPath = path.join(dir, file)
475
+ if (fs.lstatSync(currentPath).isDirectory()) {
476
+ this.removeDirectory(currentPath)
477
+ } else {
478
+ fs.unlinkSync(currentPath)
479
+ }
480
+ })
481
+ fs.rmdirSync(dir)
482
+ }
483
+ }
484
+ }
485
+
486
+ BuildCommand.flags = {
487
+ strict: flags.boolean({
488
+ char: "s",
489
+ description: "strict mode",
490
+ default: false,
491
+ }),
492
+ help: flags.help({ char: "h" }),
493
+ }
494
+
495
+ export default BuildCommand
@@ -136,7 +136,7 @@ export default function Login({ onFinish }: { onFinish: () => void }) {
136
136
  <div className="bg-blue-50 text-sm p-2 rounded text-left">
137
137
  <p className="text-gray-700 m-0">You don't have an account?</p>
138
138
  <a
139
- href="https://4geeks.com/checkout?plan=4geeks-creator"
139
+ href="https://4geeks.com/checkout?plan=learnpack-creator"
140
140
  target="_blank"
141
141
  className="text-blue-600 font-medium"
142
142
  >
@@ -88683,7 +88683,7 @@ function Jfe({ onFinish: n }) {
88683
88683
  children: "You don't have an account?",
88684
88684
  }),
88685
88685
  fe.jsx("a", {
88686
- href: "https://4geeks.com/checkout?plan=4geeks-creator",
88686
+ href: "https://4geeks.com/checkout?plan=learnpack-creator",
88687
88687
  target: "_blank",
88688
88688
  className: "text-blue-600 font-medium",
88689
88689
  children: "Register here.",
@@ -10,7 +10,7 @@
10
10
  />
11
11
 
12
12
  <title>Learnpack Creator: Craft tutorials in seconds!</title>
13
- <script type="module" crossorigin src="/creator/assets/index-D386iq2u.js"></script>
13
+ <script type="module" crossorigin src="/creator/assets/index-Bw3XbAoy.js"></script>
14
14
  <link rel="stylesheet" crossorigin href="/creator/assets/index-VqUlNIHR.css">
15
15
  </head>
16
16
  <body>