repo-therapy
v0.23.15
Published
*Tired of boilerplate? Heal your repositories with automated, best-practice configurations.*
Readme
🩺 Repo Therapy
Tired of boilerplate? Heal your repositories with automated, best-practice configurations.
Why Repo Therapy?
Setting up a new Node.js project involves tedious, repetitive configuration of tools like TypeScript, ESLint, Husky, and VS Code. Ensuring these configurations are consistent and adhere to best practices across multiple projects is a constant challenge.
Repo Therapy is a command-line tool that automates this entire process. With a single command, it initializes your repository with a robust, modern, and consistent set of configurations, letting you focus on writing code instead of wrestling with boilerplate.
✨ Features
- One-Command Setup: Initialize a fully configured repository with a single command.
- Extensible Configuration: While Repo Therapy provides sensible defaults, you can override and customize almost every aspect of the configuration.
- Smart
package.jsonConfiguration: Automatically adds required scripts (lint,postinstall), dependencies, and even detects and sets your git repository URL. - Best-Practice
tsconfig.json: Generates a strict, modern TypeScript configuration tailored to your project type. - Automatic Tooling Setup:
- Configures ESLint with a proven ruleset.
- Sets up Husky to run pre-commit hooks, ensuring code quality.
- Creates
.gitignoreand.vscode/settings.jsonto ensure a consistent development environment.
- CSV Processing: Define and manage CSV files in your project.
- Environment Variable Management: Easily manage your environment variables.
- Error Handling: A dedicated error handling module.
- Import Management: A module for managing imports.
- JSON file Management: A module for managing JSON files.
- Logging: A dedicated logging module.
- Scripts: A module for managing scripts.
- Wrapper: A wrapper module for other modules.
🚀 Getting Started
Installation
No installation is needed. The recommended way to use Repo Therapy is with npx, which ensures you are always using the latest version.
Usage
From the root of your new project's directory, run the init command:
npx repo-therapy initThis will guide you through the process of setting up your project.
🔧 Core Concepts
Repo Therapy is built around a series of modules that each handle a specific aspect of your project's configuration. These modules are available as functions that you can import from the root of the project.
defineRepoTherapy
The main entry point for the library. It composes many of the other define modules to provide a high-level interface for scaffolding and managing a project.
Usage:
import { defineRepoTherapy } from 'repo-therapy';
const repoTherapy = await defineRepoTherapy({
project: 'my-awesome-project',
projectType: 'npm-lib',
})();
await repoTherapy.init();Expected Outcome:
This will initialize your project with a package.json, .gitignore, tsconfig.json, .vscode/settings.json, and Husky pre-commit hooks, all configured with best practices for an NPM library. It also returns an object with the following properties:
init: A function that initializes the project.rootPath: The root path of the project.env: The environment variables for the project.serverCode: An object containing a mapping of HTTP status codes to their names and descriptions.error: An object containing a collection of predefined error classes.newError: A function that can be used to create new custom error classes.logger: A logger instance.lint: A function that returns the ESLint configuration.wrapper: A function for wrapping other functions.import: A function for importing files and modules.script: A function for creating and managing scripts.json: A function for creating and managing JSON files.packageJson: The content of thepackage.jsonfile.
defineRepoTherapyCli
The main entry point for the command-line interface. It uses yargs to create a powerful and flexible CLI.
Usage:
import { defineRepoTherapyCli } from 'repo-therapy';
defineRepoTherapyCli();Expected Outcome:
This will create a CLI for your project with init, help, and version commands.
defineRepoTherapyCsv
A utility for reading and writing CSV files.
Usage:
import { defineRepoTherapyCsv } from 'repo-therapy';
const csv = defineRepoTherapyCsv(['name', 'email']);
const data = await csv('my-data.csv').read();
await csv('my-data.csv').write([...data, { name: 'John Doe', email: '[email protected]' }]);Expected Outcome:
This will read the data from my-data.csv, and then write the new data back to the file.
Remark:
This function uses defineRepoTherapyImport internally to read the CSV file.
defineRepoTherapyEnv
A utility for managing environment variables. It can read .env files, validate environment variables, and generate type declarations.
Usage:
import { defineRepoTherapyEnv } from 'repo-therapy';
const { env } = await defineRepoTherapyEnv(({ envPreset }) => ({
env: {
...envPreset.base(),
...envPreset.aws(),
},
}))();Expected Outcome:
This will load the environment variables from your .env file and validate them against the defined schema.
defineRepoTherapyError
A utility for creating custom error classes.
Usage:
import { defineRepoTherapyError } from 'repo-therapy';
const MyError = defineRepoTherapyError({
name: 'MyError',
defaultMessage: 'Something went wrong',
});
throw MyError;Expected Outcome:
This will throw a custom error with the name "MyError" and the default message.
defineRepoTherapyGitignore
A utility for creating and managing .gitignore files.
Usage:
import { defineRepoTherapyGitignore } from 'repo-therapy';
const gitignore = await defineRepoTherapyGitignore({
framework: ['next.js'],
})();
await gitignore.write();Expected Outcome:
This will create a .gitignore file with the default ignores for a Next.js project.
Remark:
You can also use the gitignore function returned by defineRepoTherapy to avoid manually passing the framework option.
defineRepoTherapyHusky
A utility for setting up Husky pre-commit hooks.
Usage:
import { defineRepoTherapyHusky } from 'repo-therapy';
const husky = defineRepoTherapyHusky();
husky.setup();Expected Outcome:
This will create a .husky/pre-commit file that runs npm run lint before each commit.
Remark:
You can also use the husky function returned by defineRepoTherapy to avoid manually passing the packageManager option.
defineRepoTherapyImport
A utility for importing files and modules. It can import .js, .ts, .json, and .csv files.
Usage:
import { defineRepoTherapyImport } from 'repo-therapy';
const myModule = await defineRepoTherapyImport().importScript('my-module.ts');Expected Outcome:
This will import the my-module.ts file and return its content.
Remark:
You can also use the import function returned by defineRepoTherapy to avoid manually passing the rootPath.
defineRepoTherapyJson
A utility for creating and managing JSON files.
Usage:
import { defineRepoTherapyJson } from 'repo-therapy';
const myJson = defineRepoTherapyJson({
'my-key': { default: 'my-value' },
});
const json = myJson({ 'my-key': 'my-new-value' }).json;Expected Outcome:
This will create a JSON object with the key "my-key" and the value "my-new-value".
Remark:
You can also use the json function returned by defineRepoTherapy to avoid manually passing the rootPath.
defineRepoTherapyLint
A utility for configuring ESLint.
Usage:
import { defineRepoTherapyLint } from 'repo-therapy';
const lint = await defineRepoTherapyLint({
projectType: 'backend',
})();
const eslintConfig = lint.lint();Expected Outcome:
This will create an ESLint configuration for a backend project.
Remark:
You can also use the lint function returned by defineRepoTherapy to avoid manually passing the projectType and framework options.
defineRepoTherapyLogger
A utility for creating a logger.
Usage:
import { defineRepoTherapyLogger } from 'repo-therapy';
const { logger } = defineRepoTherapyLogger({
service: 'my-service',
})();
logger.info('Hello, world!');Expected Outcome:
This will log "Hello, world!" to the console with the service name "my-service".
Remark:
You can also use the logger object returned by defineRepoTherapy.
defineRepoTherapyPackageJson
A utility for creating and managing package.json files.
Usage:
import { defineRepoTherapyPackageJson } from 'repo-therapy';
const packageJson = await defineRepoTherapyPackageJson({
projectType: 'npm-lib',
})();
await packageJson.write();Expected Outcome:
This will create a package.json file with the default settings for an NPM library.
Remark:
You can also use the packageJson function returned by defineRepoTherapy to avoid manually passing the projectType and packageManager options.
defineRepoTherapyScript
A utility for creating and managing scripts.
Usage:
import { defineRepoTherapyScript } from 'repo-therapy';
const myScript = defineRepoTherapyScript((libTool, args) => {
libTool.logger.info(`Hello, ${args.name}!`);
});Expected Outcome:
This will create a script that logs a greeting to the console.
Remark:
You can also use the script function returned by defineRepoTherapy to avoid manually passing the libTool.
defineRepoTherapyTsconfig
A utility for creating and managing tsconfig.json files.
Usage:
import { defineRepoTherapyTsconfig } from 'repo-therapy';
const tsconfig = await defineRepoTherapyTsconfig({
projectType: 'backend',
})();
await tsconfig.write();Expected Outcome:
This will create a tsconfig.json file with the default settings for a backend project.
Remark:
You can also use the tsconfig function returned by defineRepoTherapy to avoid manually passing the projectType option.
defineRepoTherapyVsCode
A utility for creating and managing VS Code settings.
Usage:
import { defineRepoTherapyVsCode } from 'repo-therapy';
const vscode = await defineRepoTherapyVsCode()();
await vscode.write();Expected Outcome:
This will create a .vscode/settings.json and .vscode/extensions.json file with the default settings.
Remark:
You can also use the vscode function returned by defineRepoTherapy to avoid manually passing the packageManager and framework options.
defineRepoTherapyWrapper
A utility for wrapping other functions.
Usage:
import { defineRepoTherapyWrapper } from 'repo-therapy';
const myWrappedFunction = defineRepoTherapyWrapper('my-function', () => {
// ...
});Expected Outcome:
This will create a wrapped function with a slug and a validation function.
Remark:
You can also use the wrapper function returned by defineRepoTherapy to avoid manually passing the warpperClient.
🤝 Contributing
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
We have a friendly and welcoming community on Discord. Come and say hi!
📄 License
This project is MIT licensed.
