@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/commands/start.js
CHANGED
|
@@ -1,208 +1,239 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
// import path from "path";
|
|
5
|
+
const command_1 = require("@oclif/command");
|
|
6
|
+
const SessionCommand_1 = require("../utils/SessionCommand");
|
|
7
|
+
const console_1 = require("../utils/console");
|
|
8
|
+
const socket_1 = require("../managers/socket");
|
|
9
|
+
const telemetry_1 = require("../managers/telemetry");
|
|
10
|
+
const server_1 = require("../managers/server");
|
|
11
|
+
const fileQueue_1 = require("../utils/fileQueue");
|
|
12
|
+
const file_1 = require("../managers/file");
|
|
13
|
+
const misc_1 = require("../utils/misc");
|
|
14
|
+
const osOperations_1 = require("../utils/osOperations");
|
|
15
|
+
const cli_ux_1 = require("cli-ux");
|
|
16
|
+
const checkNotInstalled_1 = require("../utils/checkNotInstalled");
|
|
17
|
+
class StartCommand extends SessionCommand_1.default {
|
|
18
|
+
// 🛑 IMPORTANT
|
|
19
|
+
// Every command that will use the configManager needs this init method
|
|
20
|
+
async init() {
|
|
21
|
+
const { flags } = this.parse(StartCommand);
|
|
22
|
+
await this.initSession(flags);
|
|
23
|
+
}
|
|
24
|
+
async run() {
|
|
25
|
+
var e_1, _a;
|
|
26
|
+
var _b, _c, _d, _e, _f, _g;
|
|
27
|
+
// get configuration object
|
|
28
|
+
const configObject = (_b = this.configManager) === null || _b === void 0 ? void 0 : _b.get();
|
|
29
|
+
// TODO: console.log(this.config.platform); get the platfrom from Oclif
|
|
30
|
+
const installedPlugins = this.config.plugins.map(plugin => {
|
|
31
|
+
return `${plugin.pjson.name}`;
|
|
32
|
+
});
|
|
33
|
+
const neededToInstallPlugins = checkNotInstalled_1.checkNotInstalledPlugins((configObject === null || configObject === void 0 ? void 0 : configObject.exercises) || [], installedPlugins);
|
|
34
|
+
if (neededToInstallPlugins.length > 0) {
|
|
35
|
+
console_1.default.error("These plugins are not installed but required: ", neededToInstallPlugins);
|
|
36
|
+
const confirmInstall = await cli_ux_1.cli.confirm("Do you want to install the needed plugins? (y/n)");
|
|
37
|
+
if (confirmInstall) {
|
|
38
|
+
console_1.default.info("Installing the needed plugins...");
|
|
39
|
+
try {
|
|
40
|
+
for (var neededToInstallPlugins_1 = tslib_1.__asyncValues(neededToInstallPlugins), neededToInstallPlugins_1_1; neededToInstallPlugins_1_1 = await neededToInstallPlugins_1.next(), !neededToInstallPlugins_1_1.done;) {
|
|
41
|
+
const p = neededToInstallPlugins_1_1.value;
|
|
42
|
+
await this.config.runCommand(`plugins:install`, [p]);
|
|
43
|
+
console_1.default.log(`Plugin ${p} installed`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
47
|
+
finally {
|
|
48
|
+
try {
|
|
49
|
+
if (neededToInstallPlugins_1_1 && !neededToInstallPlugins_1_1.done && (_a = neededToInstallPlugins_1.return)) await _a.call(neededToInstallPlugins_1);
|
|
50
|
+
}
|
|
51
|
+
finally { if (e_1) throw e_1.error; }
|
|
52
|
+
}
|
|
53
|
+
console_1.default.log("All needed plugins installed, please restart LearnPack to load them.");
|
|
54
|
+
console_1.default.info("Run: $ learnpack start");
|
|
55
|
+
this.exit(0);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
console_1.default.error("You need to install the plugins to complete this exercise");
|
|
59
|
+
console_1.default.info("To install the plugins run each of the following commands: ");
|
|
60
|
+
for (const p of neededToInstallPlugins) {
|
|
61
|
+
console_1.default.log(`learnpack plugins:install ${p}`);
|
|
62
|
+
}
|
|
63
|
+
this.exit(1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (configObject) {
|
|
67
|
+
const { config } = configObject;
|
|
68
|
+
// build exerises
|
|
69
|
+
(_c = this.configManager) === null || _c === void 0 ? void 0 : _c.buildIndex();
|
|
70
|
+
console_1.default.debug(`Grading: ${config === null || config === void 0 ? void 0 : config.grading} ${((_d = config === null || config === void 0 ? void 0 : config.disabledActions) === null || _d === void 0 ? void 0 : _d.includes("test")) ? "(disabled)" : ""}, editor: ${config === null || config === void 0 ? void 0 : config.editor.mode} ${config === null || config === void 0 ? void 0 : config.editor.version}, for ${Array.isArray(configObject === null || configObject === void 0 ? void 0 : configObject.exercises) ? configObject === null || configObject === void 0 ? void 0 : configObject.exercises.length :
|
|
71
|
+
0} exercises found`);
|
|
72
|
+
const appAlreadyExists = file_1.checkIfDirectoryExists(`${config === null || config === void 0 ? void 0 : config.dirPath}/_app`);
|
|
73
|
+
if (!appAlreadyExists) {
|
|
74
|
+
// download app and decompress
|
|
75
|
+
await file_1.downloadEditor(config === null || config === void 0 ? void 0 : config.editor.version, `${config === null || config === void 0 ? void 0 : config.dirPath}/app.tar.gz`);
|
|
76
|
+
console_1.default.info("Decompressing LearnPack UI, this may take a minute...");
|
|
77
|
+
await file_1.decompress(`${config === null || config === void 0 ? void 0 : config.dirPath}/app.tar.gz`, `${config === null || config === void 0 ? void 0 : config.dirPath}/_app/`);
|
|
78
|
+
}
|
|
79
|
+
// listen to socket commands
|
|
80
|
+
if (config && this.configManager) {
|
|
81
|
+
const server = await server_1.default(configObject, this.configManager, process.env.NODE_ENV === "test");
|
|
82
|
+
server.setMaxListeners(25);
|
|
83
|
+
// I should call a method to get the EventListener
|
|
84
|
+
const dispatcher = fileQueue_1.default.dispatcher({
|
|
85
|
+
create: true,
|
|
86
|
+
path: `${config.dirPath}/vscode_queue.json`,
|
|
87
|
+
});
|
|
88
|
+
if (configObject.exercises) {
|
|
89
|
+
const agent = ((_e = configObject.config) === null || _e === void 0 ? void 0 : _e.editor.agent) || "";
|
|
90
|
+
const path = ((_f = configObject.config) === null || _f === void 0 ? void 0 : _f.dirPath) || "";
|
|
91
|
+
const tutorialSlug = ((_g = configObject.config) === null || _g === void 0 ? void 0 : _g.slug) || "";
|
|
92
|
+
const steps = configObject.exercises.map((e, index) => ({
|
|
93
|
+
slug: e.slug,
|
|
94
|
+
position: e.position || index,
|
|
95
|
+
files: e.files,
|
|
96
|
+
ai_interactions: [],
|
|
97
|
+
compilations: [],
|
|
98
|
+
tests: [],
|
|
99
|
+
is_testeable: e.graded || false,
|
|
100
|
+
}));
|
|
101
|
+
if (path && steps.length > 0) {
|
|
102
|
+
telemetry_1.default.start(agent, steps, path, tutorialSlug);
|
|
103
|
+
}
|
|
104
|
+
if (config.telemetry) {
|
|
105
|
+
telemetry_1.default.urls = config.telemetry;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
socket_1.default.start(config, server, false);
|
|
109
|
+
socket_1.default.on("open", (data) => {
|
|
110
|
+
console_1.default.debug("Opening these files: ", data);
|
|
111
|
+
const files = misc_1.prioritizeHTMLFile(data.files);
|
|
112
|
+
if (config.editor.agent === "os") {
|
|
113
|
+
osOperations_1.eventManager.enqueue(dispatcher.events.OPEN_FILES, files);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
dispatcher.enqueue(dispatcher.events.OPEN_FILES, files);
|
|
117
|
+
}
|
|
118
|
+
socket_1.default.ready("Ready to compile...");
|
|
119
|
+
});
|
|
120
|
+
socket_1.default.on("open_window", (data) => {
|
|
121
|
+
console_1.default.debug("Opening window: ", data);
|
|
122
|
+
cli_ux_1.cli.open(data.url);
|
|
123
|
+
socket_1.default.log("open_window", `URL ${data.url} opened in the browser`);
|
|
124
|
+
});
|
|
125
|
+
socket_1.default.on("reset", (exercise) => {
|
|
126
|
+
var _a;
|
|
127
|
+
try {
|
|
128
|
+
(_a = this.configManager) === null || _a === void 0 ? void 0 : _a.reset(exercise.exerciseSlug);
|
|
129
|
+
socket_1.default.ready("Ready to compile...");
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
socket_1.default.error("compiler-error", error.message ||
|
|
133
|
+
"There was an error reseting the exercise");
|
|
134
|
+
setTimeout(() => socket_1.default.ready("Ready to compile..."), 2000);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
socket_1.default.on("build", async (data) => {
|
|
138
|
+
var _a;
|
|
139
|
+
const exercise = (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.getExercise(data.exerciseSlug);
|
|
140
|
+
if (!(exercise === null || exercise === void 0 ? void 0 : exercise.language)) {
|
|
141
|
+
socket_1.default.error("compiler-error", "Impossible to detect language to build for " +
|
|
142
|
+
data.exerciseSlug +
|
|
143
|
+
"...");
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
socket_1.default.log("compiling", "Building exercise " +
|
|
147
|
+
data.exerciseSlug +
|
|
148
|
+
" with " +
|
|
149
|
+
exercise.language +
|
|
150
|
+
"...");
|
|
151
|
+
await this.config.runHook("action", {
|
|
152
|
+
action: "compile",
|
|
153
|
+
socket: socket_1.default,
|
|
154
|
+
configuration: config,
|
|
155
|
+
exercise,
|
|
156
|
+
telemetry: telemetry_1.default,
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
socket_1.default.on("ai_interaction", (data) => {
|
|
160
|
+
const { stepPosition, event, eventData } = data;
|
|
161
|
+
telemetry_1.default.registerStepEvent(stepPosition, event, eventData);
|
|
162
|
+
});
|
|
163
|
+
socket_1.default.on("test", async (data) => {
|
|
164
|
+
var _a, _b;
|
|
165
|
+
const exercise = (_a = this.configManager) === null || _a === void 0 ? void 0 : _a.getExercise(data.exerciseSlug);
|
|
166
|
+
if (!(exercise === null || exercise === void 0 ? void 0 : exercise.language)) {
|
|
167
|
+
socket_1.default.error("compiler-error", "Impossible to detect engine language for testing for " +
|
|
168
|
+
data.exerciseSlug +
|
|
169
|
+
"...");
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if ((config === null || config === void 0 ? void 0 : config.disabledActions.includes("test")) || (config === null || config === void 0 ? void 0 : config.disableGrading)) {
|
|
173
|
+
socket_1.default.ready("Grading is disabled on configuration");
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
socket_1.default.log("testing", "Testing your exercise using the " + exercise.language + " engine.");
|
|
177
|
+
await this.config.runHook("action", {
|
|
178
|
+
action: "test",
|
|
179
|
+
socket: socket_1.default,
|
|
180
|
+
configuration: config,
|
|
181
|
+
exercise,
|
|
182
|
+
telemetry: telemetry_1.default,
|
|
183
|
+
});
|
|
184
|
+
(_b = this.configManager) === null || _b === void 0 ? void 0 : _b.save();
|
|
185
|
+
return true;
|
|
186
|
+
});
|
|
187
|
+
const terminate = async () => {
|
|
188
|
+
var _a;
|
|
189
|
+
console_1.default.error("Terminating Learnpack...");
|
|
190
|
+
await telemetry_1.default.submit();
|
|
191
|
+
(_a = this.configManager) === null || _a === void 0 ? void 0 : _a.noCurrentExercise();
|
|
192
|
+
dispatcher.enqueue(dispatcher.events.END);
|
|
193
|
+
process.exit();
|
|
194
|
+
};
|
|
195
|
+
server.on("close", terminate);
|
|
196
|
+
process.on("SIGINT", terminate);
|
|
197
|
+
process.on("SIGTERM", terminate);
|
|
198
|
+
process.on("SIGHUP", terminate);
|
|
199
|
+
// finish the server startup
|
|
200
|
+
setTimeout(() => dispatcher.enqueue(dispatcher.events.RUNNING), 1000);
|
|
201
|
+
// start watching for file changes
|
|
202
|
+
if (StartCommand.flags.watch)
|
|
203
|
+
this.configManager.watchIndex(_filename => {
|
|
204
|
+
// Instead of reloading with socket.reload(), I just notify the frontend for the file change
|
|
205
|
+
socket_1.default.emit("file_change", "ready", _filename);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.default = StartCommand;
|
|
212
|
+
StartCommand.description = "Runs a small server with all the exercise instructions";
|
|
213
|
+
StartCommand.flags = Object.assign(Object.assign({}, SessionCommand_1.default.flags), { port: command_1.flags.string({ char: "p", description: "server port" }), host: command_1.flags.string({ char: "h", description: "server host" }), disableGrading: command_1.flags.boolean({
|
|
214
|
+
char: "D",
|
|
215
|
+
description: "disble grading functionality",
|
|
216
|
+
default: false,
|
|
217
|
+
}),
|
|
218
|
+
// disableGrading: flags.boolean({char: 'dg', description: 'disble grading functionality', default: false }),
|
|
219
|
+
watch: command_1.flags.boolean({
|
|
220
|
+
char: "w",
|
|
221
|
+
description: "Watch for file changes",
|
|
222
|
+
default: false,
|
|
223
|
+
}), editor: command_1.flags.string({
|
|
224
|
+
char: "e",
|
|
225
|
+
description: "[preview, extension]",
|
|
226
|
+
options: ["extension", "preview"],
|
|
227
|
+
}), version: command_1.flags.string({
|
|
228
|
+
char: "v",
|
|
229
|
+
description: "E.g: 1.0.1",
|
|
230
|
+
default: undefined,
|
|
231
|
+
}), grading: command_1.flags.string({
|
|
232
|
+
char: "g",
|
|
233
|
+
description: "[isolated, incremental]",
|
|
234
|
+
options: ["isolated", "incremental"],
|
|
235
|
+
}), debug: command_1.flags.boolean({
|
|
236
|
+
char: "d",
|
|
237
|
+
description: "debugger mode for more verbage",
|
|
238
|
+
default: false,
|
|
239
|
+
}) });
|
package/lib/commands/test.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import SessionCommand from "../utils/SessionCommand";
|
|
2
|
-
declare class TestCommand extends SessionCommand {
|
|
3
|
-
init(): Promise<void>;
|
|
4
|
-
run(): Promise<void>;
|
|
5
|
-
}
|
|
6
|
-
export default TestCommand;
|
|
1
|
+
import SessionCommand from "../utils/SessionCommand";
|
|
2
|
+
declare class TestCommand extends SessionCommand {
|
|
3
|
+
init(): Promise<void>;
|
|
4
|
+
run(): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export default TestCommand;
|
package/lib/commands/test.js
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const console_1 = require("../utils/console");
|
|
4
|
-
const SessionCommand_1 = require("../utils/SessionCommand");
|
|
5
|
-
const socket_1 = require("../managers/socket");
|
|
6
|
-
const server_1 = require("../managers/server");
|
|
7
|
-
const exercisesQueue_1 = require("../utils/exercisesQueue");
|
|
8
|
-
class TestCommand extends SessionCommand_1.default {
|
|
9
|
-
async init() {
|
|
10
|
-
const { flags } = this.parse(TestCommand);
|
|
11
|
-
await this.initSession(flags);
|
|
12
|
-
}
|
|
13
|
-
async run() {
|
|
14
|
-
var _a, _b, _c;
|
|
15
|
-
const { args: { exerciseSlug }, } = this.parse(TestCommand);
|
|
16
|
-
// Build exercises index
|
|
17
|
-
(_a = this.configManager) === null || _a === void 0 ? void 0 : _a.buildIndex();
|
|
18
|
-
let exercises = [];
|
|
19
|
-
// test all exercises
|
|
20
|
-
!exerciseSlug ?
|
|
21
|
-
(exercises = (_b = this.configManager) === null || _b === void 0 ? void 0 : _b.getAllExercises()) :
|
|
22
|
-
(exercises = [this.configManager.getExercise(exerciseSlug)]);
|
|
23
|
-
const exercisesQueue = new exercisesQueue_1.default(exercises);
|
|
24
|
-
const configObject = (_c = this.configManager) === null || _c === void 0 ? void 0 : _c.get();
|
|
25
|
-
let hasFailed = false;
|
|
26
|
-
let failedTestsCount = 0;
|
|
27
|
-
let successTestsCount = 0;
|
|
28
|
-
const testsToRunCount = exercisesQueue.size();
|
|
29
|
-
configObject.config.testingFinishedCallback = ({ result }) => {
|
|
30
|
-
if (result === "failed") {
|
|
31
|
-
hasFailed = true;
|
|
32
|
-
failedTestsCount++;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
successTestsCount++;
|
|
36
|
-
}
|
|
37
|
-
if (exercisesQueue.isEmpty()) {
|
|
38
|
-
console_1.default.info(`${testsToRunCount} test${testsToRunCount > 1 ? "s" : ""} runned`);
|
|
39
|
-
console_1.default.success(`${successTestsCount} test${successTestsCount > 1 ? "s" : ""} passed`);
|
|
40
|
-
console_1.default.error(`${failedTestsCount} test${failedTestsCount > 1 ? "s" : ""} failed`);
|
|
41
|
-
process.exit(hasFailed ? 1 : 0);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
exercisesQueue.pop().test(this.config, config, socket_1.default);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const config = configObject === null || configObject === void 0 ? void 0 : configObject.config;
|
|
48
|
-
const server = await server_1.default(configObject, this.configManager, true);
|
|
49
|
-
socket_1.default.start(config, server, true);
|
|
50
|
-
exercisesQueue.pop().test(this.config, config, socket_1.default);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
TestCommand.description = `Test exercises`;
|
|
54
|
-
TestCommand.args = [
|
|
55
|
-
{
|
|
56
|
-
name: "exerciseSlug",
|
|
57
|
-
required: false,
|
|
58
|
-
description: "The name of the exercise to test",
|
|
59
|
-
hidden: false,
|
|
60
|
-
},
|
|
61
|
-
];
|
|
62
|
-
exports.default = TestCommand;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const console_1 = require("../utils/console");
|
|
4
|
+
const SessionCommand_1 = require("../utils/SessionCommand");
|
|
5
|
+
const socket_1 = require("../managers/socket");
|
|
6
|
+
const server_1 = require("../managers/server");
|
|
7
|
+
const exercisesQueue_1 = require("../utils/exercisesQueue");
|
|
8
|
+
class TestCommand extends SessionCommand_1.default {
|
|
9
|
+
async init() {
|
|
10
|
+
const { flags } = this.parse(TestCommand);
|
|
11
|
+
await this.initSession(flags);
|
|
12
|
+
}
|
|
13
|
+
async run() {
|
|
14
|
+
var _a, _b, _c;
|
|
15
|
+
const { args: { exerciseSlug }, } = this.parse(TestCommand);
|
|
16
|
+
// Build exercises index
|
|
17
|
+
(_a = this.configManager) === null || _a === void 0 ? void 0 : _a.buildIndex();
|
|
18
|
+
let exercises = [];
|
|
19
|
+
// test all exercises
|
|
20
|
+
!exerciseSlug ?
|
|
21
|
+
(exercises = (_b = this.configManager) === null || _b === void 0 ? void 0 : _b.getAllExercises()) :
|
|
22
|
+
(exercises = [this.configManager.getExercise(exerciseSlug)]);
|
|
23
|
+
const exercisesQueue = new exercisesQueue_1.default(exercises);
|
|
24
|
+
const configObject = (_c = this.configManager) === null || _c === void 0 ? void 0 : _c.get();
|
|
25
|
+
let hasFailed = false;
|
|
26
|
+
let failedTestsCount = 0;
|
|
27
|
+
let successTestsCount = 0;
|
|
28
|
+
const testsToRunCount = exercisesQueue.size();
|
|
29
|
+
configObject.config.testingFinishedCallback = ({ result }) => {
|
|
30
|
+
if (result === "failed") {
|
|
31
|
+
hasFailed = true;
|
|
32
|
+
failedTestsCount++;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
successTestsCount++;
|
|
36
|
+
}
|
|
37
|
+
if (exercisesQueue.isEmpty()) {
|
|
38
|
+
console_1.default.info(`${testsToRunCount} test${testsToRunCount > 1 ? "s" : ""} runned`);
|
|
39
|
+
console_1.default.success(`${successTestsCount} test${successTestsCount > 1 ? "s" : ""} passed`);
|
|
40
|
+
console_1.default.error(`${failedTestsCount} test${failedTestsCount > 1 ? "s" : ""} failed`);
|
|
41
|
+
process.exit(hasFailed ? 1 : 0);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
exercisesQueue.pop().test(this.config, config, socket_1.default);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const config = configObject === null || configObject === void 0 ? void 0 : configObject.config;
|
|
48
|
+
const server = await server_1.default(configObject, this.configManager, true);
|
|
49
|
+
socket_1.default.start(config, server, true);
|
|
50
|
+
exercisesQueue.pop().test(this.config, config, socket_1.default);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
TestCommand.description = `Test exercises`;
|
|
54
|
+
TestCommand.args = [
|
|
55
|
+
{
|
|
56
|
+
name: "exerciseSlug",
|
|
57
|
+
required: false,
|
|
58
|
+
description: "The name of the exercise to test",
|
|
59
|
+
hidden: false,
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
exports.default = TestCommand;
|
package/lib/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '@oclif/command';
|
|
1
|
+
export * from '@oclif/command';
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("@oclif/command"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("@oclif/command"), exports);
|