File Patching
Asten-Valentinus opened this issue · 0 comments
Please note that this is a feature suggestion rather than a bug report.
Problem
In some situations, you may need to patch some files in the parent directory to where the template is being placed.
An example is if you are working on a CMake project, and you want to add a new custom library from a template:
While the extension makes the library's folder for you, you'll still need to modify the CMakeLists.txt
file to accompany this.
Proposed Solution
The solution I have thought of uses two new mutually dependant features: File Variables, and File Patching.
File variables will be variables that are defined inside the template, based on a file in a particular folder:
The template can specify some files in the parent directory to process file variables for. The extension will modify a version of the file with a .ftin
file extension, then replace the version of the file without this special file extension with the .ftin
version with file variable calls removed (to prevent syntax errors.)
Example
Template:
newSubdirectory.txt
:
add_subdirectory([FTName])
[newSubdirectory]
.ftsettings.json
:
{
"filesToPatch": ["CMakeLists.txt"]
}
Before:
CMakeLists.txt
is empty.
CMakeLists.txt.ftin
:
[newSubdirectory]
After:
CMakeLists.txt
:
add_subdirectory(newLibrary)
CMakeLists.txt.ftin
:
add_subdirectory(newLibrary)
[newSubdirectory]
From this example, you may be thinking that just appending to CMakeLists.txt
would be a better solution, but in situations where the setup is more complicated, this would not work.
Details
File variables can follow the same syntax as regular variables.
File variables would be unnecessary and possibly confusing outside of file patching, so possibly they may only be able to be called in the context of file patching.
Regular variables would be useless if used with file patching, so possibly they may not be called within the context of file patching.
Given the two above details, file variables and regular variables shouldn't ever be able to called together within the same file, so their variable names can be kept track of separately.
In the "filesToPatch"
component, the directory that the template is being placed (in the above examples, src/
) is assumed.