@learnpack/learnpack 2.1.27 → 2.1.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. package/README.md +10 -10
  2. package/lib/commands/audit.d.ts +6 -0
  3. package/lib/commands/audit.js +342 -0
  4. package/lib/commands/clean.d.ts +8 -0
  5. package/lib/commands/clean.js +25 -0
  6. package/lib/commands/download.d.ts +13 -0
  7. package/lib/commands/download.js +55 -0
  8. package/lib/commands/init.d.ts +9 -0
  9. package/lib/commands/init.js +123 -0
  10. package/lib/commands/login.d.ts +14 -0
  11. package/lib/commands/login.js +37 -0
  12. package/lib/commands/logout.d.ts +14 -0
  13. package/lib/commands/logout.js +37 -0
  14. package/lib/commands/publish.d.ts +14 -0
  15. package/lib/commands/publish.js +82 -0
  16. package/lib/commands/start.d.ts +7 -0
  17. package/lib/commands/start.js +176 -0
  18. package/lib/commands/test.d.ts +6 -0
  19. package/lib/commands/test.js +62 -0
  20. package/lib/index.d.ts +1 -0
  21. package/lib/index.js +4 -0
  22. package/lib/managers/config/allowed_files.d.ts +5 -0
  23. package/lib/managers/config/allowed_files.js +30 -0
  24. package/lib/managers/config/defaults.d.ts +39 -0
  25. package/lib/managers/config/defaults.js +40 -0
  26. package/lib/managers/config/exercise.d.ts +36 -0
  27. package/lib/managers/config/exercise.js +233 -0
  28. package/lib/managers/config/index.d.ts +3 -0
  29. package/lib/managers/config/index.js +320 -0
  30. package/lib/managers/file.d.ts +14 -0
  31. package/lib/managers/file.js +141 -0
  32. package/lib/managers/gitpod.d.ts +3 -0
  33. package/lib/managers/gitpod.js +67 -0
  34. package/lib/managers/server/index.d.ts +6 -0
  35. package/lib/managers/server/index.js +58 -0
  36. package/lib/managers/server/routes.d.ts +4 -0
  37. package/lib/managers/server/routes.js +201 -0
  38. package/lib/managers/session.d.ts +3 -0
  39. package/lib/managers/session.js +131 -0
  40. package/lib/managers/socket.d.ts +3 -0
  41. package/lib/managers/socket.js +178 -0
  42. package/lib/managers/test.d.ts +0 -0
  43. package/lib/managers/test.js +84 -0
  44. package/lib/models/action.d.ts +2 -0
  45. package/lib/models/action.js +2 -0
  46. package/lib/models/audit.d.ts +15 -0
  47. package/lib/models/audit.js +2 -0
  48. package/lib/models/config-manager.d.ts +21 -0
  49. package/lib/models/config-manager.js +2 -0
  50. package/lib/models/config.d.ts +62 -0
  51. package/lib/models/config.js +2 -0
  52. package/lib/models/counter.d.ts +11 -0
  53. package/lib/models/counter.js +2 -0
  54. package/lib/models/errors.d.ts +15 -0
  55. package/lib/models/errors.js +2 -0
  56. package/lib/models/exercise-obj.d.ts +30 -0
  57. package/lib/models/exercise-obj.js +2 -0
  58. package/lib/models/file.d.ts +5 -0
  59. package/lib/models/file.js +2 -0
  60. package/lib/models/findings.d.ts +17 -0
  61. package/lib/models/findings.js +2 -0
  62. package/lib/models/flags.d.ts +10 -0
  63. package/lib/models/flags.js +2 -0
  64. package/lib/models/front-matter.d.ts +11 -0
  65. package/lib/models/front-matter.js +2 -0
  66. package/lib/models/gitpod-data.d.ts +16 -0
  67. package/lib/models/gitpod-data.js +2 -0
  68. package/lib/models/language.d.ts +4 -0
  69. package/lib/models/language.js +2 -0
  70. package/lib/models/package.d.ts +7 -0
  71. package/lib/models/package.js +2 -0
  72. package/lib/models/plugin-config.d.ts +16 -0
  73. package/lib/models/plugin-config.js +2 -0
  74. package/lib/models/session.d.ts +26 -0
  75. package/lib/models/session.js +2 -0
  76. package/lib/models/socket.d.ts +32 -0
  77. package/lib/models/socket.js +2 -0
  78. package/lib/models/status.d.ts +1 -0
  79. package/lib/models/status.js +2 -0
  80. package/lib/models/success-types.d.ts +1 -0
  81. package/lib/models/success-types.js +2 -0
  82. package/lib/plugin/command/compile.d.ts +6 -0
  83. package/lib/plugin/command/compile.js +18 -0
  84. package/lib/plugin/command/test.d.ts +6 -0
  85. package/lib/plugin/command/test.js +25 -0
  86. package/lib/plugin/index.d.ts +27 -0
  87. package/lib/plugin/index.js +7 -0
  88. package/lib/plugin/plugin.d.ts +8 -0
  89. package/lib/plugin/plugin.js +68 -0
  90. package/lib/plugin/utils.d.ts +16 -0
  91. package/lib/plugin/utils.js +58 -0
  92. package/lib/ui/download.d.ts +5 -0
  93. package/lib/ui/download.js +61 -0
  94. package/lib/utils/BaseCommand.d.ts +8 -0
  95. package/lib/utils/BaseCommand.js +41 -0
  96. package/lib/utils/SessionCommand.d.ts +10 -0
  97. package/lib/utils/SessionCommand.js +47 -0
  98. package/lib/utils/api.d.ts +14 -0
  99. package/lib/utils/api.js +218 -0
  100. package/lib/utils/audit.d.ts +16 -0
  101. package/lib/utils/audit.js +302 -0
  102. package/lib/utils/console.d.ts +12 -0
  103. package/lib/utils/console.js +19 -0
  104. package/lib/utils/errors.d.ts +17 -0
  105. package/lib/utils/errors.js +100 -0
  106. package/lib/utils/exercisesQueue.d.ts +9 -0
  107. package/lib/utils/exercisesQueue.js +38 -0
  108. package/lib/utils/fileQueue.d.ts +40 -0
  109. package/lib/utils/fileQueue.js +168 -0
  110. package/lib/utils/misc.d.ts +1 -0
  111. package/lib/utils/misc.js +23 -0
  112. package/lib/utils/validators.d.ts +5 -0
  113. package/lib/utils/validators.js +17 -0
  114. package/lib/utils/watcher.d.ts +2 -0
  115. package/lib/utils/watcher.js +23 -0
  116. package/oclif.manifest.json +1 -1
  117. package/package.json +2 -1
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/2.1.27 darwin-arm64 node-v16.20.0
24
+ @learnpack/learnpack/2.1.29 darwin-arm64 node-v16.20.0
25
25
  $ learnpack --help [COMMAND]
