Kobold 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c742718fdab33d2dcf4ca03749e3df35e57a3ffbf988f2ba2a58904ce3414c3
4
- data.tar.gz: abd99306ceb78dde69e0dcb504670c2cd9bcb54f9c792ffee570b74e4c9ee07c
3
+ metadata.gz: 9a104942e0236e764a6fa1adbd31d8e65fa84f550ff56c4138db311191dcb58a
4
+ data.tar.gz: 696e18a91d1a5d84d9ba8f3cebe96cc18805bce71a94b4227fdb482bca9fc8ce
5
5
  SHA512:
6
- metadata.gz: 5e654583ded3e1113c5c427c32547414ee020290401ac27c43bc7de77e948f9d1314f0ed3dd8272f55627e592277001f0ec776ff6175198232457c6cb0af47cf
7
- data.tar.gz: e75b81edfe86a795b9fdfcf64a04f03611b5adedcaf32d9772047f141cca651b12f6b7706b69738d28fd7b57f4270d6848b95feb92743e2e76a7ba4edffaac03
6
+ metadata.gz: e403e1b4a039586145d0de0b2311ebccb258e418fef3c43981ddbf0324d234b3d9fbe3a65c3892da01edd3b63233e427dfc2ba3af65dfe559b85c86d33aefbf8
7
+ data.tar.gz: f2f7d927a487911b8ddc39967378761568bb28ab9e8c199a8c5c4136dcb23a309101494e95b7f0f8484f3c61dc16cfc84f1043dfa2c7046595cbe7a2648f2229
data/exe/kobold CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'Kobold'
4
4
  require 'tty-option'
5
- require 'pry'
5
+ #require 'pry'
6
6
 
7
7
  module Kobold
8
8
  class Command
@@ -11,24 +11,19 @@ module Kobold
11
11
  usage do
12
12
  program "kobold"
13
13
 
14
- command "init"
14
+ commands "init", "invoke"
15
15
 
16
- desc "Initializes empty Kobold configuration file"
17
16
  end
18
17
 
19
18
  argument :command do
20
19
  optional
21
- desc "askjd"
20
+ desc "Accepts commands for Kobold to execute."
22
21
  end
23
22
 
24
23
  flag :help do
25
24
  short "-h"
26
25
  long "--help"
27
- desc "Print usage"
28
- end
29
-
30
- flag :init do
31
- desc "initialize"
26
+ desc "Print usage."
32
27
  end
33
28
 
34
29
  def run
@@ -37,7 +32,7 @@ module Kobold
37
32
  elsif params.errors.any?
38
33
  puts params.errors.summary
39
34
  else
40
- pp params.to_h
35
+ #pp params.to_h
41
36
  end
42
37
  end
43
38
  end
@@ -50,6 +45,16 @@ run = cmd.run
50
45
 
51
46
  if cmd.params[:command] == nil || cmd.params == "invoke"
52
47
  Kobold.invoke
