@learnpack/learnpack 2.1.39 → 2.1.40
Sign up to get free protection for your applications and to get access to all the features.
- 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/src/managers/file.ts
CHANGED
@@ -1,196 +1,196 @@
|
|
1
|
-
import * as fs from "fs"
|
2
|
-
import * as p from "path"
|
3
|
-
import * as shell from "shelljs"
|
4
|
-
import { cli } from "cli-ux"
|
5
|
-
import * as targz from "targz"
|
6
|
-
import Console from "../utils/console"
|
7
|
-
import * as https from "https"
|
8
|
-
import { InternalError } from "../utils/errors"
|
9
|
-
|
10
|
-
// eslint-disable-next-line
|
11
|
-
const fetch = require("node-fetch");
|
12
|
-
|
13
|
-
export const decompress = (sourcePath: string, destinationPath: string) =>
|
14
|
-
new Promise((resolve, reject) => {
|
15
|
-
Console.debug("Decompressing " + sourcePath)
|
16
|
-
targz.decompress(
|
17
|
-
{
|
18
|
-
src: sourcePath,
|
19
|
-
dest: destinationPath,
|
20
|
-
},
|
21
|
-
function (err: string | Error | null) {
|
22
|
-
if (err) {
|
23
|
-
Console.error("Error when trying to decompress")
|
24
|
-
reject(err)
|
25
|
-
} else {
|
26
|
-
Console.info("Decompression finished successfully")
|
27
|
-
resolve(/* */ "")
|
28
|
-
}
|
29
|
-
}
|
30
|
-
)
|
31
|
-
})
|
32
|
-
|
33
|
-
export const downloadEditor = async (
|
34
|
-
version: string | undefined,
|
35
|
-
destination: string
|
36
|
-
) => {
|
37
|
-
// https://raw.githubusercontent.com/learnpack/coding-ide/master/dist/app.tar.gz
|
38
|
-
// if(versions[version] === undefined) throw new Error(`Invalid editor version ${version}`)
|
39
|
-
|
40
|
-
if (!version) {
|
41
|
-
const res = await fetch(
|
42
|
-
"https://raw.githubusercontent.com/learnpack/ide/master/package.json"
|
43
|
-
)
|
44
|
-
const json = await res.json()
|
45
|
-
version = json.version
|
46
|
-
|
47
|
-
if (!version)
|
48
|
-
throw InternalError(
|
49
|
-
`Coding Editor version was not found on learnpack repository, check the config.editor.version property on learn.json`
|
50
|
-
)
|
51
|
-
}
|
52
|
-
|
53
|
-
const versionNumber = parseInt(version.split(".")[0])
|
54
|
-
|
55
|
-
let url = `https://github.com/learnpack/coding-ide/blob/${version}/dist`
|
56
|
-
|
57
|
-
if (versionNumber > 2)
|
58
|
-
url = `https://github.com/learnpack/ide/blob/master/bin/learnpack-${version}.tar.gz`
|
59
|
-
|
60
|
-
const resp2 = await fetch(url, { method: "HEAD" })
|
61
|
-
if (!resp2.ok)
|
62
|
-
throw InternalError(
|
63
|
-
`Coding Editor ${version} was not found on learnpack repository, check the config.editor.version property on learn.json`
|
64
|
-
)
|
65
|
-
|
66
|
-
Console.info(
|
67
|
-
"Downloading the LearnPack coding UI, this may take a minute..."
|
68
|
-
)
|
69
|
-
|
70
|
-
url += versionNumber > 2 ? `?raw=true` : `/app.tar.gz?raw=true`
|
71
|
-
|
72
|
-
return download(url, destination)
|
73
|
-
}
|
74
|
-
|
75
|
-
export const download = (url: string, dest: string) => {
|
76
|
-
Console.debug("Downloading " + url)
|
77
|
-
return new Promise((resolve, reject) => {
|
78
|
-
const request = https.get(url, response => {
|
79
|
-
if (response.statusCode === 200) {
|
80
|
-
const file = fs.createWriteStream(dest, { flags: "wx" })
|
81
|
-
file.on("finish", () => {
|
82
|
-
resolve(true)
|
83
|
-
})
|
84
|
-
file.on("error", err => {
|
85
|
-
file.close()
|
86
|
-
if (err.code === "EEXIST") {
|
87
|
-
Console.debug("File already exists")
|
88
|
-
resolve("File already exists")
|
89
|
-
} else {
|
90
|
-
Console.debug("Error ", err.message)
|
91
|
-
fs.unlink(dest, () => reject(err.message)) // Delete temp file
|
92
|
-
}
|
93
|
-
})
|
94
|
-
response.pipe(file)
|
95
|
-
} else if (response.statusCode === 302 || response.statusCode === 301) {
|
96
|
-
// Console.debug("Servers redirected to "+response.headers.location)
|
97
|
-
// Recursively follow redirects, only a 200 will resolve.
|
98
|
-
if (response.headers.location) {
|
99
|
-
download(response.headers.location, dest)
|
100
|
-
.then(() => resolve(/* */ ""))
|
101
|
-
.catch(error => {
|
102
|
-
Console.error(error)
|
103
|
-
reject(error)
|
104
|
-
})
|
105
|
-
}
|
106
|
-
} else {
|
107
|
-
Console.debug(
|
108
|
-
`Server responded with ${response.statusCode}: ${response.statusMessage}`
|
109
|
-
)
|
110
|
-
reject(
|
111
|
-
`Server responded with ${response.statusCode}: ${response.statusMessage}`
|
112
|
-
)
|
113
|
-
}
|
114
|
-
})
|
115
|
-
|
116
|
-
request.on("error", err => {
|
117
|
-
reject(err.message)
|
118
|
-
})
|
119
|
-
})
|
120
|
-
}
|
121
|
-
|
122
|
-
export const clone = (repository = "", folder = "./") =>
|
123
|
-
new Promise((resolve, reject) => {
|
124
|
-
if (!repository) {
|
125
|
-
reject("Missing repository url for this package")
|
126
|
-
// return false
|
127
|
-
}
|
128
|
-
|
129
|
-
cli.action.start("Verifying GIT...")
|
130
|
-
if (!shell.which("git")) {
|
131
|
-
reject("Sorry, this script requires git")
|
132
|
-
// return false
|
133
|
-
}
|
134
|
-
|
135
|
-
cli.action.stop()
|
136
|
-
|
137
|
-
let fileName = p.basename(repository)
|
138
|
-
if (!fileName) {
|
139
|
-
reject("Invalid repository information on package: " + repository)
|
140
|
-
// return false
|
141
|
-
}
|
142
|
-
|
143
|
-
fileName = fileName.split(".")[0]
|
144
|
-
if (fs.existsSync("./" + fileName)) {
|
145
|
-
reject(
|
146
|
-
`Directory ${fileName} already exists; Did you download this package already?`
|
147
|
-
)
|
148
|
-
// return false
|
149
|
-
}
|
150
|
-
|
151
|
-
cli.action.start(`Cloning repository ${repository}...`)
|
152
|
-
if (shell.exec(`git clone ${repository}`).code !== 0) {
|
153
|
-
reject("Error: Installation failed")
|
154
|
-
}
|
155
|
-
|
156
|
-
cli.action.stop()
|
157
|
-
|
158
|
-
cli.action.start("Cleaning installation...")
|
159
|
-
if (shell.exec(`rm -R -f ${folder}${fileName}/.git`).code !== 0) {
|
160
|
-
reject("Error: removing .git directory")
|
161
|
-
}
|
162
|
-
|
163
|
-
cli.action.stop()
|
164
|
-
|
165
|
-
resolve("Done")
|
166
|
-
})
|
167
|
-
|
168
|
-
export const rmSync = function (path: string) {
|
169
|
-
let files = []
|
170
|
-
if (fs.existsSync(path)) {
|
171
|
-
files = fs.readdirSync(path)
|
172
|
-
for (const [, file] of files.entries()) {
|
173
|
-
const curPath = path + "/" + file
|
174
|
-
if (fs.lstatSync(curPath).isDirectory()) {
|
175
|
-
// recurse
|
176
|
-
rmSync(curPath)
|
177
|
-
} else {
|
178
|
-
// delete file
|
179
|
-
fs.unlinkSync(curPath)
|
180
|
-
}
|
181
|
-
}
|
182
|
-
|
183
|
-
fs.rmdirSync(path)
|
184
|
-
}
|
185
|
-
}
|
186
|
-
|
187
|
-
export const checkIfDirectoryExists = (path: string) => {
|
188
|
-
const fs = require("fs")
|
189
|
-
if (fs.existsSync(path)) {
|
190
|
-
return true
|
191
|
-
}
|
192
|
-
|
193
|
-
return false
|
194
|
-
}
|
195
|
-
|
196
|
-
export default { download, decompress, downloadEditor, clone, rmSync }
|
1
|
+
import * as fs from "fs"
|
2
|
+
import * as p from "path"
|
3
|
+
import * as shell from "shelljs"
|
4
|
+
import { cli } from "cli-ux"
|
5
|
+
import * as targz from "targz"
|
6
|
+
import Console from "../utils/console"
|
7
|
+
import * as https from "https"
|
8
|
+
import { InternalError } from "../utils/errors"
|
9
|
+
|
10
|
+
// eslint-disable-next-line
|
11
|
+
const fetch = require("node-fetch");
|
12
|
+
|
13
|
+
export const decompress = (sourcePath: string, destinationPath: string) =>
|
14
|
+
new Promise((resolve, reject) => {
|
15
|
+
Console.debug("Decompressing " + sourcePath)
|
16
|
+
targz.decompress(
|
17
|
+
{
|
18
|
+
src: sourcePath,
|
19
|
+
dest: destinationPath,
|
20
|
+
},
|
21
|
+
function (err: string | Error | null) {
|
22
|
+
if (err) {
|
23
|
+
Console.error("Error when trying to decompress")
|
24
|
+
reject(err)
|
25
|
+
} else {
|
26
|
+
Console.info("Decompression finished successfully")
|
27
|
+
resolve(/* */ "")
|
28
|
+
}
|
29
|
+
}
|
30
|
+
)
|
31
|
+
})
|
32
|
+
|
33
|
+
export const downloadEditor = async (
|
34
|
+
version: string | undefined,
|
35
|
+
destination: string
|
36
|
+
) => {
|
37
|
+
// https://raw.githubusercontent.com/learnpack/coding-ide/master/dist/app.tar.gz
|
38
|
+
// if(versions[version] === undefined) throw new Error(`Invalid editor version ${version}`)
|
39
|
+
|
40
|
+
if (!version) {
|
41
|
+
const res = await fetch(
|
42
|
+
"https://raw.githubusercontent.com/learnpack/ide/master/package.json"
|
43
|
+
)
|
44
|
+
const json = await res.json()
|
45
|
+
version = json.version
|
46
|
+
|
47
|
+
if (!version)
|
48
|
+
throw InternalError(
|
49
|
+
`Coding Editor version was not found on learnpack repository, check the config.editor.version property on learn.json`
|
50
|
+
)
|
51
|
+
}
|
52
|
+
|
53
|
+
const versionNumber = parseInt(version.split(".")[0])
|
54
|
+
|
55
|
+
let url = `https://github.com/learnpack/coding-ide/blob/${version}/dist`
|
56
|
+
|
57
|
+
if (versionNumber > 2)
|
58
|
+
url = `https://github.com/learnpack/ide/blob/master/bin/learnpack-${version}.tar.gz`
|
59
|
+
|
60
|
+
const resp2 = await fetch(url, { method: "HEAD" })
|
61
|
+
if (!resp2.ok)
|
62
|
+
throw InternalError(
|
63
|
+
`Coding Editor ${version} was not found on learnpack repository, check the config.editor.version property on learn.json`
|
64
|
+
)
|
65
|
+
|
66
|
+
Console.info(
|
67
|
+
"Downloading the LearnPack coding UI, this may take a minute..."
|
68
|
+
)
|
69
|
+
|
70
|
+
url += versionNumber > 2 ? `?raw=true` : `/app.tar.gz?raw=true`
|
71
|
+
|
72
|
+
return download(url, destination)
|
73
|
+
}
|
74
|
+
|
75
|
+
export const download = (url: string, dest: string) => {
|
76
|
+
Console.debug("Downloading " + url)
|
77
|
+
return new Promise((resolve, reject) => {
|
78
|
+
const request = https.get(url, response => {
|
79
|
+
if (response.statusCode === 200) {
|
80
|
+
const file = fs.createWriteStream(dest, { flags: "wx" })
|
81
|
+
file.on("finish", () => {
|
82
|
+
resolve(true)
|
83
|
+
})
|
84
|
+
file.on("error", err => {
|
85
|
+
file.close()
|
86
|
+
if (err.code === "EEXIST") {
|
87
|
+
Console.debug("File already exists")
|
88
|
+
resolve("File already exists")
|
89
|
+
} else {
|
90
|
+
Console.debug("Error ", err.message)
|
91
|
+
fs.unlink(dest, () => reject(err.message)) // Delete temp file
|
92
|
+
}
|
93
|
+
})
|
94
|
+
response.pipe(file)
|
95
|
+
} else if (response.statusCode === 302 || response.statusCode === 301) {
|
96
|
+
// Console.debug("Servers redirected to "+response.headers.location)
|
97
|
+
// Recursively follow redirects, only a 200 will resolve.
|
98
|
+
if (response.headers.location) {
|
99
|
+
download(response.headers.location, dest)
|
100
|
+
.then(() => resolve(/* */ ""))
|
101
|
+
.catch(error => {
|
102
|
+
Console.error(error)
|
103
|
+
reject(error)
|
104
|
+
})
|
105
|
+
}
|
106
|
+
} else {
|
107
|
+
Console.debug(
|
108
|
+
`Server responded with ${response.statusCode}: ${response.statusMessage}`
|
109
|
+
)
|
110
|
+
reject(
|
111
|
+
`Server responded with ${response.statusCode}: ${response.statusMessage}`
|
112
|
+
)
|
113
|
+
}
|
114
|
+
})
|
115
|
+
|
116
|
+
request.on("error", err => {
|
117
|
+
reject(err.message)
|
118
|
+
})
|
119
|
+
})
|
120
|
+
}
|
121
|
+
|
122
|
+
export const clone = (repository = "", folder = "./") =>
|
123
|
+
new Promise((resolve, reject) => {
|
124
|
+
if (!repository) {
|
125
|
+
reject("Missing repository url for this package")
|
126
|
+
// return false
|
127
|
+
}
|
128
|
+
|
129
|
+
cli.action.start("Verifying GIT...")
|
130
|
+
if (!shell.which("git")) {
|
131
|
+
reject("Sorry, this script requires git")
|
132
|
+
// return false
|
133
|
+
}
|
134
|
+
|
135
|
+
cli.action.stop()
|
136
|
+
|
137
|
+
let fileName = p.basename(repository)
|
138
|
+
if (!fileName) {
|
139
|
+
reject("Invalid repository information on package: " + repository)
|
140
|
+
// return false
|
141
|
+
}
|
142
|
+
|
143
|
+
fileName = fileName.split(".")[0]
|
144
|
+
if (fs.existsSync("./" + fileName)) {
|
145
|
+
reject(
|
146
|
+
`Directory ${fileName} already exists; Did you download this package already?`
|
147
|
+
)
|
148
|
+
// return false
|
149
|
+
}
|
150
|
+
|
151
|
+
cli.action.start(`Cloning repository ${repository}...`)
|
152
|
+
if (shell.exec(`git clone ${repository}`).code !== 0) {
|
153
|
+
reject("Error: Installation failed")
|
154
|
+
}
|
155
|
+
|
156
|
+
cli.action.stop()
|
157
|
+
|
158
|
+
cli.action.start("Cleaning installation...")
|
159
|
+
if (shell.exec(`rm -R -f ${folder}${fileName}/.git`).code !== 0) {
|
160
|
+
reject("Error: removing .git directory")
|
161
|
+
}
|
162
|
+
|
163
|
+
cli.action.stop()
|
164
|
+
|
165
|
+
resolve("Done")
|
166
|
+
})
|
167
|
+
|
168
|
+
export const rmSync = function (path: string) {
|
169
|
+
let files = []
|
170
|
+
if (fs.existsSync(path)) {
|
171
|
+
files = fs.readdirSync(path)
|
172
|
+
for (const [, file] of files.entries()) {
|
173
|
+
const curPath = path + "/" + file
|
174
|
+
if (fs.lstatSync(curPath).isDirectory()) {
|
175
|
+
// recurse
|
176
|
+
rmSync(curPath)
|
177
|
+
} else {
|
178
|
+
// delete file
|
179
|
+
fs.unlinkSync(curPath)
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
fs.rmdirSync(path)
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
export const checkIfDirectoryExists = (path: string) => {
|
188
|
+
const fs = require("fs")
|
189
|
+
if (fs.existsSync(path)) {
|
190
|
+
return true
|
191
|
+
}
|
192
|
+
|
193
|
+
return false
|
194
|
+
}
|
195
|
+
|
196
|
+
export default { download, decompress, downloadEditor, clone, rmSync }
|
package/src/managers/gitpod.ts
CHANGED
@@ -1,84 +1,84 @@
|
|
1
|
-
import Console from '../utils/console'
|
2
|
-
import * as shell from 'shelljs'
|
3
|
-
import socket from './socket'
|
4
|
-
import * as fs from 'fs'
|
5
|
-
|
6
|
-
import {TFile, IGitpod} from '../models/gitpod-data'
|
7
|
-
import {IConfigObj} from '../models/config'
|
8
|
-
|
9
|
-
const Gitpod: IGitpod = {
|
10
|
-
socket: null,
|
11
|
-
config: null,
|
12
|
-
initialized: false,
|
13
|
-
hasGPCommand: false,
|
14
|
-
init: function (config?: IConfigObj) {
|
15
|
-
if (this.initialized) {
|
16
|
-
return
|
17
|
-
}
|
18
|
-
|
19
|
-
this.initialized = true
|
20
|
-
|
21
|
-
if (config) {
|
22
|
-
this.config = config
|
23
|
-
}
|
24
|
-
|
25
|
-
if (shell.exec('gp -h', {silent: true}).code === 0) {
|
26
|
-
this.hasGPCommand = true
|
27
|
-
if (config) {
|
28
|
-
config.address = shell
|
29
|
-
.exec('gp url', {silent: true})
|
30
|
-
.stdout.replace(/(\r\n|\n|\r)/gm, '')
|
31
|
-
}
|
32
|
-
} else {
|
33
|
-
Console.debug('Gitpod command line tool not found')
|
34
|
-
}
|
35
|
-
},
|
36
|
-
openFiles: async function (files: Array<TFile>) {
|
37
|
-
Console.debug('Attempting to open files in gitpod mode', files)
|
38
|
-
this.init() // initilize gitpod config
|
39
|
-
|
40
|
-
// gitpod will open files only on isolated mode
|
41
|
-
if (!this.config || this.config.config?.grading !== 'isolated') {
|
42
|
-
Console.debug(
|
43
|
-
'Files cannot be automatically opened because we are not on isolated grading (only for isolated)',
|
44
|
-
)
|
45
|
-
socket.log('ready', ['Ready to compile or test...'])
|
46
|
-
return true
|
47
|
-
}
|
48
|
-
|
49
|
-
if (this.hasGPCommand)
|
50
|
-
for (const f of files.reverse()) {
|
51
|
-
if (shell.exec(`gp open ${f}`).code > 0) {
|
52
|
-
Console.debug(`Error opening file ${f} on gitpod`)
|
53
|
-
}
|
54
|
-
}
|
55
|
-
|
56
|
-
socket.log('ready', ['Ready to compile or test...'])
|
57
|
-
},
|
58
|
-
setup(config?: IConfigObj) {
|
59
|
-
this.init(config) // initilize gitpod config
|
60
|
-
this.autosave('on')
|
61
|
-
},
|
62
|
-
autosave: async function (value = 'on') {
|
63
|
-
this.init() // initilize gitpod config
|
64
|
-
|
65
|
-
if (this.hasGPCommand) {
|
66
|
-
if (!fs.existsSync('./.theia'))
|
67
|
-
fs.mkdirSync('./.theia')
|
68
|
-
if (!fs.existsSync('./.theia/settings.json')) {
|
69
|
-
fs.writeFileSync(
|
70
|
-
'./.theia/settings.json',
|
71
|
-
JSON.stringify(
|
72
|
-
{
|
73
|
-
'editor.autoSave': value,
|
74
|
-
},
|
75
|
-
null,
|
76
|
-
4,
|
77
|
-
),
|
78
|
-
)
|
79
|
-
}
|
80
|
-
}
|
81
|
-
},
|
82
|
-
}
|
83
|
-
|
84
|
-
export default Gitpod
|
1
|
+
import Console from '../utils/console'
|
2
|
+
import * as shell from 'shelljs'
|
3
|
+
import socket from './socket'
|
4
|
+
import * as fs from 'fs'
|
5
|
+
|
6
|
+
import {TFile, IGitpod} from '../models/gitpod-data'
|
7
|
+
import {IConfigObj} from '../models/config'
|
8
|
+
|
9
|
+
const Gitpod: IGitpod = {
|
10
|
+
socket: null,
|
11
|
+
config: null,
|
12
|
+
initialized: false,
|
13
|
+
hasGPCommand: false,
|
14
|
+
init: function (config?: IConfigObj) {
|
15
|
+
if (this.initialized) {
|
16
|
+
return
|
17
|
+
}
|
18
|
+
|
19
|
+
this.initialized = true
|
20
|
+
|
21
|
+
if (config) {
|
22
|
+
this.config = config
|
23
|
+
}
|
24
|
+
|
25
|
+
if (shell.exec('gp -h', {silent: true}).code === 0) {
|
26
|
+
this.hasGPCommand = true
|
27
|
+
if (config) {
|
28
|
+
config.address = shell
|
29
|
+
.exec('gp url', {silent: true})
|
30
|
+
.stdout.replace(/(\r\n|\n|\r)/gm, '')
|
31
|
+
}
|
32
|
+
} else {
|
33
|
+
Console.debug('Gitpod command line tool not found')
|
34
|
+
}
|
35
|
+
},
|
36
|
+
openFiles: async function (files: Array<TFile>) {
|
37
|
+
Console.debug('Attempting to open files in gitpod mode', files)
|
38
|
+
this.init() // initilize gitpod config
|
39
|
+
|
40
|
+
// gitpod will open files only on isolated mode
|
41
|
+
if (!this.config || this.config.config?.grading !== 'isolated') {
|
42
|
+
Console.debug(
|
43
|
+
'Files cannot be automatically opened because we are not on isolated grading (only for isolated)',
|
44
|
+
)
|
45
|
+
socket.log('ready', ['Ready to compile or test...'])
|
46
|
+
return true
|
47
|
+
}
|
48
|
+
|
49
|
+
if (this.hasGPCommand)
|
50
|
+
for (const f of files.reverse()) {
|
51
|
+
if (shell.exec(`gp open ${f}`).code > 0) {
|
52
|
+
Console.debug(`Error opening file ${f} on gitpod`)
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
socket.log('ready', ['Ready to compile or test...'])
|
57
|
+
},
|
58
|
+
setup(config?: IConfigObj) {
|
59
|
+
this.init(config) // initilize gitpod config
|
60
|
+
this.autosave('on')
|
61
|
+
},
|
62
|
+
autosave: async function (value = 'on') {
|
63
|
+
this.init() // initilize gitpod config
|
64
|
+
|
65
|
+
if (this.hasGPCommand) {
|
66
|
+
if (!fs.existsSync('./.theia'))
|
67
|
+
fs.mkdirSync('./.theia')
|
68
|
+
if (!fs.existsSync('./.theia/settings.json')) {
|
69
|
+
fs.writeFileSync(
|
70
|
+
'./.theia/settings.json',
|
71
|
+
JSON.stringify(
|
72
|
+
{
|
73
|
+
'editor.autoSave': value,
|
74
|
+
},
|
75
|
+
null,
|
76
|
+
4,
|
77
|
+
),
|
78
|
+
)
|
79
|
+
}
|
80
|
+
}
|
81
|
+
},
|
82
|
+
}
|
83
|
+
|
84
|
+
export default Gitpod
|