26
26
  USAGE
27
27
  $ learnpack COMMAND
@@ -74,7 +74,7 @@ DESCRIPTION
74
74
  12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)
75
75
  ```
76
76
 
77
- _See code: [src/commands/audit.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.27/src/commands/audit.ts)_
77
+ _See code: [src/commands/audit.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.29/src/commands/audit.ts)_
78
78
 
79
79
  ## `learnpack clean`
80
80
 
@@ -89,7 +89,7 @@ DESCRIPTION
89
89
  Extra documentation goes here
90
90
  ```
91
91
 
92
- _See code: [src/commands/clean.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.27/src/commands/clean.ts)_
92
+ _See code: [src/commands/clean.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.29/src/commands/clean.ts)_
93
93
 
94
94
  ## `learnpack download [PACKAGE]`
95
95
 
@@ -107,7 +107,7 @@ DESCRIPTION
107
107
  Extra documentation goes here
108
108
  ```
109
109
 
110
- _See code: [src/commands/download.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.27/src/commands/download.ts)_
110
+ _See code: [src/commands/download.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.29/src/commands/download.ts)_
111
111
 
112
112
  ## `learnpack help [COMMAND]`
113
113
 
@@ -138,7 +138,7 @@ OPTIONS
138
138
  -h, --grading show CLI help
139
139
  ```
140
140
 
141
- _See code: [src/commands/init.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.27/src/commands/init.ts)_
141
+ _See code: [src/commands/init.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.29/src/commands/init.ts)_
142
142
 
143
143
  ## `learnpack login [PACKAGE]`
