@learnpack/learnpack 4.0.10 → 4.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. package/README.md +16 -20
  2. package/lib/commands/audit.d.ts +6 -6
  3. package/lib/commands/audit.js +327 -327
  4. package/lib/commands/clean.d.ts +8 -8
  5. package/lib/commands/clean.js +22 -22
  6. package/lib/commands/download.d.ts +13 -13
  7. package/lib/commands/download.js +52 -52
  8. package/lib/commands/init.d.ts +9 -9
  9. package/lib/commands/init.js +127 -127
  10. package/lib/commands/login.d.ts +14 -14
  11. package/lib/commands/login.js +34 -34
  12. package/lib/commands/logout.d.ts +14 -14
  13. package/lib/commands/logout.js +34 -34
  14. package/lib/commands/publish.d.ts +11 -14
  15. package/lib/commands/publish.js +160 -82
  16. package/lib/commands/start.d.ts +7 -7
  17. package/lib/commands/start.js +252 -250
  18. package/lib/commands/test.d.ts +6 -6
  19. package/lib/commands/test.js +62 -62
  20. package/lib/index.d.ts +1 -1
  21. package/lib/index.js +4 -4
  22. package/lib/managers/config/allowed_files.d.ts +5 -5
  23. package/lib/managers/config/allowed_files.js +30 -30
  24. package/lib/managers/config/defaults.d.ts +47 -48
  25. package/lib/managers/config/defaults.js +51 -51
  26. package/lib/managers/config/exercise.d.ts +36 -36
  27. package/lib/managers/config/exercise.js +243 -236
  28. package/lib/managers/config/index.d.ts +3 -3
  29. package/lib/managers/config/index.js +464 -459
  30. package/lib/managers/file.d.ts +14 -14
  31. package/lib/managers/file.js +190 -184
  32. package/lib/managers/gitpod.d.ts +3 -3
  33. package/lib/managers/gitpod.js +67 -67
  34. package/lib/managers/server/index.d.ts +5 -6
  35. package/lib/managers/server/index.js +58 -58
  36. package/lib/managers/server/routes.d.ts +4 -4
  37. package/lib/managers/server/routes.js +228 -220
  38. package/lib/managers/session.d.ts +3 -3
  39. package/lib/managers/session.js +125 -125
  40. package/lib/managers/socket.d.ts +3 -3
  41. package/lib/managers/socket.js +188 -186
  42. package/lib/managers/telemetry.d.ts +74 -74
  43. package/lib/managers/telemetry.js +215 -214
  44. package/lib/managers/test.js +84 -84
  45. package/lib/models/action.d.ts +2 -2
  46. package/lib/models/action.js +2 -2
  47. package/lib/models/audit.d.ts +15 -15
  48. package/lib/models/audit.js +2 -2
  49. package/lib/models/config-manager.d.ts +21 -21
  50. package/lib/models/config-manager.js +2 -2
  51. package/lib/models/config.d.ts +86 -86
  52. package/lib/models/config.js +2 -2
  53. package/lib/models/counter.d.ts +11 -11
  54. package/lib/models/counter.js +2 -2
  55. package/lib/models/errors.d.ts +15 -15
  56. package/lib/models/errors.js +2 -2
  57. package/lib/models/exercise-obj.d.ts +29 -30
  58. package/lib/models/exercise-obj.js +2 -2
  59. package/lib/models/file.d.ts +5 -5
  60. package/lib/models/file.js +2 -2
  61. package/lib/models/findings.d.ts +17 -17
  62. package/lib/models/findings.js +2 -2
  63. package/lib/models/flags.d.ts +10 -10
  64. package/lib/models/flags.js +2 -2
  65. package/lib/models/front-matter.d.ts +11 -11
  66. package/lib/models/front-matter.js +2 -2
  67. package/lib/models/gitpod-data.d.ts +16 -16
  68. package/lib/models/gitpod-data.js +2 -2
  69. package/lib/models/language.d.ts +4 -4
  70. package/lib/models/language.js +2 -2
  71. package/lib/models/package.d.ts +7 -7
  72. package/lib/models/package.js +2 -2
  73. package/lib/models/plugin-config.d.ts +16 -16
  74. package/lib/models/plugin-config.js +2 -2
  75. package/lib/models/session.d.ts +31 -31
  76. package/lib/models/session.js +2 -2
  77. package/lib/models/socket.d.ts +37 -37
  78. package/lib/models/socket.js +2 -2
  79. package/lib/models/status.d.ts +1 -1
  80. package/lib/models/status.js +2 -2
  81. package/lib/models/success-types.d.ts +1 -1
  82. package/lib/models/success-types.js +2 -2
  83. package/lib/plugin/command/compile.d.ts +6 -6
  84. package/lib/plugin/command/compile.js +18 -18
  85. package/lib/plugin/command/test.d.ts +6 -6
  86. package/lib/plugin/command/test.js +25 -25
  87. package/lib/plugin/index.d.ts +27 -27
  88. package/lib/plugin/index.js +7 -7
  89. package/lib/plugin/plugin.d.ts +8 -8
  90. package/lib/plugin/plugin.js +68 -68
  91. package/lib/plugin/utils.d.ts +16 -16
  92. package/lib/plugin/utils.js +58 -58
  93. package/lib/ui/download.d.ts +5 -5
  94. package/lib/ui/download.js +62 -61
  95. package/lib/utils/BaseCommand.d.ts +8 -8
  96. package/lib/utils/BaseCommand.js +41 -41
  97. package/lib/utils/SessionCommand.d.ts +10 -10
  98. package/lib/utils/SessionCommand.js +43 -43
  99. package/lib/utils/api.d.ts +14 -14
  100. package/lib/utils/api.js +255 -255
  101. package/lib/utils/audit.d.ts +16 -16
  102. package/lib/utils/audit.js +303 -303
  103. package/lib/utils/checkNotInstalled.d.ts +8 -8
  104. package/lib/utils/checkNotInstalled.js +185 -181
  105. package/lib/utils/console.d.ts +12 -12
  106. package/lib/utils/console.js +19 -19
  107. package/lib/utils/errors.d.ts +17 -17
  108. package/lib/utils/errors.js +107 -100
  109. package/lib/utils/exercisesQueue.d.ts +9 -9
  110. package/lib/utils/exercisesQueue.js +38 -38
  111. package/lib/utils/fileQueue.d.ts +43 -43
  112. package/lib/utils/fileQueue.js +169 -169
  113. package/lib/utils/misc.d.ts +1 -1
  114. package/lib/utils/misc.js +24 -23
  115. package/lib/utils/osOperations.d.ts +5 -5
  116. package/lib/utils/osOperations.js +72 -72
  117. package/lib/utils/validators.d.ts +5 -5
  118. package/lib/utils/validators.js +16 -17
  119. package/lib/utils/watcher.d.ts +2 -2
  120. package/lib/utils/watcher.js +25 -25
  121. package/oclif.manifest.json +1 -1
  122. package/package.json +6 -4
  123. package/src/commands/publish.ts +181 -107
  124. package/src/managers/config/index.ts +5 -0
  125. package/src/managers/server/routes.ts +10 -0
  126. package/src/managers/session.ts +145 -145
