{"id":17217095,"url":"https://github.com/sroze/companienv","last_synced_at":"2025-04-12T18:47:13.506Z","repository":{"id":28799322,"uuid":"119355496","full_name":"sroze/companienv","owner":"sroze","description":"Companion for .env files","archived":false,"fork":false,"pushed_at":"2023-08-28T22:45:55.000Z","size":64,"stargazers_count":247,"open_issues_count":3,"forks_count":12,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-03T21:12:29.158Z","etag":null,"topics":["companion","dotenv","generator","php","symfony"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sroze.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-29T08:40:12.000Z","updated_at":"2025-02-10T09:36:15.000Z","dependencies_parsed_at":"2024-06-18T18:41:30.854Z","dependency_job_id":"56607eb1-8db9-443f-91f1-df40c1cea2cd","html_url":"https://github.com/sroze/companienv","commit_stats":{"total_commits":41,"total_committers":9,"mean_commits":4.555555555555555,"dds":0.3414634146341463,"last_synced_commit":"0b12fff154d3205bbe8cc93d7a95afd7c07ce5ef"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sroze%2Fcompanienv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sroze%2Fcompanienv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sroze%2Fcompanienv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sroze%2Fcompanienv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sroze","download_url":"https://codeload.github.com/sroze/companienv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248617790,"owners_count":21134197,"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":["companion","dotenv","generator","php","symfony"],"created_at":"2024-10-15T03:43:17.362Z","updated_at":"2025-04-12T18:47:13.475Z","avatar_url":"https://github.com/sroze.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Companienv\n\nYour companion for `.env` files. Everybody knows about [12 factor](https://12factor.net/) and [environments variables](https://12factor.net/config) now.\nA lot of frameworks such as Symfony [are using a `.env` file](https://symfony.com/doc/current/configuration.html#the-env-file-environment-variables) to configure the application,\nbut we don't have anything to help users to complete their local `.env` file.\n\nCompanienv will helps you manage the `.env` files, from a reference `.env.dist` version in your code repository. Companienv can:\n\n- Read and populate default values\n- Identify and ask only missing variables\n- Ask variables [only if matching some conditions](#only-if-extension)\n- [Propagate files](#file-to-propagate-extension) (copy files from somewhere else)\n- Generate [public/private RSA keys](#rsa-pair-extension)\n- Generate [SSL certificates](#ssl-certificate-extension)\n- Much more, via [your own extensions](#your-own-extensions)\n\n## Usage\n\n1. Require `sroze/companienv` as your project dependency:\n```\ncomposer req sroze/companienv\n```\n\n2. Run your companion:\n```\nvendor/bin/companienv\n```\n\n### Composer automation\n\nYou can run Companienv automatically after `composer install` or `composer update` commands by configuring the scripts in your `composer.json` file:\n\n```json\n{\n    \"scripts\": {\n        \"post-install-cmd\": [\n            \"Companienv\\\\Composer\\\\ScriptHandler::run\"\n        ],\n        \"post-update-cmd\": [\n            \"Companienv\\\\Composer\\\\ScriptHandler::run\"\n        ]\n    }\n}\n```\n\nBy default, the file used as a template is `.env.dist` and the written file is `.env`. You can change these defaults within your `composer.json` file:\n\n\n```json\n{\n    \"extra\": {\n        \"companienv-parameters\": [\n            {\n                \"file\": \".env.foo\",\n                \"dist-file\": \".env.foo.dist\"\n            }\n        ]\n    }\n}\n```\n\n## The `.env.dist` file\n\n**All your configuration is directly in your `.env.dist` file, as comments.** The configuration is divided in blocks that \nwill be displayed to the user for a greater understanding of the configuration. Here are the fondations for Companienv:\n\n- **Blocks.** They logically group variables together. They are defined by a title (line starting with a double-comment \n  `##`) and a description (every comment line directly bellow)\n- **Attributes.** Defined by a line starting with `#+`, an attribute is associated to one or multiple variables. These \n  attributes are the entrypoint for extensions. In the example above, it says that the `JWT_*` variables are associated\n  with an RSA key pair, so Companienv will automatically offer the user to generate one for them.\n- **Comments.** Lines starting by `#~` will be ignored by Companienv.\n\n*Example of `.env.dist.` file*\n```\n# .env.dist\n\n## Welcome in the configuration of [my-project]\n#\n#~ Please run the `bin/start` command.\n#~ These lines starting with `~` are not going to be displayed to the user\n\n## GitHub\n# In order to be able to login with GitHub, you need to create a GitHub application. To get access to the code\n# repositories, you need to create a GitHub integration.\n#\n#+file-to-propagate(GITHUB_INTEGRATION_KEY_PATH)\n#\nGITHUB_CLIENT_ID=\nGITHUB_CLIENT_SECRET=\nGITHUB_INTEGRATION_ID=\nGITHUB_INTEGRATION_KEY_PATH=\nGITHUB_SECRET=\n\n## Security\n# We need sauce! Well, no, we need an SSL certificate.\n#\n#+rsa-pair(JWT_PRIVATE_KEY_PATH JWT_PUBLIC_KEY_PATH JWT_PRIVATE_KEY_PASS_PHRASE)\n#\nJWT_PRIVATE_KEY_PATH=/runtime/keys/jwt-private.pem\nJWT_PUBLIC_KEY_PATH=/runtime/keys/jwt-public.pem\nJWT_PRIVATE_KEY_PASS_PHRASE=\n\n## Another block\n# With its (optional) description\nAND_OTHER_VARIABLES=\n```\n\n## Built-in extensions\n\n- [Only if ...](#only-if-extension)\n- [Propagate file](#file-to-propagate-extension)\n- [RSA keys](#rsa-pair-extension)\n- [SSL certificate](#ssl-certificate-extension)\n\n### `only-if` extension\n\nSome of the blocks of your `.env` file might not even be relevant if some other variable was disabling a given feature.\n\n**Example:** This will only ask for the `INTERCOM_APPLICATION_ID` variable if `INTERCOM_ENABLED` has the value (current \nor entered by the user) `true`.\n```\n## Support \u0026 Feedback\n# If you would like to allow your users to get some support from you, give you some feedback and this\n# sort of things, select the integrations you'd like.\n#\n#+only-if(INTERCOM_APPLICATION_ID):(INTERCOM_ENABLED=true)\n#\nINTERCOM_ENABLED=false\nINTERCOM_APPLICATION_ID=none\n```\n\n### `file-to-propagate` extension\n\nWill ask the path of an existing file and copy it to the destination mentioned in the reference.\n\n**Example:** this will ask the user to give the path of an existing file. It will copy this file to the path \n             `/runtime/keys/firebase.json`, relative to the root directory of the project.\n```yaml\n#+file-to-propagate(FIREBASE_SERVICE_ACCOUNT_PATH)\nFIREBASE_SERVICE_ACCOUNT_PATH=/runtime/keys/firebase.json\n```\n\n### `rsa-pair` extension\n\nIf the public/private key pair does not exist, Companienv will offer to generate one for the user.\n```yaml\n#+rsa-pair(JWT_PRIVATE_KEY_PATH JWT_PUBLIC_KEY_PATH JWT_PRIVATE_KEY_PASS_PHRASE)\nJWT_PRIVATE_KEY_PATH=/runtime/keys/jwt-private.pem\nJWT_PUBLIC_KEY_PATH=/runtime/keys/jwt-public.pem\nJWT_PRIVATE_KEY_PASS_PHRASE=\n```\n\n### `ssl-certificate-extension`\n\nSimilar to the [RSA keys pair](#rsa-pair-extension): Companienv will offer to generate a self-signed SSL certificate if\nit does not exist yet.\n\n```yaml\n#+ssl-certificate(SSL_CERTIFICATE_PRIVATE_KEY_PATH SSL_CERTIFICATE_CERTIFICATE_PATH SSL_CERTIFICATE_DOMAIN_NAME)\nSSL_CERTIFICATE_PRIVATE_KEY_PATH=/runtime/keys/server.key\nSSL_CERTIFICATE_CERTIFICATE_PATH=/runtime/keys/server.crt\nSSL_CERTIFICATE_DOMAIN_NAME=\n```\n\n## Your own extensions\n\nYou can easily create and use your own extensions with Companienv. In order to do so, you'll have to start Companienv \nwith your own PHP file and use the `registerExtension` method of the `Application`:\n\n```php\nuse Companienv\\Application;\nuse Companienv\\Extension;\n\n$application = new Application($rootDirectory);\n$application-\u003eregisterExtension(new class() implements Extension {\n    // Implements the interface...\n});\n$application-\u003erun();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsroze%2Fcompanienv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsroze%2Fcompanienv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsroze%2Fcompanienv/lists"}