Injection

scaffdog can inject code into already existing files! ⛏️
Injection can be achieved by using the helper function. The following are some examples.

Append#

You can use the read helper function and output.abs to get the file to output.
If you want to append a text to the last line, put a body after the call to the read helper function.

# `index.js`
```javascript
{{ read output.abs }}
console.log('last line');
```

Prepend#

Using much the same mechanism as the Append section, text can be added to the first line.

# `index.js`
```javascript
console.log('first line');
{{ read output.abs }}
```

Before / After#

There may be cases where you want to add text to a specific line in a file's contents. The before and after helper functions make it easy!

For example, if you want to add text to the first blank line, the case is as follows:

# `index.js`
```javascript
{{ read output.abs | before "^$" }}
console.log('first blank line');
{{ read output.abs | after "^$" -1 }}
```

The before and after helper functions each retrieve values that do not include the specified line, so you will need to adjust the position of the inject by making use of the offset.

At line#

The before and after helper functions are also useful when you want to add text to a specific line.

# `index.js`
```javascript
{{ read output.abs | before 6 }}
console.log('line at 6');
{{ read output.abs | after 6 -1 }}
```
Edit this page on GitHub

Last edited on

Copyright © 2022 wadackel

Released under the MIT License

Built with Next.js

Source Code