yonaskolb / Genesis

Templating, scaffolding and generation tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature -- allow for git repositories

thecb4 opened this issue · comments

As a user I want to be able to pass a git repository instead of a template.yml file so that I can maintain my own templates and make use of community templates.

use:

$ mkdir HappyDance && cd HappyDance
$ genesis generate https://github.com/thecb4/GenesisTemplate
  1. It should allow for http || https || git protocols
  2. It should download to a common folder
        // replace the standard path call with one that checks the string and does some work 
        // let templatePath = Path(self.templatePath.value).absolute()
        let templatePath = determinePath(from: self.templatePath.value)
    /**
      This method allows for the use of git repositories to hold templates in addition to passing in a flat template file.

      - Parameter from: The string passed in from the command line
      - Returns: Returns the Path of the template file

      ## Important Notes ##
      1. template.yml file should be top level of the git repository
      2. template repositories will be downloaded to a .genesis folder in users home (~) directory
      3. Each download replaces prior versions of the template

    */
    func determinePath(from: String) -> Path {

      if
        from.contains("http")  ||
        from.contains("https") ||
        from.contains("git")
      {

        do {

          let project = URL(string: from)!.lastPathComponent.components(separatedBy: ".")[0]

          let mkdirCommand  = try shellOut(to: "ls .genesis 2>/dev/null || mkdir .genesis", at: "~")

          print("removing existing template")
          let deleteCommand = try shellOut(to: "rm -rf .genesis/\(project)", at: "~")

          print("cloning repository")
          let cloneCommand = try shellOut(to: "git clone --verbose \(from)", at: "~/.genesis")

          return Path("~/.genesis/\(project)/template.yml").absolute()

        } catch {

          print(error)
          exit(1)

        }

      } else {

        return Path(from).absolute()

      }

    }