aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/dev-cmd/tap-new.rb
blob: 38cdb1c2e78f38d265dffaed621d0685244f6b3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
#:  * `tap-new` <user>`/`<repo>:
#:    Generate the template files for a new tap.

require "tap"

module Homebrew
  module_function

  def write_path(tap, filename, content)
    path = tap.path/filename
    tap.path.mkpath
    raise "#{path} already exists" if path.exist?
    path.write content
  end

  def tap_new
    raise "A tap argument is required" if ARGV.named.empty?

    tap = Tap.fetch(ARGV.named.first)
    titleized_user = tap.user.dup
    titleized_repo = tap.repo.dup
    titleized_user[0] = titleized_user[0].upcase
    titleized_repo[0] = titleized_repo[0].upcase

    (tap.path/"Formula").mkpath

    readme = <<~EOS
      # #{titleized_user} #{titleized_repo}

      ## How do I install these formulae?
      `brew install #{tap}/<formula>`

      Or `brew tap #{tap}` and then `brew install <formula>`.

      Or install via URL (which will not receive updates):

      ```
      brew install https://raw.githubusercontent.com/#{tap.user}/homebrew-#{tap.repo}/master/Formula/<formula>.rb
      ```

      ## Documentation
      `brew help`, `man brew` or check [Homebrew's documentation](https://docs.brew.sh).
    EOS
    write_path(tap, "README.md", readme)

    travis = <<~EOS
      language: c
      os: osx
      compiler: clang
      osx_image: xcode9.2
      cache:
        directories:
          - $HOME/.gem/ruby
          - Library/Homebrew/vendor/bundle
      branches:
        only:
          - master

      before_install:
        - sudo chown -R "$USER" "$(brew --repo)"
        - travis_retry brew update
        - HOMEBREW_TAP_DIR="$(brew --repo "$TRAVIS_REPO_SLUG")"
        - mkdir -p "$HOMEBREW_TAP_DIR"
        - rm -rf "$HOMEBREW_TAP_DIR"
        - ln -s "$PWD" "$HOMEBREW_TAP_DIR"

      script:
        - brew test-bot
    EOS
    write_path(tap, ".travis.yml", travis)
  end
end