@learnpack/learnpack 5.0.274 → 5.0.275

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 (70) 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/serve.js +127 -70
  8. package/lib/creatorDist/assets/index-BfLyIQVh.js +10223 -10342
  9. package/lib/managers/config/index.js +77 -77
  10. package/lib/models/creator.d.ts +7 -0
  11. package/lib/utils/api.d.ts +1 -0
  12. package/lib/utils/api.js +2 -1
  13. package/lib/utils/creatorUtilities.js +14 -14
  14. package/package.json +1 -1
  15. package/src/commands/audit.ts +487 -487
  16. package/src/commands/breakToken.ts +67 -67
  17. package/src/commands/clean.ts +30 -30
  18. package/src/commands/init.ts +650 -650
  19. package/src/commands/logout.ts +38 -38
  20. package/src/commands/publish.ts +522 -522
  21. package/src/commands/serve.ts +162 -107
  22. package/src/commands/start.ts +333 -333
  23. package/src/commands/translate.ts +123 -123
  24. package/src/creator/README.md +54 -54
  25. package/src/creator/eslint.config.js +28 -28
  26. package/src/creator/src/components/syllabus/ContentIndex.tsx +312 -312
  27. package/src/creator/src/i18n.ts +28 -28
  28. package/src/creator/src/index.css +217 -217
  29. package/src/creator/src/locales/en.json +126 -126
  30. package/src/creator/src/locales/es.json +126 -126
  31. package/src/creator/src/utils/configTypes.ts +122 -122
  32. package/src/creator/src/utils/constants.ts +13 -13
  33. package/src/creator/src/utils/creatorUtils.ts +46 -46
  34. package/src/creator/src/utils/eventBus.ts +2 -2
  35. package/src/creator/src/utils/lib.ts +468 -468
  36. package/src/creator/src/utils/socket.ts +61 -61
  37. package/src/creator/src/utils/store.ts +222 -222
  38. package/src/creator/src/vite-env.d.ts +1 -1
  39. package/src/creator/vite.config.ts +13 -13
  40. package/src/creatorDist/assets/index-BfLyIQVh.js +10223 -10342
  41. package/src/managers/config/defaults.ts +49 -49
  42. package/src/managers/config/exercise.ts +364 -364
  43. package/src/managers/config/index.ts +775 -775
  44. package/src/managers/file.ts +236 -236
  45. package/src/managers/server/routes.ts +554 -554
  46. package/src/managers/session.ts +182 -182
  47. package/src/managers/telemetry.ts +188 -188
  48. package/src/models/action.ts +13 -13
  49. package/src/models/config-manager.ts +28 -28
  50. package/src/models/config.ts +106 -106
  51. package/src/models/creator.ts +47 -40
  52. package/src/models/exercise-obj.ts +30 -30
  53. package/src/models/session.ts +39 -39
  54. package/src/models/socket.ts +61 -61
  55. package/src/models/status.ts +16 -16
  56. package/src/ui/_app/app.js +141 -141
  57. package/src/ui/app.tar.gz +0 -0
  58. package/src/utils/BaseCommand.ts +56 -56
  59. package/src/utils/api.ts +31 -30
  60. package/src/utils/audit.ts +392 -392
  61. package/src/utils/checkNotInstalled.ts +267 -267
  62. package/src/utils/configBuilder.ts +82 -82
  63. package/src/utils/convertCreds.js +34 -34
  64. package/src/utils/creatorUtilities.ts +504 -504
  65. package/src/utils/incrementVersion.js +74 -74
  66. package/src/utils/misc.ts +58 -58
  67. package/src/utils/rigoActions.ts +500 -500
  68. package/src/utils/sidebarGenerator.ts +195 -195
  69. package/src/utils/templates/isolated/exercises/01-hello-world/README.es.md +26 -26
  70. package/src/utils/templates/isolated/exercises/01-hello-world/README.md +26 -26
@@ -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
+ }