@learnpack/learnpack 2.0.2 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,234 +1,234 @@
1
- // import path from "path";
2
- import { flags } from "@oclif/command";
3
- import SessionCommand from "../utils/SessionCommand";
4
- import Console from "../utils/console";
5
- import socket from "../managers/socket";
6
- import queue from "../utils/fileQueue";
7
- import { decompress, downloadEditor } from "../managers/file";
8
- import { prioritizeHTMLFile } from "../utils/misc";
9
-
10
- import createServer from "../managers/server";
11
-
12
- import { IGitpodData } from "../models/gitpod-data";
13
- import { IExercise, IExerciseData } from "../models/exercise-obj";
14
-
15
- export default class StartCommand extends SessionCommand {
16
- static description = "Runs a small server with all the exercise instructions";
17
-
18
- static flags = {
19
- ...SessionCommand.flags,
20
- port: flags.string({ char: "p", description: "server port" }),
21
- host: flags.string({ char: "h", description: "server host" }),
22
- disableGrading: flags.boolean({
23
- char: "D",
24
- description: "disble grading functionality",
25
- default: false,
26
- }),
27
- // disableGrading: flags.boolean({char: 'dg', description: 'disble grading functionality', default: false }),
28
- watch: flags.boolean({
29
- char: "w",
30
- description: "Watch for file changes",
31
- default: false,
32
- }),
33
- editor: flags.string({
34
- char: "e",
35
- description: "[standalone, gitpod]",
36
- options: ["standalone", "gitpod"],
37
- }),
38
- version: flags.string({
39
- char: "v",
40
- description: "E.g: 1.0.1",
41
- default: undefined,
42
- }),
43
- grading: flags.string({
44
- char: "g",
45
- description: "[isolated, incremental]",
46
- options: ["isolated", "incremental"],
47
- }),
48
- debug: flags.boolean({
49
- char: "d",
50
- description: "debugger mode for more verbage",
51
- default: false,
52
- }),
53
- };
54
-
55
- // 🛑 IMPORTANT
56
- // Every command that will use the configManager needs this init method
57
- async init() {
58
- const { flags } = this.parse(StartCommand);
59
- await this.initSession(flags);
60
- }
61
-
62
- async run() {
63
- // get configuration object
64
- const configObject = this.configManager?.get();
65
- const config = configObject?.config;
66
-
67
- if (configObject) {
68
- const { config } = configObject;
69
-
70
- // build exerises
71
- this.configManager?.buildIndex();
72
-
73
- Console.debug(
74
- `Grading: ${config?.grading} ${
75
- config?.disabledActions?.includes("test") ? "(disabled)" : ""
76
- }, editor: ${config?.editor.mode} ${config?.editor.version}, for ${
77
- Array.isArray(configObject?.exercises) ?
78
- configObject?.exercises.length :
79
- 0
80
- } exercises found`
81
- );
82
-
83
- // download app and decompress
84
- await downloadEditor(
85
- config?.editor.version,
86
- `${config?.dirPath}/app.tar.gz`
87
- );
88
-
89
- Console.info("Decompressing LearnPack UI, this may take a minute...");
90
- await decompress(
91
- `${config?.dirPath}/app.tar.gz`,
92
- `${config?.dirPath}/_app/`
93
- );
94
-
95
- // listen to socket commands
96
- if (config && this.configManager) {
97
- const server = await createServer(configObject, this.configManager);
98
-
99
- const dispatcher = queue.dispatcher({
100
- create: true,
101
- path: `${config.dirPath}/vscode_queue.json`,
102
- });
103
-
104
- socket.start(config, server, false);
105
-
106
- socket.on("open", (data: IGitpodData) => {
107
- Console.debug("Opening these files: ", data);
108
- const files = prioritizeHTMLFile(data.files);
109
- dispatcher.enqueue(dispatcher.events.OPEN_FILES, files);
110
- socket.ready("Ready to compile...");
111
- });
112
-
113
- socket.on("open_window", (data: IGitpodData) => {
114
- Console.debug("Opening window: ", data);
115
- dispatcher.enqueue(dispatcher.events.OPEN_WINDOW, data);
116
- socket.ready("Ready to compile...");
117
- });
118
-
119
- socket.on("reset", (exercise: IExerciseData) => {
120
- try {
121
- this.configManager?.reset(exercise.exerciseSlug);
122
- dispatcher.enqueue(
123
- dispatcher.events.RESET_EXERCISE,
124
- exercise.exerciseSlug
125
- );
126
- socket.ready("Ready to compile...");
127
- } catch (error) {
128
- socket.error(
129
- "compiler-error",
130
- (error as TypeError).message ||
131
- "There was an error reseting the exercise"
132
- );
133
- setTimeout(() => socket.ready("Ready to compile..."), 2000);
134
- }
135
- });
136
- // socket.on("preview", (data) => {
137
- // Console.debug("Preview triggered, removing the 'preview' action ")
138
- // socket.removeAllowed("preview")
139
- // socket.log('ready',['Ready to compile...'])
140
- // })
141
-
142
- socket.on("build", async (data: IExerciseData) => {
143
- const exercise = this.configManager?.getExercise(data.exerciseSlug);
144
-
145
- if (!exercise?.language) {
146
- socket.error(
147
- "compiler-error",
148
- "Impossible to detect language to build for " +
149
- data.exerciseSlug +
150
- "..."
151
- );
152
- return;
153
- }
154
-
155
- socket.log(
156
- "compiling",
157
- "Building exercise " +
158
- data.exerciseSlug +
159
- " with " +
160
- exercise.language +
161
- "..."
162
- );
163
- await this.config.runHook("action", {
164
- action: "compile",
165
- socket,
166
- configuration: config,
167
- exercise,
168
- });
169
- });
170
-
171
- socket.on("test", async (data: IExerciseData) => {
172
- const exercise = this.configManager?.getExercise(data.exerciseSlug);
173
-
174
- if (!exercise?.language) {
175
- socket.error(
176
- "compiler-error",
177
- "Impossible to detect engine language for testing for " +
178
- data.exerciseSlug +
179
- "..."
180
- );
181
- return;
182
- }
183
-
184
- if (
185
- config?.disabledActions!.includes("test") ||
186
- config?.disableGrading
187
- ) {
188
- socket.ready("Grading is disabled on configuration");
189
- return true;
190
- }
191
-
192
- socket.log(
193
- "testing",
194
- "Testing your exercise using the " + exercise.language + " engine."
195
- );
196
-
197
- await this.config.runHook("action", {
198
- action: "test",
199
- socket,
200
- configuration: config,
201
- exercise,
202
- });
203
- this.configManager?.save();
204
-
205
- return true;
206
- });
207
-
208
- const terminate = () => {
209
- Console.debug("Terminating Learnpack...");
210
- server.terminate(() => {
211
- this.configManager?.noCurrentExercise();
212
- dispatcher.enqueue(dispatcher.events.END);
213
- process.exit();
214
- });
215
- };
216
-
217
- server.on("close", terminate);
218
- process.on("SIGINT", terminate);
219
- process.on("SIGTERM", terminate);
220
- process.on("SIGHUP", terminate);
221
-
222
- // finish the server startup
223
- setTimeout(() => dispatcher.enqueue(dispatcher.events.RUNNING), 1000);
224
-
225
- // start watching for file changes
226
-
227
- if (StartCommand.flags.watch)
228
- this.configManager.watchIndex(_exercises =>
229
- socket.reload(null, _exercises)
230
- );
231
- }
232
- }
233
- }
234
- }
1
+ // import path from "path";
2
+ import { flags } from "@oclif/command";
3
+ import SessionCommand from "../utils/SessionCommand";
4
+ import Console from "../utils/console";
5
+ import socket from "../managers/socket";
6
+ import queue from "../utils/fileQueue";
7
+ import { decompress, downloadEditor } from "../managers/file";
8
+ import { prioritizeHTMLFile } from "../utils/misc";
9
+
10
+ import createServer from "../managers/server";
11
+
12
+ import { IGitpodData } from "../models/gitpod-data";
13
+ import { IExercise, IExerciseData } from "../models/exercise-obj";
14
+
15
+ export default class StartCommand extends SessionCommand {
16
+ static description = "Runs a small server with all the exercise instructions";
17
+
18
+ static flags = {
19
+ ...SessionCommand.flags,
20
+ port: flags.string({ char: "p", description: "server port" }),
21
+ host: flags.string({ char: "h", description: "server host" }),
22
+ disableGrading: flags.boolean({
23
+ char: "D",
24
+ description: "disble grading functionality",
25
+ default: false,
26
+ }),
27
+ // disableGrading: flags.boolean({char: 'dg', description: 'disble grading functionality', default: false }),
28
+ watch: flags.boolean({
29
+ char: "w",
30
+ description: "Watch for file changes",
31
+ default: false,
32
+ }),
33
+ editor: flags.string({
34
+ char: "e",
35
+ description: "[standalone, gitpod]",
36
+ options: ["standalone", "gitpod"],
37
+ }),
38
+ version: flags.string({
39
+ char: "v",
40
+ description: "E.g: 1.0.1",
41
+ default: undefined,
42
+ }),
43
+ grading: flags.string({
44
+ char: "g",
45
+ description: "[isolated, incremental]",
46
+ options: ["isolated", "incremental"],
47
+ }),
48
+ debug: flags.boolean({
49
+ char: "d",
50
+ description: "debugger mode for more verbage",
51
+ default: false,
52
+ }),
53
+ };
54
+
55
+ // 🛑 IMPORTANT
56
+ // Every command that will use the configManager needs this init method
57
+ async init() {
58
+ const { flags } = this.parse(StartCommand);
59
+ await this.initSession(flags);
60
+ }
61
+
62
+ async run() {
63
+ // get configuration object
64
+ const configObject = this.configManager?.get();
65
+ const config = configObject?.config;
66
+
67
+ if (configObject) {
68
+ const { config } = configObject;
69
+
70
+ // build exerises
71
+ this.configManager?.buildIndex();
72
+
73
+ Console.debug(
74
+ `Grading: ${config?.grading} ${
75
+ config?.disabledActions?.includes("test") ? "(disabled)" : ""
76
+ }, editor: ${config?.editor.mode} ${config?.editor.version}, for ${
77
+ Array.isArray(configObject?.exercises) ?
78
+ configObject?.exercises.length :
79
+ 0
80
+ } exercises found`
81
+ );
82
+
83
+ // download app and decompress
84
+ await downloadEditor(
85
+ config?.editor.version,
86
+ `${config?.dirPath}/app.tar.gz`
87
+ );
88
+
89
+ Console.info("Decompressing LearnPack UI, this may take a minute...");
90
+ await decompress(
91
+ `${config?.dirPath}/app.tar.gz`,
92
+ `${config?.dirPath}/_app/`
93
+ );
94
+
95
+ // listen to socket commands
96
+ if (config && this.configManager) {
97
+ const server = await createServer(configObject, this.configManager);
98
+
99
+ const dispatcher = queue.dispatcher({
100
+ create: true,
101
+ path: `${config.dirPath}/vscode_queue.json`,
102
+ });
103
+
104
+ socket.start(config, server, false);
105
+
106
+ socket.on("open", (data: IGitpodData) => {
107
+ Console.debug("Opening these files: ", data);
108
+ const files = prioritizeHTMLFile(data.files);
109
+ dispatcher.enqueue(dispatcher.events.OPEN_FILES, files);
110
+ socket.ready("Ready to compile...");
111
+ });
112
+
113
+ socket.on("open_window", (data: IGitpodData) => {
114
+ Console.debug("Opening window: ", data);
115
+ dispatcher.enqueue(dispatcher.events.OPEN_WINDOW, data);
116
+ socket.ready("Ready to compile...");
117
+ });
118
+
119
+ socket.on("reset", (exercise: IExerciseData) => {
120
+ try {
121
+ this.configManager?.reset(exercise.exerciseSlug);
122
+ dispatcher.enqueue(
123
+ dispatcher.events.RESET_EXERCISE,
124
+ exercise.exerciseSlug
125
+ );
126
+ socket.ready("Ready to compile...");
127
+ } catch (error) {
128
+ socket.error(
129
+ "compiler-error",
130
+ (error as TypeError).message ||
131
+ "There was an error reseting the exercise"
132
+ );
133
+ setTimeout(() => socket.ready("Ready to compile..."), 2000);
134
+ }
135
+ });
136
+ // socket.on("preview", (data) => {
137
+ // Console.debug("Preview triggered, removing the 'preview' action ")
138
+ // socket.removeAllowed("preview")
139
+ // socket.log('ready',['Ready to compile...'])
140
+ // })
141
+
142
+ socket.on("build", async (data: IExerciseData) => {
143
+ const exercise = this.configManager?.getExercise(data.exerciseSlug);
144
+
145
+ if (!exercise?.language) {
146
+ socket.error(
147
+ "compiler-error",
148
+ "Impossible to detect language to build for " +
149
+ data.exerciseSlug +
150
+ "..."
151
+ );
152
+ return;
153
+ }
154
+
155
+ socket.log(
156
+ "compiling",
157
+ "Building exercise " +
158
+ data.exerciseSlug +
159
+ " with " +
160
+ exercise.language +
161
+ "..."
162
+ );
163
+ await this.config.runHook("action", {
164
+ action: "compile",
165
+ socket,
166
+ configuration: config,
167
+ exercise,
168
+ });
169
+ });
170
+
171
+ socket.on("test", async (data: IExerciseData) => {
172
+ const exercise = this.configManager?.getExercise(data.exerciseSlug);
173
+
174
+ if (!exercise?.language) {
175
+ socket.error(
176
+ "compiler-error",
177
+ "Impossible to detect engine language for testing for " +
178
+ data.exerciseSlug +
179
+ "..."
180
+ );
181
+ return;
182
+ }
183
+
184
+ if (
185
+ config?.disabledActions!.includes("test") ||
186
+ config?.disableGrading
187
+ ) {
188
+ socket.ready("Grading is disabled on configuration");
189
+ return true;
190
+ }
191
+
192
+ socket.log(
193
+ "testing",
194
+ "Testing your exercise using the " + exercise.language + " engine."
195
+ );
196
+
197
+ await this.config.runHook("action", {
198
+ action: "test",
199
+ socket,
200
+ configuration: config,
201
+ exercise,
202
+ });
203
+ this.configManager?.save();
204
+
205
+ return true;
206
+ });
207
+
208
+ const terminate = () => {
209
+ Console.debug("Terminating Learnpack...");
210
+ server.terminate(() => {
211
+ this.configManager?.noCurrentExercise();
212
+ dispatcher.enqueue(dispatcher.events.END);
213
+ process.exit();
214
+ });
215
+ };
216
+
217
+ server.on("close", terminate);
218
+ process.on("SIGINT", terminate);
219
+ process.on("SIGTERM", terminate);
220
+ process.on("SIGHUP", terminate);
221
+
222
+ // finish the server startup
223
+ setTimeout(() => dispatcher.enqueue(dispatcher.events.RUNNING), 1000);
224
+
225
+ // start watching for file changes
226
+
227
+ if (StartCommand.flags.watch)
228
+ this.configManager.watchIndex(_exercises =>
229
+ socket.reload(null, _exercises)
230
+ );
231
+ }
232
+ }
233
+ }
234
+ }
@@ -1,85 +1,85 @@
1
- import Console from "../utils/console";
2
- import SessionCommand from "../utils/SessionCommand";
3
- import socket from "../managers/socket";
4
-
5
- import createServer from "../managers/server";
6
- import ExercisesQueue from "../utils/exercisesQueue";
7
- import { IExercise } from "../models/exercise-obj";
8
-
9
- class TestCommand extends SessionCommand {
10
- async init() {
11
- const { flags } = this.parse(TestCommand);
12
- await this.initSession(flags);
13
- }
14
-
15
- async run() {
16
- const {
17
- args: { exerciseSlug },
18
- } = this.parse(TestCommand);
19
-
20
- // Build exercises index
21
- this.configManager?.buildIndex();
22
-
23
- let exercises: IExercise[] | undefined = [];
24
-
25
- // test all exercises
26
- !exerciseSlug ?
27
- (exercises = this.configManager?.getAllExercises()) :
28
- (exercises = [this.configManager!.getExercise(exerciseSlug)]);
29
-
30
- const exercisesQueue = new ExercisesQueue(exercises);
31
-
32
- const configObject = this.configManager?.get();
33
-
34
- let hasFailed = false;
35
- let failedTestsCount = 0;
36
- let successTestsCount = 0;
37
- const testsToRunCount = exercisesQueue.size();
38
-
39
- configObject!.config!.testingFinishedCallback = ({ result }) => {
40
- if (result === "failed") {
41
- hasFailed = true;
42
- failedTestsCount++;
43
- } else {
44
- successTestsCount++;
45
- }
46
-
47
- if (exercisesQueue.isEmpty()) {
48
- Console.info(
49
- `${testsToRunCount} test${testsToRunCount > 1 ? "s" : ""} runned`
50
- );
51
- Console.success(
52
- `${successTestsCount} test${successTestsCount > 1 ? "s" : ""} passed`
53
- );
54
- Console.error(
55
- `${failedTestsCount} test${failedTestsCount > 1 ? "s" : ""} failed`
56
- );
57
-
58
- process.exit(hasFailed ? 1 : 0);
59
- } else {
60
- exercisesQueue.pop()!.test!(this.config, config!, socket);
61
- }
62
- };
63
-
64
- const config = configObject?.config;
65
-
66
- const server = await createServer(configObject!, this.configManager!, true);
67
-
68
- socket.start(config!, server, true);
69
-
70
- exercisesQueue.pop()!.test!(this.config, config!, socket);
71
- }
72
- }
73
-
74
- TestCommand.description = `Test exercises`;
75
-
76
- TestCommand.args = [
77
- {
78
- name: "exerciseSlug",
79
- required: false,
80
- description: "The name of the exercise to test",
81
- hidden: false,
82
- },
83
- ];
84
-
85
- export default TestCommand;
1
+ import Console from "../utils/console";
2
+ import SessionCommand from "../utils/SessionCommand";
3
+ import socket from "../managers/socket";
4
+
5
+ import createServer from "../managers/server";
6
+ import ExercisesQueue from "../utils/exercisesQueue";
7
+ import { IExercise } from "../models/exercise-obj";
8
+
9
+ class TestCommand extends SessionCommand {
10
+ async init() {
11
+ const { flags } = this.parse(TestCommand);
12
+ await this.initSession(flags);
13
+ }
14
+
15
+ async run() {
16
+ const {
17
+ args: { exerciseSlug },
18
+ } = this.parse(TestCommand);
19
+
20
+ // Build exercises index
21
+ this.configManager?.buildIndex();
22
+
23
+ let exercises: IExercise[] | undefined = [];
24
+
25
+ // test all exercises
26
+ !exerciseSlug ?
27
+ (exercises = this.configManager?.getAllExercises()) :
28
+ (exercises = [this.configManager!.getExercise(exerciseSlug)]);
29
+
30
+ const exercisesQueue = new ExercisesQueue(exercises);
31
+
32
+ const configObject = this.configManager?.get();
33
+
34
+ let hasFailed = false;
35
+ let failedTestsCount = 0;
36
+ let successTestsCount = 0;
37
+ const testsToRunCount = exercisesQueue.size();
38
+
39
+ configObject!.config!.testingFinishedCallback = ({ result }) => {
40
+ if (result === "failed") {
41
+ hasFailed = true;
42
+ failedTestsCount++;
43
+ } else {
44
+ successTestsCount++;
45
+ }
46
+
47
+ if (exercisesQueue.isEmpty()) {
48
+ Console.info(
49
+ `${testsToRunCount} test${testsToRunCount > 1 ? "s" : ""} runned`
50
+ );
51
+ Console.success(
52
+ `${successTestsCount} test${successTestsCount > 1 ? "s" : ""} passed`
53
+ );
54
+ Console.error(
55
+ `${failedTestsCount} test${failedTestsCount > 1 ? "s" : ""} failed`
56
+ );
57
+
58
+ process.exit(hasFailed ? 1 : 0);
59
+ } else {
60
+ exercisesQueue.pop()!.test!(this.config, config!, socket);
61
+ }
62
+ };
63
+
64
+ const config = configObject?.config;
65
+
66
+ const server = await createServer(configObject!, this.configManager!, true);
67
+
68
+ socket.start(config!, server, true);
69
+
70
+ exercisesQueue.pop()!.test!(this.config, config!, socket);
71
+ }
72
+ }
73
+
74
+ TestCommand.description = `Test exercises`;
75
+
76
+ TestCommand.args = [
77
+ {
78
+ name: "exerciseSlug",
79
+ required: false,
80
+ description: "The name of the exercise to test",
81
+ hidden: false,
82
+ },
83
+ ];
84
+
85
+ export default TestCommand;