dotfiles-tui 0.0.6 → 0.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.
- checksums.yaml +4 -4
- data/bootstrap.rb +10 -3
- data/lib/dotfiles_tui/initializer.rb +91 -0
- data/lib/dotfiles_tui/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 99df3422da7ac64a7988774cd47e0a6457914fd1fcc4244ea49af15da5e109cc
|
|
4
|
+
data.tar.gz: 266e40a25302449fb0b1bac341d6d682afc9cdd288af268bd90c50952266c8c9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2a1281b93152b7943e794707701cebd22646e3d41d61ac76a80f4d5410eb9adbc81dd77cfe88c111570e4734e768145459901f15e134b74ffb30b823e643f94b
|
|
7
|
+
data.tar.gz: 3c4a2438638790cb128b2b97db1e1a84a79438c3278c076e44de06c4678231954eeef55bcac3cf41ad1c072d7815cfd471a8d4d7d473a9f8bd2829354ebacfde
|
data/bootstrap.rb
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
# frozen_string_literal: true
|
|
4
4
|
|
|
5
|
-
# Set up the Bundler environment
|
|
6
|
-
|
|
5
|
+
# Set up the Bundler environment (only when running from source)
|
|
6
|
+
begin
|
|
7
|
+
require 'bundler/setup'
|
|
8
|
+
rescue LoadError
|
|
9
|
+
# Running as installed gem - dependencies already managed by RubyGems
|
|
10
|
+
end
|
|
7
11
|
require 'optparse'
|
|
8
12
|
|
|
9
13
|
require_relative './Hooks/core/common'
|
|
@@ -41,7 +45,10 @@ module Bootstrap
|
|
|
41
45
|
SCRIPT_DIR = GEM_ROOT
|
|
42
46
|
else
|
|
43
47
|
# Running from gem installation - use user directory
|
|
44
|
-
|
|
48
|
+
# Ensure the gem's lib directory is in the load path
|
|
49
|
+
lib_dir = File.join(GEM_ROOT, 'lib')
|
|
50
|
+
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
|
|
51
|
+
require 'dotfiles_tui/initializer'
|
|
45
52
|
SCRIPT_DIR = DotfilesTui::Initializer.setup(GEM_ROOT)
|
|
46
53
|
end
|
|
47
54
|
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
|
|
5
|
+
module DotfilesTui
|
|
6
|
+
# Handles initialization of the user-writable working directory
|
|
7
|
+
module Initializer
|
|
8
|
+
WORKING_DIR = File.join(Dir.home, '.dotfiles-tui')
|
|
9
|
+
VERSION_FILE = File.join(WORKING_DIR, '.version')
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
# Initialize the working directory with files from the gem
|
|
13
|
+
# @param gem_root [String] Path to the gem installation directory
|
|
14
|
+
# @return [String] Path to the working directory
|
|
15
|
+
def setup(gem_root)
|
|
16
|
+
ensure_working_directory_exists
|
|
17
|
+
copy_gem_files_if_needed(gem_root)
|
|
18
|
+
WORKING_DIR
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def ensure_working_directory_exists
|
|
24
|
+
return if Dir.exist?(WORKING_DIR)
|
|
25
|
+
|
|
26
|
+
FileUtils.mkdir_p(WORKING_DIR)
|
|
27
|
+
puts "Created working directory at #{WORKING_DIR}"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def copy_gem_files_if_needed(gem_root)
|
|
31
|
+
current_version = DotfilesTui::VERSION
|
|
32
|
+
installed_version = read_installed_version
|
|
33
|
+
|
|
34
|
+
# Copy files if:
|
|
35
|
+
# 1. This is the first run (no version file)
|
|
36
|
+
# 2. The gem version has changed
|
|
37
|
+
# 3. Required directories are missing
|
|
38
|
+
if installed_version.nil? || installed_version != current_version || missing_required_directories?
|
|
39
|
+
copy_gem_files(gem_root)
|
|
40
|
+
write_version_file(current_version)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def missing_required_directories?
|
|
45
|
+
!Dir.exist?(File.join(WORKING_DIR, 'Configs')) ||
|
|
46
|
+
!Dir.exist?(File.join(WORKING_DIR, 'Hooks'))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def copy_gem_files(gem_root)
|
|
50
|
+
puts "Initializing dotfiles-tui working directory..."
|
|
51
|
+
|
|
52
|
+
# Copy Configs
|
|
53
|
+
gem_configs = File.join(gem_root, 'Configs')
|
|
54
|
+
if Dir.exist?(gem_configs)
|
|
55
|
+
dest_configs = File.join(WORKING_DIR, 'Configs')
|
|
56
|
+
FileUtils.mkdir_p(dest_configs)
|
|
57
|
+
FileUtils.cp_r("#{gem_configs}/.", dest_configs, remove_destination: false)
|
|
58
|
+
puts " ✓ Copied Configs"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Copy Hooks
|
|
62
|
+
gem_hooks = File.join(gem_root, 'Hooks')
|
|
63
|
+
if Dir.exist?(gem_hooks)
|
|
64
|
+
dest_hooks = File.join(WORKING_DIR, 'Hooks')
|
|
65
|
+
FileUtils.mkdir_p(dest_hooks)
|
|
66
|
+
FileUtils.cp_r("#{gem_hooks}/.", dest_hooks, remove_destination: false)
|
|
67
|
+
puts " ✓ Copied Hooks"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Copy .env if it exists
|
|
71
|
+
gem_env = File.join(gem_root, '.env')
|
|
72
|
+
if File.exist?(gem_env)
|
|
73
|
+
FileUtils.cp(gem_env, File.join(WORKING_DIR, '.env'))
|
|
74
|
+
puts " ✓ Copied .env"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def read_installed_version
|
|
79
|
+
return nil unless File.exist?(VERSION_FILE)
|
|
80
|
+
|
|
81
|
+
File.read(VERSION_FILE).strip
|
|
82
|
+
rescue StandardError
|
|
83
|
+
nil
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def write_version_file(version)
|
|
87
|
+
File.write(VERSION_FILE, version)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
data/lib/dotfiles_tui/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dotfiles-tui
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Narender
|
|
@@ -247,6 +247,7 @@ files:
|
|
|
247
247
|
- bootstrap.rb
|
|
248
248
|
- dotfiles-tui.gemspec
|
|
249
249
|
- lib/dotfiles_tui.rb
|
|
250
|
+
- lib/dotfiles_tui/initializer.rb
|
|
250
251
|
- lib/dotfiles_tui/version.rb
|
|
251
252
|
homepage: https://github.com/mr-narender/dotfiles-tui
|
|
252
253
|
licenses:
|