@@ -1,250 +1,252 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // import path from "path";
4
- const command_1 = require("@oclif/command");
5
- const fs = require("fs");
6
- const path = require("path");
7
- const SessionCommand_1 = require("../utils/SessionCommand");
8
- const console_1 = require("../utils/console");
9
- const socket_1 = require("../managers/socket");
10
- const telemetry_1 = require("../managers/telemetry");
11
- const server_1 = require("../managers/server");
12
- const fileQueue_1 = require("../utils/fileQueue");
13
- const file_1 = require("../managers/file");
14
- const misc_1 = require("../utils/misc");
15
- const osOperations_1 = require("../utils/osOperations");
16
- const checkNotInstalled_1 = require("../utils/checkNotInstalled");
17
- class StartCommand extends SessionCommand_1.default {
18
- // 🛑 IMPORTANT
19
- // Every command that will use the configManager needs this init method
20
- async init() {
21
- const { flags } = this.parse(StartCommand);
22
- await this.initSession(flags);
23
- }
24
- async run() {
25
- var _a, _b, _c, _d, _e, _f;
26
- // get configuration object
27
- const configObject = (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.get();
28
- const hasXDG = await osOperations_1.eventManager.checkXDGInstalled();
29
- const installedPlugins = this.config.plugins.map(plugin => {
30
- return `${plugin.pjson.name}`;
31
- });
32
- if (configObject) {
33
- const { config } = configObject;
34
- // build exerises
35
- (_b = this.configManager) === null || _b === void 0 ? void 0 : _b.buildIndex();
36
- console_1.default.debug(`Grading: ${config === null || config === void 0 ? void 0 : config.grading} ${((_c = config === null || config === void 0 ? void 0 : config.disabledActions) === null || _c === void 0 ? void 0 : _c.includes("test")) ? "(disabled)" : ""}, editor: ${config === null || config === void 0 ? void 0 : config.editor.mode} ${config === null || config === void 0 ? void 0 : config.editor.version}, for ${Array.isArray(configObject === null || configObject === void 0 ? void 0 : configObject.exercises) ? configObject === null || configObject === void 0 ? void 0 : configObject.exercises.length :
37
- 0} exercises found`);
38
- const neededPlugins = await checkNotInstalled_1.checkNotInstalledPlugins((configObject === null || configObject === void 0 ? void 0 : configObject.exercises) || [], installedPlugins, this);
39
- const allDepsInstalled = await checkNotInstalled_1.checkNotInstalledDependencies(neededPlugins.needed);
40
- if (!allDepsInstalled) {
41
- this.exit(1);
42
- }
43
- const appAlreadyExists = file_1.checkIfDirectoryExists(`${config === null || config === void 0 ? void 0 : config.dirPath}/_app`);
44
- if (!appAlreadyExists) {
45
- // download app and decompress
46
- await file_1.downloadEditor(config === null || config === void 0 ? void 0 : config.editor.version, `${config === null || config === void 0 ? void 0 : config.dirPath}/app.tar.gz`);
47
- console_1.default.info("Decompressing LearnPack UI, this may take a minute...");
48
- await file_1.decompress(`${config === null || config === void 0 ? void 0 : config.dirPath}/app.tar.gz`, `${config === null || config === void 0 ? void 0 : config.dirPath}/_app/`);
49
- }
50
- // listen to socket commands
51
- if (config && this.configManager) {
52
- const server = await server_1.default(configObject, this.configManager, process.env.NODE_ENV === "test");
53
- server.setMaxListeners(30);
54
- // I should call a method to get the EventListener
55
- const dispatcher = fileQueue_1.default.dispatcher({
56
- create: true,
57
- path: `${config.dirPath}/vscode_queue.json`,
58
- });
59
- if (configObject.exercises) {
60
- const agent = ((_d = configObject.config) === null || _d === void 0 ? void 0 : _d.editor.agent) || "";
61
- const path = ((_e = configObject.config) === null || _e === void 0 ? void 0 : _e.dirPath) || "";
62
- const tutorialSlug = ((_f = configObject.config) === null || _f === void 0 ? void 0 : _f.slug) || "";
63
- const steps = configObject.exercises.map((e, index) => ({
64
- slug: e.slug,
65
- position: e.position || index,
66
- files: e.files,
67
- ai_interactions: [],
68
- compilations: [],
69
- tests: [],
70
- is_testeable: e.graded || false,
71
- }));
72
- if (path && steps.length > 0) {
73
- telemetry_1.default.start(agent, steps, path, tutorialSlug);
74
- }
75
- if (config.telemetry) {
76
- telemetry_1.default.urls = config.telemetry;
77
- }
78
- }
79
- socket_1.default.start(config, server, false);
80
- socket_1.default.on("open", (data) => {
81
- console_1.default.debug("Opening these files: ", data);
82
- const files = misc_1.prioritizeHTMLFile(data.files);
83
- if (config.editor.agent === "os") {
84
- osOperations_1.eventManager.enqueue(dispatcher.events.OPEN_FILES, files);
85
- }
86
- else {
87
- dispatcher.enqueue(dispatcher.events.OPEN_FILES, files);
88
- }
89
- socket_1.default.ready("Ready to compile...");
90
- });
91
- socket_1.default.on("open_window", (data) => {
92
- console_1.default.debug("Opening window: ", data);
93
- // cli.open(data.url); This uses XDG under the ground
94
- if (config.os !== "linux" || (config.os === "linux" && hasXDG)) {
95
- osOperations_1.eventManager.enqueue(dispatcher.events.OPEN_WINDOW, data);
96
- }
97
- else {
98
- dispatcher.enqueue(dispatcher.events.OPEN_WINDOW, data);
99
- }
100
- socket_1.default.log("open_window", "", undefined, data.url);
101
- });
102
- socket_1.default.on("open_terminal", (exercise) => {
103
- console_1.default.debug("Opening terminal: ", exercise);
104
- // eventManager.enqueue(dispatcher.events.OPEN_TERMINAL, exercise);
105
- if (config.editor.agent === "vscode") {
106
- dispatcher.enqueue(dispatcher.events.OPEN_TERMINAL, exercise);
107
- }
108
- });
109
- socket_1.default.on("reset", (exercise) => {
110
- var _a;
111
- try {
112
- (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.reset(exercise.exerciseSlug);
113
- socket_1.default.ready("Ready to compile...");
114
- }
115
- catch (error) {
116
- socket_1.default.error("compiler-error", error.message ||
117
- "There was an error reseting the exercise");
118
- setTimeout(() => socket_1.default.ready("Ready to compile..."), 2000);
119
- }
120
- });
121
- socket_1.default.on("build", async (data) => {
122
- var _a;
123
- const exercise = (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.getExercise(data.exerciseSlug);
124
- if (!(exercise === null || exercise === void 0 ? void 0 : exercise.language)) {
125
- socket_1.default.error("compiler-error", "Impossible to detect language to build for " +
126
- data.exerciseSlug +
127
- "...");
128
- return;
129
- }
130
- socket_1.default.log("compiling", "Building exercise " +
131
- data.exerciseSlug +
132
- " with " +
133
- exercise.language +
134
- "...");
135
- await this.config.runHook("action", {
136
- action: "compile",
137
- socket: socket_1.default,
138
- configuration: config,
139
- exercise,
140
- telemetry: telemetry_1.default,
141
- });
142
- });
143
- socket_1.default.on("ai_interaction", (data) => {
144
- const { stepPosition, event, eventData } = data;
145
- telemetry_1.default.registerStepEvent(stepPosition, event, eventData);
146
- });
147
- socket_1.default.on("test", async (data) => {
148
- var _a, _b;
149
- const exercise = (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.getExercise(data.exerciseSlug);
150
- if (!(exercise === null || exercise === void 0 ? void 0 : exercise.language)) {
151
- socket_1.default.error("compiler-error", "Impossible to detect engine language for testing for " +
152
- data.exerciseSlug +
153
- "...");
154
- return;
155
- }
156
- if ((config === null || config === void 0 ? void 0 : config.disabledActions.includes("test")) || (config === null || config === void 0 ? void 0 : config.disableGrading)) {
157
- socket_1.default.ready("Grading is disabled on configuration");
158
- return true;
159
- }
160
- socket_1.default.log("testing", "Testing your exercise using the " + exercise.language + " engine.");
161
- await this.config.runHook("action", {
162
- action: "test",
163
- socket: socket_1.default,
164
- configuration: config,
165
- exercise,
166
- telemetry: telemetry_1.default,
167
- });
168
- try {
169
- if (!configObject.config) {
170
- return;
171
- }
172
- const getReportPath = (ext) => {
173
- var _a;
174
- if (!((_a = configObject.config) === null || _a === void 0 ? void 0 : _a.dirPath)) {
175
- throw new Error("No directory path found in config");
176
- }
177
- return path.join(configObject.config.dirPath, "reports", `${exercise.slug}`, `report.${ext}`);
178
- };
179
- const markdownReportPath = getReportPath("md");
180
- const textReportPath = getReportPath("txt");
181
- if (fs.existsSync(markdownReportPath)) {
182
- let reportContent = "";
183
- reportContent = fs.readFileSync(markdownReportPath, "utf8");
184
- socket_1.default.dialog(reportContent);
185
- }
186
- if (fs.existsSync(textReportPath)) {
187
- let reportContent = "";
188
- reportContent = fs.readFileSync(textReportPath, "utf8");
189
- socket_1.default.dialog(reportContent);
190
- }
191
- }
192
- catch (error) {
193
- console_1.default.debug("Error finding report for exercise.slug", error);
194
- }
195
- (_b = this.configManager) === null || _b === void 0 ? void 0 : _b.save();
196
- return true;
197
- });
198
- const terminate = async () => {
199
- var _a;
200
- console_1.default.error("Terminating Learnpack...");
201
- await telemetry_1.default.submit();
202
- (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.noCurrentExercise();
203
- dispatcher.enqueue(dispatcher.events.END);
204
- process.exit();
205
- };
206
- server.on("close", terminate);
207
- process.on("SIGINT", terminate);
208
- process.on("SIGTERM", terminate);
209
- process.on("SIGHUP", terminate);
210
- // finish the server startup
211
- setTimeout(() => dispatcher.enqueue(dispatcher.events.RUNNING), 1000);
212
- // start watching for file changes
213
- if (StartCommand.flags.watch)
214
- this.configManager.watchIndex(_filename => {
215
- // Instead of reloading with socket.reload(), I just notify the frontend for the file change
216
- socket_1.default.emit("file_change", "ready", _filename);
217
- });
218
- }
219
- }
220
- }
221
- }
222
- exports.default = StartCommand;
223
- StartCommand.description = "Runs a small server with all the exercise instructions";
224
- StartCommand.flags = Object.assign(Object.assign({}, SessionCommand_1.default.flags), { port: command_1.flags.string({ char: "p", description: "server port" }), host: command_1.flags.string({ char: "h", description: "server host" }), disableGrading: command_1.flags.boolean({
225
- char: "D",
226
- description: "disble grading functionality",
227
- default: false,
228
- }),
229
- // disableGrading: flags.boolean({char: 'dg', description: 'disble grading functionality', default: false }),
230
- watch: command_1.flags.boolean({
231
- char: "w",
232
- description: "Watch for file changes",
233
- default: false,
234
- }), editor: command_1.flags.string({
235
- char: "e",
236
- description: "[preview, extension]",
237
- options: ["extension", "preview"],
238
- }), version: command_1.flags.string({
239
- char: "v",
240
- description: "E.g: 1.0.1",
241
- default: undefined,
242
- }), grading: command_1.flags.string({
243
- char: "g",
244
- description: "[isolated, incremental]",
245
- options: ["isolated", "incremental"],
246
- }), debug: command_1.flags.boolean({
247
- char: "d",
248
- description: "debugger mode for more verbage",
249
- default: false,
250
- }) });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // import path from "path";
4
+ const command_1 = require("@oclif/command");
5
+ const fs = require("fs");
6
+ const path = require("path");
7
+ const SessionCommand_1 = require("../utils/SessionCommand");
8
+ const console_1 = require("../utils/console");
9
+ const socket_1 = require("../managers/socket");
10
+ const telemetry_1 = require("../managers/telemetry");
11
+ const server_1 = require("../managers/server");
12
+ const fileQueue_1 = require("../utils/fileQueue");
13
+ const file_1 = require("../managers/file");
14
+ const misc_1 = require("../utils/misc");
15
+ const osOperations_1 = require("../utils/osOperations");
16
+ const checkNotInstalled_1 = require("../utils/checkNotInstalled");
17
+ class StartCommand extends SessionCommand_1.default {
18
+ // 🛑 IMPORTANT
19
+ // Every command that will use the configManager needs this init method
20
+ async init() {
21
+ const { flags } = this.parse(StartCommand);
22
+ await this.initSession(flags);
23
+ }
24
+ async run() {
25
+ var _a, _b, _c, _d, _e, _f;
26
+ // get configuration object
27
+ const configObject = (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.get();
28
+ const hasXDG = await osOperations_1.eventManager.checkXDGInstalled();
29
+ const installedPlugins = this.config.plugins.map(plugin => {
30
+ return `${plugin.pjson.name}`;
31
+ });
32
+ if (configObject) {
33
+ const { config } = configObject;
34
+ // build exerises
35
+ (_b = this.configManager) === null || _b === void 0 ? void 0 : _b.buildIndex();
36
+ console_1.default.debug(`Grading: ${config === null || config === void 0 ? void 0 : config.grading} ${((_c = config === null || config === void 0 ? void 0 : config.disabledActions) === null || _c === void 0 ? void 0 : _c.includes("test")) ? "(disabled)" : ""}, editor: ${config === null || config === void 0 ? void 0 : config.editor.mode} ${config === null || config === void 0 ? void 0 : config.editor.version}, for ${Array.isArray(configObject === null || configObject === void 0 ? void 0 : configObject.exercises) ?
37
+ configObject === null || configObject === void 0 ? void 0 : configObject.exercises.length :
38
+ 0} exercises found`);
39
+ const neededPlugins = await (0, checkNotInstalled_1.checkNotInstalledPlugins)((configObject === null || configObject === void 0 ? void 0 : configObject.exercises) || [], installedPlugins, this);
40
+ const allDepsInstalled = await (0, checkNotInstalled_1.checkNotInstalledDependencies)(neededPlugins.needed);
41
+ if (!allDepsInstalled) {
42
+ this.exit(1);
43
+ }
44
+ const appAlreadyExists = (0, file_1.checkIfDirectoryExists)(`${config === null || config === void 0 ? void 0 : config.dirPath}/_app`);
45
+ if (!appAlreadyExists) {
46
+ // download app and decompress
47
+ await (0, file_1.downloadEditor)(config === null || config === void 0 ? void 0 : config.editor.version, `${config === null || config === void 0 ? void 0 : config.dirPath}/app.tar.gz`);
48
+ console_1.default.info("Decompressing LearnPack UI, this may take a minute...");
49
+ await (0, file_1.decompress)(`${config === null || config === void 0 ? void 0 : config.dirPath}/app.tar.gz`, `${config === null || config === void 0 ? void 0 : config.dirPath}/_app/`);
50
+ }
51
+ // listen to socket commands
52
+ if (config && this.configManager) {
53
+ const server = await (0, server_1.default)(configObject, this.configManager, process.env.NODE_ENV === "test");
54
+ server.setMaxListeners(30);
55
+ // I should call a method to get the EventListener
56
+ const dispatcher = fileQueue_1.default.dispatcher({
57
+ create: true,
58
+ path: `${config.dirPath}/vscode_queue.json`,
59
+ });
60
+ if (configObject.exercises) {
61
+ const agent = ((_d = configObject.config) === null || _d === void 0 ? void 0 : _d.editor.agent) || "";
62
+ const path = ((_e = configObject.config) === null || _e === void 0 ? void 0 : _e.dirPath) || "";
63
+ const tutorialSlug = ((_f = configObject.config) === null || _f === void 0 ? void 0 : _f.slug) || "";
64
+ const steps = configObject.exercises.map((e, index) => ({
65
+ slug: e.slug,
66
+ position: e.position || index,
67
+ files: e.files,
68
+ ai_interactions: [],
69
+ compilations: [],
70
+ tests: [],
71
+ is_testeable: e.graded || false,
72
+ }));
73
+ if (path && steps.length > 0) {
74
+ telemetry_1.default.start(agent, steps, path, tutorialSlug);
75
+ }
76
+ if (config.telemetry) {
77
+ telemetry_1.default.urls = config.telemetry;
78
+ }
79
+ }
80
+ socket_1.default.start(config, server, false);
81
+ socket_1.default.on("open", (data) => {
82
+ console_1.default.debug("Opening these files: ", data);
83
+ const files = (0, misc_1.prioritizeHTMLFile)(data.files);
84
+ if (config.editor.agent === "os") {
85
+ osOperations_1.eventManager.enqueue(dispatcher.events.OPEN_FILES, files);
86
+ }
87
+ else {
88
+ dispatcher.enqueue(dispatcher.events.OPEN_FILES, files);
89
+ }
90
+ socket_1.default.ready("Ready to compile...");
91
+ });
92
+ socket_1.default.on("open_window", (data) => {
93
+ console_1.default.debug("Opening window: ", data);
94
+ // cli.open(data.url); This uses XDG under the ground
95
+ if (config.os !== "linux" || (config.os === "linux" && hasXDG)) {
96
+ osOperations_1.eventManager.enqueue(dispatcher.events.OPEN_WINDOW, data);
97
+ }
98
+ else {
99
+ dispatcher.enqueue(dispatcher.events.OPEN_WINDOW, data);
100
+ }
101
+ socket_1.default.log("open_window", "", undefined, data.url);
102
+ });
103
+ socket_1.default.on("open_terminal", (exercise) => {
104
+ console_1.default.debug("Opening terminal: ", exercise);
105
+ // eventManager.enqueue(dispatcher.events.OPEN_TERMINAL, exercise);
106
+ if (config.editor.agent === "vscode") {
107
+ dispatcher.enqueue(dispatcher.events.OPEN_TERMINAL, exercise);
108
+ }
109
+ });
110
+ socket_1.default.on("reset", (exercise) => {
111
+ var _a;
112
+ try {
113
+ (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.reset(exercise.exerciseSlug);
114
+ socket_1.default.ready("Ready to compile...");
115
+ }
116
+ catch (error) {
117
+ socket_1.default.error("compiler-error", error.message ||
118
+ "There was an error reseting the exercise");
119
+ setTimeout(() => socket_1.default.ready("Ready to compile..."), 2000);
120
+ }
121
+ });
122
+ socket_1.default.on("build", async (data) => {
123
+ var _a;
124
+ const exercise = (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.getExercise(data.exerciseSlug);
125
+ if (!(exercise === null || exercise === void 0 ? void 0 : exercise.language)) {
126
+ socket_1.default.error("compiler-error", "Impossible to detect language to build for " +
127
+ data.exerciseSlug +
128
+ "...");
129
+ return;
130
+ }
131
+ socket_1.default.log("compiling", "Building exercise " +
132
+ data.exerciseSlug +
133
+ " with " +
134
+ exercise.language +
135
+ "...");
136
+ await this.config.runHook("action", {
137
+ action: "compile",
138
+ socket: socket_1.default,
139
+ configuration: config,
140
+ exercise,
141
+ telemetry: telemetry_1.default,
142
+ });
143
+ });
144
+ socket_1.default.on("ai_interaction", (data) => {
145
+ const { stepPosition, event, eventData } = data;
146
+ telemetry_1.default.registerStepEvent(stepPosition, event, eventData);
147
+ });
148
+ socket_1.default.on("test", async (data) => {
149
+ var _a, _b;
150
+ const exercise = (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.getExercise(data.exerciseSlug);
151
+ if (!(exercise === null || exercise === void 0 ? void 0 : exercise.language)) {
152
+ socket_1.default.error("compiler-error", "Impossible to detect engine language for testing for " +
153
+ data.exerciseSlug +
154
+ "...");
155
+ return;
156
+ }
157
+ if ((config === null || config === void 0 ? void 0 : config.disabledActions.includes("test")) ||
158
+ (config === null || config === void 0 ? void 0 : config.disableGrading)) {
159
+ socket_1.default.ready("Grading is disabled on configuration");
160
+ return true;
161
+ }
162
+ socket_1.default.log("testing", "Testing your exercise using the " + exercise.language + " engine.");
163
+ await this.config.runHook("action", {
164
+ action: "test",
165
+ socket: socket_1.default,
166
+ configuration: config,
167
+ exercise,
168
+ telemetry: telemetry_1.default,
169
+ });
170
+ try {
171
+ if (!configObject.config) {
172
+ return;
173
+ }
174
+ const getReportPath = (ext) => {
175
+ var _a;
176
+ if (!((_a = configObject.config) === null || _a === void 0 ? void 0 : _a.dirPath)) {
177
+ throw new Error("No directory path found in config");
178
+ }
179
+ return path.join(configObject.config.dirPath, "reports", `${exercise.slug}`, `report.${ext}`);
180
+ };
181
+ const markdownReportPath = getReportPath("md");
182
+ const textReportPath = getReportPath("txt");
183
+ if (fs.existsSync(markdownReportPath)) {
184
+ let reportContent = "";
185
+ reportContent = fs.readFileSync(markdownReportPath, "utf8");
186
+ socket_1.default.dialog(reportContent);
187
+ }
188
+ if (fs.existsSync(textReportPath)) {
189
+ let reportContent = "";
190
+ reportContent = fs.readFileSync(textReportPath, "utf8");
191
+ socket_1.default.dialog(reportContent);
192
+ }
193
+ }
194
+ catch (error) {
195
+ console_1.default.debug("Error finding report for exercise.slug", error);
196
+ }
197
+ (_b = this.configManager) === null || _b === void 0 ? void 0 : _b.save();
198
+ return true;
199
+ });
200
+ const terminate = async () => {
201
+ var _a;
202
+ console_1.default.error("Terminating Learnpack...");
203
+ await telemetry_1.default.submit();
204
+ (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.noCurrentExercise();
205
+ dispatcher.enqueue(dispatcher.events.END);
206
+ process.exit();
207
+ };
208
+ server.on("close", terminate);
209
+ process.on("SIGINT", terminate);
210
+ process.on("SIGTERM", terminate);
211
+ process.on("SIGHUP", terminate);
212
+ // finish the server startup
213
+ setTimeout(() => dispatcher.enqueue(dispatcher.events.RUNNING), 1000);
214
+ // start watching for file changes
215
+ if (StartCommand.flags.watch)
216
+ this.configManager.watchIndex(_filename => {
217
+ // Instead of reloading with socket.reload(), I just notify the frontend for the file change
218
+ socket_1.default.emit("file_change", "ready", _filename);
219
+ });
220
+ }
221
+ }
222
+ }
223
+ }
224
+ StartCommand.description = "Runs a small server with all the exercise instructions";
225
+ StartCommand.flags = Object.assign(Object.assign({}, SessionCommand_1.default.flags), { port: command_1.flags.string({ char: "p", description: "server port" }), host: command_1.flags.string({ char: "h", description: "server host" }), disableGrading: command_1.flags.boolean({
226
+ char: "D",
227
+ description: "disble grading functionality",
228
+ default: false,
229
+ }),
230
+ // disableGrading: flags.boolean({char: 'dg', description: 'disble grading functionality', default: false }),
231
+ watch: command_1.flags.boolean({
232
+ char: "w",
233
+ description: "Watch for file changes",
234
+ default: false,
235
+ }), editor: command_1.flags.string({
236
+ char: "e",
237
+ description: "[preview, extension]",
238
+ options: ["extension", "preview"],
239
+ }), version: command_1.flags.string({
240
+ char: "v",
241
+ description: "E.g: 1.0.1",
242
+ default: undefined,
243
+ }), grading: command_1.flags.string({
244
+ char: "g",
245
+ description: "[isolated, incremental]",
246
+ options: ["isolated", "incremental"],
247
+ }), debug: command_1.flags.boolean({
248
+ char: "d",
249
+ description: "debugger mode for more verbage",
250
+ default: false,
251
+ }) });
252
+ exports.default = StartCommand;
@@ -1,6 +1,6 @@
1
- import SessionCommand from "../utils/SessionCommand";
2
- declare class TestCommand extends SessionCommand {
3
- init(): Promise<void>;
4
- run(): Promise<void>;
5
- }
6
- export default TestCommand;
1
+ import SessionCommand from "../utils/SessionCommand";
2
+ declare class TestCommand extends SessionCommand {
3
+ init(): Promise<void>;
4
+ run(): Promise<void>;
5
+ }
6
+ export default TestCommand;