Module: Squared::Workspace::Repo

Included in:
Application
Defined in:
lib/squared/workspace/repo.rb

Instance Method Summary collapse

Instance Method Details

#repo(url, manifest = 'latest', run: nil, script: nil, args: nil, dev: nil, prod: nil, doc: false, test: false, lint: false, install: nil, name: nil, ref: @ref, group: @group) ⇒ Object



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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/squared/workspace/repo.rb', line 9

def repo(url, manifest = 'latest', run: nil, script: nil, args: nil, dev: nil, prod: nil, doc: false, test: false,
         lint: false, install: nil, name: nil, ref: @ref, group: @group)
  if @repo_bin.nil?
    self.home = if (val = env('REPO_HOME'))
                  path = Pathname.new(val)
                  if main == path.basename.to_s
                    @root = path.parent
                    if path.exist?
                      @root = nil unless path.directory?
                    elsif !@root.exist?
                      @root.mkpath
                    elsif !repo_install? && !repo_confirm
                      @root = nil
                    end
                    raise_error Errno::EEXIST, path.cleanpath, hint: 'REPO_HOME' unless @root
                  end
                  path.realdirpath
                elsif (val = env('REPO_ROOT'))
                  @root = Pathname.new(val).realdirpath
                  if !@root.exist?
                    @root.mkpath
                  elsif !repo_install?(parent: true) && !repo_confirm
                    raise_error Errno::EEXIST, @root, hint: 'REPO_ROOT'
                  end
                  @root.join(main).realdirpath
                elsif repo_install?(parent: true) && (!home.exist? || @root + main == home)
                  home
                elsif repo_install?(home)
                  home + main
                else
                  pwd == home || !repo_install?(pwd) ? home : pwd + main
                end
    @repo_bin = if install
                  install.is_a?(String) ? @root + install : @root
                else
                  false
                end
  end
  envargs = name ? { suffix: name.upcase, strict: true } : {}
  data = scriptobj
  if repo?
    env('REPO_GROUP', **envargs) { |s| group = split_escape(s) }
    env('REPO_REF', **envargs) { |s| ref = split_escape(s) }
    data[:dev] = env_match('REPO_DEV', dev, **envargs)
    data[:prod] = env_match('REPO_PROD', prod, **envargs)
    @warning = env_match('REPO_WARN', @warning && !root?(@root, pass: ['.repo'])) != false unless name
    sc, ru = split_escape(env('REPO_BUILD', '', **envargs), limit: 2)
    global = data[:global]
    if script
      data[:script] = if sc.to_s.empty?
                        script
                      else
                        data[:env][:script] = true
                        case sc
                        when 'verbose'
                          @verbose = 1
                          if script.is_a?(Array)
                            script[0] = task_join script[0], 'verbose'
                            script
                          else
                            task_join script, 'verbose'
                          end
                        when 'silent'
                          @verbose = false
                          @warning = false
                          script
                        else
                          sc
                        end
                      end
      data[:args] = env('REPO_SCRIPT', **envargs) { |s| shell_split(s, join: true) } || args
      global[:script] = true
    else
      ru ||= sc
    end
    if run
      data[:run] = if ru.to_s.empty?
                     run
                   else
                     data[:env][:run] = true
                     ru
                   end
      global[:run] = true
    end
    global[:doc] = doc
    global[:lint] = lint
    global[:test] = test
    script_set('repo', data, name: name, group: group, ref: ref, extras: { url: url, manifest: manifest })
    @extensions << :__repo__
  elsif script || run
    if script
      data[:script] = script
      data[:args] = args
    end
    data[:run] = run if run
    data[:dev] = dev
    data[:prod] = prod
    script_set('repo', data, name: name, group: group, ref: ref)
  end
  self
end

#repo?(active = false) ⇒ Boolean

Returns:

  • (Boolean)


111
112
113
# File 'lib/squared/workspace/repo.rb', line 111

def repo?(active = false)
  active ? @extensions.include?(:__repo__) : !windows? && (repo_install? || @repo_override == true)
end