Coder Social home page Coder Social logo

thespyder / rescript-atdgen-generator Goto Github PK

View Code? Open in Web Editor NEW
10.0 4.0 4.0 96 KB

Pre-compiled versions of atdgen binaries to be consumed from ReScript projects

License: Other

JavaScript 94.44% OCaml 0.60% Shell 4.96%
reasonml bucklescript atd ocaml rescript

rescript-atdgen-generator's Introduction

rescript-atdgen-generator

Atdgen prebuilt binaries for 3 major OS platforms.

This is capped at version 2.15.0, after which BuckleScript support (which ReScript relies on) was removed. ahrefs/atd#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 folder)

Runtime library installation

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 still works - but not on ReScript 11.

Generator installation

With yarn or npm:

yarn add -D rescript-atdgen-generator
npm i -D rescript-atdgen-generator

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:

"generators": [
  {
    "name": "atd_types",
    "command": "../../node_modules/.bin/atdgen -t $in"
  },
  {
    "name": "atd_runtime",
    "command": "../../node_modules/.bin/atdgen -bs $in"
  }
],

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.

"sources": {
  // 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"
},

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.

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.

License and Credits

All code is licensed as MIT. See LICENSE.

This project was transferred to me by Javier Chávarri after it was abandoned following the switch of ahrefs to Melange.

rescript-atdgen-generator's People

Contributors

et7f3 avatar jchavarri avatar thespyder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

et7f3 cknitt lozlow

rescript-atdgen-generator's Issues

Error when running bsb -make-world + atdgen on Windows

https://github.com/jchavarri/bs-atdgen-generator/runs/659691890

[8/8] Building src\atdgen_codec_runtime.cmj
ninja: fatal: ReadFile: The handle is invalid.
[1/16] Building d:\a\bs-atdgen-generator\bs-atdgen-generator\test\src\atd\Foo_t.ml d:\a\bs-atdgen-generator\bs-atdgen-generator\test\src\atd\Foo_t.mli

FAILED: d:/a/bs-atdgen-generator/bs-atdgen-generator/test/src/atd/Foo_t.ml d:/a/bs-atdgen-generator/bs-atdgen-generator/test/src/atd/Foo_t.mli 

npx atdgen -t d:\a\bs-atdgen-generator\bs-atdgen-generator\test\src\atd\Foo.atd
CreateProcess failed: The system cannot find the file specified.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: `bsb -make-world`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\npm\cache\_logs\2020-05-09T21_53_12_608Z-debug.log
##[error]Process completed with exit code 2.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.