contensis-cli 1.0.0-beta.5 → 1.0.0-beta.51
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 +669 -74
- package/dist/commands/connect.js +3 -3
- package/dist/commands/connect.js.map +2 -2
- package/dist/commands/create.js +30 -10
- package/dist/commands/create.js.map +2 -2
- package/dist/commands/diff.js +57 -0
- package/dist/commands/diff.js.map +7 -0
- package/dist/commands/get.js +61 -12
- package/dist/commands/get.js.map +2 -2
- package/dist/commands/globalOptions.js +22 -17
- package/dist/commands/globalOptions.js.map +2 -2
- package/dist/commands/import.js +36 -10
- package/dist/commands/import.js.map +2 -2
- package/dist/commands/index.js +9 -1
- package/dist/commands/index.js.map +2 -2
- package/dist/commands/list.js +19 -8
- package/dist/commands/list.js.map +2 -2
- package/dist/commands/login.js +3 -3
- package/dist/commands/login.js.map +2 -2
- package/dist/commands/push.js +8 -4
- package/dist/commands/push.js.map +2 -2
- package/dist/commands/release.js +47 -0
- package/dist/commands/release.js.map +7 -0
- package/dist/commands/remove.js +10 -8
- package/dist/commands/remove.js.map +2 -2
- package/dist/commands/set.js +53 -12
- package/dist/commands/set.js.map +2 -2
- package/dist/localisation/en-GB.js +97 -47
- package/dist/localisation/en-GB.js.map +2 -2
- package/dist/providers/CredentialProvider.js +36 -7
- package/dist/providers/CredentialProvider.js.map +3 -3
- package/dist/providers/SessionCacheProvider.js +21 -1
- package/dist/providers/SessionCacheProvider.js.map +2 -2
- package/dist/providers/file-provider.js +8 -4
- package/dist/providers/file-provider.js.map +3 -3
- package/dist/services/ContensisCliService.js +600 -336
- package/dist/services/ContensisCliService.js.map +3 -3
- package/dist/shell.js +27 -10
- package/dist/shell.js.map +3 -3
- package/dist/util/console.printer.js +170 -47
- package/dist/util/console.printer.js.map +2 -2
- package/dist/util/index.js +5 -2
- package/dist/util/index.js.map +3 -3
- package/dist/util/logger.js +45 -13
- package/dist/util/logger.js.map +2 -2
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/connect.ts +3 -2
- package/src/commands/create.ts +37 -8
- package/src/commands/diff.ts +41 -0
- package/src/commands/get.ts +80 -5
- package/src/commands/globalOptions.ts +18 -17
- package/src/commands/import.ts +43 -4
- package/src/commands/index.ts +9 -1
- package/src/commands/list.ts +35 -9
- package/src/commands/login.ts +3 -2
- package/src/commands/push.ts +9 -2
- package/src/commands/release.ts +32 -0
- package/src/commands/remove.ts +12 -4
- package/src/commands/set.ts +65 -9
- package/src/localisation/en-GB.ts +142 -64
- package/src/providers/CredentialProvider.ts +39 -6
- package/src/providers/SessionCacheProvider.ts +29 -2
- package/src/providers/file-provider.ts +8 -4
- package/src/services/ContensisCliService.ts +742 -387
- package/src/shell.ts +31 -11
- package/src/util/console.printer.ts +234 -66
- package/src/util/index.ts +12 -6
- package/src/util/logger.ts +84 -15
- package/src/version.ts +1 -1
package/src/shell.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import figlet from 'figlet';
|
|
3
2
|
import inquirer from 'inquirer';
|
|
4
3
|
import inquirerPrompt from 'inquirer-command-prompt';
|
|
5
4
|
import commands from './commands';
|
|
6
5
|
import { LogMessages } from './localisation/en-GB';
|
|
7
|
-
import { logError, Logger } from './util/logger';
|
|
8
6
|
import CredentialProvider from './providers/CredentialProvider';
|
|
7
|
+
import { appRootDir } from './providers/file-provider';
|
|
9
8
|
import ContensisCli, { cliCommand } from './services/ContensisCliService';
|
|
10
9
|
import { Logging } from './util';
|
|
10
|
+
import { logError, Logger } from './util/logger';
|
|
11
|
+
import { LIB_VERSION } from './version';
|
|
11
12
|
|
|
12
13
|
class ContensisShell {
|
|
13
14
|
private currentEnvironment!: string;
|
|
@@ -39,12 +40,11 @@ class ContensisShell {
|
|
|
39
40
|
inquirerPrompt.setConfig({
|
|
40
41
|
history: {
|
|
41
42
|
save: true,
|
|
42
|
-
folder:
|
|
43
|
+
folder: appRootDir,
|
|
43
44
|
limit: 100,
|
|
44
45
|
blacklist: ['quit'],
|
|
45
46
|
},
|
|
46
47
|
});
|
|
47
|
-
// inquirer.registerPrompt('command', inquirerPrompt);
|
|
48
48
|
|
|
49
49
|
const { log, messages } = this;
|
|
50
50
|
|
|
@@ -64,7 +64,7 @@ class ContensisShell {
|
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
console.log(log.successText(data));
|
|
67
|
-
console.log(log.infoText(messages.app.startup()));
|
|
67
|
+
console.log(log.infoText(messages.app.startup(LIB_VERSION)));
|
|
68
68
|
console.log(log.helpText(messages.app.help()));
|
|
69
69
|
|
|
70
70
|
this.start().catch(ex => log.error(ex));
|
|
@@ -72,8 +72,13 @@ class ContensisShell {
|
|
|
72
72
|
);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
restart = async () => {
|
|
76
|
+
this.firstStart = false;
|
|
77
|
+
this.log.line(); // add a line so we can see where the shell has been restarted
|
|
78
|
+
await this.start();
|
|
79
|
+
};
|
|
80
|
+
|
|
75
81
|
start = async () => {
|
|
76
|
-
this.log.line();
|
|
77
82
|
this.refreshEnvironment();
|
|
78
83
|
this.userId = '';
|
|
79
84
|
const { currentEnvironment, env, log, messages } = this;
|
|
@@ -98,7 +103,10 @@ class ContensisShell {
|
|
|
98
103
|
silent: true,
|
|
99
104
|
}
|
|
100
105
|
);
|
|
101
|
-
if (token)
|
|
106
|
+
if (token) {
|
|
107
|
+
this.userId = env.lastUserId;
|
|
108
|
+
if (!env.currentProject) log.warning(messages.projects.tip());
|
|
109
|
+
}
|
|
102
110
|
this.firstStart = false;
|
|
103
111
|
this.refreshEnvironment();
|
|
104
112
|
} else {
|
|
@@ -127,14 +135,20 @@ class ContensisShell {
|
|
|
127
135
|
availableCommands.push('login', 'list projects', 'set project');
|
|
128
136
|
if (userId)
|
|
129
137
|
availableCommands.push(
|
|
138
|
+
'create project',
|
|
139
|
+
'diff models',
|
|
130
140
|
'get block',
|
|
131
141
|
'get block logs',
|
|
132
142
|
'get contenttype',
|
|
133
143
|
'get component',
|
|
134
144
|
'get entries',
|
|
145
|
+
'get model',
|
|
146
|
+
'get project',
|
|
147
|
+
'get version',
|
|
135
148
|
'import contenttypes',
|
|
136
149
|
'import components',
|
|
137
150
|
'import entries',
|
|
151
|
+
'import models',
|
|
138
152
|
'list blocks',
|
|
139
153
|
'list contenttypes',
|
|
140
154
|
'list components',
|
|
@@ -143,10 +157,13 @@ class ContensisShell {
|
|
|
143
157
|
'list webhooks',
|
|
144
158
|
'create key',
|
|
145
159
|
'push block',
|
|
160
|
+
'release block',
|
|
146
161
|
'remove key',
|
|
147
|
-
'remove
|
|
162
|
+
'remove entries',
|
|
148
163
|
'remove contenttypes',
|
|
149
|
-
'remove components'
|
|
164
|
+
'remove components',
|
|
165
|
+
'set project name',
|
|
166
|
+
'set project description'
|
|
150
167
|
);
|
|
151
168
|
|
|
152
169
|
const prompt = inquirer.createPromptModule();
|
|
@@ -168,7 +185,7 @@ class ContensisShell {
|
|
|
168
185
|
return true;
|
|
169
186
|
}
|
|
170
187
|
},
|
|
171
|
-
prefix: `${env?.currentProject || 'contensis'}`,
|
|
188
|
+
prefix: `${env?.currentProject || log.infoText('contensis')}`,
|
|
172
189
|
short: true,
|
|
173
190
|
},
|
|
174
191
|
])
|
|
@@ -221,7 +238,10 @@ class ContensisShell {
|
|
|
221
238
|
let globalShell: ContensisShell;
|
|
222
239
|
|
|
223
240
|
export const shell = () => {
|
|
224
|
-
|
|
241
|
+
// Return a benign function for shell().restart() when used in cli context
|
|
242
|
+
// as some commands need to restart the shell to show an updated prompt
|
|
243
|
+
// after successful connect / login / set project
|
|
244
|
+
if (typeof process.argv?.[2] !== 'undefined') return { restart() {} } as any;
|
|
225
245
|
if (!globalShell) globalShell = new ContensisShell();
|
|
226
246
|
return globalShell;
|
|
227
247
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
|
-
import { BlockVersion, MigrateStatus } from 'migratortron';
|
|
2
|
+
import { BlockVersion, MigrateModelsResult, MigrateStatus } from 'migratortron';
|
|
3
3
|
import ContensisCli from '~/services/ContensisCliService';
|
|
4
|
+
import { Logger } from './logger';
|
|
4
5
|
|
|
5
6
|
const formatDate = (date: Date | string, format = 'DD/MM/YYYY HH:mm') =>
|
|
6
7
|
dayjs(date).format(format);
|
|
@@ -106,17 +107,90 @@ export const printBlockVersion = (
|
|
|
106
107
|
export const printMigrateResult = (
|
|
107
108
|
{ log, messages, contensis, currentProject }: ContensisCli,
|
|
108
109
|
migrateResult: any,
|
|
109
|
-
{
|
|
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
|
+
} = {}
|
|
110
121
|
) => {
|
|
122
|
+
if (Object.keys(migrateResult.entriesToMigrate.entryIds).length)
|
|
123
|
+
console.log(``);
|
|
124
|
+
|
|
125
|
+
for (const [contentTypeId, entryRes] of Object.entries(
|
|
126
|
+
migrateResult.entriesToMigrate.entryIds
|
|
127
|
+
) as [string, any]) {
|
|
128
|
+
for (const [originalId, entryStatus] of Object.entries(entryRes) as [
|
|
129
|
+
string,
|
|
130
|
+
any
|
|
131
|
+
][]) {
|
|
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
|
+
);
|
|
159
|
+
|
|
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
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
111
178
|
console.log(``);
|
|
179
|
+
if (
|
|
180
|
+
contensis?.isPreview &&
|
|
181
|
+
migrateResult.entriesToMigrate?.[currentProject]?.totalCount > 0 &&
|
|
182
|
+
!migrateResult.errors
|
|
183
|
+
) {
|
|
184
|
+
log.help(messages.entries.commitTip());
|
|
185
|
+
}
|
|
112
186
|
|
|
113
187
|
if (action === 'import') {
|
|
114
188
|
for (const [projectId, contentTypeCounts] of Object.entries(
|
|
115
189
|
migrateResult.entries || {}
|
|
116
190
|
) as [string, any][]) {
|
|
117
|
-
|
|
191
|
+
log.help(
|
|
118
192
|
`import from project ${log.highlightText(projectId)} to ${log.boldText(
|
|
119
|
-
log.
|
|
193
|
+
log.warningText(currentProject)
|
|
120
194
|
)}`
|
|
121
195
|
);
|
|
122
196
|
for (const [contentTypeId, count] of Object.entries(
|
|
@@ -124,80 +198,174 @@ export const printMigrateResult = (
|
|
|
124
198
|
) as [string, number][]) {
|
|
125
199
|
const entriesToMigrate =
|
|
126
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);
|
|
215
|
+
|
|
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;
|
|
127
223
|
|
|
128
224
|
console.log(
|
|
129
225
|
` - ${
|
|
130
|
-
|
|
131
|
-
? log.
|
|
132
|
-
:
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
+
}`
|
|
146
250
|
);
|
|
147
251
|
}
|
|
148
|
-
console.log(``);
|
|
149
252
|
}
|
|
150
|
-
|
|
151
|
-
if (
|
|
152
|
-
contensis?.isPreview &&
|
|
153
|
-
migrateResult.entriesToMigrate?.[currentProject]?.totalCount > 0 &&
|
|
154
|
-
!migrateResult.errors
|
|
155
|
-
) {
|
|
156
|
-
log.help(messages.entries.commitTip());
|
|
157
|
-
}
|
|
158
|
-
for (const [contentTypeId, entryRes] of Object.entries(
|
|
159
|
-
migrateResult.entriesToMigrate.entryIds
|
|
160
|
-
) as [string, any]) {
|
|
161
|
-
for (const [originalId, entryStatus] of Object.entries(entryRes) as [
|
|
162
|
-
string,
|
|
163
|
-
any
|
|
164
|
-
][]) {
|
|
253
|
+
if (migrateResult.errors?.length) {
|
|
165
254
|
console.log(
|
|
166
|
-
log.
|
|
167
|
-
`${originalId} [${Object.entries(entryStatus || {})
|
|
168
|
-
.filter(x => x[0] !== 'entryTitle')
|
|
169
|
-
.map(([projectId, projectStatus]) => {
|
|
170
|
-
const [targetGuid, { status }] = (Object.entries(
|
|
171
|
-
projectStatus || {}
|
|
172
|
-
)?.[0] as [string, { status: MigrateStatus }]) || [
|
|
173
|
-
'',
|
|
174
|
-
{ x: { status: undefined } },
|
|
175
|
-
];
|
|
176
|
-
return `${messages.entries.migrateStatus(status)(
|
|
177
|
-
`${projectId}: ${status}`
|
|
178
|
-
)}${targetGuid !== originalId ? `-> ${targetGuid}` : ''}`;
|
|
179
|
-
})}]`
|
|
180
|
-
)
|
|
255
|
+
` - ${log.errorText(`errors: ${migrateResult.errors.length}`)}\n`
|
|
181
256
|
);
|
|
182
|
-
|
|
257
|
+
for (const error of migrateResult.errors)
|
|
258
|
+
log.error(error.message || error);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const highlightDiffText = (str: string) => {
|
|
264
|
+
const addedRegex = new RegExp(/<<\+>>(.*?)<<\/\+>>/, 'g');
|
|
265
|
+
const removedRegex = new RegExp(/<<->>(.*?)<<\/->>/, 'g');
|
|
266
|
+
return str
|
|
267
|
+
.replace(addedRegex, match => {
|
|
268
|
+
return Logger.successText(
|
|
269
|
+
match.replace(/<<\+>>/g, '<+>').replace(/<<\/\+>>/g, '</+>')
|
|
270
|
+
);
|
|
271
|
+
})
|
|
272
|
+
.replace(removedRegex, match => {
|
|
273
|
+
return Logger.errorText(
|
|
274
|
+
match.replace(/<<->>/g, '<->').replace(/<<\/->>/g, '</->')
|
|
275
|
+
);
|
|
276
|
+
});
|
|
277
|
+
};
|
|
183
278
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
279
|
+
export const printModelMigrationAnalysis = (
|
|
280
|
+
{ log, messages }: ContensisCli,
|
|
281
|
+
result: any = {}
|
|
282
|
+
) => {
|
|
283
|
+
for (const [contentTypeId, model] of Object.entries(result) as [
|
|
284
|
+
string,
|
|
285
|
+
any
|
|
286
|
+
][]) {
|
|
287
|
+
let mainOutput = log.standardText(` - ${contentTypeId}`);
|
|
288
|
+
let extraOutput = '';
|
|
289
|
+
let errorOutput = '';
|
|
290
|
+
let diffOutput = '';
|
|
291
|
+
for (const [key, details] of Object.entries(model) as [string, any][]) {
|
|
292
|
+
if (key === 'dependencies') {
|
|
293
|
+
extraOutput += log.infoText(
|
|
294
|
+
` references: [${details?.join(', ')}]\n`
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
if (key === 'dependencyOf') {
|
|
298
|
+
extraOutput += log.infoText(
|
|
299
|
+
` required by: [${details?.join(', ')}]\n`
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
if (key === 'projects') {
|
|
303
|
+
for (const [projectId, projectDetails] of Object.entries(details) as [
|
|
304
|
+
string,
|
|
305
|
+
any
|
|
306
|
+
][]) {
|
|
307
|
+
mainOutput += log.infoText(
|
|
308
|
+
` [${messages.migrate.status(projectDetails.status)(
|
|
309
|
+
`${projectId}: ${projectDetails.status}`
|
|
310
|
+
)}] v${projectDetails.versionNo}`
|
|
196
311
|
);
|
|
197
|
-
|
|
198
|
-
|
|
312
|
+
if (projectDetails.diff)
|
|
313
|
+
diffOutput += ` ${log.highlightText(`diff:`)} ${log.infoText(
|
|
314
|
+
highlightDiffText(projectDetails.diff)
|
|
315
|
+
)}\n`;
|
|
316
|
+
if (projectDetails.error)
|
|
317
|
+
errorOutput += ` ${log.highlightText(
|
|
318
|
+
`error::`
|
|
319
|
+
)} ${log.errorText(projectDetails.error)}`;
|
|
199
320
|
}
|
|
200
321
|
}
|
|
201
322
|
}
|
|
323
|
+
console.log(mainOutput);
|
|
324
|
+
if (extraOutput) {
|
|
325
|
+
const search = '\n';
|
|
326
|
+
const replace = '';
|
|
327
|
+
console.log(
|
|
328
|
+
extraOutput.replace(
|
|
329
|
+
new RegExp(search + '([^' + search + ']*)$'),
|
|
330
|
+
replace + '$1'
|
|
331
|
+
)
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
if (diffOutput) console.log(diffOutput);
|
|
335
|
+
if (errorOutput) console.log(errorOutput);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
type MigrateResultSummary = MigrateModelsResult['']['contentTypes'];
|
|
340
|
+
type MigrateResultStatus = keyof MigrateResultSummary;
|
|
341
|
+
|
|
342
|
+
export const printModelMigrationResult = (
|
|
343
|
+
{ log, messages }: ContensisCli,
|
|
344
|
+
result: MigrateResultSummary
|
|
345
|
+
) => {
|
|
346
|
+
for (const [status, ids] of Object.entries(result) as [
|
|
347
|
+
MigrateResultStatus,
|
|
348
|
+
string[]
|
|
349
|
+
][]) {
|
|
350
|
+
if (ids?.length) {
|
|
351
|
+
if (status === 'errors') {
|
|
352
|
+
const errors: [string, MappedError][] = ids as any;
|
|
353
|
+
log.raw(
|
|
354
|
+
` - ${status}: [ ${messages.migrate.models.result(status)(
|
|
355
|
+
ids.map(id => id[0]).join(', ')
|
|
356
|
+
)} ]\n`
|
|
357
|
+
);
|
|
358
|
+
for (const [contentTypeId, error] of errors)
|
|
359
|
+
log.error(
|
|
360
|
+
`${log.highlightText(contentTypeId)}: ${error.message}`,
|
|
361
|
+
error
|
|
362
|
+
);
|
|
363
|
+
} else
|
|
364
|
+
log.raw(
|
|
365
|
+
` - ${status}: [ ${messages.migrate.models.result(status)(
|
|
366
|
+
ids.join(', ')
|
|
367
|
+
)} ]`
|
|
368
|
+
);
|
|
369
|
+
}
|
|
202
370
|
}
|
|
203
371
|
};
|
package/src/util/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import mergeWith from 'lodash/mergeWith';
|
|
2
2
|
import { Logger } from './logger';
|
|
3
|
+
import { LogMessages as enGB } from '../localisation/en-GB.js';
|
|
3
4
|
|
|
4
5
|
export const isSharedSecret = (str = '') =>
|
|
5
6
|
str.length > 80 && str.split('-').length === 3 ? str : undefined;
|
|
@@ -50,12 +51,17 @@ export const url = (alias: string, project: string) => {
|
|
|
50
51
|
};
|
|
51
52
|
|
|
52
53
|
export const Logging = async (language = 'en-GB') => {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
const defaultMessages = enGB;
|
|
55
|
+
// const { LogMessages: defaultMessages } = await import(
|
|
56
|
+
// `../localisation/en-GB.js`
|
|
57
|
+
// );
|
|
58
|
+
let localisedMessages = defaultMessages;
|
|
59
|
+
|
|
60
|
+
if (language === 'en-GB') {
|
|
61
|
+
// Using a variable import e.g. `import(`../localisation/${language}.js`);`
|
|
62
|
+
// does not play well with packaged executables
|
|
63
|
+
// So we have to hard code the import for each language individually
|
|
64
|
+
}
|
|
59
65
|
return {
|
|
60
66
|
messages: mergeWith(
|
|
61
67
|
localisedMessages,
|
package/src/util/logger.ts
CHANGED
|
@@ -7,7 +7,8 @@ import { tryStringify } from '.';
|
|
|
7
7
|
|
|
8
8
|
type LogMethod = (content: string) => void;
|
|
9
9
|
type LogErrorMethod = (content: string, err?: any) => void;
|
|
10
|
-
type LogJsonMethod = (content: any) => void;
|
|
10
|
+
type LogJsonMethod = (content: any, depth?: number, indent?: string) => void;
|
|
11
|
+
type LogJsonDepthMethod = (content: any, depth: number) => void;
|
|
11
12
|
type LogArrayMethod = (contentArray: string[]) => void;
|
|
12
13
|
type LogErrorFunc = (
|
|
13
14
|
err: any,
|
|
@@ -83,7 +84,7 @@ export class Logger {
|
|
|
83
84
|
else console.log(message);
|
|
84
85
|
progress.current.interrupt(message);
|
|
85
86
|
};
|
|
86
|
-
static json:
|
|
87
|
+
static json: LogJsonDepthMethod = (content, depth = 9) =>
|
|
87
88
|
console.dir(deepCleaner(content), { colors: true, depth });
|
|
88
89
|
static mixed: LogArrayMethod = contentArray =>
|
|
89
90
|
console.log(`${Logger.getPrefix()} ${contentArray.join(' ')}`);
|
|
@@ -97,7 +98,38 @@ export class Logger {
|
|
|
97
98
|
if (key === 'fields' && Array.isArray(value)) {
|
|
98
99
|
for (const field of value || []) {
|
|
99
100
|
Logger.raw(
|
|
100
|
-
` ${chalk.bold(field.id)}
|
|
101
|
+
` ${chalk.bold(field.id)}${
|
|
102
|
+
field.id === content.entryTitleField
|
|
103
|
+
? '**'
|
|
104
|
+
: field.validations.minCount?.value ||
|
|
105
|
+
typeof field.validations.required?.message !== 'undefined'
|
|
106
|
+
? '*'
|
|
107
|
+
: ''
|
|
108
|
+
}: ${chalk.grey(
|
|
109
|
+
`${field.dataType}${
|
|
110
|
+
field.dataFormat
|
|
111
|
+
? `<${
|
|
112
|
+
Array.isArray(
|
|
113
|
+
field.validations.allowedFieldTypes?.fields
|
|
114
|
+
)
|
|
115
|
+
? `composer[${field.validations.allowedFieldTypes.fields
|
|
116
|
+
.map((f: any) => f.id)
|
|
117
|
+
.join(' | ')}]`
|
|
118
|
+
: field.dataFormat
|
|
119
|
+
}${
|
|
120
|
+
field.dataFormat === 'entry'
|
|
121
|
+
? `, ${field.validations.allowedContentTypes.contentTypes.join(
|
|
122
|
+
' | '
|
|
123
|
+
)}`
|
|
124
|
+
: ''
|
|
125
|
+
}>`
|
|
126
|
+
: ''
|
|
127
|
+
}${
|
|
128
|
+
field.validations.maxLength?.value
|
|
129
|
+
? `(${field.validations.maxLength.value})`
|
|
130
|
+
: ''
|
|
131
|
+
}`
|
|
132
|
+
)}`
|
|
101
133
|
);
|
|
102
134
|
}
|
|
103
135
|
} else if (key === 'groups' && Array.isArray(value)) {
|
|
@@ -114,22 +146,59 @@ export class Logger {
|
|
|
114
146
|
);
|
|
115
147
|
}
|
|
116
148
|
} else {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
149
|
+
Logger.objectRecurse(value, 3, ' ');
|
|
150
|
+
// for (const [innerkey, innervalue] of Object.entries(value)) {
|
|
151
|
+
// if (innervalue && typeof innervalue === 'object') {
|
|
152
|
+
// Logger.raw(` ${chalk.bold.grey(innerkey)}:`);
|
|
153
|
+
// console.table(innervalue);
|
|
154
|
+
// } else if (
|
|
155
|
+
// typeof innervalue !== 'undefined' &&
|
|
156
|
+
// innervalue !== null
|
|
157
|
+
// ) {
|
|
158
|
+
// Logger.raw(` ${chalk.bold.grey(innerkey)}: ${innervalue}`);
|
|
159
|
+
// }
|
|
160
|
+
// }
|
|
161
|
+
}
|
|
162
|
+
} else if (typeof value !== 'undefined' && value !== null) {
|
|
163
|
+
const valueText =
|
|
164
|
+
key === 'id' && typeof value === 'string'
|
|
165
|
+
? Logger.highlightText(value)
|
|
166
|
+
: value;
|
|
167
|
+
Logger.raw(` ${chalk.bold.grey(key)}: ${valueText}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
static objectRecurse: LogJsonMethod = (content, depth = 3, indent = '') => {
|
|
173
|
+
if (Array.isArray(content)) {
|
|
174
|
+
for (const item of content) {
|
|
175
|
+
if (item && typeof item === 'object') {
|
|
176
|
+
if (Array.isArray(item) && depth > 3)
|
|
177
|
+
Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));
|
|
178
|
+
else Logger.objectRecurse(item, depth + 1, `${indent} `);
|
|
179
|
+
} else Logger.raw(`${indent}${item}`);
|
|
180
|
+
}
|
|
181
|
+
} else
|
|
182
|
+
for (const [key, value] of Object.entries(content)) {
|
|
183
|
+
if (Array.isArray(value)) {
|
|
184
|
+
for (const item of value) {
|
|
185
|
+
if (item && typeof item === 'object') {
|
|
186
|
+
if (Array.isArray(item) && depth > 3)
|
|
187
|
+
Logger.raw(chalk.grey(`${indent} [${item.join(', ')}]`));
|
|
188
|
+
else Logger.objectRecurse(item, depth + 1, `${indent}`);
|
|
189
|
+
} else {
|
|
190
|
+
Logger.raw(`${indent} ${item}`);
|
|
126
191
|
}
|
|
127
192
|
}
|
|
193
|
+
} else if (value && typeof value === 'object') {
|
|
194
|
+
Logger.raw(`${indent}${chalk.bold.grey(key)}:`);
|
|
195
|
+
|
|
196
|
+
Logger.objectRecurse(value, depth + 1, `${indent} `);
|
|
197
|
+
// console.table(value);
|
|
198
|
+
} else if (typeof value !== 'undefined' && value !== null) {
|
|
199
|
+
Logger.raw(`${indent}${chalk.bold.grey(key)}: ${value}`);
|
|
128
200
|
}
|
|
129
|
-
} else if (typeof value !== 'undefined' || value !== null) {
|
|
130
|
-
Logger.raw(` ${chalk.bold.grey(key)}: ${value}`);
|
|
131
201
|
}
|
|
132
|
-
}
|
|
133
202
|
};
|
|
134
203
|
static raw: LogMethod = (content: string) => {
|
|
135
204
|
if (progress.active) progress.current.interrupt(content);
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = "1.0.0-beta.
|
|
1
|
+
export const LIB_VERSION = "1.0.0-beta.51";
|