@learnpack/learnpack 2.1.39 → 2.1.40
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.
- package/README.md +370 -35
- package/bin/run +17 -17
- package/bin/run.cmd +3 -3
- package/lib/commands/audit.d.ts +6 -6
- package/lib/commands/audit.js +342 -342
- package/lib/commands/clean.d.ts +8 -8
- package/lib/commands/clean.js +25 -25
- package/lib/commands/download.d.ts +13 -13
- package/lib/commands/download.js +55 -55
- package/lib/commands/init.d.ts +9 -9
- package/lib/commands/init.js +123 -123
- package/lib/commands/login.d.ts +14 -14
- package/lib/commands/login.js +37 -37
- package/lib/commands/logout.d.ts +14 -14
- package/lib/commands/logout.js +37 -37
- package/lib/commands/publish.d.ts +14 -14
- package/lib/commands/publish.js +82 -82
- package/lib/commands/start.d.ts +7 -7
- package/lib/commands/start.js +239 -208
- package/lib/commands/test.d.ts +6 -6
- package/lib/commands/test.js +62 -62
- package/lib/index.d.ts +1 -1
- package/lib/index.js +4 -4
- package/lib/managers/config/allowed_files.d.ts +5 -5
- package/lib/managers/config/allowed_files.js +30 -30
- package/lib/managers/config/defaults.d.ts +41 -41
- package/lib/managers/config/defaults.js +44 -44
- package/lib/managers/config/exercise.d.ts +36 -36
- package/lib/managers/config/exercise.js +236 -236
- package/lib/managers/config/index.d.ts +3 -3
- package/lib/managers/config/index.js +337 -337
- package/lib/managers/file.d.ts +14 -14
- package/lib/managers/file.js +153 -153
- package/lib/managers/gitpod.d.ts +3 -3
- package/lib/managers/gitpod.js +67 -67
- package/lib/managers/server/index.d.ts +6 -6
- package/lib/managers/server/index.js +58 -58
- package/lib/managers/server/routes.d.ts +4 -4
- package/lib/managers/server/routes.js +219 -219
- package/lib/managers/session.d.ts +3 -3
- package/lib/managers/session.js +125 -125
- package/lib/managers/socket.d.ts +3 -3
- package/lib/managers/socket.js +176 -176
- package/lib/managers/telemetry.d.ts +74 -74
- package/lib/managers/telemetry.js +206 -206
- package/lib/managers/test.js +84 -84
- package/lib/models/action.d.ts +2 -2
- package/lib/models/action.js +2 -2
- package/lib/models/audit.d.ts +15 -15
- package/lib/models/audit.js +2 -2
- package/lib/models/config-manager.d.ts +21 -21
- package/lib/models/config-manager.js +2 -2
- package/lib/models/config.d.ts +68 -67
- package/lib/models/config.js +2 -2
- package/lib/models/counter.d.ts +11 -11
- package/lib/models/counter.js +2 -2
- package/lib/models/errors.d.ts +15 -15
- package/lib/models/errors.js +2 -2
- package/lib/models/exercise-obj.d.ts +30 -30
- package/lib/models/exercise-obj.js +2 -2
- package/lib/models/file.d.ts +5 -5
- package/lib/models/file.js +2 -2
- package/lib/models/findings.d.ts +17 -17
- package/lib/models/findings.js +2 -2
- package/lib/models/flags.d.ts +10 -10
- package/lib/models/flags.js +2 -2
- package/lib/models/front-matter.d.ts +11 -11
- package/lib/models/front-matter.js +2 -2
- package/lib/models/gitpod-data.d.ts +16 -16
- package/lib/models/gitpod-data.js +2 -2
- package/lib/models/language.d.ts +4 -4
- package/lib/models/language.js +2 -2
- package/lib/models/package.d.ts +7 -7
- package/lib/models/package.js +2 -2
- package/lib/models/plugin-config.d.ts +16 -16
- package/lib/models/plugin-config.js +2 -2
- package/lib/models/session.d.ts +31 -31
- package/lib/models/session.js +2 -2
- package/lib/models/socket.d.ts +36 -32
- package/lib/models/socket.js +2 -2
- package/lib/models/status.d.ts +1 -1
- package/lib/models/status.js +2 -2
- package/lib/models/success-types.d.ts +1 -1
- package/lib/models/success-types.js +2 -2
- package/lib/plugin/command/compile.d.ts +6 -6
- package/lib/plugin/command/compile.js +18 -18
- package/lib/plugin/command/test.d.ts +6 -6
- package/lib/plugin/command/test.js +25 -25
- package/lib/plugin/index.d.ts +27 -27
- package/lib/plugin/index.js +7 -7
- package/lib/plugin/plugin.d.ts +8 -8
- package/lib/plugin/plugin.js +68 -68
- package/lib/plugin/utils.d.ts +16 -16
- package/lib/plugin/utils.js +58 -58
- package/lib/ui/download.d.ts +5 -5
- package/lib/ui/download.js +61 -61
- package/lib/utils/BaseCommand.d.ts +8 -8
- package/lib/utils/BaseCommand.js +41 -41
- package/lib/utils/SessionCommand.d.ts +10 -10
- package/lib/utils/SessionCommand.js +43 -43
- package/lib/utils/api.d.ts +14 -14
- package/lib/utils/api.js +255 -255
- package/lib/utils/audit.d.ts +16 -16
- package/lib/utils/audit.js +303 -303
- package/lib/utils/checkNotInstalled.d.ts +2 -0
- package/lib/utils/checkNotInstalled.js +36 -0
- package/lib/utils/console.d.ts +12 -12
- package/lib/utils/console.js +19 -19
- package/lib/utils/errors.d.ts +17 -17
- package/lib/utils/errors.js +100 -100
- package/lib/utils/exercisesQueue.d.ts +9 -9
- package/lib/utils/exercisesQueue.js +38 -38
- package/lib/utils/fileQueue.d.ts +40 -40
- package/lib/utils/fileQueue.js +168 -168
- package/lib/utils/misc.d.ts +1 -1
- package/lib/utils/misc.js +23 -23
- package/lib/utils/osOperations.d.ts +5 -5
- package/lib/utils/osOperations.js +72 -72
- package/lib/utils/validators.d.ts +5 -5
- package/lib/utils/validators.js +17 -17
- package/lib/utils/watcher.d.ts +2 -2
- package/lib/utils/watcher.js +25 -25
- package/oclif.manifest.json +1 -1
- package/package.json +139 -139
- package/src/commands/audit.ts +443 -443
- package/src/commands/clean.ts +29 -29
- package/src/commands/download.ts +61 -61
- package/src/commands/init.ts +170 -170
- package/src/commands/login.ts +42 -42
- package/src/commands/logout.ts +43 -43
- package/src/commands/publish.ts +107 -107
- package/src/commands/start.ts +53 -23
- package/src/commands/test.ts +85 -85
- package/src/index.ts +1 -1
- package/src/managers/config/allowed_files.ts +29 -29
- package/src/managers/config/defaults.ts +42 -42
- package/src/managers/config/exercise.ts +311 -311
- package/src/managers/config/index.ts +455 -455
- package/src/managers/file.ts +196 -196
- package/src/managers/gitpod.ts +84 -84
- package/src/managers/server/index.ts +78 -78
- package/src/managers/server/routes.ts +330 -330
- package/src/managers/session.ts +145 -145
- package/src/managers/socket.ts +250 -250
- package/src/managers/telemetry.ts +346 -346
- package/src/managers/test.ts +83 -83
- package/src/models/action.ts +10 -10
- package/src/models/audit.ts +16 -16
- package/src/models/config-manager.ts +23 -23
- package/src/models/config.ts +5 -3
- package/src/models/counter.ts +11 -11
- package/src/models/errors.ts +22 -22
- package/src/models/exercise-obj.ts +29 -29
- package/src/models/file.ts +5 -5
- package/src/models/findings.ts +18 -18
- package/src/models/flags.ts +10 -10
- package/src/models/front-matter.ts +11 -11
- package/src/models/gitpod-data.ts +19 -19
- package/src/models/language.ts +4 -4
- package/src/models/package.ts +7 -7
- package/src/models/plugin-config.ts +17 -17
- package/src/models/session.ts +34 -34
- package/src/models/socket.ts +5 -0
- package/src/models/status.ts +16 -16
- package/src/models/success-types.ts +1 -1
- package/src/plugin/command/compile.ts +17 -17
- package/src/plugin/command/test.ts +30 -30
- package/src/plugin/index.ts +6 -6
- package/src/plugin/plugin.ts +94 -94
- package/src/plugin/utils.ts +87 -87
- package/src/types/node-fetch.d.ts +1 -1
- package/src/ui/download.ts +71 -71
- package/src/utils/BaseCommand.ts +48 -48
- package/src/utils/SessionCommand.ts +43 -43
- package/src/utils/api.ts +303 -303
- package/src/utils/audit.ts +393 -393
- package/src/utils/checkNotInstalled.ts +46 -0
- package/src/utils/console.ts +24 -24
- package/src/utils/errors.ts +117 -117
- package/src/utils/exercisesQueue.ts +51 -51
- package/src/utils/fileQueue.ts +198 -198
- package/src/utils/misc.ts +23 -23
- package/src/utils/osOperations.ts +79 -79
- package/src/utils/templates/gitignore.txt +19 -19
- package/src/utils/templates/incremental/.learn/exercises/01-hello-world/README.es.md +24 -24
- package/src/utils/templates/incremental/.learn/exercises/01-hello-world/README.md +24 -24
- package/src/utils/templates/incremental/README.ejs +4 -4
- package/src/utils/templates/incremental/README.es.ejs +4 -4
- package/src/utils/templates/isolated/01-hello-world/README.es.md +26 -26
- package/src/utils/templates/isolated/01-hello-world/README.md +26 -26
- package/src/utils/templates/isolated/README.ejs +4 -4
- package/src/utils/templates/isolated/README.es.ejs +4 -4
- package/src/utils/templates/no-grading/README.ejs +4 -4
- package/src/utils/templates/no-grading/README.es.ejs +4 -4
- package/src/utils/validators.ts +18 -18
- package/src/utils/watcher.ts +27 -27
package/lib/managers/session.js
CHANGED
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const console_1 = require("../utils/console");
|
|
4
|
-
const api_1 = require("../utils/api");
|
|
5
|
-
const validator_1 = require("validator");
|
|
6
|
-
const errors_1 = require("../utils/errors");
|
|
7
|
-
const fs = require("fs");
|
|
8
|
-
const cli_ux_1 = require("cli-ux");
|
|
9
|
-
const storage = require("node-persist");
|
|
10
|
-
const telemetry_1 = require("./telemetry");
|
|
11
|
-
const Session = {
|
|
12
|
-
sessionStarted: false,
|
|
13
|
-
token: null,
|
|
14
|
-
config: null,
|
|
15
|
-
currentCohort: null,
|
|
16
|
-
initialize: async function () {
|
|
17
|
-
if (!this.sessionStarted) {
|
|
18
|
-
if (!this.config) {
|
|
19
|
-
throw errors_1.InternalError("Configuration not found");
|
|
20
|
-
}
|
|
21
|
-
if (!fs.existsSync(this.config.dirPath)) {
|
|
22
|
-
fs.mkdirSync(this.config.dirPath);
|
|
23
|
-
}
|
|
24
|
-
await storage.init({ dir: `${this.config.dirPath}/.session` });
|
|
25
|
-
this.sessionStarted = true;
|
|
26
|
-
}
|
|
27
|
-
return true;
|
|
28
|
-
},
|
|
29
|
-
setRigoToken: async function (token) {
|
|
30
|
-
await this.initialize();
|
|
31
|
-
const payload = await storage.getItem("bc-payload");
|
|
32
|
-
await storage.setItem("bc-payload", Object.assign(Object.assign({}, payload), { rigobot: { key: token } }));
|
|
33
|
-
console_1.default.debug("Rigobot token successfuly set");
|
|
34
|
-
return true;
|
|
35
|
-
},
|
|
36
|
-
setPayload: async function (value) {
|
|
37
|
-
await this.initialize();
|
|
38
|
-
await storage.setItem("bc-payload", Object.assign({ token: this.token }, value));
|
|
39
|
-
console_1.default.debug("Payload successfuly found and set for " + value.email);
|
|
40
|
-
return true;
|
|
41
|
-
},
|
|
42
|
-
getPayload: async function () {
|
|
43
|
-
await this.initialize();
|
|
44
|
-
let payload = null;
|
|
45
|
-
try {
|
|
46
|
-
payload = await storage.getItem("bc-payload");
|
|
47
|
-
}
|
|
48
|
-
catch (_a) {
|
|
49
|
-
console_1.default.debug("Error retriving session payload");
|
|
50
|
-
}
|
|
51
|
-
return payload;
|
|
52
|
-
},
|
|
53
|
-
isActive: function () {
|
|
54
|
-
/* if (this.token) {
|
|
55
|
-
return true
|
|
56
|
-
} else {
|
|
57
|
-
return false
|
|
58
|
-
} */
|
|
59
|
-
return !!this.token;
|
|
60
|
-
},
|
|
61
|
-
get: async function (configObj) {
|
|
62
|
-
if (configObj && configObj.config) {
|
|
63
|
-
this.config = configObj.config;
|
|
64
|
-
}
|
|
65
|
-
await this.sync();
|
|
66
|
-
if (!this.isActive()) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
const payload = await this.getPayload();
|
|
70
|
-
return {
|
|
71
|
-
payload,
|
|
72
|
-
token: this.token,
|
|
73
|
-
};
|
|
74
|
-
},
|
|
75
|
-
login: async function () {
|
|
76
|
-
const email = await cli_ux_1.default.prompt("What is your email?");
|
|
77
|
-
if (!validator_1.default.isEmail(email)) {
|
|
78
|
-
throw errors_1.ValidationError("Invalid email");
|
|
79
|
-
}
|
|
80
|
-
const password = await cli_ux_1.default.prompt("What is your password?", {
|
|
81
|
-
type: "hide",
|
|
82
|
-
});
|
|
83
|
-
const data = await api_1.default.login(email, password);
|
|
84
|
-
if (data) {
|
|
85
|
-
cli_ux_1.default.log(data);
|
|
86
|
-
this.start({ token: data.token, payload: data });
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
loginWeb: async function (email, password) {
|
|
90
|
-
if (!validator_1.default.isEmail(email)) {
|
|
91
|
-
throw errors_1.ValidationError("Invalid email");
|
|
92
|
-
}
|
|
93
|
-
const data = await api_1.default.login(email, password);
|
|
94
|
-
if (data) {
|
|
95
|
-
this.start({ token: data.token, payload: data });
|
|
96
|
-
telemetry_1.default.setStudent({
|
|
97
|
-
user_id: data.user_id,
|
|
98
|
-
email: data.email,
|
|
99
|
-
token: data.token,
|
|
100
|
-
});
|
|
101
|
-
return data;
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
sync: async function () {
|
|
105
|
-
const payload = await this.getPayload();
|
|
106
|
-
if (payload) {
|
|
107
|
-
this.token = payload.token;
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
start: async function ({ token, payload = null }) {
|
|
111
|
-
if (!token) {
|
|
112
|
-
throw new Error("A token and email is needed to start a session");
|
|
113
|
-
}
|
|
114
|
-
this.token = token;
|
|
115
|
-
if (payload && (await this.setPayload(payload))) {
|
|
116
|
-
console_1.default.success(`Successfully logged in as ${payload.email}`);
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
destroy: async function () {
|
|
120
|
-
await storage.clear();
|
|
121
|
-
this.token = null;
|
|
122
|
-
console_1.default.success("You have logged out");
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
exports.default = Session;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const console_1 = require("../utils/console");
|
|
4
|
+
const api_1 = require("../utils/api");
|
|
5
|
+
const validator_1 = require("validator");
|
|
6
|
+
const errors_1 = require("../utils/errors");
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
const cli_ux_1 = require("cli-ux");
|
|
9
|
+
const storage = require("node-persist");
|
|
10
|
+
const telemetry_1 = require("./telemetry");
|
|
11
|
+
const Session = {
|
|
12
|
+
sessionStarted: false,
|
|
13
|
+
token: null,
|
|
14
|
+
config: null,
|
|
15
|
+
currentCohort: null,
|
|
16
|
+
initialize: async function () {
|
|
17
|
+
if (!this.sessionStarted) {
|
|
18
|
+
if (!this.config) {
|
|
19
|
+
throw errors_1.InternalError("Configuration not found");
|
|
20
|
+
}
|
|
21
|
+
if (!fs.existsSync(this.config.dirPath)) {
|
|
22
|
+
fs.mkdirSync(this.config.dirPath);
|
|
23
|
+
}
|
|
24
|
+
await storage.init({ dir: `${this.config.dirPath}/.session` });
|
|
25
|
+
this.sessionStarted = true;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
},
|
|
29
|
+
setRigoToken: async function (token) {
|
|
30
|
+
await this.initialize();
|
|
31
|
+
const payload = await storage.getItem("bc-payload");
|
|
32
|
+
await storage.setItem("bc-payload", Object.assign(Object.assign({}, payload), { rigobot: { key: token } }));
|
|
33
|
+
console_1.default.debug("Rigobot token successfuly set");
|
|
34
|
+
return true;
|
|
35
|
+
},
|
|
36
|
+
setPayload: async function (value) {
|
|
37
|
+
await this.initialize();
|
|
38
|
+
await storage.setItem("bc-payload", Object.assign({ token: this.token }, value));
|
|
39
|
+
console_1.default.debug("Payload successfuly found and set for " + value.email);
|
|
40
|
+
return true;
|
|
41
|
+
},
|
|
42
|
+
getPayload: async function () {
|
|
43
|
+
await this.initialize();
|
|
44
|
+
let payload = null;
|
|
45
|
+
try {
|
|
46
|
+
payload = await storage.getItem("bc-payload");
|
|
47
|
+
}
|
|
48
|
+
catch (_a) {
|
|
49
|
+
console_1.default.debug("Error retriving session payload");
|
|
50
|
+
}
|
|
51
|
+
return payload;
|
|
52
|
+
},
|
|
53
|
+
isActive: function () {
|
|
54
|
+
/* if (this.token) {
|
|
55
|
+
return true
|
|
56
|
+
} else {
|
|
57
|
+
return false
|
|
58
|
+
} */
|
|
59
|
+
return !!this.token;
|
|
60
|
+
},
|
|
61
|
+
get: async function (configObj) {
|
|
62
|
+
if (configObj && configObj.config) {
|
|
63
|
+
this.config = configObj.config;
|
|
64
|
+
}
|
|
65
|
+
await this.sync();
|
|
66
|
+
if (!this.isActive()) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const payload = await this.getPayload();
|
|
70
|
+
return {
|
|
71
|
+
payload,
|
|
72
|
+
token: this.token,
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
login: async function () {
|
|
76
|
+
const email = await cli_ux_1.default.prompt("What is your email?");
|
|
77
|
+
if (!validator_1.default.isEmail(email)) {
|
|
78
|
+
throw errors_1.ValidationError("Invalid email");
|
|
79
|
+
}
|
|
80
|
+
const password = await cli_ux_1.default.prompt("What is your password?", {
|
|
81
|
+
type: "hide",
|
|
82
|
+
});
|
|
83
|
+
const data = await api_1.default.login(email, password);
|
|
84
|
+
if (data) {
|
|
85
|
+
cli_ux_1.default.log(data);
|
|
86
|
+
this.start({ token: data.token, payload: data });
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
loginWeb: async function (email, password) {
|
|
90
|
+
if (!validator_1.default.isEmail(email)) {
|
|
91
|
+
throw errors_1.ValidationError("Invalid email");
|
|
92
|
+
}
|
|
93
|
+
const data = await api_1.default.login(email, password);
|
|
94
|
+
if (data) {
|
|
95
|
+
this.start({ token: data.token, payload: data });
|
|
96
|
+
telemetry_1.default.setStudent({
|
|
97
|
+
user_id: data.user_id,
|
|
98
|
+
email: data.email,
|
|
99
|
+
token: data.token,
|
|
100
|
+
});
|
|
101
|
+
return data;
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
sync: async function () {
|
|
105
|
+
const payload = await this.getPayload();
|
|
106
|
+
if (payload) {
|
|
107
|
+
this.token = payload.token;
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
start: async function ({ token, payload = null }) {
|
|
111
|
+
if (!token) {
|
|
112
|
+
throw new Error("A token and email is needed to start a session");
|
|
113
|
+
}
|
|
114
|
+
this.token = token;
|
|
115
|
+
if (payload && (await this.setPayload(payload))) {
|
|
116
|
+
console_1.default.success(`Successfully logged in as ${payload.email}`);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
destroy: async function () {
|
|
120
|
+
await storage.clear();
|
|
121
|
+
this.token = null;
|
|
122
|
+
console_1.default.success("You have logged out");
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
exports.default = Session;
|
package/lib/managers/socket.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ISocket } from "../models/socket";
|
|
2
|
-
declare const SocketManager: ISocket;
|
|
3
|
-
export default SocketManager;
|
|
1
|
+
import { ISocket } from "../models/socket";
|
|
2
|
+
declare const SocketManager: ISocket;
|
|
3
|
+
export default SocketManager;
|
package/lib/managers/socket.js
CHANGED
|
@@ -1,176 +1,176 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const socket_io_1 = require("socket.io");
|
|
4
|
-
const console_1 = require("../utils/console");
|
|
5
|
-
const fileQueue_1 = require("../utils/fileQueue");
|
|
6
|
-
const SocketManager = {
|
|
7
|
-
socket: null,
|
|
8
|
-
config: null,
|
|
9
|
-
allowedActions: [],
|
|
10
|
-
possibleActions: ["build", "reset", "test", "tutorial"],
|
|
11
|
-
isTestingEnvironment: false,
|
|
12
|
-
actionCallBacks: {
|
|
13
|
-
clean: (_, s) => {
|
|
14
|
-
s.logs = [];
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
addAllowed: function (actions) {
|
|
18
|
-
var _a, _b;
|
|
19
|
-
if (!Array.isArray(actions))
|
|
20
|
-
actions = [actions];
|
|
21
|
-
// avoid adding the "test" action if grading is disabled
|
|
22
|
-
if (actions.includes("test") && ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.disabledActions) === null || _b === void 0 ? void 0 : _b.includes("test"))) {
|
|
23
|
-
actions = actions.filter((a) => a !== "test");
|
|
24
|
-
}
|
|
25
|
-
this.allowedActions = [
|
|
26
|
-
...(this.allowedActions || []).filter((a) => !actions.includes(a)),
|
|
27
|
-
...actions,
|
|
28
|
-
];
|
|
29
|
-
},
|
|
30
|
-
removeAllowed: function (actions) {
|
|
31
|
-
if (!Array.isArray(actions)) {
|
|
32
|
-
actions = [actions];
|
|
33
|
-
}
|
|
34
|
-
this.allowedActions = (this.allowedActions || []).filter((a) => !actions.includes(a));
|
|
35
|
-
},
|
|
36
|
-
start: function (config, server, isTestingEnvironment = false) {
|
|
37
|
-
var _a, _b, _c, _d;
|
|
38
|
-
this.config = config;
|
|
39
|
-
this.isTestingEnvironment = isTestingEnvironment;
|
|
40
|
-
this.socket = new socket_io_1.Server(server, {
|
|
41
|
-
allowEIO3: true,
|
|
42
|
-
cors: {
|
|
43
|
-
origin: "http://localhost:5173",
|
|
44
|
-
methods: ["GET", "POST"],
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
this.allowedActions =
|
|
48
|
-
((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.disabledActions) === null || _b === void 0 ? void 0 : _b.includes("test")) || ((_c = this.config) === null || _c === void 0 ? void 0 : _c.disableGrading) ?
|
|
49
|
-
this.possibleActions.filter(a => { var _a, _b; return !((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.disabledActions) === null || _b === void 0 ? void 0 : _b.includes(a)) && a !== "test"; }) :
|
|
50
|
-
this.possibleActions.filter(a => { var _a; return !((_a = this.allowedActions) === null || _a === void 0 ? void 0 : _a.includes(a)); });
|
|
51
|
-
if (((_d = this.config) === null || _d === void 0 ? void 0 : _d.grading) === "incremental") {
|
|
52
|
-
this.removeAllowed("reset");
|
|
53
|
-
}
|
|
54
|
-
if (this.socket) {
|
|
55
|
-
this.socket.on("connection", (socket) => {
|
|
56
|
-
console_1.default.debug("Connection with client successfully established", this.allowedActions);
|
|
57
|
-
if (!this.isTestingEnvironment) {
|
|
58
|
-
this.log("ready", ["Ready to compile or test..."]);
|
|
59
|
-
}
|
|
60
|
-
socket.on("compiler", ({ action, data }) => {
|
|
61
|
-
this.emit("clean", "pending", ["Working..."]);
|
|
62
|
-
if (typeof data.exerciseSlug === "undefined") {
|
|
63
|
-
this.log("internal-error", ["No exercise slug specified"]);
|
|
64
|
-
console_1.default.error("No exercise slug especified");
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (this.actionCallBacks &&
|
|
68
|
-
typeof this.actionCallBacks[action] === "function") {
|
|
69
|
-
this.actionCallBacks[action](data);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
this.log("internal-error", ["Uknown action " + action]);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
on: function (action, callBack) {
|
|
79
|
-
if (this.actionCallBacks) {
|
|
80
|
-
this.actionCallBacks[action] = callBack;
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
clean: function (_ = "pending", logs = []) {
|
|
84
|
-
this.emit("clean", "pending", logs);
|
|
85
|
-
},
|
|
86
|
-
ask: function (questions = []) {
|
|
87
|
-
return new Promise((resolve, _) => {
|
|
88
|
-
this.emit("ask", "pending", ["Waiting for input..."], questions);
|
|
89
|
-
this.on("input", ({ inputs }) => {
|
|
90
|
-
// Workaround to fix issue because null inputs
|
|
91
|
-
let isNull = false;
|
|
92
|
-
// eslint-disable-next-line
|
|
93
|
-
inputs.forEach((input) => {
|
|
94
|
-
if (input === null) {
|
|
95
|
-
isNull = true;
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
if (!isNull) {
|
|
99
|
-
resolve(inputs);
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
},
|
|
104
|
-
reload: function (files = null, exercises = null) {
|
|
105
|
-
this.emit("reload", (files === null || files === void 0 ? void 0 : files.join("")) || "" /* TODO: Check it out this */, exercises);
|
|
106
|
-
},
|
|
107
|
-
openWindow: function (url = "") {
|
|
108
|
-
fileQueue_1.default.dispatcher().enqueue(fileQueue_1.default.events.OPEN_WINDOW, url);
|
|
109
|
-
this.emit(fileQueue_1.default.events.OPEN_WINDOW, "ready", [`Opening ${url}`], [], [], url);
|
|
110
|
-
},
|
|
111
|
-
log: function (status, messages = [], report = [], data = null) {
|
|
112
|
-
this.emit("log", status, messages, [], report, data);
|
|
113
|
-
console_1.default.log(messages);
|
|
114
|
-
},
|
|
115
|
-
emit: function (action, status = "ready", logs = [], inputs = [], report = [], data = null) {
|
|
116
|
-
var _a, _b, _c, _d, _e, _f;
|
|
117
|
-
if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.compiler) &&
|
|
118
|
-
["webpack", "vanillajs", "vue", "react", "css", "html"].includes((_b = this.config) === null || _b === void 0 ? void 0 : _b.compiler)) {
|
|
119
|
-
if (["compiler-success", "compiler-warning"].includes(status))
|
|
120
|
-
this.addAllowed("preview");
|
|
121
|
-
if (["compiler-error"].includes(status) || action === "ready")
|
|
122
|
-
this.removeAllowed("preview");
|
|
123
|
-
}
|
|
124
|
-
if (((_c = this.config) === null || _c === void 0 ? void 0 : _c.grading) === "incremental") {
|
|
125
|
-
this.removeAllowed("reset");
|
|
126
|
-
}
|
|
127
|
-
// eslint-disable-next-line
|
|
128
|
-
(_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.disabledActions) === null || _e === void 0 ? void 0 : _e.forEach((a) => this.removeAllowed(a));
|
|
129
|
-
(_f = this.socket) === null || _f === void 0 ? void 0 : _f.emit("compiler", {
|
|
130
|
-
action,
|
|
131
|
-
status,
|
|
132
|
-
logs,
|
|
133
|
-
allowed: this.allowedActions,
|
|
134
|
-
inputs,
|
|
135
|
-
report,
|
|
136
|
-
data,
|
|
137
|
-
});
|
|
138
|
-
},
|
|
139
|
-
ready: function (message) {
|
|
140
|
-
this.log("ready", [message]);
|
|
141
|
-
},
|
|
142
|
-
success: function (type, stdout) {
|
|
143
|
-
const types = ["compiler", "testing"];
|
|
144
|
-
if (!types.includes(type))
|
|
145
|
-
this.fatal(`Invalid socket success type "${type}" on socket`);
|
|
146
|
-
else if (stdout === "")
|
|
147
|
-
this.log((type + "-success"), [
|
|
148
|
-
"No stdout to display on the console",
|
|
149
|
-
]);
|
|
150
|
-
else
|
|
151
|
-
this.log((type + "-success"), [stdout]);
|
|
152
|
-
},
|
|
153
|
-
error: function (type, stdout) {
|
|
154
|
-
console.error("Socket error: " + type, stdout);
|
|
155
|
-
this.log(type, [stdout]);
|
|
156
|
-
if (this.isTestingEnvironment) {
|
|
157
|
-
this.onTestingFinished({
|
|
158
|
-
result: "failed",
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
complete: function () {
|
|
163
|
-
console.log("complete");
|
|
164
|
-
},
|
|
165
|
-
fatal: function (msg) {
|
|
166
|
-
this.log("internal-error", [msg]);
|
|
167
|
-
throw msg;
|
|
168
|
-
},
|
|
169
|
-
onTestingFinished: function (result) {
|
|
170
|
-
var _a;
|
|
171
|
-
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.testingFinishedCallback) {
|
|
172
|
-
this.config.testingFinishedCallback(result);
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
exports.default = SocketManager;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const socket_io_1 = require("socket.io");
|
|
4
|
+
const console_1 = require("../utils/console");
|
|
5
|
+
const fileQueue_1 = require("../utils/fileQueue");
|
|
6
|
+
const SocketManager = {
|
|
7
|
+
socket: null,
|
|
8
|
+
config: null,
|
|
9
|
+
allowedActions: [],
|
|
10
|
+
possibleActions: ["build", "reset", "test", "tutorial"],
|
|
11
|
+
isTestingEnvironment: false,
|
|
12
|
+
actionCallBacks: {
|
|
13
|
+
clean: (_, s) => {
|
|
14
|
+
s.logs = [];
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
addAllowed: function (actions) {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
if (!Array.isArray(actions))
|
|
20
|
+
actions = [actions];
|
|
21
|
+
// avoid adding the "test" action if grading is disabled
|
|
22
|
+
if (actions.includes("test") && ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.disabledActions) === null || _b === void 0 ? void 0 : _b.includes("test"))) {
|
|
23
|
+
actions = actions.filter((a) => a !== "test");
|
|
24
|
+
}
|
|
25
|
+
this.allowedActions = [
|
|
26
|
+
...(this.allowedActions || []).filter((a) => !actions.includes(a)),
|
|
27
|
+
...actions,
|
|
28
|
+
];
|
|
29
|
+
},
|
|
30
|
+
removeAllowed: function (actions) {
|
|
31
|
+
if (!Array.isArray(actions)) {
|
|
32
|
+
actions = [actions];
|
|
33
|
+
}
|
|
34
|
+
this.allowedActions = (this.allowedActions || []).filter((a) => !actions.includes(a));
|
|
35
|
+
},
|
|
36
|
+
start: function (config, server, isTestingEnvironment = false) {
|
|
37
|
+
var _a, _b, _c, _d;
|
|
38
|
+
this.config = config;
|
|
39
|
+
this.isTestingEnvironment = isTestingEnvironment;
|
|
40
|
+
this.socket = new socket_io_1.Server(server, {
|
|
41
|
+
allowEIO3: true,
|
|
42
|
+
cors: {
|
|
43
|
+
origin: "http://localhost:5173",
|
|
44
|
+
methods: ["GET", "POST"],
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
this.allowedActions =
|
|
48
|
+
((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.disabledActions) === null || _b === void 0 ? void 0 : _b.includes("test")) || ((_c = this.config) === null || _c === void 0 ? void 0 : _c.disableGrading) ?
|
|
49
|
+
this.possibleActions.filter(a => { var _a, _b; return !((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.disabledActions) === null || _b === void 0 ? void 0 : _b.includes(a)) && a !== "test"; }) :
|
|
50
|
+
this.possibleActions.filter(a => { var _a; return !((_a = this.allowedActions) === null || _a === void 0 ? void 0 : _a.includes(a)); });
|
|
51
|
+
if (((_d = this.config) === null || _d === void 0 ? void 0 : _d.grading) === "incremental") {
|
|
52
|
+
this.removeAllowed("reset");
|
|
53
|
+
}
|
|
54
|
+
if (this.socket) {
|
|
55
|
+
this.socket.on("connection", (socket) => {
|
|
56
|
+
console_1.default.debug("Connection with client successfully established", this.allowedActions);
|
|
57
|
+
if (!this.isTestingEnvironment) {
|
|
58
|
+
this.log("ready", ["Ready to compile or test..."]);
|
|
59
|
+
}
|
|
60
|
+
socket.on("compiler", ({ action, data }) => {
|
|
61
|
+
this.emit("clean", "pending", ["Working..."]);
|
|
62
|
+
if (typeof data.exerciseSlug === "undefined") {
|
|
63
|
+
this.log("internal-error", ["No exercise slug specified"]);
|
|
64
|
+
console_1.default.error("No exercise slug especified");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (this.actionCallBacks &&
|
|
68
|
+
typeof this.actionCallBacks[action] === "function") {
|
|
69
|
+
this.actionCallBacks[action](data);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this.log("internal-error", ["Uknown action " + action]);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
on: function (action, callBack) {
|
|
79
|
+
if (this.actionCallBacks) {
|
|
80
|
+
this.actionCallBacks[action] = callBack;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
clean: function (_ = "pending", logs = []) {
|
|
84
|
+
this.emit("clean", "pending", logs);
|
|
85
|
+
},
|
|
86
|
+
ask: function (questions = []) {
|
|
87
|
+
return new Promise((resolve, _) => {
|
|
88
|
+
this.emit("ask", "pending", ["Waiting for input..."], questions);
|
|
89
|
+
this.on("input", ({ inputs }) => {
|
|
90
|
+
// Workaround to fix issue because null inputs
|
|
91
|
+
let isNull = false;
|
|
92
|
+
// eslint-disable-next-line
|
|
93
|
+
inputs.forEach((input) => {
|
|
94
|
+
if (input === null) {
|
|
95
|
+
isNull = true;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
if (!isNull) {
|
|
99
|
+
resolve(inputs);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
reload: function (files = null, exercises = null) {
|
|
105
|
+
this.emit("reload", (files === null || files === void 0 ? void 0 : files.join("")) || "" /* TODO: Check it out this */, exercises);
|
|
106
|
+
},
|
|
107
|
+
openWindow: function (url = "") {
|
|
108
|
+
fileQueue_1.default.dispatcher().enqueue(fileQueue_1.default.events.OPEN_WINDOW, url);
|
|
109
|
+
this.emit(fileQueue_1.default.events.OPEN_WINDOW, "ready", [`Opening ${url}`], [], [], url);
|
|
110
|
+
},
|
|
111
|
+
log: function (status, messages = [], report = [], data = null) {
|
|
112
|
+
this.emit("log", status, messages, [], report, data);
|
|
113
|
+
console_1.default.log(messages);
|
|
114
|
+
},
|
|
115
|
+
emit: function (action, status = "ready", logs = [], inputs = [], report = [], data = null) {
|
|
116
|
+
var _a, _b, _c, _d, _e, _f;
|
|
117
|
+
if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.compiler) &&
|
|
118
|
+
["webpack", "vanillajs", "vue", "react", "css", "html"].includes((_b = this.config) === null || _b === void 0 ? void 0 : _b.compiler)) {
|
|
119
|
+
if (["compiler-success", "compiler-warning"].includes(status))
|
|
120
|
+
this.addAllowed("preview");
|
|
121
|
+
if (["compiler-error"].includes(status) || action === "ready")
|
|
122
|
+
this.removeAllowed("preview");
|
|
123
|
+
}
|
|
124
|
+
if (((_c = this.config) === null || _c === void 0 ? void 0 : _c.grading) === "incremental") {
|
|
125
|
+
this.removeAllowed("reset");
|
|
126
|
+
}
|
|
127
|
+
// eslint-disable-next-line
|
|
128
|
+
(_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.disabledActions) === null || _e === void 0 ? void 0 : _e.forEach((a) => this.removeAllowed(a));
|
|
129
|
+
(_f = this.socket) === null || _f === void 0 ? void 0 : _f.emit("compiler", {
|
|
130
|
+
action,
|
|
131
|
+
status,
|
|
132
|
+
logs,
|
|
133
|
+
allowed: this.allowedActions,
|
|
134
|
+
inputs,
|
|
135
|
+
report,
|
|
136
|
+
data,
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
ready: function (message) {
|
|
140
|
+
this.log("ready", [message]);
|
|
141
|
+
},
|
|
142
|
+
success: function (type, stdout) {
|
|
143
|
+
const types = ["compiler", "testing"];
|
|
144
|
+
if (!types.includes(type))
|
|
145
|
+
this.fatal(`Invalid socket success type "${type}" on socket`);
|
|
146
|
+
else if (stdout === "")
|
|
147
|
+
this.log((type + "-success"), [
|
|
148
|
+
"No stdout to display on the console",
|
|
149
|
+
]);
|
|
150
|
+
else
|
|
151
|
+
this.log((type + "-success"), [stdout]);
|
|
152
|
+
},
|
|
153
|
+
error: function (type, stdout) {
|
|
154
|
+
console.error("Socket error: " + type, stdout);
|
|
155
|
+
this.log(type, [stdout]);
|
|
156
|
+
if (this.isTestingEnvironment) {
|
|
157
|
+
this.onTestingFinished({
|
|
158
|
+
result: "failed",
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
complete: function () {
|
|
163
|
+
console.log("complete");
|
|
164
|
+
},
|
|
165
|
+
fatal: function (msg) {
|
|
166
|
+
this.log("internal-error", [msg]);
|
|
167
|
+
throw msg;
|
|
168
|
+
},
|
|
169
|
+
onTestingFinished: function (result) {
|
|
170
|
+
var _a;
|
|
171
|
+
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.testingFinishedCallback) {
|
|
172
|
+
this.config.testingFinishedCallback(result);
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
exports.default = SocketManager;
|