## ✨ Features
- **CLI** (`config-sync` CLI for syncing the config from the command line)
- **GUI** (Settings page for syncing the config in Strapi admin)
- **Partial sync** (Import or export only specific portions of config)
- **Exclude configs** (Exclude specific config from the sync)
## ⏳ Installation
Install the plugin in your Strapi project.
```bash
# using yarn
yarn add strapi-plugin-config-sync
# using npm
npm install strapi-plugin-config-sync --save
```
Add the export path to the `watchIgnoreFiles` list in the `config/admin.js` file.
This way your app won't reload when you export the config in development.
##### `config/admin.js`:
```
module.exports = ({ env }) => ({
// ...
watchIgnoreFiles: [
'**/config-sync/files/**',
],
});
```
After successful installation you have to rebuild the admin UI so it'll include this plugin. To rebuild and restart Strapi run:
```bash
# using yarn
yarn build --clean
yarn develop
# using npm
npm run build --clean
npm run develop
```
The **Config Sync** plugin should appear in the **Plugins** section of Strapi sidebar after you run app again.
Enjoy 🎉
## 🖐 Requirements
Complete installation requirements are the exact same as for Strapi itself and can be found in the [Strapi documentation](https://strapi.io/documentation).
**Supported Strapi versions**:
- Strapi 4.0.0 (recently tested)
- Strapi ^4.x
- Strapi ^3.4.x (use `strapi-plugin-config-sync@0.1.6`)
(This plugin may work with older Strapi versions, but these are not tested nor officially supported at this time.)
**We recommend always using the latest version of Strapi to start your new projects**.
## 💡 Motivation
In Strapi we come across what I would call config types. These are models of which the records are stored in our database, just like content types. Though the big difference here is that your code ofter relies on the database records of these types.
Having said that, it makes sense that these records can be exported, added to git, and be migrated across environments. This way we can make sure we have all the data our code relies on, on each environment.
Examples of these types are:
- Admin roles _(admin::role)_
- User roles _(plugin::users-permissions.role)_
- Admin settings _(strapi::core-store)_
- I18n locale _(plugin::i18n.locale)_
This plugin gives you the tools to sync this data. You can export the data as JSON files on one env, and import them on every other env. By writing this data as JSON files you can easily track them in your version control system (git).
_With great power comes great responsibility - Spider-Man_
## ⌨️ Usage / Workflow
### Local development
When building a new feature locally for your Strapi project you'd use the following workflow:
- Build the feature.
- Export the config. Either through the CLI or the GUI.
- Commit and push the files to git.
### Deployment
When deploying the newly created feature you'd use the following workflow:
- Pull the latest file changes to the environment.
- Import the config. Preferably through the CLI.
- (Re)start your Strapi instance.
### Production deployment
When you're deploying your Strapi project to production please be cautious when import the config.
You should make sure there are no config changes that will be overwritten by the import.
If there have been made changes to the config since the last import you should export these first before importing the new config.
_There really shouldn't be any config changes made directly on production. This is a bad practice._
## 🔌 Command line interface (CLI)
Add the `config-sync` command as a script to the `package.json` of your Strapi project:
```
"scripts": {
// ...
"cs": "config-sync"
},
```
You can now run all the `config-sync` commands like this:
```bash
# using yarn
yarn cs --help
# using npm
npm run cs --help
```
### ⬆️ Import ⬇️ Export
> _Command:_ `import` _Alias:_ `i`
>
> _Command:_ `export` _Alias:_ `e`
These commands are used to sync the config in your Strapi project.
_Example:_
```bash
# using yarn
yarn cs import
yarn cs export
# using npm
npm run cs import
npm run cs export
```
##### Flag: `--yes` `-y`
Use this flag to skip the confirm prompt and go straight to syncing the config.
```bash
[command] --yes
```
##### Flag: `--type` `-t`
Use this flag to specify the type of config you want to sync.
```bash
[command] --type user-role
```
##### Flag: `--partial` `-p`
Use this flag to sync a specific set of configs by giving the CLI a comma-separated string of config names.
```bash
[command] --partial user-role.public,i18n-locale.en
```
### ↔️ Diff
> _Command:_ `diff` | _Alias:_ `d`
This command is used to see the difference between the config as found in the sync directory, and the config as found in the database.
_Example:_
```bash
# using yarn
yarn cs diff
# using npm
npm run cs diff
```
## 🖥️ Admin panel (GUI)
This plugin ships with a settings page which can be accessed from the admin panel of Strapi. On this page you can pretty much do the same as you can from the CLI. You can import, export and see the difference between the config as found in the sync directory, and the config as found in the database.
**Pro tip:**
By clicking on one of the items in the diff table you can see the exact difference between sync dir and database in a git-style diff viewer.