Class: Rawfeed::Installer
- Inherits:
-
Object
- Object
- Rawfeed::Installer
- Defined in:
- lib/rawfeed/command/installer.rb
Class Method Summary collapse
-
.copy_items(items, dest_path, force = false) ⇒ Object
Generic function to copy files or folders If dest is a nested directory, it automatically creates the parent directories.
- .create_new_site(path, *args) ⇒ Object
- .gem_root ⇒ Object
Class Method Details
.copy_items(items, dest_path, force = false) ⇒ Object
Generic function to copy files or folders If dest is a nested directory, it automatically creates the parent directories
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rawfeed/command/installer.rb', line 15 def self.copy_items(items, dest_path, force = false) items.each do |src, dest_rel| dest = File.join(dest_path, dest_rel) # Creates parent directory if it doesn't exist. FileUtils.mkdir_p(File.dirname(dest)) if File.exist?(src) || Dir.exist?(src) # Remove destination if it already exists and force is true if force && (File.exist?(dest) || Dir.exist?(dest)) if Dir.exist?(dest) FileUtils.rm_rf(dest) else File.delete(dest) end end FileUtils.cp_r(src, dest) else puts "Warning: #{src} not found".yellow end end end |
.create_new_site(path, *args) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/rawfeed/command/installer.rb', line 39 def self.create_new_site(path, *args) force = args.include?("--force") # Normalize path path = "." if path.nil? || path.empty? actual_path = File.(path) # Check if directory exists and is not empty if Dir.exist?(actual_path) entries = Dir.entries(actual_path) - [".", ".."] if entries.any? unless force puts "Directory #{path} is not empty!".red puts "Use the --force flag to proceed: rawfeed new #{path} --force".yellow return end end else FileUtils.mkdir_p(actual_path) end gem_dir = gem_root # --- files and folders to copy --- items_to_copy = [ [File.join(gem_dir, "Gemfile"), "Gemfile"], [File.join(gem_dir, "_config.yml"), "_config.yml"], [File.join(gem_dir, "index.md"), "index.md"], [File.join(gem_dir, "404.html"), "404.html"], [File.join(gem_dir, ".gitignore"), ".gitignore"], [File.join(gem_dir, ".gitlab/ci/gitlab-pages.yml"), ".gitlab/ci/gitlab-pages.yml"], [File.join(gem_dir, ".github/workflows/github-pages.yml"), ".github/workflows/github-pages.yml"], [File.join(gem_dir, ".editorconfig"), ".editorconfig"], [File.join(gem_dir, ".hidden"), ".hidden"], [File.join(gem_dir, "robots.txt"), "robots.txt"], [File.join(gem_dir, "_data"), "_data"], [File.join(gem_dir, "_posts"), "_posts"], [File.join(gem_dir, "_pages"), "_pages"], [File.join(gem_dir, "_pixels"), "_pixels"], [File.join(gem_dir, "blog"), "blog"], [File.join(gem_dir, "pixels"), "pixels"], [File.join(gem_dir, "assets/images"), "assets/images"] ] copy_items(items_to_copy, actual_path, force) # --- Bundle config set --- puts <<~MSG.yellow.bold To silence rubyzip post-install messages, run: bundle config set --local ignore_messages true MSG # --- Gemfile --- DEPRECATED - Using the dev's Gemfile # gemfile_dest = File.join(actual_path, "Gemfile") # create_gemfile(actual_path) unless File.exist?(gemfile_dest) # --- final --- puts "New rawfeed site created at #{path}".green end |