contensis-cli 1.0.0-beta.47 → 1.0.0-beta.49

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.
@@ -107,7 +107,17 @@ export const printBlockVersion = (
107
107
  export const printMigrateResult = (
108
108
  { log, messages, contensis, currentProject }: ContensisCli,
109
109
  migrateResult: any,
110
- { action = 'import' }: { action?: 'import' | 'delete' } = {}
110
+ {
111
+ action = 'import',
112
+ showDiff = false,
113
+ showAllEntries = false,
114
+ showChangedEntries = false,
115
+ }: {
116
+ action?: 'import' | 'delete';
117
+ showDiff?: boolean;
118
+ showAllEntries?: boolean;
119
+ showChangedEntries?: boolean;
120
+ } = {}
111
121
  ) => {
112
122
  if (Object.keys(migrateResult.entriesToMigrate.entryIds).length)
113
123
  console.log(``);
@@ -119,43 +129,53 @@ export const printMigrateResult = (
119
129
  string,
120
130
  any
121
131
  ][]) {
122
- console.log(`${log.helpText(contentTypeId)} ${entryStatus.entryTitle}`);
123
- console.log(
124
- log.infoText(
125
- ` ${originalId} ${Object.entries(entryStatus || {})
126
- .filter(x => x[0] !== 'entryTitle')
127
- .map(([projectId, projectStatus]) => {
128
- const [targetGuid, { status }] = (Object.entries(
129
- projectStatus || {}
130
- )?.[0] as [string, { status: MigrateStatus }]) || [
131
- '',
132
- { x: { status: undefined } },
133
- ];
134
- return `${messages.migrate.status(status)(`${status}`)}${
135
- targetGuid !== originalId ? `-> ${targetGuid}` : ''
136
- }`;
137
- })}`
138
- )
139
- );
132
+ // console.log(`${log.helpText(contentTypeId)} ${entryStatus.entryTitle}`);
133
+ if (
134
+ showAllEntries ||
135
+ (showChangedEntries &&
136
+ (
137
+ Object.entries(
138
+ Object.entries(entryStatus[currentProject])[0]
139
+ )[1][1] as any
140
+ ).status !== 'no change')
141
+ ) {
142
+ console.log(
143
+ log.infoText(
144
+ `${originalId} ${Object.entries(entryStatus || {})
145
+ .filter(x => x[0] !== 'entryTitle')
146
+ .map(([projectId, projectStatus]) => {
147
+ const [targetGuid, { status }] = (Object.entries(
148
+ projectStatus || {}
149
+ )?.[0] as [string, { status: MigrateStatus }]) || [
150
+ '',
151
+ { x: { status: undefined } },
152
+ ];
153
+ return `${messages.migrate.status(status)(`${status}`)}${
154
+ targetGuid !== originalId ? `-> ${targetGuid}` : ''
155
+ }`;
156
+ })}`
157
+ ) + ` ${log.helpText(contentTypeId)} ${entryStatus.entryTitle}`
158
+ );
140
159
 
141
- for (const [projectId, projectStatus] of Object.entries(
142
- entryStatus
143
- ).filter(([key]) => key !== 'entryTitle') as [string, any][]) {
144
- const [targetGuid, { error, diff, status }] = Object.entries(
145
- projectStatus
146
- )[0] as [string, any];
147
- if (error) log.error(error);
148
- if (diff) {
149
- console.log(
150
- ` ${log.highlightText(`diff:`)} ${log.infoText(
151
- highlightDiffText(diff)
152
- )}\n`
153
- );
160
+ for (const [projectId, projectStatus] of Object.entries(
161
+ entryStatus
162
+ ).filter(([key]) => key !== 'entryTitle') as [string, any][]) {
163
+ const [targetGuid, { error, diff, status }] = Object.entries(
164
+ projectStatus
165
+ )[0] as [string, any];
166
+ if (error) log.error(error);
167
+ if (diff && showDiff) {
168
+ console.log(
169
+ ` ${log.highlightText(`diff:`)} ${log.infoText(
170
+ highlightDiffText(diff)
171
+ )}\n`
172
+ );
173
+ }
154
174
  }
155
175
  }
156
176
  }
157
- console.log(``);
158
177
  }
178
+ console.log(``);
159
179
  if (
160
180
  contensis?.isPreview &&
161
181
  migrateResult.entriesToMigrate?.[currentProject]?.totalCount > 0 &&
@@ -164,44 +184,80 @@ export const printMigrateResult = (
164
184
  log.help(messages.entries.commitTip());
165
185
  }
166
186
 
167
- // Needs work
168
- // if (action === 'import') {
169
- // for (const [projectId, contentTypeCounts] of Object.entries(
170
- // migrateResult.entries || {}
171
- // ) as [string, any][]) {
172
- // console.log(
173
- // `import from project ${log.highlightText(projectId)} to ${log.boldText(
174
- // log.warningText(currentProject)
175
- // )}`
176
- // );
177
- // for (const [contentTypeId, count] of Object.entries(
178
- // contentTypeCounts
179
- // ) as [string, number][]) {
180
- // const entriesToMigrate =
181
- // migrateResult.entriesToMigrate?.[projectId]?.[contentTypeId];
187
+ if (action === 'import') {
188
+ for (const [projectId, contentTypeCounts] of Object.entries(
189
+ migrateResult.entries || {}
190
+ ) as [string, any][]) {
191
+ log.help(
192
+ `import from project ${log.highlightText(projectId)} to ${log.boldText(
193
+ log.warningText(currentProject)
194
+ )}`
195
+ );
196
+ for (const [contentTypeId, count] of Object.entries(
197
+ contentTypeCounts
198
+ ) as [string, number][]) {
199
+ const entriesToMigrate =
200
+ migrateResult.entriesToMigrate?.[projectId]?.[contentTypeId];
201
+ const existingCount =
202
+ migrateResult.existing?.[projectId]?.[contentTypeId] || 0;
203
+ const existingPercent = ((existingCount / count) * 100).toFixed(0);
204
+ const noChangeOrTotalEntriesCount =
205
+ typeof entriesToMigrate !== 'number'
206
+ ? entriesToMigrate?.['no change'] || 0
207
+ : entriesToMigrate;
208
+
209
+ const isTotalCountRow = contentTypeId === 'totalCount';
210
+
211
+ const changedPercentage = (
212
+ (noChangeOrTotalEntriesCount / count) *
213
+ 100
214
+ ).toFixed(0);
182
215
 
183
- // console.log(
184
- // ` - ${
185
- // contentTypeId === 'totalCount'
186
- // ? log.warningText(`${contentTypeId}: ${count}`)
187
- // : `${contentTypeId}: ${log.helpText(count)}`
188
- // } ${log.infoText`[existing: ${(
189
- // ((migrateResult.existing?.[projectId]?.[contentTypeId] || 0) /
190
- // count) *
191
- // 100
192
- // ).toFixed(0)}%]`} [${
193
- // typeof entriesToMigrate !== 'number' ? `unchanged` : `to update`
194
- // }: ${(
195
- // ((typeof entriesToMigrate !== 'number'
196
- // ? entriesToMigrate?.['no change'] || 0
197
- // : entriesToMigrate) /
198
- // count) *
199
- // 100
200
- // ).toFixed(0)}%]`
201
- // );
202
- // }
203
- // }
204
- // }
216
+ const existingColor =
217
+ existingPercent === '0' ? log.warningText : log.infoText;
218
+ const changedColor = isTotalCountRow
219
+ ? log.helpText
220
+ : changedPercentage === '100'
221
+ ? log.successText
222
+ : log.warningText;
223
+
224
+ console.log(
225
+ ` - ${
226
+ isTotalCountRow
227
+ ? log.highlightText(`${contentTypeId}: ${count}`)
228
+ : `${contentTypeId}: ${log.helpText(count)}`
229
+ }${
230
+ changedPercentage === '100'
231
+ ? ''
232
+ : existingColor(
233
+ ` [existing: ${
234
+ isTotalCountRow ? existingCount : `${existingPercent}%`
235
+ }]`
236
+ )
237
+ }${
238
+ existingPercent === '0'
239
+ ? ''
240
+ : changedColor(
241
+ ` ${
242
+ isTotalCountRow
243
+ ? `[to change: ${noChangeOrTotalEntriesCount}]`
244
+ : changedPercentage === '100'
245
+ ? 'up to date'
246
+ : `[needs update: ${100 - Number(changedPercentage)}%]`
247
+ }`
248
+ )
249
+ }`
250
+ );
251
+ }
252
+ }
253
+ if (migrateResult.errors?.length) {
254
+ console.log(
255
+ ` - ${log.errorText(`errors: ${migrateResult.errors.length}`)}\n`
256
+ );
257
+ for (const error of migrateResult.errors)
258
+ log.error(error.message || error);
259
+ }
260
+ }
205
261
  };
206
262
 
207
263
  const highlightDiffText = (str: string) => {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "1.0.0-beta.47";
1
+ export const LIB_VERSION = "1.0.0-beta.49";