label_weaver 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +35 -3
 - data/label_weaver.gemspec +1 -1
 - data/lib/label_weaver/cli/actions/develop/start.rb +10 -2
 - data/lib/label_weaver/cli/actions/develop/stop.rb +11 -2
 - data/lib/label_weaver/configuration/contract.rb +1 -0
 - data/lib/label_weaver/configuration/defaults.yml +9 -0
 - data/lib/label_weaver/configuration/model.rb +3 -2
 - data/lib/label_weaver/merger.rb +77 -0
 - data/lib/label_weaver/temp_repo.rb +2 -0
 - metadata +3 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 6bbe89444ed69fe936e7e64cb7c0e2b36c013df2afef71f1b33ae65a17e67fa3
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: db4917c239cf6502e3da219f7fe215af11d5fa5dd3668e16b01fad2389c93243
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: edb992f4593c2de938debe63bc4ee1f60bf4f308b80e859a82c1fb6e3318f45aca96096c8b0859f33c72e916f61f2bffb5f627af4effae44b4135313490b92f1
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 2d51c191608b5070f20f31ef818b26d4d21d67839427655974e8ff55b3911ce41b3a501418e9151bd1d61f8fc1d49393fdaa68f01e225d673687913f8a59f553
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -7,7 +7,10 @@ 
     | 
|
| 
       7 
7 
     | 
    
         
             
            * [LabelWeaver](#labelweaver)
         
     | 
| 
       8 
8 
     | 
    
         
             
              * [Installation](#installation)
         
     | 
| 
       9 
9 
     | 
    
         
             
              * [Setting up a new whitelabel project](#setting-up-a-new-whitelabel-project)
         
     | 
| 
       10 
     | 
    
         
            -
              * [Developing  
     | 
| 
      
 10 
     | 
    
         
            +
              * [Developing a whitelabel project](#developing-a-whitelabel-project)
         
     | 
| 
      
 11 
     | 
    
         
            +
                * [Starting local development](#starting-local-development)
         
     | 
| 
      
 12 
     | 
    
         
            +
                * [Stopping local development](#stopping-local-development)
         
     | 
| 
      
 13 
     | 
    
         
            +
                * [Diffs](#diffs)
         
     | 
| 
       11 
14 
     | 
    
         
             
              * [CI Usage](#ci-usage)
         
     | 
| 
       12 
15 
     | 
    
         
             
            <!-- TOC -->
         
     | 
| 
       13 
16 
     | 
    
         | 
| 
         @@ -24,10 +27,39 @@ gem install label_weaver 
     | 
|
| 
       24 
27 
     | 
    
         | 
| 
       25 
28 
     | 
    
         
             
            ## Setting up a new whitelabel project
         
     | 
| 
       26 
29 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
30 
     | 
    
         
             
            ## Developing a whitelabel project
         
     | 
| 
       29 
31 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
            ###  
     | 
| 
      
 32 
     | 
    
         
            +
            ### Starting local development
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            ```
         
     | 
| 
      
 35 
     | 
    
         
            +
            label_weaver develop --start
         
     | 
| 
      
 36 
     | 
    
         
            +
            ```
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            This command will perform the following actions:
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            1. Run any `before_start` hooks 
         
     | 
| 
      
 41 
     | 
    
         
            +
            2. Clone or check out the base repository
         
     | 
| 
      
 42 
     | 
    
         
            +
            3. Copy all files from the base repository to the whitelabel project that do not already exist
         
     | 
| 
      
 43 
     | 
    
         
            +
            4. Merge configured files
         
     | 
| 
      
 44 
     | 
    
         
            +
            5. Run any `after_start` hooks
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
            Please note that the gem will inform you about files with a newer version in the base repository.
         
     | 
| 
      
 47 
     | 
    
         
            +
            This could mean that you have to update them in your whitelabel project as well to ensure compatibility.
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            ### Stopping local development
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            ```
         
     | 
| 
      
 52 
     | 
    
         
            +
            label_weaver develop --stop
         
     | 
| 
      
 53 
     | 
    
         
            +
            ```
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            This command will perform the following actions:
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
            1. Run any `before_start` hooks
         
     | 
| 
      
 58 
     | 
    
         
            +
            2. Restore all files that were automatically created through merging
         
     | 
| 
      
 59 
     | 
    
         
            +
            3. Remove all files from the project that do not differ from the base project
         
     | 
| 
      
 60 
     | 
    
         
            +
            4. Run any `after_start` hooks
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
            You should be left with only the changed files in your repository now.
         
     | 
| 
       31 
63 
     | 
    
         | 
| 
       32 
64 
     | 
    
         
             
            ### Diffs
         
     | 
| 
       33 
65 
     | 
    
         | 
    
        data/label_weaver.gemspec
    CHANGED
    
    
| 
         @@ -23,10 +23,9 @@ module LabelWeaver 
     | 
|
| 
       23 
23 
     | 
    
         
             
                        end
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
                        Hooks.new.run(:develop, :before_start)
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
26 
     | 
    
         
             
                        repo.clone_or_update
         
     | 
| 
       28 
27 
     | 
    
         
             
                        copy_repository_files
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
                        handle_file_merges
         
     | 
| 
       30 
29 
     | 
    
         
             
                        Hooks.new.run(:develop, :after_start)
         
     | 
| 
       31 
30 
     | 
    
         
             
                      end
         
     | 
| 
       32 
31 
     | 
    
         | 
| 
         @@ -53,6 +52,15 @@ module LabelWeaver 
     | 
|
| 
       53 
52 
     | 
    
         
             
                        end
         
     | 
| 
       54 
53 
     | 
    
         
             
                      end
         
     | 
| 
       55 
54 
     | 
    
         | 
| 
      
 55 
     | 
    
         
            +
                      def handle_file_merges
         
     | 
| 
      
 56 
     | 
    
         
            +
                        merger = ::LabelWeaver::Merger.new(project_root_dir: context.project_root_dir, repo:)
         
     | 
| 
      
 57 
     | 
    
         
            +
                        if merger.present?
         
     | 
| 
      
 58 
     | 
    
         
            +
                          logger.info "Merging files..."
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                          merger.merge!
         
     | 
| 
      
 61 
     | 
    
         
            +
                        end
         
     | 
| 
      
 62 
     | 
    
         
            +
                      end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
       56 
64 
     | 
    
         
             
                      def repo
         
     | 
| 
       57 
65 
     | 
    
         
             
                        @repo ||= LabelWeaver::TempRepo.new(
         
     | 
| 
       58 
66 
     | 
    
         
             
                          context.repository_dir,
         
     | 
| 
         @@ -23,6 +23,7 @@ module LabelWeaver 
     | 
|
| 
       23 
23 
     | 
    
         
             
                        end
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
25 
     | 
    
         
             
                        Hooks.new.run(:develop, :before_stop)
         
     | 
| 
      
 26 
     | 
    
         
            +
                        restore_merged_files
         
     | 
| 
       26 
27 
     | 
    
         
             
                        remove_base_files
         
     | 
| 
       27 
28 
     | 
    
         
             
                        Hooks.new.run(:develop, :after_stop)
         
     | 
| 
       28 
29 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -37,9 +38,8 @@ module LabelWeaver 
     | 
|
| 
       37 
38 
     | 
    
         
             
                          project_file = context.project_root_dir + relative_filename
         
     | 
| 
       38 
39 
     | 
    
         | 
| 
       39 
40 
     | 
    
         
             
                          if project_file.exist?
         
     | 
| 
       40 
     | 
    
         
            -
                            # TODO: Should we get a time component in here to check for possible newer base repo files?
         
     | 
| 
       41 
41 
     | 
    
         
             
                            if digest(project_file) != digest(repository_file)
         
     | 
| 
       42 
     | 
    
         
            -
                              logger. 
     | 
| 
      
 42 
     | 
    
         
            +
                              logger.debug "File '#{relative_filename}' is kept as it was changed in the whitelabel project (r: #{repo.timestamp_for(repository_file)} vs w: #{project_file.mtime})."
         
     | 
| 
       43 
43 
     | 
    
         
             
                            else
         
     | 
| 
       44 
44 
     | 
    
         
             
                              logger.debug "Deleting file '#{relative_filename}'..."
         
     | 
| 
       45 
45 
     | 
    
         
             
                              project_file.unlink
         
     | 
| 
         @@ -59,6 +59,15 @@ module LabelWeaver 
     | 
|
| 
       59 
59 
     | 
    
         
             
                        remove_empty_tree(dir.parent)
         
     | 
| 
       60 
60 
     | 
    
         
             
                      end
         
     | 
| 
       61 
61 
     | 
    
         | 
| 
      
 62 
     | 
    
         
            +
                      def restore_merged_files
         
     | 
| 
      
 63 
     | 
    
         
            +
                        merger = ::LabelWeaver::Merger.new(project_root_dir: context.project_root_dir, repo:)
         
     | 
| 
      
 64 
     | 
    
         
            +
                        if merger.present?
         
     | 
| 
      
 65 
     | 
    
         
            +
                          logger.info "Restoring merged files..."
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                          merger.restore!
         
     | 
| 
      
 68 
     | 
    
         
            +
                        end
         
     | 
| 
      
 69 
     | 
    
         
            +
                      end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
       62 
71 
     | 
    
         
             
                      def digest(file)
         
     | 
| 
       63 
72 
     | 
    
         
             
                        Digest::SHA1.file(file).hexdigest
         
     | 
| 
       64 
73 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -9,6 +9,15 @@ hooks: 
     | 
|
| 
       9 
9 
     | 
    
         
             
              develop:
         
     | 
| 
       10 
10 
     | 
    
         
             
                after_start:
         
     | 
| 
       11 
11 
     | 
    
         
             
                  - echo "Development Mode Started"
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            # Define files from the base and whitelabel projects that should be merged into
         
     | 
| 
      
 14 
     | 
    
         
            +
            # a new or existing file.
         
     | 
| 
      
 15 
     | 
    
         
            +
            # Currently supported formats are JSON and YAML
         
     | 
| 
      
 16 
     | 
    
         
            +
            #merges:
         
     | 
| 
      
 17 
     | 
    
         
            +
            #  - source_file: package.json
         
     | 
| 
      
 18 
     | 
    
         
            +
            #    target_file: package.json
         
     | 
| 
      
 19 
     | 
    
         
            +
            #    overrides_file: package.whitelabel.json
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
       12 
21 
     | 
    
         
             
            # Files here will be appended on whitelabel development instead of being skipped if the
         
     | 
| 
       13 
22 
     | 
    
         
             
            # file already exists in a project
         
     | 
| 
       14 
23 
     | 
    
         
             
            #append:
         
     | 
| 
         @@ -0,0 +1,77 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module LabelWeaver
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Merger
         
     | 
| 
      
 3 
     | 
    
         
            +
                include Import[:configuration, :logger]
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                attr_reader :project_root_dir, :repo
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                def initialize(project_root_dir:, repo:, configuration: nil, logger: nil)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @configuration = configuration
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @logger = logger
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @project_root_dir = project_root_dir
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @repo = repo
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                def present?
         
     | 
| 
      
 15 
     | 
    
         
            +
                  merge_entries.any?
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                def merge!
         
     | 
| 
      
 19 
     | 
    
         
            +
                  merge_entries.each do |entry|
         
     | 
| 
      
 20 
     | 
    
         
            +
                    entry => {source_file:, target_file:, overrides_file:}
         
     | 
| 
      
 21 
     | 
    
         
            +
                    logger.debug "Merging '#{overrides_file}' and '#{source_file}' into '#{target_file}'..."
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                    merge_file(project_root_dir + source_file, project_root_dir + target_file, project_root_dir + overrides_file)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                def restore!
         
     | 
| 
      
 28 
     | 
    
         
            +
                  merge_entries.each do |entry|
         
     | 
| 
      
 29 
     | 
    
         
            +
                    logger.debug "Restoring '#{entry[:target_file]}'..."
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                    restore_file(entry[:target_file])
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                private
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                def merge_file(source_file, target_file, overrides_file)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  source = load_file(source_file)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  overrides = load_file(overrides_file)
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                  write_file(target_file, source.deep_merge(overrides))
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                def restore_file(relative_file_path)
         
     | 
| 
      
 45 
     | 
    
         
            +
                  repository_file = repo.root_path + relative_file_path
         
     | 
| 
      
 46 
     | 
    
         
            +
                  project_file = project_root_dir + relative_file_path
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                  FileUtils.cp(repository_file, project_file, preserve: true)
         
     | 
| 
      
 49 
     | 
    
         
            +
                end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                def merge_entries
         
     | 
| 
      
 52 
     | 
    
         
            +
                  configuration.merges.map { _1.transform_keys(&:to_sym) }
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                def load_file(file)
         
     | 
| 
      
 56 
     | 
    
         
            +
                  case file.extname
         
     | 
| 
      
 57 
     | 
    
         
            +
                  when ".yaml", ".yml"
         
     | 
| 
      
 58 
     | 
    
         
            +
                    YAML.load_file(file)
         
     | 
| 
      
 59 
     | 
    
         
            +
                  when ".json"
         
     | 
| 
      
 60 
     | 
    
         
            +
                    JSON.parse(File.read(file))
         
     | 
| 
      
 61 
     | 
    
         
            +
                  else
         
     | 
| 
      
 62 
     | 
    
         
            +
                    raise ArgumentError, "Unsupported file type: #{file.extname}"
         
     | 
| 
      
 63 
     | 
    
         
            +
                  end
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                def write_file(file, content)
         
     | 
| 
      
 67 
     | 
    
         
            +
                  case file.extname
         
     | 
| 
      
 68 
     | 
    
         
            +
                  when ".yaml", ".yml"
         
     | 
| 
      
 69 
     | 
    
         
            +
                    File.write(file, content.to_yaml)
         
     | 
| 
      
 70 
     | 
    
         
            +
                  when ".json"
         
     | 
| 
      
 71 
     | 
    
         
            +
                    File.write(file, JSON.pretty_generate(content))
         
     | 
| 
      
 72 
     | 
    
         
            +
                  else
         
     | 
| 
      
 73 
     | 
    
         
            +
                    raise ArgumentError, "Unsupported file type: #{file.extname}"
         
     | 
| 
      
 74 
     | 
    
         
            +
                  end
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
              end
         
     | 
| 
      
 77 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: label_weaver
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.5
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Stefan Exner
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2024-09- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-09-29 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: cogger
         
     | 
| 
         @@ -220,6 +220,7 @@ files: 
     | 
|
| 
       220 
220 
     | 
    
         
             
            - lib/label_weaver/container.rb
         
     | 
| 
       221 
221 
     | 
    
         
             
            - lib/label_weaver/hooks.rb
         
     | 
| 
       222 
222 
     | 
    
         
             
            - lib/label_weaver/import.rb
         
     | 
| 
      
 223 
     | 
    
         
            +
            - lib/label_weaver/merger.rb
         
     | 
| 
       223 
224 
     | 
    
         
             
            - lib/label_weaver/temp_repo.rb
         
     | 
| 
       224 
225 
     | 
    
         
             
            homepage: https://gitlab.com/lopo-tech/label_weaver
         
     | 
| 
       225 
226 
     | 
    
         
             
            licenses:
         
     |