53
- elsif cmd.params[:command] == "init"
54
- Kobold.init
48
+ else
49
+ case cmd.params[:command]
50
+ when "add"
51
+ when "remove"
52
+ when "update"
53
+ when "list"
54
+ Kobold.list
55
+ when "init"
56
+ Kobold.init
57
+ else
58
+ print cmd.help
59
+ end
55
60
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tty-config"
4
+ require 'fileutils'
5
+ require 'git'
6
+
7
+ module Kobold
8
+ class << self
9
+ def first_time_setup
10
+ FileUtils.mkdir_p "#{KOBOLD_DIR}/repo_cache"
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tty-config"
4
+ require 'fileutils'
5
+ require 'git'
6
+
7
+ module Kobold
8
+ class << self
9
+ # create empty file with current
10
+ # file version in current dir
11
+ def init
12
+ kobold_config = TTY::Config.new
13
+ kobold_config.filename = ".kobold"
14
+ kobold_config.extname = ".ini"
15
+ kobold_config.set "_kobold_config", "format_version", value: Kobold::FORMAT_VERSION
16
+ kobold_config.write
17
+ File.rename ".kobold.ini", ".kobold"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,202 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tty-config"
4
+ require 'fileutils'
5
+ require 'git'
6
+
7
+ #require_relative "Kobold/vars.rb"
8
+
9
+ module Kobold
10
+ class << self
11
+ def invoke
12
+ Kobold.first_time_setup if !File.directory? "#{KOBOLD_DIR}/repo_cache"
13
+ if !File.file? "#{Dir.pwd}/.kobold"
14
+ puts "ERROR: Kobold file not found at '#{Dir.pwd}'"
15
+ return
16
+ end
17
+ settings = Kobold.read_config(Dir.pwd)
18
+
19
+ if Kobold::FORMAT_VERSION == settings["_kobold_config"]["format_version"]
20
+ # iterate over all dependencies
21
+ settings.each do |key, value|
22
+ if key[0] == '_'
23
+ next
24
+ end
25
+ repo_dir = "#{KOBOLD_DIR}/repo_cache/#{value['repo'].gsub('/', '-')}"
26
+
27
+ source_repo = nil;
28
+ # check if source exists
29
+ if !Dir.exist? "#{repo_dir}/source" # TODO: make this properly check for git repo
30
+ # if it doesnt, make it
31
+ FileUtils.mkdir_p "#{repo_dir}/source"
32
+ FileUtils.mkdir_p "#{repo_dir}/worktrees"
33
+ FileUtils.mkdir_p "#{repo_dir}/worktrees/branched"
34
+ FileUtils.mkdir_p "#{repo_dir}/worktrees/sha"
35
+ FileUtils.mkdir_p "#{repo_dir}/worktrees/labelled"
36
+ FileUtils.mkdir_p "#{repo_dir}/branches"
37
+ source_repo = clone_git_repo "#{value["source"]}/#{value['repo']}.git", "#{repo_dir}/source"
38
+ else
39
+ source_repo = Git.open("#{repo_dir}/source")
40
+ end
41
+
42
+ # must be scoped here, used in various inner scopes
43
+ target_symlink = nil
44
+
45
+ # Structure of a segment of following code:
46
+ # if it declares a branch: make the branch
47
+ # if it has a label
48
+ # it must have a sha
49
+ # if it has a branch
50
+ # use that branch + sha
51
+ # else
52
+ # use source + sha
53
+ # end
54
+ # else check if it has a branch
55
+ # if it has a sha
56
+ # make the sha
57
+ # else
58
+ # make it point to branch
59
+ # end
60
+ # else check if it has a sha
61
+ # make the sha on the source
62
+ # else
63
+ # use source
64
+ # end
65
+
66
+ branch_repo = nil
67
+ if value["branch"]
68
+ branch_repo_path = "#{repo_dir}/branches/#{value["branch"]}"
69
+ # check if branch already exists, make it if it doesnt
70
+ if !Dir.exist? branch_repo_path
71
+ FileUtils.mkdir_p "#{repo_dir}/branches"
72
+ source_repo.worktree(branch_repo_path, value["branch"]).add
73
+ end
74
+ branch_repo = Git.open(branch_repo_path)
75
+ end
76
+
77
+ target_symlink = nil
78
+ # if it has a label
79
+ if value["label"]
80
+
81
+ if !value["commit"]
82
+ raise "Must give a specific sha when making a label. #{key} has no specific sha given"
83
+ end
84
+ if value["branch"]
85
+ worktree_path = "#{repo_dir}/worktrees/labelled/#{value["label"]}/#{value["branch"]}"
86
+ _commit_val = value["commit"].to_s.delete_prefix('"').delete_suffix('"').delete_prefix("'").delete_suffix("'")
87
+ worktree_sha = branch_repo.object(_commit_val).sha;
88
+ target_symlink = "#{worktree_path}/#{worktree_sha}"
89
+ if !Dir.exist? target_symlink
90
+ FileUtils.mkdir_p "#{worktree_path}"
91
+ branch_repo.worktree(target_symlink, worktree_sha).add
92
+ end
93
+ else
94
+ branch = source_repo.branch.name
95
+ worktree_path = "#{repo_dir}/worktrees/labelled/#{value["label"]}/#{branch}"
96
+ _commit_val = value["commit"].to_s.delete_prefix('"').delete_suffix('"').delete_prefix("'").delete_suffix("'")
97
+ worktree_sha = source_repo.object(_commit_val).sha;
98
+ target_symlink = "#{worktree_path}/#{worktree_sha}"
99
+ if !Dir.exist? target_symlink
100
+ FileUtils.mkdir_p "#{worktree_path}"
101
+ source_repo.worktree(target_symlink, worktree_sha).add
102
+ end
103
+ end
104
+
105
+ elsif value["branch"]
106
+
107
+ if value['sha']
108
+ worktree_path = "#{repo_dir}/worktrees/branched/#{branch}"
109
+ _commit_val = value["commit"].to_s.delete_prefix('"').delete_suffix('"').delete_prefix("'").delete_suffix("'")
110
+ worktree_sha = branch_repo.object(_commit_val).sha;
111
+ target_symlink = "#{worktree_path}/#{worktree_sha}"
112
+ if !Dir.exist? target_symlink
113
+ FileUtils.mkdir_p "#{worktree_path}"
114
+ branch_repo.worktree(target_symlink, worktree_sha).add
115
+ end
116
+ else
117
+ target_symlink = "#{repo_dir}/branches/#{value['branch']}"
118
+ end
119
+
120
+ elsif value["commit"]
121
+
122
+ worktree_path = "#{repo_dir}/worktrees/sha"
123
+ _commit_val = value["commit"].to_s.delete_prefix('"').delete_suffix('"').delete_prefix("'").delete_suffix("'")
124
+ worktree_sha = source_repo.object(_commit_val).sha;
125
+ target_symlink = "#{worktree_path}/#{worktree_sha}"
126
+ if !Dir.exist? target_symlink
127
+ FileUtils.mkdir_p "#{worktree_path}"
128
+ source_repo.worktree(target_symlink, worktree_sha).add
129
+ end
130
+
131
+ else
132
+
133
+ target_symlink = "#{repo_dir}/source"
134
+
135
+ end
136
+
137
+ # build the symlink
138
+ if value["dir"].end_with? "/"
139
+ FileUtils.mkdir_p value["dir"]
140
+ #puts "value: " + value["dir"] + key.split('/').last
141
+ #puts !File.symlink?(value["dir"] + key.split('/').last)
142
+
143
+ symlink1 = File.symlink?(value["dir"] + value['repo'].split('/').last)
144
+ symlink2 = File.symlink? value["dir"]
145
+
146
+ if !(symlink1 || symlink2)
147
+ puts "value['dir'] #{value['dir']}"
148
+ puts "value['repo'] #{value['repo']}"
149
+ puts "target_symlink #{target_symlink}"
150
+ File.symlink(target_symlink, "#{value['dir']}/#{value['repo'].split('/').last}")
151
+ end
152
+ #File.symlink(target_symlink, "#{value['dir']}/#{key.split('/').last}")
153
+
154
+ else
155
+ dir_components = value["dir"].split "/"
156
+ dir_components.pop
157
+ dir_components = dir_components.join "/"
158
+ FileUtils.mkdir_p dir_components
159
+ File.symlink(target_symlink, value["dir"]) if !File.symlink? value["dir"]
160
+
161
+ symlink1 = File.symlink?(value["dir"] + ['repo'].split('/').last)
162
+ symlink2 = File.symlink? value["dir"]
163
+
164
+ if !(symlink1 || symlink2)
165
+ File.symlink(target_symlink, value["dir"])
166
+ end
167
+ #File.symlink(target_symlink, value["dir"])
168
+ end
169
+
170
+ end
171
+
172
+ # iterate over all sub kobold files
173
+ sub_kobolds = if settings["_kobold_include"] then settings["_kobold_include"]["files"].strip.split("\n") else [] end
174
+ sub_kobolds.each do |path|
175
+ Dir.chdir(path.strip) do
176
+ invoke
177
+ end
178
+ end
179
+
180
+ else
181
+ raise "Wrong format version"
182
+ end
183
+ end
184
+
185
+ private
186
+
187
+ def clone_git_repo(url, path)
188
+ progress_bar = TTY::ProgressBar.new("[:bar] Cloning: #{url} ", bar_format: :blade, total: nil, width: 45)
189
+
190
+ thread = Thread.new(abort_on_exception: true) do
191
+ Git.clone url, path
192
+ end
193
+ progress_bar.start
194
+ while thread.status
195
+ progress_bar.advance
196
+ sleep 0.016
197
+ end
198
+ puts
199
+ return thread.value
200
+ end
201
+ end
202
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tty-config"
4
+ #require 'fileutils'
5
+
6
+ module Kobold
7
+ class << self
8
+ def read_config(dir)
9
+ config = TTY::Config.new
10
+ config.append_path dir
11
+ settings = config.read ".kobold", format: :ini
12
+ return settings
13
+ end
14
+ end
15
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kobold
4
- VERSION = "0.1.0"
5
- FORMAT_VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
+ FORMAT_VERSION = "0.3.0"
6
6
  end
