1021
This commit is contained in:
		
							parent
							
								
									24282364a2
								
							
						
					
					
						commit
						c5bd8e0bf8
					
				
							
								
								
									
										12
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								go.mod
									
									
									
									
									
								
							@ -1,4 +1,4 @@
 | 
			
		||||
module apigo.cc/apigo/ag
 | 
			
		||||
module ag
 | 
			
		||||
 | 
			
		||||
go 1.18
 | 
			
		||||
 | 
			
		||||
@ -8,16 +8,6 @@ require (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	github.com/dlclark/regexp2 v1.11.4 // indirect
 | 
			
		||||
	github.com/fsnotify/fsnotify v1.7.0 // indirect
 | 
			
		||||
	github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
 | 
			
		||||
	github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
 | 
			
		||||
	github.com/ssgo/tool v0.4.27 // indirect
 | 
			
		||||
	golang.org/x/sys v0.26.0 // indirect
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	apigo.cc/gojs v0.0.2
 | 
			
		||||
	github.com/ssgo/config v1.7.7 // indirect
 | 
			
		||||
	github.com/ssgo/log v1.7.7 // indirect
 | 
			
		||||
	github.com/ssgo/standard v1.7.7 // indirect
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										14
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								go.sum
									
									
									
									
									
								
							@ -1,13 +1,3 @@
 | 
			
		||||
apigo.cc/gojs v0.0.2 h1:MMJfnFuQHNOVFnxiNhfMa4Yrr/CtCcW6sO27DZux/DE=
 | 
			
		||||
apigo.cc/gojs v0.0.2/go.mod h1:iuTCYlxSnz2ARxaYigk5sHpUEjLCSKdtKXcG9xwxKxY=
 | 
			
		||||
github.com/dlclark/regexp2 v1.11.4 h1:rPYF9/LECdNymJufQKmri9gV604RvvABwgOA8un7yAo=
 | 
			
		||||
github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
 | 
			
		||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
 | 
			
		||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
 | 
			
		||||
github.com/go-sourcemap/sourcemap v2.1.4+incompatible h1:a+iTbH5auLKxaNwQFg0B+TCYl6lbukKPc7b5x0n1s6Q=
 | 
			
		||||
github.com/go-sourcemap/sourcemap v2.1.4+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
 | 
			
		||||
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 h1:4/hN5RUoecvl+RmJRE2YxKWtnnQls6rQjjW5oV7qg2U=
 | 
			
		||||
github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg=
 | 
			
		||||
github.com/ssgo/config v1.7.7 h1:gYYDuEEdesH41oNtvKHuwaua9quU655O8TRd3pBcuK8=
 | 
			
		||||
github.com/ssgo/config v1.7.7/go.mod h1:4mnR3YLGkmK+YnVT0NAbfUpvxqGyjyEElag+bH4zb0c=
 | 
			
		||||
github.com/ssgo/httpclient v1.7.7 h1:ex7pEwEpDaNtm334b04F0EQ62rPCNNxjOMi9tosXvGA=
 | 
			
		||||
@ -16,14 +6,10 @@ github.com/ssgo/log v1.7.7 h1:EjgPGDTAEz+ApNyluLpof9QlftxBiqh1Jt3e3E0h/m4=
 | 
			
		||||
github.com/ssgo/log v1.7.7/go.mod h1:5E2Mkk+np9SCU84bX+lxBOG8QBD3XVkvFCbFi0RiKyk=
 | 
			
		||||
github.com/ssgo/standard v1.7.7 h1:5tnlcr9Nmftp7JI3jszYCEbW7VgS5HHsGueD+yWxbh0=
 | 
			
		||||
github.com/ssgo/standard v1.7.7/go.mod h1:LZcn56DzHu8OlDXrUPLI6h+RZbZRXhkmiKh6PSE8eDs=
 | 
			
		||||
github.com/ssgo/tool v0.4.27 h1:tB2VvEWt0jSazel2/G+/JmhsYesJWCeRLEdyV2r5QeM=
 | 
			
		||||
github.com/ssgo/tool v0.4.27/go.mod h1:qIQYzXya36WWVypWP5T/AgKwKBwZkEvMRfjACkAeUuw=
 | 
			
		||||
github.com/ssgo/u v1.7.9 h1:m1wcJWQg13+NbqpG+c2z3yWO+PC7qE3PIwKfXhQqdPg=
 | 
			
		||||
github.com/ssgo/u v1.7.9/go.mod h1:dUG/PBG5k9fSM7SOp8RZLsK0KytNxhtenpoLgjhfxpY=
 | 
			
		||||
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
 | 
			
		||||
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
 | 
			
		||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
 | 
			
		||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 | 
			
		||||
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
 | 
			
		||||
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
 | 
			
		||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										94
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										94
									
								
								main.go
									
									
									
									
									
								
							@ -7,6 +7,7 @@ import (
 | 
			
		||||
	"io"
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/exec"
 | 
			
		||||
	"path"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"regexp"
 | 
			
		||||
	"runtime"
 | 
			
		||||
@ -41,7 +42,6 @@ type Config struct {
 | 
			
		||||
	Name        string
 | 
			
		||||
	Version     string
 | 
			
		||||
	Main        string
 | 
			
		||||
	Output      string
 | 
			
		||||
	Target      map[string]string
 | 
			
		||||
	Module      map[string]string
 | 
			
		||||
	ModuleAlias map[string]string
 | 
			
		||||
@ -289,7 +289,6 @@ func getConfig() *Config {
 | 
			
		||||
		Name:        "",
 | 
			
		||||
		Version:     "v0.0.1",
 | 
			
		||||
		Main:        "main.js",
 | 
			
		||||
		Output:      "dist",
 | 
			
		||||
		Module:      map[string]string{},
 | 
			
		||||
		ModuleAlias: map[string]string{},
 | 
			
		||||
		ExtraImport: map[string]string{},
 | 
			
		||||
@ -417,10 +416,67 @@ func initProject(args []string) bool {
 | 
			
		||||
	return true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func buildProject(args []string) bool {
 | 
			
		||||
	conf := getConfig()
 | 
			
		||||
func packageProject(args []string) bool {
 | 
			
		||||
	return buildProjectWithOption(args, true)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
	return false
 | 
			
		||||
func buildProject(args []string) bool {
 | 
			
		||||
	return buildProjectWithOption(args, false)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func buildProjectWithOption(args []string, isPack bool) bool {
 | 
			
		||||
	conf := getConfig()
 | 
			
		||||
	targets := make([][]string, 0)
 | 
			
		||||
	if len(args) > 0 {
 | 
			
		||||
		if args[0] == "all" {
 | 
			
		||||
			for k, v := range conf.Target {
 | 
			
		||||
				for _, arch := range strings.Split(v, " ") {
 | 
			
		||||
					targets = append(targets, []string{k, arch})
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
			if len(args) > 1 {
 | 
			
		||||
				targets = append(targets, []string{args[0], args[1]})
 | 
			
		||||
			} else {
 | 
			
		||||
				targets = append(targets, []string{args[0], runtime.GOARCH})
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		targets = append(targets, []string{runtime.GOOS, runtime.GOARCH})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	output := "build"
 | 
			
		||||
	if isPack {
 | 
			
		||||
		output = "release"
 | 
			
		||||
		// TODO 生成静态文件和入口文件嵌入代码
 | 
			
		||||
		// TODO 生成SSKey嵌入代码
 | 
			
		||||
		defer func() {
 | 
			
		||||
			os.Remove("cacheFiles.go")
 | 
			
		||||
			os.Remove("setSSKey.go")
 | 
			
		||||
		}()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_ = runCommand(goPath, "mod", "tidy")
 | 
			
		||||
 | 
			
		||||
	for _, target := range targets {
 | 
			
		||||
		buildOS := target[0]
 | 
			
		||||
		buildArch := target[1]
 | 
			
		||||
		name := path.Base(conf.Name)
 | 
			
		||||
		ext := ""
 | 
			
		||||
		if buildOS == "windows" {
 | 
			
		||||
			ext = ".exe"
 | 
			
		||||
		}
 | 
			
		||||
		buildPath := filepath.Join(output, fmt.Sprintf("%s_%s_%s%s", name, buildOS, buildArch, ext))
 | 
			
		||||
		env := append(make([]string, 0), "GOOS="+buildOS, "GOARCH="+buildArch)
 | 
			
		||||
		err := runCommandWithEnv("go", env, "build", "-o", buildPath, "-ldflags", "-s -w", ".")
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			fmt.Println(u.BRed("build failed"), buildOS, buildArch, err.Error())
 | 
			
		||||
		} else {
 | 
			
		||||
			fmt.Println(u.Green("build for"), buildOS, buildArch, "to", buildPath)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func CopyFile(from, to string) error {
 | 
			
		||||
@ -465,7 +521,7 @@ func CopyFile(from, to string) error {
 | 
			
		||||
// 		goBinPath = goPath
 | 
			
		||||
// 		args = append(args, "run", ".")
 | 
			
		||||
// 	}
 | 
			
		||||
// 	return nil == runCommandPipeWithEnv(logVPath, goBinPath, goRunEnv, args...)
 | 
			
		||||
// 	return nil == runCommandPipe          (logVPath, goBinPath, goRunEnv, args...)
 | 
			
		||||
// }
 | 
			
		||||
 | 
			
		||||
// func runProject(args []string) bool {
 | 
			
		||||
@ -694,14 +750,14 @@ func runCommand(name string, args ...string) error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func runCommandWithEnv(name string, env []string, args ...string) error {
 | 
			
		||||
	pathname, _ := os.Getwd()
 | 
			
		||||
	fmt.Println(u.BMagenta(pathname), u.BCyan(name), u.Cyan(strings.Join(args, " ")))
 | 
			
		||||
	// pathname, _ := os.Getwd()
 | 
			
		||||
	// fmt.Println(u.BMagenta(pathname), u.BCyan(name), u.Cyan(strings.Join(args, " ")))
 | 
			
		||||
	cmd := exec.Command(name, args...)
 | 
			
		||||
	if env != nil {
 | 
			
		||||
		if runtime.GOOS == "windows" {
 | 
			
		||||
			env = append(env, "GOTMPDIR="+pathname, "GOWORK="+pathname)
 | 
			
		||||
		}
 | 
			
		||||
		cmd.Env = append(cmd.Env, env...)
 | 
			
		||||
		// if runtime.GOOS == "windows" {
 | 
			
		||||
		// 	env = append(env, "GOTMPDIR="+pathname, "GOWORK="+pathname)
 | 
			
		||||
		// }
 | 
			
		||||
		cmd.Env = append(os.Environ(), env...)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	cmd.Stdin = os.Stdin
 | 
			
		||||
@ -723,13 +779,13 @@ func runCommandPipeWithEnv(pipeCommandName, commandName string, env []string, ar
 | 
			
		||||
	fmt.Println(u.BMagenta(pathname), u.BCyan(commandName), u.Cyan(strings.Join(args, " ")), u.BMagenta(pipeCommandName))
 | 
			
		||||
	cmd1 := exec.Command(commandName, args...)
 | 
			
		||||
	cmd2 := exec.Command(pipeCommandName)
 | 
			
		||||
	if env != nil {
 | 
			
		||||
		if runtime.GOOS == "windows" {
 | 
			
		||||
			env = append(env, "GOTMPDIR="+pathname, "GOWORK="+pathname)
 | 
			
		||||
		}
 | 
			
		||||
		cmd1.Env = append(cmd1.Env, env...)
 | 
			
		||||
		cmd2.Env = append(cmd2.Env, env...)
 | 
			
		||||
	}
 | 
			
		||||
	// if env != nil {
 | 
			
		||||
	// 	if runtime.GOOS == "windows" {
 | 
			
		||||
	// 		env = append(env, "GOTMPDIR="+pathname, "GOWORK="+pathname)
 | 
			
		||||
	// 	}
 | 
			
		||||
	// 	cmd1.Env = append(cmd1.Env, env...)
 | 
			
		||||
	// 	cmd2.Env = append(cmd2.Env, env...)
 | 
			
		||||
	// }
 | 
			
		||||
 | 
			
		||||
	r, w := io.Pipe()
 | 
			
		||||
	wClosed := false
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
.*
 | 
			
		||||
!.gitignore
 | 
			
		||||
go.sum
 | 
			
		||||
/dist
 | 
			
		||||
/build*
 | 
			
		||||
/build
 | 
			
		||||
/release
 | 
			
		||||
node_modules
 | 
			
		||||
package.json
 | 
			
		||||
@ -1,7 +1,6 @@
 | 
			
		||||
name:
 | 
			
		||||
version: v0.0.1
 | 
			
		||||
main: main.js
 | 
			
		||||
output: dist
 | 
			
		||||
target:
 | 
			
		||||
  darwin: amd64 arm64
 | 
			
		||||
  linux: amd64 arm64
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										0
									
								
								tests/client_test.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								tests/client_test.js
									
									
									
									
									
										Normal file
									
								
							@ -14,7 +14,7 @@ require (
 | 
			
		||||
	apigo.cc/gojs/service v0.0.1
 | 
			
		||||
	apigo.cc/gojs/util v0.0.2
 | 
			
		||||
	github.com/ssgo/log v1.7.7
 | 
			
		||||
	github.com/ssgo/s v1.7.16
 | 
			
		||||
	github.com/ssgo/s v1.7.17
 | 
			
		||||
	github.com/ssgo/u v1.7.9
 | 
			
		||||
	modernc.org/sqlite v1.33.1
 | 
			
		||||
)
 | 
			
		||||
@ -68,3 +68,5 @@ require (
 | 
			
		||||
	modernc.org/strutil v1.2.0 // indirect
 | 
			
		||||
	modernc.org/token v1.1.0 // indirect
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
replace apigo.cc/gojs v0.0.2 => ../../../gojs/gojs
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user