Skip to content

Commit

Permalink
Finalise names of everything in preparation for the first release
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpyder committed Apr 15, 2024
1 parent f726fc9 commit 7bc3168
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 119 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ jobs:
working-directory: test
shell: bash

- name: "[Test] npm run build (latest)"
- name: "[Test] npm run build (dev)"
run: npm run build
working-directory: test

- name: "[Test] Install latest"
- name: "[Test] Install last published version"
run: npm install @jchavarri/bs-atdgen-generator --save-dev
working-directory: test

Expand Down Expand Up @@ -167,10 +167,10 @@ jobs:
ls -la binaries/darwin
ls -la binaries/windows
ls -la binaries/linux
mv binaries/darwin-arm64/atdgen exe/bs-atdgen-generator-darwin-arm64.exe
mv binaries/darwin/atdgen exe/bs-atdgen-generator-darwin-x64.exe
mv binaries/windows/atdgen.exe exe/bs-atdgen-generator-win-x64.exe
mv binaries/linux/atdgen exe/bs-atdgen-generator-linux-x64.exe
mv binaries/darwin-arm64/atdgen exe/rescript-atdgen-generator-darwin-arm64.exe
mv binaries/darwin/atdgen exe/rescript-atdgen-generator-darwin-x64.exe
mv binaries/windows/atdgen.exe exe/rescript-atdgen-generator-win-x64.exe
mv binaries/linux/atdgen exe/rescript-atdgen-generator-linux-x64.exe
- name: Upload release artifacts
# if: github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/')
Expand Down
5 changes: 4 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
MIT License

Copyright (c) 2020 Javier Chávarri
Copyright (c) 2024 Andrew Herron

Previous maintainers:
- Copyright (c) 2020 Javier Chávarri

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
127 changes: 44 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,119 +1,80 @@
# Project is under migration
The installation instructions still point to the old binaries, the project has changed owners but I haven't had a chance to publish binaries under my name yet. Apologies.

# bs-atdgen-generator
# rescript-atdgen-generator

