提交 e6c88e65 编写于 作者: yanghye's avatar yanghye

energy-command-line, set env to path

上级 5d999084
......@@ -8,7 +8,7 @@
//
//----------------------------------------
package command
package consts
import "runtime"
......@@ -39,6 +39,7 @@ const (
// https://gitee.com/energye/assets/releases/download/environment/nsis.windows.386-3.09.zip
NSISDownloadURL = "https://gitee.com/energye/assets/releases/download/environment/%s"
NSISDownloadVersion = "3.09"
NSISHomeKey = "NSIS_HOME"
)
const (
......
......@@ -12,6 +12,7 @@ package internal
import (
"github.com/energye/energy/v2/cmd/internal/command"
"github.com/energye/energy/v2/cmd/internal/consts"
"os"
)
......@@ -29,7 +30,7 @@ func init() {
}
func runGetEnv(c *command.Config) error {
envPath := os.Getenv(command.EnergyHomeKey)
envPath := os.Getenv(consts.EnergyHomeKey)
println("ENERGY_HOME_KEY", envPath)
return nil
}
......@@ -13,7 +13,7 @@ package env
import (
"bytes"
"fmt"
"github.com/energye/energy/v2/cmd/internal/command"
"github.com/energye/energy/v2/cmd/internal/consts"
"github.com/energye/energy/v2/cmd/internal/tools"
"github.com/energye/golcl/energy/homedir"
toolsCommand "github.com/energye/golcl/tools/command"
......@@ -31,7 +31,7 @@ type envToPath struct {
}
func init() {
if command.IsWindows {
if consts.IsWindows {
envPath = &envToPath{}
}
}
......@@ -83,15 +83,15 @@ func SetNSISEnv(nsisRoot string) {
}
}
defer cmd.Close()
var args = []string{"NSIS_HOME", nsisRoot}
var args = []string{consts.NSISHomeKey, nsisRoot}
cmd.Command("setx", args...)
envPath.add("%NSIS_HOME%")
//envPath.add("%NSIS_HOME%")
println("\nHint: Reopen the cmd window for the makensis command to take effect.")
}
func SetGoEnv(goRoot string) {
var goexe = "go"
if command.IsWindows {
if consts.IsWindows {
goexe += ".exe"
}
gobin := filepath.Join(goRoot, "bin", goexe)
......@@ -112,7 +112,7 @@ func SetGoEnv(goRoot string) {
}
}
defer cmd.Close()
if command.IsWindows {
if consts.IsWindows {
// setx
// GOROOT=/to/go/path
var args = []string{"GOROOT", goRoot}
......@@ -142,11 +142,11 @@ func SetGoEnv(goRoot string) {
func SetEnergyHomeEnv(homePath string) {
var cef string
if command.IsWindows {
if consts.IsWindows {
cef = "libcef.dll"
} else if command.IsLinux {
} else if consts.IsLinux {
cef = "libcef.so"
} else if command.IsDarwin {
} else if consts.IsDarwin {
cef = "cef_sandbox.a"
}
cefPath := filepath.Join(homePath, cef)
......@@ -167,11 +167,11 @@ func SetEnergyHomeEnv(homePath string) {
}
}
defer cmd.Close()
if command.IsWindows {
var args = []string{"/c", "setx", command.EnergyHomeKey, homePath}
if consts.IsWindows {
var args = []string{"/c", "setx", consts.EnergyHomeKey, homePath}
cmd.Command("cmd.exe", args...)
} else {
var energyHome = fmt.Sprintf("export %s=%s", command.EnergyHomeKey, homePath)
var energyHome = fmt.Sprintf("export %s=%s", consts.EnergyHomeKey, homePath)
exs := []string{energyHome}
setPosixEnv(exs, "", "")
}
......@@ -192,9 +192,9 @@ func setPosixEnv(exs []string, binPath, bin string) {
}
defer cmd.Close()
var envFiles []string
if command.IsLinux {
if consts.IsLinux {
envFiles = []string{".profile", ".zshrc", ".bashrc"}
} else if command.IsDarwin {
} else if consts.IsDarwin {
envFiles = []string{".profile", ".zshrc", ".bash_profile"}
}
homeDir, err := homedir.Dir()
......
......@@ -16,6 +16,7 @@ import (
"compress/gzip"
"fmt"
"github.com/energye/energy/v2/cmd/internal/command"
"github.com/energye/energy/v2/cmd/internal/consts"
"github.com/energye/energy/v2/cmd/internal/env"
progressbar "github.com/energye/energy/v2/cmd/internal/progress-bar"
"github.com/energye/energy/v2/cmd/internal/tools"
......@@ -93,7 +94,7 @@ func initInstall(c *command.Config) {
os.MkdirAll(cefInstallPathName(c), fs.ModePerm)
os.MkdirAll(goInstallPathName(c), fs.ModePerm)
os.MkdirAll(nsisInstallPathName(c), fs.ModePerm)
os.MkdirAll(filepath.Join(c.Install.Path, command.FrameworkCache), fs.ModePerm)
os.MkdirAll(filepath.Join(c.Install.Path, consts.FrameworkCache), fs.ModePerm)
}
func filePathInclude(compressPath string, files ...any) (string, bool) {
......
......@@ -14,6 +14,7 @@ import (
"encoding/json"
"fmt"
"github.com/energye/energy/v2/cmd/internal/command"
"github.com/energye/energy/v2/cmd/internal/consts"
progressbar "github.com/energye/energy/v2/cmd/internal/progress-bar"
"github.com/energye/energy/v2/cmd/internal/tools"
"net/url"
......@@ -39,7 +40,7 @@ func installCEFFramework(c *command.Config) string {
}
}
// 获取提取文件配置
extractData, err := tools.HttpRequestGET(command.DownloadExtractURL)
extractData, err := tools.HttpRequestGET(consts.DownloadExtractURL)
if err != nil {
fmt.Println("Error:", err.Error())
os.Exit(1)
......@@ -55,7 +56,7 @@ func installCEFFramework(c *command.Config) string {
extractOSConfig := extractConfig[runtime.GOOS].(map[string]any)
// 获取安装版本配置
downloadJSON, err := tools.HttpRequestGET(command.DownloadVersionURL)
downloadJSON, err := tools.HttpRequestGET(consts.DownloadVersionURL)
if err != nil {
fmt.Println("Error:", err.Error())
os.Exit(1)
......@@ -72,7 +73,7 @@ func installCEFFramework(c *command.Config) string {
// -c cef args value
// default(empty), windows7, gtk2, flash
cef := strings.ToLower(c.Install.CEF)
if cef != command.CefEmpty && cef != command.Cef109 && cef != command.Cef106 && cef != command.Cef87 {
if cef != consts.CefEmpty && cef != consts.Cef109 && cef != consts.Cef106 && cef != consts.Cef87 {
fmt.Println("Error:", "-c [cef] Incorrect args value")
os.Exit(1)
return ""
......@@ -108,11 +109,11 @@ func installCEFFramework(c *command.Config) string {
cefModuleName, liblclModuleName string
)
// 使用提供的特定版本号
if cef == command.Cef106 {
if cef == consts.Cef106 {
cefModuleName = "cef-106" // CEF 106.1.1
} else if cef == command.Cef109 {
} else if cef == consts.Cef109 {
cefModuleName = "cef-109" // CEF 109.1.18
} else if cef == command.Cef87 {
} else if cef == consts.Cef87 {
// cef 87 要和 liblcl 87 配对
cefModuleName = "cef-87" // CEF 87.1.14
liblclModuleName = "liblcl-87" // liblcl 87
......@@ -185,7 +186,7 @@ func installCEFFramework(c *command.Config) string {
downloadCefURL = replaceSource(downloadCefURL, tools.ToString(cefModule["downloadSource"]), tools.ToInt(cefModule["downloadSourceSelect"]), "cef")
downloadCefURL = strings.ReplaceAll(downloadCefURL, "{version}", cefVersion)
downloadCefURL = strings.ReplaceAll(downloadCefURL, "{OSARCH}", libCEFOS)
downloads[command.CefKey] = &downloadInfo{isSupport: isSupport, fileName: urlName(downloadCefURL), downloadPath: filepath.Join(c.Install.Path, command.FrameworkCache, urlName(downloadCefURL)), frameworkPath: installPathName, url: downloadCefURL, module: cefModuleName}
downloads[consts.CefKey] = &downloadInfo{isSupport: isSupport, fileName: urlName(downloadCefURL), downloadPath: filepath.Join(c.Install.Path, consts.FrameworkCache, urlName(downloadCefURL)), frameworkPath: installPathName, url: downloadCefURL, module: cefModuleName}
// liblcl
// 如果选定的cef 106,在linux会指定liblcl gtk2 版本, 其它系统和版本以默认的形式区分
......@@ -199,7 +200,7 @@ func installCEFFramework(c *command.Config) string {
downloadEnergyURL = strings.ReplaceAll(downloadEnergyURL, "{version}", liblclVersion)
downloadEnergyURL = strings.ReplaceAll(downloadEnergyURL, "{module}", module)
downloadEnergyURL = strings.ReplaceAll(downloadEnergyURL, "{OSARCH}", libEnergyOS)
downloads[command.LiblclKey] = &downloadInfo{isSupport: isSupport, fileName: urlName(downloadEnergyURL), downloadPath: filepath.Join(c.Install.Path, command.FrameworkCache, urlName(downloadEnergyURL)), frameworkPath: installPathName, url: downloadEnergyURL, module: liblclModuleName}
downloads[consts.LiblclKey] = &downloadInfo{isSupport: isSupport, fileName: urlName(downloadEnergyURL), downloadPath: filepath.Join(c.Install.Path, consts.FrameworkCache, urlName(downloadEnergyURL)), frameworkPath: installPathName, url: downloadEnergyURL, module: liblclModuleName}
}
// 在线下载框架二进制包
......@@ -230,7 +231,7 @@ func installCEFFramework(c *command.Config) string {
continue
}
if di.success {
if key == command.CefKey {
if key == consts.CefKey {
bar := progressbar.NewBar(0)
bar.SetNotice("Unpack file " + key + ": ")
tarName := UnBz2ToTar(di.downloadPath, func(totalLength, processLength int64) {
......@@ -238,7 +239,7 @@ func installCEFFramework(c *command.Config) string {
})
bar.PrintEnd()
ExtractFiles(key, tarName, di, extractOSConfig)
} else if key == command.LiblclKey {
} else if key == consts.LiblclKey {
ExtractFiles(key, di.downloadPath, di, extractOSConfig)
}
println("Unpack file", key, "success\n")
......@@ -263,49 +264,49 @@ func cefOS(module map[string]any) (string, bool) {
}
return false
}
if command.IsWindows { // windows arm for 64 bit, windows for 32/64 bit
if consts.IsWindows { // windows arm for 64 bit, windows for 32/64 bit
if runtime.GOARCH == "arm64" {
return "windowsarm64", isSupport(command.WindowsARM64)
return "windowsarm64", isSupport(consts.WindowsARM64)
}
if strconv.IntSize == 32 {
return fmt.Sprintf("windows%d", strconv.IntSize), isSupport(command.Windows32)
return fmt.Sprintf("windows%d", strconv.IntSize), isSupport(consts.Windows32)
}
return fmt.Sprintf("windows%d", strconv.IntSize), isSupport(command.Windows64)
} else if command.IsLinux { //linux for 64 bit
return fmt.Sprintf("windows%d", strconv.IntSize), isSupport(consts.Windows64)
} else if consts.IsLinux { //linux for 64 bit
if runtime.GOARCH == "arm64" {
if mod == command.Cef106 {
return "linuxarm64", isSupport(command.LinuxARM64GTK2)
if mod == consts.Cef106 {
return "linuxarm64", isSupport(consts.LinuxARM64GTK2)
}
return "linuxarm64", isSupport(command.LinuxARM64) || isSupport(command.LinuxARM64GTK3)
return "linuxarm64", isSupport(consts.LinuxARM64) || isSupport(consts.LinuxARM64GTK3)
} else if runtime.GOARCH == "amd64" {
if mod == command.Cef106 {
return "linux64", isSupport(command.Linux64GTK2)
if mod == consts.Cef106 {
return "linux64", isSupport(consts.Linux64GTK2)
}
return "linux64", isSupport(command.Linux64) || isSupport(command.Linux64GTK3)
return "linux64", isSupport(consts.Linux64) || isSupport(consts.Linux64GTK3)
}
} else if command.IsDarwin { // macosx for 64 bit
} else if consts.IsDarwin { // macosx for 64 bit
//if runtime.GOARCH == "arm64" {
// return "macosarm64", isSupport(MacOSARM64)
//} else if runtime.GOARCH == "amd64" {
// return "macosx64", isSupport(MacOSX64)
//}
// Mac amd64 m1 m2 架构目前使用amd64, m1,m2使用Rosetta2兼容
return "macosx64", isSupport(command.MacOSX64)
return "macosx64", isSupport(consts.MacOSX64)
}
//not support
return fmt.Sprintf("%v %v", runtime.GOOS, runtime.GOARCH), false
}
var liblclFileNames = map[string]string{
"windows32": command.Windows32,
"windows64": command.Windows64,
"windowsarm64": command.WindowsARM64,
"linuxarm64": command.LinuxARM64,
"linuxarm64gtk2": command.LinuxARM64GTK2,
"linux64": command.Linux64,
"linux64gtk2": command.Linux64GTK2,
"darwin64": command.MacOSX64,
"darwinarm64": command.MacOSARM64,
"windows32": consts.Windows32,
"windows64": consts.Windows64,
"windowsarm64": consts.WindowsARM64,
"linuxarm64": consts.LinuxARM64,
"linuxarm64gtk2": consts.LinuxARM64GTK2,
"linux64": consts.Linux64,
"linux64gtk2": consts.Linux64GTK2,
"darwin64": consts.MacOSX64,
"darwinarm64": consts.MacOSARM64,
"windows32_old": "Windows 32 bits",
"windows64_old": "Windows 64 bits",
"linux64gtk2_old": "Linux GTK2 x86 64 bits",
......@@ -317,10 +318,10 @@ func liblclName(version, cef string) (string, bool) {
var key string
var isOld bool
if runtime.GOARCH == "arm64" {
if command.IsLinux && cef == command.Cef106 { // 只linux区别liblcl gtk2
if consts.IsLinux && cef == consts.Cef106 { // 只linux区别liblcl gtk2
key = "linuxarm64gtk2"
} else {
if command.IsDarwin {
if consts.IsDarwin {
// Mac amd64 m1 m2 架构目前使用amd64, m1,m2使用Rosetta2兼容
key = fmt.Sprintf("%samd64", runtime.GOOS)
} else {
......@@ -328,7 +329,7 @@ func liblclName(version, cef string) (string, bool) {
}
}
} else if runtime.GOARCH == "amd64" {
if command.IsLinux && cef == command.Cef106 { // 只linux区别liblcl gtk2
if consts.IsLinux && cef == consts.Cef106 { // 只linux区别liblcl gtk2
key = "linux64gtk2"
} else {
key = fmt.Sprintf("%s%d", runtime.GOOS, strconv.IntSize)
......@@ -374,10 +375,10 @@ func liblclOS(cef, version, buildSupportOSArch string) (string, bool) {
func ExtractFiles(keyName, sourcePath string, di *downloadInfo, extractOSConfig map[string]any) {
println("Extract", keyName, "sourcePath:", sourcePath, "targetPath:", di.frameworkPath)
files := extractOSConfig[keyName].([]any)
if keyName == command.CefKey {
if keyName == consts.CefKey {
//tar
ExtractUnTar(sourcePath, di.frameworkPath, files...)
} else if keyName == command.LiblclKey {
} else if keyName == consts.LiblclKey {
//zip
ExtractUnZip(sourcePath, di.frameworkPath, false, files...)
}
......
......@@ -12,6 +12,7 @@ package install
import (
"fmt"
"github.com/energye/energy/v2/cmd/internal/command"
"github.com/energye/energy/v2/cmd/internal/consts"
progressbar "github.com/energye/energy/v2/cmd/internal/progress-bar"
"github.com/energye/energy/v2/cmd/internal/tools"
"io/fs"
......@@ -43,7 +44,7 @@ func installGolang(c *command.Config) string {
"windows": "zip",
}
// 开始下载并安装Go开发环境
version := command.GolangDefaultVersion
version := consts.GolangDefaultVersion
gos := runtime.GOOS
arch := runtime.GOARCH
ext := exts[gos]
......@@ -55,8 +56,8 @@ func installGolang(c *command.Config) string {
}
}
fileName := fmt.Sprintf("go%s.%s-%s.%s", version, gos, arch, ext)
downloadUrl := fmt.Sprintf(command.GolangDownloadURL, fileName)
savePath := filepath.Join(s, command.FrameworkCache, fileName)
downloadUrl := fmt.Sprintf(consts.GolangDownloadURL, fileName)
savePath := filepath.Join(s, consts.FrameworkCache, fileName)
var err error
println("Golang Download URL:", downloadUrl)
println("Golang Save Path:", savePath)
......@@ -78,7 +79,7 @@ func installGolang(c *command.Config) string {
// 使用 go 名字做为 go 安装目录
targetPath := filepath.Join(s, "go")
// 释放文件
if command.IsWindows {
if consts.IsWindows {
//zip
ExtractUnZip(savePath, targetPath, true)
} else {
......
......@@ -12,16 +12,19 @@ package install
import (
"fmt"
"github.com/energye/energy/v2/cmd/internal/command"
"github.com/energye/energy/v2/cmd/internal/consts"
progressbar "github.com/energye/energy/v2/cmd/internal/progress-bar"
"github.com/energye/energy/v2/cmd/internal/tools"
"os"
"path/filepath"
"runtime"
"strings"
)
func installNSIS(c *command.Config) string {
if command.IsWindows && runtime.GOARCH == "amd64" {
if tools.CommandExists("makensis") {
if consts.IsWindows && runtime.GOARCH == "amd64" {
//if tools.CommandExists("makensis") {
if tools.IsExist(filepath.Join(os.Getenv(consts.NSISHomeKey), "makensis.exe")) {
println("NSIS installed")
return ""
}
......@@ -36,9 +39,9 @@ func installNSIS(c *command.Config) string {
}
// 下载并安装配置NSIS
s = c.Install.Path // 安装目录
fileName := fmt.Sprintf("nsis.windows.386-%s.zip", command.NSISDownloadVersion)
downloadUrl := fmt.Sprintf(command.NSISDownloadURL, fileName)
savePath := filepath.Join(s, command.FrameworkCache, fileName)
fileName := fmt.Sprintf("nsis.windows.386-%s.zip", consts.NSISDownloadVersion)
downloadUrl := fmt.Sprintf(consts.NSISDownloadURL, fileName)
savePath := filepath.Join(s, consts.FrameworkCache, fileName)
var err error
println("Golang Download URL:", downloadUrl)
println("Golang Save Path:", savePath)
......
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
package install
import "github.com/energye/energy/v2/cmd/internal/command"
func installUPX(c *command.Config) string {
return ""
}
......@@ -12,6 +12,7 @@ package project
import (
"encoding/json"
"github.com/energye/energy/v2/cmd/internal/consts"
"github.com/energye/golcl/energy/tools"
"os"
"path/filepath"
......@@ -38,7 +39,7 @@ func (m *Project) setDefaults() {
m.ProjectPath, _ = os.Getwd()
}
if m.FrameworkPath == "" {
m.FrameworkPath = os.Getenv("ENERGY_HOME")
m.FrameworkPath = os.Getenv(consts.EnergyHomeKey)
}
if !tools.IsExist(m.FrameworkPath) {
panic("energy framework directory does not exist: " + m.FrameworkPath)
......
......@@ -12,7 +12,7 @@ package tools
import (
"bytes"
"github.com/energye/energy/v2/cmd/internal/command"
"github.com/energye/energy/v2/cmd/internal/consts"
"github.com/energye/golcl/energy/tools"
"io/ioutil"
"math"
......@@ -164,17 +164,17 @@ func Compare(compare1, compare2 string) bool {
func CheckCEFDir() bool {
var lib = func() string {
if command.IsWindows {
if consts.IsWindows {
return "libcef.dll"
} else if command.IsLinux {
} else if consts.IsLinux {
return "libcef.so"
} else if command.IsDarwin {
} else if consts.IsDarwin {
return "cef_sandbox.a"
}
return ""
}()
if lib != "" {
return tools.IsExist(filepath.Join(os.Getenv("ENERGY_HOME"), lib))
return tools.IsExist(filepath.Join(os.Getenv(consts.EnergyHomeKey), lib))
}
return false
}
......@@ -15,6 +15,7 @@ import (
"encoding/json"
"fmt"
"github.com/energye/energy/v2/cmd/internal/command"
"github.com/energye/energy/v2/cmd/internal/consts"
"github.com/energye/energy/v2/cmd/internal/tools"
"os"
"sort"
......@@ -35,7 +36,7 @@ func init() {
}
func runVersion(c *command.Config) error {
downloadJSON, err := tools.HttpRequestGET(command.DownloadVersionURL)
downloadJSON, err := tools.HttpRequestGET(consts.DownloadVersionURL)
if err != nil {
fmt.Fprint(os.Stderr, err.Error()+"\n")
os.Exit(1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册