-
Notifications
You must be signed in to change notification settings - Fork 0
/
ElmAsset.js
43 lines (35 loc) · 951 Bytes
/
ElmAsset.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const elmCompiler = require('node-elm-compiler');
const findAllDependencies = require("find-elm-dependencies").findAllDependencies;
const fs = require('fs');
const path = require('path');
const process = require('process');
const Asset = require('parcel-bundler/src/Asset');
class ElmAsset extends Asset {
constructor(name, options) {
super(name, options);
this.type = 'js';
}
getParserOptions() {
const defaultOptions = {
cwd: process.cwd(),
};
return defaultOptions;
}
async getDependencies() {
let deps = await findAllDependencies(this.name);
deps.forEach(dep => {
this.addDependency(dep, { includedInParent: true });
});
}
async generate() {
const options = this.getParserOptions();
const data = await elmCompiler.compileToString(this.name, options);
return [
{
type: 'js',
value: data.toString()
}
];
}
}
module.exports = ElmAsset;