This follows from this thread with @fkleuver concerning the problems around managing templates.
As always I will keep this as concise as possible.
Yesterday afternoon I had a few hours so I decided to look into the diff/patch approach to generating templates, enabling a command line (or any other app) to change templates that are created by any IDE (in my case Visual Studio 2017) and ‘add’ an Aurelia app to a template by modifying the code generated by the IDE. This has many benefits.
What I created was a basic app that compares 2 folders of code which I have called ‘source’ and ‘destination’ and take the diffs and generate a json patch file. See here for more info on diff/patch.
The ‘source’ folder contains the users newly generated project, generated by the IDE, to which they would like to add Aurelia.
The ‘destination’ folder contains all the files that have been added and modified to enable the Aurelia CLI project build and to run.
A third folder called ‘patch’ which contains a json document that is the serialised patch made from the diffs between the files in the ‘source’ and ‘destination’ folders, along with the filenames.
With this patch file we can alter any existing template of the same type and add Aurelia to it.
This means that it is minutes work to generate a patch file which can subsequently be used to decorate any template of that type with an Aurelia CLI project.
I have only tested this with a Visual Studio asp.net core 2.2.0 MVC app at the moment. But since we are dealing with text files, it should work with any IDE. I will be testing more later.
Essentially, I generated a Visual Studio dotnet core MVC project and added Aurelia to it by running a command that applied an earlier generated json patch file, reading in that patch, deserializing it, and patching/copying the files to modify the template. It worked fine.
Does anyone has a suggestion for a template (VS Code probably next)?
I have also created a basic .NET Core Global Tool as a complimentary to the CLI. I plan use this to add Aurelia to Visual Studio (or any other project types I generate patches for), via the command line, as such:
agt -add {some-template-identifier}
…meaning ‘aurelia global tools -add {some-template-identifier}’
Or, maybe even (for fun):
gta -add {some-template-identifier}
…meaning ‘global tools aurelia -add {some-template-identifier}’
So why all this?
- Because the user can add the Aurelia goodness to their default IDE generated projects
- The templates can be maintained easily
- New templates added quickly
- Users could create, publish their own templates that could be used by a command like:
agt -add -net {some-github-repo}
Mostly, it could be used to more easily manage templated starting points for Aurelia projects.
For anyone interested, a patch entry looks like this:
{ "SourceFile":"content\\Template2\\source\\Site\\Controllers\\HomeController.cs", "DestinationFile":"content\\Template2\\destination\\Site\\Controllers\\HomeController.cs", "PatchResultType":1, "PatchList":[ { "diffs":[ { "operation":2, "text":" {\r\n" }, { "operation":0, "text":" /// <summary>\r\n /// This is some text that I have added to test the patching for Aurelia!\r\n /// </summary>\r\n /// <returns></returns>\r\n" }, { "operation":2, "text":" " } ], "start1":263, "start2":263, "length1":171, "length2":8 } ] }