Selaa lähdekoodia

Clone a local copy of the repo if run through https

Chris Oliver 6 vuotta sitten
vanhempi
commit
6e18e7c748
1 muutettua tiedostoa jossa 24 lisäystä ja 2 poistoa
  1. 24 2
      template.rb

+ 24 - 2
template.rb

@@ -1,5 +1,25 @@
-def source_paths
-  [File.expand_path(File.dirname(__FILE__))]
+# Copied from: https://github.com/mattbrictson/rails-template
+# Add this template directory to source_paths so that Thor actions like
+# copy_file and template resolve against our source files. If this file was
+# invoked remotely via HTTP, that means the files are not present locally.
+# In that case, use `git clone` to download them to a local temporary dir.
+def add_template_repository_to_source_path
+  if __FILE__ =~ %r{\Ahttps?://}
+    require "tmpdir"
+    source_paths.unshift(tempdir = Dir.mktmpdir("jumpstart-"))
+    at_exit { FileUtils.remove_entry(tempdir) }
+    git clone: [
+      "--quiet",
+      "https://github.com/excid3/jumpstart.git",
+      tempdir
+    ].map(&:shellescape).join(" ")
+
+    if (branch = __FILE__[%r{jumpstart/(.+)/template.rb}, 1])
+      Dir.chdir(tempdir) { git checkout: branch }
+    end
+  else
+    source_paths.unshift(File.dirname(__FILE__))
+  end
 end
 
 def add_gems
@@ -160,6 +180,8 @@ def add_whenever
 end
 
 # Main setup
+add_template_repository_to_source_path
+
 add_gems
 
 after_bundle do