@politecnicoopenunixlabs/slidev-addon-code-runners 0.0.1 → 0.2.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 +8 -10
- package/package.json +4 -7
- package/setup/code-runners.ts +16 -35
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @politecnicoopenunixlabs/slidev-addon-
|
|
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,20 @@ 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:
|
|
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
|
|
18
|
+
Adds code runners to Monaco Editor in your slides. Currently, it supports the following languages:
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
println!("Sum of squares: {sum}");
|
|
24
|
-
}
|
|
25
|
-
```</code></pre>
|
|
20
|
+
- Rust (`rust`)
|
|
21
|
+
- Kotlin (`kotlin`)
|
|
22
|
+
- Brainfuck (`brainfuck`)
|
|
23
|
+
- Go (`go`)
|
|
26
24
|
|
|
27
25
|
## Contributing
|
|
28
26
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@politecnicoopenunixlabs/slidev-addon-code-runners",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.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
|
-
|
|
55
|
-
}
|
|
51
|
+
}
|
|
52
|
+
}
|
package/setup/code-runners.ts
CHANGED
|
@@ -1,41 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { CodeRunnerProviders, CodeRunnersSetup } from "@slidev/types"
|
|
2
|
+
import { defineCodeRunnersSetup } from "@slidev/types"
|
|
2
3
|
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
stdout?: string
|
|
6
|
-
stderr?: string
|
|
7
|
-
error?: string
|
|
4
|
+
type RunnerModule = {
|
|
5
|
+
default: CodeRunnersSetup
|
|
8
6
|
}
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
+
})
|