@learnpack/learnpack 4.0.9 → 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 +11 -1
- package/src/managers/session.ts +1 -1
@@ -1,58 +1,58 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.TEST_SERVER = void 0;
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
const
|
8
|
-
const
|
9
|
-
const
|
10
|
-
|
11
|
-
|
12
|
-
const
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
//
|
24
|
-
// res.header("Access-Control-Allow-
|
25
|
-
// res.header("Access-Control-Allow-
|
26
|
-
//
|
27
|
-
//
|
28
|
-
//
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
console_1.default.success(
|
34
|
-
console_1.default.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TEST_SERVER = void 0;
|
4
|
+
exports.default = default_1;
|
5
|
+
const express = require("express");
|
6
|
+
// eslint-disable-next-line
|
7
|
+
const cors = require("cors");
|
8
|
+
const console_1 = require("../../utils/console");
|
9
|
+
const routes_1 = require("./routes");
|
10
|
+
const cli_ux_1 = require("cli-ux");
|
11
|
+
async function default_1(configObj, configManager, isTestingEnvironment = false) {
|
12
|
+
const { config } = configObj;
|
13
|
+
const app = express();
|
14
|
+
let server;
|
15
|
+
if (isTestingEnvironment) {
|
16
|
+
if (exports.TEST_SERVER === undefined)
|
17
|
+
exports.TEST_SERVER = require("http").Server(app);
|
18
|
+
server = exports.TEST_SERVER;
|
19
|
+
}
|
20
|
+
else
|
21
|
+
server = require("http").Server(app);
|
22
|
+
app.use(cors());
|
23
|
+
// app.use(function(req, res, next) {
|
24
|
+
// res.header("Access-Control-Allow-Origin", "*")
|
25
|
+
// res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
|
26
|
+
// res.header("Access-Control-Allow-Methods", "GET,PUT")
|
27
|
+
// next()
|
28
|
+
// })
|
29
|
+
// add all needed endpoints
|
30
|
+
await (0, routes_1.default)(app, configObj, configManager);
|
31
|
+
server.listen(isTestingEnvironment ? 5000 : config === null || config === void 0 ? void 0 : config.port, function () {
|
32
|
+
if (!isTestingEnvironment) {
|
33
|
+
console_1.default.success(`Exercises are running 😃 Open your browser to start practicing!`);
|
34
|
+
console_1.default.success(`\n Open the exercise on this link:`);
|
35
|
+
console_1.default.log(` ${config === null || config === void 0 ? void 0 : config.publicUrl}`);
|
36
|
+
if ((config === null || config === void 0 ? void 0 : config.editor.mode) === "preview")
|
37
|
+
cli_ux_1.default.open(`${config.publicUrl}`);
|
38
|
+
}
|
39
|
+
});
|
40
|
+
const sockets = new Set();
|
41
|
+
server.on("connection", (socket) => {
|
42
|
+
sockets.add(socket);
|
43
|
+
server.once("close", () => {
|
44
|
+
sockets.delete(socket);
|
45
|
+
});
|
46
|
+
});
|
47
|
+
/**
|
48
|
+
* Forcefully terminates HTTP server.
|
49
|
+
*/
|
50
|
+
server.terminate = (callback) => {
|
51
|
+
for (const socket of sockets) {
|
52
|
+
socket.destroy();
|
53
|
+
sockets.delete(socket);
|
54
|
+
}
|
55
|
+
server.close(callback);
|
56
|
+
};
|
57
|
+
return server;
|
58
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import * as express from "express";
|
2
|
-
import { IConfigObj } from "../../models/config";
|
3
|
-
import { IConfigManager } from "../../models/config-manager";
|
4
|
-
export default function (app: express.Application, configObject: IConfigObj, configManager: IConfigManager): Promise<void>;
|
1
|
+
import * as express from "express";
|
2
|
+
import { IConfigObj } from "../../models/config";
|
3
|
+
import { IConfigManager } from "../../models/config-manager";
|
4
|
+
export default function (app: express.Application, configObject: IConfigObj, configManager: IConfigManager): Promise<void>;
|
@@ -1,220 +1,228 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
|
4
|
-
const
|
5
|
-
const
|
6
|
-
const
|
7
|
-
const
|
8
|
-
const
|
9
|
-
|
10
|
-
|
11
|
-
const
|
12
|
-
const
|
13
|
-
const
|
14
|
-
const
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
res.
|
29
|
-
|
30
|
-
}
|
31
|
-
|
32
|
-
|
33
|
-
const
|
34
|
-
const
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
const
|
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
|
-
|
122
|
-
|
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
|
-
|
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
|
-
if (!exercise.
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
}
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
app.
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.default = default_1;
|
4
|
+
const console_1 = require("../../utils/console");
|
5
|
+
const express = require("express");
|
6
|
+
const fs = require("fs");
|
7
|
+
const bodyParser = require("body-parser");
|
8
|
+
const socket_1 = require("../socket");
|
9
|
+
const fileQueue_1 = require("../../utils/fileQueue");
|
10
|
+
// import gitpod from '../gitpod'
|
11
|
+
const exercise_1 = require("../config/exercise");
|
12
|
+
const session_1 = require("../../managers/session");
|
13
|
+
const telemetry_1 = require("../telemetry");
|
14
|
+
const osOperations_1 = require("../../utils/osOperations");
|
15
|
+
const withHandler = (func) => (req, res) => {
|
16
|
+
try {
|
17
|
+
func(req, res);
|
18
|
+
}
|
19
|
+
catch (error) {
|
20
|
+
console_1.default.debug(error);
|
21
|
+
const _err = {
|
22
|
+
message: error.message || "There has been an error",
|
23
|
+
status: error.status || 500,
|
24
|
+
type: error.type || null,
|
25
|
+
};
|
26
|
+
console_1.default.error(_err.message);
|
27
|
+
// send rep to the server
|
28
|
+
res.status(_err.status);
|
29
|
+
res.json(_err);
|
30
|
+
}
|
31
|
+
};
|
32
|
+
async function default_1(app, configObject, configManager) {
|
33
|
+
const { config, exercises } = configObject;
|
34
|
+
const session = await session_1.default.get(configManager === null || configManager === void 0 ? void 0 : configManager.get());
|
35
|
+
const dispatcher = fileQueue_1.default.dispatcher({
|
36
|
+
create: true,
|
37
|
+
path: `${config === null || config === void 0 ? void 0 : config.dirPath}/vscode_queue.json`,
|
38
|
+
});
|
39
|
+
app.get("/config", withHandler((_, res) => {
|
40
|
+
const confObject = configManager.get();
|
41
|
+
res.json(confObject);
|
42
|
+
}));
|
43
|
+
// Added this line to parse the json body
|
44
|
+
const jsonBodyParser = bodyParser.json();
|
45
|
+
// Trying to log in from frontend
|
46
|
+
app.post("/login", jsonBodyParser, withHandler(async (req, res) => {
|
47
|
+
const email = req.body.email;
|
48
|
+
const password = req.body.password;
|
49
|
+
session_1.default.destroy();
|
50
|
+
const payload = await session_1.default.loginWeb(email, password);
|
51
|
+
res.json(payload);
|
52
|
+
}));
|
53
|
+
app.post("/logout", jsonBodyParser, withHandler(async (req, res) => {
|
54
|
+
session_1.default.destroy();
|
55
|
+
res.json({ message: "You've logged out from Breathecode and Rigobot" });
|
56
|
+
}));
|
57
|
+
app.post("/set-rigobot-token", jsonBodyParser, withHandler(async (req, res) => {
|
58
|
+
const token = req.body.token;
|
59
|
+
// Ensure token is provided in the request body
|
60
|
+
if (!token) {
|
61
|
+
return res.status(400).json({ error: "Token is required" });
|
62
|
+
}
|
63
|
+
try {
|
64
|
+
const tokenSaved = await session_1.default.setRigoToken(token);
|
65
|
+
// Check if the token was saved successfully
|
66
|
+
if (tokenSaved) {
|
67
|
+
res.json({ status: "ok" });
|
68
|
+
}
|
69
|
+
else {
|
70
|
+
res.status(500).json({ error: "Failed to save the token" });
|
71
|
+
}
|
72
|
+
}
|
73
|
+
catch (_a) {
|
74
|
+
// Handle any unexpected errors during the process
|
75
|
+
res.status(500).json({ error: "Internal server error" });
|
76
|
+
}
|
77
|
+
}));
|
78
|
+
app.get("/check/rigo/status", withHandler(async (_, res) => {
|
79
|
+
const payload = await session_1.default.getPayload();
|
80
|
+
if (payload && payload.rigobot && payload.rigobot.key) {
|
81
|
+
res.json({ rigoToken: payload.rigobot.key, payload: payload });
|
82
|
+
}
|
83
|
+
else {
|
84
|
+
res
|
85
|
+
.status(400)
|
86
|
+
.json({ details: `Rigobot token not found, please log in first!` });
|
87
|
+
}
|
88
|
+
}));
|
89
|
+
// symbolic link to maintain path compatiblity
|
90
|
+
const fetchStaticAsset = withHandler((req, res) => {
|
91
|
+
const filePath = `${config === null || config === void 0 ? void 0 : config.dirPath}/assets/${req.params.filePath}`;
|
92
|
+
if (!fs.existsSync(filePath))
|
93
|
+
throw new Error("File not found: " + filePath);
|
94
|
+
const content = fs.readFileSync(filePath);
|
95
|
+
res.write(content);
|
96
|
+
res.end();
|
97
|
+
});
|
98
|
+
app.get(`${(config === null || config === void 0 ? void 0 : config.dirPath.indexOf("./")) === 0 ?
|
99
|
+
config.dirPath.slice(1) :
|
100
|
+
config === null || config === void 0 ? void 0 : config.dirPath}/assets/:filePath`, fetchStaticAsset);
|
101
|
+
app.get("/assets/:filePath", fetchStaticAsset);
|
102
|
+
app.get("/exercise", withHandler((_, res) => {
|
103
|
+
res.json(exercises);
|
104
|
+
}));
|
105
|
+
app.get("/exercise/:slug/readme", withHandler(({ params: { slug }, query: { lang } }, res) => {
|
106
|
+
const exercise = configManager.getExercise(slug);
|
107
|
+
if (exercise && exercise.getReadme) {
|
108
|
+
const readme = exercise.getReadme(lang || null);
|
109
|
+
res.json(readme);
|
110
|
+
}
|
111
|
+
else {
|
112
|
+
res.status(400);
|
113
|
+
}
|
114
|
+
}));
|
115
|
+
app.get("/exercise/:slug/report", withHandler(({ params: { slug } }, res) => {
|
116
|
+
const exercise = configManager.getExercise(slug);
|
117
|
+
if (exercise && exercise.getTestReport) {
|
118
|
+
const report = exercise.getTestReport();
|
119
|
+
res.json(JSON.stringify(report));
|
120
|
+
}
|
121
|
+
}));
|
122
|
+
app.get("/exercise/:slug", withHandler((req, res) => {
|
123
|
+
var _a, _b, _c, _d, _e;
|
124
|
+
// no need to re-start exercise if it's already started
|
125
|
+
if (configObject.currentExercise &&
|
126
|
+
req.params.slug === configObject.currentExercise) {
|
127
|
+
const exercise = configManager.getExercise(req.params.slug);
|
128
|
+
res.json(exercise);
|
129
|
+
if (exercise.position) {
|
130
|
+
telemetry_1.default.registerStepEvent(exercise.position, "open_step", {});
|
131
|
+
}
|
132
|
+
return;
|
133
|
+
}
|
134
|
+
const exercise = configManager.startExercise(req.params.slug);
|
135
|
+
if (exercise.position) {
|
136
|
+
telemetry_1.default.registerStepEvent(exercise.position, "open_step", {});
|
137
|
+
}
|
138
|
+
if (((_a = configObject.config) === null || _a === void 0 ? void 0 : _a.editor.agent) === "os") {
|
139
|
+
osOperations_1.eventManager.enqueue(dispatcher.events.START_EXERCISE, exercise);
|
140
|
+
}
|
141
|
+
else {
|
142
|
+
dispatcher.enqueue(dispatcher.events.START_EXERCISE, req.params.slug);
|
143
|
+
}
|
144
|
+
const entries = new Set(Object.keys(config === null || config === void 0 ? void 0 : config.entries).map(lang => config === null || config === void 0 ? void 0 : config.entries[lang]));
|
145
|
+
// if we are in incremental grading, the entry file can by dinamically detected
|
146
|
+
// based on the changes the student is making during the exercise
|
147
|
+
if ((config === null || config === void 0 ? void 0 : config.grading) === "incremental") {
|
148
|
+
const scanedFiles = fs.readdirSync("./");
|
149
|
+
// update the file hierarchy with updates
|
150
|
+
exercise.files = [
|
151
|
+
...exercise.files.filter(f => f.name.includes("test.")),
|
152
|
+
...(0, exercise_1.filterFiles)(scanedFiles),
|
153
|
+
];
|
154
|
+
console_1.default.debug(`Exercise updated files: `, exercise.files);
|
155
|
+
}
|
156
|
+
const detected = (0, exercise_1.detect)(configObject, exercise.files
|
157
|
+
.filter(fileName => entries.has(fileName.name))
|
158
|
+
.map(f => f.name || f));
|
159
|
+
// if a new language for the testing engine is detected, we replace it
|
160
|
+
// if not we leave it as it was before
|
161
|
+
if ((config === null || config === void 0 ? void 0 : config.language) && !["", "auto"].includes(config === null || config === void 0 ? void 0 : config.language)) {
|
162
|
+
console_1.default.debug(`Exercise language ignored, instead imported from configuration ${config === null || config === void 0 ? void 0 : config.language}`);
|
163
|
+
exercise.language = detected === null || detected === void 0 ? void 0 : detected.language;
|
164
|
+
}
|
165
|
+
else if ((detected === null || detected === void 0 ? void 0 : detected.language) &&
|
166
|
+
(!(config === null || config === void 0 ? void 0 : config.language) || (config === null || config === void 0 ? void 0 : config.language) === "auto")) {
|
167
|
+
console_1.default.debug(`Switching to ${detected.language} engine in this exercise`);
|
168
|
+
exercise.language = detected.language;
|
169
|
+
}
|
170
|
+
// WARNING: has to be the FULL PATH to the entry path
|
171
|
+
// We need to detect entry in both gradings: Incremental and Isolate
|
172
|
+
exercise.entry = detected === null || detected === void 0 ? void 0 : detected.entry;
|
173
|
+
console_1.default.debug(`Exercise detected entry: ${detected === null || detected === void 0 ? void 0 : detected.entry} and language ${exercise.language}`);
|
174
|
+
// exercises.graded and exercises.disableGrading deprecated.
|
175
|
+
if (!exercise.graded ||
|
176
|
+
(config === null || config === void 0 ? void 0 : config.disableGrading) ||
|
177
|
+
((_b = config === null || config === void 0 ? void 0 : config.disabledActions) === null || _b === void 0 ? void 0 : _b.includes("test"))) {
|
178
|
+
socket_1.default.removeAllowed("test");
|
179
|
+
}
|
180
|
+
else {
|
181
|
+
socket_1.default.addAllowed("test");
|
182
|
+
}
|
183
|
+
if (!exercise.entry || ((_c = config === null || config === void 0 ? void 0 : config.disabledActions) === null || _c === void 0 ? void 0 : _c.includes("build"))) {
|
184
|
+
socket_1.default.removeAllowed("build");
|
185
|
+
}
|
186
|
+
else {
|
187
|
+
socket_1.default.addAllowed("build");
|
188
|
+
}
|
189
|
+
if (exercise.files.filter((f) => !f.name.toLowerCase().includes("readme.") &&
|
190
|
+
!f.name.toLowerCase().includes("test.")).length === 0 ||
|
191
|
+
((_d = config === null || config === void 0 ? void 0 : config.disabledActions) === null || _d === void 0 ? void 0 : _d.includes("reset"))) {
|
192
|
+
socket_1.default.removeAllowed("reset");
|
193
|
+
}
|
194
|
+
else if (!((_e = config === null || config === void 0 ? void 0 : config.disabledActions) === null || _e === void 0 ? void 0 : _e.includes("reset"))) {
|
195
|
+
socket_1.default.addAllowed("reset");
|
196
|
+
}
|
197
|
+
socket_1.default.log("ready");
|
198
|
+
res.json(exercise);
|
199
|
+
}));
|
200
|
+
app.get("/exercise/:slug/file/:fileName", withHandler((req, res) => {
|
201
|
+
const exercise = configManager.getExercise(req.params.slug);
|
202
|
+
if (exercise && exercise.getFile) {
|
203
|
+
res.write(exercise.getFile(req.params.fileName));
|
204
|
+
res.end();
|
205
|
+
}
|
206
|
+
}));
|
207
|
+
/*
|
208
|
+
app.post(
|
209
|
+
"/exercise/:slug/file/:fileName",
|
210
|
+
withHandler((req: express.Request, res: express.Response) => {
|
211
|
+
get tokens but also, add allowed action for 'generate'
|
212
|
+
use the sessionManager to keep compatibility with the cli login command.
|
213
|
+
})
|
214
|
+
);
|
215
|
+
*/
|
216
|
+
const textBodyParser = bodyParser.text();
|
217
|
+
app.put("/exercise/:slug/file/:fileName", textBodyParser, withHandler((req, res) => {
|
218
|
+
const exercise = configManager.getExercise(req.params.slug);
|
219
|
+
if (exercise && exercise.saveFile) {
|
220
|
+
exercise.saveFile(req.params.fileName, req.body);
|
221
|
+
res.end();
|
222
|
+
}
|
223
|
+
}));
|
224
|
+
if (config === null || config === void 0 ? void 0 : config.outputPath) {
|
225
|
+
app.use("/preview", express.static(config.outputPath));
|
226
|
+
}
|
227
|
+
app.use("/", express.static(`${config === null || config === void 0 ? void 0 : config.dirPath}/_app`));
|
228
|
+
}
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import { ISession } from "../models/session";
|
2
|
-
declare const Session: ISession;
|
3
|
-
export default Session;
|
1
|
+
import { ISession } from "../models/session";
|
2
|
+
declare const Session: ISession;
|
3
|
+
export default Session;
|