@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,26 +1,26 @@
1
- # `01` First Exercise
2
-
3
- We created this first exercise as an example, you can find it located in the folder `./01-hello-world`.
4
-
5
- 1. Every exercise must be located on a separate folder and it must have a README.md file inside with the exercise instructions written in markdown.
6
- 2. You can have just a README file and it will be like a page in a book, no code files.
7
- 3. You can also add a `README.[lang].md` file for translations, for example: `README.es.md` for spanish.
8
-
9
- ## Video compatibility
10
-
11
- If you want to include some video introduction for each exercise, add a `intro` property in the markdown frontmatter of the README.md for that particular exercise:
12
-
13
- ```markdown
14
- ---
15
- intro: "https://www.youtube.com/watch?v=YkgkThdzX-8"
16
- ---
17
- ```
18
-
19
- You can also add a video solution for each exercise by adding a `tutorial` property on the markdown frontmatter of it's README.md:
20
-
21
- ```markdown
22
- ---
23
- intro: "https://www.youtube.com/watch?v=YkgkThdzX-8"
24
- tutorial: "https://www.youtube.com/watch?v=YkgkThdzX-8"
25
- ---
26
- ```
1
+ # `01` First Exercise
2
+
3
+ We created this first exercise as an example, you can find it located in the folder `./01-hello-world`.
4
+
5
+ 1. Every exercise must be located on a separate folder and it must have a README.md file inside with the exercise instructions written in markdown.
6
+ 2. You can have just a README file and it will be like a page in a book, no code files.
7
+ 3. You can also add a `README.[lang].md` file for translations, for example: `README.es.md` for spanish.
8
+
9
+ ## Video compatibility
10
+
11
+ If you want to include some video introduction for each exercise, add a `intro` property in the markdown frontmatter of the README.md for that particular exercise:
12
+
13
+ ```markdown
14
+ ---
15
+ intro: "https://www.youtube.com/watch?v=YkgkThdzX-8"
16
+ ---
17
+ ```
18
+
19
+ You can also add a video solution for each exercise by adding a `tutorial` property on the markdown frontmatter of it's README.md:
20
+
21
+ ```markdown
22
+ ---
23
+ intro: "https://www.youtube.com/watch?v=YkgkThdzX-8"
24
+ tutorial: "https://www.youtube.com/watch?v=YkgkThdzX-8"
25
+ ---
26
+ ```
@@ -1,5 +1,5 @@
1
- # Welcome to <%= it.title %>
2
-
3
- You have initialized the exercises with grading=`incremental`; meaning that your students will complete one single tutorial with clear and autograded steps from beginning to end.
4
-
1
+ # Welcome to <%= it.title %>
2
+
3
+ You have initialized the exercises with grading=`incremental`; meaning that your students will complete one single tutorial with clear and autograded steps from beginning to end.
4
+
5
5
  Type `$ learnpack start` in your terminal to start the exercises.
@@ -1,5 +1,5 @@
1
- # Bienvenido a <%= it.title %>
2
-
3
- Has inicializado los ejercicios con grading=`incremental`; esto signigica que tus estudiantes completarán un solo tutorial con pasos claros e incrementales, desde el comienzo hasta el final.
4
-
1
+ # Bienvenido a <%= it.title %>
2
+
3
+ Has inicializado los ejercicios con grading=`incremental`; esto signigica que tus estudiantes completarán un solo tutorial con pasos claros e incrementales, desde el comienzo hasta el final.
4
+
5
5
  Ejecuta `$ learnpack start` en la terminal para comenzar con los ejercicios.
@@ -1,5 +1,5 @@
1
- # Welcome to <%= it.title %>
2
-
3
- You have initialized the exercises without grading, meaning that your students will completed exercises without the need of coding.
4
-
1
+ # Welcome to <%= it.title %>
2
+
3
+ You have initialized the exercises without grading, meaning that your students will completed exercises without the need of coding.
4
+
5
5
  Type `$ learnpack start` in your terminal to start the exercises.
@@ -1,5 +1,5 @@
1
- # Bienvenido a <%= it.title %>
2
-
3
- Has inicializado los ejercicios sin grading; lo que signigica que tus estudiantes completarán los ejercicios sin necesidad de codificar.
4
-
1
+ # Bienvenido a <%= it.title %>
2
+
3
+ Has inicializado los ejercicios sin grading; lo que signigica que tus estudiantes completarán los ejercicios sin necesidad de codificar.
4
+
5
5
  Ejecuta `$ learnpack start` en la terminal para comenzar con los ejercicios.
