gitee_pack 1.0.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/LICENSE.txt +1 -1
- data/README.md +115 -9
- data/bin/gitee_pack +2 -2
- data/exe/update.sh +67 -0
- data/lib/gitee_pack.rb +9 -1
- data/lib/gitee_pack/diff.rb +43 -11
- data/lib/gitee_pack/filer.rb +39 -9
- data/lib/gitee_pack/folder.rb +15 -3
- data/lib/gitee_pack/logger.rb +40 -0
- data/lib/gitee_pack/parser.rb +49 -0
- data/lib/gitee_pack/precompile.rb +21 -3
- data/lib/gitee_pack/status.rb +14 -0
- data/lib/gitee_pack/verifier.rb +21 -0
- data/lib/gitee_pack/version.rb +1 -1
- data/lib/gitee_pack/worker.rb +125 -14
- metadata +7 -4
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c9adbed7bd55f10620212932db594690e1bd2b7c4629abaa53dcd24a0f180c9a
|
|
4
|
+
data.tar.gz: 6de7ad9b25d042db6dde002a8ec8030cae8632ab5c82d765c9e5ec7a8cb54d21
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 995bd5a5b776510047cc125aedda46c17778b28fcd1832e838ea227eb6d2c1e4995df8d2d078f8dd7c336c6d2deb09737918deac87d1238ca80e0f7429bb8705
|
|
7
|
+
data.tar.gz: ffb05ca566555eca10fc14321dcadc64d4091541d3875cc899b44bb78cdba85a8454cb9df86fa057c456595286fee45c6984022b3acc668e404ea994fc43971b
|
data/.gitignore
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -1,28 +1,134 @@
|
|
|
1
1
|
# GiteePack
|
|
2
2
|
|
|
3
|
-
一个GiteePremium增量打包工具
|
|
3
|
+
一个 GiteePremium 增量打包工具
|
|
4
|
+
|
|
4
5
|
|
|
5
6
|
## 安装
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
```shell
|
|
9
|
+
$ gem install gitee_pack
|
|
10
|
+
```
|
|
8
11
|
|
|
9
|
-
$ gem install gitee_pack
|
|
10
12
|
|
|
11
13
|
## 使用
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
### 打包
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
在 gitee-premium 目录执行:
|
|
18
|
+
|
|
19
|
+
```shell
|
|
20
|
+
$ gitee_pack BASE HEAD
|
|
17
21
|
```
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
BASE: Commit提交的SHA值作为对比起点
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
HEAD: Commit提交的SHA值作为对比终点
|
|
22
26
|
|
|
23
27
|
示例:
|
|
24
28
|
|
|
25
|
-
```
|
|
29
|
+
```shell
|
|
26
30
|
$ gitee_pack a9b6296 6ac0f97
|
|
27
31
|
```
|
|
28
32
|
|
|
33
|
+
执行后会在当前目录下生成一个增量文件的升级包,例如 upgrade-20200430
|
|
34
|
+
|
|
35
|
+
升级包目录结构说明:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
upgrade-20200430
|
|
39
|
+
├── commit.txt // 记录 base、head 的 CommitID
|
|
40
|
+
├── diff.txt // 记录 base 和 head 之间的所有改动文件名称
|
|
41
|
+
├── delete.txt // 记录 base 和 head 之间被删除的文件名称
|
|
42
|
+
├── run.log // 打包时的运行日志
|
|
43
|
+
├── files // 用于存放代码文件的目录
|
|
44
|
+
└── update.sh // 部署脚本,更新代码时使用
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 更多选项
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
$ gitee_pack --help
|
|
51
|
+
Usage: gitee_pack BASE HEAD [options]
|
|
52
|
+
|
|
53
|
+
Specific options:
|
|
54
|
+
--skip-compile-asset Skip compile asset.
|
|
55
|
+
--skip-compile-webpack Skip compile webpack.
|
|
56
|
+
--skip-package-gem Skip package gem.
|
|
57
|
+
-h, --help Show this message.
|
|
58
|
+
-v, --version Show version info.
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`--skip-compile-asset` 当有 asset 文件改动时,跳过 asset 资源文件编译
|
|
62
|
+
|
|
63
|
+
`--skip-compile-webpack` 当有 vue 文件改动时,跳过 npm 资源文件编译
|
|
64
|
+
|
|
65
|
+
`--skip-package-gem` 当有 gem 改动时,跳过 gem 打包
|
|
66
|
+
|
|
67
|
+
### 错误值
|
|
68
|
+
|
|
69
|
+
执行 gitee_pack 命令,错误值解释如下
|
|
70
|
+
|
|
71
|
+
- `100` vue 资源文件编译失败
|
|
72
|
+
- `101` asset 资源文件编译失败
|
|
73
|
+
- `102` gem 打包失败
|
|
74
|
+
- `200` 升级包不完整
|
|
75
|
+
|
|
76
|
+
### 部署
|
|
77
|
+
|
|
78
|
+
在升级包中执行 update.sh 脚本,一键自动部署
|
|
79
|
+
|
|
80
|
+
```shell
|
|
81
|
+
$ cd upgrade-20200430
|
|
82
|
+
$ ./update.sh GITEE_PATH
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
GITEE_PATH: gitee-premium 的绝对路径
|
|
86
|
+
|
|
87
|
+
示例
|
|
88
|
+
|
|
89
|
+
```shell
|
|
90
|
+
$ ./update.sh /home/git/gitee-premium/gitee
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
## 版本变更
|
|
95
|
+
|
|
96
|
+
### v1.5.0
|
|
97
|
+
|
|
98
|
+
- feat: 支持打包完成后,检测包的完整性
|
|
99
|
+
- feat: 支持跳过编译流程打包
|
|
100
|
+
- feat: 支持新增、修改、删除 Gem 时自动打包
|
|
101
|
+
- feat: 支持记录打包日志到升级包中
|
|
102
|
+
- fix: 修复打包过程中失败,以非 0 值推出程序
|
|
103
|
+
|
|
104
|
+
### v1.4.0
|
|
105
|
+
|
|
106
|
+
- feat: 支持部署备份代码时过滤 tmp 目录(感谢@彭超越大佬)
|
|
107
|
+
|
|
108
|
+
### v1.3.0
|
|
109
|
+
|
|
110
|
+
- feat: 支持检测 asset 文件改动并自动编译及打包
|
|
111
|
+
|
|
112
|
+
### v1.2.0
|
|
113
|
+
|
|
114
|
+
- feat: 支持部署时代码备份功能
|
|
115
|
+
- feat: 打包时记录 Commit 信息
|
|
116
|
+
- fix: 修复部署脚本 Bug
|
|
117
|
+
|
|
118
|
+
### v1.1.0
|
|
119
|
+
|
|
120
|
+
- feat: 支持通过脚本自动化部署改动文件
|
|
121
|
+
|
|
122
|
+
### v1.0.0
|
|
123
|
+
|
|
124
|
+
- feat: 支持代码文件打包
|
|
125
|
+
- feat: 支持检测 webpack 文件改动并自动编译及打包
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
## 常见问题
|
|
129
|
+
|
|
130
|
+
1. 执行 `git status`、`git diff` 等命令,中文名文件显示为乱码,导致中文名文件无法打包成功。
|
|
131
|
+
|
|
132
|
+
```shell
|
|
133
|
+
$ git config --global core.quotepath false
|
|
134
|
+
```
|
data/bin/gitee_pack
CHANGED
|
@@ -5,7 +5,7 @@ require 'gitee_pack'
|
|
|
5
5
|
base, head = ARGV[0], ARGV[1]
|
|
6
6
|
|
|
7
7
|
start_at = Time.now
|
|
8
|
-
GiteePack.execute(base, head)
|
|
8
|
+
GiteePack.execute(base, head, { ARGV: ARGV })
|
|
9
9
|
end_at = Time.now
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
GiteePack.logger.success "Complete! cost time: #{end_at - start_at} seconds."
|
data/exe/update.sh
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
SCRIPT_DIR=$(cd $(dirname $0); pwd)
|
|
4
|
+
|
|
5
|
+
# Check parameter
|
|
6
|
+
GITEE_PATH=$1
|
|
7
|
+
if [ ! $GITEE_PATH ]; then
|
|
8
|
+
printf "\033[31mERROR: gitee-path cannot not be empty.\033[0m\n"
|
|
9
|
+
exit 1
|
|
10
|
+
fi
|
|
11
|
+
|
|
12
|
+
FINAL=${GITEE_PATH: -1}
|
|
13
|
+
if [ $FINAL = '/' ]; then
|
|
14
|
+
GITEE_PATH=${GITEE_PATH%?}
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
# Backup
|
|
18
|
+
BACKUP_DIR="$(dirname $GITEE_PATH)/backup/`date "+%Y%m%d%H%M%S"`/$(basename $GITEE_PATH)"
|
|
19
|
+
echo mkdir -p $BACKUP_DIR
|
|
20
|
+
mkdir -p $BACKUP_DIR
|
|
21
|
+
echo "cd $GITEE_PATH && tar --exclude tmp -cf - * | tar -xf - -C $BACKUP_DIR"
|
|
22
|
+
cd $GITEE_PATH && tar --exclude tmp -cf - * | tar -xf - -C $BACKUP_DIR
|
|
23
|
+
if [ $? -ne 0 ]; then
|
|
24
|
+
printf "\033[31mERROR: Gitee backup failed.\033[0m\n"
|
|
25
|
+
exit 1
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
echo cd $SCRIPT_DIR
|
|
29
|
+
cd $SCRIPT_DIR
|
|
30
|
+
|
|
31
|
+
# Delete webpacks dir
|
|
32
|
+
WEBPACK_PATH=$GITEE_PATH/public/webpacks
|
|
33
|
+
if [ -d files/public/webpacks ] && [ -d $WEBPACK_PATH ]; then
|
|
34
|
+
rm -rf $WEBPACK_PATH
|
|
35
|
+
echo rm -rf $WEBPACK_PATH
|
|
36
|
+
fi
|
|
37
|
+
|
|
38
|
+
# Delete assets dir
|
|
39
|
+
ASSET_PATH=$GITEE_PATH/public/assets
|
|
40
|
+
if [ -d files/public/assets ] && [ -d $ASSET_PATH ]; then
|
|
41
|
+
rm -rf $ASSET_PATH
|
|
42
|
+
echo rm -rf $ASSET_PATH
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
# Delete bundle cache dir
|
|
46
|
+
BUNDLE_CACHE_PATH=$GITEE_PATH/vendor/cache
|
|
47
|
+
if [ -d files/vendor/cache ] && [ -d $BUNDLE_CACHE_PATH ]; then
|
|
48
|
+
rm -rf $BUNDLE_CACHE_PATH
|
|
49
|
+
echo rm -rf $BUNDLE_CACHE_PATH
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
# Delete files with delete.txt
|
|
53
|
+
DELETE_FILE=delete.txt
|
|
54
|
+
if [ -f $DELETE_FILE ]; then
|
|
55
|
+
while read LINE
|
|
56
|
+
do
|
|
57
|
+
rm -rf $GITEE_PATH/$LINE
|
|
58
|
+
echo rm -rf $GITEE_PATH/$LINE
|
|
59
|
+
done < $DELETE_FILE
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
# Update files
|
|
63
|
+
cp -rf files/* $GITEE_PATH
|
|
64
|
+
echo cp -rf files/\* $GITEE_PATH
|
|
65
|
+
|
|
66
|
+
exit 0
|
|
67
|
+
|
data/lib/gitee_pack.rb
CHANGED
|
@@ -5,12 +5,20 @@ require 'gitee_pack/diff'
|
|
|
5
5
|
require 'gitee_pack/folder'
|
|
6
6
|
require 'gitee_pack/filer'
|
|
7
7
|
require 'gitee_pack/precompile'
|
|
8
|
+
require 'gitee_pack/logger'
|
|
9
|
+
require 'gitee_pack/verifier'
|
|
10
|
+
require 'gitee_pack/status'
|
|
11
|
+
require 'gitee_pack/parser'
|
|
8
12
|
require 'gitee_pack/worker'
|
|
9
13
|
|
|
10
14
|
module GiteePack
|
|
11
15
|
class CmdError < StandardError; end
|
|
12
16
|
|
|
13
17
|
def self.execute(base, head, options = {})
|
|
14
|
-
Worker.new(base, head).execute
|
|
18
|
+
Worker.new(base, head, options).execute
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.logger
|
|
22
|
+
@logger ||= Logger.new
|
|
15
23
|
end
|
|
16
24
|
end
|
data/lib/gitee_pack/diff.rb
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
module GiteePack
|
|
2
2
|
class Diff
|
|
3
|
-
attr_reader :empty_folders, :delete_files, :cp_files
|
|
3
|
+
attr_reader :empty_folders, :delete_files, :cp_files,
|
|
4
|
+
:webpack_files, :asset_files, :gem_files
|
|
5
|
+
|
|
6
|
+
IGNORE_FILES = [
|
|
7
|
+
'config/gitee.yml',
|
|
8
|
+
'config/database.yml',
|
|
9
|
+
'config/startup.yml',
|
|
10
|
+
'app/assets/javascripts/webpack/webide'
|
|
11
|
+
].freeze
|
|
4
12
|
|
|
5
13
|
def initialize(base, head)
|
|
6
14
|
@base = base
|
|
7
15
|
@head = head
|
|
8
|
-
@precompile = false
|
|
9
16
|
@empty_folders = []
|
|
10
17
|
@delete_files = []
|
|
11
18
|
@cp_files = []
|
|
19
|
+
@webpack_files = []
|
|
20
|
+
@asset_files = []
|
|
21
|
+
@gem_files = []
|
|
12
22
|
|
|
13
|
-
|
|
23
|
+
init_list_by_files
|
|
14
24
|
end
|
|
15
25
|
|
|
16
26
|
def diff_files
|
|
@@ -27,16 +37,41 @@ module GiteePack
|
|
|
27
37
|
result.split("\n")
|
|
28
38
|
end
|
|
29
39
|
|
|
30
|
-
def
|
|
31
|
-
|
|
40
|
+
def has_webpack_file?
|
|
41
|
+
!webpack_files.empty?
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def has_asset_file?
|
|
45
|
+
!asset_files.empty?
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def has_gem_file?
|
|
49
|
+
!gem_files.empty?
|
|
32
50
|
end
|
|
33
51
|
|
|
34
52
|
private
|
|
35
53
|
|
|
36
|
-
def
|
|
54
|
+
def init_list_by_files
|
|
55
|
+
init_empty_folders_and_cp_files
|
|
56
|
+
init_delete_files
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def init_delete_files
|
|
60
|
+
@delete_files = diff_files_with_status.map do |file|
|
|
61
|
+
file.sub("D\t", '') if file.start_with?('D')
|
|
62
|
+
end.compact
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def init_empty_folders_and_cp_files
|
|
37
66
|
diff_files.each do |file|
|
|
67
|
+
next if IGNORE_FILES.include?(file)
|
|
68
|
+
|
|
38
69
|
if file.start_with?('app/assets/javascripts/webpack')
|
|
39
|
-
@
|
|
70
|
+
@webpack_files << file
|
|
71
|
+
elsif file.start_with?('app/assets')
|
|
72
|
+
@asset_files << file
|
|
73
|
+
elsif file.start_with?('Gemfile')
|
|
74
|
+
@gem_files << file
|
|
40
75
|
end
|
|
41
76
|
|
|
42
77
|
if Dir.exist?(file)
|
|
@@ -44,10 +79,7 @@ module GiteePack
|
|
|
44
79
|
next
|
|
45
80
|
end
|
|
46
81
|
|
|
47
|
-
unless File.exist?(file)
|
|
48
|
-
@delete_files << file
|
|
49
|
-
next
|
|
50
|
-
end
|
|
82
|
+
next unless File.exist?(file)
|
|
51
83
|
|
|
52
84
|
@cp_files << file
|
|
53
85
|
end
|
data/lib/gitee_pack/filer.rb
CHANGED
|
@@ -3,24 +3,46 @@ module GiteePack
|
|
|
3
3
|
class << self
|
|
4
4
|
def cp_diff_files(files)
|
|
5
5
|
files.each do |file|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
puts "cp #{file} #{dirname}"
|
|
6
|
+
from = file
|
|
7
|
+
to = File.join(Folder.upgrade_files_dir, File.dirname(file))
|
|
8
|
+
cp_file from, to
|
|
10
9
|
end
|
|
11
10
|
end
|
|
12
11
|
|
|
13
12
|
def cp_webpack_files
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
from = File.join(Folder.webpacks_dir, '.')
|
|
14
|
+
to = File.join(Folder.upgrade_files_dir, Folder.webpacks_dir)
|
|
15
|
+
cp_file from, to
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def cp_asset_files
|
|
19
|
+
from = File.join(Folder.assets_dir, '.')
|
|
20
|
+
to = File.join(Folder.upgrade_files_dir, Folder.assets_dir)
|
|
21
|
+
cp_file from, to
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def cp_gems
|
|
25
|
+
from = File.join(Folder.bundle_cache_dir, '.')
|
|
26
|
+
to = File.join(Folder.upgrade_files_dir, Folder.bundle_cache_dir)
|
|
27
|
+
cp_file from, to
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def cp_update_file
|
|
31
|
+
from = File.join(File.expand_path('../../../', __FILE__), 'exe/update.sh')
|
|
32
|
+
to = Folder.upgrade_dir
|
|
33
|
+
cp_file from, to
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def cp_file(from, to)
|
|
37
|
+
FileUtils.mkdir_p to
|
|
38
|
+
GiteePack.logger.debug "cp -r #{from} #{to}"
|
|
39
|
+
FileUtils.cp_r from, to
|
|
18
40
|
end
|
|
19
41
|
|
|
20
42
|
def g_file(path, content = [])
|
|
21
43
|
File.open(path, 'w') do |f|
|
|
22
44
|
f.write("#{content.join("\n")}\n")
|
|
23
|
-
end
|
|
45
|
+
end unless content.empty?
|
|
24
46
|
end
|
|
25
47
|
|
|
26
48
|
def g_delete_file(content = [])
|
|
@@ -30,6 +52,14 @@ module GiteePack
|
|
|
30
52
|
def g_diff_file(content = [])
|
|
31
53
|
g_file(File.join(Folder.upgrade_dir, 'diff.txt'), content)
|
|
32
54
|
end
|
|
55
|
+
|
|
56
|
+
def g_commit_file(content = [])
|
|
57
|
+
g_file(File.join(Folder.upgrade_dir, 'commit.txt'), content)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def g_log_file(content= [])
|
|
61
|
+
g_file(File.join(Folder.upgrade_dir, 'run.log'), content)
|
|
62
|
+
end
|
|
33
63
|
end
|
|
34
64
|
end
|
|
35
65
|
end
|
data/lib/gitee_pack/folder.rb
CHANGED
|
@@ -6,8 +6,8 @@ module GiteePack
|
|
|
6
6
|
def mkdir_upgrade
|
|
7
7
|
rm_dir(upgrade_dir)
|
|
8
8
|
FileUtils.mkdir_p(upgrade_files_dir)
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
GiteePack.logger.debug "mkdir #{upgrade_dir}"
|
|
10
|
+
GiteePack.logger.debug "mkdir #{upgrade_files_dir}"
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def upgrade_dir
|
|
@@ -21,9 +21,21 @@ module GiteePack
|
|
|
21
21
|
def rm_dir(dir)
|
|
22
22
|
if Dir.exist?(dir)
|
|
23
23
|
`rm -rf #{dir}`
|
|
24
|
-
|
|
24
|
+
GiteePack.logger.debug "rm -rf #{dir}"
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
+
|
|
28
|
+
def webpacks_dir
|
|
29
|
+
'public/webpacks/'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def assets_dir
|
|
33
|
+
'public/assets/'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def bundle_cache_dir
|
|
37
|
+
'vendor/cache/'
|
|
38
|
+
end
|
|
27
39
|
end
|
|
28
40
|
end
|
|
29
41
|
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module GiteePack
|
|
2
|
+
class Logger
|
|
3
|
+
attr_accessor :history
|
|
4
|
+
|
|
5
|
+
def initialize
|
|
6
|
+
@history = []
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def debug(content)
|
|
10
|
+
logging content
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def info(content)
|
|
14
|
+
logging "\033[36m#{content}\033[0m"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def warn(content)
|
|
18
|
+
logging "\033[33m#{content}\033[0m"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def error(content)
|
|
22
|
+
logging "\033[31m#{content}\033[0m"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def success(content)
|
|
26
|
+
logging "\033[32m#{content}\033[0m"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def logging(content)
|
|
32
|
+
set_history content
|
|
33
|
+
puts content
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def set_history(content)
|
|
37
|
+
@history << content
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'optparse'
|
|
2
|
+
|
|
3
|
+
module GiteePack
|
|
4
|
+
class Parser
|
|
5
|
+
def execute(args)
|
|
6
|
+
options = default_options
|
|
7
|
+
OptionParser.new do |opts|
|
|
8
|
+
opts.banner = 'Usage: gitee_pack BASE HEAD [options]'
|
|
9
|
+
|
|
10
|
+
opts.separator ''
|
|
11
|
+
opts.separator 'Specific options:'
|
|
12
|
+
|
|
13
|
+
opts.on('--skip-compile-asset', 'Skip compile asset.') do
|
|
14
|
+
options[:skip_asset_compile] = true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
opts.on('--skip-compile-webpack', 'Skip compile webpack.') do
|
|
18
|
+
options[:skip_webpack_compile] = true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
opts.on('--skip-package-gem', 'Skip package gem.') do
|
|
22
|
+
options[:skip_gem_compile] = true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
opts.on_tail('-h', '--help', 'Show this message.') do
|
|
26
|
+
GiteePack.logger.debug opts
|
|
27
|
+
exit
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
opts.on_tail('-v', '--version', 'Show version info.') do
|
|
31
|
+
GiteePack.logger.debug "Version: #{GiteePack::VERSION}"
|
|
32
|
+
exit
|
|
33
|
+
end
|
|
34
|
+
end.parse!(args)
|
|
35
|
+
|
|
36
|
+
options
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def default_options
|
|
42
|
+
{
|
|
43
|
+
skip_asset_compile: false,
|
|
44
|
+
skip_webpack_compile: false,
|
|
45
|
+
skip_gem_compile: false
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -2,9 +2,27 @@ module GiteePack
|
|
|
2
2
|
class Precompile
|
|
3
3
|
class << self
|
|
4
4
|
def with_webpack
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
GiteePack.logger.info '[Compiling] webpack files is compiling, please wait ...'
|
|
6
|
+
Folder.rm_dir(Folder.webpacks_dir)
|
|
7
|
+
cmd = 'npm run build-vendor && npm run f-build'
|
|
8
|
+
GiteePack.logger.debug cmd
|
|
9
|
+
`#{cmd}`
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def with_asset
|
|
13
|
+
GiteePack.logger.info '[Compiling] asset files is compiling, please wait ...'
|
|
14
|
+
Folder.rm_dir(Folder.assets_dir)
|
|
15
|
+
cmd = 'RAILS_ENV=production bundle exec rake assets:precompile'
|
|
16
|
+
GiteePack.logger.debug cmd
|
|
17
|
+
`#{cmd}`
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def with_gem
|
|
21
|
+
GiteePack.logger.info '[Compiling] gems is compiling, please wait ...'
|
|
22
|
+
Folder.rm_dir(Folder.bundle_cache_dir)
|
|
23
|
+
cmd = 'bundle package --all'
|
|
24
|
+
GiteePack.logger.debug cmd
|
|
25
|
+
`#{cmd}`
|
|
8
26
|
end
|
|
9
27
|
end
|
|
10
28
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module GiteePack
|
|
2
|
+
class Status
|
|
3
|
+
ERR_COMPILE_WEBPACK = 100
|
|
4
|
+
ERR_COMPILE_ASSET = 101
|
|
5
|
+
ERR_COMPILE_GEM = 102
|
|
6
|
+
ERR_VERIFY_PACKAGE = 200
|
|
7
|
+
|
|
8
|
+
class << self
|
|
9
|
+
def success?(status_code)
|
|
10
|
+
(!status_code.nil?) && (status_code.to_i.eql? 0)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module GiteePack
|
|
2
|
+
class Verifier
|
|
3
|
+
def execute(from, to)
|
|
4
|
+
result = system "diff -r #{from} #{to} > /dev/null 2>&1"
|
|
5
|
+
message = get_message(result, from)
|
|
6
|
+
[result, message]
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def get_message(result, file_path)
|
|
12
|
+
msg = if result
|
|
13
|
+
"\033[32m[OK]\033[0m"
|
|
14
|
+
else
|
|
15
|
+
"\033[31m[FAILED]\033[0m"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
"#{file_path}\t#{msg}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/gitee_pack/version.rb
CHANGED
data/lib/gitee_pack/worker.rb
CHANGED
|
@@ -1,40 +1,151 @@
|
|
|
1
1
|
module GiteePack
|
|
2
2
|
class Worker
|
|
3
|
-
def initialize(base, head)
|
|
4
|
-
@
|
|
5
|
-
@
|
|
6
|
-
@
|
|
3
|
+
def initialize(base, head, options = {})
|
|
4
|
+
@options = Parser.new.execute(options[:ARGV])
|
|
5
|
+
@base = base
|
|
6
|
+
@head = head
|
|
7
|
+
@diff = Diff.new(@base, @head)
|
|
8
|
+
@errors = []
|
|
7
9
|
end
|
|
8
10
|
|
|
9
11
|
def execute
|
|
10
12
|
Folder.mkdir_upgrade
|
|
11
13
|
Filer.cp_diff_files(@diff.cp_files)
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
end
|
|
15
|
+
compile_webpack_files_and_cp
|
|
16
|
+
compile_asset_files_and_cp
|
|
17
|
+
compile_gems_and_cp
|
|
17
18
|
|
|
18
19
|
Filer.g_diff_file(@diff.diff_files_with_status)
|
|
19
20
|
Filer.g_delete_file(@diff.delete_files)
|
|
21
|
+
Filer.g_commit_file(["old: #{@base}", "new: #{@head}"])
|
|
22
|
+
Filer.cp_update_file
|
|
20
23
|
|
|
21
24
|
puts_empty_folders
|
|
22
|
-
|
|
25
|
+
puts_deleted_files
|
|
26
|
+
|
|
27
|
+
verify_upgrade_package
|
|
28
|
+
|
|
29
|
+
Filer.g_log_file GiteePack.logger.history
|
|
23
30
|
end
|
|
24
31
|
|
|
25
32
|
private
|
|
26
33
|
|
|
27
|
-
def
|
|
34
|
+
def compile_webpack_files_and_cp
|
|
35
|
+
if process_webpack?
|
|
36
|
+
Precompile.with_webpack
|
|
37
|
+
unless Status.success?($?)
|
|
38
|
+
Filer.g_log_file GiteePack.logger.history
|
|
39
|
+
exit Status::ERR_COMPILE_WEBPACK
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
Filer.cp_webpack_files
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def compile_asset_files_and_cp
|
|
47
|
+
if process_asset?
|
|
48
|
+
Precompile.with_asset
|
|
49
|
+
unless Status.success?($?)
|
|
50
|
+
Filer.g_log_file GiteePack.logger.history
|
|
51
|
+
exit Status::ERR_COMPILE_ASSET
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
Filer.cp_asset_files
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def compile_gems_and_cp
|
|
59
|
+
if process_gem?
|
|
60
|
+
Precompile.with_gem
|
|
61
|
+
unless Status.success?($?)
|
|
62
|
+
Filer.g_log_file GiteePack.logger.history
|
|
63
|
+
exit Status::ERR_COMPILE_GEM
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
Filer.cp_gems
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def verify_upgrade_package
|
|
71
|
+
GiteePack.logger.info '[Verifying] package is verifying, please wait ...'
|
|
72
|
+
|
|
73
|
+
verify_digest_with_cp_files
|
|
74
|
+
verify_digest_with_webpacks_dir
|
|
75
|
+
verify_digest_with_assets_dir
|
|
76
|
+
verify_digest_with_gems_dir
|
|
77
|
+
|
|
78
|
+
unless @errors.empty?
|
|
79
|
+
Filer.g_log_file GiteePack.logger.history
|
|
80
|
+
exit Status::ERR_VERIFY_PACKAGE
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def verify_digest_with_cp_files
|
|
85
|
+
@diff.cp_files.each do |file|
|
|
86
|
+
from = File.join(Folder.upgrade_files_dir, file)
|
|
87
|
+
to = file
|
|
88
|
+
verify_files from, to
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def verify_digest_with_webpacks_dir
|
|
93
|
+
if process_webpack?
|
|
94
|
+
from = File.join(Folder.upgrade_files_dir, Folder.webpacks_dir)
|
|
95
|
+
to = Folder.webpacks_dir
|
|
96
|
+
verify_files from, to
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def verify_digest_with_assets_dir
|
|
101
|
+
if process_asset?
|
|
102
|
+
from = File.join(Folder.upgrade_files_dir, Folder.assets_dir)
|
|
103
|
+
to = Folder.assets_dir
|
|
104
|
+
verify_files from, to
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def verify_digest_with_gems_dir
|
|
109
|
+
if process_gem?
|
|
110
|
+
from = File.join(Folder.upgrade_files_dir, Folder.bundle_cache_dir)
|
|
111
|
+
to = Folder.bundle_cache_dir
|
|
112
|
+
verify_files from, to
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def verify_files(from, to)
|
|
117
|
+
result, message = Verifier.new.execute(from, to)
|
|
118
|
+
GiteePack.logger.debug message
|
|
119
|
+
set_errors(result, message) unless result
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def process_webpack?
|
|
123
|
+
!@options[:skip_webpack_compile] && @diff.has_webpack_file?
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def process_asset?
|
|
127
|
+
!@options[:skip_asset_compile] && @diff.has_asset_file?
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def process_gem?
|
|
131
|
+
!@options[:skip_gem_compile] && @diff.has_gem_file?
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def set_errors(result, message)
|
|
135
|
+
@errors << { result: result, message: message }
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def puts_deleted_files
|
|
28
139
|
unless @diff.delete_files.empty?
|
|
29
|
-
|
|
30
|
-
|
|
140
|
+
GiteePack.logger.warn "\nDelete Files:"
|
|
141
|
+
GiteePack.logger.warn "#{@diff.delete_files.join("\n")}"
|
|
31
142
|
end
|
|
32
143
|
end
|
|
33
144
|
|
|
34
145
|
def puts_empty_folders
|
|
35
146
|
unless @diff.empty_folders.empty?
|
|
36
|
-
|
|
37
|
-
|
|
147
|
+
GiteePack.logger.warn "\nEmpty Folders:"
|
|
148
|
+
GiteePack.logger.warn "#{@diff.empty_folders.join("\n")}"
|
|
38
149
|
end
|
|
39
150
|
end
|
|
40
151
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gitee_pack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- jk-sun
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-01-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description:
|
|
14
14
|
email:
|
|
@@ -23,15 +23,18 @@ files:
|
|
|
23
23
|
- LICENSE.txt
|
|
24
24
|
- README.md
|
|
25
25
|
- Rakefile
|
|
26
|
-
- bin/console
|
|
27
26
|
- bin/gitee_pack
|
|
28
|
-
-
|
|
27
|
+
- exe/update.sh
|
|
29
28
|
- gitee_pack.gemspec
|
|
30
29
|
- lib/gitee_pack.rb
|
|
31
30
|
- lib/gitee_pack/diff.rb
|
|
32
31
|
- lib/gitee_pack/filer.rb
|
|
33
32
|
- lib/gitee_pack/folder.rb
|
|
33
|
+
- lib/gitee_pack/logger.rb
|
|
34
|
+
- lib/gitee_pack/parser.rb
|
|
34
35
|
- lib/gitee_pack/precompile.rb
|
|
36
|
+
- lib/gitee_pack/status.rb
|
|
37
|
+
- lib/gitee_pack/verifier.rb
|
|
35
38
|
- lib/gitee_pack/version.rb
|
|
36
39
|
- lib/gitee_pack/worker.rb
|
|
37
40
|
homepage: https://github.com/JK-Sun/gitee_pack
|
data/bin/console
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
require "gitee_pack"
|
|
5
|
-
|
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
-
|
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
-
# require "pry"
|
|
11
|
-
# Pry.start
|
|
12
|
-
|
|
13
|
-
require "irb"
|
|
14
|
-
IRB.start(__FILE__)
|