@learnpack/learnpack 2.1.25 → 2.1.27

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. package/README.md +16 -16
  2. package/bin/run +17 -17
  3. package/bin/run.cmd +3 -3
  4. package/oclif.manifest.json +1 -1
  5. package/package.json +139 -138
  6. package/src/commands/audit.ts +134 -109
  7. package/src/commands/clean.ts +29 -29
  8. package/src/commands/download.ts +62 -62
  9. package/src/commands/init.ts +39 -39
  10. package/src/commands/login.ts +42 -42
  11. package/src/commands/logout.ts +43 -43
  12. package/src/commands/publish.ts +107 -107
  13. package/src/commands/start.ts +264 -234
  14. package/src/commands/test.ts +85 -85
  15. package/src/index.ts +1 -1
  16. package/src/managers/config/allowed_files.ts +29 -29
  17. package/src/managers/config/defaults.ts +4 -2
  18. package/src/managers/config/exercise.ts +309 -302
  19. package/src/managers/config/index.ts +159 -138
  20. package/src/managers/file.ts +178 -169
  21. package/src/managers/gitpod.ts +84 -84
  22. package/src/managers/server/index.ts +78 -69
  23. package/src/managers/server/routes.ts +139 -90
  24. package/src/managers/session.ts +147 -118
  25. package/src/managers/socket.ts +252 -239
  26. package/src/managers/test.ts +83 -83
  27. package/src/models/action.ts +10 -3
  28. package/src/models/config-manager.ts +23 -23
  29. package/src/models/config.ts +9 -2
  30. package/src/models/counter.ts +11 -11
  31. package/src/models/errors.ts +22 -22
  32. package/src/models/exercise-obj.ts +6 -3
  33. package/src/models/file.ts +5 -5
  34. package/src/models/findings.ts +18 -18
  35. package/src/models/flags.ts +10 -10
  36. package/src/models/front-matter.ts +11 -11
  37. package/src/models/gitpod-data.ts +19 -19
  38. package/src/models/language.ts +4 -4
  39. package/src/models/package.ts +7 -7
  40. package/src/models/plugin-config.ts +17 -17
  41. package/src/models/session.ts +29 -26
  42. package/src/models/socket.ts +54 -48
  43. package/src/models/status.ts +16 -15
  44. package/src/models/success-types.ts +1 -1
  45. package/src/plugin/command/compile.ts +17 -17
  46. package/src/plugin/command/test.ts +30 -30
  47. package/src/plugin/index.ts +6 -6
  48. package/src/plugin/plugin.ts +94 -94
  49. package/src/plugin/utils.ts +87 -87
  50. package/src/types/node-fetch.d.ts +1 -1
  51. package/src/ui/download.ts +71 -71
  52. package/src/utils/BaseCommand.ts +48 -48
  53. package/src/utils/SessionCommand.ts +48 -48
  54. package/src/utils/api.ts +246 -194
  55. package/src/utils/audit.ts +392 -395
  56. package/src/utils/console.ts +24 -24
  57. package/src/utils/errors.ts +117 -117
  58. package/src/utils/exercisesQueue.ts +51 -51
  59. package/src/utils/fileQueue.ts +198 -198
  60. package/src/utils/misc.ts +23 -23
  61. package/src/utils/templates/gitignore.txt +19 -19
  62. package/src/utils/templates/incremental/.learn/exercises/01-hello-world/README.es.md +24 -24
  63. package/src/utils/templates/incremental/.learn/exercises/01-hello-world/README.md +24 -24
  64. package/src/utils/templates/incremental/README.ejs +4 -4
  65. package/src/utils/templates/incremental/README.es.ejs +4 -4
  66. package/src/utils/templates/isolated/01-hello-world/README.es.md +26 -26
  67. package/src/utils/templates/isolated/01-hello-world/README.md +26 -26
  68. package/src/utils/templates/isolated/README.ejs +4 -4
  69. package/src/utils/templates/isolated/README.es.ejs +4 -4
  70. package/src/utils/templates/no-grading/README.ejs +4 -4
  71. package/src/utils/templates/no-grading/README.es.ejs +4 -4
  72. package/src/utils/validators.ts +18 -18
  73. package/src/utils/watcher.ts +14 -14
  74. package/lib/commands/audit.d.ts +0 -6
  75. package/lib/commands/audit.js +0 -317
  76. package/lib/commands/clean.d.ts +0 -8
  77. package/lib/commands/clean.js +0 -25
  78. package/lib/commands/download.d.ts +0 -13
  79. package/lib/commands/download.js +0 -55
  80. package/lib/commands/init.d.ts +0 -9
  81. package/lib/commands/init.js +0 -123
  82. package/lib/commands/login.d.ts +0 -14
  83. package/lib/commands/login.js +0 -37
  84. package/lib/commands/logout.d.ts +0 -14
  85. package/lib/commands/logout.js +0 -37
  86. package/lib/commands/publish.d.ts +0 -14
  87. package/lib/commands/publish.js +0 -82
  88. package/lib/commands/start.d.ts +0 -7
  89. package/lib/commands/start.js +0 -165
  90. package/lib/commands/test.d.ts +0 -6
  91. package/lib/commands/test.js +0 -62
  92. package/lib/index.d.ts +0 -1
  93. package/lib/index.js +0 -4
  94. package/lib/managers/config/allowed_files.d.ts +0 -5
  95. package/lib/managers/config/allowed_files.js +0 -30
  96. package/lib/managers/config/defaults.d.ts +0 -37
  97. package/lib/managers/config/defaults.js +0 -38
  98. package/lib/managers/config/exercise.d.ts +0 -36
  99. package/lib/managers/config/exercise.js +0 -230
  100. package/lib/managers/config/index.d.ts +0 -3
  101. package/lib/managers/config/index.js +0 -302
  102. package/lib/managers/file.d.ts +0 -13
  103. package/lib/managers/file.js +0 -134
  104. package/lib/managers/gitpod.d.ts +0 -3
  105. package/lib/managers/gitpod.js +0 -67
  106. package/lib/managers/server/index.d.ts +0 -6
  107. package/lib/managers/server/index.js +0 -51
  108. package/lib/managers/server/routes.d.ts +0 -4
  109. package/lib/managers/server/routes.js +0 -167
  110. package/lib/managers/session.d.ts +0 -3
  111. package/lib/managers/session.js +0 -104
  112. package/lib/managers/socket.d.ts +0 -3
  113. package/lib/managers/socket.js +0 -164
  114. package/lib/managers/test.d.ts +0 -0
  115. package/lib/managers/test.js +0 -84
  116. package/lib/models/action.d.ts +0 -2
  117. package/lib/models/action.js +0 -2
  118. package/lib/models/audit.d.ts +0 -15
  119. package/lib/models/audit.js +0 -2
  120. package/lib/models/config-manager.d.ts +0 -21
  121. package/lib/models/config-manager.js +0 -2
  122. package/lib/models/config.d.ts +0 -60
  123. package/lib/models/config.js +0 -2
  124. package/lib/models/counter.d.ts +0 -11
  125. package/lib/models/counter.js +0 -2
  126. package/lib/models/errors.d.ts +0 -15
  127. package/lib/models/errors.js +0 -2
  128. package/lib/models/exercise-obj.d.ts +0 -27
  129. package/lib/models/exercise-obj.js +0 -2
  130. package/lib/models/file.d.ts +0 -5
  131. package/lib/models/file.js +0 -2
  132. package/lib/models/findings.d.ts +0 -17
  133. package/lib/models/findings.js +0 -2
  134. package/lib/models/flags.d.ts +0 -10
  135. package/lib/models/flags.js +0 -2
  136. package/lib/models/front-matter.d.ts +0 -11
  137. package/lib/models/front-matter.js +0 -2
  138. package/lib/models/gitpod-data.d.ts +0 -16
  139. package/lib/models/gitpod-data.js +0 -2
  140. package/lib/models/language.d.ts +0 -4
  141. package/lib/models/language.js +0 -2
  142. package/lib/models/package.d.ts +0 -7
  143. package/lib/models/package.js +0 -2
  144. package/lib/models/plugin-config.d.ts +0 -16
  145. package/lib/models/plugin-config.js +0 -2
  146. package/lib/models/session.d.ts +0 -23
  147. package/lib/models/session.js +0 -2
  148. package/lib/models/socket.d.ts +0 -31
  149. package/lib/models/socket.js +0 -2
  150. package/lib/models/status.d.ts +0 -1
  151. package/lib/models/status.js +0 -2
  152. package/lib/models/success-types.d.ts +0 -1
  153. package/lib/models/success-types.js +0 -2
  154. package/lib/plugin/command/compile.d.ts +0 -6
  155. package/lib/plugin/command/compile.js +0 -18
  156. package/lib/plugin/command/test.d.ts +0 -6
  157. package/lib/plugin/command/test.js +0 -25
  158. package/lib/plugin/index.d.ts +0 -27
  159. package/lib/plugin/index.js +0 -7
  160. package/lib/plugin/plugin.d.ts +0 -8
  161. package/lib/plugin/plugin.js +0 -68
  162. package/lib/plugin/utils.d.ts +0 -16
  163. package/lib/plugin/utils.js +0 -58
  164. package/lib/ui/download.d.ts +0 -5
  165. package/lib/ui/download.js +0 -61
  166. package/lib/utils/BaseCommand.d.ts +0 -8
  167. package/lib/utils/BaseCommand.js +0 -41
  168. package/lib/utils/SessionCommand.d.ts +0 -10
  169. package/lib/utils/SessionCommand.js +0 -47
  170. package/lib/utils/api.d.ts +0 -12
  171. package/lib/utils/api.js +0 -173
  172. package/lib/utils/audit.d.ts +0 -16
  173. package/lib/utils/audit.js +0 -302
  174. package/lib/utils/console.d.ts +0 -12
  175. package/lib/utils/console.js +0 -19
  176. package/lib/utils/errors.d.ts +0 -17
  177. package/lib/utils/errors.js +0 -100
  178. package/lib/utils/exercisesQueue.d.ts +0 -9
  179. package/lib/utils/exercisesQueue.js +0 -38
  180. package/lib/utils/fileQueue.d.ts +0 -40
  181. package/lib/utils/fileQueue.js +0 -168
  182. package/lib/utils/misc.d.ts +0 -1
  183. package/lib/utils/misc.js +0 -23
  184. package/lib/utils/validators.d.ts +0 -5
  185. package/lib/utils/validators.js +0 -17
  186. package/lib/utils/watcher.d.ts +0 -2
  187. package/lib/utils/watcher.js +0 -23
