@learnpack/learnpack 2.0.2 → 2.0.5
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 +33 -38
- package/bin/run +1 -1
- package/oclif.manifest.json +1 -0
- package/package.json +4 -2
- package/src/commands/clean.ts +29 -29
- package/src/commands/download.ts +62 -62
- package/src/commands/init.ts +172 -172
- 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 +234 -234
- package/src/commands/test.ts +85 -85
- package/src/managers/config/exercise.ts +302 -302
- package/src/managers/config/index.ts +412 -412
- package/src/managers/file.ts +169 -169
- package/src/managers/server/index.ts +69 -69
- package/src/managers/server/routes.ts +255 -255
- package/src/managers/test.ts +83 -83
- package/src/plugin/plugin.ts +94 -94
- package/src/plugin/utils.ts +87 -87
- package/src/utils/BaseCommand.ts +48 -48
- package/src/utils/api.ts +194 -194
- package/src/utils/fileQueue.ts +198 -198
package/src/commands/publish.ts
CHANGED
@@ -1,107 +1,107 @@
|
|
1
|
-
import { prompt } from "enquirer";
|
2
|
-
import SessionCommand from "../utils/SessionCommand";
|
3
|
-
import Console from "../utils/console";
|
4
|
-
import api from "../utils/api";
|
5
|
-
import { validURL } from "../utils/validators";
|
6
|
-
|
7
|
-
// eslint-disable-next-line
|
8
|
-
const fetch = require("node-fetch");
|
9
|
-
|
10
|
-
class PublishCommand extends SessionCommand {
|
11
|
-
static description = `Describe the command here
|
12
|
-
...
|
13
|
-
Extra documentation goes here
|
14
|
-
`;
|
15
|
-
|
16
|
-
static flags: any = {
|
17
|
-
// name: flags.string({char: 'n', description: 'name to print'}),
|
18
|
-
};
|
19
|
-
|
20
|
-
static args = [
|
21
|
-
{
|
22
|
-
name: "package", // name of arg to show in help and reference with args[name]
|
23
|
-
required: false, // make the arg required with `required: true`
|
24
|
-
description:
|
25
|
-
"The unique string that identifies this package on learnpack", // help description
|
26
|
-
hidden: false, // hide this arg from help
|
27
|
-
},
|
28
|
-
];
|
29
|
-
|
30
|
-
async init() {
|
31
|
-
const { flags } = this.parse(PublishCommand);
|
32
|
-
await this.initSession(flags, true);
|
33
|
-
}
|
34
|
-
|
35
|
-
async run() {
|
36
|
-
const { flags, args } = this.parse(PublishCommand);
|
37
|
-
|
38
|
-
// avoid annonymus sessions
|
39
|
-
// eslint-disable-next-line
|
40
|
-
if (!this.session) return;
|
41
|
-
|
42
|
-
Console.info(
|
43
|
-
`Session found for ${this.session.payload.email}, publishing the package...`
|
44
|
-
);
|
45
|
-
|
46
|
-
const configObject = this.configManager?.get();
|
47
|
-
if (
|
48
|
-
configObject?.config?.slug === undefined ||
|
49
|
-
!configObject.config?.slug
|
50
|
-
) {
|
51
|
-
throw new Error(
|
52
|
-
"The package is missing a slug (unique name identifier), please check your learn.json file and make sure it has a 'slug'"
|
53
|
-
);
|
54
|
-
}
|
55
|
-
|
56
|
-
if (!validURL(configObject?.config?.repository ?? "")) {
|
57
|
-
throw new Error(
|
58
|
-
"The package has a missing or invalid 'repository' on the configuration file, it needs to be a Github URL"
|
59
|
-
);
|
60
|
-
} else {
|
61
|
-
const validateResp = await fetch(configObject.config?.repository, {
|
62
|
-
method: "HEAD",
|
63
|
-
});
|
64
|
-
if (!validateResp.ok || validateResp.status !== 200) {
|
65
|
-
throw new Error(
|
66
|
-
`The specified repository URL on the configuration file does not exist or its private, only public repositories are allowed at the moment: ${configObject.config?.repository}`
|
67
|
-
);
|
68
|
-
}
|
69
|
-
}
|
70
|
-
|
71
|
-
// start watching for file changes
|
72
|
-
try {
|
73
|
-
await api.publish({
|
74
|
-
...configObject,
|
75
|
-
author: this.session.payload.user_id,
|
76
|
-
});
|
77
|
-
Console.success(
|
78
|
-
`Package updated and published successfully: ${configObject.config?.slug}`
|
79
|
-
);
|
80
|
-
} catch (error) {
|
81
|
-
if ((error as any).status === 404) {
|
82
|
-
const answer = await prompt([
|
83
|
-
{
|
84
|
-
type: "confirm",
|
85
|
-
name: "create",
|
86
|
-
message: `Package with slug ${configObject.config?.slug} does not exist, do you want to create it?`,
|
87
|
-
},
|
88
|
-
]);
|
89
|
-
if (answer) {
|
90
|
-
await api.update({
|
91
|
-
...configObject,
|
92
|
-
author: this.session.payload.user_id,
|
93
|
-
});
|
94
|
-
Console.success(
|
95
|
-
`Package created and published successfully: ${configObject.config?.slug}`
|
96
|
-
);
|
97
|
-
} else {
|
98
|
-
Console.error("No answer from server");
|
99
|
-
}
|
100
|
-
} else {
|
101
|
-
Console.error((error as TypeError).message);
|
102
|
-
}
|
103
|
-
}
|
104
|
-
}
|
105
|
-
}
|
106
|
-
|
107
|
-
export default PublishCommand;
|
1
|
+
import { prompt } from "enquirer";
|
2
|
+
import SessionCommand from "../utils/SessionCommand";
|
3
|
+
import Console from "../utils/console";
|
4
|
+
import api from "../utils/api";
|
5
|
+
import { validURL } from "../utils/validators";
|
6
|
+
|
7
|
+
// eslint-disable-next-line
|
8
|
+
const fetch = require("node-fetch");
|
9
|
+
|
10
|
+
class PublishCommand extends SessionCommand {
|
11
|
+
static description = `Describe the command here
|
12
|
+
...
|
13
|
+
Extra documentation goes here
|
14
|
+
`;
|
15
|
+
|
16
|
+
static flags: any = {
|
17
|
+
// name: flags.string({char: 'n', description: 'name to print'}),
|
18
|
+
};
|
19
|
+
|
20
|
+
static args = [
|
21
|
+
{
|
22
|
+
name: "package", // name of arg to show in help and reference with args[name]
|
23
|
+
required: false, // make the arg required with `required: true`
|
24
|
+
description:
|
25
|
+
"The unique string that identifies this package on learnpack", // help description
|
26
|
+
hidden: false, // hide this arg from help
|
27
|
+
},
|
28
|
+
];
|
29
|
+
|
30
|
+
async init() {
|
31
|
+
const { flags } = this.parse(PublishCommand);
|
32
|
+
await this.initSession(flags, true);
|
33
|
+
}
|
34
|
+
|
35
|
+
async run() {
|
36
|
+
const { flags, args } = this.parse(PublishCommand);
|
37
|
+
|
38
|
+
// avoid annonymus sessions
|
39
|
+
// eslint-disable-next-line
|
40
|
+
if (!this.session) return;
|
41
|
+
|
42
|
+
Console.info(
|
43
|
+
`Session found for ${this.session.payload.email}, publishing the package...`
|
44
|
+
);
|
45
|
+
|
46
|
+
const configObject = this.configManager?.get();
|
47
|
+
if (
|
48
|
+
configObject?.config?.slug === undefined ||
|
49
|
+
!configObject.config?.slug
|
50
|
+
) {
|
51
|
+
throw new Error(
|
52
|
+
"The package is missing a slug (unique name identifier), please check your learn.json file and make sure it has a 'slug'"
|
53
|
+
);
|
54
|
+
}
|
55
|
+
|
56
|
+
if (!validURL(configObject?.config?.repository ?? "")) {
|
57
|
+
throw new Error(
|
58
|
+
"The package has a missing or invalid 'repository' on the configuration file, it needs to be a Github URL"
|
59
|
+
);
|
60
|
+
} else {
|
61
|
+
const validateResp = await fetch(configObject.config?.repository, {
|
62
|
+
method: "HEAD",
|
63
|
+
});
|
64
|
+
if (!validateResp.ok || validateResp.status !== 200) {
|
65
|
+
throw new Error(
|
66
|
+
`The specified repository URL on the configuration file does not exist or its private, only public repositories are allowed at the moment: ${configObject.config?.repository}`
|
67
|
+
);
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
// start watching for file changes
|
72
|
+
try {
|
73
|
+
await api.publish({
|
74
|
+
...configObject,
|
75
|
+
author: this.session.payload.user_id,
|
76
|
+
});
|
77
|
+
Console.success(
|
78
|
+
`Package updated and published successfully: ${configObject.config?.slug}`
|
79
|
+
);
|
80
|
+
} catch (error) {
|
81
|
+
if ((error as any).status === 404) {
|
82
|
+
const answer = await prompt([
|
83
|
+
{
|
84
|
+
type: "confirm",
|
85
|
+
name: "create",
|
86
|
+
message: `Package with slug ${configObject.config?.slug} does not exist, do you want to create it?`,
|
87
|
+
},
|
88
|
+
]);
|
89
|
+
if (answer) {
|
90
|
+
await api.update({
|
91
|
+
...configObject,
|
92
|
+
author: this.session.payload.user_id,
|
93
|
+
});
|
94
|
+
Console.success(
|
95
|
+
`Package created and published successfully: ${configObject.config?.slug}`
|
96
|
+
);
|
97
|
+
} else {
|
98
|
+
Console.error("No answer from server");
|
99
|
+
}
|
100
|
+
} else {
|
101
|
+
Console.error((error as TypeError).message);
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
export default PublishCommand;
|