Feature Name: (fill me in with a unique identity, myawesomefeature)
Type: (feature, enhancement)
Start Date: (fill me in with today's date, YYYY-MM-DD)
Author: (your names)
const read = async (filePath: string) => { | |
return new Promise((resolve, reject) => { | |
fs.readFile(filePath, 'utf8', (err: any, data: string) => { | |
if (err) reject(err) | |
resolve(data) | |
}) | |
}) | |
} | |
const write = (filePath: string, fileName: string, fileExtension: string, content: any) => { |
As a developer who works on multiple React projects daily, I like having a tool that can help me quickly and efficiently write consistent code. One of the best ways I've found is writing a custom command line tool to rapidly scaffold out my most common code patterns.
My tool of choice is Plop.js. Plop is a powerful "micro-generator framework" built to help maintain patterns as well as speed up your project build time. From the documenation:
If you boil plop down to its core, it is basically glue code between inquirer prompts and handlebar templates.
In this tutorial, we'll build out a simple React component generator for your Typescript projects. By the end, you'll have a fully functioning CLI that is customized to your file generating needs. Let's get started.