@learnpack/learnpack 5.0.275 → 5.0.277

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.
Files changed (95) hide show
  1. package/README.md +409 -409
  2. package/lib/commands/audit.js +15 -15
  3. package/lib/commands/breakToken.js +19 -19
  4. package/lib/commands/clean.js +3 -3
  5. package/lib/commands/init.js +41 -41
  6. package/lib/commands/logout.js +3 -3
  7. package/lib/commands/publish.js +5 -10
  8. package/lib/commands/serve.js +55 -2
  9. package/lib/creatorDist/assets/index-BfLyIQVh.js +10343 -10224
  10. package/lib/managers/config/index.js +77 -77
  11. package/lib/utils/api.d.ts +1 -1
  12. package/lib/utils/api.js +12 -9
  13. package/lib/utils/creatorUtilities.js +14 -14
  14. package/lib/utils/export/epub.d.ts +2 -0
  15. package/lib/utils/export/epub.js +298 -0
  16. package/lib/utils/export/index.d.ts +3 -0
  17. package/lib/utils/export/index.js +7 -0
  18. package/lib/utils/export/scorm.d.ts +2 -0
  19. package/lib/utils/export/scorm.js +84 -0
  20. package/lib/utils/export/shared.d.ts +4 -0
  21. package/lib/utils/export/shared.js +61 -0
  22. package/lib/utils/export/types.d.ts +15 -0
  23. package/lib/utils/export/types.js +2 -0
  24. package/package.json +2 -1
  25. package/src/commands/audit.ts +487 -487
  26. package/src/commands/breakToken.ts +67 -67
  27. package/src/commands/clean.ts +30 -30
  28. package/src/commands/init.ts +650 -650
  29. package/src/commands/logout.ts +38 -38
  30. package/src/commands/publish.ts +20 -25
  31. package/src/commands/serve.ts +69 -4
  32. package/src/commands/start.ts +333 -333
  33. package/src/commands/translate.ts +123 -123
  34. package/src/creator/README.md +54 -54
  35. package/src/creator/eslint.config.js +7 -7
  36. package/src/creator/src/components/syllabus/ContentIndex.tsx +312 -312
  37. package/src/creator/src/i18n.ts +28 -28
  38. package/src/creator/src/index.css +217 -217
  39. package/src/creator/src/locales/en.json +126 -126
  40. package/src/creator/src/locales/es.json +126 -126
  41. package/src/creator/src/utils/configTypes.ts +122 -122
  42. package/src/creator/src/utils/constants.ts +13 -13
  43. package/src/creator/src/utils/creatorUtils.ts +46 -46
  44. package/src/creator/src/utils/eventBus.ts +2 -2
  45. package/src/creator/src/utils/lib.ts +468 -468
  46. package/src/creator/src/utils/socket.ts +61 -61
  47. package/src/creator/src/utils/store.ts +222 -222
  48. package/src/creator/src/vite-env.d.ts +1 -1
  49. package/src/creator/vite.config.ts +13 -13
  50. package/src/creatorDist/assets/index-BfLyIQVh.js +10343 -10224
  51. package/src/managers/config/defaults.ts +49 -49
  52. package/src/managers/config/exercise.ts +364 -364
  53. package/src/managers/config/index.ts +775 -775
  54. package/src/managers/file.ts +236 -236
  55. package/src/managers/server/routes.ts +554 -554
  56. package/src/managers/session.ts +182 -182
  57. package/src/managers/telemetry.ts +188 -188
  58. package/src/models/action.ts +13 -13
  59. package/src/models/config-manager.ts +28 -28
  60. package/src/models/config.ts +106 -106
  61. package/src/models/creator.ts +47 -47
  62. package/src/models/exercise-obj.ts +30 -30
  63. package/src/models/session.ts +39 -39
  64. package/src/models/socket.ts +61 -61
  65. package/src/models/status.ts +16 -16
  66. package/src/ui/_app/app.css +1 -1
  67. package/src/ui/_app/app.js +400 -397
  68. package/src/ui/app.tar.gz +0 -0
  69. package/src/utils/BaseCommand.ts +56 -56
  70. package/src/utils/api.ts +53 -39
  71. package/src/utils/audit.ts +392 -392
  72. package/src/utils/checkNotInstalled.ts +267 -267
  73. package/src/utils/configBuilder.ts +82 -82
  74. package/src/utils/convertCreds.js +34 -34
  75. package/src/utils/creatorUtilities.ts +504 -504
  76. package/src/utils/export/README.md +178 -0
  77. package/src/utils/export/epub.ts +400 -0
  78. package/src/utils/export/index.ts +3 -0
  79. package/src/utils/export/scorm.ts +121 -0
  80. package/src/utils/export/shared.ts +61 -0
  81. package/src/utils/export/types.ts +17 -0
  82. package/src/utils/incrementVersion.js +74 -74
  83. package/src/utils/misc.ts +58 -58
  84. package/src/utils/rigoActions.ts +500 -500
  85. package/src/utils/sidebarGenerator.ts +195 -195
  86. package/src/utils/templates/epub/epub.css +133 -0
  87. package/src/utils/templates/isolated/exercises/01-hello-world/README.es.md +26 -26
  88. package/src/utils/templates/isolated/exercises/01-hello-world/README.md +26 -26
  89. package/src/utils/templates/scorm/adlcp_rootv1p2.xsd +110 -0
  90. package/src/utils/templates/scorm/config/api.js +175 -0
  91. package/src/utils/templates/scorm/config/index.html +210 -0
  92. package/src/utils/templates/scorm/ims_xml.xsd +1 -0
  93. package/src/utils/templates/scorm/imscp_rootv1p1p2.xsd +345 -0
  94. package/src/utils/templates/scorm/imsmanifest.xml +38 -0
  95. package/src/utils/templates/scorm/imsmd_rootv1p2p1.xsd +573 -0