@@ -1,18 +1,18 @@
1
- export function validURL(str: string) {
2
- if (!str.includes('github.com')) {
3
- return false
4
- }
5
-
6
- const pattern = new RegExp(
7
- '^(https?:\\/\\/)?' + // protocol
8
- '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
9
- '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
10
- '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
11
- '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
12
- '(\\#[-a-z\\d_]*)?$',
13
- 'i',
14
- ) // fragment locator
15
- return !!pattern.test(str)
16
- }
17
-
18
- export default {validURL}
1
+ export function validURL(str: string) {
2
+ if (!str.includes('github.com')) {
3
+ return false
4
+ }
5
+
6
+ const pattern = new RegExp(
7
+ '^(https?:\\/\\/)?' + // protocol
8
+ '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
9
+ '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
10
+ '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
11
+ '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
12
+ '(\\#[-a-z\\d_]*)?$',
13
+ 'i',
14
+ ) // fragment locator
15
+ return !!pattern.test(str)
16
+ }
17
+
18
+ export default {validURL}
@@ -1,25 +1,25 @@
1
- import * as chokidar from "chokidar";
2
- import Console from "./console";
3
- import * as debounce from "debounce";
4
- import { IConfigManager } from "../models/config-manager";
1
+ import * as chokidar from "chokidar"
2
+ import Console from "./console"
3
+ import * as debounce from "debounce"
4
+ import { IConfigManager } from "../models/config-manager"
5
5
 
6
6
  export default (path: string, reloadSocket: () => void) =>
7
7
  new Promise((resolve /* , reject */) => {
8
- Console.debug("PATH:", path);
8
+ Console.debug("PATH:", path)
9
9
  const watcher = chokidar.watch(path, {
10
10
  // TODO: This watcher is not ready yet
11
11
  ignored: /^(?=.*(\.\w+)$)(?!.*\.md$).*$/gm,
12
12
  ignoreInitial: true,
13
- });
13
+ })
14
14
  const onChange = (eventname: string, _filename: string) => {
15
- resolve(eventname /* , filename */);
16
- reloadSocket();
17
- };
15
+ resolve(eventname /* , filename */)
16
+ reloadSocket()
17
+ }
18
18
 
19
- watcher.on("all", debounce(onChange, 500, true));
19
+ watcher.on("all", debounce(onChange, 500, true))
20
20
  // watcher.on('all', onChange)
