When working on a project, you often need to create multiple files with similar content. For example, you might need to create a new React component, a CSS file, and a test file for that component. Often times teams will have a convention to write different types of files in a certain way, With Copasta, you can define templates for these files and generate them with a single command.
- Generate file templates with a single command.
- Pre-defined templates for common file types.
- Easy to use with
npx, no need to install globally. - Extensible to create your own templates.
- Create your own copasta config file in your project.
- use dynamic values to make your templates more flexible.
- you can use the copata playground to create your own templates and configurations.
- Run
npx copasta <template-name>to generate the files. - Select which files you want to generate.
- Files will be generated in the current working directory.
CapitalizedName: The name of the template in PascalCase. e.g.npx copasta hello-worldwill find and replaceCapitalizedNamewithHelloWorld.KebabedName: The name of the template in kebab-case. e.g.npx copasta hello-worldwill find and replaceKebabedNamewithhello-world.- file names will be kebab-cased by default.
Copasta uses cosmiconfig internally to load configuration files. You can create a copasta property in you package.json, copasta.json, copasta.config.js or any other supported file format.
package.json:
{
"copasta": {
"templates": [
{
"emoji": "🔥", // optional
"fileExtension": ".tsx",
"content": "import React from 'react';\n\nconst CapitalizedName = () => {\n return <div>Hello, World!</div>;\n};\n\nexport default CapitalizedName;\n"
},
{
"emoji": "🌍", // optional
"fileExtension": ".css",
"content": ".KebabedName {\n color: red;\n}\n"
}
]
}
}copasta.json:
{
"templates": [
// templates here
]
}copasta.config.js:
module.exports = {
templates: [
// templates here
],
};This project is a monorepo containing the following packages:
- copasta-cli: The actual CLI tool. This is the npm package you will use to generate templates.
- playground-app: A web app to create and test copasta configurations.