module Comfpile class FilesourceArtefact < Artefact attr_reader :filename alias path filename alias file filename def initialize(*args, file: nil, **opts) super(*args, **opts) @original_filename = file unless File.exist? @original_filename fail! "File could not be loaded!" return end @filename = @target add_step do FileUtils.mkpath File.dirname(@filename) FileUtils.cp @original_filename, @filename end end def mtime File.mtime(@filename) end end class FilesourceEngine < ArtefactEngine def initialize(core, **options) super(core, **options) @root_path = options[:root_path] end def craft(stage, target, context) return nil unless stage == :sourcefile full_path = File.expand_path(File.join(@root_path, target)) return nil unless File.exists? full_path FilesourceArtefact.new(@core, self, stage, target, context, file: full_path); end end end