Class: Shell_Command

Inherits:
Object
  • Object
show all
Includes:
Uki_config::Mixin
Defined in:
lib/cocoapods-uki-packager/shell.rb

Defined Under Namespace

Modules: Mixin

Class Attribute Summary collapse

Instance Method Summary collapse

Methods included from Uki_config::Mixin

#uki_config

Class Attribute Details

.instanceObject



215
216
217
# File 'lib/cocoapods-uki-packager/shell.rb', line 215

def self.instance
    @instance ||= new
end

Instance Method Details

#buildObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cocoapods-uki-packager/shell.rb', line 13

def build

    puts %x{echo "*********************************************************  开始编译"}
    
    log = %x{

        xcodebuild build -workspace #{uki_config.workspace} -scheme #{uki_config.scheme} -destination generic/platform=iOS -configuration #{uki_config.configuration} DEBUG_INFORMATION_FORMAT=#{uki_config.dsym_config} DWARF_DSYM_FOLDER_PATH=#{uki_config.dsym_path}

        if [[ $? -ne 0 ]]; then
            echo "************************************* 编译失败 *************************************"
            exit 1
        fi
    }

    puts %x{echo "*********************************************************  编译完成"}

    if uki_config.verbose?
        # puts(log)
    end

    # 直接开始导出
    self.export

end

#exportObject

暂时先不copy到跟目录, 防止Git提交代码时提交上去需安装Fir 不太友好安装命令 sudo gem install fir-cli



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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/cocoapods-uki-packager/shell.rb', line 41

def export
    unless uki_config.build_exe_path
        puts "未生成目标文件目录"
        return
    end

    puts %x{echo "*********************************************************  开始导出ipa"}

    log = %x{
        product_path=#{uki_config.build_exe_path}
        if [[ $product_path == "" ]]; then
            echo "===no path input==="
            product_path=`dirname $0`
        fi

        echo -e “=====path=$product_path =====“

        cd $product_path

        fir_log="fir auto release"

        APP=$(find $product_path -type d | grep ".app$" | head -n 1)
        APP=${APP%.*}

        echo -e “=====APP=$APP =====“

        rm -rf "$APP.ipa";
        rm -rf ./Payload;
        mkdir Payload;
        cp -rf "$APP.app" ./Payload;
        zip -r -q "$APP.ipa" ./Payload;
        rm -rf ./Payload;

        # echo "===生成ipa开始上传 ==="

        #计时
        SECONDS=0

        fir_token="207c7aad886da8009a73486d5154a7a6"
        fir publish "$APP.ipa" -T $fir_token -c "$fir_log" -R

        size=$(ls -l $APP.ipa | awk '{ print $5 }')

        sizeM=`echo "scale=2; ${size}/1024.0/1024" | bc`
        #sizeM="$((${size}/1000.0))
        echo -e "===size=${sizeM}m==="

        notification="Did uploaded to fir caost time:${SECONDS}s"
        echo "===$notification===%" 

        osascript -e 'display notification "size:'$sizeM'm\ncaost:'$SECONDS's" with title "Uploaded to fir!" sound name "default" '

        echo "upload_time=${SECONDS}"
    }

    puts("恭喜打包完成")

    if uki_config.verbose?
        puts(log)
    end

    url = log[/http:.*$/]
    array = log.split('%')
    uki_config.upload_time = array.last.split("=").last.to_i
    uki_config.build_time = Time.now.to_i - uki_config.build_time - uki_config.upload_time
    uki_config.fir_url = url

    send_notifi
end

#send_notifiObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/cocoapods-uki-packager/shell.rb', line 111

def send_notifi

    branch = %x{
        if branch=$(git symbolic-ref --short -q HEAD)
            then
              echo  $branch
            else
              echo "未知分支"
        fi
    }
    
    hostname = Socket.gethostname
    project_name = uki_config.project_sea ? "iOS海外极速打包已完成": "iOS国内极速打包已完成"
    project_env = uki_config.release ? "Release": "Debug"
    project_dsym = uki_config.dsym ? "已上传": "无符号表"

    message = {
        "msg_type": "interactive",
        "card": {
            "elements": [
              {
                "fields": [
                  {
                    "is_short": true,
                    "text": {
                      "content": "**打包分支**\n#{branch}",
                      "tag": "lark_md"
                    }
                  },
                  {
                    "is_short": true,
                    "text": {
                      "content": "**打包环境**\n#{project_env}",
                      "tag": "lark_md"
                    }
                  },
                  {
                    "is_short": true,
                    "text": {
                      "content": "**打包机器**\n#{hostname}",
                      "tag": "lark_md"
                    }
                  },
                  {
                    "is_short": true,
                    "text": {
                      "content": "**dsym**\n#{project_dsym}",
                      "tag": "lark_md"
                    }
                  },
                  {
                    "is_short": true,
                    "text": {
                      "content": "**编译耗时**\n#{uki_config.build_time}s",
                      "tag": "lark_md"
                    }
                  },
                  {
                    "is_short": true,
                    "text": {
                      "content": "**上传耗时**\n#{uki_config.upload_time}s",
                      "tag": "lark_md"
                    }
                  }
                ],
                "tag": "div"
              },
              {
                "tag": "hr"
              },
              {
                  "tag": "action",
                  "actions": [
                      {
                        "tag": "button",
                        "text": {
                          "tag": "lark_md",
                          "content": "点击下载"
                        },
                        "type": "default",
                        "url": "#{uki_config.fir_url}"
                      }
                  ]
              }
            ],
            "header": {
              "template": "green",
              "title": {
                "content": "#{project_name}",
                "tag": "plain_text"
              }
            }
          }
    }

    log = %x{
        curl -X POST -H "Content-Type: application/json" -d '#{message.to_json}' "https://open.feishu.cn/open-apis/bot/v2/hook/68c47d38-fc65-4cc5-a386-885a1fbff11b"
    }

    if uki_config.verbose?
        puts(log)
    end
end