144
144
 
@@ -156,7 +156,7 @@ DESCRIPTION
156
156
  Extra documentation goes here
157
157
  ```
158
158
 
159
- _See code: [src/commands/login.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.27/src/commands/login.ts)_
159
+ _See code: [src/commands/login.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.29/src/commands/login.ts)_
160
160
 
161
161
  ## `learnpack logout [PACKAGE]`
162
162
 
@@ -174,7 +174,7 @@ DESCRIPTION
174
174
  Extra documentation goes here
175
175
  ```
176
176
 
177
- _See code: [src/commands/logout.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.27/src/commands/logout.ts)_
177
+ _See code: [src/commands/logout.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.29/src/commands/logout.ts)_
178
178
 
179
179
  ## `learnpack plugins`
180
180
 
@@ -309,7 +309,7 @@ DESCRIPTION
309
309
  Extra documentation goes here
310
310
  ```
311
311
 
312
- _See code: [src/commands/publish.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.27/src/commands/publish.ts)_
312
+ _See code: [src/commands/publish.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.29/src/commands/publish.ts)_
313
313
 
314
314
  ## `learnpack start`
315
315
 
@@ -330,7 +330,7 @@ OPTIONS
330
330
  -w, --watch Watch for file changes
331
331
  ```
332
332
 
333
- _See code: [src/commands/start.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.27/src/commands/start.ts)_
333
+ _See code: [src/commands/start.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.29/src/commands/start.ts)_
334
334
 
335
335
  ## `learnpack test [EXERCISESLUG]`
336
336
 
@@ -344,5 +344,5 @@ ARGUMENTS
344
344
  EXERCISESLUG The name of the exercise to test
