123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- package main
- import (
- "app-uploader/huawei"
- "app-uploader/utils"
- "fmt"
- "path/filepath"
- "runtime"
- "strconv"
- "strings"
- "time"
- "github.com/jessevdk/go-flags"
- )
- var GAppOption = &AppOption{}
- // short只能是一个字符
- type AppOption struct {
- Unzip string `short:"d" long:"unzip" description:"unzip file"`
- }
- func (o *AppOption) Parse() {
- _, err := flags.NewParser(o, flags.Default|flags.IgnoreUnknown).Parse()
- fmt.Println(err)
- }
- func main() {
- // 读取package.json版本数据
- // 复制app.json文件和logo文件
- // 读取配置
- // 解压工具 app-uploader.exe -d output/queenter-v1.1.2-amd64-windows.zip
- // !压缩后的文件在windows上用软件打开有问题,但在linux上解压或者unzip正常
- // utils.Unzip(zipPath,filepath.Base(zipFile),nil)
- GAppOption.Parse()
- if len(GAppOption.Unzip) > 0 {
- fileName := filepath.Base(GAppOption.Unzip)
- ext := filepath.Ext(fileName)
- fileDir := strings.TrimSuffix(fileName, ext)
- fmt.Println(GAppOption.Unzip)
- dest := fmt.Sprintf("%s/%s", filepath.Dir(GAppOption.Unzip), fileDir)
- fmt.Println("unzip dir:", dest)
- err := utils.Unzip(GAppOption.Unzip, dest, nil)
- if err != nil {
- fmt.Println("unzip err:", err)
- return
- }
- return
- }
- appConf, err := utils.ReadAppConfig()
- if err != nil {
- fmt.Println("读取配置文件错误")
- return
- }
- uploadConf, err := utils.ReadUpConf()
- if err != nil {
- fmt.Println("读取配置文件错误")
- return
- }
- if _, ok := uploadConf[appConf.Key]; !ok {
- fmt.Println("未找到该配置项")
- return
- }
- // 复制文件到对应目录
- dest := uploadConf[appConf.Key].Dest
- copyFiles := uploadConf[appConf.Key].Files
- modify := uploadConf[appConf.Key].Modify
- fmt.Println(uploadConf[appConf.Key])
- // 复制文件到目标目录中
- for _, file := range copyFiles {
- err := utils.Copy(file, fmt.Sprintf("%s/%s", dest, file))
- if err != nil {
- fmt.Println(err)
- return
- }
- }
- // 获取版本信息
- version, err := utils.GetVersion()
- if err != nil {
- fmt.Println(err)
- return
- }
- appConf.Version = version
- appConfDest := fmt.Sprintf("%s/%s", dest, modify)
- err = utils.WriteAppConfig(appConf, appConfDest)
- if err != nil {
- fmt.Println(err)
- return
- }
- // 压缩文件
- // remoteswift-v1.0.0-x64-windows.zip
- zipFile := fmt.Sprintf("%s-v%s-%s-%s.zip", appConf.Key, version, runtime.GOARCH, runtime.GOOS)
- zipPath := fmt.Sprintf("output/%s", zipFile)
- fmt.Println("压缩文件中...")
- err = utils.Zip(zipPath, dest)
- if err != nil {
- fmt.Println("压缩文件出错")
- return
- }
- fmt.Println("上传中...")
- // 上传文件
- huawei.InitConfig()
- // http://spu3dv1.obs.cn-east-3.myhuaweicloud.com/pkg/lancher1.0.2.windows-amd64.zip
- obsDir := "pkg"
- obs, err := huawei.UploadFile(zipPath, obsDir, zipFile)
- if err != nil {
- fmt.Println(err)
- return
- }
- if len(obs.Url) < 1 {
- fmt.Println("上传zipfile错误")
- return
- }
- fmt.Println("succ uploaded=>", obs.Url)
- // 获取最新版本
- // 输出db文件
- outputDb := "output/db.json"
- sizeM, err := strconv.Atoi(strings.Replace(appConf.Size, "MB", "", -1))
- if err != nil {
- fmt.Println("转换size string->int 错误:", err)
- }
- err = utils.WriteVersionDb(&utils.Version{
- Name: appConf.Key,
- Version: version,
- SizeM: sizeM,
- Url: fmt.Sprintf("https:%s", obs.Url),
- }, outputDb)
- if err != nil {
- fmt.Println(err)
- return
- }
- fmt.Println("上传成功")
- fmt.Println("输出文件目录=>: output")
- time.Sleep(3 * time.Second)
- }
|