瀏覽代碼

Clone a local copy of the repo if run through https

Chris Oliver 6 年之前
父節點
當前提交
6e18e7c748
共有 1 個文件被更改,包括 24 次插入2 次删除
  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