-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain.go
84 lines (74 loc) · 2.01 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"CocosCreator3DPlayable/fileEmbed"
"CocosCreator3DPlayable/mix/engine"
"CocosCreator3DPlayable/mix/res"
_ "embed"
"flag"
"fmt"
"os"
"path/filepath"
"regexp"
"github.com/Jecced/go-tools/src/ak"
_ "github.com/Jecced/go-tools/src/ak"
"github.com/Jecced/go-tools/src/fileutil"
)
var (
mobileDir = "E:\\Projects\\Cocos\\Taxi"
outDir = ""
htmlFile = ""
tmpOutFile = ""
)
func main() {
//build, _ := os.Executable()
build := mobileDir
//build = filepath.Dir(build)
buildPath := flag.String("path", build, "build path")
flag.Parse()
if !fileutil.PathExists(*buildPath) {
fmt.Printf("%s Path Error\n", *buildPath)
return
}
mobileDir = *buildPath + ak.PS + "build/web-mobile"
outDir = *buildPath + ak.PS + "build/PS"
htmlFile = outDir + ak.PS + "index.html"
tmpOutFile = outDir + ak.PS + "/index.html"
fileutil.ClearDir(outDir)
fmt.Printf("copy project from:%s --->to:%s\n", mobileDir, outDir)
var err = fileutil.DirCopy(mobileDir, outDir)
if err != nil {
return
}
indexhtml, err := fileutil.ReadBytes(outDir + ak.PS + "index.html")
if err != nil {
fmt.Printf("read index.html error:%s\n", err)
return
}
pat := `.+Import map(.*\n)*.*index\.js`
re := regexp.MustCompile(pat)
indexhtml = re.ReplaceAll(indexhtml, []byte(`<!-- RESOURCE -->
<!-- SCRIPT -->
<!-- JSON IMPORT-MAP -->
<!-- new-res-loader.js -->
<script src="new-res-loader.js" charset="utf-8"></script>
<script>
System.import('index.js`))
fileutil.WriteData(indexhtml, outDir+ak.PS+"index.html")
plugin, err := fileEmbed.Plugin.ReadFile("plugin/new-res-loader.js")
if err != nil {
return
}
fileutil.WriteData(plugin, outDir+ak.PS+"new-res-loader.js")
path, _ := os.Executable()
dir := filepath.Dir(path)
fmt.Printf("OS:%s\n", dir)
htmlContent, err := fileutil.ReadText(htmlFile)
if err != nil {
fmt.Println(err, htmlContent)
}
engine.Mix(outDir, &htmlContent)
res.Mix(outDir, &htmlContent)
fileutil.ClearDir(outDir)
fileutil.WriteText(htmlContent, tmpOutFile)
fileutil.DelEmptyDir(outDir)
}