Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vdustr/simple-ignore

One `.gitignore` file to rule them all.
https://github.com/vdustr/simple-ignore

cli docker eslint git gitignore ignorefile monorepo nodejs npm prettier stylelint

Last synced: 26 days ago
JSON representation

One `.gitignore` file to rule them all.

Awesome Lists containing this project

README

        

# simple-ignore

One `.gitignore` file to rule them all.

## Background

- Some tools do not consistently follow the rules outlined in the `.gitignore` file. While a few of these tools may offer the option to enforce `.gitignore` rules, this feature is not universally compatible. For example, there might be a necessity to exclude specific files from version control without modifying their formatting, such as autogenerated files like `CHANGELOG.md`.
- Certain tools exhibit suboptimal performance within the VSCode workspace environment. For instance, `eslint` may encounter issues when used within a subfolder of a monorepo.
- Different ignore files, such as `.dockerignore`, employ distinct syntax conventions. For instance, while specifying `package.json` in `.gitignore` is equivalent to `**/package.json` in `.dockerignore`, specifying `/package.json` in `.gitignore` equates to specifying `package.json` in `.dockerignore`.

## Features

- Generate ignore files for multiple tools.
- Add extra rules for files that should not undergo formatting.
- Structure ignore files for packages within monorepositories.
- Translate rules into `.dockerignore` syntax.

## Usage

When embarking on a new project, it's advisable to procure the `.gitignore` file from [github/gitignore](https://github.com/github/gitignore).

Alternatively, you can obtain one from Toptal by using the following command:

```sh
curl -o .gitignore https://www.toptal.com/developers/gitignore/api/node
```

If your repository is not a node project, you can generate a tailored `.gitignore` file for your needs on [Toptal's gitignore generator](https://www.toptal.com/developers/gitignore).

It's strongly encouraged to employ project-specific `.gitignore` files exclusively within the repository. Any environment-specific ignore files, such as those for operating systems or editors, should be stored directly within your user directory.

To obtain such files for macOS and Visual Studio Code, you can use the following command:

```sh
curl -o ~/.gitignore https://www.toptal.com/developers/gitignore/api/macos,visualstudiocode
```

If you're already working within a project, you can employ the following command to delete the ignore files:

```sh
rm .*ignore packages/*/.*ignore
git checkout .gitignore
```

If you wish to lint the dotfiles using tools such as `eslint`, you can prepend it to the `.gitignore` file:

```ini
!.*
```

You only need to maintain `.gitignore`, so you can remove all other files and append the following rules to it:

```ini
.*ignore
!/.gitignore
```

Add the following to your `package.json`:

```json
{
"scripts": {
"postinstall": "npx simple-ignore"
}
}
```

Each time you run `npm install`, the required ignore files will be generated automatically, following the specifications outlined in the `.gitignore` file. Additionally, `simple-ignore` will detect monorepos and generate ignore files for each package by locating the `package.json` files.

If you prefer to run it locally or are concerned about potential breaking changes, we highly recommend installing and running it locally:

```sh
npm install simple-ignore
npm exec simple-ignore
```

## Configuration

To customize the ignore files, simply add a `simple-ignore.config.ts` file to the root directory of your project.

```ts
// simple-ignore.config.ts
import { defineConfig } from "simple-ignore";

export default defineConfig({
// ...
});
```

You can also utilize other methods supported by [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig), like adding a `simple-ignore` field to your `package.json` file.

To view all available options, you can refer to the [default configuration](https://github.com/VdustR/simple-ignore/blob/main/packages/simple-ignore/src/defaultConfig.ts).

## CLI

```sh
# Default Usage
npx simple-ignore

# Help Command
npx simple-ignore -h

# Using Specific Configuration File
npx simple-ignore -c simple-ignore.config.ts

# Dry Run Mode
npx simple-ignore -d

# Overriding Rules
npx simple-ignore -lr __snapshots__,/package-lock.json,/pnpm-lock.yaml,/yarn.lock,CHANGELOG.md

# Override Root Directory
# By default, the rootDir is the directory where the configuration file resides.
# If the configuration file is absent, the rootDir defaults to the directory where the command is executed.
# You can specify a different rootDir using the -r flag.
npx simple-ignore -r ..
```

## API

```ts
import { generateIgnoreFiles } from "simple-ignore";

await generateIgnoreFiles({
// configuration
});
```

## License

[MIT](https://github.com/VdustR/simple-ignore/blob/main/LICENSE)

Copyright (c) 2024 ViPro (http://vdustr.dev)