{"id":20284173,"url":"https://github.com/clebert/onecfg-rust","last_synced_at":"2025-04-11T08:24:09.583Z","repository":{"id":65561283,"uuid":"594747672","full_name":"clebert/onecfg-rust","owner":"clebert","description":"One config file to generate them all.","archived":false,"fork":false,"pushed_at":"2023-06-21T22:54:43.000Z","size":141,"stargazers_count":4,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T19:19:50.442Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://crates.io/crates/onecfg","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clebert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-29T14:24:03.000Z","updated_at":"2024-10-11T19:47:03.000Z","dependencies_parsed_at":"2023-02-18T15:46:20.044Z","dependency_job_id":null,"html_url":"https://github.com/clebert/onecfg-rust","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clebert%2Fonecfg-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clebert%2Fonecfg-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clebert%2Fonecfg-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clebert%2Fonecfg-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clebert","download_url":"https://codeload.github.com/clebert/onecfg-rust/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248361059,"owners_count":21090808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T14:18:36.293Z","updated_at":"2025-04-11T08:24:09.564Z","avatar_url":"https://github.com/clebert.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# onecfg\n\n\u003e One config file to generate them all.\n\n`onecfg` provides an efficient solution for managing config files in projects\nthat use multiple tools with interdependent configurations. It introduces the\nconcept of **onecfg files**, which are JSON-based files that store the necessary\ninformation to generate and customize config files for different tools. These\nonecfg files can be shared, extended, and loaded via HTTPS from any location,\nenabling users to create customized configurations tailored to their specific\nneeds.\n\nThis approach addresses two main challenges: first, it eliminates the repetitive\nnature of config files and reduces the need for manual updates across projects.\nSecond, it simplifies the complexity of managing configurations when working\nwith a combination of different tools.\n\n## Installation\n\nYou can install `onecfg` using Cargo:\n\n```\ncargo install onecfg\n```\n\n## Usage\n\nBefore you can generate config files with `onecfg`, you'll need to create a\n`onecfg.json` file in your project's root directory. This file will define how\nthe config files should be generated, as well as any customizations you'd like\nto make.\n\nTo generate the config files, use the following command:\n\n```\nonecfg onecfg.json\n```\n\nTo quickly get started with `onecfg`, you can use the\n[`onecfg-lib`](https://github.com/clebert/onecfg-lib) library. It is a\ncollection of onecfg files specifically designed to configure TypeScript and\nRust projects. By extending these predefined onecfg files, you can easily set up\nyour project without having to create your own configurations from scratch.\n\nTo use the `onecfg-lib` library, simply include the desired onecfg files in the\n`extends` section of your project's `onecfg.json` file. For example:\n\n```json\n{\n  \"extends\": [\n    \"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-editorconfig.json\",\n    \"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-git.json\",\n    \"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-prettier.json\",\n    \"https://raw.githubusercontent.com/clebert/onecfg-lib/main/lib/onecfg-vscode.json\"\n  ]\n}\n```\n\nIn this example, the `onecfg.json` file extends four different onecfg files from\nthe `onecfg-lib` library, which are specifically designed for configuring\nEditorConfig, Git, Prettier, and Visual Studio Code. By extending these files,\nyour project will be set up with the recommended configuration for each tool.\n\nYou can find more onecfg files for TypeScript and Rust projects in the\n[`onecfg-lib` repository](https://github.com/clebert/onecfg-lib).\n\n_Note: You can use the\n[JSON Schema](https://github.com/clebert/onecfg-rust/blob/main/schema.json) to\nvalidate your onecfg file or enable autocompletion in the editor._\n\n### Defining the format of the config files to be generated\n\nIn your `onecfg.json` file, you can define the format of the config files as\nshown below:\n\n```json\n{\n  \"defines\": {\n    \".gitignore\": {\"format\": \"ignorefile\"},\n    \".prettierrc.json\": {\"format\": \"json\"}\n  }\n}\n```\n\nIt's important to note that only config files directly or indirectly defined in\nan extended onecfg file can be generated and patched. A config file under a\nspecific path should only be defined once across all extended onecfg files.\n\nWhen extending onecfg files, ensure that there are no conflicting definitions\nfor the same file paths. If a conflict occurs, you may need to either modify\nyour custom `onecfg.json` file or create a new onecfg file to resolve the issue.\n\n### Declaring patches specific to certain config files\n\nYou can declare patches specific to certain config files in your `onecfg.json`\nfile:\n\n```json\n{\n  \"patches\": {\n    \".gitignore\": [{\"value\": [\"/dist\"]}],\n    \".prettierrc.json\": [{\"value\": {\"printWidth\": 80, \"singleQuote\": true}}]\n  }\n}\n```\n\nIt's crucial to understand that patches for undefined files will have no effect\nand will not negatively impact the configuration process. This has the advantage\nof allowing you to plan integration patches for tools that may not be used in a\nspecific project. If the tool is not being used, the corresponding configuration\nwon't be applied, thus preventing any unnecessary configurations from being\ngenerated.\n\n## Config formats\n\n`onecfg` supports various config formats including `text`, `json`, `toml`,\n`yaml`, and `ignorefile`. You can define the format of a config file in the\ndefines section of your onecfg.json file, and provide patches to customize the\nvalues.\n\n### `text`\n\n```json\n{\n  \"defines\": {\n    \"test.txt\": {\"format\": \"text\"}\n  },\n  \"patches\": {\n    \"test.txt\": [{\"value\": \"foo\"}, {\"value\": \"bar\"}]\n  }\n}\n```\n\n```\nbar\n```\n\n### `json`\n\n```json\n{\n  \"defines\": {\n    \"test.json\": {\"format\": \"json\"}\n  },\n  \"patches\": {\n    \"test.json\": [{\"value\": {\"foo\": \"bar\"}}, {\"value\": {\"baz\": \"qux\"}}]\n  }\n}\n```\n\n```json\n{\n  \"baz\": \"qux\",\n  \"foo\": \"bar\"\n}\n```\n\n### `toml`\n\n```json\n{\n  \"defines\": {\n    \"test.toml\": {\"format\": \"toml\"}\n  },\n  \"patches\": {\n    \"test.toml\": [{\"value\": {\"foo\": \"bar\"}}, {\"value\": {\"baz\": \"qux\"}}]\n  }\n}\n```\n\n```toml\nbaz = \"qux\"\nfoo = \"bar\"\n```\n\n### `yaml`\n\n```json\n{\n  \"defines\": {\n    \"test.yml\": {\"format\": \"yaml\"}\n  },\n  \"patches\": {\n    \"test.yml\": [{\"value\": {\"foo\": \"bar\"}}, {\"value\": {\"baz\": \"qux\"}}]\n  }\n}\n```\n\n```yaml\nbaz: qux\nfoo: bar\n```\n\n### `ignorefile`\n\n```json\n{\n  \"defines\": {\n    \".testignore\": {\"format\": \"ignorefile\"}\n  },\n  \"patches\": {\n    \".testignore\": [{\"value\": [\"foo\", \"bar\"]}, {\"value\": [\"baz\"]}]\n  }\n}\n```\n\n```\nfoo\nbar\nbaz\n```\n\n## License\n\nLicensed under either of\n\n- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or\n  http://www.apache.org/licenses/LICENSE-2.0)\n- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclebert%2Fonecfg-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclebert%2Fonecfg-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclebert%2Fonecfg-rust/lists"}