@learnpack/learnpack 2.1.31 → 2.1.32
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +10 -10
- package/lib/commands/start.js +8 -3
- package/lib/managers/config/index.js +2 -3
- package/lib/managers/telemetry.d.ts +26 -0
- package/lib/managers/telemetry.js +26 -0
- package/lib/models/action.d.ts +1 -1
- package/lib/utils/watcher.d.ts +1 -1
- package/lib/utils/watcher.js +5 -3
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/src/commands/start.ts +9 -9
- package/src/managers/config/index.ts +5 -4
- package/src/managers/telemetry.ts +58 -0
- package/src/models/action.ts +1 -1
- package/src/utils/watcher.ts +6 -4
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/2.1.
|
24
|
+
@learnpack/learnpack/2.1.32 darwin-arm64 node-v16.20.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/v2.1.
|
77
|
+
_See code: [src/commands/audit.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/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/v2.1.
|
92
|
+
_See code: [src/commands/clean.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/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/v2.1.
|
110
|
+
_See code: [src/commands/download.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/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/v2.1.
|
141
|
+
_See code: [src/commands/init.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/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/v2.1.
|
159
|
+
_See code: [src/commands/login.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/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/v2.1.
|
177
|
+
_See code: [src/commands/logout.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/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/v2.1.
|
312
|
+
_See code: [src/commands/publish.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/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/v2.1.
|
333
|
+
_See code: [src/commands/start.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/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/v2.1.
|
347
|
+
_See code: [src/commands/test.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/src/commands/test.ts)_
|
348
348
|
<!-- commandsstop -->
|
349
349
|
|
350
350
|
> > > > > > > 0cb3e56d84c197f9d008836bb573eade212b7e57
|
package/lib/commands/start.js
CHANGED
@@ -5,6 +5,7 @@ const command_1 = require("@oclif/command");
|
|
5
5
|
const SessionCommand_1 = require("../utils/SessionCommand");
|
6
6
|
const console_1 = require("../utils/console");
|
7
7
|
const socket_1 = require("../managers/socket");
|
8
|
+
const telemetry_1 = require("../managers/telemetry");
|
8
9
|
const fileQueue_1 = require("../utils/fileQueue");
|
9
10
|
const file_1 = require("../managers/file");
|
10
11
|
const misc_1 = require("../utils/misc");
|
@@ -92,8 +93,9 @@ class StartCommand extends SessionCommand_1.default {
|
|
92
93
|
exercise,
|
93
94
|
});
|
94
95
|
});
|
95
|
-
socket_1.default.on("
|
96
|
-
|
96
|
+
socket_1.default.on("telemetry", (data) => {
|
97
|
+
console_1.default.info("Registering telemetry event: ", data);
|
98
|
+
telemetry_1.default.registerEvent(data);
|
97
99
|
});
|
98
100
|
socket_1.default.on("test", async (data) => {
|
99
101
|
var _a, _b;
|
@@ -135,7 +137,10 @@ class StartCommand extends SessionCommand_1.default {
|
|
135
137
|
setTimeout(() => dispatcher.enqueue(dispatcher.events.RUNNING), 1000);
|
136
138
|
// start watching for file changes
|
137
139
|
if (StartCommand.flags.watch)
|
138
|
-
this.configManager.watchIndex(
|
140
|
+
this.configManager.watchIndex(_filename => {
|
141
|
+
// Instead of reloading with socket.reload(), I just notify the frontend for the file change
|
142
|
+
socket_1.default.emit("file_change", "ready", _filename);
|
143
|
+
});
|
139
144
|
}
|
140
145
|
}
|
141
146
|
}
|
@@ -284,11 +284,10 @@ exports.default = async ({ grading, mode, disableGrading, version, }) => {
|
|
284
284
|
throw errors_1.ValidationError("No exercises directory to watch: " + configObj.config.exercisesPath);
|
285
285
|
this.buildIndex();
|
286
286
|
watcher_1.default(((_a = configObj === null || configObj === void 0 ? void 0 : configObj.config) === null || _a === void 0 ? void 0 : _a.exercisesPath) || "", onChange)
|
287
|
-
.then((
|
287
|
+
.then(() => {
|
288
288
|
console_1.default.debug("Changes detected on your exercises");
|
289
289
|
this.buildIndex();
|
290
|
-
if (onChange)
|
291
|
-
onChange();
|
290
|
+
// if (onChange) onChange(filename);
|
292
291
|
})
|
293
292
|
.catch(error => {
|
294
293
|
throw error;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
declare type TEventType = "form_submit" | "build" | "test" | "visualize_step" | "code_start";
|
2
|
+
declare type TFile = {
|
3
|
+
name: string;
|
4
|
+
content: string;
|
5
|
+
};
|
6
|
+
declare type TStep = {
|
7
|
+
name: string;
|
8
|
+
position: number;
|
9
|
+
files: TFile[];
|
10
|
+
};
|
11
|
+
declare type TTelemetryEvent = {
|
12
|
+
type: TEventType;
|
13
|
+
data: any;
|
14
|
+
timestamp: number;
|
15
|
+
step: TStep;
|
16
|
+
};
|
17
|
+
interface ITelemetryManager {
|
18
|
+
current: Array<TTelemetryEvent> | null;
|
19
|
+
start: () => void;
|
20
|
+
submit: () => void;
|
21
|
+
registerEvent: (event: Omit<TTelemetryEvent, "timestamp">) => void;
|
22
|
+
save: () => void;
|
23
|
+
onSaveCallback?: (current: Array<TTelemetryEvent>) => void;
|
24
|
+
}
|
25
|
+
declare const TelemetryManager: ITelemetryManager;
|
26
|
+
export default TelemetryManager;
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const TelemetryManager = {
|
4
|
+
current: null,
|
5
|
+
start: function () {
|
6
|
+
if (!this.current) {
|
7
|
+
this.current = [];
|
8
|
+
}
|
9
|
+
},
|
10
|
+
submit: function () {
|
11
|
+
console.log("submit");
|
12
|
+
},
|
13
|
+
registerEvent: function (event) {
|
14
|
+
var _a;
|
15
|
+
this.start();
|
16
|
+
const timestamp = Date.now();
|
17
|
+
const _event = Object.assign(Object.assign({}, event), { timestamp });
|
18
|
+
(_a = this.current) === null || _a === void 0 ? void 0 : _a.push(_event);
|
19
|
+
},
|
20
|
+
save: function () {
|
21
|
+
if (this.onSaveCallback && this.current) {
|
22
|
+
this.onSaveCallback(this.current);
|
23
|
+
}
|
24
|
+
},
|
25
|
+
};
|
26
|
+
exports.default = TelemetryManager;
|
package/lib/models/action.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare type TAction = "test" | "log" | "reload" | "ready" | "clean" | "ask" | "
|
1
|
+
export declare type TAction = "test" | "log" | "reload" | "ready" | "clean" | "ask" | "file_change";
|
2
2
|
export declare type ICallback = (...agrs: any[]) => any;
|
package/lib/utils/watcher.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
declare const _default: (path: string, reloadSocket: () => void) => Promise<unknown>;
|
1
|
+
declare const _default: (path: string, reloadSocket: (filename: string) => void) => Promise<unknown>;
|
2
2
|
export default _default;
|
package/lib/utils/watcher.js
CHANGED
@@ -7,12 +7,14 @@ exports.default = (path, reloadSocket) => new Promise((resolve /* , reject */) =
|
|
7
7
|
console_1.default.debug("PATH:", path);
|
8
8
|
const watcher = chokidar.watch(path, {
|
9
9
|
// TODO: This watcher is not ready yet
|
10
|
-
ignored: /^(?=.*(\.\w+)$)(?!.*\.md$).*$/gm,
|
10
|
+
// ignored: /^(?=.*(\.\w+)$)(?!.*\.md$).*$/gm,
|
11
|
+
ignored: /\.pyc$/,
|
11
12
|
ignoreInitial: true,
|
12
13
|
});
|
13
14
|
const onChange = (eventname, _filename) => {
|
14
|
-
|
15
|
-
|
15
|
+
// Console.info(`Event ${eventname} detected. in file: ${_filename}`)
|
16
|
+
resolve(_filename);
|
17
|
+
reloadSocket(_filename);
|
16
18
|
};
|
17
19
|
watcher.on("all", debounce(onChange, 500, true));
|
18
20
|
// watcher.on('all', onChange)
|
package/oclif.manifest.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":"2.1.
|
1
|
+
{"version":"2.1.32","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
package/src/commands/start.ts
CHANGED
@@ -4,6 +4,8 @@ import { flags } from "@oclif/command"
|
|
4
4
|
import SessionCommand from "../utils/SessionCommand"
|
5
5
|
import Console from "../utils/console"
|
6
6
|
import socket from "../managers/socket"
|
7
|
+
import TelemetryManager from "../managers/telemetry"
|
8
|
+
|
7
9
|
import queue from "../utils/fileQueue"
|
8
10
|
import {
|
9
11
|
decompress,
|
@@ -185,11 +187,9 @@ export default class StartCommand extends SessionCommand {
|
|
185
187
|
})
|
186
188
|
})
|
187
189
|
|
188
|
-
socket.on("
|
189
|
-
|
190
|
-
|
191
|
-
data
|
192
|
-
)
|
190
|
+
socket.on("telemetry", (data: any) => {
|
191
|
+
Console.info("Registering telemetry event: ", data)
|
192
|
+
TelemetryManager.registerEvent(data)
|
193
193
|
})
|
194
194
|
|
195
195
|
socket.on("test", async (data: IExerciseData) => {
|
@@ -248,11 +248,11 @@ export default class StartCommand extends SessionCommand {
|
|
248
248
|
setTimeout(() => dispatcher.enqueue(dispatcher.events.RUNNING), 1000)
|
249
249
|
|
250
250
|
// start watching for file changes
|
251
|
-
|
252
251
|
if (StartCommand.flags.watch)
|
253
|
-
this.configManager.watchIndex(
|
254
|
-
socket.reload(
|
255
|
-
|
252
|
+
this.configManager.watchIndex(_filename => {
|
253
|
+
// Instead of reloading with socket.reload(), I just notify the frontend for the file change
|
254
|
+
socket.emit("file_change", "ready", _filename)
|
255
|
+
})
|
256
256
|
}
|
257
257
|
}
|
258
258
|
}
|
@@ -386,24 +386,25 @@ fs.mkdirSync(confPath.base)
|
|
386
386
|
[exercise(configObj?.config?.exercisesPath || "", 0, configObj)]
|
387
387
|
this.save()
|
388
388
|
},
|
389
|
-
watchIndex: function (onChange: () => void) {
|
389
|
+
watchIndex: function (onChange: (filename: string) => void) {
|
390
390
|
if (configObj.config && !configObj.config.exercisesPath)
|
391
391
|
throw ValidationError(
|
392
392
|
"No exercises directory to watch: " + configObj.config.exercisesPath
|
393
393
|
)
|
394
394
|
|
395
395
|
this.buildIndex()
|
396
|
+
|
396
397
|
watch(configObj?.config?.exercisesPath || "", onChange)
|
397
|
-
.then((
|
398
|
+
.then(() => {
|
398
399
|
Console.debug("Changes detected on your exercises")
|
399
400
|
this.buildIndex()
|
400
|
-
if (onChange)
|
401
|
-
onChange()
|
401
|
+
// if (onChange) onChange(filename);
|
402
402
|
})
|
403
403
|
.catch(error => {
|
404
404
|
throw error
|
405
405
|
})
|
406
406
|
},
|
407
|
+
|
407
408
|
save: () => {
|
408
409
|
// Console.debug("Saving configuration with: ", configObj)
|
409
410
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
type TEventType =
|
2
|
+
| "form_submit"
|
3
|
+
| "build"
|
4
|
+
| "test"
|
5
|
+
| "visualize_step"
|
6
|
+
| "code_start";
|
7
|
+
|
8
|
+
type TFile = {
|
9
|
+
name: string;
|
10
|
+
content: string;
|
11
|
+
};
|
12
|
+
|
13
|
+
type TStep = {
|
14
|
+
name: string;
|
15
|
+
position: number;
|
16
|
+
files: TFile[];
|
17
|
+
};
|
18
|
+
|
19
|
+
type TTelemetryEvent = {
|
20
|
+
type: TEventType;
|
21
|
+
data: any;
|
22
|
+
timestamp: number;
|
23
|
+
step: TStep;
|
24
|
+
};
|
25
|
+
|
26
|
+
interface ITelemetryManager {
|
27
|
+
current: Array<TTelemetryEvent> | null;
|
28
|
+
start: () => void;
|
29
|
+
submit: () => void;
|
30
|
+
registerEvent: (event: Omit<TTelemetryEvent, "timestamp">) => void;
|
31
|
+
save: () => void;
|
32
|
+
onSaveCallback?: (current: Array<TTelemetryEvent>) => void;
|
33
|
+
}
|
34
|
+
|
35
|
+
const TelemetryManager: ITelemetryManager = {
|
36
|
+
current: null,
|
37
|
+
start: function () {
|
38
|
+
if (!this.current) {
|
39
|
+
this.current = []
|
40
|
+
}
|
41
|
+
},
|
42
|
+
submit: function () {
|
43
|
+
console.log("submit")
|
44
|
+
},
|
45
|
+
registerEvent: function (event) {
|
46
|
+
this.start()
|
47
|
+
const timestamp = Date.now()
|
48
|
+
const _event = { ...event, timestamp }
|
49
|
+
this.current?.push(_event)
|
50
|
+
},
|
51
|
+
save: function () {
|
52
|
+
if (this.onSaveCallback && this.current) {
|
53
|
+
this.onSaveCallback(this.current)
|
54
|
+
}
|
55
|
+
},
|
56
|
+
}
|
57
|
+
|
58
|
+
export default TelemetryManager
|
package/src/models/action.ts
CHANGED
package/src/utils/watcher.ts
CHANGED
@@ -3,17 +3,19 @@ import Console from "./console"
|
|
3
3
|
import * as debounce from "debounce"
|
4
4
|
import { IConfigManager } from "../models/config-manager"
|
5
5
|
|
6
|
-
export default (path: string, reloadSocket: () => void) =>
|
6
|
+
export default (path: string, reloadSocket: (filename: string) => void) =>
|
7
7
|
new Promise((resolve /* , reject */) => {
|
8
8
|
Console.debug("PATH:", path)
|
9
9
|
const watcher = chokidar.watch(path, {
|
10
10
|
// TODO: This watcher is not ready yet
|
11
|
-
ignored: /^(?=.*(\.\w+)$)(?!.*\.md$).*$/gm,
|
11
|
+
// ignored: /^(?=.*(\.\w+)$)(?!.*\.md$).*$/gm,
|
12
|
+
ignored: /\.pyc$/,
|
12
13
|
ignoreInitial: true,
|
13
14
|
})
|
14
15
|
const onChange = (eventname: string, _filename: string) => {
|
15
|
-
|
16
|
-
|
16
|
+
// Console.info(`Event ${eventname} detected. in file: ${_filename}`)
|
17
|
+
resolve(_filename)
|
18
|
+
reloadSocket(_filename)
|
17
19
|
}
|
18
20
|
|
19
21
|
watcher.on("all", debounce(onChange, 500, true))
|