3
3
package appbuild
4
4
5
5
import (
6
+ _ "embed"
6
7
"fmt"
7
8
"os"
8
9
"path/filepath"
10
+ "strings"
9
11
10
12
"wa-lang.org/wa/internal/3rdparty/cli"
11
13
"wa-lang.org/wa/internal/app/appbase"
@@ -15,6 +17,18 @@ import (
15
17
"wa-lang.org/wa/internal/wat/watutil"
16
18
)
17
19
20
+ //go:embed assets/favicon.ico
21
+ var favicon_ico string
22
+
23
+ //go:embed assets/index.html
24
+ var w4index_html string
25
+
26
+ //go:embed assets/wasm4.js
27
+ var w4js string
28
+
29
+ //go:embed assets/wasm4.css
30
+ var w4css string
31
+
18
32
var CmdBuild = & cli.Command {
19
33
Name : "build" ,
20
34
Usage : "compile Wa source code" ,
@@ -209,6 +223,21 @@ func BuildApp(opt *appbase.Option, input, outfile string) (mainFunc string, wasm
209
223
os .Exit (1 )
210
224
}
211
225
226
+ if opt .TargetOS == config .WaOS_wasm4 {
227
+ icoOutfile := filepath .Join (filepath .Dir (outfile ), "favicon.ico" )
228
+ w4JsOutfile := filepath .Join (filepath .Dir (outfile ), "wasm4.js" )
229
+ w4CssOutfile := filepath .Join (filepath .Dir (outfile ), "wasm4.css" )
230
+ w4IndexOutfile := filepath .Join (filepath .Dir (outfile ), "index.html" )
231
+
232
+ wasm4Cart := filepath .Base (outfile )
233
+ wasm4JsCode := strings .Replace (w4js , `"cart.wasm"` , `"` + wasm4Cart + `"` , - 1 )
234
+
235
+ os .WriteFile (icoOutfile , []byte (favicon_ico ), 0666 )
236
+ os .WriteFile (w4JsOutfile , []byte (wasm4JsCode ), 0666 )
237
+ os .WriteFile (w4CssOutfile , []byte (w4css ), 0666 )
238
+ os .WriteFile (w4IndexOutfile , []byte (w4index_html ), 0666 )
239
+ }
240
+
212
241
// 主函数
213
242
mainFunc := manifest .MainPkg + ".main"
214
243
0 commit comments