Sometimes adding integration with a specific tool requires "boilerplate" files that are not configuration files. For example, redux requires
configureStore.js, and other boilerplate files. Because of this, Alfred provides
dirs properties which let writers of skills easily add boilerplate files and entire boilerplate directories to a user's project.
Here is an example of how the react skill uses the
files API to add react support to a project:
dest property determines where the file is written to relative to the user's root project directory. The
src property is the path to the file you want to write to to the location given by
Conditionally Adding Files
You may want to write a file only if certain conditions are met. Returning
condition will determine if the file should be written or not. In the example above, the file will be written if at least one target is a browser app.
Similar to configs which are transformed by functions in
transforms, skills can also change their files to be compatible with other skills.
Alfred provides some helpful ways of transforming files. Currently, Alfred supports file transformations through the following methods: applying diffs and string replacement. Note that directly writing files to the file system is highly discouraged.
This section is a work in progress
Content in files can either be replaced by the
replace method, which can be used in two ways:
Replacing an entire file with the given content:
Or giving a string to search for and replacing that matched string with the given content:
When Files are Written
Files are written during the
afterNew hooks. Only skills that are newly learned will have their files transformed.