You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But it more complicated cases (replace more the one variable, print something conditionally, use iteration) it can be difficult do only with regexp .
I suggest adding the ability to use the (template literals)[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals].
All variables must be available in template scope.
For example:
template file must contain special extention tmpl.js end export function:
module.tmpl.js
module.exports=answers=>(`import React from 'react';import PT from 'proptypes';import cn from 'classnames';import style from './style.css';${answers.libs.map(lib=>`import ${lib.name} from ${lib.path}`)}export default function ${answers.moduleName}({ className }) { return <div className={cn(className, style.root)}>${answers.language==='ru' ? 'Здарова мир' : 'Hello world'} </div>}${answers.moduleName}.propTypes = { className: PT.string }`)
And run it when module .move()
cliOf('Create module',module).ask({name: 'moduleName',message: 'How we name it?',type: 'input'}).move(['./module.tmpl.js], './src/modules/)
or we can add method write that can just write string in file, it more transparent and simpler but in that case we need manually require or import every template
const{ cliOf }=require('@recli/cli');constmoduleTemplate=require('./templates/module.tmpl.js');cliOf('Create module',module).ask({name: 'moduleName',message: 'How we name it?',type: 'input'}).write([answers=>moduleTemplate(answers)],'./src/modules/module/index.js')
The text was updated successfully, but these errors were encountered:
I mainly use once generated modules like this:
template.js
If I need replace {componentName} i can use make something like this.
But it more complicated cases (replace more the one variable, print something conditionally, use iteration) it can be difficult do only with regexp .
I suggest adding the ability to use the (template literals)[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals].
All variables must be available in template scope.
For example:
template file must contain special extention
tmpl.js
end export function:module.tmpl.js
And run it when module
.move()
or we can add method
write
that can just write string in file, it more transparent and simpler but in that case we need manually require or import every templateThe text was updated successfully, but these errors were encountered: