HanseltimeIndustries / template-repo-sync

A project for synchronizing template repositories with configured control on both sides of the repo.
0 stars 0 forks source link

Impossible to have different merge plugins with the same file extension #11

Open oprypkhantc opened 3 months ago

oprypkhantc commented 3 months ago

Hey

Currently merges configuration has file extension as the key, meaning you may only have one configuration for merging a specific extension. The problem is that if you want different handling for specific file types (for example, handle package.json with some kind of npm-merge-plugin, and handle composer.json with a different `composer-merge-plugin), you can't do so.

Are extensions necessary? I believe instead of relying on extensions, merge could be an array. Then the first matching plugin simply gets executed, after filtering based on glob of course:

interface Config {
  merge: {
    {
      glob: string;
      plugin: string;
      options: object;
    }[];
  };
};

then it can be used like so:

{
    "ignore": ["src/**"],
    "merge": [
        {"glob": "composer.json", "plugin": "composer"},
        {"glob": "package.json", "plugin": "npm"},
        {
            "glob": "*.json", 
            "plugin": "json",
            "options": {
                "paths": [
                    ["$.scripts", "merge-template"],
                    ["$.devDependencies", "merge-template"]
                ]
            }
        }
    ]
}
hanseltime commented 1 month ago

@oprypkhantc - This is a great call out. I would like to implement this since the extension is pretty clearly something I started with and didn't re-evaluate.

I am currently working on several different competing concerns, so if you would like to take a crack at it, I think the change needs to be made in merge-file where we get the config files. Otherwise, I will try to get to this in the next little while.

Note, for now, this behavior can be achieved by creating a wrapper plugin in the repo and then doing the evaluation can calling of other plugins within that wrapper.

oprypkhantc commented 1 month ago

@hanseltime Hey :)

Since it's been some time, I've decided to instead write our own template sync. It started as a fork with an intention to contribute here, but I realized it would be too disruptive for this repo so decided to start over. This is the result:

https://github.com/tenantcloud/template-sync/tree/alpha https://github.com/tenantcloud/php-package-skeleton/blob/sync/.github/template-sync.template.json https://github.com/tenantcloud/php-guzzle-helper/blob/master/.github/template-sync.json

I don't think it has anything of value for your project, but I thought it was worth mentioning. The plugin system was re-made to not have a dependency on file extensions or types, more as a kind of scripts. Committing and creating PRs was also removed, as this allows adding additional steps before committing and there are already GH actions that do the job very well. Some other small things done as well, and it's been working quite well for us after ironing out the initial issues.

hanseltime commented 1 month ago

Ah that's great! Sorry about dropping the ball on this. Glad your set up is working well though.

I'll have to take a look and see if I'm in favor of deprecating this over yours.