data/lib/Kobold.rb CHANGED
@@ -1,110 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "Kobold/version"
4
- require "tty-config"
3
+ require_relative 'Kobold/version'
4
+ require 'tty-config'
5
5
  require 'fileutils'
6
6
  require 'git'
7
+ require 'tty-progressbar'
8
+
9
+ require_relative 'Kobold/vars.rb'
10
+ require_relative 'Kobold/read_config.rb'
11
+ require_relative 'Kobold/first_time_setup.rb'
12
+ require_relative 'Kobold/invoke.rb'
13
+ require_relative 'Kobold/init.rb'
7
14
 
8
15
  module Kobold
9
16
  KOBOLD_DIR = "#{Dir.home}/.local/share/Kobold"
10
17
  class << self
11
-
12
- # read configuration file
13
- # for each item:
14
- # 1. check if repo exists
15
- # ~2. check if correct version exists~
16
- # 3. check if symlink is correct
17
-
18
- def invoke
19
- first_time_setup if !File.directory? "#{KOBOLD_DIR}/repo_cache"
20
- config = TTY::Config.new
21
- config.append_path Dir.pwd
22
- settings = config.read ".kobold", format: :ini
23
-
24
- puts Kobold::FORMAT_VERSION + " " + settings["kobold_config"]["format_version"]
25
- if Kobold::FORMAT_VERSION == settings["kobold_config"]["format_version"]
26
- settings.delete "kobold_config"
27
-
28
- # iterate over all dependencies
29
- settings.each do |key, value|
30
- puts "key:#{key}"
31
- repo_dir = "#{KOBOLD_DIR}/repo_cache/#{key.gsub('/', '-')}"
32
-
33
- master_repo = nil;
34
- # check if master exists
35
- if !Dir.exist? "#{repo_dir}/master" # TODO: make this properly check for git repo
36
- # if it doesnt, make it
37
- FileUtils.mkdir_p "#{repo_dir}/master"
38
- FileUtils.mkdir_p "#{repo_dir}/worktrees"
39
- puts "#{value["source"]}/#{key}.git", "#{repo_dir}/master"
40
- master_repo = Git.clone "#{value["source"]}/#{key}.git", "#{repo_dir}/master"
41
- else
42
- master_repo = Git.open("#{repo_dir}/master")
43
- end
44
-
45
- target_symlink = nil
46
- # check if requested version exists
47
- if value["tag"]
48
- dir_name = value["tag"].to_s.gsub("/","-")
49
- # TODO make the thing
50
- else # use hash as name
51
- if value["commit"]
52
- # use given commit name, also check it exists
53
- begin # git errors when it does not find the hash
54
- if value["commit"].is_a? Float
55
- value["commit"] = value["commit"].to_i.to_s
56
- end
57
- commit_sha = master_repo.object(value["commit"].to_s.delete_prefix('"').delete_suffix('"').delete_prefix("'").delete_suffix("'")).sha;
58
- if commit_sha
59
- target_symlink = "#{repo_dir}/worktrees/#{commit_sha}"
60
- if !Dir.exist? target_symlink
61
- # make it
62
- master_repo.worktree(target_symlink, commit_sha).add
63
- end
64
- else
65
- raise "Cannot find commit"
66
- end
67
- rescue # we catch this error here
68
- raise "Cannot find commit"
69
- end
70
- else
71
- raise "No commit given for #{key}"
72
- end
73
- end
74
-
75
- # build the symlink
76
- if value["dir"].end_with? "/"
77
- FileUtils.mkdir_p value["dir"]
78
- File.symlink target_symlink, "#{value['dir']}/#{key.split('/').last}"
79
- else
80
- dir_components = value["dir"].split "/"
81
- dir_components.pop
82
- dir_components = dir_components.join "/"
83
- FileUtils.mkdir_p dir_components
84
- File.symlink target_symlink, value["dir"]
85
- end
86
-
87
- end
88
-
89
- else
90
- raise "Wrong format version"
91
- end
92
-
93
- end
94
-
95
- def first_time_setup
96
- FileUtils.mkdir_p "#{KOBOLD_DIR}/repo_cache"
97
- end
98
-
99
- # create empty file with current
100
- # file version in current dir
101
- def init
102
- kobold_config = TTY::Config.new
103
- kobold_config.filename = ".kobold"
104
- kobold_config.extname = ".ini"
105
- kobold_config.set "kobold_config", "format_version", value: Kobold::FORMAT_VERSION
106
- kobold_config.write
107
- File.rename ".kobold.ini", ".kobold"
108
- end
109
18
  end
