This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
73 lines (61 loc) · 1.96 KB
/
index.mjs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { validate } from 'schema-utils';
import { resolve, dirname, extname } from 'path';
import { execa } from 'execa';
import { readFileSync } from 'fs';
import { install, run } from '@haskell-org/ghc-installer';
const schema = {
type: 'object',
additionalProperties: false,
required: ['executable'],
properties: {
"install-ghc": {
type: 'string'
},
"install-cabal": {
type: 'string'
},
"executable": {
type: 'string'
},
"system-tools": {
type: 'boolean'
},
}
}
export default async function (_source) {
const options = this.getOptions();
validate(schema, options, {
name: 'Haskell loader',
baseDataPath: 'options'
});
const currentFolder = resolve(import.meta.dirname);
const projectFolder = dirname(this.resourcePath);
var buildOpt = '';
if (extname(this.resourcePath) === '.project') {
buildOpt = `--project-file=${this.resourcePath}`;
}
else {
buildOpt = `--project-dir=${projectFolder}`;
}
// add dependency to the whole folder
// this.addDependency(projectFolder);
if (options['system-tools']) {
await execa('cabal', ['build', 'all', `--builddir=${currentFolder}`, buildOpt ], { stdio: 'inherit' });
const {stdout} = await execa('cabal', ['-v0', `--builddir=${currentFolder}`, buildOpt, 'exec', '--', 'which', options['executable'] ]);
console.log("Output haskell file: " + stdout);
return readFileSync(stdout);
}
else {
if(options['install-ghc']) {
await install('ghc', options['install-ghc']);
}
if(options['install-cabal']) {
await install('cabal', options['install-cabal']);
await run('cabal', ['update']);
}
await run('cabal', ['build', 'all', `--builddir=${currentFolder}`, buildOpt]);
const {stdout} = await run('cabal', ['-v0', `--builddir=${currentFolder}`, buildOpt, 'exec', '--', 'which', options['executable'] ]);
console.log("Output haskell file: " + stdout);
return readFileSync(stdout);
}
}