@learnpack/learnpack 5.0.29 → 5.0.30

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.
@@ -123,7 +123,7 @@ export const download = (url: string, dest: string) => {
123
123
  })
124
124
  file.on("error", err => {
125
125
  file.close()
126
- if (err.code === "EEXIST") {
126
+ if (err.name === "EEXIST") {
127
127
  Console.debug("File already exists")
128
128
  resolve("File already exists")
129
129
  } else {
@@ -381,6 +381,48 @@ throw new Error("File not found: " + filePath)
381
381
  })
382
382
  )
383
383
 
384
+ app.delete(
385
+ "/exercise/:slug/delete",
386
+ withHandler(async (req: express.Request, res: express.Response) => {
387
+ const exerciseDeleted = configManager.deleteExercise(req.params.slug)
388
+ if (exerciseDeleted) {
389
+ configManager.buildIndex()
390
+ res.json({ status: "ok" })
391
+ } else {
392
+ res.status(500).json({ error: "Failed to delete exercise" })
393
+ }
394
+ })
395
+ )
396
+
397
+ app.post(
398
+ "/exercise/:slug/create",
399
+ jsonBodyParser,
400
+ withHandler(async (req: express.Request, res: express.Response) => {
401
+ const { title, readme, language } = req.body
402
+ const { slug } = req.params
403
+
404
+ if (!title || !readme || !language) {
405
+ return res.status(400).json({ error: "Missing required fields" })
406
+ }
407
+
408
+ try {
409
+ const exerciseCreated = await configManager.createExercise(
410
+ slug,
411
+ readme,
412
+ language
413
+ )
414
+ if (exerciseCreated) {
415
+ configManager.buildIndex()
416
+ res.json({ status: "ok" })
417
+ } else {
418
+ res.status(500).json({ error: "Failed to create exercise" })
419
+ }
420
+ } catch {
421
+ res.status(500).json({ error: "Failed to create exercise" })
422
+ }
423
+ })
424
+ )
425
+
384
426
  const textBodyParser = bodyParser.text()
385
427
  app.put(
386
428
  "/exercise/:slug/file/:fileName",
@@ -163,6 +163,10 @@ const Session: ISession = {
163
163
  }
164
164
  },
165
165
  destroy: async function () {
166
+ if (!this.sessionStarted) {
167
+ await this.initialize()
168
+ }
169
+
166
170
  await storage.clear()
167
171
  this.token = null
168
172
  Console.success("You have logged out")
@@ -1,23 +1,25 @@
1
- import { IConfigObj, TGrading } from "./config"
2
- import { IExercise } from "./exercise-obj"
3
-
4
- export interface IConfigManagerAttributes {
5
- grading: TGrading;
6
- disableGrading: boolean;
7
- version: string;
8
- mode?: string;
9
- }
10
-
11
- export interface IConfigManager {
12
- validLanguages?: any;
13
- get: () => IConfigObj;
14
- clean: () => void;
15
- getExercise: (slug: string | undefined) => IExercise;
16
- startExercise: (slug: string) => IExercise;
17
- reset: (slug: string) => void;
18
- buildIndex: () => boolean | void;
19
- watchIndex: (onChange: (...args: Array<any>) => void) => void;
20
- save: () => void;
21
- noCurrentExercise: () => void;
22
- getAllExercises: () => IExercise[];
23
- }
1
+ import { IConfigObj, TGrading } from "./config"
2
+ import { IExercise } from "./exercise-obj"
3
+
4
+ export interface IConfigManagerAttributes {
5
+ grading: TGrading
6
+ disableGrading: boolean
7
+ version: string
8
+ mode?: string
9
+ }
10
+
11
+ export interface IConfigManager {
12
+ validLanguages?: any
13
+ get: () => IConfigObj
14
+ clean: () => void
15
+ getExercise: (slug: string | undefined) => IExercise
16
+ startExercise: (slug: string) => IExercise
17
+ reset: (slug: string) => void
18
+ createExercise: (slug: string, content: string, language: string) => boolean
19
+ deleteExercise: (slug: string) => boolean
20
+ buildIndex: () => boolean | void
21
+ watchIndex: (onChange: (...args: Array<any>) => void) => void
22
+ save: () => void
23
+ noCurrentExercise: () => void
24
+ getAllExercises: () => IExercise[]
25
+ }
@@ -0,0 +1,29 @@
1
+ # This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
+
4
+ name: Learnpack audit
5
+
6
+ on:
7
+ push:
8
+ branches: [ main ]
9
+ pull_request:
10
+ branches: [ main ]
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+
17
+ strategy:
18
+ matrix:
19
+ node-version: [20.x]
20
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21
+
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ - name: Use Node.js ${{ matrix.node-version }}
25
+ uses: actions/setup-node@v2
26
+ with:
27
+ node-version: ${{ matrix.node-version }}
28
+ - run: npm install @learnpack/learnpack@latest -g
29
+ - run: learnpack audit
@@ -0,0 +1,29 @@
1
+ # This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
+
4
+ name: Learnpack audit
5
+
6
+ on:
7
+ push:
8
+ branches: [ main ]
9
+ pull_request:
10
+ branches: [ main ]
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+
17
+ strategy:
18
+ matrix:
19
+ node-version: [20.x]
20
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21
+
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+ - name: Use Node.js ${{ matrix.node-version }}
25
+ uses: actions/setup-node@v2
26
+ with:
27
+ node-version: ${{ matrix.node-version }}
28
+ - run: npm install @learnpack/learnpack@latest -g
29
+ - run: learnpack audit