@jungvonmatt/contentful-migrations 6.1.0 → 6.1.2

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 CHANGED
@@ -30,7 +30,7 @@ We use [`@jungvonmatt/contentful-config`](https://github.com/jungvonmatt/content
30
30
 
31
31
  **Supported configuration locations (in order of priority):**
32
32
  - Configuration overrides passed via command line arguments
33
- - User-specified config file (via `--config-file` option)
33
+ - User-specified config file (via `--config` option)
34
34
  - `migrations.config.{js,ts,mjs,cjs,mts,cts}`
35
35
  - `.config/migrations.{js,ts,mjs,cjs,mts,cts,json,jsonc,json5,yaml,yml,toml}`
36
36
  - `.migrationsrc.{js,ts,mjs,cjs,mts,cts,json,jsonc,json5,yaml,yml,toml}`
@@ -60,7 +60,7 @@ export default {
60
60
  }
61
61
  ```
62
62
 
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.
63
+ You can specify any config file path using the `--config <path/to/config>` command line argument. Multiple config files can be used for different environments or spaces in your project.
64
64
 
65
65
  #### Configuration values
66
66
 
package/cli.js CHANGED
@@ -82,8 +82,6 @@ program
82
82
  ]
83
83
  );
84
84
 
85
- const { managementToken, accessToken, environmentId, spaceId, ...rest } = config;
86
-
87
85
  if (config.storage === STORAGE_CONTENT) {
88
86
  await initializeContentModel(config);
89
87
  await migrateToContentStorage(config);
@@ -92,24 +90,35 @@ program
92
90
  await migrateToTagStorage(config);
93
91
  }
94
92
 
95
- if (!process.env.CONTENTFUL_SPACE_ID) {
96
- rest.spaceId = spaceId;
97
- }
98
-
99
93
  const storeConfig = await confirm({ message: 'Do you want to store the configuration?' });
100
94
 
101
95
  if (storeConfig) {
96
+ // only store relevant config values without management token
97
+ // management token should not be stored inside the project
98
+ const { host, spaceId, environmentId, storage, fieldId, migrationContentTypeId, directory } = config;
99
+
100
+ const data = {
101
+ host,
102
+ spaceId,
103
+ environmentId,
104
+ directory,
105
+ storage,
106
+ ...(storage === STORAGE_CONTENT ? { migrationContentTypeId } : { fieldId }),
107
+ };
108
+
102
109
  // try to store in package.json
103
110
  const { pkgUp } = await import('pkg-up');
104
111
  const localPkg = await pkgUp();
105
112
  if (localPkg) {
106
113
  const packageJson = await fs.readJson(localPkg);
107
- rest.directory = path.relative(path.dirname(localPkg), rest.directory);
108
- packageJson.migrations = rest;
114
+ data.directory = path.relative(path.dirname(localPkg), data.directory);
115
+ packageJson.migrations = data;
109
116
  await fs.outputJson(localPkg, packageJson, { spaces: 2 });
110
117
  } else {
111
118
  // store in .migrationsrc if no package.json is available
112
- await fs.outputJson(path.join(process.cwd(), '.migrationsrc'), rest, { spaces: 2 });
119
+ const cwd = cmd.cwd ? path.resolve(cmd.cwd) : process.cwd();
120
+ data.directory = path.relative(cwd, data.directory);
121
+ await fs.outputJson(path.join(cwd, '.migrationsrc.json'), data, { spaces: 2 });
113
122
  }
114
123
  }
115
124
  })
@@ -134,6 +143,7 @@ program
134
143
  'environmentId',
135
144
  'directory',
136
145
  ]);
146
+
137
147
  await fetchMigration({ ...config, contentType: cmd.contentType });
138
148
  })
139
149
  );
@@ -207,7 +217,7 @@ program
207
217
  .description('Execute a single migration.')
208
218
  .action(
209
219
  actionRunner(async (file, options) => {
210
- const config = await getConfig(parseArgs(cmd || {}), [
220
+ const config = await getConfig(parseArgs(options || {}), [
211
221
  'managementToken',
212
222
  'spaceId',
213
223
  'environmentId',
@@ -240,7 +250,7 @@ program
240
250
  .action(
241
251
  actionRunner(async (file, options) => {
242
252
  const { remove, add } = options;
243
- const config = await getConfig(parseArgs(cmd || {}), [
253
+ const config = await getConfig(parseArgs(options || {}), [
244
254
  'managementToken',
245
255
  'spaceId',
246
256
  'environmentId',
package/lib/config.js CHANGED
@@ -16,6 +16,7 @@ const STATE_FAILURE = 'failure';
16
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
20
  const result = await loadContentfulConfig('migrations', {
20
21
  configFile,
21
22
  cwd,
package/lib/diff.js CHANGED
@@ -30,7 +30,7 @@ const getNodeDate = (node) => {
30
30
 
31
31
  const oldValueColor = (text) => pc.reset(pc.red(pc.dim(text)));
32
32
  const newValueColor = (text) => pc.reset(pc.green(text));
33
- const unchangedColor = (text) => pc.reset(pc.grey(text));
33
+ const unchangedColor = (text) => pc.reset(pc.gray(text));
34
34
 
35
35
  const diffString = (source, dest) => {
36
36
  const diff = Diff.diffWords(source, dest);
@@ -45,7 +45,7 @@ const diffString = (source, dest) => {
45
45
 
46
46
  if (part.value.length > 50) {
47
47
  const value = `${part.value.slice(0, 15)} [...] ${part.value.slice(-15)}`;
48
- return unchangedColor(pc.grey(value));
48
+ return unchangedColor(pc.gray(value));
49
49
  }
50
50
 
51
51
  return unchangedColor(part.value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jungvonmatt/contentful-migrations",
3
- "version": "6.1.0",
3
+ "version": "6.1.2",
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.3",
38
+ "@jungvonmatt/contentful-config": "^3.0.5",
39
39
  "array.prototype.flatmap": "^1.3.3",
40
40
  "ascii-tree": "^0.3.0",
41
41
  "cli-progress": "^3.11.2",