-
Notifications
You must be signed in to change notification settings - Fork 0
/
coppier.go
62 lines (48 loc) · 1.18 KB
/
coppier.go
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
package coppier
import (
"embed"
"log"
"os"
"path/filepath"
)
const distFolder string = "dist"
func UserDefinedContent() {
log.Printf("copying across user defined content")
targetFile := "styles.css"
data, err := os.ReadFile(targetFile)
if err != nil {
log.Printf("no styles.css found, not including user defined css in build")
}
outputPath := filepath.Join(distFolder, targetFile)
err = os.WriteFile(outputPath, data, 0644)
if err != nil {
log.Fatalf("could not create asset %q", targetFile)
}
log.Printf("user defined content %v copied to %v", targetFile, outputPath)
}
func Assets(assets embed.FS) {
files := readFiles(assets)
for k, v := range files {
err := os.WriteFile(filepath.Join(distFolder, k), v, 0644)
if err != nil {
log.Fatalf("could not create asset %q", k)
}
}
}
func readFiles(assets embed.FS) map[string][]byte {
resp := make(map[string][]byte)
files := []string{
"index.html",
"script.js",
"wasm_exec.js",
}
// Read and display the file content
for _, f := range files {
fBytes, err := assets.ReadFile("assets/" + f)
if err != nil {
log.Fatalf("could not load in file %q error %v", f, err)
}
resp[f] = fBytes
}
return resp
}