- 
                Notifications
    You must be signed in to change notification settings 
- Fork 570
feat: print modified and created files when scaffolding components #1250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            11 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      a3a46b7
              
                Source modification
              
              
                lumtis 3fce198
              
                Scaffolder modificaiton
              
              
                lumtis 02542ae
              
                Commands
              
              
                lumtis 88aa010
              
                Update command
              
              
                lumtis f99576d
              
                Fix template name
              
              
                lumtis d32a80a
              
                sorted list
              
              
                lumtis e83164c
              
                Conflict
              
              
                lumtis c32aa8a
              
                changelog
              
              
                lumtis 4b58d30
              
                New print format
              
              
                lumtis c687d23
              
                starport/cmd/type.go
              
              
                lumtis dd44ed7
              
                change color
              
              
                lumtis File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||
| package xgenny | ||||||
|  | ||||||
| // SourceModification describes modified and created files in the source code after a run | ||||||
| type SourceModification struct { | ||||||
| modified map[string]struct{} | ||||||
| created map[string]struct{} | ||||||
| } | ||||||
|  | ||||||
| func NewSourceModification() SourceModification { | ||||||
| return SourceModification{ | ||||||
| make(map[string]struct{}), | ||||||
| make(map[string]struct{}), | ||||||
| } | ||||||
| } | ||||||
|  | ||||||
| // ModifiedFiles returns the modified files of the source modification | ||||||
| func (sm SourceModification) ModifiedFiles() (modifiedFiles []string) { | ||||||
| for modified := range sm.modified { | ||||||
| modifiedFiles = append(modifiedFiles, modified) | ||||||
| } | ||||||
| return | ||||||
| } | ||||||
|  | ||||||
| // CreatedFiles returns the created files of the source modification | ||||||
| func (sm SourceModification) CreatedFiles() (createdFiles []string) { | ||||||
| for created := range sm.created { | ||||||
| createdFiles = append(createdFiles, created) | ||||||
| } | ||||||
| return | ||||||
| } | ||||||
|  | ||||||
| // AppendModifiedFile appends modified files in the source modification that are not already documented | ||||||
| func (sm *SourceModification) AppendModifiedFiles(modifiedFiles ...string) { | ||||||
| for _, modifiedFile := range modifiedFiles { | ||||||
| _, alreadyModified := sm.modified[modifiedFile] | ||||||
| _, alreadyCreated := sm.created[modifiedFile] | ||||||
| if !alreadyModified && !alreadyCreated { | ||||||
| sm.modified[modifiedFile] = struct{}{} | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|  | ||||||
| // AppendCreatedFiles appends a created files in the source modification that are not already documented | ||||||
| func (sm *SourceModification) AppendCreatedFiles(createdFiles ...string) { | ||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
 ? | ||||||
| for _, createdFile := range createdFiles { | ||||||
| _, alreadyModified := sm.modified[createdFile] | ||||||
| _, alreadyCreated := sm.created[createdFile] | ||||||
| if !alreadyModified && !alreadyCreated { | ||||||
| sm.created[createdFile] = struct{}{} | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|  | ||||||
| // Merge merges new source modification to an existing one | ||||||
| func (sm *SourceModification) Merge(newSm SourceModification) { | ||||||
| sm.AppendModifiedFiles(newSm.ModifiedFiles()...) | ||||||
| sm.AppendCreatedFiles(newSm.CreatedFiles()...) | ||||||
| } | ||||||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package xgenny_test | ||
|  | ||
| import ( | ||
| "github.com/stretchr/testify/require" | ||
| "github.com/tendermint/starport/starport/pkg/xgenny" | ||
| "testing" | ||
| ) | ||
|  | ||
| var ( | ||
| modifiedExample = []string{"mfoo", "mbar", "mfoobar"} | ||
| createdExample = []string{"cfoo", "cbar", "cfoobar"} | ||
| ) | ||
|  | ||
| func sourceModificationExample() xgenny.SourceModification { | ||
| sourceModification := xgenny.NewSourceModification() | ||
| sourceModification.AppendModifiedFiles(modifiedExample...) | ||
| sourceModification.AppendCreatedFiles(createdExample...) | ||
| return sourceModification | ||
| } | ||
|  | ||
| func TestNewSourceModification(t *testing.T) { | ||
| sm := xgenny.NewSourceModification() | ||
| require.Empty(t, sm.ModifiedFiles()) | ||
| require.Empty(t, sm.CreatedFiles()) | ||
| } | ||
|  | ||
| func TestModifiedFiles(t *testing.T) { | ||
| sm := sourceModificationExample() | ||
| require.Len(t, sm.ModifiedFiles(), len(modifiedExample)) | ||
| require.Subset(t, sm.ModifiedFiles(), modifiedExample) | ||
| } | ||
|  | ||
| func TestCreatedFiles(t *testing.T) { | ||
| sm := sourceModificationExample() | ||
| require.Len(t, sm.CreatedFiles(), len(createdExample)) | ||
| require.Subset(t, sm.CreatedFiles(), createdExample) | ||
| } | ||
|  | ||
| func TestAppendModifiedFiles(t *testing.T) { | ||
| sm := sourceModificationExample() | ||
| sm.AppendModifiedFiles("foo1") | ||
| require.Len(t, sm.ModifiedFiles(), len(modifiedExample)+1) | ||
| require.Contains(t, sm.ModifiedFiles(), "foo1") | ||
|  | ||
| // Do not append a existing element | ||
| sm.AppendModifiedFiles("foo1") | ||
| require.Len(t, sm.ModifiedFiles(), len(modifiedExample)+1) | ||
| sm.AppendCreatedFiles("foo2") | ||
| sm.AppendModifiedFiles("foo2") | ||
| require.Len(t, sm.ModifiedFiles(), len(modifiedExample)+1) | ||
| } | ||
|  | ||
| func TestAppendCreatedFiles(t *testing.T) { | ||
| sm := sourceModificationExample() | ||
| sm.AppendCreatedFiles("foo1") | ||
| require.Len(t, sm.CreatedFiles(), len(createdExample)+1) | ||
| require.Contains(t, sm.CreatedFiles(), "foo1") | ||
|  | ||
| // Do not append a existing element | ||
| sm.AppendCreatedFiles("foo1") | ||
| require.Len(t, sm.CreatedFiles(), len(createdExample)+1) | ||
| sm.AppendModifiedFiles("foo2") | ||
| sm.AppendCreatedFiles("foo2") | ||
| require.Len(t, sm.ModifiedFiles(), len(modifiedExample)+1) | ||
| } | ||
|  | ||
| func TestMerge(t *testing.T) { | ||
| sm1 := xgenny.NewSourceModification() | ||
| sm2 := xgenny.NewSourceModification() | ||
|  | ||
| sm1.AppendModifiedFiles("foo1", "foo2", "foo3") | ||
| sm2.AppendModifiedFiles("foo3", "foo4", "foo5") | ||
| sm1.AppendCreatedFiles("bar1", "bar2", "bar3") | ||
| sm2.AppendCreatedFiles("foo1", "bar2", "bar3") | ||
|  | ||
| sm1.Merge(sm2) | ||
| require.Len(t, sm1.ModifiedFiles(), 5) | ||
| require.Len(t, sm1.CreatedFiles(), 3) | ||
| require.Subset(t, sm1.ModifiedFiles(), []string{"foo1", "foo2", "foo3", "foo4", "foo5"}) | ||
| require.Subset(t, sm1.CreatedFiles(), []string{"bar1", "bar2", "bar3"}) | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are actually part of the encapsulated interface, this also allows us to use a separate package for the tests