-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
91 lines (77 loc) · 2.02 KB
/
build.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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// build.js
// Martin Pravda
/*jslint node */
import {resolve} from "node:path";
import {writeFile} from "node:fs";
import {build} from "vite";
import create_html from "./document.js";
import parseq from "./parseq.js";
import create_logger from "./logger.js";
const logger = create_logger({type: "build"});
function entrify(path) {
return resolve(
import.meta.dirname,
path
);
}
function create_bundle(input_file, environment) {
return function (callback) {
return build({
build: {
minify: (
environment === "production"
),
rollupOptions: {
input: input_file,
output: {
format: "module",
name: "mapier"
}
},
write: false
}
}).then(function ({output}) {
return callback(output[0].code);
}).catch(function (err) {
return callback(undefined, err);
});
};
}
function write_document(output_path) {
return function (callback, {
app_code
}) {
const document = create_html({
app_code,
// todo state
state: JSON.stringify({})
});
writeFile(output_path, document, function (err) {
if (err) {
return callback(undefined, err);
}
return callback({
preview: document
});
});
};
}
function log_result(ignore, reason) {
if (reason !== undefined) {
logger.error(reason);
return;
}
return logger.info("Quine has been successfully build");
}
function build_html(input, output, environment = "development") {
return parseq.sequence([
parseq.parallel_object({
app_code: create_bundle(input, environment)
}),
write_document(output)
])(log_result);
}
build_html(
entrify("./mapier.js"),
entrify("./mapier.html")
);