-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.gr
52 lines (50 loc) · 1.34 KB
/
index.gr
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
module Main
// Imports
include "bytes"
include "sys/file"
include "sys/process"
include "int64"
include "string"
include "path"
include "./linker/ResolvePath"
include "./linker/index"
include "./fs"
from ResolvePath use { resolvePath }
from Linker use { link }
record Arguments {
inFile: Option<String>,
outFile: Option<String>,
}
// Definition For Write File
let writeFile = (filePath, fileContents) => {
match (Fs.writeFile(Path.fromString(filePath), fileContents)) {
Err(err) => fail toString(err),
Ok(_) => void,
}
}
// Definition For ReadFile
let readFile = filePath => {
match (Fs.readFile(Path.fromString(filePath))) {
Err(err) => Err(toString(err)),
Ok(fileContents) => Ok(fileContents),
}
}
// Perform Linking
let linkBuild = (filePath, outputPath) => {
// Link The File
let wasmOutput = link(filePath, readFile, resolvePath)
// Write The output File
writeFile(outputPath, wasmOutput)
}
// Deal With Command Line Arguments
// TODO: Replace with argument parser library
let (input, output) = match (Process.argv()) {
Ok([> file, input, output]) when !String.endsWith("node", file) =>
(input, output),
Ok([> file, input]) when !String.endsWith("node", file) =>
fail "Output file was not provided",
Err(err) => throw err,
_ => fail "Input/Output file was not provided",
}
// link The Build
linkBuild(input, output)