Creating complex file structures has never been easier. @cmorales_/touch is a powerful CLI tool that allows you to generate nested directories and files using a simple and intuitive syntax.
You can use the package directly via npx or install it globally.
npm install -g @cmorales_/touch
# or
pnpm add -g @cmorales_/touch
# or
bun add -g @cmorales_/touchnpx @cmorales_/touch <structure>The basic syntax is:
touch <input>Where <input> describes the file and folder structure you want to create.
To create a directory, simply append a / to the name.
app/-> Creates a folder namedapp.app/models/-> Creates anappfolder and amodelsfolder inside it.
You can group multiple items at the same level using {}, [], or (). All work identically and can be used interchangeably.
- Curly Braces:
src/{components,utils} - Square Brackets:
src/[components,utils] - Parentheses:
src/(components,utils)
All the above commands create src/components and src/utils.
You can nest groups within groups to build complex trees.
src/{components/{Button,Input},utils}Creates:
src/components/Buttonsrc/components/Inputsrc/utils
You can specify extensions in two ways:
-
Per File: Directly in the name.
src/{index.ts,styles.css} -
Default Extension: If you provide an extension at the end of a group, it will be applied to all files in that group that don't already have one.
src/{components,utils}.tsCreates:src/components.tssrc/utils.ts
React Component Structure:
src/components/Button/{index.tsx,styles.module.css,types.ts}MVC Backend Structure:
src/{controllers/,models/,routes/,services/}Complex Project Setup:
my-app/{src/{components/,hooks/,utils/},public/,package.json,README.md}Created by Cristian Morales.
- GitHub: Cristian-F-M
- Twitter: @Morales_M20
If you find this tool useful, you can support my work!