@@ -1,302 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const console_1 = require("./console");
4
- const fs = require("fs");
5
- const path = require("path");
6
- // eslint-disable-next-line
7
- const fetch = require("node-fetch");
8
- // eslint-disable-next-line
9
- const fm = require("front-matter");
10
- // This function checks if a url is valid.
11
- const isUrl = async (url, errors, counter) => {
12
- const regexUrl = /(https?:\/\/[\w./-]+)/gm;
13
- counter.links.total++;
14
- if (!regexUrl.test(url)) {
15
- counter.links.error++;
16
- errors.push({
17
- exercise: undefined,
18
- msg: `The repository value of the configuration file is not a link: ${url}`,
19
- });
20
- return false;
21
- }
22
- const res = await fetch(url, { method: "HEAD" });
23
- if (!res.ok) {
24
- counter.links.error++;
25
- errors.push({
26
- exercise: undefined,
27
- msg: `The link of the repository is broken: ${url}`,
28
- });
29
- }
30
- return true;
31
- };
32
- const checkForEmptySpaces = (str) => {
33
- const isEmpty = true;
34
- for (const letter of str) {
35
- if (letter !== " ") {
36
- return false;
37
- }
38
- }
39
- return isEmpty;
40
- };
41
- const checkLearnpackClean = (configObj, errors) => {
42
- var _a, _b, _c, _d, _e, _f, _g, _h;
43
- if ((((_a = configObj.config) === null || _a === void 0 ? void 0 : _a.outputPath) &&
44
- fs.existsSync((_b = configObj.config) === null || _b === void 0 ? void 0 : _b.outputPath)) ||
45
- fs.existsSync(`${(_c = configObj.config) === null || _c === void 0 ? void 0 : _c.dirPath}/_app`) ||
46
- fs.existsSync(`${(_d = configObj.config) === null || _d === void 0 ? void 0 : _d.dirPath}/reports`) ||
47
- fs.existsSync(`${(_e = configObj.config) === null || _e === void 0 ? void 0 : _e.dirPath}/resets`) ||
48
- fs.existsSync(`${(_f = configObj.config) === null || _f === void 0 ? void 0 : _f.dirPath}/app.tar.gz`) ||
49
- fs.existsSync(`${(_g = configObj.config) === null || _g === void 0 ? void 0 : _g.dirPath}/config.json`) ||
50
- fs.existsSync(`${(_h = configObj.config) === null || _h === void 0 ? void 0 : _h.dirPath}/vscode_queue.json`)) {
51
- errors.push({
52
- exercise: undefined,
53
- msg: "You have to run learnpack clean command",
54
- });
55
- }
56
- };
57
- const findInFile = (types, content) => {
58
- const regex = {
59
- relativeImages: /!\[.*]\s*\((((\.\/)?(\.{2}\/){1,5})(.*\/)*(.[^\s/]*\.[A-Za-z]{2,4})\S*)\)/gm,
60
- externalImages: /!\[.*]\((https?:\/(\/[^)/]+)+\/?)\)/gm,
61
- markdownLinks: /(\s)+\[.*]\((https?:\/(\/[^)/]+)+\/?)\)/gm,
62
- url: /(https?:\/\/[\w./-]+)/gm,
63
- uploadcare: /https:\/\/ucarecdn.com\/(?:.*\/)*([\w./-]+)/gm,
64
- };
65
- const validTypes = Object.keys(regex);
66
- if (!Array.isArray(types))
67
- types = [types];
68
- const findings = {};
69
- for (const type of types) {
70
- if (!validTypes.includes(type))
71
- throw new Error("Invalid type: " + type);
72
- else
73
- findings[type] = {};
74
- }
75
- for (const type of types) {
76
- let m;
77
- while ((m = regex[type].exec(content)) !== null) {
78
- // This is necessary to avoid infinite loops with zero-width matches
79
- if (m.index === regex.lastIndex) {
80
- regex.lastIndex++;
81
- }
82
- // The result can be accessed through the `m`-variable.
83
- // m.forEach((match, groupIndex) => values.push(match));
84
- findings[type][m[0]] = {
85
- content: m[0],
86
- absUrl: m[1],
87
- mdUrl: m[2],
88
- relUrl: m[6],
89
- };
90
- }
91
- }
92
- return findings;
93
- };
94
- // This function checks that each of the url's are working.
95
- const checkUrl = async (config, filePath, fileName, exercise, errors, warnings, counter) => {
96
- var _a, _b, _c, _d;
97
- if (!fs.existsSync(filePath))
98
- return false;
99
- const content = fs.readFileSync(filePath).toString();
100
- const isEmpty = checkForEmptySpaces(content);
101
- if (isEmpty || !content)
102
- errors.push({
103
- exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
104
- msg: `This file (${fileName}) doesn't have any content inside.`,
105
- });
106
- const frontmatter = fm(content);
107
- for (const attribute in frontmatter.attributes) {
108
- if (Object.prototype.hasOwnProperty.call(frontmatter.attributes, attribute) &&
109
- (attribute === "intro" || attribute === "tutorial")) {
110
- counter && counter.links.total++;
111
- try {
112
- // eslint-disable-next-line
113
- let res = await fetch(frontmatter.attributes[attribute], {
114
- method: "HEAD",
115
- });
116
- if (!res.ok) {
117
- counter && counter.links.error++;
118
- errors.push({
119
- exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
120
- msg: `This link is broken (${res.ok}): ${frontmatter.attributes[attribute]}`,
121
- });
122
- }
123
- }
124
- catch (_e) {
125
- counter && counter.links.error++;
126
- errors.push({
127
- exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
128
- msg: `This link is broken: ${frontmatter.attributes[attribute]}`,
129
- });
130
- }
131
- }
132
- }
133
- // Check url's of each README file.
134
- const findings = findInFile(["relativeImages", "externalImages", "markdownLinks"], content);
135
- for (const finding in findings) {
136
- if (Object.prototype.hasOwnProperty.call(findings, finding)) {
137
- const obj = findings[finding];
138
- // Valdites all the relative path images.
139
- if (finding === "relativeImages" && Object.keys(obj).length > 0) {
140
- for (const img in obj) {
141
- if (Object.prototype.hasOwnProperty.call(obj, img)) {
142
- // Validates if the image is in the assets folder.
143
- counter && counter.images.total++;
144
- const relativePath = path
145
- .relative(exercise ? exercise.path.replace(/\\/gm, "/") : "./", `${(_a = config.config) === null || _a === void 0 ? void 0 : _a.dirPath}/assets/${obj[img].relUrl}`)
146
- .replace(/\\/gm, "/");
147
- if (relativePath !== obj[img].absUrl.split("?").shift()) {
148
- counter && counter.images.error++;
149
- errors.push({
150
- exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
151
- msg: `This relative path (${obj[img].relUrl}) is not pointing to the assets folder.`,
152
- });
153
- }
154
- if (!fs.existsSync(`${(_b = config.config) === null || _b === void 0 ? void 0 : _b.dirPath}/assets/${obj[img].relUrl}`)) {
155
- counter && counter.images.error++;
156
- errors.push({
157
- exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
158
- msg: `The file ${obj[img].relUrl} doesn't exist in the assets folder.`,
159
- });
160
- }
161
- }
162
- }
163
- }
164
- else if (finding === "externalImages" && Object.keys(obj).length > 0) {
165
- // Valdites all the aboslute path images.
166
- for (const img in obj) {
167
- if (Object.prototype.hasOwnProperty.call(obj, img)) {
168
- counter && counter.images.total++;
169
- if (fs.existsSync(`${(_c = config.config) === null || _c === void 0 ? void 0 : _c.dirPath}/assets${obj[img].mdUrl
170
- .split("?")
171
- .shift()}`)) {
172
- const relativePath = path
173
- .relative(exercise ? exercise.path.replace(/\\/gm, "/") : "./", `${(_d = config.config) === null || _d === void 0 ? void 0 : _d.dirPath}/assets/${obj[img].mdUrl}`)
174
- .replace(/\\/gm, "/");
175
- warnings.push({
176
- exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
177
- msg: `On this exercise you have an image with an absolute path "${obj[img].absUrl}". We recommend you to replace it by the relative path: "${relativePath}".`,
178
- });
179
- }
180
- try {
181
- // eslint-disable-next-line
182
- let res = await fetch(obj[img].absUrl, {
183
- method: "HEAD",
184
- });
185
- if (!res.ok) {
186
- counter && counter.images.error++;
187
- errors.push({
188
- exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
189
- msg: `This link is broken: ${obj[img].absUrl}`,
190
- });
191
- }
192
- }
193
- catch (_f) {
194
- counter && counter.images.error++;
195
- errors.push({
196
- exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
197
- msg: `This link is broken: ${obj[img].absUrl}`,
198
- });
199
- }
200
- }
201
- }
202
- }
203
- else if (finding === "markdownLinks" && Object.keys(obj).length > 0) {
204
- for (const link in obj) {
205
- if (Object.prototype.hasOwnProperty.call(obj, link)) {
206
- counter && counter.links.total++;
207
- if (!obj[link].mdUrl.includes("twitter")) {
208
- try {
209
- // eslint-disable-next-line
210
- let res = await fetch(obj[link].mdUrl, {
211
- method: "HEAD",
212
- });
213
- if (res.status > 399 && res.status < 500) {
214
- counter && counter.links.error++;
215
- errors.push({
216
- exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
217
- msg: `This link is broken: ${obj[link].mdUrl}`,
218
- });
219
- }
220
- }
221
- catch (_g) {
222
- counter && counter.links.error++;
223
- errors.push({
224
- exercise: exercise === null || exercise === void 0 ? void 0 : exercise.title,
225
- msg: `This link is broken: ${obj[link].mdUrl}`,
226
- });
227
- }
228
- }
229
- }
230
- }
231
- }
232
- }
233
- }
234
- return true;
235
- };
236
- // This function writes a given file with the given content.
237
- const writeFile = async (content, filePath) => {
238
- try {
239
- await fs.promises.writeFile(filePath, content);
240
- }
241
- catch (error) {
242
- if (error)
243
- console_1.default.error(`We weren't able to write the file in this path "${filePath}".`, error);
244
- }
245
- };
246
- // This function checks if there are errors, and show them in the console at the end.
247
- const showErrors = (errors, counter) => {
248
- return new Promise((resolve, reject) => {
249
- if (errors) {
250
- if (errors.length > 0) {
251
- console_1.default.log("Checking for errors...");
252
- for (const [i, error] of errors.entries())
253
- console_1.default.error(`${i + 1}) ${error.msg} ${error.exercise ? `(Exercise: ${error.exercise})` : ""}`);
254
- if (counter) {
255
- console_1.default.error(` We found ${errors.length} error${errors.length > 1 ? "s" : ""} among ${counter.images.total} images, ${counter.links.total} link, ${counter.readmeFiles} README files and ${counter.exercises} exercises.`);
256
- }
257
- else {
258
- console_1.default.error(` We found ${errors.length} error${errors.length > 1 ? "s" : ""} related with the project integrity.`);
259
- }
260
- process.exit(1);
261
- }
262
- else {
263
- if (counter) {
264
- console_1.default.success(`We didn't find any errors in this repository among ${counter.images.total} images, ${counter.links.total} link, ${counter.readmeFiles} README files and ${counter.exercises} exercises.`);
265
- }
266
- else {
267
- console_1.default.success(`We didn't find any errors in this repository.`);
268
- }
269
- process.exit(0);
270
- }
271
- }
272
- else {
273
- reject("Failed");
274
- }
275
- });
276
- };
277
- // This function checks if there are warnings, and show them in the console at the end.
278
- const showWarnings = (warnings) => {
279
- return new Promise((resolve, reject) => {
280
- if (warnings) {
281
- if (warnings.length > 0) {
282
- console_1.default.log("Checking for warnings...");
283
- for (const [i, warning] of warnings.entries())
284
- console_1.default.warning(`${i + 1}) ${warning.msg} ${warning.exercise ? `File: ${warning.exercise}` : ""}`);
285
- }
286
- resolve("SUCCESS");
287
- }
288
- else {
289
- reject("Failed");
290
- }
291
- });
292
- };
293
- exports.default = {
294
- isUrl,
295
- checkForEmptySpaces,
296
- checkLearnpackClean,
297
- findInFile,
298
- checkUrl,
299
- writeFile,
300
- showErrors,
301
- showWarnings,
302
- };
@@ -1,12 +0,0 @@
1
- declare const _default: {
2
- _debug: boolean;
3
- startDebug: () => void;
4
- log: (msg: string | Array<string>, ...args: Array<any>) => void;
5
- error: (msg: string, ...args: Array<any>) => void;
6
- success: (msg: string, ...args: Array<any>) => void;
7
- info: (msg: string, ...args: Array<any>) => void;
8
- help: (msg: string) => void;
9
- debug(...args: Array<any>): void;
10
- warning: (msg: string) => void;
11
- };
12
- export default _default;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const chalk = require("chalk");
4
- exports.default = {
5
- // _debug: true,
6
- _debug: process.env.DEBUG === 'true',
7
- startDebug: function () {
8
- this._debug = true;
9
- },
10
- log: (msg, ...args) => console.log(chalk.gray(msg), ...args),
11
- error: (msg, ...args) => console.log(chalk.red('⨉ ' + msg), ...args),
12
- success: (msg, ...args) => console.log(chalk.green('✓ ' + msg), ...args),
13
- info: (msg, ...args) => console.log(chalk.blue('ⓘ ' + msg), ...args),
14
- help: (msg) => console.log(`${chalk.white.bold('⚠ help:')} ${chalk.white(msg)}`),
15
- debug(...args) {
16
- this._debug && console.log(chalk.magentaBright('⚠ debug: '), args);
17
- },
18
- warning: (msg) => console.log(`${chalk.yellow('⚠ warning:')} ${chalk.yellow(msg)}`),
19
- };
@@ -1,17 +0,0 @@
1
- import { ISolution, IError } from '../models/errors';
2
- export declare const getSolution: (slug?: string | undefined) => ISolution;
3
- export declare const ValidationError: (error: IError | string) => IError;
4
- export declare const NotFoundError: (error: IError | string) => IError;
5
- export declare const CompilerError: (error: IError | string) => IError;
6
- export declare const TestingError: (error: IError | string) => IError;
7
- export declare const AuthError: (error: IError | string) => IError;
8
- export declare const InternalError: (error: IError | string) => IError;
9
- declare const _default: {
10
- ValidationError: (error: string | IError) => IError;
11
- CompilerError: (error: string | IError) => IError;
12
- TestingError: (error: string | IError) => IError;
13
- NotFoundError: (error: string | IError) => IError;
14
- InternalError: (error: string | IError) => IError;
15
- AuthError: (error: string | IError) => IError;
16
- };
17
- export default _default;
@@ -1,100 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InternalError = exports.AuthError = exports.TestingError = exports.CompilerError = exports.NotFoundError = exports.ValidationError = exports.getSolution = void 0;
4
- const console_1 = require("./console");
5
- // eslint-disable-next-line
6
- const fetch = require("node-fetch");
7
- let solutions = null;
8
- const uknown = {
9
- video: 'https://www.youtube.com/watch?v=gD1Sa99GiE4',
10
- message: 'Uknown internal error',
11
- slug: 'uknown',
12
- gif: 'https://github.com/breatheco-de/breathecode-cli/blob/master/docs/errors/uknown.gif?raw=true',
13
- };
14
- exports.getSolution = (slug) => {
15
- if (!slug) {
16
- console_1.default.debug('Getting solution templates from the learnpack repository');
17
- }
18
- else {
19
- console_1.default.debug(`Getting solution for ${slug}`, solutions);
20
- }
21
- if (!solutions) {
22
- console_1.default.debug('Fetching for errors.json on github');
23
- fetch('https://raw.githubusercontent.com/breatheco-de/breathecode-cli/master/docs/errors/errors.json')
24
- .then((r) => r.json())
25
- .then(function (_s) {
26
- solutions = _s;
27
- });
28
- return uknown;
29
- }
30
- return typeof solutions[slug || ''] === 'undefined' || !slug ?
31
- uknown :
32
- solutions[slug];
33
- };
34
- exports.ValidationError = (error) => {
35
- const message = error.message || error;
36
- const _err = new Error(message);
37
- _err.status = 400;
38
- _err.type = 'validation-error';
39
- const sol = exports.getSolution(error.slug);
40
- _err.video = sol.video;
41
- _err.gif = sol.gif;
42
- _err.message = typeof message === 'string' ? message : sol.message;
43
- return _err;
44
- };
45
- exports.NotFoundError = (error) => {
46
- const message = error.message || error;
47
- const _err = new Error(message);
48
- _err.status = 400;
49
- _err.type = 'not-found-error';
50
- const sol = exports.getSolution(error.slug);
51
- _err.video = sol.video;
52
- _err.gif = sol.gif;
53
- _err.message = typeof message === 'string' ? message : sol.message;
54
- return _err;
55
- };
56
- exports.CompilerError = (error) => {
57
- const message = error.message || error;
58
- const _err = new Error(message);
59
- _err.status = 400;
60
- _err.type = 'compiler-error';
61
- const sol = exports.getSolution(error.slug);
62
- _err.video = sol.video;
63
- _err.gif = sol.gif;
64
- _err.message = typeof message === 'string' ? message : sol.message;
65
- return _err;
66
- };
67
- exports.TestingError = (error) => {
68
- const message = error.message || error;
69
- const _err = new Error(message);
70
- _err.status = 400;
71
- _err.type = 'testing-error';
72
- return _err;
73
- };
74
- exports.AuthError = (error) => {
75
- const message = error.message || error;
76
- const _err = new Error(message);
77
- _err.status = 403;
78
- _err.type = 'auth-error';
79
- return _err;
80
- };
81
- exports.InternalError = (error) => {
82
- const message = error.message || error;
83
- const _err = new Error(message);
84
- _err.status = 500;
85
- _err.type = 'internal-error';
86
- const sol = exports.getSolution(error.slug);
87
- _err.video = sol.video;
88
- _err.gif = sol.gif;
89
- _err.message = typeof message === 'string' ? message : sol.message;
90
- return _err;
91
- };
92
- exports.getSolution();
93
- exports.default = {
94
- ValidationError: exports.ValidationError,
95
- CompilerError: exports.CompilerError,
96
- TestingError: exports.TestingError,
97
- NotFoundError: exports.NotFoundError,
98
- InternalError: exports.InternalError,
99
- AuthError: exports.AuthError,
100
- };
@@ -1,9 +0,0 @@
1
- import { IExercise } from "../models/exercise-obj";
2
- declare class ExercisesQueue {
3
- exercises: IExercise[];
4
- constructor(exercises: any);
5
- pop(): IExercise | undefined;
6
- isEmpty(): boolean;
7
- size(): number;
8
- }
9
- export default ExercisesQueue;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class Exercise {
4
- constructor(exercise) {
5
- this.exercise = exercise;
6
- }
7
- test(sessionConfig, config, socket) {
8
- if (this.exercise.language) {
9
- socket.log("testing", `Testing exercise ${this.exercise.slug} using ${this.exercise.language} engine`);
10
- sessionConfig.runHook("action", {
11
- action: "test",
12
- socket,
13
- configuration: config,
14
- exercise: this.exercise,
15
- });
16
- }
17
- else {
18
- socket.onTestingFinished({ result: "success" });
19
- }
20
- }
21
- }
22
- class ExercisesQueue {
23
- constructor(exercises) {
24
- this.exercises = exercises.map((exercise) => {
25
- return new Exercise(exercise);
26
- });
27
- }
28
- pop() {
29
- return this.exercises.shift();
30
- }
31
- isEmpty() {
32
- return this.size() === 0;
33
- }
34
- size() {
35
- return this.exercises.length;
36
- }
37
- }
38
- exports.default = ExercisesQueue;
@@ -1,40 +0,0 @@
1
- declare const _default: {
2
- events: {
3
- START_EXERCISE: string;
4
- INIT: string;
5
- RUNNING: string;
6
- END: string;
7
- RESET_EXERCISE: string;
8
- OPEN_FILES: string;
9
- OPEN_WINDOW: string;
10
- INSTRUCTIONS_CLOSED: string;
11
- };
12
- dispatcher: (opts?: any) => {
13
- enqueue: (name: string, data?: any) => void;
14
- events: {
15
- START_EXERCISE: string;
16
- INIT: string;
17
- RUNNING: string;
18
- END: string;
19
- RESET_EXERCISE: string;
20
- OPEN_FILES: string;
21
- OPEN_WINDOW: string;
22
- INSTRUCTIONS_CLOSED: string;
23
- };
24
- };
25
- listener: (opts?: any) => {
26
- onPull: (callback: (T?: any) => any) => boolean;
27
- onReset: (callback: (T?: any) => any) => boolean;
28
- events: {
29
- START_EXERCISE: string;
30
- INIT: string;
31
- RUNNING: string;
32
- END: string;
33
- RESET_EXERCISE: string;
34
- OPEN_FILES: string;
35
- OPEN_WINDOW: string;
36
- INSTRUCTIONS_CLOSED: string;
37
- };
38
- };
39
- };
40
- export default _default;