I am building an app with React Native and when I need a new component, I go through a few steps (lets assume I need a Button component) :
/src/components/Button
Button.js
Button.styles.js
index.js
, which exports both the component and its styles That's takes some time, so I want to create a script that does the following things:
Creates files listed above with predefined templates, for example:
import $component from './$component'; import styles from './$component.styles'; export { $component, styles };
where $component
is a name, provided via cli.
I can create folder and files with node, but how can I write a template and provide a variable to those files?
Create a template file manually. While running your script, read the contents of the file and then replace predetermined variable ($component for example) with the name from the console.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.