{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://catalog.lintel.tools/schemas/schemastore/plagiarize-me-yaml/versions/0.0.json",
  "title": "Plagiarize Me Configuration",
  "description": "plagiarize-me.yaml configuration schema",
  "x-lintel": {
    "source": "https://www.schemastore.org/plagiarize-me-0.0.json",
    "sourceSha256": "cb25defc3b3318a310ff708a62446ccdc780f8a42acf357a9c62a204e2b1a5cb",
    "fileMatch": [
      "plagiarize-me.yaml",
      "plagiarize-me.json"
    ],
    "parsers": [
      "json",
      "yaml"
    ]
  },
  "type": "object",
  "properties": {
    "repo": {
      "type": "object",
      "description": "Git repo of where this plagiarizable project is hosted",
      "properties": {
        "url": {
          "type": "string",
          "description": "The git repo url of this project"
        },
        "checkout": {
          "type": "string",
          "description": "The default branch that downstream projects should checkout when plagiarizing this project",
          "default": "master"
        }
      },
      "required": [
        "url"
      ],
      "additionalProperties": false
    },
    "move": {
      "type": "object",
      "description": "Files to move in target project from their previous locations",
      "properties": {
        "directories": {
          "type": "array",
          "description": "Directories to move from the target repo to the target repo. Useful for refactoring project structures",
          "items": {
            "$ref": "#/$defs/moveItems"
          }
        },
        "files": {
          "type": "array",
          "description": "Files to move from the target repo to the target repo. Useful for refactoring",
          "items": {
            "$ref": "#/$defs/moveItems"
          }
        }
      }
    },
    "run": {
      "type": "array",
      "description": "Shell commands to run after plagiarize files are done being copied and updated",
      "items": {
        "type": "object",
        "required": [
          "command"
        ],
        "properties": {
          "command": {
            "type": "string",
            "description": "The shell command to run"
          },
          "parallel": {
            "type": "boolean",
            "description": "Whether or not to run this command synchronously or in parallel to other commands where `parallel: true`"
          },
          "when": {
            "oneOf": [
              {
                "type": "string",
                "enum": [
                  "always"
                ],
                "description": "Condition type"
              },
              {
                "type": "object",
                "description": "Run this command only if configured file does not exist in target project",
                "required": [
                  "type",
                  "options"
                ],
                "properties": {
                  "type": {
                    "type": "string",
                    "description": "Condition type",
                    "enum": [
                      "if-missing"
                    ]
                  },
                  "options": {
                    "type": "object",
                    "required": [
                      "path"
                    ],
                    "properties": {
                      "path": {
                        "type": "string"
                      }
                    }
                  }
                },
                "additionalProperties": false
              },
              {
                "type": "object",
                "description": "Always run this command",
                "required": [
                  "type"
                ],
                "properties": {
                  "type": {
                    "description": "Condition type",
                    "type": "string",
                    "enum": [
                      "always"
                    ]
                  }
                },
                "additionalProperties": false
              }
            ]
          }
        }
      }
    },
    "replace": {
      "required": [
        "strings"
      ],
      "type": "object",
      "description": "Configuration for strings, files, and file paths to replace in target file",
      "properties": {
        "strings": {
          "description": "Strings to find in target project and be replaced with plagiarized project's values",
          "type": "object",
          "properties": {
            "project": {
              "type": "string"
            }
          },
          "required": [
            "project"
          ],
          "additionalProperties": {
            "type": [
              "string",
              "integer",
              "boolean"
            ]
          }
        },
        "vars": {
          "description": "Variables available to be used for finding and replacing by variable name. For example `$var_name: hello` would replace string '$var_name' with 'hello' in target project",
          "type": "object",
          "additionalProperties": {
            "type": [
              "string",
              "integer",
              "boolean"
            ]
          }
        },
        "files": {
          "description": "Relative path to target files that will be completely overwritten by source files in the same path",
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "create": {
      "type": "object",
      "properties": {
        "files": {
          "type": "array",
          "description": "Files to copy from plagiarized project if they do not exist in the target project",
          "items": {
            "type": "string"
          }
        },
        "andClean": {
          "type": "array",
          "description": "Files to remove commented sections from. Eg code between `// plagiarize:start:always:delete` and `// plagiarize:end:always:delete`",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "merge": {
      "type": "array",
      "items": {
        "oneOf": [
          {
            "$ref": "#/$defs/mergeJson"
          },
          {
            "$ref": "#/$defs/mergeYaml"
          },
          {
            "$ref": "#/$defs/mergeGit"
          },
          {
            "$ref": "#/$defs/mergeEnv"
          }
        ]
      }
    },
    "templates": {
      "type": "array",
      "description": "Files that are used the have similarities between instances of that that. .env files for example are similar and could be templated",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "The name of the template"
          },
          "replace": {
            "type": "object",
            "properties": {
              "strings": {
                "type": "object",
                "description": "Values to be used as variables within the target project. So `var_name: hello` in the template configuration and `var_name: world` would replace instances of 'hello' found in the source file with with 'world' found in the target file",
                "additionalProperties": {
                  "type": [
                    "string",
                    "boolean",
                    "number"
                  ]
                }
              },
              "values": {
                "type": "object",
                "description": "Values to be used as variables within the target project. So `var_name: hello` would replace instances of '$var_name' with 'hello' in the target file",
                "additionalProperties": {
                  "type": [
                    "string",
                    "boolean",
                    "number",
                    "null"
                  ]
                }
              },
              "vars": {
                "type": "object",
                "description": "Values to be used as variables within the plagiarize-me.yaml file only. So `var_name: hello` would replace '$var_name' with 'hello' in plagiarize-me.yaml",
                "additionalProperties": {
                  "type": [
                    "string",
                    "boolean",
                    "number",
                    "null"
                  ]
                }
              }
            },
            "required": [
              "strings"
            ],
            "additionalProperties": false
          },
          "merge": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "$ref": "#/$defs/mergeJson"
                },
                {
                  "$ref": "#/$defs/mergeYaml"
                },
                {
                  "$ref": "#/$defs/mergeGit"
                },
                {
                  "$ref": "#/$defs/mergeEnv"
                }
              ]
            }
          },
          "create": {
            "type": "object",
            "properties": {
              "files": {
                "type": "array",
                "items": {
                  "type": "string",
                  "description": "The path to the file to create if it does not already exist"
                }
              }
            },
            "additionalProperties": false
          },
          "configs": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "strings": {
                  "type": "object",
                  "additionalProperties": {
                    "type": [
                      "string",
                      "boolean",
                      "number"
                    ]
                  }
                },
                "vars": {
                  "type": "object",
                  "additionalProperties": {
                    "type": [
                      "string",
                      "boolean",
                      "number",
                      "null"
                    ]
                  }
                }
              },
              "additionalProperties": false
            }
          }
        },
        "required": [
          "name",
          "replace"
        ],
        "additionalProperties": false
      }
    },
    "push": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "values": {
            "type": "object",
            "description": "Values to set when iterating through each instance",
            "additionalProperties": {
              "type": "string"
            }
          },
          "instances": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "project"
              ],
              "additionalProperties": {
                "type": "string"
              }
            }
          },
          "git": {
            "type": "object",
            "properties": {
              "repos": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "local": {
                      "type": "string"
                    },
                    "remote": {
                      "type": "object",
                      "properties": {
                        "url": {
                          "type": "string"
                        },
                        "checkout": {
                          "type": "string"
                        },
                        "defaultName": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "url",
                        "checkout",
                        "defaultName"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "required": [
                    "remote"
                  ],
                  "additionalProperties": false
                }
              },
              "commit": {
                "type": "object",
                "properties": {
                  "create": {
                    "type": "boolean",
                    "default": false
                  },
                  "message": {
                    "type": "string"
                  }
                },
                "required": [
                  "message"
                ],
                "additionalProperties": false
              },
              "branch": {
                "type": "string"
              },
              "push": {
                "type": "boolean",
                "default": false
              },
              "remotes": {
                "type": "array",
                "description": "A list of removes to push to (if `push: true`)",
                "items": {
                  "type": "string",
                  "description": "name of the remote"
                }
              },
              "hooks": {
                "type": "object",
                "properties": {
                  "post-push": {
                    "type": "array",
                    "items": {
                      "oneOf": [
                        {
                          "type": "object",
                          "required": [
                            "type",
                            "api",
                            "remote",
                            "targetBranch"
                          ],
                          "properties": {
                            "type": {
                              "type": "string",
                              "enum": [
                                "create-merge-request"
                              ]
                            },
                            "api": {
                              "type": "string",
                              "enum": [
                                "gitlab"
                              ]
                            },
                            "envVars": {
                              "type": "object",
                              "additionalProperties": {
                                "type": "string"
                              }
                            },
                            "remote": {
                              "type": "string"
                            },
                            "targetBranch": {
                              "type": "string"
                            },
                            "removeSourceBranch": {
                              "type": "boolean",
                              "default": false
                            }
                          }
                        }
                      ]
                    }
                  }
                },
                "additionalProperties": false
              }
            },
            "required": [
              "repos",
              "commit",
              "branch",
              "remotes"
            ],
            "additionalProperties": false
          }
        },
        "additionalProperties": false
      }
    }
  },
  "required": [
    "replace"
  ],
  "$defs": {
    "moveItems": {
      "type": "object",
      "required": [
        "to",
        "names"
      ],
      "properties": {
        "to": {
          "type": "string",
          "description": "The path to move the directory to"
        },
        "names": {
          "type": "array",
          "items": {
            "type": "string",
            "description": "The directories to move"
          }
        }
      }
    },
    "mergeJson": {
      "description": "Merge json file with jq command line tool pattern matching",
      "required": [
        "type",
        "path"
      ],
      "properties": {
        "type": {
          "type": "string",
          "description": "Merge type",
          "enum": [
            "jq"
          ]
        },
        "path": {
          "type": "string",
          "description": "Path to file to merge"
        },
        "replace": {
          "type": "array",
          "description": "JQ pattern of property to replace",
          "items": {
            "type": "string"
          }
        },
        "create": {
          "type": "array",
          "description": "JQ pattern of property to create if the property does not exist in target project file",
          "items": {
            "type": "string"
          }
        },
        "replaceIf": {
          "type": "array",
          "description": "A set of properties to replace if the condition evaluates to truthy",
          "items": {
            "type": "object",
            "description": "Configuration for property to replace if condition evaluates to truthy",
            "required": [
              "condition",
              "pattern"
            ],
            "properties": {
              "condition": {
                "type": "string",
                "description": "The condition to evaluate for truthiness. If truthy will replace property matched by pattern"
              },
              "pattern": {
                "type": "string",
                "description": "JQ pattern of property to replace"
              }
            }
          }
        },
        "set": {
          "type": "object",
          "description": "Set the value of these items to the value. So `'.license':MIT` would set the `license` property of the json file to 'MIT'",
          "additionalProperties": {
            "type": "string"
          }
        },
        "skip": {
          "type": "array",
          "description": "A list of items to not create, copy, replace, or remove in target file",
          "items": {
            "type": "string"
          }
        },
        "skipIfNotSameFileName": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "mergeYaml": {
      "description": "Merge yaml file with yq command line tool pattern matching",
      "required": [
        "type",
        "path"
      ],
      "properties": {
        "type": {
          "type": "string",
          "description": "Merge type",
          "enum": [
            "yq"
          ]
        },
        "path": {
          "type": "string",
          "description": "Path to file to merge"
        },
        "replace": {
          "type": "array",
          "description": "YQ pattern of property to replace",
          "items": {
            "type": "string"
          }
        },
        "create": {
          "type": "array",
          "description": "YQ pattern of property to create if the property does not exist in target project file",
          "items": {
            "type": "string"
          }
        },
        "replaceIf": {
          "type": "array",
          "description": "A set of properties to replace if the condition evaluates to truthy",
          "items": {
            "type": "object",
            "description": "Configuration for property to replace if condition evaluates to truthy",
            "required": [
              "condition",
              "pattern"
            ],
            "properties": {
              "condition": {
                "type": "string",
                "description": "The condition to evaluate for truthiness. If truthy will replace property matched by pattern"
              },
              "pattern": {
                "type": "string",
                "description": "YQ pattern of property to replace"
              }
            }
          }
        },
        "set": {
          "type": "object",
          "description": "Set the value of these items to the value. So `'license':MIT` would set the `license` property of the yaml file to 'MIT'",
          "additionalProperties": {
            "type": "string"
          }
        },
        "skip": {
          "type": "array",
          "description": "A list of items to not create, copy, replace, or remove in target file",
          "items": {
            "type": "string"
          }
        },
        "skipIfNotSameFileName": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "mergeGit": {
      "description": "Merge file using git merge (use with varied reliability)",
      "required": [
        "type",
        "path"
      ],
      "properties": {
        "type": {
          "type": "string",
          "description": "Merge type",
          "enum": [
            "git"
          ]
        },
        "path": {
          "type": "string",
          "description": "Path to file to merge"
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "mergeEnv": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "env"
          ]
        },
        "path": {
          "type": "string"
        },
        "set": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "skip": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "create": {
          "type": "array",
          "description": "List of Environment variable names to create in target project if they are not already created",
          "items": {
            "type": "string",
            "description": "The Environment variable name"
          }
        },
        "skipIfNotSameFileName": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "type",
        "path"
      ],
      "additionalProperties": false
    }
  },
  "additionalProperties": false,
  "id": "https://json.schemastore.org/plagiarize-me-0.0"
}