21
21
  process.on("SIGINT", function () {
22
- watcher.close();
23
- process.exit();
24
- });
25
- });
22
+ watcher.close()
23
+ process.exit()
24
+ })
25
+ })
@@ -1,6 +0,0 @@
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;
@@ -1,317 +0,0 @@
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;
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
- if (!((_e = config.config) === null || _e === void 0 ? void 0 : _e.slug))
72
- errors.push({
73
- exercise: undefined,
74
- msg: "The slug property is not in the configuration object",
75
- });
76
- // These two lines check if the 'repository' property is inside the configuration object.
77
- console_1.default.debug("Checking if the repository property is inside the configuration object...");
78
- if (!((_f = config.config) === null || _f === void 0 ? void 0 : _f.repository))
79
- errors.push({
80
- exercise: undefined,
81
- msg: "The repository property is not in the configuration object",
82
- });
83
- else
84
- audit_1.default.isUrl((_g = config.config) === null || _g === void 0 ? void 0 : _g.repository, errors, counter);
85
- // These two lines check if the 'description' property is inside the configuration object.
86
- console_1.default.debug("Checking if the description property is inside the configuration object...");
87
- if (!((_h = config.config) === null || _h === void 0 ? void 0 : _h.description))
88
- errors.push({
89
- exercise: undefined,
90
- msg: "The description property is not in the configuration object",
91
- });
92
- if (errors.length === 0)
93
- console_1.default.log("The config file is ok");
94
- // Validates if images and links are working at every README file.
95
- const exercises = config.exercises;
96
- const readmeFiles = [];
97
- if (exercises && exercises.length > 0) {
98
- console_1.default.info(" Checking if the images are working...");
99
- for (const index in exercises) {
100
- if (Object.prototype.hasOwnProperty.call(exercises, index)) {
101
- const exercise = exercises[index];
102
- if (!exercise_1.validateExerciseDirectoryName(exercise.title))
103
- errors.push({
104
- exercise: exercise.title,
105
- msg: `The exercise ${exercise.title} has an invalid name.`,
106
- });
107
- let readmeFilesCount = { exercise: exercise.title, count: 0 };
108
- if (Object.keys(exercise.translations).length === 0)
109
- errors.push({
110
- exercise: exercise.title,
111
- msg: `The exercise ${exercise.title} doesn't have a README.md file.`,
112
- });
113
- if (exercise.language === "python3" ||
114
- exercise.language === "python") {
115
- for (const f of exercise.files.map(f => f)) {
116
- if (f.path.includes("test.py") ||
117
- f.path.includes("tests.py")) {
118
- const content = fs.readFileSync(f.path).toString();
119
- const isEmpty = audit_1.default.checkForEmptySpaces(content);
120
- if (isEmpty || !content)
121
- errors.push({
122
- exercise: exercise.title,
123
- msg: `This file (${f.name}) doesn't have any content inside.`,
124
- });
125
- }
126
- }
127
- }
128
- else {
129
- for (const f of exercise.files.map(f => f)) {
130
- if (f.path.includes("test.js") ||
131
- f.path.includes("tests.js")) {
132
- const content = fs.readFileSync(f.path).toString();
133
- const isEmpty = audit_1.default.checkForEmptySpaces(content);
134
- if (isEmpty || !content)
135
- errors.push({
136
- exercise: exercise.title,
137
- msg: `This file (${f.name}) doesn't have any content inside.`,
138
- });
139
- }
140
- }
141
- }
142
- for (const lang in exercise.translations) {
143
- if (Object.prototype.hasOwnProperty.call(exercise.translations, lang)) {
144
- const files = [];
145
- const findResultPromises = [];
146
- for (const file of exercise.files) {
147
- const found = find(file, exercise.translations[lang], exercise);
148
- findResultPromises.push(found);
149
- }
150
- // eslint-disable-next-line
151
- let findResults = await Promise.all(findResultPromises);
152
- for (const found of findResults) {
153
- if (found) {
154
- readmeFilesCount = Object.assign(Object.assign({}, readmeFilesCount), { count: readmeFilesCount.count + 1 });
155
- files.push(found);
156
- }
157
- }
158
- if (!files.includes(true))
159
- errors.push({
160
- exercise: exercise.title,
161
- msg: "This exercise doesn't have a README.md file.",
162
- });
163
- }
164
- }
165
- readmeFiles.push(readmeFilesCount);
166
- }
167
- }
168
- }
169
- else
170
- errors.push({
171
- exercise: undefined,
172
- msg: "The exercises array is empty.",
173
- });
174
- console_1.default.log(`${counter.images.total - counter.images.error} images ok from ${counter.images.total}`);
175
- console_1.default.info(" Checking if important files are missing... (README's, translations, gitignore...)");
176
- // 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.
177
- const files = [];
178
- let count = 0;
179
- for (const item of readmeFiles) {
180
- if (count < item.count)
181
- count = item.count;
182
- }
183
- for (const item of readmeFiles) {
184
- if (item.count !== count)
185
- files.push(` ${item.exercise}`);
186
- }
187
- if (files.length > 0) {
188
- const filesString = files.join(",");
189
- warnings.push({
190
- exercise: undefined,
191
- msg: files.length === 1 ?
192
- `This exercise is missing translations:${filesString}` :
193
- `These exercises are missing translations:${filesString}`,
194
- });
195
- }
196
- // Checks if the .gitignore file exists.
197
- if (!fs.existsSync(".gitignore"))
198
- warnings.push({
199
- exercise: undefined,
200
- msg: ".gitignore file doesn't exist",
201
- });
202
- counter.exercises = exercises.length;
203
- for (const readme of readmeFiles) {
204
- counter.readmeFiles += readme.count;
205
- }
206
- }
207
- else {
208
- // This is the audit code for Projects
209
- // Getting the learn.json schema
210
- const schemaResponse = await fetch("https://raw.githubusercontent.com/tommygonzaleza/project-template/main/.github/learn-schema.json");
211
- const schema = await schemaResponse.json();
212
- // Checking the "learn.json" file:
213
- const learnjson = JSON.parse(fs.readFileSync("./learn.json").toString());
214
- if (!learnjson) {
215
- console_1.default.error("There is no learn.json file located in the root of the project.");
216
- process.exit(1);
217
- }
218
- // Checking the README.md files and possible translations.
219
- let readmeFiles = [];
220
- const translations = [];
221
- const translationRegex = /README\.([a-z]{2,3})\.md/;
222
- try {
223
- const data = await fs.promises.readdir("./");
224
- readmeFiles = data.filter(file => file.includes("README"));
225
- if (readmeFiles.length === 0)
226
- errors.push({
227
- exercise: undefined,
228
- msg: `There is no README file in the repository.`,
229
- });
230
- }
231
- catch (error) {
232
- if (error)
233
- console_1.default.error("There was an error getting the directory files", error);
234
- }
235
- for (const readmeFile of readmeFiles) {
236
- // Checking the language of each README file.
237
- if (readmeFile === "README.md")
238
- translations.push("us");
239
- else {
240
- const regexGroups = translationRegex.exec(readmeFile);
241
- if (regexGroups)
242
- translations.push(regexGroups[1]);
243
- }
244
- const readme = fs.readFileSync(path.resolve(readmeFile)).toString();
245
- const isEmpty = audit_1.default.checkForEmptySpaces(readme);
246
- if (isEmpty || !readme) {
247
- errors.push({
248
- exercise: undefined,
249
- msg: `This file "${readmeFile}" doesn't have any content inside.`,
250
- });
251
- continue;
252
- }
253
- if (readme.length < 800)
254
- errors.push({
255
- exercise: undefined,
256
- msg: `The "${readmeFile}" file should have at least 800 characters (It currently have: ${readme.length}).`,
257
- });
258
- // eslint-disable-next-line
259
- await audit_1.default.checkUrl(config, path.resolve(readmeFile), readmeFile, undefined, errors, warnings,
260
- // eslint-disable-next-line
261
- undefined);
262
- }
263
- // Adding the translations to the learn.json
264
- learnjson.translations = translations;
265
- // Checking if the preview image (from the learn.json) is OK.
266
- try {
267
- const res = await fetch(learnjson.preview, { method: "HEAD" });
268
- if (res.status > 399 && res.status < 500) {
269
- errors.push({
270
- exercise: undefined,
271
- msg: `The link of the "preview" is broken: ${learnjson.preview}`,
272
- });
273
- }
274
- }
275
- catch (_j) {
276
- errors.push({
277
- exercise: undefined,
278
- msg: `The link of the "preview" is broken: ${learnjson.preview}`,
279
- });
280
- }
281
- const date = new Date();
282
- learnjson.validationAt = date.getTime();
283
- if (errors.length > 0)
284
- learnjson.validationStatus = "error";
285
- else if (warnings.length > 0)
286
- learnjson.validationStatus = "warning";
287
- else
288
- learnjson.validationStatus = "success";
289
- // Writes the "learn.json" file with all the new properties
290
- await fs.promises.writeFile("./learn.json", JSON.stringify(learnjson));
291
- }
292
- await audit_1.default.showWarnings(warnings);
293
- // eslint-disable-next-line
294
- await audit_1.default.showErrors(errors, undefined);
295
- }
296
- }
297
- }
298
- AuditCommand.description = `learnpack audit is the command in charge of creating an auditory of the repository
299
- ...
300
- learnpack audit checks for the following information in a repository:
301
- 1. The configuration object has slug, repository and description. (Error)
302
- 2. The command learnpack clean has been run. (Error)
303
- 3. If a markdown or test file doesn't have any content. (Error)
304
- 4. The links are accessing to valid servers. (Error)
305
- 5. The relative images are working (If they have the shortest path to the image or if the images exists in the assets). (Error)
306
- 6. The external images are working (If they are pointing to a valid server). (Error)
307
- 7. The exercises directory names are valid. (Error)
308
- 8. If an exercise doesn't have a README file. (Error)
309
- 9. The exercises array (Of the config file) has content. (Error)
310
- 10. The exercses have the same translations. (Warning)
311
- 11. The .gitignore file exists. (Warning)
312
- 12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)
313
- `;
314
- AuditCommand.flags = {
315
- // name: flags.string({char: 'n', description: 'name to print'}),
316
- };
317
- exports.default = AuditCommand;
@@ -1,8 +0,0 @@
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;
@@ -1,25 +0,0 @@
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;
@@ -1,13 +0,0 @@
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;
@@ -1,55 +0,0 @@
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;
@@ -1,9 +0,0 @@
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;