New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Replace a line during inject #84

Whoaa512 opened this Issue Dec 4, 2018 · 4 comments


None yet
2 participants

Whoaa512 commented Dec 4, 2018

Amazing piece of software you've got here. Has saved my team countless hours.

I'd like the ability to be able to run an arbitrary function on the matching line and return a modified version of that line.


This comment has been minimized.


jondot commented Dec 6, 2018

Interesting.. what can help is if you drop here a sample for a template with API you would expect, and then i'll do the hard work of implementing that. so just pencil in how you would see the YAML frontmatter for such an ability

@jondot jondot added the enhancement label Dec 6, 2018


This comment has been minimized.

Whoaa512 commented Dec 11, 2018

So I've thought about this a bit and I keep coming back to 2 API proposals.

Both share the common boolean attribute replace to trigger the replacement code.

The tricky part comes in specifying the replacement function. My initial thought is to specify a replacer attribute which contains the path to a js file with a single export or maybe a specifically named export. Alternatively we could try allowing the replacement function to be defined within the body of the template.

Defining the function in the template body is convenient for simple replacements, but we are then forced to eval the body which doesn't seem desirable.

Here's an example:

replace: true
to: src/apis/serverless.yml
at_line: 145
skip_if: "<%= h.inflection.classify(name) %>,"
eof_last: false
replacer: ./replacers/my-replacement-func.js
// Some body text here
// Or maybe a replacement function

What do you think @jondot?


This comment has been minimized.


jondot commented Dec 11, 2018

Interesting. And this kind of replacer function - is this specific to this template (in this instance, the serverless template) in term of logic that's "attached" to this template or is it a generic kind of function that can be used by other templates as well?


This comment has been minimized.

Whoaa512 commented Dec 11, 2018

Not sure I guess it could be specific but it doesn't have to be. Why do you ask?

Also forgot to mention my proposed function signature

// @flow
type ReplacerFunc = (matchingLine: string, lineIndex: number, content: string) => string

Maybe the front-matter attributes could be in there too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment