https://github.com/objectionary/eo2js
EOLANG to JavaScript transpiler and runtime
https://github.com/objectionary/eo2js
eolang javascript oop
Last synced: 3 months ago
JSON representation
EOLANG to JavaScript transpiler and runtime
- Host: GitHub
- URL: https://github.com/objectionary/eo2js
- Owner: objectionary
- License: mit
- Created: 2024-05-10T12:32:18.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2025-04-18T19:14:08.000Z (about 1 year ago)
- Last Synced: 2025-04-19T07:45:58.799Z (about 1 year ago)
- Topics: eolang, javascript, oop
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/eo2js
- Size: 655 KB
- Stars: 9
- Watchers: 4
- Forks: 5
- Open Issues: 27
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# eo2js
[](https://www.elegantobjects.org)
[](https://www.jetbrains.com/idea/)
[](https://github.com/objectionary/eo2js/actions/workflows/test.yml)
[](https://hitsofcode.com/view/github/objectionary/eo2js)
[](LICENSE.txt)
Command-line toolkit and runtime that takes **EO XMIR + `eo-foreign.json`**
(usually in `.eoc/`) and turns them into a **Node.js project** you can run or
test. It does **not** read `.eo` directly — you must generate XMIR first.
## EO version
Built and tested with EO version `0.59.0`
([eo2js/test/mvnw/eo-version.txt](https://github.com/objectionary/eo2js/blob/master/eo2js/test/mvnw/eo-version.txt)).
Using other versions may lead to unpredictable results.
## Prerequisites
- Node.js 20+ and npm
- Java + Maven (if you generate XMIR via `eo-maven-plugin`; other EO toolchains
like `eoc` are fine too)
## Install (CLI users)
```bash
npm install -g eo2js
```
## Getting `.eoc` (XMIR + foreign)
Use any EO toolchain to compile `.eo` into `.eoc`.
Example with EO Maven plugin:
```bash
mvn org.eolang:eo-maven-plugin:register \
org.eolang:eo-maven-plugin:parse \
org.eolang:eo-maven-plugin:lint \
-Deo.sourcesDir=src \
-Deo.targetDir=.eoc \
-Deo.failOnWarning=false
```
After that, `.eoc/eo-foreign.json` and XMIR files are ready for eo2js.
## Core commands
- `transpile` — convert XMIR from `eo-foreign.json` to JS under `/`
- `link` — build npm project (`package.json`, deps, `__main__.js`)
- `dataize [args...]` — transpile+link (unless `--alone`) and run the
EO object
- `test` — transpile+link (unless `--alone`) and run EO tests generated from
XMIR with `+tests`
Common options: `-t/--target` `.eoc` dir (default `.eoc`), `-p/--project`
JS subdir (default `project`), `-f/--foreign` path to `eo-foreign.json`
(default `eo-foreign.json` in target), `-r/--resources` path to eo2js resources
(only needed when running from a clone), `-d/--dependency` path to local
`eo2js-runtime`, `--alone` to skip automatic prerequisites.
## Typical workflow (global install)
```bash
# After generating .eoc:
eo2js dataize org.eo2js.demo.main -t .eoc -p project
# If transpile/link already done:
eo2js dataize org.eo2js.demo.main --alone -t .eoc -p project
```
If you use the defaults (`.eoc` and `project`), you can omit `-t`/`-p`.
## Minimal EO example
Create `hello/main.eo` (any folder name is fine):
```eo
+package hello
+home https://example.com
+version 0.1.0
[] > main
"Hello from eo2js!" > @
```
Compile to `.eoc` from the folder where `hello/` lives:
```bash
mvn org.eolang:eo-maven-plugin:register \
org.eolang:eo-maven-plugin:parse \
org.eolang:eo-maven-plugin:lint \
-Deo.sourcesDir=hello \
-Deo.targetDir=.eoc \
-Deo.failOnWarning=false
```
Then run via eo2js:
```bash
eo2js dataize hello.main -t .eoc -p project
```
## From this repo without global install
```bash
NODE_PATH=eo2js/node_modules \
node eo2js/src/eo2js.js dataize org.eo2js.demo.main \
-t readme-demo/.eoc -p project \
-r eo2js/src/resources \
-d eo2js-runtime
```
(`-r`/`-d` point to local resources/runtime; omit if installed globally.)
## How to Contribute
First, run `npm install`. Then, run `npm test`. All tests should pass.
Make your changes and then
[make](https://www.yegor256.com/2014/04/15/github-guidelines.html)
a pull request.