gitee_pack 1.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3f4e4fc20534e610006456f1253a49882b4d7366579141ab00268e8fc77b8f9d
4
+ data.tar.gz: d4e748f744e3f468974e86d1a9ae3458a0b6d4e534ee836d709eafb9eb54be7e
5
+ SHA512:
6
+ metadata.gz: 131088c837eef33d4e89c723348540fb9413ecf8d4fddd87277a6cc78aeeb6e88bcef4b195020e8b46876cb041b3e9abc00e0bb54aee277b3634f88528c25eae
7
+ data.tar.gz: 51d709aba694a05a51d6f19c5ea08e080eb19f2827c16ea17d3606f85f5a85235b9fd4aa72bc2d280e593b3a83a1da72c19fad45ff967b7cd7e04acbb4166612
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gitee_pack.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # GiteePack
2
+
3
+ 一个GiteePremium增量打包工具
4
+
5
+ ## 安装
6
+
7
+ 在gitee-premium目录执行:
8
+
9
+ ```shell
10
+ $ gem install gitee_pack
11
+ ```
12
+
13
+ ## 使用
14
+
15
+ ### 打包
16
+
17
+ 在gitee-premium目录执行:
18
+
19
+ ```shell
20
+ $ gitee_pack [base] [head]
21
+ ```
22
+
23
+ base: Commit提交的SHA值作为对比起点
24
+
25
+ head: Commit提交的SHA值作为对比终点
26
+
27
+ 示例:
28
+
29
+ ```shell
30
+ $ gitee_pack a9b6296 6ac0f97
31
+ ```
32
+
33
+ 执行后会在当前目录下生成一个增量文件的升级包,例如 upgrade-20200430
34
+
35
+ ### 部署
36
+
37
+ 先备份原有文件
38
+
39
+ 在升级包中执行update.sh脚本,一键自动部署
40
+
41
+ ```shell
42
+ $ cd upgrade-20200430
43
+ $ ./update.sh [gitee-path]
44
+ ```
45
+
46
+ gitee-path: gitee-premium的绝对路径
47
+
48
+ 示例
49
+
50
+ ```shell
51
+ $ ./update.sh /home/gite/gitee-premium/gitee
52
+ ```
53
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
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__)
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gitee_pack'
4
+
5
+ base, head = ARGV[0], ARGV[1]
6
+
7
+ start_at = Time.now
8
+ GiteePack.execute(base, head)
9
+ end_at = Time.now
10
+
11
+ GiteePack.logger.success "Complete! cost time: #{end_at - start_at} seconds."
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,18 @@
1
+ require_relative 'lib/gitee_pack/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "gitee_pack"
5
+ spec.version = GiteePack::VERSION
6
+ spec.authors = ["jk-sun"]
7
+ spec.email = ["jk-sun@qq.com"]
8
+
9
+ spec.summary = %q{It's incremental packager for Gitee Premium.}
10
+ spec.homepage = "https://github.com/JK-Sun/gitee_pack"
11
+ spec.license = "MIT"
12
+
13
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
14
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ end
16
+ spec.executables = ["gitee_pack"]
17
+ spec.require_paths = ["lib"]
18
+ end
@@ -0,0 +1,21 @@
1
+ require 'fileutils'
2
+
3
+ require 'gitee_pack/version'
4
+ require 'gitee_pack/diff'
5
+ require 'gitee_pack/folder'
6
+ require 'gitee_pack/filer'
7
+ require 'gitee_pack/precompile'
8
+ require 'gitee_pack/logger'
9
+ require 'gitee_pack/worker'
10
+
11
+ module GiteePack
12
+ class CmdError < StandardError; end
13
+
14
+ def self.execute(base, head, options = {})
15
+ Worker.new(base, head).execute
16
+ end
17
+
18
+ def self.logger
19
+ @logger ||= Logger.new
20
+ end
21
+ end
@@ -0,0 +1,71 @@
1
+ module GiteePack
2
+ class Diff
3
+ attr_reader :empty_folders, :delete_files, :cp_files
4
+
5
+ IGNORE_FILES = [
6
+ 'config/gitee.yml',
7
+ 'config/database.yml',
8
+ 'config/startup.yml',
9
+ 'app/assets/javascripts/webpack/webide'
10
+ ].freeze
11
+
12
+ def initialize(base, head)
13
+ @base = base
14
+ @head = head
15
+ @precompile = false
16
+ @empty_folders = []
17
+ @delete_files = []
18
+ @cp_files = []
19
+
20
+ init_list_by_files
21
+ end
22
+
23
+ def diff_files
24
+ result = `git diff #{@base} #{@head} --name-only`
25
+ raise CmdError, 'cmd error' if result.empty?
26
+
27
+ result.split("\n")
28
+ end
29
+
30
+ def diff_files_with_status
31
+ result = `git diff #{@base} #{@head} --name-status`
32
+ raise CmdError, 'cmd error' if result.empty?
33
+
34
+ result.split("\n")
35
+ end
36
+
37
+ def precompile?
38
+ @precompile
39
+ end
40
+
41
+ private
42
+
43
+ def init_list_by_files
44
+ init_empty_folders_and_cp_files
45
+ init_delete_files
46
+ end
47
+
48
+ def init_delete_files
49
+ @delete_files = diff_files_with_status.map do |file|
50
+ file.sub("D\t", '') if file.start_with?('D')
51
+ end.compact
52
+ end
53
+
54
+ def init_empty_folders_and_cp_files
55
+ diff_files.each do |file|
56
+ next if IGNORE_FILES.include?(file)
57
+
58
+ file.start_with?('app/assets/javascripts/webpack') && @precompile = true
59
+
60
+ if Dir.exist?(file)
61
+ @empty_folders << file
62
+ next
63
+ end
64
+
65
+ next unless File.exist?(file)
66
+
67
+ @cp_files << file
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,35 @@
1
+ #!/bin/bash
2
+
3
+ GITEE_PATH=$1
4
+ if [ ! $GITEE_PATH ]; then
5
+ printf "\033[31mERROR: gitee-path cannot not be empty.\033[0m\n"
6
+ exit 1
7
+ fi
8
+
9
+ FINAL=${GITEE_PATH: -1}
10
+ if [ $FINAL = '/' ]; then
11
+ GITEE_PATH=${GITEE_PATH%?}
12
+ fi
13
+
14
+ APP_PATH=$GITEE_PATH/app
15
+ CONFIG_APTH=$GITEE_PATH/config
16
+ DB_APTH=$GITEE_PATH/db
17
+ if [ ! -d $APP_PATH ] || [ ! -d $CONFIG_PATH ] || [ ! -d $DB_PATH ]; then
18
+ printf "\033[31mERROR: $GITEE_PATH is not the gitee-path.\033[0m\n"
19
+ exit 1
20
+ fi
21
+
22
+ cp -r files/* $GITEE_PATH
23
+ echo cp -r files/\* $GITEE_PATH
24
+
25
+ DELETE_FILE=delete.txt
26
+ if [ -f $DELETE_FILE ]; then
27
+ while read LINE
28
+ do
29
+ rm -rf $GITEE_PATH/$LINE
30
+ echo rm -rf $GITEE_PATH/$LINE
31
+ done < $DELETE_FILE
32
+ fi
33
+
34
+ exit 0
35
+
@@ -0,0 +1,41 @@
1
+ module GiteePack
2
+ class Filer
3
+ class << self
4
+ def cp_diff_files(files)
5
+ files.each do |file|
6
+ dirname = File.join(Folder.upgrade_files_dir, File.dirname(file))
7
+ FileUtils.mkdir_p dirname
8
+ FileUtils.cp file, dirname
9
+ GiteePack.logger.debug "cp #{file} #{dirname}"
10
+ end
11
+ end
12
+
13
+ def cp_webpack_files
14
+ dirname = File.join(Folder.upgrade_files_dir, 'public/webpacks')
15
+ FileUtils.mkdir_p dirname
16
+ FileUtils.cp_r 'public/webpacks/.', dirname
17
+ GiteePack.logger.debug "cp -r public/webpacks/. #{dirname}"
18
+ end
19
+
20
+ def cp_update_file
21
+ filepath = File.join(File.dirname(__FILE__), 'exe/update.sh')
22
+ FileUtils.cp filepath, Folder.upgrade_dir
23
+ GiteePack.logger.debug "cp #{filepath} #{Folder.upgrade_dir}"
24
+ end
25
+
26
+ def g_file(path, content = [])
27
+ File.open(path, 'w') do |f|
28
+ f.write("#{content.join("\n")}\n")
29
+ end unless content.empty?
30
+ end
31
+
32
+ def g_delete_file(content = [])
33
+ g_file(File.join(Folder.upgrade_dir, 'delete.txt'), content)
34
+ end
35
+
36
+ def g_diff_file(content = [])
37
+ g_file(File.join(Folder.upgrade_dir, 'diff.txt'), content)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,29 @@
1
+ require 'fileutils'
2
+
3
+ module GiteePack
4
+ class Folder
5
+ class << self
6
+ def mkdir_upgrade
7
+ rm_dir(upgrade_dir)
8
+ FileUtils.mkdir_p(upgrade_files_dir)
9
+ GiteePack.logger.debug "mkdir #{upgrade_dir}"
10
+ GiteePack.logger.debug "mkdir #{upgrade_files_dir}"
11
+ end
12
+
13
+ def upgrade_dir
14
+ @upgrade_dir ||= "upgrade-#{Time.now.strftime('%Y%m%d')}"
15
+ end
16
+
17
+ def upgrade_files_dir
18
+ @upgrade_files_dir ||= File.join(upgrade_dir, 'files')
19
+ end
20
+
21
+ def rm_dir(dir)
22
+ if Dir.exist?(dir)
23
+ `rm -rf #{dir}`
24
+ GiteePack.logger.debug "rm -rf #{dir}"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ module GiteePack
2
+ class Logger
3
+ def debug(content)
4
+ puts content
5
+ end
6
+
7
+ def info(content)
8
+ puts "\033[36m#{content}\033[0m"
9
+ end
10
+
11
+ def warn(content)
12
+ puts "\033[33m#{content}\033[0m"
13
+ end
14
+
15
+ def error(content)
16
+ puts "\033[31m#{content}\033[0m"
17
+ end
18
+
19
+ def success(content)
20
+ puts "\033[32m#{content}\033[0m"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ module GiteePack
2
+ class Precompile
3
+ class << self
4
+ def with_webpack
5
+ Folder.rm_dir('public/webpacks')
6
+ `npm run build-vendor`
7
+ `npm run f-build`
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module GiteePack
2
+ VERSION = "1.1.0"
3
+ end
@@ -0,0 +1,42 @@
1
+ module GiteePack
2
+ class Worker
3
+ def initialize(base, head)
4
+ @base = base
5
+ @head = head
6
+ @diff = Diff.new(@base, @head)
7
+ end
8
+
9
+ def execute
10
+ Folder.mkdir_upgrade
11
+ Filer.cp_diff_files(@diff.cp_files)
12
+
13
+ if @diff.precompile?
14
+ Precompile.with_webpack
15
+ Filer.cp_webpack_files
16
+ end
17
+
18
+ Filer.g_diff_file(@diff.diff_files_with_status)
19
+ Filer.g_delete_file(@diff.delete_files)
20
+ Filer.cp_update_file
21
+
22
+ puts_empty_folders
23
+ puts_delete_files
24
+ end
25
+
26
+ private
27
+
28
+ def puts_delete_files
29
+ unless @diff.delete_files.empty?
30
+ GiteePack.logger.warn "\nDelete Files:"
31
+ GiteePack.logger.warn "#{@diff.delete_files.join("\n")}"
32
+ end
33
+ end
34
+
35
+ def puts_empty_folders
36
+ unless @diff.empty_folders.empty?
37
+ GiteePack.logger.warn "\nEmpty Folders:"
38
+ GiteePack.logger.warn "#{@diff.empty_folders.join("\n")}"
39
+ end
40
+ end
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitee_pack
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jk-sun
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - jk-sun@qq.com
16
+ executables:
17
+ - gitee_pack
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - bin/console
27
+ - bin/gitee_pack
28
+ - bin/setup
29
+ - gitee_pack.gemspec
30
+ - lib/gitee_pack.rb
31
+ - lib/gitee_pack/diff.rb
32
+ - lib/gitee_pack/exe/update.sh
33
+ - lib/gitee_pack/filer.rb
34
+ - lib/gitee_pack/folder.rb
35
+ - lib/gitee_pack/logger.rb
36
+ - lib/gitee_pack/precompile.rb
37
+ - lib/gitee_pack/version.rb
38
+ - lib/gitee_pack/worker.rb
39
+ homepage: https://github.com/JK-Sun/gitee_pack
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.1.2
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: It's incremental packager for Gitee Premium.
62
+ test_files: []