lib/appifier/actors/generator.rb in appifier-0.2.0 vs lib/appifier/actors/generator.rb in appifier-0.3.0

- old
+ new

@@ -7,21 +7,22 @@ extend Carioca::Injector inject service: :output - def initialize(src_root:, target_root:, dataset: ) - @src_root = src_root + def initialize(template_root:, target_root:, dataset: ) + @template_root = template_root + @src_root = "#{template_root}/skeleton" @target_root = target_root @target_folders = [] @target_files = [] @data = dataset @src_paths = Dir.glob("#{@src_root}/**/*", File::FNM_DOTMATCH) @src_paths.delete_if { |file| file =~ %r{/\.$} } @src_folders = @src_paths.select { |item| File.directory? item } @src_files = @src_paths.select { |item| File.file? item } - raise 'Application template not found' unless File.exist?(src_root) + raise 'Application template not found' unless File.exist?(@template_root) end def generate(dry_run: false, force: false) output.info 'Running in dry_run (operation will be SKIPPED)' if dry_run calculate @@ -29,10 +30,11 @@ FileUtils.rm_rf("#{@target_root}/#{@target_folders.first}") if force output.info 'Generate folders' generate_folders dry_run: dry_run output.info 'Generate files' generate_files dry_run: dry_run + copy_appifile dry_run: dry_run end def calculate calculate_target type: :folder calculate_target type: :file @@ -50,9 +52,18 @@ action = dry_run ? :skipped : :ok FileUtils.mkdir_p "#{@target_root}/#{path}", noop: dry_run output.send action, "#{path}" end end + + + def copy_appifile(dry_run:) + output.info "Copy Appifile in #{@target_root} :" + action = dry_run ? :skipped : :ok + FileUtils.cp "#{@template_root}/Appifile", @target_root unless dry_run + output.send action, "Install Appifile" + end + def generate_files(dry_run:) output.info "Target files to create in #{@target_root} :" @src_files.each_with_index do |path, index| if dry_run