@learnpack/learnpack 4.0.10 → 4.0.12
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +25 -10
- package/lib/commands/audit.d.ts +6 -6
- package/lib/commands/audit.js +327 -327
- package/lib/commands/build.d.ts +11 -0
- package/lib/commands/build.js +160 -0
- package/lib/commands/clean.d.ts +8 -8
- package/lib/commands/clean.js +22 -22
- package/lib/commands/download.d.ts +13 -13
- package/lib/commands/download.js +52 -52
- package/lib/commands/init.d.ts +9 -9
- package/lib/commands/init.js +127 -127
- package/lib/commands/login.d.ts +14 -14
- package/lib/commands/login.js +34 -34
- package/lib/commands/logout.d.ts +14 -14
- package/lib/commands/logout.js +34 -34
- package/lib/commands/publish.d.ts +14 -14
- package/lib/commands/publish.js +79 -79
- package/lib/commands/start.d.ts +7 -7
- package/lib/commands/start.js +252 -250
- 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 +47 -48
- package/lib/managers/config/defaults.js +51 -51
- package/lib/managers/config/exercise.d.ts +36 -36
- package/lib/managers/config/exercise.js +243 -236
- package/lib/managers/config/index.d.ts +3 -3
- package/lib/managers/config/index.js +464 -459
- package/lib/managers/file.d.ts +14 -14
- package/lib/managers/file.js +190 -184
- package/lib/managers/gitpod.d.ts +3 -3
- package/lib/managers/gitpod.js +67 -67
- package/lib/managers/server/index.d.ts +5 -6
- package/lib/managers/server/index.js +58 -58
- package/lib/managers/server/routes.d.ts +4 -4
- package/lib/managers/server/routes.js +228 -220
- 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 +188 -186
- package/lib/managers/telemetry.d.ts +74 -74
- package/lib/managers/telemetry.js +215 -214
- 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 +86 -86
- 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 +29 -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 +37 -37
- 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 +62 -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 +8 -8
- package/lib/utils/checkNotInstalled.js +185 -181
- 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 +107 -100
- package/lib/utils/exercisesQueue.d.ts +9 -9
- package/lib/utils/exercisesQueue.js +38 -38
- package/lib/utils/fileQueue.d.ts +43 -43
- package/lib/utils/fileQueue.js +169 -169
- package/lib/utils/misc.d.ts +1 -1
- package/lib/utils/misc.js +24 -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 +16 -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 +6 -4
- package/src/commands/build.ts +181 -0
- package/src/managers/config/index.ts +5 -0
- package/src/managers/server/routes.ts +10 -0
- package/src/managers/session.ts +1 -1
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
|
-
|
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 (0, 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 (0, 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.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 (0, 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,186 +1,188 @@
|
|
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") &&
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
...actions,
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
this.
|
40
|
-
this.
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
//
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
if (["compiler-
|
122
|
-
this.
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
this.
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
}
|
186
|
-
|
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") &&
|
23
|
+
((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.disabledActions) === null || _b === void 0 ? void 0 : _b.includes("test"))) {
|
24
|
+
actions = actions.filter((a) => a !== "test");
|
25
|
+
}
|
26
|
+
this.allowedActions = [
|
27
|
+
...(this.allowedActions || []).filter((a) => !actions.includes(a)),
|
28
|
+
...actions,
|
29
|
+
];
|
30
|
+
},
|
31
|
+
removeAllowed: function (actions) {
|
32
|
+
if (!Array.isArray(actions)) {
|
33
|
+
actions = [actions];
|
34
|
+
}
|
35
|
+
this.allowedActions = (this.allowedActions || []).filter((a) => !actions.includes(a));
|
36
|
+
},
|
37
|
+
start: function (config, server, isTestingEnvironment = false) {
|
38
|
+
var _a, _b, _c, _d;
|
39
|
+
this.config = config;
|
40
|
+
this.isTestingEnvironment = isTestingEnvironment;
|
41
|
+
this.socket = new socket_io_1.Server(server, {
|
42
|
+
allowEIO3: true,
|
43
|
+
cors: {
|
44
|
+
origin: "http://localhost:5173",
|
45
|
+
methods: ["GET", "POST"],
|
46
|
+
},
|
47
|
+
});
|
48
|
+
this.allowedActions =
|
49
|
+
((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.disabledActions) === null || _b === void 0 ? void 0 : _b.includes("test")) ||
|
50
|
+
((_c = this.config) === null || _c === void 0 ? void 0 : _c.disableGrading) ?
|
51
|
+
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"; }) :
|
52
|
+
this.possibleActions.filter(a => { var _a; return !((_a = this.allowedActions) === null || _a === void 0 ? void 0 : _a.includes(a)); });
|
53
|
+
if (((_d = this.config) === null || _d === void 0 ? void 0 : _d.grading) === "incremental") {
|
54
|
+
this.removeAllowed("reset");
|
55
|
+
}
|
56
|
+
if (this.socket) {
|
57
|
+
this.socket.on("connection", (socket) => {
|
58
|
+
console_1.default.debug("Connection with client successfully established", this.allowedActions);
|
59
|
+
if (!this.isTestingEnvironment) {
|
60
|
+
this.log("ready", ["Ready to compile or test..."]);
|
61
|
+
}
|
62
|
+
socket.on("compiler", ({ action, data }) => {
|
63
|
+
this.emit("clean", "pending", ["Working..."]);
|
64
|
+
if (typeof data.exerciseSlug === "undefined") {
|
65
|
+
this.log("internal-error", ["No exercise slug specified"]);
|
66
|
+
console_1.default.error("No exercise slug especified");
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
if (this.actionCallBacks &&
|
70
|
+
typeof this.actionCallBacks[action] === "function") {
|
71
|
+
this.actionCallBacks[action](data);
|
72
|
+
}
|
73
|
+
else {
|
74
|
+
this.log("internal-error", ["Uknown action " + action]);
|
75
|
+
}
|
76
|
+
});
|
77
|
+
});
|
78
|
+
}
|
79
|
+
},
|
80
|
+
on: function (action, callBack) {
|
81
|
+
if (this.actionCallBacks) {
|
82
|
+
this.actionCallBacks[action] = callBack;
|
83
|
+
}
|
84
|
+
},
|
85
|
+
clean: function (_ = "pending", logs = []) {
|
86
|
+
this.emit("clean", "pending", logs);
|
87
|
+
},
|
88
|
+
ask: function (questions = []) {
|
89
|
+
return new Promise((resolve, _) => {
|
90
|
+
this.emit("ask", "pending", ["Waiting for input..."], questions);
|
91
|
+
this.on("input", ({ inputs }) => {
|
92
|
+
// Workaround to fix issue because null inputs
|
93
|
+
let isNull = false;
|
94
|
+
// eslint-disable-next-line
|
95
|
+
inputs.forEach((input) => {
|
96
|
+
if (input === null) {
|
97
|
+
isNull = true;
|
98
|
+
}
|
99
|
+
});
|
100
|
+
if (!isNull) {
|
101
|
+
resolve(inputs);
|
102
|
+
}
|
103
|
+
});
|
104
|
+
});
|
105
|
+
},
|
106
|
+
reload: function (files = null, exercises = null) {
|
107
|
+
this.emit("reload", (files === null || files === void 0 ? void 0 : files.join("")) || "", exercises);
|
108
|
+
},
|
109
|
+
openWindow: function (url = "") {
|
110
|
+
fileQueue_1.default.dispatcher().enqueue(fileQueue_1.default.events.OPEN_WINDOW, url);
|
111
|
+
this.emit(fileQueue_1.default.events.OPEN_WINDOW, "ready", [`Opening ${url}`], [], [], url);
|
112
|
+
},
|
113
|
+
log: function (status, messages = [], report = [], data = null) {
|
114
|
+
this.emit("log", status, messages, [], report, data);
|
115
|
+
console_1.default.log(messages);
|
116
|
+
},
|
117
|
+
emit: function (action, status = "ready", logs = [], inputs = [], report = [], data = null) {
|
118
|
+
var _a, _b, _c, _d, _e, _f;
|
119
|
+
if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.compiler) &&
|
120
|
+
["webpack", "vanillajs", "vue", "react", "css", "html"].includes((_b = this.config) === null || _b === void 0 ? void 0 : _b.compiler)) {
|
121
|
+
if (["compiler-success", "compiler-warning"].includes(status))
|
122
|
+
this.addAllowed("preview");
|
123
|
+
if (["compiler-error"].includes(status) || action === "ready")
|
124
|
+
this.removeAllowed("preview");
|
125
|
+
}
|
126
|
+
if (((_c = this.config) === null || _c === void 0 ? void 0 : _c.grading) === "incremental") {
|
127
|
+
this.removeAllowed("reset");
|
128
|
+
}
|
129
|
+
// eslint-disable-next-line
|
130
|
+
(_e = (_d = this.config) === null || _d === void 0 ? void 0 : _d.disabledActions) === null || _e === void 0 ? void 0 : _e.forEach((a) => this.removeAllowed(a));
|
131
|
+
(_f = this.socket) === null || _f === void 0 ? void 0 : _f.emit("compiler", {
|
132
|
+
action,
|
133
|
+
status,
|
134
|
+
logs,
|
135
|
+
allowed: this.allowedActions,
|
136
|
+
inputs,
|
137
|
+
report,
|
138
|
+
data,
|
139
|
+
});
|
140
|
+
},
|
141
|
+
ready: function (message) {
|
142
|
+
this.log("ready", [message]);
|
143
|
+
},
|
144
|
+
success: function (type, stdout) {
|
145
|
+
const types = ["compiler", "testing"];
|
146
|
+
if (!types.includes(type))
|
147
|
+
this.fatal(`Invalid socket success type "${type}" on socket`);
|
148
|
+
else if (stdout === "")
|
149
|
+
this.log((type + "-success"), [
|
150
|
+
"No stdout to display on the console",
|
151
|
+
]);
|
152
|
+
else
|
153
|
+
this.log((type + "-success"), [stdout]);
|
154
|
+
},
|
155
|
+
error: function (type, stdout) {
|
156
|
+
var _a;
|
157
|
+
if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.editor.hideTerminal)) {
|
158
|
+
fileQueue_1.default.dispatcher().enqueue(fileQueue_1.default.events.OPEN_TERMINAL, "");
|
159
|
+
}
|
160
|
+
this.log(type, [stdout]);
|
161
|
+
if (this.isTestingEnvironment) {
|
162
|
+
this.onTestingFinished({
|
163
|
+
result: "failed",
|
164
|
+
});
|
165
|
+
}
|
166
|
+
},
|
167
|
+
complete: function () {
|
168
|
+
console.log("complete");
|
169
|
+
},
|
170
|
+
dialog: function (message, format = "md") {
|
171
|
+
if (!this.socket) {
|
172
|
+
this.fatal("Socket is not initialized");
|
173
|
+
return;
|
174
|
+
}
|
175
|
+
this.emit("dialog", "talk", [], undefined, undefined, { message, format });
|
176
|
+
},
|
177
|
+
fatal: function (msg) {
|
178
|
+
this.log("internal-error", [msg]);
|
179
|
+
throw msg;
|
180
|
+
},
|
181
|
+
onTestingFinished: function (result) {
|
182
|
+
var _a;
|
183
|
+
if ((_a = this.config) === null || _a === void 0 ? void 0 : _a.testingFinishedCallback) {
|
184
|
+
this.config.testingFinishedCallback(result);
|
185
|
+
}
|
186
|
+
},
|
187
|
+
};
|
188
|
+
exports.default = SocketManager;
|