UNPKG

1.3 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
6
7const Asset = require('../Asset');
8
9const fs = require('@parcel/fs');
10
11const localRequire = require('../utils/localRequire');
12
13class ReasonAsset extends Asset {
14 constructor(name, options) {
15 super(name, options);
16 this.type = 'js';
17 }
18
19 generate() {
20 var _this = this;
21
22 return (0, _asyncToGenerator2.default)(function* () {
23 const bsb = yield localRequire('bsb-js', _this.name); // This runs BuckleScript - the Reason to JS compiler.
24 // Other Asset types use `localRequire` but the `bsb-js` package already
25 // does that internally. This should also take care of error handling in
26 // the Reason compilation process.
27
28 if (process.env.NODE_ENV !== 'test') {
29 yield bsb.runBuild();
30 } // This is a simplified use-case for Reason - it only loads the recommended
31 // BuckleScript configuration to simplify the file processing.
32
33
34 const outputFile = _this.name.replace(/\.(re|ml)$/, '.bs.js');
35
36 const outputContent = yield fs.readFile(outputFile);
37 return outputContent.toString();
38 })();
39 }
40
41}
42
43module.exports = ReasonAsset;
\No newline at end of file