Class: Giblish::CopyAssetDirsPostBuild

Inherits:
Object
  • Object
show all
Defined in:
lib/giblish/resourcepaths.rb

Overview

copy all directories whose name matches a given regex from the source tree to the destination tree.

Instance Method Summary collapse

Constructor Details

#initialize(cmd_opts) ⇒ CopyAssetDirsPostBuild

Returns a new instance of CopyAssetDirsPostBuild.



175
176
177
178
179
# File 'lib/giblish/resourcepaths.rb', line 175

def initialize(cmd_opts)
  @asset_regex = cmd_opts.copy_asset_folders
  @srcdir = cmd_opts.srcdir
  @dstdir = cmd_opts.dstdir
end

Instance Method Details

#on_postbuild(src_tree, dst_tree, converter) ⇒ Object

Called from TreeConverter during post build phase

copy all directories matching the regexp pattern from the src tree to the dst tree



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/giblish/resourcepaths.rb', line 185

def on_postbuild(src_tree, dst_tree, converter)
  return if @asset_regex.nil?

  # build a tree with all dirs matching the given regexp
  st = PathTree.build_from_fs(@srcdir, prune: true) do |p|
    p.directory? && @asset_regex =~ p.to_s
  end

  return if st.nil?

  Giblog.logger&.info "Copy asset directories from #{@srcdir} to #{@dstdir}"
  st.traverse_preorder do |level, node|
    next unless node.leaf?

    n = node.relative_path_from(st)
    src = @srcdir.join(n)
    dst = @dstdir.join(n).dirname
    dst.mkpath

    FileUtils.cp_r(src.to_s, dst.to_s)
  end
end