@learnpack/learnpack 2.1.26 → 2.1.27
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 +10 -10
- package/oclif.manifest.json +1 -1
- package/package.json +2 -1
- package/src/commands/audit.ts +113 -113
- package/src/commands/clean.ts +10 -10
- package/src/commands/download.ts +18 -18
- package/src/commands/init.ts +39 -39
- package/src/commands/login.ts +13 -13
- package/src/commands/logout.ts +9 -9
- package/src/commands/publish.ts +25 -25
- package/src/commands/start.ts +101 -75
- package/src/commands/test.ts +34 -34
- package/src/managers/config/allowed_files.ts +2 -2
- package/src/managers/config/defaults.ts +2 -2
- package/src/managers/config/exercise.ts +79 -79
- package/src/managers/config/index.ts +145 -145
- package/src/managers/file.ts +74 -65
- package/src/managers/server/index.ts +32 -31
- package/src/managers/server/routes.ts +139 -90
- package/src/managers/session.ts +53 -24
- package/src/managers/socket.ts +92 -79
- package/src/models/action.ts +8 -1
- package/src/models/config-manager.ts +2 -2
- package/src/models/config.ts +7 -2
- package/src/models/exercise-obj.ts +6 -3
- package/src/models/plugin-config.ts +2 -2
- package/src/models/session.ts +5 -2
- package/src/models/socket.ts +12 -6
- package/src/models/status.ts +15 -14
- package/src/plugin/command/compile.ts +10 -10
- package/src/plugin/command/test.ts +14 -14
- package/src/plugin/index.ts +5 -5
- package/src/plugin/plugin.ts +26 -26
- package/src/plugin/utils.ts +23 -23
- package/src/utils/BaseCommand.ts +16 -16
- package/src/utils/api.ts +143 -91
- package/src/utils/audit.ts +93 -96
- package/src/utils/exercisesQueue.ts +15 -15
- package/src/utils/fileQueue.ts +85 -85
- package/src/utils/watcher.ts +14 -14
- package/lib/commands/audit.d.ts +0 -6
- package/lib/commands/audit.js +0 -342
- package/lib/commands/clean.d.ts +0 -8
- package/lib/commands/clean.js +0 -25
- package/lib/commands/download.d.ts +0 -13
- package/lib/commands/download.js +0 -55
- package/lib/commands/init.d.ts +0 -9
- package/lib/commands/init.js +0 -123
- package/lib/commands/login.d.ts +0 -14
- package/lib/commands/login.js +0 -37
- package/lib/commands/logout.d.ts +0 -14
- package/lib/commands/logout.js +0 -37
- package/lib/commands/publish.d.ts +0 -14
- package/lib/commands/publish.js +0 -82
- package/lib/commands/start.d.ts +0 -7
- package/lib/commands/start.js +0 -165
- package/lib/commands/test.d.ts +0 -6
- package/lib/commands/test.js +0 -62
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -4
- package/lib/managers/config/allowed_files.d.ts +0 -5
- package/lib/managers/config/allowed_files.js +0 -30
- package/lib/managers/config/defaults.d.ts +0 -39
- package/lib/managers/config/defaults.js +0 -40
- package/lib/managers/config/exercise.d.ts +0 -36
- package/lib/managers/config/exercise.js +0 -233
- package/lib/managers/config/index.d.ts +0 -3
- package/lib/managers/config/index.js +0 -320
- package/lib/managers/file.d.ts +0 -13
- package/lib/managers/file.js +0 -134
- package/lib/managers/gitpod.d.ts +0 -3
- package/lib/managers/gitpod.js +0 -67
- package/lib/managers/server/index.d.ts +0 -6
- package/lib/managers/server/index.js +0 -58
- package/lib/managers/server/routes.d.ts +0 -4
- package/lib/managers/server/routes.js +0 -167
- package/lib/managers/session.d.ts +0 -3
- package/lib/managers/session.js +0 -104
- package/lib/managers/socket.d.ts +0 -3
- package/lib/managers/socket.js +0 -164
- package/lib/managers/test.d.ts +0 -0
- package/lib/managers/test.js +0 -84
- package/lib/models/action.d.ts +0 -2
- package/lib/models/action.js +0 -2
- package/lib/models/audit.d.ts +0 -15
- package/lib/models/audit.js +0 -2
- package/lib/models/config-manager.d.ts +0 -21
- package/lib/models/config-manager.js +0 -2
- package/lib/models/config.d.ts +0 -62
- package/lib/models/config.js +0 -2
- package/lib/models/counter.d.ts +0 -11
- package/lib/models/counter.js +0 -2
- package/lib/models/errors.d.ts +0 -15
- package/lib/models/errors.js +0 -2
- package/lib/models/exercise-obj.d.ts +0 -27
- package/lib/models/exercise-obj.js +0 -2
- package/lib/models/file.d.ts +0 -5
- package/lib/models/file.js +0 -2
- package/lib/models/findings.d.ts +0 -17
- package/lib/models/findings.js +0 -2
- package/lib/models/flags.d.ts +0 -10
- package/lib/models/flags.js +0 -2
- package/lib/models/front-matter.d.ts +0 -11
- package/lib/models/front-matter.js +0 -2
- package/lib/models/gitpod-data.d.ts +0 -16
- package/lib/models/gitpod-data.js +0 -2
- package/lib/models/language.d.ts +0 -4
- package/lib/models/language.js +0 -2
- package/lib/models/package.d.ts +0 -7
- package/lib/models/package.js +0 -2
- package/lib/models/plugin-config.d.ts +0 -16
- package/lib/models/plugin-config.js +0 -2
- package/lib/models/session.d.ts +0 -23
- package/lib/models/session.js +0 -2
- package/lib/models/socket.d.ts +0 -31
- package/lib/models/socket.js +0 -2
- package/lib/models/status.d.ts +0 -1
- package/lib/models/status.js +0 -2
- package/lib/models/success-types.d.ts +0 -1
- package/lib/models/success-types.js +0 -2
- package/lib/plugin/command/compile.d.ts +0 -6
- package/lib/plugin/command/compile.js +0 -18
- package/lib/plugin/command/test.d.ts +0 -6
- package/lib/plugin/command/test.js +0 -25
- package/lib/plugin/index.d.ts +0 -27
- package/lib/plugin/index.js +0 -7
- package/lib/plugin/plugin.d.ts +0 -8
- package/lib/plugin/plugin.js +0 -68
- package/lib/plugin/utils.d.ts +0 -16
- package/lib/plugin/utils.js +0 -58
- package/lib/ui/download.d.ts +0 -5
- package/lib/ui/download.js +0 -61
- package/lib/utils/BaseCommand.d.ts +0 -8
- package/lib/utils/BaseCommand.js +0 -41
- package/lib/utils/SessionCommand.d.ts +0 -10
- package/lib/utils/SessionCommand.js +0 -47
- package/lib/utils/api.d.ts +0 -12
- package/lib/utils/api.js +0 -173
- package/lib/utils/audit.d.ts +0 -16
- package/lib/utils/audit.js +0 -302
- package/lib/utils/console.d.ts +0 -12
- package/lib/utils/console.js +0 -19
- package/lib/utils/errors.d.ts +0 -17
- package/lib/utils/errors.js +0 -100
- package/lib/utils/exercisesQueue.d.ts +0 -9
- package/lib/utils/exercisesQueue.js +0 -38
- package/lib/utils/fileQueue.d.ts +0 -40
- package/lib/utils/fileQueue.js +0 -168
- package/lib/utils/misc.d.ts +0 -1
- package/lib/utils/misc.js +0 -23
- package/lib/utils/validators.d.ts +0 -5
- package/lib/utils/validators.js +0 -17
- package/lib/utils/watcher.d.ts +0 -2
- package/lib/utils/watcher.js +0 -23
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const shell = require("shelljs");
|
|
6
|
-
const console_1 = require("../../utils/console");
|
|
7
|
-
const watcher_1 = require("../../utils/watcher");
|
|
8
|
-
const errors_1 = require("../../utils/errors");
|
|
9
|
-
const defaults_1 = require("./defaults");
|
|
10
|
-
const exercise_1 = require("./exercise");
|
|
11
|
-
const file_1 = require("../file");
|
|
12
|
-
/* exercise folder name standard */
|
|
13
|
-
// eslint-disable-next-line
|
|
14
|
-
const fetch = require("node-fetch");
|
|
15
|
-
// eslint-disable-next-line
|
|
16
|
-
const chalk = require("chalk");
|
|
17
|
-
/* exercise folder name standard */
|
|
18
|
-
const getConfigPath = () => {
|
|
19
|
-
const possibleFileNames = ["learn.json", ".learn/learn.json"];
|
|
20
|
-
const config = possibleFileNames.find(file => fs.existsSync(file)) || null;
|
|
21
|
-
if (config && fs.existsSync(".breathecode"))
|
|
22
|
-
return { config, base: ".breathecode" };
|
|
23
|
-
if (config === null)
|
|
24
|
-
throw errors_1.NotFoundError("learn.json file not found on current folder, is this a learnpack package?");
|
|
25
|
-
return { config, base: ".learn" };
|
|
26
|
-
};
|
|
27
|
-
const getExercisesPath = (base) => {
|
|
28
|
-
const possibleFileNames = ["./exercises", base + "/exercises", "./"];
|
|
29
|
-
return possibleFileNames.find(file => fs.existsSync(file)) || null;
|
|
30
|
-
};
|
|
31
|
-
const getGitpodAddress = () => {
|
|
32
|
-
if (shell.exec("gp -h", { silent: true }).code === 0) {
|
|
33
|
-
return shell
|
|
34
|
-
.exec("gp url", { silent: true })
|
|
35
|
-
.stdout.replace(/(\r\n|\n|\r)/gm, "");
|
|
36
|
-
}
|
|
37
|
-
console_1.default.debug("Gitpod command line tool not found");
|
|
38
|
-
return "http://localhost";
|
|
39
|
-
};
|
|
40
|
-
const getCodespacesNamespace = () => {
|
|
41
|
-
// https://orange-rotary-phone-wxpg49q5gcg4rp-3000.app.github.dev
|
|
42
|
-
const codespace_name = shell
|
|
43
|
-
.exec("echo $CODESPACE_NAME", { silent: true })
|
|
44
|
-
.stdout.replace(/(\r\n|\n|\r)/gm, "");
|
|
45
|
-
if (!codespace_name ||
|
|
46
|
-
codespace_name === "" ||
|
|
47
|
-
codespace_name === undefined) {
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
return codespace_name;
|
|
51
|
-
};
|
|
52
|
-
exports.default = async ({ grading, mode, disableGrading, version, }) => {
|
|
53
|
-
var _a, _b;
|
|
54
|
-
const confPath = getConfigPath();
|
|
55
|
-
console_1.default.debug("This is the config path: ", confPath);
|
|
56
|
-
let configObj = {};
|
|
57
|
-
if (confPath) {
|
|
58
|
-
const bcContent = fs.readFileSync(confPath.config);
|
|
59
|
-
let hiddenBcContent = {};
|
|
60
|
-
if (fs.existsSync(confPath.base + "/config.json")) {
|
|
61
|
-
hiddenBcContent = fs.readFileSync(confPath.base + "/config.json");
|
|
62
|
-
hiddenBcContent = JSON.parse(hiddenBcContent);
|
|
63
|
-
if (!hiddenBcContent)
|
|
64
|
-
throw new Error(`Invalid ${confPath.base}/config.json syntax: Unable to parse.`);
|
|
65
|
-
}
|
|
66
|
-
const jsonConfig = JSON.parse(`${bcContent}`);
|
|
67
|
-
if (!jsonConfig)
|
|
68
|
-
throw new Error(`Invalid ${confPath.config} syntax: Unable to parse.`);
|
|
69
|
-
let session;
|
|
70
|
-
// add using id to the installation
|
|
71
|
-
if (!jsonConfig.session) {
|
|
72
|
-
session = Math.floor(Math.random() * 10000000000000000000);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
session = jsonConfig.session;
|
|
76
|
-
delete jsonConfig.session;
|
|
77
|
-
}
|
|
78
|
-
configObj = deepMerge(hiddenBcContent, {
|
|
79
|
-
config: jsonConfig,
|
|
80
|
-
session: session,
|
|
81
|
-
});
|
|
82
|
-
console_1.default.debug("Content from the configuration .json ", configObj);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
throw errors_1.ValidationError("No learn.json file has been found, make sure you are in the folder");
|
|
86
|
-
}
|
|
87
|
-
configObj = deepMerge(defaults_1.default || {}, configObj, {
|
|
88
|
-
config: {
|
|
89
|
-
grading: grading || ((_a = configObj.config) === null || _a === void 0 ? void 0 : _a.grading),
|
|
90
|
-
configPath: confPath.config,
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
if (configObj.config) {
|
|
94
|
-
configObj.config.outputPath = confPath.base + "/dist";
|
|
95
|
-
}
|
|
96
|
-
console_1.default.debug("This is your configuration object: ", Object.assign(Object.assign({}, configObj), { exercises: configObj.exercises ?
|
|
97
|
-
configObj.exercises.map(e => e.slug) :
|
|
98
|
-
[] }));
|
|
99
|
-
// auto detect agent (if possible)
|
|
100
|
-
const codespaces_workspace = getCodespacesNamespace();
|
|
101
|
-
if (shell.which("gp") && configObj && configObj.config) {
|
|
102
|
-
configObj.config.editor.agent = "vscode";
|
|
103
|
-
configObj.address = getGitpodAddress();
|
|
104
|
-
configObj.config.publicUrl = `https://${configObj.config.port}-${(_b = configObj.address) === null || _b === void 0 ? void 0 : _b.slice(8)}`;
|
|
105
|
-
}
|
|
106
|
-
else if (configObj.config && codespaces_workspace) {
|
|
107
|
-
configObj.config.editor.agent = "vscode";
|
|
108
|
-
configObj.address = `https://${codespaces_workspace}.github.dev`;
|
|
109
|
-
configObj.config.publicUrl = `https://${codespaces_workspace}-${configObj.config.port}.app.github.dev`;
|
|
110
|
-
}
|
|
111
|
-
else if (configObj.config && !configObj.config.editor.agent) {
|
|
112
|
-
configObj.config.editor.agent = "localhost";
|
|
113
|
-
}
|
|
114
|
-
if (configObj.config && !configObj.config.publicUrl)
|
|
115
|
-
configObj.config.publicUrl = `${configObj.address}:${configObj.config.port}`;
|
|
116
|
-
// Assign default editor mode if not set already
|
|
117
|
-
if (configObj.config && !mode) {
|
|
118
|
-
configObj.config.editor.mode = mode;
|
|
119
|
-
}
|
|
120
|
-
if (configObj.config && !configObj.config.editor.mode)
|
|
121
|
-
configObj.config.editor.mode =
|
|
122
|
-
configObj.config.editor.agent === "localhost" ? "standalone" : "preview";
|
|
123
|
-
if (version && configObj.config)
|
|
124
|
-
configObj.config.editor.version = version;
|
|
125
|
-
else if (configObj.config && configObj.config.editor.version === null) {
|
|
126
|
-
console_1.default.debug("Config version not found, downloading default.");
|
|
127
|
-
const resp = await fetch("https://raw.githubusercontent.com/learnpack/coding-ide/learnpack/package.json");
|
|
128
|
-
const packageJSON = await resp.json();
|
|
129
|
-
configObj.config.editor.version = packageJSON.version || "1.0.73";
|
|
130
|
-
}
|
|
131
|
-
if (configObj.config) {
|
|
132
|
-
configObj.config.dirPath = "./" + confPath.base;
|
|
133
|
-
configObj.config.exercisesPath = getExercisesPath(confPath.base) || "./";
|
|
134
|
-
}
|
|
135
|
-
return {
|
|
136
|
-
validLanguages: {},
|
|
137
|
-
get: () => configObj,
|
|
138
|
-
validateEngine: function (language, server, socket) {
|
|
139
|
-
// eslint-disable-next-line
|
|
140
|
-
const alias = (_l) => {
|
|
141
|
-
const map = {
|
|
142
|
-
python3: "python",
|
|
143
|
-
};
|
|
144
|
-
if (map[_l])
|
|
145
|
-
return map[_l];
|
|
146
|
-
return _l;
|
|
147
|
-
};
|
|
148
|
-
// decode aliases
|
|
149
|
-
language = alias(language);
|
|
150
|
-
if (this.validLanguages[language])
|
|
151
|
-
return true;
|
|
152
|
-
console_1.default.debug(`Validating engine for ${language} compilation`);
|
|
153
|
-
let result = shell.exec("learnpack plugins", { silent: true });
|
|
154
|
-
if (result.code === 0 &&
|
|
155
|
-
result.stdout.includes(`learnpack-${language}`)) {
|
|
156
|
-
this.validLanguages[language] = true;
|
|
157
|
-
return true;
|
|
158
|
-
}
|
|
159
|
-
console_1.default.info(`Language engine for ${language} not found, installing...`);
|
|
160
|
-
result = shell.exec(`learnpack plugins:install learnpack-${language}`, {
|
|
161
|
-
silent: true,
|
|
162
|
-
});
|
|
163
|
-
if (result.code === 0) {
|
|
164
|
-
socket.log("compiling", "Installing the python compiler, you will have to reset the exercises after installation by writing on your terminal: $ learnpack run");
|
|
165
|
-
console_1.default.info(`Successfully installed the ${language} exercise engine, \n please start learnpack again by running the following command: \n ${chalk.white("$ learnpack start")}\n\n `);
|
|
166
|
-
server.terminate();
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
this.validLanguages[language] = false;
|
|
170
|
-
socket.error(`Error installing ${language} exercise engine`);
|
|
171
|
-
console_1.default.error(`Error installing ${language} exercise engine`);
|
|
172
|
-
console_1.default.log(result.stdout);
|
|
173
|
-
throw errors_1.InternalError(`Error installing ${language} exercise engine`);
|
|
174
|
-
},
|
|
175
|
-
clean: () => {
|
|
176
|
-
if (configObj.config) {
|
|
177
|
-
if (configObj.config.outputPath) {
|
|
178
|
-
file_1.rmSync(configObj.config.outputPath);
|
|
179
|
-
}
|
|
180
|
-
file_1.rmSync(configObj.config.dirPath + "/_app");
|
|
181
|
-
file_1.rmSync(configObj.config.dirPath + "/reports");
|
|
182
|
-
file_1.rmSync(configObj.config.dirPath + "/.session");
|
|
183
|
-
file_1.rmSync(configObj.config.dirPath + "/resets");
|
|
184
|
-
// clean tag gz
|
|
185
|
-
if (fs.existsSync(configObj.config.dirPath + "/app.tar.gz"))
|
|
186
|
-
fs.unlinkSync(configObj.config.dirPath + "/app.tar.gz");
|
|
187
|
-
if (fs.existsSync(configObj.config.dirPath + "/config.json"))
|
|
188
|
-
fs.unlinkSync(configObj.config.dirPath + "/config.json");
|
|
189
|
-
if (fs.existsSync(configObj.config.dirPath + "/vscode_queue.json"))
|
|
190
|
-
fs.unlinkSync(configObj.config.dirPath + "/vscode_queue.json");
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
getExercise: slug => {
|
|
194
|
-
console_1.default.debug("ExercisePath Slug", slug);
|
|
195
|
-
const exercise = (configObj.exercises || []).find(ex => ex.slug === slug);
|
|
196
|
-
if (!exercise)
|
|
197
|
-
throw errors_1.ValidationError(`Exercise ${slug} not found`);
|
|
198
|
-
return exercise;
|
|
199
|
-
},
|
|
200
|
-
getAllExercises: () => {
|
|
201
|
-
return configObj.exercises;
|
|
202
|
-
},
|
|
203
|
-
startExercise: function (slug) {
|
|
204
|
-
const exercise = this.getExercise(slug);
|
|
205
|
-
// set config.json with current exercise
|
|
206
|
-
configObj.currentExercise = exercise.slug;
|
|
207
|
-
this.save();
|
|
208
|
-
// eslint-disable-next-line
|
|
209
|
-
exercise.files.forEach((f) => {
|
|
210
|
-
if (configObj.config) {
|
|
211
|
-
const _path = configObj.config.outputPath + "/" + f.name;
|
|
212
|
-
if (f.hidden === false && fs.existsSync(_path))
|
|
213
|
-
fs.unlinkSync(_path);
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
return exercise;
|
|
217
|
-
},
|
|
218
|
-
noCurrentExercise: function () {
|
|
219
|
-
configObj.currentExercise = null;
|
|
220
|
-
this.save();
|
|
221
|
-
},
|
|
222
|
-
reset: slug => {
|
|
223
|
-
var _a;
|
|
224
|
-
if (configObj.config &&
|
|
225
|
-
!fs.existsSync(`${configObj.config.dirPath}/resets/` + slug))
|
|
226
|
-
throw errors_1.ValidationError("Could not find the original files for " + slug);
|
|
227
|
-
const exercise = (configObj.exercises || []).find(ex => ex.slug === slug);
|
|
228
|
-
if (!exercise)
|
|
229
|
-
throw errors_1.ValidationError(`Exercise ${slug} not found on the configuration`);
|
|
230
|
-
if (configObj.config) {
|
|
231
|
-
for (const fileName of fs.readdirSync(`${configObj.config.dirPath}/resets/${slug}/`)) {
|
|
232
|
-
const content = fs.readFileSync(`${(_a = configObj.config) === null || _a === void 0 ? void 0 : _a.dirPath}/resets/${slug}/${fileName}`);
|
|
233
|
-
fs.writeFileSync(`${exercise.path}/${fileName}`, content);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
buildIndex: function () {
|
|
238
|
-
var _a, _b;
|
|
239
|
-
console_1.default.info("Building the exercise index...");
|
|
240
|
-
const isDirectory = (source) => {
|
|
241
|
-
var _a;
|
|
242
|
-
const name = path.basename(source);
|
|
243
|
-
if (name === path.basename(((_a = configObj === null || configObj === void 0 ? void 0 : configObj.config) === null || _a === void 0 ? void 0 : _a.dirPath) || ""))
|
|
244
|
-
return false;
|
|
245
|
-
// ignore folders that start with a dot
|
|
246
|
-
if (name.charAt(0) === "." || name.charAt(0) === "_")
|
|
247
|
-
return false;
|
|
248
|
-
return fs.lstatSync(source).isDirectory();
|
|
249
|
-
};
|
|
250
|
-
const getDirectories = (source) => fs
|
|
251
|
-
.readdirSync(source)
|
|
252
|
-
.map(name => path.join(source, name))
|
|
253
|
-
.filter(isDirectory);
|
|
254
|
-
// add the .learn folder
|
|
255
|
-
if (!fs.existsSync(confPath.base))
|
|
256
|
-
fs.mkdirSync(confPath.base);
|
|
257
|
-
// add the outout folder where webpack will publish the the html/css/js files
|
|
258
|
-
if (configObj.config &&
|
|
259
|
-
configObj.config.outputPath &&
|
|
260
|
-
!fs.existsSync(configObj.config.outputPath))
|
|
261
|
-
fs.mkdirSync(configObj.config.outputPath);
|
|
262
|
-
// TODO: we could use npm library front-mater to read the title of the exercises from the README.md
|
|
263
|
-
const grupedByDirectory = getDirectories(((_a = configObj === null || configObj === void 0 ? void 0 : configObj.config) === null || _a === void 0 ? void 0 : _a.exercisesPath) || "");
|
|
264
|
-
configObj.exercises =
|
|
265
|
-
grupedByDirectory.length > 0 ?
|
|
266
|
-
grupedByDirectory.map((path, position) => exercise_1.exercise(path, position, configObj)) :
|
|
267
|
-
[exercise_1.exercise(((_b = configObj === null || configObj === void 0 ? void 0 : configObj.config) === null || _b === void 0 ? void 0 : _b.exercisesPath) || "", 0, configObj)];
|
|
268
|
-
this.save();
|
|
269
|
-
},
|
|
270
|
-
watchIndex: function (onChange) {
|
|
271
|
-
var _a;
|
|
272
|
-
if (configObj.config && !configObj.config.exercisesPath)
|
|
273
|
-
throw errors_1.ValidationError("No exercises directory to watch: " + configObj.config.exercisesPath);
|
|
274
|
-
this.buildIndex();
|
|
275
|
-
watcher_1.default(((_a = configObj === null || configObj === void 0 ? void 0 : configObj.config) === null || _a === void 0 ? void 0 : _a.exercisesPath) || "", onChange)
|
|
276
|
-
.then(( /* eventname, filename */) => {
|
|
277
|
-
console_1.default.debug("Changes detected on your exercises");
|
|
278
|
-
this.buildIndex();
|
|
279
|
-
if (onChange)
|
|
280
|
-
onChange();
|
|
281
|
-
})
|
|
282
|
-
.catch(error => {
|
|
283
|
-
throw error;
|
|
284
|
-
});
|
|
285
|
-
},
|
|
286
|
-
save: () => {
|
|
287
|
-
console_1.default.debug("Saving configuration with: ", configObj);
|
|
288
|
-
// remove the duplicates form the actions array
|
|
289
|
-
// configObj.config.actions = [...new Set(configObj.config.actions)];
|
|
290
|
-
if (configObj.config) {
|
|
291
|
-
configObj.config.translations = [
|
|
292
|
-
...new Set(configObj.config.translations),
|
|
293
|
-
];
|
|
294
|
-
fs.writeFileSync(configObj.config.dirPath + "/config.json", JSON.stringify(configObj, null, 4));
|
|
295
|
-
}
|
|
296
|
-
},
|
|
297
|
-
};
|
|
298
|
-
};
|
|
299
|
-
function deepMerge(...sources) {
|
|
300
|
-
let acc = {};
|
|
301
|
-
for (const source of sources) {
|
|
302
|
-
if (Array.isArray(source)) {
|
|
303
|
-
if (!Array.isArray(acc)) {
|
|
304
|
-
acc = [];
|
|
305
|
-
}
|
|
306
|
-
acc = [...source];
|
|
307
|
-
}
|
|
308
|
-
else if (source instanceof Object) {
|
|
309
|
-
// eslint-disable-next-line
|
|
310
|
-
for (let [key, value] of Object.entries(source)) {
|
|
311
|
-
if (value instanceof Object && key in acc) {
|
|
312
|
-
value = deepMerge(acc[key], value);
|
|
313
|
-
}
|
|
314
|
-
if (value !== undefined)
|
|
315
|
-
acc = Object.assign(Object.assign({}, acc), { [key]: value });
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return acc;
|
|
320
|
-
}
|
package/lib/managers/file.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare const decompress: (sourcePath: string, destinationPath: string) => Promise<unknown>;
|
|
2
|
-
export declare const downloadEditor: (version: string | undefined, destination: string) => Promise<unknown>;
|
|
3
|
-
export declare const download: (url: string, dest: string) => Promise<unknown>;
|
|
4
|
-
export declare const clone: (repository?: string, folder?: string) => Promise<unknown>;
|
|
5
|
-
export declare const rmSync: (path: string) => void;
|
|
6
|
-
declare const _default: {
|
|
7
|
-
download: (url: string, dest: string) => Promise<unknown>;
|
|
8
|
-
decompress: (sourcePath: string, destinationPath: string) => Promise<unknown>;
|
|
9
|
-
downloadEditor: (version: string | undefined, destination: string) => Promise<unknown>;
|
|
10
|
-
clone: (repository?: string, folder?: string) => Promise<unknown>;
|
|
11
|
-
rmSync: (path: string) => void;
|
|
12
|
-
};
|
|
13
|
-
export default _default;
|
package/lib/managers/file.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rmSync = exports.clone = exports.download = exports.downloadEditor = exports.decompress = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const p = require("path");
|
|
6
|
-
const shell = require("shelljs");
|
|
7
|
-
const cli_ux_1 = require("cli-ux");
|
|
8
|
-
const targz = require("targz");
|
|
9
|
-
const console_1 = require("../utils/console");
|
|
10
|
-
const https = require("https");
|
|
11
|
-
const errors_1 = require("../utils/errors");
|
|
12
|
-
// eslint-disable-next-line
|
|
13
|
-
const fetch = require("node-fetch");
|
|
14
|
-
exports.decompress = (sourcePath, destinationPath) => new Promise((resolve, reject) => {
|
|
15
|
-
console_1.default.debug("Decompressing " + sourcePath);
|
|
16
|
-
targz.decompress({
|
|
17
|
-
src: sourcePath,
|
|
18
|
-
dest: destinationPath,
|
|
19
|
-
}, function (err) {
|
|
20
|
-
if (err) {
|
|
21
|
-
console_1.default.error("Error when trying to decompress");
|
|
22
|
-
reject(err);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
console_1.default.info("Decompression finished successfully");
|
|
26
|
-
resolve(/* */ "");
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
exports.downloadEditor = async (version, destination) => {
|
|
31
|
-
// https://raw.githubusercontent.com/learnpack/coding-ide/master/dist/app.tar.gz
|
|
32
|
-
// if(versions[version] === undefined) throw new Error(`Invalid editor version ${version}`)
|
|
33
|
-
const resp2 = await fetch(`https://github.com/learnpack/coding-ide/blob/${version}/dist`, { method: "HEAD" });
|
|
34
|
-
if (!resp2.ok)
|
|
35
|
-
throw errors_1.InternalError(`Coding Editor ${version} was not found on learnpack repository, check the config.editor.version property on learn.json`);
|
|
36
|
-
console_1.default.info("Downloading the LearnPack coding UI, this may take a minute...");
|
|
37
|
-
return exports.download(`https://github.com/learnpack/coding-ide/blob/${version}/dist/app.tar.gz?raw=true`, destination);
|
|
38
|
-
};
|
|
39
|
-
exports.download = (url, dest) => {
|
|
40
|
-
console_1.default.debug("Downloading " + url);
|
|
41
|
-
return new Promise((resolve, reject) => {
|
|
42
|
-
const request = https.get(url, response => {
|
|
43
|
-
if (response.statusCode === 200) {
|
|
44
|
-
const file = fs.createWriteStream(dest, { flags: "wx" });
|
|
45
|
-
file.on("finish", () => {
|
|
46
|
-
resolve(true);
|
|
47
|
-
});
|
|
48
|
-
file.on("error", err => {
|
|
49
|
-
file.close();
|
|
50
|
-
if (err.code === "EEXIST") {
|
|
51
|
-
console_1.default.debug("File already exists");
|
|
52
|
-
resolve("File already exists");
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
console_1.default.debug("Error ", err.message);
|
|
56
|
-
fs.unlink(dest, () => reject(err.message)); // Delete temp file
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
response.pipe(file);
|
|
60
|
-
}
|
|
61
|
-
else if (response.statusCode === 302 || response.statusCode === 301) {
|
|
62
|
-
// Console.debug("Servers redirected to "+response.headers.location)
|
|
63
|
-
// Recursively follow redirects, only a 200 will resolve.
|
|
64
|
-
if (response.headers.location) {
|
|
65
|
-
exports.download(response.headers.location, dest)
|
|
66
|
-
.then(() => resolve(/* */ ""))
|
|
67
|
-
.catch(error => {
|
|
68
|
-
console_1.default.error(error);
|
|
69
|
-
reject(error);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
console_1.default.debug(`Server responded with ${response.statusCode}: ${response.statusMessage}`);
|
|
75
|
-
reject(`Server responded with ${response.statusCode}: ${response.statusMessage}`);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
request.on("error", err => {
|
|
79
|
-
reject(err.message);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
exports.clone = (repository = "", folder = "./") => new Promise((resolve, reject) => {
|
|
84
|
-
if (!repository) {
|
|
85
|
-
reject("Missing repository url for this package");
|
|
86
|
-
// return false
|
|
87
|
-
}
|
|
88
|
-
cli_ux_1.cli.action.start("Verifying GIT...");
|
|
89
|
-
if (!shell.which("git")) {
|
|
90
|
-
reject("Sorry, this script requires git");
|
|
91
|
-
// return false
|
|
92
|
-
}
|
|
93
|
-
cli_ux_1.cli.action.stop();
|
|
94
|
-
let fileName = p.basename(repository);
|
|
95
|
-
if (!fileName) {
|
|
96
|
-
reject("Invalid repository information on package: " + repository);
|
|
97
|
-
// return false
|
|
98
|
-
}
|
|
99
|
-
fileName = fileName.split(".")[0];
|
|
100
|
-
if (fs.existsSync("./" + fileName)) {
|
|
101
|
-
reject(`Directory ${fileName} already exists; Did you download this package already?`);
|
|
102
|
-
// return false
|
|
103
|
-
}
|
|
104
|
-
cli_ux_1.cli.action.start(`Cloning repository ${repository}...`);
|
|
105
|
-
if (shell.exec(`git clone ${repository}`).code !== 0) {
|
|
106
|
-
reject("Error: Installation failed");
|
|
107
|
-
}
|
|
108
|
-
cli_ux_1.cli.action.stop();
|
|
109
|
-
cli_ux_1.cli.action.start("Cleaning installation...");
|
|
110
|
-
if (shell.exec(`rm -R -f ${folder}${fileName}/.git`).code !== 0) {
|
|
111
|
-
reject("Error: removing .git directory");
|
|
112
|
-
}
|
|
113
|
-
cli_ux_1.cli.action.stop();
|
|
114
|
-
resolve("Done");
|
|
115
|
-
});
|
|
116
|
-
exports.rmSync = function (path) {
|
|
117
|
-
let files = [];
|
|
118
|
-
if (fs.existsSync(path)) {
|
|
119
|
-
files = fs.readdirSync(path);
|
|
120
|
-
for (const [, file] of files.entries()) {
|
|
121
|
-
const curPath = path + "/" + file;
|
|
122
|
-
if (fs.lstatSync(curPath).isDirectory()) {
|
|
123
|
-
// recurse
|
|
124
|
-
exports.rmSync(curPath);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
// delete file
|
|
128
|
-
fs.unlinkSync(curPath);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
fs.rmdirSync(path);
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
exports.default = { download: exports.download, decompress: exports.decompress, downloadEditor: exports.downloadEditor, clone: exports.clone, rmSync: exports.rmSync };
|
package/lib/managers/gitpod.d.ts
DELETED
package/lib/managers/gitpod.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const console_1 = require("../utils/console");
|
|
4
|
-
const shell = require("shelljs");
|
|
5
|
-
const socket_1 = require("./socket");
|
|
6
|
-
const fs = require("fs");
|
|
7
|
-
const Gitpod = {
|
|
8
|
-
socket: null,
|
|
9
|
-
config: null,
|
|
10
|
-
initialized: false,
|
|
11
|
-
hasGPCommand: false,
|
|
12
|
-
init: function (config) {
|
|
13
|
-
if (this.initialized) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
this.initialized = true;
|
|
17
|
-
if (config) {
|
|
18
|
-
this.config = config;
|
|
19
|
-
}
|
|
20
|
-
if (shell.exec('gp -h', { silent: true }).code === 0) {
|
|
21
|
-
this.hasGPCommand = true;
|
|
22
|
-
if (config) {
|
|
23
|
-
config.address = shell
|
|
24
|
-
.exec('gp url', { silent: true })
|
|
25
|
-
.stdout.replace(/(\r\n|\n|\r)/gm, '');
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
console_1.default.debug('Gitpod command line tool not found');
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
openFiles: async function (files) {
|
|
33
|
-
var _a;
|
|
34
|
-
console_1.default.debug('Attempting to open files in gitpod mode', files);
|
|
35
|
-
this.init(); // initilize gitpod config
|
|
36
|
-
// gitpod will open files only on isolated mode
|
|
37
|
-
if (!this.config || ((_a = this.config.config) === null || _a === void 0 ? void 0 : _a.grading) !== 'isolated') {
|
|
38
|
-
console_1.default.debug('Files cannot be automatically opened because we are not on isolated grading (only for isolated)');
|
|
39
|
-
socket_1.default.log('ready', ['Ready to compile or test...']);
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
if (this.hasGPCommand)
|
|
43
|
-
for (const f of files.reverse()) {
|
|
44
|
-
if (shell.exec(`gp open ${f}`).code > 0) {
|
|
45
|
-
console_1.default.debug(`Error opening file ${f} on gitpod`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
socket_1.default.log('ready', ['Ready to compile or test...']);
|
|
49
|
-
},
|
|
50
|
-
setup(config) {
|
|
51
|
-
this.init(config); // initilize gitpod config
|
|
52
|
-
this.autosave('on');
|
|
53
|
-
},
|
|
54
|
-
autosave: async function (value = 'on') {
|
|
55
|
-
this.init(); // initilize gitpod config
|
|
56
|
-
if (this.hasGPCommand) {
|
|
57
|
-
if (!fs.existsSync('./.theia'))
|
|
58
|
-
fs.mkdirSync('./.theia');
|
|
59
|
-
if (!fs.existsSync('./.theia/settings.json')) {
|
|
60
|
-
fs.writeFileSync('./.theia/settings.json', JSON.stringify({
|
|
61
|
-
'editor.autoSave': value,
|
|
62
|
-
}, null, 4));
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
exports.default = Gitpod;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import * as http from "http";
|
|
3
|
-
import { IConfigObj } from "../../models/config";
|
|
4
|
-
import { IConfigManager } from "../../models/config-manager";
|
|
5
|
-
export declare let TEST_SERVER: http.Server;
|
|
6
|
-
export default function (configObj: IConfigObj, configManager: IConfigManager, isTestingEnvironment?: boolean): Promise<any>;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TEST_SERVER = void 0;
|
|
4
|
-
const express = require("express");
|
|
5
|
-
// eslint-disable-next-line
|
|
6
|
-
const cors = require("cors");
|
|
7
|
-
const console_1 = require("../../utils/console");
|
|
8
|
-
const routes_1 = require("./routes");
|
|
9
|
-
const cli_ux_1 = require("cli-ux");
|
|
10
|
-
async function default_1(configObj, configManager, isTestingEnvironment = false) {
|
|
11
|
-
const { config } = configObj;
|
|
12
|
-
const app = express();
|
|
13
|
-
let server;
|
|
14
|
-
if (isTestingEnvironment) {
|
|
15
|
-
if (exports.TEST_SERVER === undefined)
|
|
16
|
-
exports.TEST_SERVER = require("http").Server(app);
|
|
17
|
-
server = exports.TEST_SERVER;
|
|
18
|
-
}
|
|
19
|
-
else
|
|
20
|
-
server = require("http").Server(app);
|
|
21
|
-
app.use(cors());
|
|
22
|
-
// app.use(function(req, res, next) {
|
|
23
|
-
// res.header("Access-Control-Allow-Origin", "*")
|
|
24
|
-
// res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")
|
|
25
|
-
// res.header("Access-Control-Allow-Methods", "GET,PUT")
|
|
26
|
-
// next()
|
|
27
|
-
// })
|
|
28
|
-
// add all needed endpoints
|
|
29
|
-
await routes_1.default(app, configObj, configManager);
|
|
30
|
-
server.listen(isTestingEnvironment ? 5000 : config === null || config === void 0 ? void 0 : config.port, function () {
|
|
31
|
-
if (!isTestingEnvironment) {
|
|
32
|
-
console_1.default.success(`Exercises are running 😃 Open your browser to start practicing!`);
|
|
33
|
-
console_1.default.success(`\n Open the exercise on this link:`);
|
|
34
|
-
console_1.default.log(` ${config === null || config === void 0 ? void 0 : config.publicUrl}`);
|
|
35
|
-
if ((config === null || config === void 0 ? void 0 : config.editor.mode) === "standalone")
|
|
36
|
-
cli_ux_1.default.open(`${config.publicUrl}`);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
const sockets = new Set();
|
|
40
|
-
server.on("connection", (socket) => {
|
|
41
|
-
sockets.add(socket);
|
|
42
|
-
server.once("close", () => {
|
|
43
|
-
sockets.delete(socket);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
/**
|
|
47
|
-
* Forcefully terminates HTTP server.
|
|
48
|
-
*/
|
|
49
|
-
server.terminate = (callback) => {
|
|
50
|
-
for (const socket of sockets) {
|
|
51
|
-
socket.destroy();
|
|
52
|
-
sockets.delete(socket);
|
|
53
|
-
}
|
|
54
|
-
server.close(callback);
|
|
55
|
-
};
|
|
56
|
-
return server;
|
|
57
|
-
}
|
|
58
|
-
exports.default = default_1;
|
|
@@ -1,4 +0,0 @@
|
|
|
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>;
|