I am trying to create a yeoman generator where I have to copy from templatePath to destinationPath some files and folders, but I would want to have some of this files with a variable that yeoman could change by one of the user's inputs.
like: "<%=name%>-plugin.php" -> "hello-plugin.php"
I saw some references that this can be done but I can't find how.
I am doing right now:
//Copy the configuration files
app: function () {
this.fs.copyTpl(
this.templatePath('**'),
this.destinationPath(),
{
name: this.props.pluginName,
name_function: this.props.pluginName.replace('-', '_'),
name_class: this.props.className,
description: this.props.pluginDescription
}
);
}
I thought that with that code my <%=name%> would magically changed on copyTpl but it doesn't work
Following @piotrek answer, I made a function to replace all props with some pattern (like ejs does) ->
$$[your prop name]$$
. warning: ES6 insideExample:
Let's assume you have
this.props.appname = MyApp
andthis.props.AnotherProps = Test
and you want to rename file or folder.Name your file or folder
MyFile$$appname$$.js
->MyFileMyApp.js
Name your file or folder
$$appname$$.js
->MyApp.js
Name your file or folder
$$AnotherProps$$.js
->Test.js
I've just found the solution:
Use
this.registerTransformStream();
to pipe all files through some node.js script.I'm using here gulp-rename to change file names to something else.
Assuming that
this.props.appName == "myFirstApp"
, this:will change its name to
This is not possible anymore. The feature was bloated and was removed at some point in 2015.
For now, just rename the file:
this.fs.copy('name.js', 'new-name.js')