110
19
  end
@@ -1,2 +1,4 @@
1
1
  external
2
2
  external/raylib
3
+ dir1
4
+ dir2
data/prototyping/.kobold CHANGED
@@ -1,7 +1,28 @@
1
- [kobold_config]
2
- format_version = 0.1.0
1
+ [_kobold_config]
2
+ format_version = 0.3.0
3
3
 
4
- [raysan5/raylib]
4
+ ;[_kobold_include]
5
+ ;files = "
6
+ ;dir1/
7
+ ;dir2/
8
+ ;"
9
+
10
+ [raylib-linux]
11
+ repo = raysan5/raylib
12
+ source = https://github.com
13
+ dir = external/linux-x64/
14
+ commit = 'b8cd102'
15
+ label = linux-x64
16
+
17
+ [raylib-web]
18
+ repo = raysan5/raylib
19
+ source = https://github.com
20
+ dir = external/emscripten/
21
+ commit = 'b8cd102'
22
+ label = web
23
+
24
+ [raygui]
25
+ repo = raysan5/raygui
5
26
  source = https://github.com
6
27
  dir = external/
7
- commit = '0851960'
28
+
metadata CHANGED
@@ -1,15 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Kobold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - CatsAtTheRodeo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-30 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-09-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tty-option
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-config
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: inifile
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: git
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.18.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.18.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: tty-progressbar
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.18.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.18.2
13
83
  description:
14
84
  email:
15
85
  - contact@tradam.dev
@@ -33,6 +103,10 @@ files:
33
103
  - Rakefile
34
104
  - exe/kobold
35
105
  - lib/Kobold.rb
106
+ - lib/Kobold/first_time_setup.rb
107
+ - lib/Kobold/init.rb
108
+ - lib/Kobold/invoke.rb
109
+ - lib/Kobold/read_config.rb
36
110
  - lib/Kobold/version.rb
37
111
  - prototyping/.gitignore
38
112
  - prototyping/.kobold
@@ -60,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
134
  - !ruby/object:Gem::Version
61
135
  version: '0'
62
136
  requirements: []
63
- rubygems_version: 3.4.7
137
+ rubygems_version: 3.3.25
64
138
  signing_key:
65
139
  specification_version: 4
66
140
  summary: Version manager for various libraries and projects.