@@ -1,267 +1,267 @@
1
- import { IExercise } from "../models/exercise-obj"
2
- import { promisify } from "util"
3
- import { exec as execCallback } from "child_process"
4
-
5
- const exec = promisify(execCallback)
6
-
7
- import { cli } from "cli-ux"
8
- import Console from "./console"
9
-
10
- type TNeededPlugins = {
11
- needed: string[]
12
- notInstalled: string[]
13
- }
14
- type TPackageManager = "npm" | "pip"
15
-
16
- export const checkNotInstalledPlugins = async (
17
- exercises: IExercise[],
18
- installedPlugins: string[],
19
- command: any
20
- ): Promise<TNeededPlugins> => {
21
- Console.info("Checking needed plugins...")
22
- const usefulExtensions = new Set(["py", "js", "jsx", "html"])
23
- const foundExtensions: string[] = []
24
- const testingExtensions: string[] = []
25
- const neededPlugins: string[] = []
26
- let someExerciseWithOnlyTestFile = false // I will suppose that there are not exercises with only readme and test files
27
-
28
- // See the extensions of the files that are not tests files
29
- for (const e of exercises) {
30
- const notReadmeFiles = e.files.filter(
31
- f => !f.name.toLowerCase().includes("readme")
32
- )
33
-
34
- if (!someExerciseWithOnlyTestFile && notReadmeFiles.length > 0) {
35
- someExerciseWithOnlyTestFile = notReadmeFiles.every(f => {
36
- return f.name.includes("test")
37
- })
38
-
39
- if (someExerciseWithOnlyTestFile) {
40
- Console.debug(
41
- "Some exercises have only test files, I will install the @learnpack/node plugin to run the tests."
42
- )
43
- }
44
- }
45
-
46
- for (const f of notReadmeFiles) {
47
- const ext = f.name.split(".").pop()
48
- if (!ext)
49
- continue
50
-
51
- if (f.name.includes("test")) {
52
- !testingExtensions.includes(ext) && testingExtensions.push(ext)
53
- continue
54
- }
55
-
56
- if (usefulExtensions.has(ext) && !foundExtensions.includes(ext)) {
57
- foundExtensions.push(ext)
58
- }
59
- }
60
- }
61
-
62
- Console.debug("foundExtensions", foundExtensions)
63
- Console.debug("testingExtensions", testingExtensions)
64
-
65
- if (foundExtensions.length === 0 && testingExtensions.length === 0)
66
- return {
67
- needed: [],
68
- notInstalled: [],
69
- }
70
-
71
- if (foundExtensions.includes("html") && foundExtensions.includes("js")) {
72
- neededPlugins.push("@learnpack/dom")
73
- }
74
-
75
- if (foundExtensions.includes("html") && !foundExtensions.includes("js")) {
76
- neededPlugins.push("@learnpack/html")
77
- }
78
-
79
- if (foundExtensions.includes("jsx")) {
80
- neededPlugins.push("@learnpack/react")
81
- }
82
-
83
- if (foundExtensions.includes("py") || testingExtensions.includes("py")) {
84
- neededPlugins.push("@learnpack/python")
85
- }
86
-
87
- if (
88
- (foundExtensions.includes("js") && !foundExtensions.includes("html")) ||
89
- (testingExtensions.includes("js") && someExerciseWithOnlyTestFile)
90
- ) {
91
- neededPlugins.push("@learnpack/node")
92
- }
93
-
94
- const notInstalled = neededPlugins.filter(
95
- item => !installedPlugins.includes(item)
96
- )
97
-
98
- if (notInstalled.length > 0) {
99
- Console.error(
100
- "These plugins are not installed but required: ",
101
- notInstalled
102
- )
103
- const confirmInstall = await cli.confirm(
104
- "Do you want to install the needed plugins? (y/n)"
105
- )
106
- if (confirmInstall) {
107
- Console.info("Installing the needed plugins...")
108
- for await (const p of notInstalled) {
109
- await command.config.runCommand(`plugins:install`, [p])
110
- Console.log(`Plugin ${p} installed`)
111
- }
112
-
113
- Console.log(
114
- "All needed plugins installed, please restart LearnPack to load them."
115
- )
116
- Console.info("Run: $ learnpack start")
117
- command.exit(0)
118
- } else {
119
- Console.error("You need to install the plugins to complete this exercise")
120
- Console.info(
121
- "To install the plugins run each of the following commands: "
122
- )
123
- for (const p of notInstalled) {
124
- Console.log(`learnpack plugins:install ${p}`)
125
- }
126
-
127
- command.exit(1)
128
- }
129
- }
130
-
131
- return {
132
- needed: neededPlugins,
133
- notInstalled,
134
- }
135
- }
136
-
137
- function includesAll(baseString: string, elementsArray: string[]) {
138
- return elementsArray.every(element => baseString.includes(element))
139
- }
140
-
141
- const installDependencies = async (
142
- deps: string[],
143
- packageManager: TPackageManager
144
- ) => {
145
- let command = ""
146
- if (packageManager === "npm") {
147
- command = `npm install -g ${deps.join(" ")}`
148
- } else if (packageManager === "pip") {
149
- command = `pip install ${deps.join(" ")}`
150
- }
151
-
152
- const { stdout, stderr } = await exec(command)
153
- if (stderr && (stderr.includes("npm ERR!") || stderr.includes("Traceback"))) {
154
- Console.error(`Error executing ${command}.`)
155
- Console.error(stderr)
156
- return
157
- }
158
-
159
- Console.info(`Dependencies ${deps.join(" ")} installed...`)
160
- return true
161
- }
162
-
163
- export const checkNotInstalledDependencies = async (
164
- neededPlugins: string[]
165
- ) => {
166
- Console.info("Checking needed dependencies...")
167
-
168
- const jsPluginsDependencies = ["jest@29.7.0", "jest-environment-jsdom@29.7.0"]
169
- // pytest up to 6.2.5
170
- const pyPluginsDependencies = ["pytest", "pytest-testdox", "mock"]
171
-
172
- const npmLsCommand = "npm ls jest jest-environment-jsdom -g"
173
-
174
- let pytestNeeded = false
175
- let jestNeeded = false
176
-
177
- if (
178
- neededPlugins.includes("@learnpack/dom") ||
179
- neededPlugins.includes("@learnpack/html") ||
180
- neededPlugins.includes("@learnpack/react") ||
181
- neededPlugins.includes("@learnpack/node")
182
- ) {
183
- jestNeeded = true
184
- }
185
-
186
- if (neededPlugins.includes("@learnpack/python")) {
187
- pytestNeeded = true
188
- }
189
-
190
- if (jestNeeded) {
191
- const { stdout, stderr } = await exec("npm ls -g")
192
- if (stderr) {
193
- Console.error(`Error executing ${npmLsCommand}. Use debug for more info`)
194
- Console.debug(stderr)
195
- return false
196
- }
197
-
198
- if (includesAll(stdout, jsPluginsDependencies))
199
- return true
200
-
201
- Console.error("The jest dependencies are not installed")
202
- const confirmInstall = await cli.confirm(
203
- "Do you want to install the needed dependencies? (y/n)"
204
- )
205
-
206
- if (!confirmInstall) {
207
- Console.error(
208
- `The exercises can't be tested without the following dependencies: ${jsPluginsDependencies.join(
209
- ", "
210
- )}`
211
- )
212
- Console.info(
213
- `Please install them and try again. Run the following command to install them: \nnpm install -g ${jsPluginsDependencies.join(
214
- " "
215
- )}`
216
- )
217
- return false
218
- }
219
-
220
- Console.log("Installing jest dependencies...")
221
- await installDependencies(jsPluginsDependencies, "npm")
222
- }
223
-
224
- if (pytestNeeded) {
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
- }
233
-
234
- const { stdout, stderr } = await exec("pip list")
235
- if (stderr) {
236
- Console.error(`Error executing pip list. Use debug for more info`)
237
- Console.debug(stderr)
238
- return
239
- }
240
-
241
- if (includesAll(stdout, pyPluginsDependencies))
242
- return true
243
-
244
- Console.error("The pytest dependencies are not installed")
245
- const confirmInstall = await cli.confirm(
246
- "Do you want to install the needed dependencies? (y/n)"
247
- )
248
- if (!confirmInstall) {
249
- Console.error(
250
- `The exercises can't be tested without the following dependencies: ${pyPluginsDependencies.join(
251
- ", "
252
- )}`
253
- )
254
- Console.info(
255
- `Please install them and try again. Run the following command to install them: \npip install ${pyPluginsDependencies.join(
256
- " "
257
- )}`
258
- )
259
- return false
260
- }
261
-
262
- Console.log("Installing pytest dependencies...")
263
- await installDependencies(pyPluginsDependencies, "pip")
264
- }
265
-
266
- return true
267
- }
1
+ import { IExercise } from "../models/exercise-obj"
2
+ import { promisify } from "util"
3
+ import { exec as execCallback } from "child_process"
4
+
5
+ const exec = promisify(execCallback)
6
+
7
+ import { cli } from "cli-ux"
8
+ import Console from "./console"
9
+
10
+ type TNeededPlugins = {
11
+ needed: string[]
12
+ notInstalled: string[]
13
+ }
14
+ type TPackageManager = "npm" | "pip"
15
+
16
+ export const checkNotInstalledPlugins = async (
17
+ exercises: IExercise[],
18
+ installedPlugins: string[],
19
+ command: any
20
+ ): Promise<TNeededPlugins> => {
21
+ Console.info("Checking needed plugins...")
22
+ const usefulExtensions = new Set(["py", "js", "jsx", "html"])
23
+ const foundExtensions: string[] = []
24
+ const testingExtensions: string[] = []
25
+ const neededPlugins: string[] = []
26
+ let someExerciseWithOnlyTestFile = false // I will suppose that there are not exercises with only readme and test files
27
+
28
+ // See the extensions of the files that are not tests files
29
+ for (const e of exercises) {
30
+ const notReadmeFiles = e.files.filter(
31
+ f => !f.name.toLowerCase().includes("readme")
32
+ )
33
+
34
+ if (!someExerciseWithOnlyTestFile && notReadmeFiles.length > 0) {
35
+ someExerciseWithOnlyTestFile = notReadmeFiles.every(f => {
36
+ return f.name.includes("test")
37
+ })
38
+
39
+ if (someExerciseWithOnlyTestFile) {
40
+ Console.debug(
41
+ "Some exercises have only test files, I will install the @learnpack/node plugin to run the tests."
42
+ )
43
+ }
44
+ }
45
+
46
+ for (const f of notReadmeFiles) {
47
+ const ext = f.name.split(".").pop()
48
+ if (!ext)
49
+ continue
50
+
51
+ if (f.name.includes("test")) {
52
+ !testingExtensions.includes(ext) && testingExtensions.push(ext)
53
+ continue
54
+ }
55
+
56
+ if (usefulExtensions.has(ext) && !foundExtensions.includes(ext)) {
57
+ foundExtensions.push(ext)
58
+ }
59
+ }
60
+ }
61
+
62
+ Console.debug("foundExtensions", foundExtensions)
63
+ Console.debug("testingExtensions", testingExtensions)
64
+
65
+ if (foundExtensions.length === 0 && testingExtensions.length === 0)
66
+ return {
67
+ needed: [],
68
+ notInstalled: [],
69
+ }
70
+
71
+ if (foundExtensions.includes("html") && foundExtensions.includes("js")) {
72
+ neededPlugins.push("@learnpack/dom")
73
+ }
74
+
75
+ if (foundExtensions.includes("html") && !foundExtensions.includes("js")) {
76
+ neededPlugins.push("@learnpack/html")
77
+ }
78
+
79
+ if (foundExtensions.includes("jsx")) {
80
+ neededPlugins.push("@learnpack/react")
81
+ }
82
+
83
+ if (foundExtensions.includes("py") || testingExtensions.includes("py")) {
84
+ neededPlugins.push("@learnpack/python")
85
+ }
86
+
87
+ if (
88
+ (foundExtensions.includes("js") && !foundExtensions.includes("html")) ||
89
+ (testingExtensions.includes("js") && someExerciseWithOnlyTestFile)
90
+ ) {
91
+ neededPlugins.push("@learnpack/node")
92
+ }
93
+
94
+ const notInstalled = neededPlugins.filter(
95
+ item => !installedPlugins.includes(item)
96
+ )
97
+
98
+ if (notInstalled.length > 0) {
99
+ Console.error(
100
+ "These plugins are not installed but required: ",
101
+ notInstalled
102
+ )
103
+ const confirmInstall = await cli.confirm(
104
+ "Do you want to install the needed plugins? (y/n)"
105
+ )
106
+ if (confirmInstall) {
107
+ Console.info("Installing the needed plugins...")
108
+ for await (const p of notInstalled) {
109
+ await command.config.runCommand(`plugins:install`, [p])
110
+ Console.log(`Plugin ${p} installed`)
111
+ }
112
+
113
+ Console.log(
114
+ "All needed plugins installed, please restart LearnPack to load them."
115
+ )
116
+ Console.info("Run: $ learnpack start")
117
+ command.exit(0)
118
+ } else {
119
+ Console.error("You need to install the plugins to complete this exercise")
120
+ Console.info(
121
+ "To install the plugins run each of the following commands: "
122
+ )
123
+ for (const p of notInstalled) {
124
+ Console.log(`learnpack plugins:install ${p}`)
125
+ }
126
+
127
+ command.exit(1)
128
+ }
129
+ }
130
+
131
+ return {
132
+ needed: neededPlugins,
133
+ notInstalled,
134
+ }
135
+ }
136
+
137
+ function includesAll(baseString: string, elementsArray: string[]) {
138
+ return elementsArray.every(element => baseString.includes(element))
139
+ }
140
+
141
+ const installDependencies = async (
142
+ deps: string[],
143
+ packageManager: TPackageManager
144
+ ) => {
145
+ let command = ""
146
+ if (packageManager === "npm") {
147
+ command = `npm install -g ${deps.join(" ")}`
148
+ } else if (packageManager === "pip") {
149
+ command = `pip install ${deps.join(" ")}`
150
+ }
151
+
152
+ const { stdout, stderr } = await exec(command)
153
+ if (stderr && (stderr.includes("npm ERR!") || stderr.includes("Traceback"))) {
154
+ Console.error(`Error executing ${command}.`)
155
+ Console.error(stderr)
156
+ return
157
+ }
158
+
159
+ Console.info(`Dependencies ${deps.join(" ")} installed...`)
160
+ return true
161
+ }
162
+
163
+ export const checkNotInstalledDependencies = async (
164
+ neededPlugins: string[]
165
+ ) => {
166
+ Console.info("Checking needed dependencies...")
167
+
168
+ const jsPluginsDependencies = ["jest@29.7.0", "jest-environment-jsdom@29.7.0"]
169
+ // pytest up to 6.2.5
170
+ const pyPluginsDependencies = ["pytest", "pytest-testdox", "mock"]
171
+
172
+ const npmLsCommand = "npm ls jest jest-environment-jsdom -g"
173
+
174
+ let pytestNeeded = false
175
+ let jestNeeded = false
176
+
177
+ if (
178
+ neededPlugins.includes("@learnpack/dom") ||
179
+ neededPlugins.includes("@learnpack/html") ||
180
+ neededPlugins.includes("@learnpack/react") ||
181
+ neededPlugins.includes("@learnpack/node")
182
+ ) {
183
+ jestNeeded = true
184
+ }
185
+
186
+ if (neededPlugins.includes("@learnpack/python")) {
187
+ pytestNeeded = true
188
+ }
189
+
190
+ if (jestNeeded) {
191
+ const { stdout, stderr } = await exec("npm ls -g")
192
+ if (stderr) {
193
+ Console.error(`Error executing ${npmLsCommand}. Use debug for more info`)
194
+ Console.debug(stderr)
195
+ return false
196
+ }
197
+
198
+ if (includesAll(stdout, jsPluginsDependencies))
199
+ return true
200
+
201
+ Console.error("The jest dependencies are not installed")
202
+ const confirmInstall = await cli.confirm(
203
+ "Do you want to install the needed dependencies? (y/n)"
204
+ )
205
+
206
+ if (!confirmInstall) {
207
+ Console.error(
208
+ `The exercises can't be tested without the following dependencies: ${jsPluginsDependencies.join(
209
+ ", "
210
+ )}`
211
+ )
212
+ Console.info(
213
+ `Please install them and try again. Run the following command to install them: \nnpm install -g ${jsPluginsDependencies.join(
214
+ " "
215
+ )}`
216
+ )
217
+ return false
218
+ }
219
+
220
+ Console.log("Installing jest dependencies...")
221
+ await installDependencies(jsPluginsDependencies, "npm")
222
+ }
223
+
224
+ if (pytestNeeded) {
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
+ }
233
+
234
+ const { stdout, stderr } = await exec("pip list")
235
+ if (stderr) {
236
+ Console.error(`Error executing pip list. Use debug for more info`)
237
+ Console.debug(stderr)
238
+ return
239
+ }
240
+
241
+ if (includesAll(stdout, pyPluginsDependencies))
242
+ return true
243
+
244
+ Console.error("The pytest dependencies are not installed")
245
+ const confirmInstall = await cli.confirm(
246
+ "Do you want to install the needed dependencies? (y/n)"
247
+ )
248
+ if (!confirmInstall) {
249
+ Console.error(
250
+ `The exercises can't be tested without the following dependencies: ${pyPluginsDependencies.join(
251
+ ", "
252
+ )}`
253
+ )
254
+ Console.info(
255
+ `Please install them and try again. Run the following command to install them: \npip install ${pyPluginsDependencies.join(
256
+ " "
257
+ )}`
258
+ )
259
+ return false
260
+ }
261
+
262
+ Console.log("Installing pytest dependencies...")
263
+ await installDependencies(pyPluginsDependencies, "pip")
264
+ }
265
+
266
+ return true
267
+ }