Skip to content

Commit 58c3213

Browse files
committed
add evaluator component and deploy workflow
1 parent c6081e5 commit 58c3213

File tree

7 files changed

+710
-444
lines changed

7 files changed

+710
-444
lines changed

.github/workflows/build-deploy.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Build and deploy runner
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
build:
9+
name: Build runner
10+
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Enable corepack
18+
run: corepack enable
19+
20+
- name: Setup node
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 22
24+
cache: yarn
25+
26+
- name: yarn install
27+
run: yarn install --immutable
28+
29+
- name: yarn build
30+
run: yarn build
31+
32+
- name: Upload artifacts
33+
id: deployment
34+
uses: actions/upload-pages-artifact@v3
35+
with:
36+
path: dist/
37+
38+
deploy:
39+
needs: build
40+
41+
name: Deploy runner
42+
43+
permissions:
44+
pages: write
45+
id-token: write
46+
47+
environment:
48+
name: github-pages
49+
url: ${{ steps.deployment.outputs.page_url }}
50+
51+
runs-on: ubuntu-latest
52+
53+
steps:
54+
- name: Deploy to GitHub Pages
55+
id: deployment
56+
uses: actions/deploy-pages@v4

package.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
"scripts": {
4848
"build": "yarn docs && yarn build:slang",
49-
"build:slang": "tsc --project tsconfig.prod.json",
49+
"build:slang": "rollup -c",
5050
"prepack": "yarn build",
5151
"eslint": "eslint src",
5252
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
@@ -64,12 +64,20 @@
6464
"devDependencies": {
6565
"@babel/core": "^7.26.10",
6666
"@babel/preset-env": "^7.23.2",
67+
"@rollup/plugin-alias": "^5.1.0",
68+
"@rollup/plugin-commonjs": "^26.0.1",
69+
"@rollup/plugin-json": "^6.1.0",
70+
"@rollup/plugin-node-resolve": "^16.0.0",
71+
"@rollup/plugin-terser": "^0.4.4",
72+
"@rollup/plugin-typescript": "^12.1.2",
6773
"@types/babel__core": "^7",
6874
"@types/jest": "^29.0.0",
6975
"@types/lodash": "^4.14.202",
7076
"@types/node": "^20.0.0",
7177
"@types/offscreencanvas": "^2019.7.0",
78+
"@types/path-browserify": "^1.0.1",
7279
"ace-builds": "~1.17.0",
80+
"conductor": "https://github.com/source-academy/conductor.git#0.2.1",
7381
"coveralls": "^3.1.0",
7482
"escodegen": "^2.0.0",
7583
"eslint": "^8.57.0",
@@ -81,9 +89,13 @@
8189
"jest-html-reporter": "^3.2.0",
8290
"jsdoc": "3.6.11",
8391
"jsdom": "^19.0.0",
92+
"path-browserify": "^1.0.1",
8493
"prettier": "^3.5.2",
94+
"rollup": "^4.34.1",
95+
"rollup-plugin-polyfill-node": "^0.13.0",
8596
"ts-jest": "^29.0.0",
86-
"typescript": "^4.0.3",
97+
"tslib": "^2.8.1",
98+
"typescript": "^5.5.3",
8799
"typescript-eslint": "^8.8.1"
88100
},
89101
"devEngines": {
@@ -111,17 +123,14 @@
111123
"testRegex": "/__tests__/.*\\.ts$",
112124
"testPathIgnorePatterns": [
113125
"/dist/",
114-
"/src/alt-langs/scheme/scm-slang",
115126
".*benchmark.*",
116127
"/__tests__/(.*/)?utils\\.ts"
117128
],
118129
"coveragePathIgnorePatterns": [
119130
"/dist/",
120131
"/node_modules/",
121132
"/src/typings/",
122-
"/src/utils/testing.ts",
123-
"/src/alt-langs/scheme/scm-slang",
124-
"/src/py-slang/"
133+
"/src/utils/testing.ts"
125134
],
126135
"reporters": [
127136
"default",

rollup.config.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import alias from "@rollup/plugin-alias";
2+
import commonjs from "@rollup/plugin-commonjs";
3+
import json from "@rollup/plugin-json";
4+
import nodeResolve from "@rollup/plugin-node-resolve";
5+
import terser from "@rollup/plugin-terser";
6+
import typescript from "@rollup/plugin-typescript";
7+
import nodePolyfills from "rollup-plugin-polyfill-node";
8+
9+
export default {
10+
plugins: [alias({ entries: [{ find: "path", replacement: "path-browserify" }] }), nodeResolve(), commonjs(), typescript(), json(), nodePolyfills()],
11+
input: "src/evaluator.ts",
12+
output: {
13+
plugins: [terser()],
14+
dir: "dist",
15+
format: "iife",
16+
sourcemap: true,
17+
}
18+
}

src/evaluator.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { BasicEvaluator } from "conductor/dist/conductor/runner";
2+
import { IRunnerPlugin } from "conductor/dist/conductor/runner/types";
3+
import { initialise } from "conductor/dist/conductor/runner/util";
4+
import { Context, runInContext, createContext } from "./index";
5+
import { Value, Chapter, Variant } from "./types";
6+
7+
class JsSlangEvaluator extends BasicEvaluator {
8+
private ctx: Context;
9+
10+
async evaluateChunk(chunk: string): Promise<void> {
11+
const res = await runInContext(chunk, this.ctx);
12+
if (res.status === "error") {
13+
console.error(res);
14+
} else {
15+
this.ctx = res.context;
16+
if (res.status === "finished") return res.value;
17+
}
18+
}
19+
20+
constructor(conductor: IRunnerPlugin) {
21+
super(conductor);
22+
23+
const rawDisplay = (value: Value, str: string, _externalContext: any) => {
24+
this.conductor.sendOutput((str === undefined ? '' : str + ' ') + String(value));
25+
return value;
26+
};
27+
28+
this.ctx = createContext(Chapter.SOURCE_4, Variant.DEFAULT, undefined, [], undefined, {
29+
rawDisplay: rawDisplay,
30+
prompt: rawDisplay,
31+
alert: rawDisplay,
32+
visualiseList: (_v: Value) => {
33+
throw new Error('List visualizer is not enabled')
34+
}
35+
});
36+
37+
console.log("Evaluator initialised!");
38+
}
39+
}
40+
41+
initialise(JsSlangEvaluator);

0 commit comments

Comments
 (0)