@learnpack/learnpack 2.1.39 → 2.1.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +370 -35
- package/bin/run +17 -17
- package/bin/run.cmd +3 -3
- package/lib/commands/audit.d.ts +6 -6
- package/lib/commands/audit.js +342 -342
- package/lib/commands/clean.d.ts +8 -8
- package/lib/commands/clean.js +25 -25
- package/lib/commands/download.d.ts +13 -13
- package/lib/commands/download.js +55 -55
- package/lib/commands/init.d.ts +9 -9
- package/lib/commands/init.js +123 -123
- package/lib/commands/login.d.ts +14 -14
- package/lib/commands/login.js +37 -37
- package/lib/commands/logout.d.ts +14 -14
- package/lib/commands/logout.js +37 -37
- package/lib/commands/publish.d.ts +14 -14
- package/lib/commands/publish.js +82 -82
- package/lib/commands/start.d.ts +7 -7
- package/lib/commands/start.js +239 -208
- package/lib/commands/test.d.ts +6 -6
- package/lib/commands/test.js +62 -62
- package/lib/index.d.ts +1 -1
- package/lib/index.js +4 -4
- package/lib/managers/config/allowed_files.d.ts +5 -5
- package/lib/managers/config/allowed_files.js +30 -30
- package/lib/managers/config/defaults.d.ts +41 -41
- package/lib/managers/config/defaults.js +44 -44
- package/lib/managers/config/exercise.d.ts +36 -36
- package/lib/managers/config/exercise.js +236 -236
- package/lib/managers/config/index.d.ts +3 -3
- package/lib/managers/config/index.js +337 -337
- package/lib/managers/file.d.ts +14 -14
- package/lib/managers/file.js +153 -153
- package/lib/managers/gitpod.d.ts +3 -3
- package/lib/managers/gitpod.js +67 -67
- package/lib/managers/server/index.d.ts +6 -6
- package/lib/managers/server/index.js +58 -58
- package/lib/managers/server/routes.d.ts +4 -4
- package/lib/managers/server/routes.js +219 -219
- package/lib/managers/session.d.ts +3 -3
- package/lib/managers/session.js +125 -125
- package/lib/managers/socket.d.ts +3 -3
- package/lib/managers/socket.js +176 -176
- package/lib/managers/telemetry.d.ts +74 -74
- package/lib/managers/telemetry.js +206 -206
- package/lib/managers/test.js +84 -84
- package/lib/models/action.d.ts +2 -2
- package/lib/models/action.js +2 -2
- package/lib/models/audit.d.ts +15 -15
- package/lib/models/audit.js +2 -2
- package/lib/models/config-manager.d.ts +21 -21
- package/lib/models/config-manager.js +2 -2
- package/lib/models/config.d.ts +68 -67
- package/lib/models/config.js +2 -2
- package/lib/models/counter.d.ts +11 -11
- package/lib/models/counter.js +2 -2
- package/lib/models/errors.d.ts +15 -15
- package/lib/models/errors.js +2 -2
- package/lib/models/exercise-obj.d.ts +30 -30
- package/lib/models/exercise-obj.js +2 -2
- package/lib/models/file.d.ts +5 -5
- package/lib/models/file.js +2 -2
- package/lib/models/findings.d.ts +17 -17
- package/lib/models/findings.js +2 -2
- package/lib/models/flags.d.ts +10 -10
- package/lib/models/flags.js +2 -2
- package/lib/models/front-matter.d.ts +11 -11
- package/lib/models/front-matter.js +2 -2
- package/lib/models/gitpod-data.d.ts +16 -16
- package/lib/models/gitpod-data.js +2 -2
- package/lib/models/language.d.ts +4 -4
- package/lib/models/language.js +2 -2
- package/lib/models/package.d.ts +7 -7
- package/lib/models/package.js +2 -2
- package/lib/models/plugin-config.d.ts +16 -16
- package/lib/models/plugin-config.js +2 -2
- package/lib/models/session.d.ts +31 -31
- package/lib/models/session.js +2 -2
- package/lib/models/socket.d.ts +36 -32
- package/lib/models/socket.js +2 -2
- package/lib/models/status.d.ts +1 -1
- package/lib/models/status.js +2 -2
- package/lib/models/success-types.d.ts +1 -1
- package/lib/models/success-types.js +2 -2
- package/lib/plugin/command/compile.d.ts +6 -6
- package/lib/plugin/command/compile.js +18 -18
- package/lib/plugin/command/test.d.ts +6 -6
- package/lib/plugin/command/test.js +25 -25
- package/lib/plugin/index.d.ts +27 -27
- package/lib/plugin/index.js +7 -7
- package/lib/plugin/plugin.d.ts +8 -8
- package/lib/plugin/plugin.js +68 -68
- package/lib/plugin/utils.d.ts +16 -16
- package/lib/plugin/utils.js +58 -58
- package/lib/ui/download.d.ts +5 -5
- package/lib/ui/download.js +61 -61
- package/lib/utils/BaseCommand.d.ts +8 -8
- package/lib/utils/BaseCommand.js +41 -41
- package/lib/utils/SessionCommand.d.ts +10 -10
- package/lib/utils/SessionCommand.js +43 -43
- package/lib/utils/api.d.ts +14 -14
- package/lib/utils/api.js +255 -255
- package/lib/utils/audit.d.ts +16 -16
- package/lib/utils/audit.js +303 -303
- package/lib/utils/checkNotInstalled.d.ts +2 -0
- package/lib/utils/checkNotInstalled.js +36 -0
- package/lib/utils/console.d.ts +12 -12
- package/lib/utils/console.js +19 -19
- package/lib/utils/errors.d.ts +17 -17
- package/lib/utils/errors.js +100 -100
- package/lib/utils/exercisesQueue.d.ts +9 -9
- package/lib/utils/exercisesQueue.js +38 -38
- package/lib/utils/fileQueue.d.ts +40 -40
- package/lib/utils/fileQueue.js +168 -168
- package/lib/utils/misc.d.ts +1 -1
- package/lib/utils/misc.js +23 -23
- package/lib/utils/osOperations.d.ts +5 -5
- package/lib/utils/osOperations.js +72 -72
- package/lib/utils/validators.d.ts +5 -5
- package/lib/utils/validators.js +17 -17
- package/lib/utils/watcher.d.ts +2 -2
- package/lib/utils/watcher.js +25 -25
- package/oclif.manifest.json +1 -1
- package/package.json +139 -139
- package/src/commands/audit.ts +443 -443
- package/src/commands/clean.ts +29 -29
- package/src/commands/download.ts +61 -61
- package/src/commands/init.ts +170 -170
- package/src/commands/login.ts +42 -42
- package/src/commands/logout.ts +43 -43
- package/src/commands/publish.ts +107 -107
- package/src/commands/start.ts +53 -23
- package/src/commands/test.ts +85 -85
- package/src/index.ts +1 -1
- package/src/managers/config/allowed_files.ts +29 -29
- package/src/managers/config/defaults.ts +42 -42
- package/src/managers/config/exercise.ts +311 -311
- package/src/managers/config/index.ts +455 -455
- package/src/managers/file.ts +196 -196
- package/src/managers/gitpod.ts +84 -84
- package/src/managers/server/index.ts +78 -78
- package/src/managers/server/routes.ts +330 -330
- package/src/managers/session.ts +145 -145
- package/src/managers/socket.ts +250 -250
- package/src/managers/telemetry.ts +346 -346
- package/src/managers/test.ts +83 -83
- package/src/models/action.ts +10 -10
- package/src/models/audit.ts +16 -16
- package/src/models/config-manager.ts +23 -23
- package/src/models/config.ts +5 -3
- package/src/models/counter.ts +11 -11
- package/src/models/errors.ts +22 -22
- package/src/models/exercise-obj.ts +29 -29
- package/src/models/file.ts +5 -5
- package/src/models/findings.ts +18 -18
- package/src/models/flags.ts +10 -10
- package/src/models/front-matter.ts +11 -11
- package/src/models/gitpod-data.ts +19 -19
- package/src/models/language.ts +4 -4
- package/src/models/package.ts +7 -7
- package/src/models/plugin-config.ts +17 -17
- package/src/models/session.ts +34 -34
- package/src/models/socket.ts +5 -0
- package/src/models/status.ts +16 -16
- package/src/models/success-types.ts +1 -1
- package/src/plugin/command/compile.ts +17 -17
- package/src/plugin/command/test.ts +30 -30
- package/src/plugin/index.ts +6 -6
- package/src/plugin/plugin.ts +94 -94
- package/src/plugin/utils.ts +87 -87
- package/src/types/node-fetch.d.ts +1 -1
- package/src/ui/download.ts +71 -71
- package/src/utils/BaseCommand.ts +48 -48
- package/src/utils/SessionCommand.ts +43 -43
- package/src/utils/api.ts +303 -303
- package/src/utils/audit.ts +393 -393
- package/src/utils/checkNotInstalled.ts +46 -0
- package/src/utils/console.ts +24 -24
- package/src/utils/errors.ts +117 -117
- package/src/utils/exercisesQueue.ts +51 -51
- package/src/utils/fileQueue.ts +198 -198
- package/src/utils/misc.ts +23 -23
- package/src/utils/osOperations.ts +79 -79
- package/src/utils/templates/gitignore.txt +19 -19
- package/src/utils/templates/incremental/.learn/exercises/01-hello-world/README.es.md +24 -24
- package/src/utils/templates/incremental/.learn/exercises/01-hello-world/README.md +24 -24
- package/src/utils/templates/incremental/README.ejs +4 -4
- package/src/utils/templates/incremental/README.es.ejs +4 -4
- package/src/utils/templates/isolated/01-hello-world/README.es.md +26 -26
- package/src/utils/templates/isolated/01-hello-world/README.md +26 -26
- package/src/utils/templates/isolated/README.ejs +4 -4
- package/src/utils/templates/isolated/README.es.ejs +4 -4
- package/src/utils/templates/no-grading/README.ejs +4 -4
- package/src/utils/templates/no-grading/README.es.ejs +4 -4
- package/src/utils/validators.ts +18 -18
- package/src/utils/watcher.ts +27 -27
package/lib/managers/file.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
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
|
-
export declare const checkIfDirectoryExists: (path: string) => boolean;
|
|
7
|
-
declare const _default: {
|
|
8
|
-
download: (url: string, dest: string) => Promise<unknown>;
|
|
9
|
-
decompress: (sourcePath: string, destinationPath: string) => Promise<unknown>;
|
|
10
|
-
downloadEditor: (version: string | undefined, destination: string) => Promise<unknown>;
|
|
11
|
-
clone: (repository?: string, folder?: string) => Promise<unknown>;
|
|
12
|
-
rmSync: (path: string) => void;
|
|
13
|
-
};
|
|
14
|
-
export default _default;
|
|
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
|
+
export declare const checkIfDirectoryExists: (path: string) => boolean;
|
|
7
|
+
declare const _default: {
|
|
8
|
+
download: (url: string, dest: string) => Promise<unknown>;
|
|
9
|
+
decompress: (sourcePath: string, destinationPath: string) => Promise<unknown>;
|
|
10
|
+
downloadEditor: (version: string | undefined, destination: string) => Promise<unknown>;
|
|
11
|
+
clone: (repository?: string, folder?: string) => Promise<unknown>;
|
|
12
|
+
rmSync: (path: string) => void;
|
|
13
|
+
};
|
|
14
|
+
export default _default;
|
package/lib/managers/file.js
CHANGED
|
@@ -1,153 +1,153 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkIfDirectoryExists = 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
|
-
if (!version) {
|
|
34
|
-
const res = await fetch("https://raw.githubusercontent.com/learnpack/ide/master/package.json");
|
|
35
|
-
const json = await res.json();
|
|
36
|
-
version = json.version;
|
|
37
|
-
if (!version)
|
|
38
|
-
throw errors_1.InternalError(`Coding Editor version was not found on learnpack repository, check the config.editor.version property on learn.json`);
|
|
39
|
-
}
|
|
40
|
-
const versionNumber = parseInt(version.split(".")[0]);
|
|
41
|
-
let url = `https://github.com/learnpack/coding-ide/blob/${version}/dist`;
|
|
42
|
-
if (versionNumber > 2)
|
|
43
|
-
url = `https://github.com/learnpack/ide/blob/master/bin/learnpack-${version}.tar.gz`;
|
|
44
|
-
const resp2 = await fetch(url, { method: "HEAD" });
|
|
45
|
-
if (!resp2.ok)
|
|
46
|
-
throw errors_1.InternalError(`Coding Editor ${version} was not found on learnpack repository, check the config.editor.version property on learn.json`);
|
|
47
|
-
console_1.default.info("Downloading the LearnPack coding UI, this may take a minute...");
|
|
48
|
-
url += versionNumber > 2 ? `?raw=true` : `/app.tar.gz?raw=true`;
|
|
49
|
-
return exports.download(url, destination);
|
|
50
|
-
};
|
|
51
|
-
exports.download = (url, dest) => {
|
|
52
|
-
console_1.default.debug("Downloading " + url);
|
|
53
|
-
return new Promise((resolve, reject) => {
|
|
54
|
-
const request = https.get(url, response => {
|
|
55
|
-
if (response.statusCode === 200) {
|
|
56
|
-
const file = fs.createWriteStream(dest, { flags: "wx" });
|
|
57
|
-
file.on("finish", () => {
|
|
58
|
-
resolve(true);
|
|
59
|
-
});
|
|
60
|
-
file.on("error", err => {
|
|
61
|
-
file.close();
|
|
62
|
-
if (err.code === "EEXIST") {
|
|
63
|
-
console_1.default.debug("File already exists");
|
|
64
|
-
resolve("File already exists");
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
console_1.default.debug("Error ", err.message);
|
|
68
|
-
fs.unlink(dest, () => reject(err.message)); // Delete temp file
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
response.pipe(file);
|
|
72
|
-
}
|
|
73
|
-
else if (response.statusCode === 302 || response.statusCode === 301) {
|
|
74
|
-
// Console.debug("Servers redirected to "+response.headers.location)
|
|
75
|
-
// Recursively follow redirects, only a 200 will resolve.
|
|
76
|
-
if (response.headers.location) {
|
|
77
|
-
exports.download(response.headers.location, dest)
|
|
78
|
-
.then(() => resolve(/* */ ""))
|
|
79
|
-
.catch(error => {
|
|
80
|
-
console_1.default.error(error);
|
|
81
|
-
reject(error);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
console_1.default.debug(`Server responded with ${response.statusCode}: ${response.statusMessage}`);
|
|
87
|
-
reject(`Server responded with ${response.statusCode}: ${response.statusMessage}`);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
request.on("error", err => {
|
|
91
|
-
reject(err.message);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
exports.clone = (repository = "", folder = "./") => new Promise((resolve, reject) => {
|
|
96
|
-
if (!repository) {
|
|
97
|
-
reject("Missing repository url for this package");
|
|
98
|
-
// return false
|
|
99
|
-
}
|
|
100
|
-
cli_ux_1.cli.action.start("Verifying GIT...");
|
|
101
|
-
if (!shell.which("git")) {
|
|
102
|
-
reject("Sorry, this script requires git");
|
|
103
|
-
// return false
|
|
104
|
-
}
|
|
105
|
-
cli_ux_1.cli.action.stop();
|
|
106
|
-
let fileName = p.basename(repository);
|
|
107
|
-
if (!fileName) {
|
|
108
|
-
reject("Invalid repository information on package: " + repository);
|
|
109
|
-
// return false
|
|
110
|
-
}
|
|
111
|
-
fileName = fileName.split(".")[0];
|
|
112
|
-
if (fs.existsSync("./" + fileName)) {
|
|
113
|
-
reject(`Directory ${fileName} already exists; Did you download this package already?`);
|
|
114
|
-
// return false
|
|
115
|
-
}
|
|
116
|
-
cli_ux_1.cli.action.start(`Cloning repository ${repository}...`);
|
|
117
|
-
if (shell.exec(`git clone ${repository}`).code !== 0) {
|
|
118
|
-
reject("Error: Installation failed");
|
|
119
|
-
}
|
|
120
|
-
cli_ux_1.cli.action.stop();
|
|
121
|
-
cli_ux_1.cli.action.start("Cleaning installation...");
|
|
122
|
-
if (shell.exec(`rm -R -f ${folder}${fileName}/.git`).code !== 0) {
|
|
123
|
-
reject("Error: removing .git directory");
|
|
124
|
-
}
|
|
125
|
-
cli_ux_1.cli.action.stop();
|
|
126
|
-
resolve("Done");
|
|
127
|
-
});
|
|
128
|
-
exports.rmSync = function (path) {
|
|
129
|
-
let files = [];
|
|
130
|
-
if (fs.existsSync(path)) {
|
|
131
|
-
files = fs.readdirSync(path);
|
|
132
|
-
for (const [, file] of files.entries()) {
|
|
133
|
-
const curPath = path + "/" + file;
|
|
134
|
-
if (fs.lstatSync(curPath).isDirectory()) {
|
|
135
|
-
// recurse
|
|
136
|
-
exports.rmSync(curPath);
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
// delete file
|
|
140
|
-
fs.unlinkSync(curPath);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
fs.rmdirSync(path);
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
exports.checkIfDirectoryExists = (path) => {
|
|
147
|
-
const fs = require("fs");
|
|
148
|
-
if (fs.existsSync(path)) {
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
return false;
|
|
152
|
-
};
|
|
153
|
-
exports.default = { download: exports.download, decompress: exports.decompress, downloadEditor: exports.downloadEditor, clone: exports.clone, rmSync: exports.rmSync };
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkIfDirectoryExists = 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
|
+
if (!version) {
|
|
34
|
+
const res = await fetch("https://raw.githubusercontent.com/learnpack/ide/master/package.json");
|
|
35
|
+
const json = await res.json();
|
|
36
|
+
version = json.version;
|
|
37
|
+
if (!version)
|
|
38
|
+
throw errors_1.InternalError(`Coding Editor version was not found on learnpack repository, check the config.editor.version property on learn.json`);
|
|
39
|
+
}
|
|
40
|
+
const versionNumber = parseInt(version.split(".")[0]);
|
|
41
|
+
let url = `https://github.com/learnpack/coding-ide/blob/${version}/dist`;
|
|
42
|
+
if (versionNumber > 2)
|
|
43
|
+
url = `https://github.com/learnpack/ide/blob/master/bin/learnpack-${version}.tar.gz`;
|
|
44
|
+
const resp2 = await fetch(url, { method: "HEAD" });
|
|
45
|
+
if (!resp2.ok)
|
|
46
|
+
throw errors_1.InternalError(`Coding Editor ${version} was not found on learnpack repository, check the config.editor.version property on learn.json`);
|
|
47
|
+
console_1.default.info("Downloading the LearnPack coding UI, this may take a minute...");
|
|
48
|
+
url += versionNumber > 2 ? `?raw=true` : `/app.tar.gz?raw=true`;
|
|
49
|
+
return exports.download(url, destination);
|
|
50
|
+
};
|
|
51
|
+
exports.download = (url, dest) => {
|
|
52
|
+
console_1.default.debug("Downloading " + url);
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
const request = https.get(url, response => {
|
|
55
|
+
if (response.statusCode === 200) {
|
|
56
|
+
const file = fs.createWriteStream(dest, { flags: "wx" });
|
|
57
|
+
file.on("finish", () => {
|
|
58
|
+
resolve(true);
|
|
59
|
+
});
|
|
60
|
+
file.on("error", err => {
|
|
61
|
+
file.close();
|
|
62
|
+
if (err.code === "EEXIST") {
|
|
63
|
+
console_1.default.debug("File already exists");
|
|
64
|
+
resolve("File already exists");
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
console_1.default.debug("Error ", err.message);
|
|
68
|
+
fs.unlink(dest, () => reject(err.message)); // Delete temp file
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
response.pipe(file);
|
|
72
|
+
}
|
|
73
|
+
else if (response.statusCode === 302 || response.statusCode === 301) {
|
|
74
|
+
// Console.debug("Servers redirected to "+response.headers.location)
|
|
75
|
+
// Recursively follow redirects, only a 200 will resolve.
|
|
76
|
+
if (response.headers.location) {
|
|
77
|
+
exports.download(response.headers.location, dest)
|
|
78
|
+
.then(() => resolve(/* */ ""))
|
|
79
|
+
.catch(error => {
|
|
80
|
+
console_1.default.error(error);
|
|
81
|
+
reject(error);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
console_1.default.debug(`Server responded with ${response.statusCode}: ${response.statusMessage}`);
|
|
87
|
+
reject(`Server responded with ${response.statusCode}: ${response.statusMessage}`);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
request.on("error", err => {
|
|
91
|
+
reject(err.message);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
exports.clone = (repository = "", folder = "./") => new Promise((resolve, reject) => {
|
|
96
|
+
if (!repository) {
|
|
97
|
+
reject("Missing repository url for this package");
|
|
98
|
+
// return false
|
|
99
|
+
}
|
|
100
|
+
cli_ux_1.cli.action.start("Verifying GIT...");
|
|
101
|
+
if (!shell.which("git")) {
|
|
102
|
+
reject("Sorry, this script requires git");
|
|
103
|
+
// return false
|
|
104
|
+
}
|
|
105
|
+
cli_ux_1.cli.action.stop();
|
|
106
|
+
let fileName = p.basename(repository);
|
|
107
|
+
if (!fileName) {
|
|
108
|
+
reject("Invalid repository information on package: " + repository);
|
|
109
|
+
// return false
|
|
110
|
+
}
|
|
111
|
+
fileName = fileName.split(".")[0];
|
|
112
|
+
if (fs.existsSync("./" + fileName)) {
|
|
113
|
+
reject(`Directory ${fileName} already exists; Did you download this package already?`);
|
|
114
|
+
// return false
|
|
115
|
+
}
|
|
116
|
+
cli_ux_1.cli.action.start(`Cloning repository ${repository}...`);
|
|
117
|
+
if (shell.exec(`git clone ${repository}`).code !== 0) {
|
|
118
|
+
reject("Error: Installation failed");
|
|
119
|
+
}
|
|
120
|
+
cli_ux_1.cli.action.stop();
|
|
121
|
+
cli_ux_1.cli.action.start("Cleaning installation...");
|
|
122
|
+
if (shell.exec(`rm -R -f ${folder}${fileName}/.git`).code !== 0) {
|
|
123
|
+
reject("Error: removing .git directory");
|
|
124
|
+
}
|
|
125
|
+
cli_ux_1.cli.action.stop();
|
|
126
|
+
resolve("Done");
|
|
127
|
+
});
|
|
128
|
+
exports.rmSync = function (path) {
|
|
129
|
+
let files = [];
|
|
130
|
+
if (fs.existsSync(path)) {
|
|
131
|
+
files = fs.readdirSync(path);
|
|
132
|
+
for (const [, file] of files.entries()) {
|
|
133
|
+
const curPath = path + "/" + file;
|
|
134
|
+
if (fs.lstatSync(curPath).isDirectory()) {
|
|
135
|
+
// recurse
|
|
136
|
+
exports.rmSync(curPath);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
// delete file
|
|
140
|
+
fs.unlinkSync(curPath);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
fs.rmdirSync(path);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
exports.checkIfDirectoryExists = (path) => {
|
|
147
|
+
const fs = require("fs");
|
|
148
|
+
if (fs.existsSync(path)) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
152
|
+
};
|
|
153
|
+
exports.default = { download: exports.download, decompress: exports.decompress, downloadEditor: exports.downloadEditor, clone: exports.clone, rmSync: exports.rmSync };
|
package/lib/managers/gitpod.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IGitpod } from '../models/gitpod-data';
|
|
2
|
-
declare const Gitpod: IGitpod;
|
|
3
|
-
export default Gitpod;
|
|
1
|
+
import { IGitpod } from '../models/gitpod-data';
|
|
2
|
+
declare const Gitpod: IGitpod;
|
|
3
|
+
export default Gitpod;
|
package/lib/managers/gitpod.js
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
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
|
+
"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 +1,6 @@
|
|
|
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
|
+
/// <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 +1,58 @@
|
|
|
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) === "preview")
|
|
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
|
+
"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) === "preview")
|
|
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 +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>;
|