@learnpack/learnpack 4.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +10 -10
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/src/managers/file.ts +212 -212
package/README.md
CHANGED
@@ -21,7 +21,7 @@ $ npm install -g @learnpack/learnpack
|
|
21
21
|
$ learnpack COMMAND
|
22
22
|
running command...
|
23
23
|
$ learnpack (-v|--version|version)
|
24
|
-
@learnpack/learnpack/4.0.
|
24
|
+
@learnpack/learnpack/4.0.1 win32-x64 node-v20.10.0
|
25
25
|
$ learnpack --help [COMMAND]
|
26
26
|
USAGE
|
27
27
|
$ learnpack COMMAND
|
@@ -74,7 +74,7 @@ DESCRIPTION
|
|
74
74
|
12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)
|
75
75
|
```
|
76
76
|
|
77
|
-
_See code: [src\commands\audit.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.
|
77
|
+
_See code: [src\commands\audit.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.1/src\commands\audit.ts)_
|
78
78
|
|
79
79
|
## `learnpack clean`
|
80
80
|
|
@@ -89,7 +89,7 @@ DESCRIPTION
|
|
89
89
|
Extra documentation goes here
|
90
90
|
```
|
91
91
|
|
92
|
-
_See code: [src\commands\clean.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.
|
92
|
+
_See code: [src\commands\clean.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.1/src\commands\clean.ts)_
|
93
93
|
|
94
94
|
## `learnpack download [PACKAGE]`
|
95
95
|
|
@@ -107,7 +107,7 @@ DESCRIPTION
|
|
107
107
|
Extra documentation goes here
|
108
108
|
```
|
109
109
|
|
110
|
-
_See code: [src\commands\download.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.
|
110
|
+
_See code: [src\commands\download.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.1/src\commands\download.ts)_
|
111
111
|
|
112
112
|
## `learnpack help [COMMAND]`
|
113
113
|
|
@@ -138,7 +138,7 @@ OPTIONS
|
|
138
138
|
-h, --grading show CLI help
|
139
139
|
```
|
140
140
|
|
141
|
-
_See code: [src\commands\init.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.
|
141
|
+
_See code: [src\commands\init.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.1/src\commands\init.ts)_
|
142
142
|
|
143
143
|
## `learnpack login [PACKAGE]`
|
144
144
|
|
@@ -156,7 +156,7 @@ DESCRIPTION
|
|
156
156
|
Extra documentation goes here
|
157
157
|
```
|
158
158
|
|
159
|
-
_See code: [src\commands\login.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.
|
159
|
+
_See code: [src\commands\login.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.1/src\commands\login.ts)_
|
160
160
|
|
161
161
|
## `learnpack logout [PACKAGE]`
|
162
162
|
|
@@ -174,7 +174,7 @@ DESCRIPTION
|
|
174
174
|
Extra documentation goes here
|
175
175
|
```
|
176
176
|
|
177
|
-
_See code: [src\commands\logout.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.
|
177
|
+
_See code: [src\commands\logout.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.1/src\commands\logout.ts)_
|
178
178
|
|
179
179
|
## `learnpack plugins`
|
180
180
|
|
@@ -309,7 +309,7 @@ DESCRIPTION
|
|
309
309
|
Extra documentation goes here
|
310
310
|
```
|
311
311
|
|
312
|
-
_See code: [src\commands\publish.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.
|
312
|
+
_See code: [src\commands\publish.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.1/src\commands\publish.ts)_
|
313
313
|
|
314
314
|
## `learnpack start`
|
315
315
|
|
@@ -330,7 +330,7 @@ OPTIONS
|
|
330
330
|
-w, --watch Watch for file changes
|
331
331
|
```
|
332
332
|
|
333
|
-
_See code: [src\commands\start.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.
|
333
|
+
_See code: [src\commands\start.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.1/src\commands\start.ts)_
|
334
334
|
|
335
335
|
## `learnpack test [EXERCISESLUG]`
|
336
336
|
|
@@ -344,7 +344,7 @@ ARGUMENTS
|
|
344
344
|
EXERCISESLUG The name of the exercise to test
|
345
345
|
```
|
346
346
|
|
347
|
-
_See code: [src\commands\test.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.
|
347
|
+
_See code: [src\commands\test.ts](https://github.com/learnpack/learnpack-cli/blob/v4.0.1/src\commands\test.ts)_
|
348
348
|
<!-- commandsstop -->
|
349
349
|
|
350
350
|
> > > > > > > 0cb3e56d84c197f9d008836bb573eade212b7e57
|
package/oclif.manifest.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":"4.0.
|
1
|
+
{"version":"4.0.1","commands":{"audit":{"id":"audit","description":"learnpack audit is the command in charge of creating an auditory of the repository\n...\nlearnpack audit checks for the following information in a repository:\n 1. The configuration object has slug, repository and description. (Error)\n 2. The command learnpack clean has been run. (Error)\n 3. If a markdown or test file doesn't have any content. (Error)\n 4. The links are accessing to valid servers. (Error)\n 5. The relative images are working (If they have the shortest path to the image or if the images exists in the assets). (Error)\n 6. The external images are working (If they are pointing to a valid server). (Error)\n 7. The exercises directory names are valid. (Error)\n 8. If an exercise doesn't have a README file. (Error)\n 9. The exercises array (Of the config file) has content. (Error)\n 10. The exercses have the same translations. (Warning)\n 11. The .gitignore file exists. (Warning)\n 12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[]},"clean":{"id":"clean","description":"Clean the configuration object\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[]},"download":{"id":"download","description":"Describe the command here\n...\nExtra documentation goes here\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"init":{"id":"init","description":"Create a new learning package: Book, Tutorial or Exercise","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"grading":{"name":"grading","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"login":{"id":"login","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"logout":{"id":"logout","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"publish":{"id":"publish","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"start":{"id":"start","description":"Runs a small server with all the exercise instructions","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"port":{"name":"port","type":"option","char":"p","description":"server port"},"host":{"name":"host","type":"option","char":"h","description":"server host"},"disableGrading":{"name":"disableGrading","type":"boolean","char":"D","description":"disble grading functionality","allowNo":false},"watch":{"name":"watch","type":"boolean","char":"w","description":"Watch for file changes","allowNo":false},"editor":{"name":"editor","type":"option","char":"e","description":"[preview, extension]","options":["extension","preview"]},"version":{"name":"version","type":"option","char":"v","description":"E.g: 1.0.1"},"grading":{"name":"grading","type":"option","char":"g","description":"[isolated, incremental]","options":["isolated","incremental"]},"debug":{"name":"debug","type":"boolean","char":"d","description":"debugger mode for more verbage","allowNo":false}},"args":[]},"test":{"id":"test","description":"Test exercises","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"exerciseSlug","description":"The name of the exercise to test","required":false,"hidden":false}]}}}
|
package/package.json
CHANGED
package/src/managers/file.ts
CHANGED
@@ -1,212 +1,212 @@
|
|
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
|
-
if (!version) {
|
38
|
-
const res = await fetch(
|
39
|
-
"https://raw.githubusercontent.com/learnpack/ide/master/package.json"
|
40
|
-
)
|
41
|
-
const json = await res.json()
|
42
|
-
version = json.version || "4.0.0"
|
43
|
-
|
44
|
-
if (!version)
|
45
|
-
throw InternalError(
|
46
|
-
`Coding Editor version was not found on learnpack repository, check the config.editor.version property on learn.json`
|
47
|
-
)
|
48
|
-
}
|
49
|
-
|
50
|
-
const [major, minor] = version.split(".")
|
51
|
-
const versionPrefix = `${major}.${minor}`
|
52
|
-
|
53
|
-
const tagsRes = await fetch(
|
54
|
-
"https://api.github.com/repos/learnpack/ide/contents/bin"
|
55
|
-
)
|
56
|
-
const tags = await tagsRes.json()
|
57
|
-
const matchingTags = tags
|
58
|
-
.filter((tag: any) => tag.name.includes(versionPrefix))
|
59
|
-
.sort((a: any, b: any) =>
|
60
|
-
b.name.localeCompare(a.name, undefined, { numeric: true })
|
61
|
-
)
|
62
|
-
|
63
|
-
if (matchingTags.length === 0)
|
64
|
-
throw InternalError(
|
65
|
-
`No matching version found for prefix ${versionPrefix} in the learnpack repository`
|
66
|
-
)
|
67
|
-
|
68
|
-
const latestVersion = matchingTags[0].name
|
69
|
-
.replace("learnpack-", "")
|
70
|
-
.replace(".tar.gz", "")
|
71
|
-
const versionNumber = parseInt(latestVersion.split(".")[0])
|
72
|
-
|
73
|
-
let url = `https://github.com/learnpack/coding-ide/blob/${latestVersion}/dist`
|
74
|
-
|
75
|
-
if (versionNumber > 2)
|
76
|
-
url = `https://github.com/learnpack/ide/blob/master/bin/learnpack-${latestVersion}.tar.gz`
|
77
|
-
|
78
|
-
const resp2 = await fetch(url, { method: "HEAD" })
|
79
|
-
if (!resp2.ok)
|
80
|
-
throw InternalError(
|
81
|
-
`Coding Editor ${latestVersion} was not found on learnpack repository, check the config.editor.version property on learn.json`
|
82
|
-
)
|
83
|
-
|
84
|
-
Console.info("Downloading the LearnPack coding UI, this may take a minute...")
|
85
|
-
|
86
|
-
url += versionNumber > 2 ? `?raw=true` : `/app.tar.gz?raw=true`
|
87
|
-
|
88
|
-
return download(url, destination)
|
89
|
-
}
|
90
|
-
|
91
|
-
export const download = (url: string, dest: string) => {
|
92
|
-
Console.debug("Downloading " + url)
|
93
|
-
return new Promise((resolve, reject) => {
|
94
|
-
const request = https.get(url, response => {
|
95
|
-
if (response.statusCode === 200) {
|
96
|
-
const file = fs.createWriteStream(dest, { flags: "wx" })
|
97
|
-
file.on("finish", () => {
|
98
|
-
resolve(true)
|
99
|
-
})
|
100
|
-
file.on("error", err => {
|
101
|
-
file.close()
|
102
|
-
if (err.code === "EEXIST") {
|
103
|
-
Console.debug("File already exists")
|
104
|
-
resolve("File already exists")
|
105
|
-
} else {
|
106
|
-
Console.debug("Error ", err.message)
|
107
|
-
fs.unlink(dest, () => reject(err.message)) // Delete temp file
|
108
|
-
}
|
109
|
-
})
|
110
|
-
response.pipe(file)
|
111
|
-
} else if (response.statusCode === 302 || response.statusCode === 301) {
|
112
|
-
// Console.debug("Servers redirected to "+response.headers.location)
|
113
|
-
// Recursively follow redirects, only a 200 will resolve.
|
114
|
-
if (response.headers.location) {
|
115
|
-
download(response.headers.location, dest)
|
116
|
-
.then(() => resolve(/* */ ""))
|
117
|
-
.catch(error => {
|
118
|
-
Console.error(error)
|
119
|
-
reject(error)
|
120
|
-
})
|
121
|
-
}
|
122
|
-
} else {
|
123
|
-
Console.debug(
|
124
|
-
`Server responded with ${response.statusCode}: ${response.statusMessage}`
|
125
|
-
)
|
126
|
-
reject(
|
127
|
-
`Server responded with ${response.statusCode}: ${response.statusMessage}`
|
128
|
-
)
|
129
|
-
}
|
130
|
-
})
|
131
|
-
|
132
|
-
request.on("error", err => {
|
133
|
-
reject(err.message)
|
134
|
-
})
|
135
|
-
})
|
136
|
-
}
|
137
|
-
|
138
|
-
export const clone = (repository = "", folder = "./") =>
|
139
|
-
new Promise((resolve, reject) => {
|
140
|
-
if (!repository) {
|
141
|
-
reject("Missing repository url for this package")
|
142
|
-
// return false
|
143
|
-
}
|
144
|
-
|
145
|
-
cli.action.start("Verifying GIT...")
|
146
|
-
if (!shell.which("git")) {
|
147
|
-
reject("Sorry, this script requires git")
|
148
|
-
// return false
|
149
|
-
}
|
150
|
-
|
151
|
-
cli.action.stop()
|
152
|
-
|
153
|
-
let fileName = p.basename(repository)
|
154
|
-
if (!fileName) {
|
155
|
-
reject("Invalid repository information on package: " + repository)
|
156
|
-
// return false
|
157
|
-
}
|
158
|
-
|
159
|
-
fileName = fileName.split(".")[0]
|
160
|
-
if (fs.existsSync("./" + fileName)) {
|
161
|
-
reject(
|
162
|
-
`Directory ${fileName} already exists; Did you download this package already?`
|
163
|
-
)
|
164
|
-
// return false
|
165
|
-
}
|
166
|
-
|
167
|
-
cli.action.start(`Cloning repository ${repository}...`)
|
168
|
-
if (shell.exec(`git clone ${repository}`).code !== 0) {
|
169
|
-
reject("Error: Installation failed")
|
170
|
-
}
|
171
|
-
|
172
|
-
cli.action.stop()
|
173
|
-
|
174
|
-
cli.action.start("Cleaning installation...")
|
175
|
-
if (shell.exec(`rm -R -f ${folder}${fileName}/.git`).code !== 0) {
|
176
|
-
reject("Error: removing .git directory")
|
177
|
-
}
|
178
|
-
|
179
|
-
cli.action.stop()
|
180
|
-
|
181
|
-
resolve("Done")
|
182
|
-
})
|
183
|
-
|
184
|
-
export const rmSync = function (path: string) {
|
185
|
-
let files = []
|
186
|
-
if (fs.existsSync(path)) {
|
187
|
-
files = fs.readdirSync(path)
|
188
|
-
for (const [, file] of files.entries()) {
|
189
|
-
const curPath = path + "/" + file
|
190
|
-
if (fs.lstatSync(curPath).isDirectory()) {
|
191
|
-
// recurse
|
192
|
-
rmSync(curPath)
|
193
|
-
} else {
|
194
|
-
// delete file
|
195
|
-
fs.unlinkSync(curPath)
|
196
|
-
}
|
197
|
-
}
|
198
|
-
|
199
|
-
fs.rmdirSync(path)
|
200
|
-
}
|
201
|
-
}
|
202
|
-
|
203
|
-
export const checkIfDirectoryExists = (path: string) => {
|
204
|
-
const fs = require("fs")
|
205
|
-
if (fs.existsSync(path)) {
|
206
|
-
return true
|
207
|
-
}
|
208
|
-
|
209
|
-
return false
|
210
|
-
}
|
211
|
-
|
212
|
-
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
|
+
if (!version) {
|
38
|
+
const res = await fetch(
|
39
|
+
"https://raw.githubusercontent.com/learnpack/ide/master/package.json"
|
40
|
+
)
|
41
|
+
const json = await res.json()
|
42
|
+
version = json.version || "4.0.0"
|
43
|
+
|
44
|
+
if (!version)
|
45
|
+
throw InternalError(
|
46
|
+
`Coding Editor version was not found on learnpack repository, check the config.editor.version property on learn.json`
|
47
|
+
)
|
48
|
+
}
|
49
|
+
|
50
|
+
const [major, minor] = version.split(".")
|
51
|
+
const versionPrefix = `${major}.${minor}`
|
52
|
+
|
53
|
+
const tagsRes = await fetch(
|
54
|
+
"https://api.github.com/repos/learnpack/ide/contents/bin"
|
55
|
+
)
|
56
|
+
const tags = await tagsRes.json()
|
57
|
+
const matchingTags = tags
|
58
|
+
.filter((tag: any) => tag.name.includes(versionPrefix))
|
59
|
+
.sort((a: any, b: any) =>
|
60
|
+
b.name.localeCompare(a.name, undefined, { numeric: true })
|
61
|
+
)
|
62
|
+
|
63
|
+
if (matchingTags.length === 0)
|
64
|
+
throw InternalError(
|
65
|
+
`No matching version found for prefix ${versionPrefix} in the learnpack repository`
|
66
|
+
)
|
67
|
+
|
68
|
+
const latestVersion = matchingTags[0].name
|
69
|
+
.replace("learnpack-", "")
|
70
|
+
.replace(".tar.gz", "")
|
71
|
+
const versionNumber = parseInt(latestVersion.split(".")[0])
|
72
|
+
|
73
|
+
let url = `https://github.com/learnpack/coding-ide/blob/${latestVersion}/dist`
|
74
|
+
|
75
|
+
if (versionNumber > 2)
|
76
|
+
url = `https://github.com/learnpack/ide/blob/master/bin/learnpack-${latestVersion}.tar.gz`
|
77
|
+
|
78
|
+
const resp2 = await fetch(url, { method: "HEAD" })
|
79
|
+
if (!resp2.ok)
|
80
|
+
throw InternalError(
|
81
|
+
`Coding Editor ${latestVersion} was not found on learnpack repository, check the config.editor.version property on learn.json`
|
82
|
+
)
|
83
|
+
|
84
|
+
Console.info("Downloading the LearnPack coding UI, this may take a minute...")
|
85
|
+
|
86
|
+
url += versionNumber > 2 ? `?raw=true` : `/app.tar.gz?raw=true`
|
87
|
+
|
88
|
+
return download(url, destination)
|
89
|
+
}
|
90
|
+
|
91
|
+
export const download = (url: string, dest: string) => {
|
92
|
+
Console.debug("Downloading " + url)
|
93
|
+
return new Promise((resolve, reject) => {
|
94
|
+
const request = https.get(url, response => {
|
95
|
+
if (response.statusCode === 200) {
|
96
|
+
const file = fs.createWriteStream(dest, { flags: "wx" })
|
97
|
+
file.on("finish", () => {
|
98
|
+
resolve(true)
|
99
|
+
})
|
100
|
+
file.on("error", err => {
|
101
|
+
file.close()
|
102
|
+
if (err.code === "EEXIST") {
|
103
|
+
Console.debug("File already exists")
|
104
|
+
resolve("File already exists")
|
105
|
+
} else {
|
106
|
+
Console.debug("Error ", err.message)
|
107
|
+
fs.unlink(dest, () => reject(err.message)) // Delete temp file
|
108
|
+
}
|
109
|
+
})
|
110
|
+
response.pipe(file)
|
111
|
+
} else if (response.statusCode === 302 || response.statusCode === 301) {
|
112
|
+
// Console.debug("Servers redirected to "+response.headers.location)
|
113
|
+
// Recursively follow redirects, only a 200 will resolve.
|
114
|
+
if (response.headers.location) {
|
115
|
+
download(response.headers.location, dest)
|
116
|
+
.then(() => resolve(/* */ ""))
|
117
|
+
.catch(error => {
|
118
|
+
Console.error(error)
|
119
|
+
reject(error)
|
120
|
+
})
|
121
|
+
}
|
122
|
+
} else {
|
123
|
+
Console.debug(
|
124
|
+
`Server responded with ${response.statusCode}: ${response.statusMessage}`
|
125
|
+
)
|
126
|
+
reject(
|
127
|
+
`Server responded with ${response.statusCode}: ${response.statusMessage}`
|
128
|
+
)
|
129
|
+
}
|
130
|
+
})
|
131
|
+
|
132
|
+
request.on("error", err => {
|
133
|
+
reject(err.message)
|
134
|
+
})
|
135
|
+
})
|
136
|
+
}
|
137
|
+
|
138
|
+
export const clone = (repository = "", folder = "./") =>
|
139
|
+
new Promise((resolve, reject) => {
|
140
|
+
if (!repository) {
|
141
|
+
reject("Missing repository url for this package")
|
142
|
+
// return false
|
143
|
+
}
|
144
|
+
|
145
|
+
cli.action.start("Verifying GIT...")
|
146
|
+
if (!shell.which("git")) {
|
147
|
+
reject("Sorry, this script requires git")
|
148
|
+
// return false
|
149
|
+
}
|
150
|
+
|
151
|
+
cli.action.stop()
|
152
|
+
|
153
|
+
let fileName = p.basename(repository)
|
154
|
+
if (!fileName) {
|
155
|
+
reject("Invalid repository information on package: " + repository)
|
156
|
+
// return false
|
157
|
+
}
|
158
|
+
|
159
|
+
fileName = fileName.split(".")[0]
|
160
|
+
if (fs.existsSync("./" + fileName)) {
|
161
|
+
reject(
|
162
|
+
`Directory ${fileName} already exists; Did you download this package already?`
|
163
|
+
)
|
164
|
+
// return false
|
165
|
+
}
|
166
|
+
|
167
|
+
cli.action.start(`Cloning repository ${repository}...`)
|
168
|
+
if (shell.exec(`git clone ${repository}`).code !== 0) {
|
169
|
+
reject("Error: Installation failed")
|
170
|
+
}
|
171
|
+
|
172
|
+
cli.action.stop()
|
173
|
+
|
174
|
+
cli.action.start("Cleaning installation...")
|
175
|
+
if (shell.exec(`rm -R -f ${folder}${fileName}/.git`).code !== 0) {
|
176
|
+
reject("Error: removing .git directory")
|
177
|
+
}
|
178
|
+
|
179
|
+
cli.action.stop()
|
180
|
+
|
181
|
+
resolve("Done")
|
182
|
+
})
|
183
|
+
|
184
|
+
export const rmSync = function (path: string) {
|
185
|
+
let files = []
|
186
|
+
if (fs.existsSync(path)) {
|
187
|
+
files = fs.readdirSync(path)
|
188
|
+
for (const [, file] of files.entries()) {
|
189
|
+
const curPath = path + "/" + file
|
190
|
+
if (fs.lstatSync(curPath).isDirectory()) {
|
191
|
+
// recurse
|
192
|
+
rmSync(curPath)
|
193
|
+
} else {
|
194
|
+
// delete file
|
195
|
+
fs.unlinkSync(curPath)
|
196
|
+
}
|
197
|
+
}
|
198
|
+
|
199
|
+
fs.rmdirSync(path)
|
200
|
+
}
|
201
|
+
}
|
202
|
+
|
203
|
+
export const checkIfDirectoryExists = (path: string) => {
|
204
|
+
const fs = require("fs")
|
205
|
+
if (fs.existsSync(path)) {
|
206
|
+
return true
|
207
|
+
}
|
208
|
+
|
209
|
+
return false
|
210
|
+
}
|
211
|
+
|
212
|
+
export default { download, decompress, downloadEditor, clone, rmSync }
|