Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature -- allow for git repositories #2

Open
thecb4 opened this issue May 21, 2018 · 0 comments
Open

Feature -- allow for git repositories #2

thecb4 opened this issue May 21, 2018 · 0 comments

Comments

@thecb4
Copy link

thecb4 commented May 21, 2018

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()

      }

    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant