@politecnicoopenunixlabs/slidev-addon-code-runners 0.0.1 → 0.1.0

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 CHANGED
@@ -1,4 +1,4 @@
1
- # @politecnicoopenunixlabs/slidev-addon-rust-runner
1
+ # @politecnicoopenunixlabs/slidev-addon-code-runners
2
2
 
3
3
  A [Politecnico Open unix Labs](https://poul.org) addon for [Slidev](https://github.com/slidevjs/slidev).
4
4
 
@@ -7,22 +7,19 @@ A [Politecnico Open unix Labs](https://poul.org) addon for [Slidev](https://gith
7
7
  Add the following frontmatter to your `slides.md`. Start Slidev then it will prompt you to install the theme automatically.
8
8
 
9
9
  <pre><code>---
10
- addons: <b>@politecnicoopenunixlabs/slidev-addon-rust-runner</b>
10
+ addons:
11
+ - <b>@politecnicoopenunixlabs/slidev-addon-code-runners</b>
11
12
  ---</code></pre>
12
13
 
13
14
  Learn more about [how to use a addon](https://sli.dev/guide/theme-addon#use-addon).
14
15
 
15
16
  ## Features
16
17
 
17
- Adds a new Monaco code runner for Rust code blocks. You can use it like this:
18
+ Adds code runners to Monaco Editor in your slides. Currently, it supports the following languages:
18
19
 
19
- <pre><code>```rust {monaco-run} {autorun:false}
20
- fn main() {
21
- let v: Vec<i32> = (1..=5).collect();
22
- let sum: i32 = v.iter().map(|x| x * x).sum();
23
- println!("Sum of squares: {sum}");
24
- }
25
- ```</code></pre>
20
+ - Rust (`rust`)
21
+ - Kotlin (`kotlin`)
22
+ - Brainfuck (`brainfuck`)
26
23
 
27
24
  ## Contributing
28
25
 
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@politecnicoopenunixlabs/slidev-addon-code-runners",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "keywords": [
5
5
  "slidev-addon",
6
6
  "slidev"
7
7
  ],
8
- "private": false,
9
8
  "repository": {
10
9
  "type": "git",
11
10
  "url": "https://gitlab.poul.org/corsi/templates/slidev-addon-code-runners.git"
@@ -22,8 +21,7 @@
22
21
  "lint": "eslint './**/*.ts'",
23
22
  "lint:fix": "eslint --fix './**/*.ts'",
24
23
  "pack": "bun pm pack --ignore-scripts",
25
- "prepare": "simple-git-hooks",
26
- "publish": "bun publish --ignore-scripts"
24
+ "prepare": "simple-git-hooks"
27
25
  },
28
26
  "simple-git-hooks": {
29
27
  "pre-commit": "bun run lint-staged",
@@ -50,6 +48,5 @@
50
48
  "engines": {
51
49
  "node": ">=24.0.0",
52
50
  "slidev": ">=52.0.0"
53
- },
54
- "packageManager": "npm@12.2.2+sha512.2a09606d9c9a71fee31fe147b8d46a56e0b3422f15848d9aec9f3b231e3716c3d3b99a065a62175c6759b4150e03bf6fc0bf8825112a511573ba903b3ec41370"
51
+ }
55
52
  }
@@ -1,41 +1,22 @@
1
- import { defineCodeRunnersSetup } from '@slidev/types'
1
+ import type { CodeRunnerProviders, CodeRunnersSetup } from "@slidev/types"
2
+ import { defineCodeRunnersSetup } from "@slidev/types"
2
3
 
3
- type RustCodeRunnerResponse = {
4
- success: boolean
5
- stdout?: string
6
- stderr?: string
7
- error?: string
4
+ type RunnerModule = {
5
+ default: CodeRunnersSetup
8
6
  }
9
7
 
10
- export default defineCodeRunnersSetup(() => {
11
- return {
12
- async rust(code) {
13
- try {
14
- const res = await fetch('https://play.rust-lang.org/execute', {
15
- method: 'POST',
16
- headers: { 'Content-Type': 'application/json' },
17
- body: JSON.stringify({
18
- channel: 'stable',
19
- mode: 'debug',
20
- edition: '2021',
21
- crateType: 'bin',
22
- tests: false,
23
- backtrace: false,
24
- code: code,
25
- }),
26
- })
8
+ // This basically just imports all the code runners in the `runners` folder and registers them with Slidev.
9
+ export default defineCodeRunnersSetup(async runners => {
10
+ const runnerModules = import.meta.glob<RunnerModule>("../runners/*.ts", { eager: true })
27
11
 
28
- const data = (await res.json()) as RustCodeRunnerResponse
12
+ const providers = await Promise.all(
13
+ Object.values(runnerModules).map(({ default: setup }) => Promise.resolve(setup(runners)))
14
+ )
15
+ const result: CodeRunnerProviders = {}
29
16
 
30
- if (data.success)
31
- return { text: data.stdout || '(no output)' }
32
-
33
- return { error: data.stderr || data.error || 'Unknown error' }
34
- }
35
- catch (e) {
36
- const message = e instanceof Error ? e.message : String(e)
37
- return { error: `Request failed: ${message}` }
38
- }
39
- },
17
+ for (const provider of providers) {
18
+ if (provider) Object.assign(result, provider)
40
19
  }
41
- })
20
+
21
+ return result
22
+ })