@learnpack/learnpack 5.0.54 → 5.0.57
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 +30 -12
- package/lib/commands/serve.d.ts +7 -0
- package/lib/commands/serve.js +149 -0
- package/lib/managers/server/routes.js +2 -0
- package/lib/utils/api.js +1 -1
- package/lib/utils/cloudStorage.d.ts +8 -0
- package/lib/utils/cloudStorage.js +17 -0
- package/oclif.manifest.json +1 -1
- package/package.json +3 -1
- package/src/commands/serve.ts +192 -0
- package/src/creator/README.md +54 -0
- package/src/creator/eslint.config.js +28 -0
- package/src/creator/index.html +13 -0
- package/src/creator/package-lock.json +4659 -0
- package/src/creator/package.json +41 -0
- package/src/creator/public/vite.svg +1 -0
- package/src/creator/src/App.css +42 -0
- package/src/creator/src/App.tsx +221 -0
- package/src/creator/src/assets/react.svg +1 -0
- package/src/creator/src/assets/svgs.tsx +88 -0
- package/src/creator/src/components/Loader.tsx +28 -0
- package/src/creator/src/components/Login.tsx +263 -0
- package/src/creator/src/components/SelectableCard.tsx +30 -0
- package/src/creator/src/components/StepWizard.tsx +77 -0
- package/src/creator/src/components/SyllabusEditor.tsx +431 -0
- package/src/creator/src/index.css +68 -0
- package/src/creator/src/main.tsx +19 -0
- package/src/creator/src/utils/configTypes.ts +122 -0
- package/src/creator/src/utils/constants.ts +2 -0
- package/src/creator/src/utils/lib.ts +36 -0
- package/src/creator/src/utils/rigo.ts +391 -0
- package/src/creator/src/utils/store.ts +78 -0
- package/src/creator/src/vite-env.d.ts +1 -0
- package/src/creator/tsconfig.app.json +26 -0
- package/src/creator/tsconfig.json +7 -0
- package/src/creator/tsconfig.node.json +24 -0
- package/src/creator/vite.config.ts +13 -0
- package/src/creatorDist/assets/index-D92OoEoU.js +23719 -0
- package/src/creatorDist/assets/index-tt9JBVY0.css +987 -0
- package/src/creatorDist/index.html +14 -0
- package/src/creatorDist/vite.svg +1 -0
- package/src/managers/server/routes.ts +3 -0
- package/src/ui/_app/app.css +1 -0
- package/src/ui/_app/app.js +3025 -0
- package/src/ui/_app/favicon.ico +0 -0
- package/src/ui/_app/index.html +109 -0
- package/src/ui/_app/index.html.backup +91 -0
- package/src/ui/_app/learnpack.svg +7 -0
- package/src/ui/_app/logo-192.png +0 -0
- package/src/ui/_app/logo-512.png +0 -0
- package/src/ui/_app/logo.png +0 -0
- package/src/ui/_app/manifest.webmanifest +21 -0
- package/src/ui/_app/sw.js +30 -0
- package/src/ui/app.tar.gz +0 -0
- package/src/utils/api.ts +1 -1
- package/src/utils/cloudStorage.ts +24 -0
- package/src/utils/creds.json +13 -0
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/5.0.
|
24
|
+
@learnpack/learnpack/5.0.57 win32-x64 node-v22.14.0
|
25
25
|
$ learnpack --help [COMMAND]
|
26
26
|
USAGE
|
27
27
|
$ learnpack COMMAND
|
@@ -46,6 +46,7 @@ USAGE
|
|
46
46
|
* [`learnpack plugins:uninstall PLUGIN...`](#learnpack-pluginsuninstall-plugin)
|
47
47
|
* [`learnpack plugins:update`](#learnpack-pluginsupdate)
|
48
48
|
* [`learnpack publish`](#learnpack-publish)
|
49
|
+
* [`learnpack serve`](#learnpack-serve)
|
49
50
|
* [`learnpack start`](#learnpack-start)
|
50
51
|
* [`learnpack test [EXERCISESLUG]`](#learnpack-test-exerciseslug)
|
51
52
|
* [`learnpack translate`](#learnpack-translate)
|
@@ -79,7 +80,7 @@ DESCRIPTION
|
|
79
80
|
12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)
|
80
81
|
```
|
81
82
|
|
82
|
-
_See code: [src\commands\audit.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
83
|
+
_See code: [src\commands\audit.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.57/src\commands\audit.ts)_
|
83
84
|
|
84
85
|
## `learnpack breakToken`
|
85
86
|
|
@@ -94,7 +95,7 @@ OPTIONS
|
|
94
95
|
-y, --yes Skip all prompts and initialize an empty project
|
95
96
|
```
|
96
97
|
|
97
|
-
_See code: [src\commands\breakToken.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
98
|
+
_See code: [src\commands\breakToken.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.57/src\commands\breakToken.ts)_
|
98
99
|
|
99
100
|
## `learnpack clean`
|
100
101
|
|
@@ -109,7 +110,7 @@ DESCRIPTION
|
|
109
110
|
Extra documentation goes here
|
110
111
|
```
|
111
112
|
|
112
|
-
_See code: [src\commands\clean.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
113
|
+
_See code: [src\commands\clean.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.57/src\commands\clean.ts)_
|
113
114
|
|
114
115
|
## `learnpack download [PACKAGE]`
|
115
116
|
|
@@ -127,7 +128,7 @@ DESCRIPTION
|
|
127
128
|
Extra documentation goes here
|
128
129
|
```
|
129
130
|
|
130
|
-
_See code: [src\commands\download.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
131
|
+
_See code: [src\commands\download.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.57/src\commands\download.ts)_
|
131
132
|
|
132
133
|
## `learnpack help [COMMAND]`
|
133
134
|
|
@@ -159,7 +160,7 @@ OPTIONS
|
|
159
160
|
-y, --yes Skip all prompts and initialize an empty project
|
160
161
|
```
|
161
162
|
|
162
|
-
_See code: [src\commands\init.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
163
|
+
_See code: [src\commands\init.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.57/src\commands\init.ts)_
|
163
164
|
|
164
165
|
## `learnpack login [PACKAGE]`
|
165
166
|
|
@@ -177,7 +178,7 @@ DESCRIPTION
|
|
177
178
|
Extra documentation goes here
|
178
179
|
```
|
179
180
|
|
180
|
-
_See code: [src\commands\login.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
181
|
+
_See code: [src\commands\login.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.57/src\commands\login.ts)_
|
181
182
|
|
182
183
|
## `learnpack logout [PACKAGE]`
|
183
184
|
|
@@ -195,7 +196,7 @@ DESCRIPTION
|
|
195
196
|
Extra documentation goes here
|
196
197
|
```
|
197
198
|
|
198
|
-
_See code: [src\commands\logout.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
199
|
+
_See code: [src\commands\logout.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.57/src\commands\logout.ts)_
|
199
200
|
|
200
201
|
## `learnpack plugins`
|
201
202
|
|
@@ -327,7 +328,24 @@ OPTIONS
|
|
327
328
|
-s, --strict strict mode
|
328
329
|
```
|
329
330
|
|
330
|
-
_See code: [src\commands\publish.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
331
|
+
_See code: [src\commands\publish.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.57/src\commands\publish.ts)_
|
332
|
+
|
333
|
+
## `learnpack serve`
|
334
|
+
|
335
|
+
Runs a small server to build tutorials
|
336
|
+
|
337
|
+
```
|
338
|
+
USAGE
|
339
|
+
$ learnpack serve
|
340
|
+
|
341
|
+
OPTIONS
|
342
|
+
-d, --debug debugger mode for more verbage
|
343
|
+
-h, --host=host server host
|
344
|
+
-p, --port=port server port
|
345
|
+
-y, --yes Skip all prompts and initialize an empty project
|
346
|
+
```
|
347
|
+
|
348
|
+
_See code: [src\commands\serve.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.57/src\commands\serve.ts)_
|
331
349
|
|
332
350
|
## `learnpack start`
|
333
351
|
|
@@ -349,7 +367,7 @@ OPTIONS
|
|
349
367
|
-y, --yes Skip all prompts and initialize an empty project
|
350
368
|
```
|
351
369
|
|
352
|
-
_See code: [src\commands\start.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
370
|
+
_See code: [src\commands\start.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.57/src\commands\start.ts)_
|
353
371
|
|
354
372
|
## `learnpack test [EXERCISESLUG]`
|
355
373
|
|
@@ -366,7 +384,7 @@ OPTIONS
|
|
366
384
|
-y, --yes Skip all prompts and initialize an empty project
|
367
385
|
```
|
368
386
|
|
369
|
-
_See code: [src\commands\test.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
387
|
+
_See code: [src\commands\test.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.57/src\commands\test.ts)_
|
370
388
|
|
371
389
|
## `learnpack translate`
|
372
390
|
|
@@ -380,7 +398,7 @@ OPTIONS
|
|
380
398
|
-y, --yes Skip all prompts and initialize an empty project
|
381
399
|
```
|
382
400
|
|
383
|
-
_See code: [src\commands\translate.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.
|
401
|
+
_See code: [src\commands\translate.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.57/src\commands\translate.ts)_
|
384
402
|
<!-- commandsstop -->
|
385
403
|
|
386
404
|
> > > > > > > 0cb3e56d84c197f9d008836bb573eade212b7e57
|
@@ -0,0 +1,149 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const command_1 = require("@oclif/command");
|
4
|
+
const express = require("express");
|
5
|
+
const cors = require("cors");
|
6
|
+
const path = require("path");
|
7
|
+
const SessionCommand_1 = require("../utils/SessionCommand");
|
8
|
+
const storage_1 = require("@google-cloud/storage");
|
9
|
+
const file_1 = require("../managers/file");
|
10
|
+
const fs = require("fs");
|
11
|
+
const frontMatter = require("front-matter");
|
12
|
+
function getSlugFromPath(path) {
|
13
|
+
const parts = path.split("/").filter(Boolean);
|
14
|
+
if (parts.length < 2)
|
15
|
+
return null;
|
16
|
+
return parts[parts.length - 2];
|
17
|
+
}
|
18
|
+
const bucketStorage = new storage_1.Storage({
|
19
|
+
keyFilename: path.resolve(__dirname, "../utils/creds.json"),
|
20
|
+
});
|
21
|
+
const bucket = bucketStorage.bucket("learnpack");
|
22
|
+
async function listFilesWithPrefix(prefix) {
|
23
|
+
const [files] = await bucket.getFiles({ prefix });
|
24
|
+
return files;
|
25
|
+
}
|
26
|
+
class ServeCommand extends SessionCommand_1.default {
|
27
|
+
async init() {
|
28
|
+
const { flags } = this.parse(ServeCommand);
|
29
|
+
console.log("Initializing serve command");
|
30
|
+
}
|
31
|
+
async run() {
|
32
|
+
const app = express();
|
33
|
+
const PORT = 3000;
|
34
|
+
const distPath = path.resolve(__dirname, "../creatorDist");
|
35
|
+
// Servir archivos estáticos
|
36
|
+
// app.use(express.static(distPath))
|
37
|
+
app.use(express.json());
|
38
|
+
app.use(cors());
|
39
|
+
const appPath = path.resolve(__dirname, "../ui/_app");
|
40
|
+
const tarPath = path.resolve(__dirname, "../ui/app.tar.gz");
|
41
|
+
if (fs.existsSync(appPath)) {
|
42
|
+
fs.rmSync(appPath, { recursive: true });
|
43
|
+
}
|
44
|
+
if (fs.existsSync(tarPath)) {
|
45
|
+
fs.rmSync(tarPath);
|
46
|
+
}
|
47
|
+
await (0, file_1.downloadEditor)("5.0.0", `${__dirname}/../ui/app.tar.gz`);
|
48
|
+
await (0, file_1.decompress)(`${__dirname}/../ui/app.tar.gz`, `${__dirname}/../ui/_app/`);
|
49
|
+
const localAppPath = path.resolve(__dirname, "../ui/_app");
|
50
|
+
// app.use(express.static(localAppPath))
|
51
|
+
app.post("/upload", async (req, res) => {
|
52
|
+
const { content, destination } = req.body;
|
53
|
+
// console.log("UPLOAD", content, destination)
|
54
|
+
if (!content || !destination) {
|
55
|
+
return res.status(400).send("Missing content or destination");
|
56
|
+
}
|
57
|
+
if (!bucket) {
|
58
|
+
return res.status(500).send("Upload failed");
|
59
|
+
}
|
60
|
+
const buffer = Buffer.from(content, "utf-8");
|
61
|
+
const file = bucket.file(destination);
|
62
|
+
const stream = file.createWriteStream({
|
63
|
+
resumable: false,
|
64
|
+
contentType: "text/plain",
|
65
|
+
});
|
66
|
+
stream.on("error", err => {
|
67
|
+
console.error("❌ Error uploading:", err);
|
68
|
+
res.status(500).send("Upload failed");
|
69
|
+
});
|
70
|
+
stream.on("finish", () => {
|
71
|
+
console.log(`✅ Uploaded to: ${file.name}`);
|
72
|
+
res.send("File uploaded successfully");
|
73
|
+
});
|
74
|
+
stream.end(buffer);
|
75
|
+
});
|
76
|
+
app.get("/", async (req, res) => {
|
77
|
+
// The the ui/_app/index.html
|
78
|
+
console.log("GET /");
|
79
|
+
const file = path.resolve(__dirname, "../ui/_app/index.html");
|
80
|
+
res.sendFile(file);
|
81
|
+
});
|
82
|
+
app.get("/config", async (req, res) => {
|
83
|
+
console.log("GET /config");
|
84
|
+
console.log(req.query.slug, "QUERY");
|
85
|
+
const files = await listFilesWithPrefix("courses/" + req.query.slug);
|
86
|
+
const learnJson = files.find(file => file.name.endsWith("learn.json"));
|
87
|
+
const learnJsonContent = await (learnJson === null || learnJson === void 0 ? void 0 : learnJson.download());
|
88
|
+
const learnJsonParsed = JSON.parse((learnJsonContent === null || learnJsonContent === void 0 ? void 0 : learnJsonContent.toString()) || "{}");
|
89
|
+
const allExercises = files.filter(file => file.name.includes("exercises/"));
|
90
|
+
const exercises = allExercises.map(exercise => {
|
91
|
+
const slug = getSlugFromPath(exercise.name);
|
92
|
+
return {
|
93
|
+
title: slug,
|
94
|
+
slug,
|
95
|
+
graded: false,
|
96
|
+
};
|
97
|
+
});
|
98
|
+
// console.log(learnJsonParsed, "LEARN JSON PARSED")
|
99
|
+
res.send({
|
100
|
+
config: Object.assign({}, learnJsonParsed),
|
101
|
+
exercises,
|
102
|
+
});
|
103
|
+
});
|
104
|
+
app.get("/exercise/:slug/readme", async (req, res) => {
|
105
|
+
console.log("GET /exercise/:slug/readme");
|
106
|
+
const { slug } = req.params;
|
107
|
+
const query = req.query;
|
108
|
+
console.log(query, "QUERY");
|
109
|
+
const courseSlug = query.slug;
|
110
|
+
const file = await bucket.file("courses/" + courseSlug + "/exercises/" + slug + "/README.md");
|
111
|
+
const content = await file.download();
|
112
|
+
const { attributes, body } = frontMatter(content[0].toString());
|
113
|
+
res.send({
|
114
|
+
attributes,
|
115
|
+
body,
|
116
|
+
});
|
117
|
+
});
|
118
|
+
app.get("/assets/:file", (req, res) => {
|
119
|
+
const file = path.join(localAppPath, req.params.file);
|
120
|
+
res.sendFile(file);
|
121
|
+
});
|
122
|
+
// Enviar index.html para todas las rutas
|
123
|
+
app.get("/creator", (req, res) => {
|
124
|
+
res.sendFile(path.join(distPath, "index.html"));
|
125
|
+
});
|
126
|
+
app.get("/creator/syllabus", (req, res) => {
|
127
|
+
res.sendFile(path.join(distPath, "index.html"));
|
128
|
+
});
|
129
|
+
app.get("/creator/:file", (req, res) => {
|
130
|
+
console.log("GET /creator/:file", req.params.file);
|
131
|
+
const file = path.join(distPath, req.params.file);
|
132
|
+
res.sendFile(file);
|
133
|
+
});
|
134
|
+
app.get("/creator/assets/:file", (req, res) => {
|
135
|
+
const file = path.join(distPath, "assets", req.params.file);
|
136
|
+
res.sendFile(file);
|
137
|
+
});
|
138
|
+
app.listen(PORT, () => {
|
139
|
+
console.log(`🚀 Creator UI server running at http://localhost:${PORT}`);
|
140
|
+
});
|
141
|
+
}
|
142
|
+
}
|
143
|
+
ServeCommand.description = "Runs a small server to build tutorials";
|
144
|
+
ServeCommand.flags = Object.assign(Object.assign({}, SessionCommand_1.default.flags), { port: command_1.flags.string({ char: "p", description: "server port" }), host: command_1.flags.string({ char: "h", description: "server host" }), debug: command_1.flags.boolean({
|
145
|
+
char: "d",
|
146
|
+
description: "debugger mode for more verbage",
|
147
|
+
default: false,
|
148
|
+
}) });
|
149
|
+
exports.default = ServeCommand;
|
@@ -14,6 +14,7 @@ const telemetry_1 = require("../telemetry");
|
|
14
14
|
const creatorUtilities_1 = require("../../utils/creatorUtilities");
|
15
15
|
const rigoActions_1 = require("../../utils/rigoActions");
|
16
16
|
const sidebarGenerator_1 = require("../../utils/sidebarGenerator");
|
17
|
+
const path = require("path");
|
17
18
|
// import { eventManager } from "../../utils/osOperations"
|
18
19
|
const withHandler = (func) => (req, res) => {
|
19
20
|
try {
|
@@ -373,4 +374,5 @@ async function default_1(app, configObject, configManager) {
|
|
373
374
|
app.use("/preview", express.static(config.outputPath));
|
374
375
|
}
|
375
376
|
app.use("/", express.static(`${config === null || config === void 0 ? void 0 : config.dirPath}/_app`));
|
377
|
+
app.use("/creator", express.static(path.join(__dirname, "..", "creatorDist")));
|
376
378
|
}
|
package/lib/utils/api.js
CHANGED
@@ -327,7 +327,7 @@ const createAsset = async (token, academyId, asset) => {
|
|
327
327
|
title: asset.title,
|
328
328
|
lang: asset.lang,
|
329
329
|
asset_type: "EXERCISE",
|
330
|
-
visibility: "
|
330
|
+
visibility: "PUBLIC",
|
331
331
|
status: "DRAFT",
|
332
332
|
url: "https://4geeksacademy.com",
|
333
333
|
readme_url: null,
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { Bucket } from "@google-cloud/storage";
|
2
|
+
/**
|
3
|
+
* Sube contenido de texto directamente a un bucket de GCS.
|
4
|
+
* @param bucket Instancia de Bucket
|
5
|
+
* @param destination Ruta destino dentro del bucket (incluye carpeta/nombre)
|
6
|
+
* @param textContent Contenido textual a subir
|
7
|
+
*/
|
8
|
+
export declare function uploadTextToBucket(bucket: Bucket, destination: string, textContent: string): Promise<void>;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.uploadTextToBucket = uploadTextToBucket;
|
4
|
+
/**
|
5
|
+
* Sube contenido de texto directamente a un bucket de GCS.
|
6
|
+
* @param bucket Instancia de Bucket
|
7
|
+
* @param destination Ruta destino dentro del bucket (incluye carpeta/nombre)
|
8
|
+
* @param textContent Contenido textual a subir
|
9
|
+
*/
|
10
|
+
async function uploadTextToBucket(bucket, destination, textContent) {
|
11
|
+
const file = bucket.file(destination);
|
12
|
+
await file.save(textContent, {
|
13
|
+
resumable: false,
|
14
|
+
contentType: "text/plain",
|
15
|
+
});
|
16
|
+
console.log(`✅ Texto subido a gs://${bucket.name}/${destination}`);
|
17
|
+
}
|
package/oclif.manifest.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":"5.0.
|
1
|
+
{"version":"5.0.57","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":{"strict":{"name":"strict","type":"boolean","char":"s","description":"strict mode","allowNo":false}},"args":[]},"breakToken":{"id":"breakToken","description":"Break the token","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"grading":{"name":"grading","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"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":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"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":"Builds the project by copying necessary files and directories into a zip file","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"strict":{"name":"strict","type":"boolean","char":"s","description":"strict mode","allowNo":false},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"serve":{"id":"serve","description":"Runs a small server to build tutorials","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"port":{"name":"port","type":"option","char":"p","description":"server port"},"host":{"name":"host","type":"option","char":"h","description":"server host"},"debug":{"name":"debug","type":"boolean","char":"d","description":"debugger mode for more verbage","allowNo":false}},"args":[]},"start":{"id":"start","description":"Runs a small server with all the exercise instructions","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"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":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false}},"args":[{"name":"exerciseSlug","description":"The name of the exercise to test","required":false,"hidden":false}]},"translate":{"id":"translate","description":"List all the lessons, the user is able of select many of them to translate to the given languages","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false}},"args":[]}}}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@learnpack/learnpack",
|
3
3
|
"description": "Seamlessly build, sell and/or take interactive & auto-graded tutorials, start learning now or build a new tutorial to your audience.",
|
4
|
-
"version": "5.0.
|
4
|
+
"version": "5.0.57",
|
5
5
|
"author": "Alejandro Sanchez @alesanchezr",
|
6
6
|
"contributors": [
|
7
7
|
{
|
@@ -21,6 +21,7 @@
|
|
21
21
|
"url": "https://github.com/learnpack/learnpack-cli/issues"
|
22
22
|
},
|
23
23
|
"dependencies": {
|
24
|
+
"@google-cloud/storage": "^7.16.0",
|
24
25
|
"@oclif/command": "^1.6.1",
|
25
26
|
"@oclif/config": "^1.15.1",
|
26
27
|
"@oclif/plugin-help": "^3.1.0",
|
@@ -33,6 +34,7 @@
|
|
33
34
|
"chalk": "^4.1.0",
|
34
35
|
"chokidar": "^3.4.0",
|
35
36
|
"cli-ux": "^5.4.6",
|
37
|
+
"cors": "^2.8.5",
|
36
38
|
"debounce": "^1.2.0",
|
37
39
|
"dotenv": "^8.2.0",
|
38
40
|
"enquirer": "^2.3.6",
|
@@ -0,0 +1,192 @@
|
|
1
|
+
import { flags } from "@oclif/command"
|
2
|
+
import * as express from "express"
|
3
|
+
import * as cors from "cors"
|
4
|
+
import * as path from "path"
|
5
|
+
import SessionCommand from "../utils/SessionCommand"
|
6
|
+
import { Storage } from "@google-cloud/storage"
|
7
|
+
import { downloadEditor, decompress } from "../managers/file"
|
8
|
+
import * as fs from "fs"
|
9
|
+
const frontMatter = require("front-matter")
|
10
|
+
|
11
|
+
function getSlugFromPath(path: string) {
|
12
|
+
const parts = path.split("/").filter(Boolean)
|
13
|
+
if (parts.length < 2)
|
14
|
+
return null
|
15
|
+
return parts[parts.length - 2]
|
16
|
+
}
|
17
|
+
|
18
|
+
const bucketStorage = new Storage({
|
19
|
+
keyFilename: path.resolve(__dirname, "../utils/creds.json"),
|
20
|
+
})
|
21
|
+
const bucket = bucketStorage.bucket("learnpack")
|
22
|
+
|
23
|
+
async function listFilesWithPrefix(prefix: string) {
|
24
|
+
const [files] = await bucket.getFiles({ prefix })
|
25
|
+
return files
|
26
|
+
}
|
27
|
+
|
28
|
+
export default class ServeCommand extends SessionCommand {
|
29
|
+
static description = "Runs a small server to build tutorials"
|
30
|
+
|
31
|
+
static flags = {
|
32
|
+
...SessionCommand.flags,
|
33
|
+
port: flags.string({ char: "p", description: "server port" }),
|
34
|
+
host: flags.string({ char: "h", description: "server host" }),
|
35
|
+
debug: flags.boolean({
|
36
|
+
char: "d",
|
37
|
+
description: "debugger mode for more verbage",
|
38
|
+
default: false,
|
39
|
+
}),
|
40
|
+
}
|
41
|
+
|
42
|
+
async init() {
|
43
|
+
const { flags } = this.parse(ServeCommand)
|
44
|
+
console.log("Initializing serve command")
|
45
|
+
}
|
46
|
+
|
47
|
+
async run() {
|
48
|
+
const app = express()
|
49
|
+
const PORT = 3000
|
50
|
+
|
51
|
+
const distPath = path.resolve(__dirname, "../creatorDist")
|
52
|
+
|
53
|
+
// Servir archivos estáticos
|
54
|
+
// app.use(express.static(distPath))
|
55
|
+
app.use(express.json())
|
56
|
+
app.use(cors())
|
57
|
+
|
58
|
+
const appPath = path.resolve(__dirname, "../ui/_app")
|
59
|
+
const tarPath = path.resolve(__dirname, "../ui/app.tar.gz")
|
60
|
+
if (fs.existsSync(appPath)) {
|
61
|
+
fs.rmSync(appPath, { recursive: true })
|
62
|
+
}
|
63
|
+
|
64
|
+
if (fs.existsSync(tarPath)) {
|
65
|
+
fs.rmSync(tarPath)
|
66
|
+
}
|
67
|
+
|
68
|
+
await downloadEditor("5.0.0", `${__dirname}/../ui/app.tar.gz`)
|
69
|
+
|
70
|
+
await decompress(
|
71
|
+
`${__dirname}/../ui/app.tar.gz`,
|
72
|
+
`${__dirname}/../ui/_app/`
|
73
|
+
)
|
74
|
+
|
75
|
+
const localAppPath = path.resolve(__dirname, "../ui/_app")
|
76
|
+
// app.use(express.static(localAppPath))
|
77
|
+
|
78
|
+
app.post("/upload", async (req, res) => {
|
79
|
+
const { content, destination } = req.body
|
80
|
+
// console.log("UPLOAD", content, destination)
|
81
|
+
|
82
|
+
if (!content || !destination) {
|
83
|
+
return res.status(400).send("Missing content or destination")
|
84
|
+
}
|
85
|
+
|
86
|
+
if (!bucket) {
|
87
|
+
return res.status(500).send("Upload failed")
|
88
|
+
}
|
89
|
+
|
90
|
+
const buffer = Buffer.from(content, "utf-8")
|
91
|
+
const file = bucket.file(destination)
|
92
|
+
|
93
|
+
const stream = file.createWriteStream({
|
94
|
+
resumable: false,
|
95
|
+
contentType: "text/plain",
|
96
|
+
})
|
97
|
+
|
98
|
+
stream.on("error", err => {
|
99
|
+
console.error("❌ Error uploading:", err)
|
100
|
+
res.status(500).send("Upload failed")
|
101
|
+
})
|
102
|
+
|
103
|
+
stream.on("finish", () => {
|
104
|
+
console.log(`✅ Uploaded to: ${file.name}`)
|
105
|
+
res.send("File uploaded successfully")
|
106
|
+
})
|
107
|
+
|
108
|
+
stream.end(buffer)
|
109
|
+
})
|
110
|
+
|
111
|
+
app.get("/", async (req, res) => {
|
112
|
+
// The the ui/_app/index.html
|
113
|
+
console.log("GET /")
|
114
|
+
|
115
|
+
const file = path.resolve(__dirname, "../ui/_app/index.html")
|
116
|
+
res.sendFile(file)
|
117
|
+
})
|
118
|
+
|
119
|
+
app.get("/config", async (req, res) => {
|
120
|
+
console.log("GET /config")
|
121
|
+
console.log(req.query.slug, "QUERY")
|
122
|
+
const files = await listFilesWithPrefix("courses/" + req.query.slug)
|
123
|
+
|
124
|
+
const learnJson = files.find(file => file.name.endsWith("learn.json"))
|
125
|
+
|
126
|
+
const learnJsonContent = await learnJson?.download()
|
127
|
+
const learnJsonParsed = JSON.parse(learnJsonContent?.toString() || "{}")
|
128
|
+
const allExercises = files.filter(file =>
|
129
|
+
file.name.includes("exercises/")
|
130
|
+
)
|
131
|
+
const exercises = allExercises.map(exercise => {
|
132
|
+
const slug = getSlugFromPath(exercise.name)
|
133
|
+
return {
|
134
|
+
title: slug,
|
135
|
+
slug,
|
136
|
+
graded: false,
|
137
|
+
}
|
138
|
+
})
|
139
|
+
// console.log(learnJsonParsed, "LEARN JSON PARSED")
|
140
|
+
|
141
|
+
res.send({
|
142
|
+
config: { ...learnJsonParsed },
|
143
|
+
exercises,
|
144
|
+
})
|
145
|
+
})
|
146
|
+
|
147
|
+
app.get("/exercise/:slug/readme", async (req, res) => {
|
148
|
+
console.log("GET /exercise/:slug/readme")
|
149
|
+
const { slug } = req.params
|
150
|
+
const query = req.query
|
151
|
+
console.log(query, "QUERY")
|
152
|
+
const courseSlug = query.slug
|
153
|
+
|
154
|
+
const file = await bucket.file(
|
155
|
+
"courses/" + courseSlug + "/exercises/" + slug + "/README.md"
|
156
|
+
)
|
157
|
+
const content = await file.download()
|
158
|
+
const { attributes, body } = frontMatter(content[0].toString())
|
159
|
+
res.send({
|
160
|
+
attributes,
|
161
|
+
body,
|
162
|
+
})
|
163
|
+
})
|
164
|
+
|
165
|
+
app.get("/assets/:file", (req, res) => {
|
166
|
+
const file = path.join(localAppPath, req.params.file)
|
167
|
+
res.sendFile(file)
|
168
|
+
})
|
169
|
+
// Enviar index.html para todas las rutas
|
170
|
+
app.get("/creator", (req, res) => {
|
171
|
+
res.sendFile(path.join(distPath, "index.html"))
|
172
|
+
})
|
173
|
+
app.get("/creator/syllabus", (req, res) => {
|
174
|
+
res.sendFile(path.join(distPath, "index.html"))
|
175
|
+
})
|
176
|
+
|
177
|
+
app.get("/creator/:file", (req, res) => {
|
178
|
+
console.log("GET /creator/:file", req.params.file)
|
179
|
+
const file = path.join(distPath, req.params.file)
|
180
|
+
res.sendFile(file)
|
181
|
+
})
|
182
|
+
|
183
|
+
app.get("/creator/assets/:file", (req, res) => {
|
184
|
+
const file = path.join(distPath, "assets", req.params.file)
|
185
|
+
res.sendFile(file)
|
186
|
+
})
|
187
|
+
|
188
|
+
app.listen(PORT, () => {
|
189
|
+
console.log(`🚀 Creator UI server running at http://localhost:${PORT}`)
|
190
|
+
})
|
191
|
+
}
|
192
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# React + TypeScript + Vite
|
2
|
+
|
3
|
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
4
|
+
|
5
|
+
Currently, two official plugins are available:
|
6
|
+
|
7
|
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
|
8
|
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
9
|
+
|
10
|
+
## Expanding the ESLint configuration
|
11
|
+
|
12
|
+
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
13
|
+
|
14
|
+
```js
|
15
|
+
export default tseslint.config({
|
16
|
+
extends: [
|
17
|
+
// Remove ...tseslint.configs.recommended and replace with this
|
18
|
+
...tseslint.configs.recommendedTypeChecked,
|
19
|
+
// Alternatively, use this for stricter rules
|
20
|
+
...tseslint.configs.strictTypeChecked,
|
21
|
+
// Optionally, add this for stylistic rules
|
22
|
+
...tseslint.configs.stylisticTypeChecked,
|
23
|
+
],
|
24
|
+
languageOptions: {
|
25
|
+
// other options...
|
26
|
+
parserOptions: {
|
27
|
+
project: ["./tsconfig.node.json", "./tsconfig.app.json"],
|
28
|
+
tsconfigRootDir: import.meta.dirname,
|
29
|
+
},
|
30
|
+
},
|
31
|
+
})
|
32
|
+
```
|
33
|
+
|
34
|
+
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
35
|
+
|
36
|
+
```js
|
37
|
+
// eslint.config.js
|
38
|
+
import reactX from "eslint-plugin-react-x"
|
39
|
+
import reactDom from "eslint-plugin-react-dom"
|
40
|
+
|
41
|
+
export default tseslint.config({
|
42
|
+
plugins: {
|
43
|
+
// Add the react-x and react-dom plugins
|
44
|
+
"react-x": reactX,
|
45
|
+
"react-dom": reactDom,
|
46
|
+
},
|
47
|
+
rules: {
|
48
|
+
// other rules...
|
49
|
+
// Enable its recommended typescript rules
|
50
|
+
...reactX.configs["recommended-typescript"].rules,
|
51
|
+
...reactDom.configs.recommended.rules,
|
52
|
+
},
|
53
|
+
})
|
54
|
+
```
|