@jungvonmatt/contentful-migrations 6.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -3
- package/cli.js +15 -9
- package/lib/config.js +10 -5
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -26,11 +26,41 @@ This initializes migrations and stores the config values in the `package.json` o
|
|
|
26
26
|
|
|
27
27
|
#### Configuration files
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
We use [`@jungvonmatt/contentful-config`](https://github.com/jungvonmatt/contentful-ssg/tree/main/packages/contentful-config) (built on [`@jungvonmatt/config-loader`](https://github.com/jungvonmatt/config-loader) and [`c12`](https://github.com/unjs/c12)) which provides extensive configuration loading capabilities from multiple sources.
|
|
30
|
+
|
|
31
|
+
**Supported configuration locations (in order of priority):**
|
|
32
|
+
- Configuration overrides passed via command line arguments
|
|
33
|
+
- User-specified config file (via `--config-file` option)
|
|
34
|
+
- `migrations.config.{js,ts,mjs,cjs,mts,cts}`
|
|
35
|
+
- `.config/migrations.{js,ts,mjs,cjs,mts,cts,json,jsonc,json5,yaml,yml,toml}`
|
|
36
|
+
- `.migrationsrc.{js,ts,mjs,cjs,mts,cts,json,jsonc,json5,yaml,yml,toml}`
|
|
37
|
+
- `.migrationsrc`
|
|
38
|
+
- `package.json` (in a `migrations` property)
|
|
39
|
+
- Environment variables (with `CONTENTFUL_MIGRATIONS_CONFIG_*` prefix)
|
|
40
|
+
- `.env` files (`.env.{NODE_ENV}`, `.env`)
|
|
41
|
+
- Default configuration
|
|
42
|
+
|
|
43
|
+
**Extending configurations:**
|
|
44
|
+
You can extend configurations from other files or remote sources using the `extends` property:
|
|
45
|
+
```js
|
|
46
|
+
// migrations.config.js
|
|
47
|
+
export default {
|
|
48
|
+
extends: ['./base.config.js', 'github:user/repo'],
|
|
49
|
+
// your config...
|
|
50
|
+
}
|
|
51
|
+
```
|
|
30
52
|
|
|
31
|
-
|
|
53
|
+
**Environment-specific configuration:**
|
|
54
|
+
```js
|
|
55
|
+
// migrations.config.js
|
|
56
|
+
export default {
|
|
57
|
+
spaceId: 'default-space',
|
|
58
|
+
$development: { spaceId: 'dev-space' },
|
|
59
|
+
$production: { spaceId: 'prod-space' }
|
|
60
|
+
}
|
|
61
|
+
```
|
|
32
62
|
|
|
33
|
-
|
|
63
|
+
You can specify any config file path using the `--config-file <path/to/config>` command line argument. Multiple config files can be used for different environments or spaces in your project.
|
|
34
64
|
|
|
35
65
|
#### Configuration values
|
|
36
66
|
|
package/cli.js
CHANGED
|
@@ -66,15 +66,21 @@ program
|
|
|
66
66
|
.description('Initialize contentful-migrations')
|
|
67
67
|
.action(
|
|
68
68
|
actionRunner(async (cmd) => {
|
|
69
|
-
const config = await getConfig(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
69
|
+
const config = await getConfig(
|
|
70
|
+
parseArgs(cmd || {}),
|
|
71
|
+
[],
|
|
72
|
+
[
|
|
73
|
+
'managementToken',
|
|
74
|
+
'host',
|
|
75
|
+
'organizationId',
|
|
76
|
+
'spaceId',
|
|
77
|
+
'environmentId',
|
|
78
|
+
'storage',
|
|
79
|
+
'fieldId',
|
|
80
|
+
'migrationContentTypeId',
|
|
81
|
+
'directory',
|
|
82
|
+
]
|
|
83
|
+
);
|
|
78
84
|
|
|
79
85
|
const { managementToken, accessToken, environmentId, spaceId, ...rest } = config;
|
|
80
86
|
|
package/lib/config.js
CHANGED
|
@@ -13,13 +13,14 @@ const STATE_FAILURE = 'failure';
|
|
|
13
13
|
* Get configuration
|
|
14
14
|
* @param {Object} args
|
|
15
15
|
*/
|
|
16
|
-
const getConfig = async (args, required = []) => {
|
|
16
|
+
const getConfig = async (args, required = [], prompt = []) => {
|
|
17
17
|
const { configFile, cwd, ...overrides } = args;
|
|
18
18
|
const { loadContentfulConfig } = await import('@jungvonmatt/contentful-config');
|
|
19
19
|
const result = await loadContentfulConfig('migrations', {
|
|
20
20
|
configFile,
|
|
21
21
|
cwd,
|
|
22
22
|
overrides,
|
|
23
|
+
prompt,
|
|
23
24
|
defaultConfig: {
|
|
24
25
|
fieldId: 'migration',
|
|
25
26
|
migrationContentTypeId: 'contentful-migrations',
|
|
@@ -61,11 +62,13 @@ const getPromts = (data) => {
|
|
|
61
62
|
message: 'How should the migrations be managed',
|
|
62
63
|
choices: [
|
|
63
64
|
{
|
|
64
|
-
|
|
65
|
+
message: 'Content-model (recommended)',
|
|
66
|
+
name: STORAGE_CONTENT,
|
|
65
67
|
value: STORAGE_CONTENT,
|
|
66
68
|
},
|
|
67
69
|
{
|
|
68
|
-
|
|
70
|
+
message: 'Tag',
|
|
71
|
+
name: STORAGE_TAG,
|
|
69
72
|
value: STORAGE_TAG,
|
|
70
73
|
},
|
|
71
74
|
],
|
|
@@ -75,7 +78,8 @@ const getPromts = (data) => {
|
|
|
75
78
|
type: 'input',
|
|
76
79
|
name: 'fieldId',
|
|
77
80
|
message: 'Id of the tag where the the migration version is stored',
|
|
78
|
-
skip(
|
|
81
|
+
skip() {
|
|
82
|
+
const answers = this?.enquirer?.answers;
|
|
79
83
|
return answers.storage === STORAGE_CONTENT;
|
|
80
84
|
},
|
|
81
85
|
initial: data.fieldId,
|
|
@@ -84,7 +88,8 @@ const getPromts = (data) => {
|
|
|
84
88
|
type: 'input',
|
|
85
89
|
name: 'migrationContentTypeId',
|
|
86
90
|
message: 'Id of the content-type where the the migrations are stored',
|
|
87
|
-
skip(
|
|
91
|
+
skip() {
|
|
92
|
+
const answers = this?.enquirer?.answers;
|
|
88
93
|
return answers.storage === STORAGE_TAG;
|
|
89
94
|
},
|
|
90
95
|
initial: data.migrationContentTypeId,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jungvonmatt/contentful-migrations",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Helper to handle migrations in contentful",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@contentful/rich-text-plain-text-renderer": "^15.12.1",
|
|
38
|
-
"@jungvonmatt/contentful-config": "^3.0.
|
|
38
|
+
"@jungvonmatt/contentful-config": "^3.0.3",
|
|
39
39
|
"array.prototype.flatmap": "^1.3.3",
|
|
40
40
|
"ascii-tree": "^0.3.0",
|
|
41
41
|
"cli-progress": "^3.11.2",
|
|
@@ -45,7 +45,6 @@
|
|
|
45
45
|
"contentful-import": "^9.4.91",
|
|
46
46
|
"contentful-management": "^11.48.0",
|
|
47
47
|
"contentful-migration": "^4.28.1",
|
|
48
|
-
"cosmiconfig": "^8.0.0",
|
|
49
48
|
"deep-diff": "^1.0.2",
|
|
50
49
|
"diff": "^5.1.0",
|
|
51
50
|
"dotenv": "^10.0.0",
|