@learnpack/learnpack 2.1.26 → 2.1.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/lib/commands/start.js +15 -4
- package/lib/managers/file.d.ts +1 -0
- package/lib/managers/file.js +8 -1
- package/lib/managers/server/routes.js +48 -14
- package/lib/managers/session.d.ts +1 -1
- package/lib/managers/session.js +39 -12
- package/lib/managers/socket.d.ts +1 -1
- package/lib/managers/socket.js +57 -43
- package/lib/models/action.d.ts +1 -1
- package/lib/models/config.d.ts +1 -1
- package/lib/models/exercise-obj.d.ts +3 -0
- package/lib/models/session.d.ts +4 -1
- package/lib/models/socket.d.ts +7 -6
- package/lib/models/status.d.ts +1 -1
- package/lib/utils/api.d.ts +2 -0
- package/lib/utils/api.js +51 -6
- package/oclif.manifest.json +1 -1
- package/package.json +3 -1
- package/src/commands/audit.ts +113 -113
- package/src/commands/clean.ts +10 -10
- package/src/commands/download.ts +18 -18
- package/src/commands/init.ts +39 -39
- package/src/commands/login.ts +13 -13
- package/src/commands/logout.ts +9 -9
- package/src/commands/publish.ts +25 -25
- package/src/commands/start.ts +101 -75
- package/src/commands/test.ts +34 -34
- package/src/managers/config/allowed_files.ts +2 -2
- package/src/managers/config/defaults.ts +2 -2
- package/src/managers/config/exercise.ts +79 -79
- package/src/managers/config/index.ts +145 -145
- package/src/managers/file.ts +74 -65
- package/src/managers/server/index.ts +32 -31
- package/src/managers/server/routes.ts +139 -90
- package/src/managers/session.ts +53 -24
- package/src/managers/socket.ts +92 -79
- package/src/models/action.ts +8 -1
- package/src/models/config-manager.ts +2 -2
- package/src/models/config.ts +7 -2
- package/src/models/exercise-obj.ts +6 -3
- package/src/models/plugin-config.ts +2 -2
- package/src/models/session.ts +5 -2
- package/src/models/socket.ts +12 -6
- package/src/models/status.ts +15 -14
- package/src/plugin/command/compile.ts +10 -10
- package/src/plugin/command/test.ts +14 -14
- package/src/plugin/index.ts +5 -5
- package/src/plugin/plugin.ts +26 -26
- package/src/plugin/utils.ts +23 -23
- package/src/utils/BaseCommand.ts +16 -16
- package/src/utils/api.ts +143 -91
- package/src/utils/audit.ts +93 -96
- package/src/utils/exercisesQueue.ts +15 -15
- package/src/utils/fileQueue.ts +85 -85
- package/src/utils/watcher.ts +14 -14
package/lib/models/socket.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import { IConfig } from
|
2
|
-
import { Server } from
|
3
|
-
import { DefaultEventsMap } from
|
4
|
-
import { TAction, ICallback } from
|
5
|
-
import { TStatus } from
|
6
|
-
export declare type TPossibleActions =
|
1
|
+
import { IConfig } from "./config";
|
2
|
+
import { Server } from "socket.io";
|
3
|
+
import { DefaultEventsMap } from "socket.io/dist/typed-events";
|
4
|
+
import { TAction, ICallback } from "./action";
|
5
|
+
import { TStatus } from "./status";
|
6
|
+
export declare type TPossibleActions = "build" | "test" | "reset" | "tutorial" | "generate";
|
7
7
|
export interface ISocket {
|
8
8
|
socket: Server<DefaultEventsMap, DefaultEventsMap, DefaultEventsMap, any> | null;
|
9
9
|
config: IConfig | null;
|
@@ -18,6 +18,7 @@ export interface ISocket {
|
|
18
18
|
start: (config: IConfig, server: any, isTestingEnvironment: boolean) => void;
|
19
19
|
on: (action: any, callBack: any) => void;
|
20
20
|
clean: (_: string, logs: Array<any>) => void;
|
21
|
+
complete: () => void;
|
21
22
|
ask: (questions: Array<string>) => void;
|
22
23
|
reload: (files: Array<string> | null, exercises: Array<string>) => void;
|
23
24
|
openWindow: (id: string) => void;
|
package/lib/models/status.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export declare type TStatus =
|
1
|
+
export declare type TStatus = "ready" | "internal-error" | "compiler-success" | "testing-success" | "compiling" | "testing" | "start_exercise" | "initializing" | "configuration_loaded" | "connection_ended" | "reset_exercise" | "open_files" | "open_window" | "instructions_closed" | "completed";
|
package/lib/utils/api.d.ts
CHANGED
package/lib/utils/api.js
CHANGED
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const console_1 = require("../utils/console");
|
4
4
|
const storage = require("node-persist");
|
5
5
|
const cli_ux_1 = require("cli-ux");
|
6
|
-
const HOST = "https://
|
6
|
+
const HOST = "https://breathecode.herokuapp.com";
|
7
|
+
const RIGOBOT_HOST = "https://rigobot.herokuapp.com";
|
7
8
|
// eslint-disable-next-line
|
8
9
|
const _fetch = require("node-fetch");
|
9
10
|
const fetch = async (url, options = {}) => {
|
10
11
|
const headers = { "Content-Type": "application/json" };
|
12
|
+
console_1.default.log(`Fetching ${url}`);
|
11
13
|
let session = null;
|
12
14
|
try {
|
13
15
|
session = await storage.getItem("bc-payload");
|
@@ -53,20 +55,54 @@ const fetch = async (url, options = {}) => {
|
|
53
55
|
};
|
54
56
|
const login = async (identification, password) => {
|
55
57
|
try {
|
56
|
-
cli_ux_1.default.action.start(
|
58
|
+
cli_ux_1.default.action.start(`Looking for credentials with ${identification}`);
|
57
59
|
await cli_ux_1.default.wait(1000);
|
58
|
-
const
|
59
|
-
|
60
|
+
const url = `${HOST}/v1/auth/login/`;
|
61
|
+
// Console.log(url);
|
62
|
+
const data = await fetch(url, {
|
63
|
+
body: JSON.stringify({
|
64
|
+
email: identification,
|
65
|
+
password: password,
|
66
|
+
}),
|
60
67
|
method: "post",
|
61
68
|
});
|
62
69
|
cli_ux_1.default.action.stop("ready");
|
63
|
-
|
70
|
+
const payload = await loginRigo(data.token);
|
71
|
+
return Object.assign(Object.assign({}, data), { rigobot: payload });
|
64
72
|
}
|
65
73
|
catch (error) {
|
74
|
+
cli_ux_1.default.action.stop("error");
|
66
75
|
console_1.default.error(error.message);
|
67
76
|
console_1.default.debug(error);
|
68
77
|
}
|
69
78
|
};
|
79
|
+
const loginRigo = async (token) => {
|
80
|
+
const rigoUrl = `${RIGOBOT_HOST}/v1/auth/me/token?breathecode_token=${token}`;
|
81
|
+
const rigoResp = await _fetch(rigoUrl);
|
82
|
+
const rigobotJson = await rigoResp.json();
|
83
|
+
return rigobotJson;
|
84
|
+
};
|
85
|
+
const getOpenAIToken = async () => {
|
86
|
+
const token = await storage.getItem("openai-token");
|
87
|
+
return token;
|
88
|
+
};
|
89
|
+
const getRigoFeedback = async (readme, currentCode) => {
|
90
|
+
const payload = {
|
91
|
+
current_code: Buffer.from(currentCode).toString("base64"),
|
92
|
+
tutorial: Buffer.from(readme).toString("base64"),
|
93
|
+
};
|
94
|
+
const session = await storage.getItem("bc-payload");
|
95
|
+
const response = await _fetch(`${RIGOBOT_HOST}/v1/conversation/feedback/`, {
|
96
|
+
method: "POST",
|
97
|
+
headers: {
|
98
|
+
"Content-Type": "application/json",
|
99
|
+
Authorization: `Token ${session.rigobot.key}`,
|
100
|
+
},
|
101
|
+
body: JSON.stringify(payload),
|
102
|
+
});
|
103
|
+
const responseData = await response.json();
|
104
|
+
return responseData.feedback;
|
105
|
+
};
|
70
106
|
const publish = async (config) => {
|
71
107
|
const keys = [
|
72
108
|
"difficulty",
|
@@ -170,4 +206,13 @@ const APIError = (error, code) => {
|
|
170
206
|
_err.status = code || 400;
|
171
207
|
return _err;
|
172
208
|
};
|
173
|
-
exports.default = {
|
209
|
+
exports.default = {
|
210
|
+
login,
|
211
|
+
publish,
|
212
|
+
update,
|
213
|
+
getPackage,
|
214
|
+
getLangs,
|
215
|
+
getAllPackages,
|
216
|
+
getRigoFeedback,
|
217
|
+
getOpenAIToken,
|
218
|
+
};
|
package/oclif.manifest.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":"2.1.
|
1
|
+
{"version":"2.1.28","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":"[standalone, gitpod]","options":["standalone","gitpod"]},"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
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@learnpack/learnpack",
|
3
3
|
"description": "Create, sell or download and take learning amazing learning packages",
|
4
|
-
"version": "2.1.
|
4
|
+
"version": "2.1.28",
|
5
5
|
"author": "Alejandro Sanchez @alesanchezr",
|
6
6
|
"bin": {
|
7
7
|
"learnpack": "bin/run"
|
@@ -67,6 +67,7 @@
|
|
67
67
|
"fs-extra": "^10.0.1",
|
68
68
|
"globby": "^10.0.2",
|
69
69
|
"husky": ">=6",
|
70
|
+
"learnpack-node": "^0.0.21",
|
70
71
|
"lint-staged": ">=10",
|
71
72
|
"mocha": "^5.2.0",
|
72
73
|
"mock-fs": "^5.1.2",
|
@@ -119,6 +120,7 @@
|
|
119
120
|
]
|
120
121
|
},
|
121
122
|
"scripts": {
|
123
|
+
"tsc": "tsc -b",
|
122
124
|
"postpack": "rm -f oclif.manifest.json && eslint . --ext .ts --config .eslintrc",
|
123
125
|
"prepack": "rm -rf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
|
124
126
|
"pre": "node ./test/precommit/index.ts",
|