[Atdgen](https://github.com/ahrefs/atd) prebuilt binaries for 3 major OS platforms.

This is capped at version 2.15.0, after that
This is capped at version 2.15.0, after which BuckleScript support (which ReScript relies on) was removed.
https://github.com/ahrefs/atd/pull/375

If `atd` proves to be a popular tool for ReScript projects it can be restored fairly easily.

## Getting started

(Prefer example? Check the [test](./test) folder)

With yarn:
### Runtime library installation

```
yarn add -D @jchavarri/bs-atdgen-generator
yarn --check-files
```
This tool will not work without a library that implements the ATD BuckleScript runtime API. A ReScript implementation is in progress, in the meantime [`bs-atdgen-codec-runtime`](https://www.npmjs.com/package/@ahrefs/bs-atdgen-codec-runtime) still works - but not on ReScript 11.

Tell bsb which files need to be processed:
### Generator installation

```json
"generators": [
{
"name": "atd_t",
"command": "yarn run atdgen -t $in"
},
{
"name": "atd_bs",
"command": "yarn run atdgen -bs $in"
}
],
```
With yarn or npm:

Or with node:
```
npm install @jchavarri/bs-atdgen-generator --save-dev
yarn add -D rescript-atdgen-generator
```
```
npm i -D rescript-atdgen-generator
```

And then:
We then need to define `atd` as a generator in `rescript.json`. For compatibility with windows development, the recommended approach is a direct reference to `atdgen.exe`. Generators are run in the `lib/bs` folder context, so a leading `../..` is required:

```json
"generators": [
{
"name": "atd_t",
"command": "npx atdgen -t $in"
"name": "atd_types",
"command": "../../node_modules/rescript-atdgen-generator/atdgen.exe -t $in"
},
{
"name": "atd_bs",
"command": "npx atdgen -bs $in"
"name": "atd_runtime",
"command": "../../node_modules/rescript-atdgen-generator/atdgen.exe -bs $in"
}
],
```

Now that the generator is defined, add the files that need to be processed to `sources` (still in `bsconfig`):
If windows compatibility is not required, or for more complex monorepo scenarios, these commands can be replaced by the shorter `npx atdgen -t $in` and `npx atdgen -bs $in` (or using `yarn run` instead of `npx`). This approach is however a little slower due to the extra nodejs invocations.

Now that the generator is defined, add the files that need to be processed to `sources`. ReScript requires a manual definition for every file that the generator will process. For `atd`, this means a pair of entries must be defined for _every_ `.atd` file in your project. Both "types" and "runtime" representations are required, and each generates both an interface and a code file.

```json
"sources": {
"dir" : "src",
"subdirs" : true,
"generators": [
{
"name": "atd_t",
"edge": ["meetup_t.ml", "meetup_t.mli", ":", "meetup.atd"]
},
{
"name": "atd_bs",
"edge": ["meetup_bs.ml", "meetup_bs.mli", ":", "meetup.atd"]
}
]
// given a `my-generated-source` folder, define generators for the file `meetup.atd` in that folder.
// it is not necessary to have a dedicated folder for generated sources,
// but it does help avoid generated files getting in the way.
{
"dir": "my-generated-source",
"generators": [
{
"name": "atd_types",
"edge": ["meetup_t.ml", "meetup_t.mli", ":", "meetup.atd"]
},
{
"name": "atd_runtime",
"edge": ["meetup_bs.ml", "meetup_bs.mli", ":", "meetup.atd"]
}
]
},
// ...other source folders
"src1",
"src2"
},
```

## For Windows users

Unfortunately, it's not possible for `npx` or `yarn run` to work directly in Windows environments, due to
the way [ninja calls CreateProcess](https://github.com/jchavarri/bs-atdgen-generator/pull/3#issue-415706268).
The syntax here is a little weird, the `edge` array defines a build syntax recognised by the compiler. The order of this array is very important; it must be the two files that `atd` generates, a `:`, and then the source file that serves as the input to the generator command.

In order to use atdgen for this platform, there are two options:
Updates to the source file are what the compiler uses to determine whether the generator needs to run. The generated files can freely be ignored by source control.

#### 1. Use relative path
## License and Credits

In `bsconfig.json`:

```diff
"generators": [
{
"name": "atd_t",
- "command": "npx atdgen -t $in"
+ "command": "../../node_modules/\@jchavarri/bs-atdgen-generator/atdgen.exe -t $in"
},
{
"name": "atd_bs",
- "command": "npx atdgen -bs $in"
+ "command": "../../node_modules/\@jchavarri/bs-atdgen-generator/atdgen.exe -bs $in"
}
],
```

#### 2. Use `cmd /c`:

```diff
"generators": [
{
"name": "atd_t",
- "command": "npx atdgen -t $in"
+ "command": "cmd /c npx atdgen -t $in"
},
{
"name": "atd_bs",
- "command": "npx atdgen -bs $in"
+ "command": "cmd /c npx atdgen -bs $in"
}
],
```
All code is licensed as MIT. See [LICENSE](LICENSE).

Both solutions are shell independent, and work with both Powershell and Windows bash.
This project was transferred to me by [Javier Chávarri](https://github.com/jchavarri) after it was abandoned following the switch of [ahrefs](https://github.com/ahrefs) to Melange.
4 changes: 2 additions & 2 deletions test/bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"generators": [
{
"name": "atd_t",
"command": "../../node_modules/rescript-atdgen-generator/atdgen.exe -t $in"
"command": "../../node_modules/@jchavarri/bs-atdgen-generator/atdgen.exe -t $in"
},
{
"name": "atd_bs",
"command": "../../node_modules/rescript-atdgen-generator/atdgen.exe -bs $in"
"command": "../../node_modules/@jchavarri/bs-atdgen-generator/atdgen.exe -bs $in"
}
],
"sources": [
Expand Down
79 changes: 59 additions & 20 deletions test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "bs-atdgen-generator-integration-test",
"name": "rescript-atdgen-generator-integration-test",
"version": "0.1.0",
"scripts": {
"build": "bsb -make-world",
"start": "bsb -make-world -w",
"clean": "bsb -clean-world"
"build": "rescript",
"start": "rescript build -w",
"clean": "rescript clean"
},
"license": "MIT",
"devDependencies": {
"@jchavarri/bs-atdgen-generator": "0.0.9",
"bs-platform": "7.3.2"
"@jchavarri/bs-atdgen-generator": "0.1.0",
"rescript": "10.1.4"
},
"dependencies": {
"@ahrefs/bs-atdgen-codec-runtime": "^2.0.1"
"@ahrefs/bs-atdgen-codec-runtime": "^2.2.0"
}
}

0 comments on commit 7bc3168

Please sign in to comment.