-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
60 lines (53 loc) · 1.22 KB
/
mod.ts
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
import { setupSolar } from './wasi.ts'
import path from 'node:path'
export class Solar {
async version(): Promise<string> {
const { stdout, stderr } = await setupSolar(['-j1', '--version'])
if (stderr) {
throw new Error(stderr)
}
let version = ''
for (const line of stdout.split('\n')) {
if (line !== '' && line.includes('solar')) {
version = line.split(':')[1].trim()
}
}
return version
}
async emitAbi(source: string): Promise<string> {
const { stderr, stdout } = await setupSolar([
'-j1',
path.relative('.', source),
'--emit',
'abi',
])
if (stderr) {
throw new Error(stderr)
}
return stdout
}
async emitHashes(source: string): Promise<string> {
const { stderr, stdout } = await setupSolar([
'-j1',
path.relative('.', source),
'--emit',
'hashes',
])
if (stderr) {
throw new Error(stderr)
}
return stdout
}
async emit(source: string): Promise<string> {
const { stderr, stdout } = await setupSolar([
'-j1',
path.relative('.', source),
'--emit',
'abi,hashes',
])
if (stderr) {
throw new Error(stderr)
}
return stdout
}
}