Module: Makit::Directories

Defined in:
lib/makit/directories.rb

Overview

This class provide methods for working with the system Environment.

Constant Summary collapse

ROOT =
normalize_path(File.join(Dir.home, ".makit"))
CLONE =
normalize_path(File.join(Dir.home, ".makit", "clone"))
MAKE =
normalize_path(File.join(Dir.home, ".makit", "make"))
LOG =
normalize_path(File.join(Dir.home, ".makit", "log"))
WORK =
normalize_path(File.join(Dir.home, ".makit", "work"))
REPOS =
normalize_path(File.join(Dir.home, ".makit", "repos"))
TEMP =
normalize_path(File.join(Dir.home, ".makit", "temp"))
INSTALL =
normalize_path(File.join(Dir.home, ".makit", "install"))
NUGET =
normalize_path(File.join(Dir.home, ".makit", "nuget"))
HOME =
normalize_path(_home_path)
ONEDRIVE =
normalize_path(_onedrive_path)
ONEDRIVE_NUGET_SOURCE =
normalize_path(File.join(_onedrive_path, "code", "artifacts", "nuget"))
ONEDRIVE_CONSOLE_SOURCE =
normalize_path(File.join(_onedrive_path, "code", "artifacts", "console"))
ONEDRIVE_INSTALLER_SOURCE =
normalize_path(File.join(_onedrive_path, "code", "artifacts", "installer"))
CURRENT =
normalize_path(Dir.pwd)
LOCAL_APPLICATION_DATA =
normalize_path(File.join(_home_path, "AppData", "Local"))
RAKEDIR =

Rake.application.init Rake.application.load_rakefile

normalize_path(_rakedir_path)
PROJECT_ROOT =
normalize_path(_project_root_path)
PROJECT_ARTIFACTS =

PROJECT_ROOT = Makit::Directory.find_directory_with_pattern(RAKEDIR, “Rakefile”) PROJECT_ROOT = Makit::Directory.find_directory_with_pattern(RAKEDIR, “rakefile.rb”) PROJECT_ROOT = Makit::Directory.find_directory_with_pattern(RAKEDIR, “.gitignore”)

if _project_root_path.nil?
  nil
else
  normalize_path(File.join(_project_root_path, "artifacts"))
end
LOCAL_NUGET_SOURCE =
normalize_path(File.join(Dir.home, ".makit", "nuget"))
NUGET_PACKAGE_CACHE =

NUGET_PACKAGE_CACHE = “#"USERPROFILE"\.nuget\packages”

normalize_path(Makit::Directory.normalize("#{Dir.home}/.nuget/packages"))
SERVICES =
if Makit::Environment.get_os == "macOS"
  "/Library/LaunchDaemons"
else
  "/etc/systemd/system"
end
GRPC_TOOLS_PATH =
normalize_path(File.join(NUGET_PACKAGE_CACHE, "grpc.tools", _grpc_tools_version))
GRPC_CSHARP_PLUGIN_PATH =
nil

Class Method Summary collapse

Class Method Details

.get_clone_directory(url) ⇒ Object



110
111
112
# File 'lib/makit/directories.rb', line 110

def self.get_clone_directory(url)
  File.join(CLONE, get_relative_directory(url))
end

.get_log_directory(url) ⇒ Object



126
127
128
# File 'lib/makit/directories.rb', line 126

def self.get_log_directory(url)
  File.join(LOG, get_relative_directory(url))
end

.get_make_commit_directory(url, commit_id) ⇒ Object



122
123
124
# File 'lib/makit/directories.rb', line 122

def self.get_make_commit_directory(url, commit_id)
  File.join(MAKE, get_relative_directory(url), commit_id)
end

.get_make_commit_log_filename(url, commit_id) ⇒ Object



130
131
132
# File 'lib/makit/directories.rb', line 130

def self.get_make_commit_log_filename(url, commit_id)
  File.join(LOG, get_relative_directory(url), "#{commit_id}.json")
end

.get_make_directory(url) ⇒ Object



118
119
120
# File 'lib/makit/directories.rb', line 118

def self.get_make_directory(url)
  File.join(MAKE, get_relative_directory(url))
end

.get_project_path(relative_path) ⇒ Object

NOTE: Nuget source setup moved to lazy initialization to avoid blocking module loading



106
107
108
# File 'lib/makit/directories.rb', line 106

def self.get_project_path(relative_path)
  File.join(PROJECT_ROOT, relative_path)
end

.get_relative_directory(url) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/makit/directories.rb', line 134

def self.get_relative_directory(url)
  # if url start with Directories::REPOS, then it is a local repository

  return url.gsub(REPOS, "") if url.start_with?(REPOS)

  url = url.gsub("https://", "").gsub("http://", "")
  url = url.gsub("gitlab.com", "gitlab")
  url = url.gsub("github.com", "github")

  # if the url ends with .git, remove it

  url = url.gsub(".git", "") if url.end_with?(".git")
  url
end

.get_work_directory(url) ⇒ Object



114
115
116
# File 'lib/makit/directories.rb', line 114

def self.get_work_directory(url)
  File.join(WORK, get_relative_directory(url))
end

.normalize_path(path) ⇒ Object

Helper method to normalize paths to use backslashes on Windows



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/makit/directories.rb', line 16

def self.normalize_path(path)
  return nil if path.nil?
  return path if path.empty?
  
  if Makit::Environment.is_windows?
    # Convert forward slashes to backslashes on Windows

    path.gsub(/\//, "\\")
  else
    # Keep forward slashes on Unix-like systems

    path
  end
end

.showObject

show all the directory constants in a nicely formatted table format with the name of the constant and the value



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/makit/directories.rb', line 148

def self.show
  # Array of constant names (symbols)

  constant_names = i[ROOT CLONE MAKE LOG WORK REPOS TEMP INSTALL HOME ONEDRIVE
                      CURRENT RAKEDIR
                      PROJECT_ROOT PROJECT_ARTIFACTS LOCAL_NUGET_SOURCE NUGET_PACKAGE_CACHE SERVICES
                      GRPC_TOOLS_PATH GRPC_CSHARP_PLUGIN_PATH]

  # Find the length of the longest constant name and add 1

  max_length = constant_names.map(&:to_s).max_by(&:length).length + 1

  # Iterate through each constant name

  constant_names.each do |constant_name|
    constant_value = const_get(constant_name) # Fetch the value of the constant

    constant_value = constant_value.colorize(:green) if !constant_value.nil? && Dir.exist?(constant_value)
    # Print the constant name right justified to the max_length

    puts "#{constant_name.to_s.rjust(max_length)} = #{constant_value}"
  rescue NameError
    # Handle the case where the constant is not defined

    puts "#{constant_name.to_s.rjust(max_length)} = [Constant not defined]"
  end
end