345
345
  ```
346
346
 
347
- _See code: [src/commands/test.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.27/src/commands/test.ts)_
347
+ _See code: [src/commands/test.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.29/src/commands/test.ts)_
348
348
  <!-- commandsstop -->
@@ -0,0 +1,6 @@
1
+ import SessionCommand from "../utils/SessionCommand";
2
+ declare class AuditCommand extends SessionCommand {
3
+ init(): Promise<void>;
4
+ run(): Promise<void>;
5
+ }
6
+ export default AuditCommand;
@@ -0,0 +1,342 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs");
4
+ const exercise_1 = require("../managers/config/exercise");
5
+ const console_1 = require("../utils/console");
6
+ const audit_1 = require("../utils/audit");
7
+ const SessionCommand_1 = require("../utils/SessionCommand");
8
+ const path = require("path");
9
+ // eslint-disable-next-line
10
+ const fetch = require("node-fetch");
11
+ class AuditCommand extends SessionCommand_1.default {
12
+ async init() {
13
+ const { flags } = this.parse(AuditCommand);
14
+ await this.initSession(flags);
15
+ }
16
+ async run() {
17
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
18
+ console_1.default.log("Running command audit...");
19
+ // Get configuration object.
20
+ let config = (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.get();
21
+ if (config) {
22
+ const errors = [];
23
+ const warnings = [];
24
+ if (((_b = config === null || config === void 0 ? void 0 : config.config) === null || _b === void 0 ? void 0 : _b.projectType) === "tutorial") {
25
+ const counter = {
26
+ images: {
27
+ error: 0,
28
+ total: 0,
29
+ },
30
+ links: {
31
+ error: 0,
32
+ total: 0,
33
+ },
34
+ exercises: 0,
35
+ readmeFiles: 0,
36
+ };
37
+ // Checks if learnpack clean has been run
38
+ audit_1.default.checkLearnpackClean(config, errors);
39
+ // Build exercises if they are not built yet.
40
+ (_c = this.configManager) === null || _c === void 0 ? void 0 : _c.buildIndex();
41
+ config = (_d = this.configManager) === null || _d === void 0 ? void 0 : _d.get();
42
+ // Check if the exercises folder has some files within any ./exercise
43
+ const exercisesPath = config.config.exercisesPath;
44
+ fs.readdir(exercisesPath, (err, files) => {
45
+ if (err) {
46
+ return console.log("Unable to scan directory: " + err);
47
+ }
48
+ // listing all files using forEach
49
+ for (const file of files) {
50
+ // Do whatever you want to do with the file
51
+ const filePath = path.join(exercisesPath, file);
52
+ if (fs.statSync(filePath).isFile())
53
+ warnings.push({
54
+ exercise: file,
55
+ msg: "This file is not inside any exercise folder.",
56
+ });
57
+ }
58
+ });
59
+ // This function is being created because the find method doesn't work with promises.
60
+ const find = async (file, lang, exercise) => {
61
+ if (file.name === lang) {
62
+ await audit_1.default.checkUrl(config, file.path, file.name, exercise, errors, warnings, counter);
63
+ return true;
64
+ }
65
+ return false;
66
+ };
67
+ console_1.default.debug("config", config);
68
+ console_1.default.info(" Checking if the config file is fine...");
69
+ // These two lines check if the 'slug' property is inside the configuration object.
70
+ console_1.default.debug("Checking if the slug property is inside the configuration object...");
71
+ // check if the slug property is in the configuration object
72
+ if (!((_e = config.config) === null || _e === void 0 ? void 0 : _e.slug))
73
+ errors.push({
74
+ exercise: undefined,
75
+ msg: "The slug property is not in the configuration object",
76
+ });
77
+ // check if the duration property is in the configuration object
78
+ if (!((_f = config.config) === null || _f === void 0 ? void 0 : _f.duration))
79
+ warnings.push({
80
+ exercise: undefined,
81
+ msg: "The duration property is not in the configuration object",
82
+ });
83
+ // check if the difficulty property is in the configuration object
84
+ if (!((_g = config.config) === null || _g === void 0 ? void 0 : _g.difficulty))
85
+ warnings.push({
86
+ exercise: undefined,
87
+ msg: "The difficulty property is not in the configuration object",
88
+ });
89
+ // check if the bugs_link property is in the configuration object
90
+ if (!((_h = config.config) === null || _h === void 0 ? void 0 : _h.bugsLink))
91
+ errors.push({
92
+ exercise: undefined,
93
+ msg: "The bugsLink property is not in the configuration object",
94
+ });
95
+ // check if the video_solutions property is in the configuration object
96
+ if (((_j = config.config) === null || _j === void 0 ? void 0 : _j.videoSolutions) === undefined)
97
+ warnings.push({
98
+ exercise: undefined,
99
+ msg: "The videoSolutions property is not in the configuration object",
100
+ });
101
+ // These two lines check if the 'repository' property is inside the configuration object.
102
+ console_1.default.debug("Checking if the repository property is inside the configuration object...");
103
+ if (!((_k = config.config) === null || _k === void 0 ? void 0 : _k.repository))
104
+ errors.push({
105
+ exercise: undefined,
106
+ msg: "The repository property is not in the configuration object",
107
+ });
108
+ else
109
+ audit_1.default.isUrl((_l = config.config) === null || _l === void 0 ? void 0 : _l.repository, errors, counter);
110
+ // These two lines check if the 'description' property is inside the configuration object.
111
+ console_1.default.debug("Checking if the description property is inside the configuration object...");
112
+ if (!((_m = config.config) === null || _m === void 0 ? void 0 : _m.description))
113
+ errors.push({
114
+ exercise: undefined,
115
+ msg: "The description property is not in the configuration object",
116
+ });
117
+ if (errors.length === 0)
118
+ console_1.default.log("The config file is ok");
119
+ // Validates if images and links are working at every README file.
120
+ const exercises = config.exercises;
121
+ const readmeFiles = [];
122
+ if (exercises && exercises.length > 0) {
123
+ console_1.default.info(" Checking if the images are working...");
124
+ for (const index in exercises) {
125
+ if (Object.prototype.hasOwnProperty.call(exercises, index)) {
126
+ const exercise = exercises[index];
127
+ if (!exercise_1.validateExerciseDirectoryName(exercise.title))
128
+ errors.push({
129
+ exercise: exercise.title,
130
+ msg: `The exercise ${exercise.title} has an invalid name.`,
131
+ });
132
+ let readmeFilesCount = { exercise: exercise.title, count: 0 };
133
+ if (Object.keys(exercise.translations).length === 0)
134
+ errors.push({
135
+ exercise: exercise.title,
136
+ msg: `The exercise ${exercise.title} doesn't have a README.md file.`,
137
+ });
138
+ if (exercise.language === "python3" ||
139
+ exercise.language === "python") {
140
+ for (const f of exercise.files.map(f => f)) {
141
+ if (f.path.includes("test.py") ||
142
+ f.path.includes("tests.py")) {
143
+ const content = fs.readFileSync(f.path).toString();
144
+ const isEmpty = audit_1.default.checkForEmptySpaces(content);
145
+ if (isEmpty || !content)
146
+ errors.push({
147
+ exercise: exercise.title,
148
+ msg: `This file (${f.name}) doesn't have any content inside.`,
149
+ });
150
+ }
151
+ }
152
+ }
153
+ else {
154
+ for (const f of exercise.files.map(f => f)) {
155
+ if (f.path.includes("test.js") ||
156
+ f.path.includes("tests.js")) {
157
+ const content = fs.readFileSync(f.path).toString();
158
+ const isEmpty = audit_1.default.checkForEmptySpaces(content);
159
+ if (isEmpty || !content)
160
+ errors.push({
161
+ exercise: exercise.title,
162
+ msg: `This file (${f.name}) doesn't have any content inside.`,
163
+ });
164
+ }
165
+ }
166
+ }
167
+ for (const lang in exercise.translations) {
168
+ if (Object.prototype.hasOwnProperty.call(exercise.translations, lang)) {
169
+ const files = [];
170
+ const findResultPromises = [];
171
+ for (const file of exercise.files) {
172
+ const found = find(file, exercise.translations[lang], exercise);
173
+ findResultPromises.push(found);
174
+ }
175
+ // eslint-disable-next-line
176
+ let findResults = await Promise.all(findResultPromises);
177
+ for (const found of findResults) {
178
+ if (found) {
179
+ readmeFilesCount = Object.assign(Object.assign({}, readmeFilesCount), { count: readmeFilesCount.count + 1 });
180
+ files.push(found);
181
+ }
182
+ }
183
+ if (!files.includes(true))
184
+ errors.push({
185
+ exercise: exercise.title,
186
+ msg: "This exercise doesn't have a README.md file.",
187
+ });
188
+ }
189
+ }
190
+ readmeFiles.push(readmeFilesCount);
191
+ }
192
+ }
193
+ }
194
+ else
195
+ errors.push({
196
+ exercise: undefined,
197
+ msg: "The exercises array is empty.",
198
+ });
199
+ console_1.default.log(`${counter.images.total - counter.images.error} images ok from ${counter.images.total}`);
200
+ console_1.default.info(" Checking if important files are missing... (README's, translations, gitignore...)");
201
+ // Check if all the exercises has the same ammount of README's, this way we can check if they have the same ammount of translations.
202
+ const files = [];
203
+ let count = 0;
204
+ for (const item of readmeFiles) {
205
+ if (count < item.count)
206
+ count = item.count;
207
+ }
208
+ for (const item of readmeFiles) {
209
+ if (item.count !== count)
210
+ files.push(` ${item.exercise}`);
211
+ }
212
+ if (files.length > 0) {
213
+ const filesString = files.join(",");
214
+ warnings.push({
215
+ exercise: undefined,
216
+ msg: files.length === 1 ?
217
+ `This exercise is missing translations:${filesString}` :
218
+ `These exercises are missing translations:${filesString}`,
219
+ });
220
+ }
221
+ // Checks if the .gitignore file exists.
222
+ if (!fs.existsSync(".gitignore"))
223
+ warnings.push({
224
+ exercise: undefined,
225
+ msg: ".gitignore file doesn't exist",
226
+ });
227
+ counter.exercises = exercises.length;
228
+ for (const readme of readmeFiles) {
229
+ counter.readmeFiles += readme.count;
230
+ }
231
+ }
232
+ else {
233
+ // This is the audit code for Projects
234
+ // Getting the learn.json schema
235
+ const schemaResponse = await fetch("https://raw.githubusercontent.com/tommygonzaleza/project-template/main/.github/learn-schema.json");
236
+ const schema = await schemaResponse.json();
237
+ // Checking the "learn.json" file:
238
+ const learnjson = JSON.parse(fs.readFileSync("./learn.json").toString());
239
+ if (!learnjson) {
240
+ console_1.default.error("There is no learn.json file located in the root of the project.");
241
+ process.exit(1);
242
+ }
243
+ // Checking the README.md files and possible translations.
244
+ let readmeFiles = [];
245
+ const translations = [];
246
+ const translationRegex = /README\.([a-z]{2,3})\.md/;
247
+ try {
248
+ const data = await fs.promises.readdir("./");
249
+ readmeFiles = data.filter(file => file.includes("README"));
250
+ if (readmeFiles.length === 0)
251
+ errors.push({
252
+ exercise: undefined,
253
+ msg: `There is no README file in the repository.`,
254
+ });
255
+ }
256
+ catch (error) {
257
+ if (error)
258
+ console_1.default.error("There was an error getting the directory files", error);
259
+ }
260
+ for (const readmeFile of readmeFiles) {
261
+ // Checking the language of each README file.
262
+ if (readmeFile === "README.md")
263
+ translations.push("us");
264
+ else {
265
+ const regexGroups = translationRegex.exec(readmeFile);
266
+ if (regexGroups)
267
+ translations.push(regexGroups[1]);
268
+ }
269
+ const readme = fs.readFileSync(path.resolve(readmeFile)).toString();
270
+ const isEmpty = audit_1.default.checkForEmptySpaces(readme);
271
+ if (isEmpty || !readme) {
272
+ errors.push({
273
+ exercise: undefined,
274
+ msg: `This file "${readmeFile}" doesn't have any content inside.`,
275
+ });
276
+ continue;
277
+ }
278
+ if (readme.length < 800)
279
+ errors.push({
280
+ exercise: undefined,
281
+ msg: `The "${readmeFile}" file should have at least 800 characters (It currently have: ${readme.length}).`,
282
+ });
283
+ // eslint-disable-next-line
284
+ await audit_1.default.checkUrl(config, path.resolve(readmeFile), readmeFile, undefined, errors, warnings,
285
+ // eslint-disable-next-line
286
+ undefined);
287
+ }
288
+ // Adding the translations to the learn.json
289
+ learnjson.translations = translations;
290
+ // Checking if the preview image (from the learn.json) is OK.
291
+ try {
292
+ const res = await fetch(learnjson.preview, { method: "HEAD" });
293
+ if (res.status > 399 && res.status < 500) {
294
+ errors.push({
295
+ exercise: undefined,
296
+ msg: `The link of the "preview" is broken: ${learnjson.preview}`,
297
+ });
298
+ }
299
+ }
300
+ catch (_o) {
301
+ errors.push({
302
+ exercise: undefined,
303
+ msg: `The link of the "preview" is broken: ${learnjson.preview}`,
304
+ });
305
+ }
306
+ const date = new Date();
307
+ learnjson.validationAt = date.getTime();
308
+ if (errors.length > 0)
309
+ learnjson.validationStatus = "error";
310
+ else if (warnings.length > 0)
311
+ learnjson.validationStatus = "warning";
312
+ else
313
+ learnjson.validationStatus = "success";
314
+ // Writes the "learn.json" file with all the new properties
315
+ await fs.promises.writeFile("./learn.json", JSON.stringify(learnjson));
316
+ }
317
+ await audit_1.default.showWarnings(warnings);
318
+ // eslint-disable-next-line
319
+ await audit_1.default.showErrors(errors, undefined);
320
+ }
321
+ }
322
+ }
323
+ AuditCommand.description = `learnpack audit is the command in charge of creating an auditory of the repository
324
+ ...
325
+ learnpack audit checks for the following information in a repository:
326
+ 1. The configuration object has slug, repository and description. (Error)
327
+ 2. The command learnpack clean has been run. (Error)
328
+ 3. If a markdown or test file doesn't have any content. (Error)
329
+ 4. The links are accessing to valid servers. (Error)
330
+ 5. The relative images are working (If they have the shortest path to the image or if the images exists in the assets). (Error)
331
+ 6. The external images are working (If they are pointing to a valid server). (Error)
332
+ 7. The exercises directory names are valid. (Error)
333
+ 8. If an exercise doesn't have a README file. (Error)
334
+ 9. The exercises array (Of the config file) has content. (Error)
335
+ 10. The exercses have the same translations. (Warning)
336
+ 11. The .gitignore file exists. (Warning)
337
+ 12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)
338
+ `;
339
+ AuditCommand.flags = {
340
+ // name: flags.string({char: 'n', description: 'name to print'}),
341
+ };
342
+ exports.default = AuditCommand;
@@ -0,0 +1,8 @@
1
+ import SessionCommand from "../utils/SessionCommand";
2
+ declare class CleanCommand extends SessionCommand {
3
+ static description: string;
4
+ static flags: any;
5
+ init(): Promise<void>;
6
+ run(): Promise<void>;
7
+ }
8
+ export default CleanCommand;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // import {flags} from '@oclif/command'
4
+ const console_1 = require("../utils/console");
5
+ const SessionCommand_1 = require("../utils/SessionCommand");
6
+ class CleanCommand extends SessionCommand_1.default {
7
+ async init() {
8
+ const { flags } = this.parse(CleanCommand);
9
+ await this.initSession(flags);
10
+ }
11
+ async run() {
12
+ var _a;
13
+ const { flags } = this.parse(CleanCommand);
14
+ (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.clean();
15
+ console_1.default.success("Package cleaned successfully, ready to publish");
16
+ }
17
+ }
18
+ CleanCommand.description = `Clean the configuration object
19
+ ...
20
+ Extra documentation goes here
21
+ `;
22
+ CleanCommand.flags = {
23
+ // name: flags.string({char: 'n', description: 'name to print'}),
24
+ };
25
+ exports.default = CleanCommand;
@@ -0,0 +1,13 @@
1
+ import { Command } from "@oclif/command";
2
+ declare class DownloadCommand extends Command {
3
+ static description: string;
4
+ static flags: any;
5
+ static args: {
6
+ name: string;
7
+ required: boolean;
8
+ description: string;
9
+ hidden: boolean;
10
+ }[];
11
+ run(): Promise<null | undefined>;
12
+ }
13
+ export default DownloadCommand;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const command_1 = require("@oclif/command");
4
+ // import fetch from 'node-fetch'
5
+ const file_1 = require("../managers/file");
6
+ const console_1 = require("../utils/console");
7
+ const api_1 = require("../utils/api");
8
+ const download_1 = require("../ui/download");
9
+ // const BaseCommand = require('../utils/BaseCommand');
10
+ class DownloadCommand extends command_1.Command {
11
+ // async init() {
12
+ // const {flags} = this.parse(DownloadCommand)
13
+ // await this.initSession(flags)
14
+ // }
15
+ async run() {
16
+ const { /* flags, */ args } = this.parse(DownloadCommand);
17
+ // start watching for file changes
18
+ let _package = args.package;
19
+ if (!_package) {
20
+ _package = (await download_1.askPackage());
21
+ }
22
+ if (!_package) {
23
+ return null;
24
+ }
25
+ try {
26
+ const packageInfo = await api_1.default.getAllPackages({ slug: _package });
27
+ if (packageInfo.results.length === 0)
28
+ console_1.default.error(`Package ${_package} not found`);
29
+ else
30
+ file_1.clone(packageInfo.results[0].repository)
31
+ .then(_result => {
32
+ console_1.default.success("Successfully downloaded");
33
+ console_1.default.info(`You can now CD into the folder like this: $ cd ${_package}`);
34
+ })
35
+ .catch(error => console_1.default.error(error.message || error));
36
+ }
37
+ catch (_a) { }
38
+ }
39
+ }
40
+ DownloadCommand.description = `Describe the command here
41
+ ...
42
+ Extra documentation goes here
43
+ `;
44
+ DownloadCommand.flags = {
45
+ // name: flags.string({char: 'n', description: 'name to print'}),
46
+ };
47
+ DownloadCommand.args = [
48
+ {
49
+ name: "package",
50
+ required: false,
51
+ description: "The unique string that identifies this package on learnpack",
52
+ hidden: false,
53
+ },
54
+ ];
55
+ exports.default = DownloadCommand;
@@ -0,0 +1,9 @@
1
+ import BaseCommand from "../utils/BaseCommand";
2
+ declare class InitComand extends BaseCommand {
3
+ static description: string;
4
+ static flags: {
5
+ grading: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
6
+ };
7
+ run(): Promise<void>;
8
+ }
9
+ export default InitComand;