Skip to content

saidake/simi-initializer

Repository files navigation

Simi Initializer

Init project files by the default config file: .simi/simi-initializer.yml.

Prerequisites:

  1. Create the configuration file in the user directory: ~/.simi/simi-initializer.yml
    Tips: The user configuration directory for Windows is "C:\Users\<username>\.simi"
  2. Add a write rule to the file ~/.simi/simi-initializer.yml.
    Tips: For the first usage, you can try adding only one rule in the ruleList, and then executing the plugin.
    Try the simplest java-annotation type to add "//" before each line in your read file.
  3. Execute the plugin in the intellij idea menu: Tools / Simi Initializer, and then you can see the execution result prompt in the lower right corner.

write types:

TYPE Description
append-properties-folder Read all properties files in the directory and append them to the write properties file.
append-properties Append a read properties file to the write properties file
replace-all Replace all content of the write file with the read file.
replace-string Replace matched content with the RP rule list manually defined or rp rule file,
Please refer to the introduction of the RP file rule format below.
append-string Append all contents of the read file to the write file.
line-replace Replace string with the RP file,
Please refer to the introduction of the RP file rule format below.
example: 2%%%String tt="xxx";
line-append Append string with the RP file,
Please refer to the introduction of the RP file rule format below.
example: 2%%%Integer tt=99;
java-annotation Each line of the write file will be preceded by '//'
xml Write xml file, Please refer to the introduction of the xml-append.xml file format below.

global env:

You can access the env variables in the simi-initializer.yml file,
or in the xxx.rp file of the rp rules and the xxx.xml file of xml-append rule referenced in the simi-initializer.yml

ENV description example
${project.name} The project name of the current project. simi-oracle
${project.path} The project path of the current project. C:\\Users\\<username>\\Desktop\\simi\\simi-service\\simi-oracle
${project.env} The ENV of the current project. UAT
${simi} The "~/.simi" configuration path. C:\\Users\\<username>\\.simi

simi-initializer.yml example:

project:
  - name: simi-oracle
    enable: true
    # Parent project folder
    path: C:\\Users\\saidake\\Desktop\\DevProject\\simi\\simi-service\\simi-oracle   
    envList: UAT,DEV,PROD
    defaultEnv: UAT
     # when executing this path, 
     # check whether Maven project name is project name based on the pom file (Optional).
    pomProjectNameCheck: true        
    ruleList:
      # Read all properties files in the directory and append them to the write properties file.  
      - type: append-properties-folder
        # The relative path to write the file.
        write: src/main/resources/application-local.properties
        # Read folder.
        # When the path starts with "/", automatically concatenate the configuration path "~/.simi"
        # Tips: The user configuration directory for Windows is "C:\Users\<username>\.simi"
        read: /${project.name}/${project.env}                     
        # Create a backup file in the current file directory.(The default backup value is "current")
        backup: current
        # Only write once, 
        # It will determine whether it is the first write based on whether the backup file exists.
        once: true        

      # Append a read properties file to the write properties file 
      - type: append-properties
        # The relative path to write the file.
        write: src/main/resources/application-dev.properties
        # Read property file.
        read: /${project.name}/test.properties                   
        # Create a backup file in the default simi backup folder.(~/.simi/AAAbackup)   
        backup: simi
        # It takes effect in the DEV and UAT environment and defaults to all environments.
        activeEnvList: DEV,UAT             
        
      # Replace all content of the write file with the read file.
      - type: replace-all 
        write: src/main/resources/logback.xml
        read: /${project.name}/logback.xml
                                                

      # Replace matched content with the RP rule list manually defined or rp rule file, 
      # Please refer to the introduction of the RP file rule format below.
      - type: replace-string
        # The same file can be written multiple times.
        write: src/main/resources/logback.xml
        # Use rpRuleList instead of rp file.(it is valid anywhere an RP file is used)
        rpRuleList:                                 
          - fffsfsfd/////%%%ddfsfsfsfsfs
          - fffsfsfd/////%%%ddfsfsfsfsfs

      - type: replace-string
        write: src/main/resources/logback.xml
         # Use the rp rule file instead manually setting one.
        read: /${project.name}/logback-replace.rp   
        
      # Append all contents of the read file to the write file.
      - type: append-string  
        write: src/main/resources/logback.xml
        read: /${project.name}/logback.txt
      #  Replace string with the RP file
       # Please refer to the introduction of the RP file rule format below.
      - type: line-replace
        write: src/main/resources/logback.xml
        read: /${project.name}/logback.rp
                                                
      # Append string with the RP file, 
      # Please refer to the introduction of the RP file rule format below.
      - type: line-append
        write: src/main/resources/logback.xml
        read: /${project.name}/logback.rp
                                                 
      # Each line of the write file will be preceded by '//'
      - type: java-annotation
        write: src\main\java\com\saidake\common\core\util\file\SmpTestBackupUtils.java
      # Write xml file, Please refer to the introduction of the xml-append.xml file format below.
      - type: xml  
        write: src/test/resources/simi-test/pom.xml
        read: /${project.name}/xml-append.xml
                                                       
  - name: simi-common-core
    path: C:\Users\saidake\Desktop\DevProject\simi\simi-common\simi-common-core
    envList: UAT,DEV,PROD
    defaultEnv: UAT
    ruleList:
      - write: src\main\java\com\saidake\common\core\util\file\SmpFileBackupUtils.java
        type: java-annotation
        once: true

RP rule file(.rp) example:

Key values are separated by '%%%'

<contextName>logback</contextName>%%%<contextName>logback-replace-content</contextName>
sourceValue%%%ReplaceValue
//source//abc.cert%%%${simi}/abc.cert

XML rule file(.xml) example:

<root>
    <replace xpath="/project/dependencyManagement/dependencies/dependency">    
        <!-- 
          xpath:  The xpath of the "replace" tag
        -->
        <ele 
                xpath="artifactId" 
                xpath-value="maven-compiler-plugin" 
                append-if-not-exists="true" 
                custom1="xxx"  
                custom2="xxx" 
        > 
            <!-- 
              xpath:                  tag name to use for matching 
              xpath-value:            matched tag value 
                  (and if the value is equal to 'maven-compiler-plugin', replace whole dependency tag.)
              append-if-not-exists:   Change replace to append
              custom1 / custom2...:   Other attributes will be appended to the tag matching the xpath of the "replace" tag
            -->
            <dependency>
                <groupId>org.saidake.simi</groupId>
                <artifactId>simi</artifactId>
                <version>1.0</version>
            </dependency>
        </ele>
    </replace>
    <append 
            parent-xpath="/project/dependencies" 
            position="top"
    >   
        <!-- 
          parent-xpath: The xpath of the parent tag.
          position:     The position to be appended.
        -->
       <dependency>
          <groupId>org.saidake.simi</groupId>
          <artifactId>simi</artifactId>
          <version>1.0</version>
       </dependency>
    </append>
</root>

About

Simi Initializer is an IntelliJ IDEA plugin designed to initialize Maven projects and switch local environment configurations.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages