contensis-cli 1.0.0-beta.9 → 1.0.0-beta.90
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 +1146 -78
- package/cli.js +3 -0
- package/dist/commands/connect.js +3 -3
- package/dist/commands/connect.js.map +2 -2
- package/dist/commands/create.js +45 -10
- package/dist/commands/create.js.map +2 -2
- package/dist/commands/dev.js +75 -0
- package/dist/commands/dev.js.map +7 -0
- package/dist/commands/diff.js +57 -0
- package/dist/commands/diff.js.map +7 -0
- package/dist/commands/execute.js +103 -0
- package/dist/commands/execute.js.map +7 -0
- package/dist/commands/get.js +169 -32
- package/dist/commands/get.js.map +3 -3
- package/dist/commands/globalOptions.js +37 -12
- package/dist/commands/globalOptions.js.map +2 -2
- package/dist/commands/import.js +47 -12
- package/dist/commands/import.js.map +2 -2
- package/dist/commands/index.js +22 -2
- package/dist/commands/index.js.map +2 -2
- package/dist/commands/list.js +53 -10
- package/dist/commands/list.js.map +2 -2
- package/dist/commands/login.js +2 -2
- package/dist/commands/login.js.map +2 -2
- package/dist/commands/push.js +17 -13
- package/dist/commands/push.js.map +2 -2
- package/dist/commands/remove.js +51 -8
- package/dist/commands/remove.js.map +2 -2
- package/dist/commands/set.js +139 -12
- package/dist/commands/set.js.map +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/dist/localisation/en-GB.js +259 -49
- package/dist/localisation/en-GB.js.map +2 -2
- package/dist/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.js +56 -0
- package/dist/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.js.map +7 -0
- package/dist/mappers/DevInit-to-CIWorkflow.js +127 -0
- package/dist/mappers/DevInit-to-CIWorkflow.js.map +7 -0
- package/dist/mappers/DevInit-to-RolePermissions.js +54 -0
- package/dist/mappers/DevInit-to-RolePermissions.js.map +7 -0
- package/dist/mappers/DevRequests-to-RequestHanderSiteConfigYaml.js +56 -0
- package/dist/mappers/DevRequests-to-RequestHanderSiteConfigYaml.js.map +7 -0
- package/dist/models/CliService.d.js +17 -0
- package/dist/models/CliService.d.js.map +7 -0
- package/dist/models/DevService.d.js +17 -0
- package/dist/models/DevService.d.js.map +7 -0
- package/dist/providers/CredentialProvider.js +46 -14
- 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 +12 -6
- package/dist/providers/file-provider.js.map +3 -3
- package/dist/services/ContensisCliService.js +1148 -421
- package/dist/services/ContensisCliService.js.map +3 -3
- package/dist/services/ContensisDevService.js +309 -0
- package/dist/services/ContensisDevService.js.map +7 -0
- package/dist/services/ContensisRoleService.js +87 -0
- package/dist/services/ContensisRoleService.js.map +7 -0
- package/dist/shell.js +58 -18
- package/dist/shell.js.map +3 -3
- package/dist/util/console.printer.js +171 -55
- package/dist/util/console.printer.js.map +2 -2
- package/dist/util/diff.js +102 -0
- package/dist/util/diff.js.map +7 -0
- package/dist/util/dotenv.js +57 -0
- package/dist/util/dotenv.js.map +7 -0
- package/dist/util/find.js +31 -0
- package/dist/util/find.js.map +7 -0
- package/dist/util/git.js +126 -0
- package/dist/util/git.js.map +7 -0
- package/dist/util/index.js +8 -2
- package/dist/util/index.js.map +3 -3
- package/dist/util/logger.js +90 -29
- package/dist/util/logger.js.map +3 -3
- package/dist/util/os.js +39 -0
- package/dist/util/os.js.map +7 -0
- package/dist/util/timers.js +49 -0
- package/dist/util/timers.js.map +7 -0
- package/dist/util/yaml.js +45 -0
- package/dist/util/yaml.js.map +7 -0
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/esbuild.config.js +3 -1
- package/package.json +12 -3
- package/src/commands/connect.ts +3 -2
- package/src/commands/create.ts +61 -8
- package/src/commands/dev.ts +69 -0
- package/src/commands/diff.ts +41 -0
- package/src/commands/execute.ts +117 -0
- package/src/commands/get.ts +242 -28
- package/src/commands/globalOptions.ts +42 -12
- package/src/commands/import.ts +58 -8
- package/src/commands/index.ts +22 -1
- package/src/commands/list.ts +85 -11
- package/src/commands/login.ts +2 -1
- package/src/commands/push.ts +18 -11
- package/src/commands/remove.ts +66 -4
- package/src/commands/set.ts +189 -9
- package/src/index.ts +1 -4
- package/src/localisation/en-GB.ts +374 -66
- package/src/mappers/ContensisCliService-to-RequestHanderSiteConfigYaml.ts +44 -0
- package/src/mappers/DevInit-to-CIWorkflow.ts +150 -0
- package/src/mappers/DevInit-to-RolePermissions.ts +33 -0
- package/src/mappers/DevRequests-to-RequestHanderSiteConfigYaml.ts +44 -0
- package/src/models/CliService.d.ts +36 -0
- package/src/models/DevService.d.ts +5 -0
- package/src/models/JsModules.d.ts +1 -0
- package/src/providers/CredentialProvider.ts +51 -18
- package/src/providers/SessionCacheProvider.ts +29 -2
- package/src/providers/file-provider.ts +17 -6
- package/src/services/ContensisCliService.ts +1458 -518
- package/src/services/ContensisDevService.ts +365 -0
- package/src/services/ContensisRoleService.ts +76 -0
- package/src/shell.ts +68 -18
- package/src/util/console.printer.ts +240 -78
- package/src/util/diff.ts +113 -0
- package/src/util/dotenv.ts +37 -0
- package/src/util/find.ts +8 -0
- package/src/util/git.ts +130 -0
- package/src/util/index.ts +16 -7
- package/src/util/logger.ts +145 -31
- package/src/util/os.ts +7 -0
- package/src/util/timers.ts +24 -0
- package/src/util/yaml.ts +13 -0
- package/src/version.ts +1 -1
|
@@ -28,52 +28,74 @@ __export(ContensisCliService_exports, {
|
|
|
28
28
|
default: () => ContensisCliService_default
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(ContensisCliService_exports);
|
|
31
|
+
var import_await_to_js = __toESM(require("await-to-js"));
|
|
32
|
+
var import_chalk = __toESM(require("chalk"));
|
|
31
33
|
var import_fs = __toESM(require("fs"));
|
|
32
|
-
var import_path = __toESM(require("path"));
|
|
33
|
-
var import_node_fetch = __toESM(require("node-fetch"));
|
|
34
34
|
var import_inquirer = __toESM(require("inquirer"));
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
35
|
+
var import_node_fetch = __toESM(require("node-fetch"));
|
|
36
|
+
var import_path = __toESM(require("path"));
|
|
37
|
+
var import_migratortron = require("migratortron");
|
|
38
38
|
var import_ContensisAuthService = __toESM(require("./ContensisAuthService"));
|
|
39
|
-
var import_CredentialProvider = __toESM(require("../providers/CredentialProvider"));
|
|
40
|
-
var import_logger = require("../util/logger");
|
|
41
39
|
var import_en_GB = require("../localisation/en-GB");
|
|
42
|
-
var
|
|
40
|
+
var import_file_provider = require("../providers/file-provider");
|
|
41
|
+
var import_SessionCacheProvider = __toESM(require("../providers/SessionCacheProvider"));
|
|
42
|
+
var import_CredentialProvider = __toESM(require("../providers/CredentialProvider"));
|
|
43
|
+
var import_util = require("../util");
|
|
44
|
+
var import_console = require("../util/console.printer");
|
|
43
45
|
var import_csv = require("../util/csv.formatter");
|
|
44
46
|
var import_xml = require("../util/xml.formatter");
|
|
45
47
|
var import_json = require("../util/json.formatter");
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
+
var import_diff = require("../util/diff");
|
|
49
|
+
var import_logger = require("../util/logger");
|
|
50
|
+
var import_timers = require("../util/timers");
|
|
51
|
+
var import_find = require("../util/find");
|
|
52
|
+
let insecurePasswordWarningShown = false;
|
|
48
53
|
class ContensisCli {
|
|
49
54
|
static quit = (error) => {
|
|
50
55
|
process.removeAllListeners("exit");
|
|
51
56
|
const exitCode = error ? 1 : 0;
|
|
52
|
-
console.info(`
|
|
53
|
-
Exiting contensis-cli with exit code: ${exitCode}
|
|
54
|
-
`);
|
|
55
57
|
process.exit(exitCode);
|
|
56
58
|
};
|
|
57
|
-
|
|
59
|
+
command;
|
|
60
|
+
format;
|
|
61
|
+
output;
|
|
62
|
+
session;
|
|
58
63
|
contensis;
|
|
59
64
|
contensisOpts;
|
|
60
|
-
contentTypes;
|
|
61
|
-
components;
|
|
62
|
-
currentEnv;
|
|
63
65
|
currentProject;
|
|
64
|
-
|
|
65
|
-
sourceEnv;
|
|
66
|
+
sourceAlias;
|
|
66
67
|
targetEnv;
|
|
67
68
|
urls;
|
|
68
|
-
command;
|
|
69
|
-
format;
|
|
70
|
-
output;
|
|
71
69
|
log = import_logger.Logger;
|
|
72
70
|
messages = import_en_GB.LogMessages;
|
|
73
|
-
session;
|
|
74
71
|
verb;
|
|
75
72
|
noun;
|
|
76
73
|
thirdArg;
|
|
74
|
+
get cache() {
|
|
75
|
+
return this.session.Get();
|
|
76
|
+
}
|
|
77
|
+
get currentEnv() {
|
|
78
|
+
return this.cache.currentEnvironment || "";
|
|
79
|
+
}
|
|
80
|
+
set currentEnv(currentEnvironment) {
|
|
81
|
+
this.session.Update({ currentEnvironment });
|
|
82
|
+
}
|
|
83
|
+
get env() {
|
|
84
|
+
const currentEnvironment = this.currentEnv;
|
|
85
|
+
const environments = this.cache.environments || {};
|
|
86
|
+
if (!currentEnvironment)
|
|
87
|
+
return {};
|
|
88
|
+
else if (!!environments[currentEnvironment])
|
|
89
|
+
return environments[currentEnvironment];
|
|
90
|
+
else {
|
|
91
|
+
return {
|
|
92
|
+
history: [],
|
|
93
|
+
lastUserId: "",
|
|
94
|
+
projects: [],
|
|
95
|
+
versionStatus: "latest"
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
77
99
|
constructor(args, outputOpts, contensisOpts = {}) {
|
|
78
100
|
const [exe, script, verb = "", noun = "", ...restArgs] = args;
|
|
79
101
|
this.verb = verb == null ? void 0 : verb.toLowerCase();
|
|
@@ -81,24 +103,12 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
81
103
|
this.thirdArg = restArgs == null ? void 0 : restArgs[0];
|
|
82
104
|
const commandText = `${this.verb} ${this.noun} ${restArgs ? restArgs.join(" ") : ""}`.trim();
|
|
83
105
|
this.session = new import_SessionCacheProvider.default();
|
|
84
|
-
this.cache = this.session.Get();
|
|
85
106
|
this.contensisOpts = contensisOpts;
|
|
86
107
|
this.format = outputOpts == null ? void 0 : outputOpts.format;
|
|
87
108
|
this.output = (outputOpts == null ? void 0 : outputOpts.output) && import_path.default.join(process.cwd(), outputOpts.output);
|
|
88
|
-
const currentEnvironment = (outputOpts == null ? void 0 : outputOpts.alias) || this.
|
|
109
|
+
const currentEnvironment = (outputOpts == null ? void 0 : outputOpts.alias) || this.currentEnv;
|
|
89
110
|
const environments = this.cache.environments || {};
|
|
90
|
-
|
|
91
|
-
this.env = {};
|
|
92
|
-
else if (!!environments[currentEnvironment])
|
|
93
|
-
this.env = environments[currentEnvironment];
|
|
94
|
-
else {
|
|
95
|
-
this.env = {
|
|
96
|
-
history: [],
|
|
97
|
-
lastUserId: "",
|
|
98
|
-
projects: [],
|
|
99
|
-
versionStatus: "latest"
|
|
100
|
-
};
|
|
101
|
-
}
|
|
111
|
+
this.currentEnv = currentEnvironment;
|
|
102
112
|
const env = this.env;
|
|
103
113
|
if (outputOpts == null ? void 0 : outputOpts.projectId)
|
|
104
114
|
env.currentProject = outputOpts.projectId;
|
|
@@ -110,9 +120,8 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
110
120
|
env.lastUserId = outputOpts.clientId;
|
|
111
121
|
if (outputOpts == null ? void 0 : outputOpts.sharedSecret)
|
|
112
122
|
env.passwordFallback = outputOpts.sharedSecret;
|
|
113
|
-
this.currentEnv = currentEnvironment;
|
|
114
123
|
this.currentProject = (env == null ? void 0 : env.currentProject) || "null";
|
|
115
|
-
this.
|
|
124
|
+
this.sourceAlias = (outputOpts == null ? void 0 : outputOpts.sourceAlias) || currentEnvironment;
|
|
116
125
|
if (currentEnvironment) {
|
|
117
126
|
this.urls = (0, import_util.url)(currentEnvironment, (env == null ? void 0 : env.currentProject) || "website");
|
|
118
127
|
}
|
|
@@ -124,7 +133,7 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
124
133
|
if (currentEnvironment) {
|
|
125
134
|
env.history = [this.command];
|
|
126
135
|
if (commandText) {
|
|
127
|
-
environments[currentEnvironment] =
|
|
136
|
+
environments[currentEnvironment] = env;
|
|
128
137
|
this.session.Update({
|
|
129
138
|
currentEnvironment,
|
|
130
139
|
environments,
|
|
@@ -149,34 +158,20 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
149
158
|
};
|
|
150
159
|
Connect = async (environment) => {
|
|
151
160
|
var _a;
|
|
152
|
-
const {
|
|
161
|
+
const { log, messages, session } = this;
|
|
153
162
|
if (environment) {
|
|
154
|
-
const envCache = cache.environments[environment];
|
|
155
|
-
if (!envCache)
|
|
156
|
-
cache.environments[environment] = {
|
|
157
|
-
versionStatus: "published",
|
|
158
|
-
history: [],
|
|
159
|
-
lastUserId: "",
|
|
160
|
-
projects: [],
|
|
161
|
-
...!this.currentEnv ? this.env : {}
|
|
162
|
-
};
|
|
163
|
-
this.env = cache.environments[environment];
|
|
164
163
|
this.currentEnv = environment;
|
|
165
164
|
this.urls = (0, import_util.url)(environment, "website");
|
|
166
165
|
const [fetchErr, response] = await (0, import_await_to_js.default)((0, import_node_fetch.default)(this.urls.cms));
|
|
167
166
|
if (response && (response == null ? void 0 : response.status) < 400) {
|
|
168
167
|
log.success(messages.connect.connected(environment));
|
|
168
|
+
session.UpdateEnv(this.env, environment);
|
|
169
169
|
if ((_a = this.env) == null ? void 0 : _a.lastUserId) {
|
|
170
|
-
await this.ConnectContensis();
|
|
171
170
|
await this.PrintProjects();
|
|
172
171
|
} else {
|
|
173
172
|
log.warning(messages.projects.noList());
|
|
174
173
|
log.help(messages.connect.tip());
|
|
175
174
|
}
|
|
176
|
-
session.Update({
|
|
177
|
-
currentEnvironment: environment,
|
|
178
|
-
environments: cache.environments
|
|
179
|
-
});
|
|
180
175
|
} else {
|
|
181
176
|
log.error(
|
|
182
177
|
messages.connect.unreachable(this.urls.cms, (response == null ? void 0 : response.status) || 0)
|
|
@@ -188,93 +183,80 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
188
183
|
};
|
|
189
184
|
ConnectContensis = async ({ commit = false } = {}) => {
|
|
190
185
|
var _a, _b, _c;
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
186
|
+
if (!this.contensis) {
|
|
187
|
+
const { contensisOpts, currentEnv, env, log, messages } = this;
|
|
188
|
+
const userId = env == null ? void 0 : env.lastUserId;
|
|
189
|
+
const isGuidId = userId && (0, import_util.isUuid)(userId);
|
|
190
|
+
if (currentEnv && userId) {
|
|
191
|
+
const credentials = await this.GetCredentials(
|
|
197
192
|
userId,
|
|
198
|
-
|
|
199
|
-
},
|
|
200
|
-
env.passwordFallback
|
|
201
|
-
).Init();
|
|
202
|
-
if (credentialError && !credentials.current) {
|
|
203
|
-
log.error(credentialError);
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
const cachedPassword = (_a = credentials == null ? void 0 : credentials.current) == null ? void 0 : _a.password;
|
|
207
|
-
if (cachedPassword) {
|
|
208
|
-
this.contensis = new import_migratortron.ContensisMigrationService(
|
|
209
|
-
{
|
|
210
|
-
...contensisOpts,
|
|
211
|
-
source: {
|
|
212
|
-
url: ((_b = this.urls) == null ? void 0 : _b.cms) || "",
|
|
213
|
-
username: !isGuidId ? userId : void 0,
|
|
214
|
-
password: !isGuidId ? cachedPassword : void 0,
|
|
215
|
-
clientId: isGuidId ? userId : void 0,
|
|
216
|
-
sharedSecret: isGuidId ? cachedPassword : void 0,
|
|
217
|
-
project: (env == null ? void 0 : env.currentProject) || "",
|
|
218
|
-
assetHostname: (_c = this.urls) == null ? void 0 : _c.previewWeb
|
|
219
|
-
},
|
|
220
|
-
concurrency: typeof contensisOpts.concurrency !== "undefined" ? contensisOpts.concurrency : 3,
|
|
221
|
-
outputProgress: true
|
|
222
|
-
},
|
|
223
|
-
!commit
|
|
193
|
+
env.passwordFallback
|
|
224
194
|
);
|
|
195
|
+
const cachedPassword = (_a = credentials == null ? void 0 : credentials.current) == null ? void 0 : _a.password;
|
|
196
|
+
if (cachedPassword) {
|
|
197
|
+
this.contensis = new import_migratortron.ContensisMigrationService(
|
|
198
|
+
{
|
|
199
|
+
...contensisOpts,
|
|
200
|
+
source: {
|
|
201
|
+
url: ((_b = this.urls) == null ? void 0 : _b.cms) || "",
|
|
202
|
+
username: !isGuidId ? userId : void 0,
|
|
203
|
+
password: !isGuidId ? cachedPassword : void 0,
|
|
204
|
+
clientId: isGuidId ? userId : void 0,
|
|
205
|
+
sharedSecret: isGuidId ? cachedPassword : void 0,
|
|
206
|
+
project: (env == null ? void 0 : env.currentProject) || "",
|
|
207
|
+
assetHostname: (_c = this.urls) == null ? void 0 : _c.previewWeb
|
|
208
|
+
},
|
|
209
|
+
concurrency: typeof contensisOpts.concurrency !== "undefined" ? contensisOpts.concurrency : 3,
|
|
210
|
+
outputProgress: true
|
|
211
|
+
},
|
|
212
|
+
!commit
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
if (!currentEnv)
|
|
217
|
+
log.help(messages.connect.help());
|
|
218
|
+
if (!userId)
|
|
219
|
+
log.help(messages.connect.tip());
|
|
225
220
|
}
|
|
226
|
-
} else {
|
|
227
|
-
if (!currentEnv)
|
|
228
|
-
log.help(messages.connect.help());
|
|
229
|
-
if (!userId)
|
|
230
|
-
log.help(messages.connect.tip());
|
|
231
221
|
}
|
|
222
|
+
return this.contensis;
|
|
232
223
|
};
|
|
233
224
|
ConnectContensisImport = async ({
|
|
234
|
-
commit,
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
fileDataType
|
|
225
|
+
commit = false,
|
|
226
|
+
fromFile,
|
|
227
|
+
importDataType
|
|
238
228
|
}) => {
|
|
239
229
|
var _a, _b, _c, _d, _e, _f;
|
|
240
|
-
const
|
|
230
|
+
const source = fromFile ? "file" : "contensis";
|
|
231
|
+
const fileData = fromFile ? (0, import_file_provider.readJsonFile)(fromFile) || [] : [];
|
|
232
|
+
if (typeof fileData === "string")
|
|
233
|
+
throw new Error(`Import file format must be of type JSON`);
|
|
234
|
+
const { contensisOpts, currentEnv, env, log, messages, sourceAlias } = this;
|
|
241
235
|
const environments = this.cache.environments || {};
|
|
242
|
-
const sourceEnvironment = environments[
|
|
236
|
+
const sourceEnvironment = environments[sourceAlias || ""] || {};
|
|
243
237
|
const sourceCms = "source" in contensisOpts && contensisOpts.source || {};
|
|
244
238
|
const sourceUserId = sourceCms.clientId || sourceCms.username || sourceEnvironment.lastUserId;
|
|
245
239
|
const sourceProjectId = sourceCms.project || sourceEnvironment.currentProject || "website";
|
|
246
240
|
const isSourceGuidId = sourceUserId && (0, import_util.isUuid)(sourceUserId);
|
|
247
|
-
const sourceUrls = (0, import_util.url)(
|
|
241
|
+
const sourceUrls = (0, import_util.url)(sourceAlias || "", sourceProjectId);
|
|
248
242
|
const sourcePassword = sourceCms.sharedSecret || sourceCms.password || sourceEnvironment.passwordFallback;
|
|
249
243
|
const targetUserId = env == null ? void 0 : env.lastUserId;
|
|
250
244
|
const isTargetGuidId = targetUserId && (0, import_util.isUuid)(targetUserId);
|
|
251
245
|
if (sourceUserId && currentEnv && targetUserId) {
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
).Init();
|
|
259
|
-
if (sourceCredentialError && !sourceCredentials.current) {
|
|
260
|
-
(0, import_logger.logError)(sourceCredentialError);
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
246
|
+
const sourceCredentials = await this.GetCredentials(
|
|
247
|
+
sourceUserId,
|
|
248
|
+
sourcePassword,
|
|
249
|
+
sourceAlias,
|
|
250
|
+
false
|
|
251
|
+
);
|
|
263
252
|
const cachedSourcePassword = (_a = sourceCredentials == null ? void 0 : sourceCredentials.current) == null ? void 0 : _a.password;
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
userId: targetUserId,
|
|
267
|
-
alias: currentEnv
|
|
268
|
-
},
|
|
253
|
+
const targetCredentials = await this.GetCredentials(
|
|
254
|
+
targetUserId,
|
|
269
255
|
env.passwordFallback
|
|
270
|
-
)
|
|
271
|
-
if (targetCredentialError && !targetCredentials.current) {
|
|
272
|
-
log.error(targetCredentialError);
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
256
|
+
);
|
|
275
257
|
const cachedTargetPassword = (_b = targetCredentials == null ? void 0 : targetCredentials.current) == null ? void 0 : _b.password;
|
|
276
258
|
if (cachedSourcePassword && cachedTargetPassword) {
|
|
277
|
-
if (source === "file" ||
|
|
259
|
+
if (source === "file" || importDataType === "user-input") {
|
|
278
260
|
this.contensis = new import_migratortron.ContensisMigrationService(
|
|
279
261
|
{
|
|
280
262
|
concurrency: 3,
|
|
@@ -289,12 +271,11 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
289
271
|
targetProjects: [env.currentProject || ""],
|
|
290
272
|
assetHostname: (_d = this.urls) == null ? void 0 : _d.previewWeb
|
|
291
273
|
},
|
|
292
|
-
...
|
|
274
|
+
...importDataType ? { [importDataType]: fileData } : {}
|
|
293
275
|
},
|
|
294
276
|
!commit
|
|
295
277
|
);
|
|
296
|
-
}
|
|
297
|
-
if (source === "contensis") {
|
|
278
|
+
} else if (source === "contensis") {
|
|
298
279
|
this.contensis = new import_migratortron.ContensisMigrationService(
|
|
299
280
|
{
|
|
300
281
|
concurrency: 3,
|
|
@@ -329,82 +310,104 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
329
310
|
if (!targetUserId)
|
|
330
311
|
log.help(messages.connect.tip());
|
|
331
312
|
}
|
|
313
|
+
return this.contensis;
|
|
314
|
+
};
|
|
315
|
+
GetCredentials = async (userId, password, currentEnv = this.currentEnv, saveCurrentEnv = true) => {
|
|
316
|
+
const { log, messages } = this;
|
|
317
|
+
if (userId) {
|
|
318
|
+
const [credentialError, credentials] = await new import_CredentialProvider.default(
|
|
319
|
+
{ userId, alias: currentEnv },
|
|
320
|
+
password
|
|
321
|
+
).Init();
|
|
322
|
+
if (credentialError && !credentials.current) {
|
|
323
|
+
log.error(credentialError);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
if (credentials.remarks.secure !== true) {
|
|
327
|
+
if (!insecurePasswordWarningShown) {
|
|
328
|
+
log.warning(messages.login.insecurePassword());
|
|
329
|
+
insecurePasswordWarningShown = true;
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
const env = this.cache.environments[currentEnv];
|
|
333
|
+
env.passwordFallback = void 0;
|
|
334
|
+
this.session.UpdateEnv(env, currentEnv, saveCurrentEnv);
|
|
335
|
+
}
|
|
336
|
+
return credentials;
|
|
337
|
+
}
|
|
332
338
|
};
|
|
333
339
|
Login = async (userId, {
|
|
334
340
|
password = (0, import_util.isPassword)(this.env.passwordFallback),
|
|
335
341
|
promptPassword = true,
|
|
336
342
|
sharedSecret = (0, import_util.isSharedSecret)(this.env.passwordFallback),
|
|
337
|
-
silent = false
|
|
338
|
-
|
|
343
|
+
silent = false,
|
|
344
|
+
attempt = 1
|
|
345
|
+
} = {}) => {
|
|
339
346
|
var _a, _b, _c, _d;
|
|
340
|
-
let inputPassword = password;
|
|
347
|
+
let inputPassword = password || sharedSecret;
|
|
341
348
|
const { log, messages } = this;
|
|
342
349
|
if (userId) {
|
|
343
|
-
const {
|
|
350
|
+
const { currentEnv, env } = this;
|
|
344
351
|
if (currentEnv) {
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
return await this.Login(userId, { password, sharedSecret });
|
|
398
|
-
} else {
|
|
399
|
-
throw new Error(messages.login.failed(currentEnv, userId));
|
|
352
|
+
const credentials = await this.GetCredentials(userId, inputPassword);
|
|
353
|
+
if (credentials) {
|
|
354
|
+
const cachedPassword = (0, import_util.isPassword)((_a = credentials.current) == null ? void 0 : _a.password);
|
|
355
|
+
const cachedSecret = (0, import_util.isSharedSecret)((_b = credentials.current) == null ? void 0 : _b.password);
|
|
356
|
+
if (!cachedPassword && !cachedSecret && promptPassword) {
|
|
357
|
+
({ inputPassword } = await import_inquirer.default.prompt([
|
|
358
|
+
{
|
|
359
|
+
type: "password",
|
|
360
|
+
message: messages.login.passwordPrompt(currentEnv, userId),
|
|
361
|
+
name: "inputPassword",
|
|
362
|
+
mask: "*",
|
|
363
|
+
prefix: void 0
|
|
364
|
+
}
|
|
365
|
+
]));
|
|
366
|
+
}
|
|
367
|
+
if (inputPassword || cachedPassword || cachedSecret) {
|
|
368
|
+
const authService = new import_ContensisAuthService.default({
|
|
369
|
+
username: userId,
|
|
370
|
+
password: inputPassword || cachedPassword,
|
|
371
|
+
projectId: (env == null ? void 0 : env.currentProject) || "website",
|
|
372
|
+
rootUrl: ((_c = this.urls) == null ? void 0 : _c.cms) || "",
|
|
373
|
+
clientId: userId,
|
|
374
|
+
clientSecret: sharedSecret || cachedSecret
|
|
375
|
+
});
|
|
376
|
+
const [authError, bearerToken] = await (0, import_await_to_js.default)(
|
|
377
|
+
authService.BearerToken()
|
|
378
|
+
);
|
|
379
|
+
if (bearerToken) {
|
|
380
|
+
env.authToken = bearerToken;
|
|
381
|
+
env.lastUserId = userId;
|
|
382
|
+
env.passwordFallback = credentials.remarks.secure !== true ? (_d = credentials.current) == null ? void 0 : _d.password : void 0;
|
|
383
|
+
this.session.UpdateEnv(env);
|
|
384
|
+
if (inputPassword)
|
|
385
|
+
await credentials.Save(inputPassword);
|
|
386
|
+
if (sharedSecret)
|
|
387
|
+
await credentials.Save(sharedSecret);
|
|
388
|
+
if (!silent) {
|
|
389
|
+
import_logger.Logger.success(messages.login.success(currentEnv, userId));
|
|
390
|
+
await this.PrintProjects();
|
|
391
|
+
}
|
|
392
|
+
} else if (authError) {
|
|
393
|
+
import_logger.Logger.error(authError.toString());
|
|
394
|
+
env.authToken = "";
|
|
395
|
+
env.lastUserId = "";
|
|
396
|
+
env.passwordFallback = void 0;
|
|
397
|
+
this.session.UpdateEnv(env);
|
|
398
|
+
if ((cachedPassword || cachedSecret) && credentials.remarks.secure) {
|
|
399
|
+
await credentials.Delete();
|
|
400
|
+
return await this.Login(userId, { password, sharedSecret });
|
|
401
|
+
} else {
|
|
402
|
+
throw new Error(messages.login.failed(currentEnv, userId));
|
|
403
|
+
}
|
|
400
404
|
}
|
|
405
|
+
return env.authToken;
|
|
406
|
+
} else {
|
|
407
|
+
import_logger.Logger.error(messages.login.passwordPrompt());
|
|
408
|
+
if (attempt < 2)
|
|
409
|
+
return await this.Login(userId, { attempt: attempt + 1 });
|
|
401
410
|
}
|
|
402
|
-
this.session.Update({
|
|
403
|
-
environments: cache.environments
|
|
404
|
-
});
|
|
405
|
-
return env.authToken;
|
|
406
|
-
} else {
|
|
407
|
-
import_logger.Logger.error(messages.login.passwordPrompt(currentEnv, userId));
|
|
408
411
|
}
|
|
409
412
|
} else {
|
|
410
413
|
import_logger.Logger.error(messages.login.noEnv());
|
|
@@ -413,37 +416,100 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
413
416
|
import_logger.Logger.error(messages.login.noUserId());
|
|
414
417
|
}
|
|
415
418
|
};
|
|
419
|
+
PrintContensisVersion = async () => {
|
|
420
|
+
const { log, messages } = this;
|
|
421
|
+
const contensis = await this.ConnectContensis();
|
|
422
|
+
if (contensis) {
|
|
423
|
+
const [projectsErr, projects] = await (0, import_await_to_js.default)(
|
|
424
|
+
contensis.projects.GetSourceProjects()
|
|
425
|
+
);
|
|
426
|
+
if (Array.isArray(projects)) {
|
|
427
|
+
this.HandleFormattingAndOutput(
|
|
428
|
+
contensis.contensisVersion,
|
|
429
|
+
() => log.raw(log.highlightText(contensis.contensisVersion))
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
if (projectsErr) {
|
|
433
|
+
log.error(messages.projects.noList());
|
|
434
|
+
log.error(projectsErr.message);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
PrintBearerToken = async () => {
|
|
439
|
+
const { log, messages } = this;
|
|
440
|
+
const contensis = await this.ConnectContensis();
|
|
441
|
+
if (contensis) {
|
|
442
|
+
const [error, token] = await (0, import_await_to_js.default)(
|
|
443
|
+
contensis.content.sourceRepo.repo.BearerToken()
|
|
444
|
+
);
|
|
445
|
+
if (token) {
|
|
446
|
+
this.HandleFormattingAndOutput(
|
|
447
|
+
token,
|
|
448
|
+
() => log.raw(log.highlightText(token))
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
if (error) {
|
|
452
|
+
log.error(messages.projects.noList());
|
|
453
|
+
log.error(error.message);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
};
|
|
416
457
|
PrintProjects = async () => {
|
|
417
|
-
const {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
if (this.contensis) {
|
|
458
|
+
const { currentProject, log, messages, session } = this;
|
|
459
|
+
const contensis = await this.ConnectContensis();
|
|
460
|
+
if (contensis) {
|
|
421
461
|
const [projectsErr, projects] = await (0, import_await_to_js.default)(
|
|
422
|
-
|
|
462
|
+
contensis.projects.GetSourceProjects()
|
|
423
463
|
);
|
|
424
464
|
if (Array.isArray(projects)) {
|
|
425
|
-
const currentVals = cache.environments[currentEnv] || {};
|
|
426
465
|
const nextCurrentProject = currentProject && currentProject !== "null" ? currentProject : projects.some((p) => p.id === "website") ? "website" : void 0;
|
|
427
|
-
|
|
428
|
-
...currentVals,
|
|
466
|
+
session.UpdateEnv({
|
|
429
467
|
projects: projects.map((p) => p.id),
|
|
430
468
|
currentProject: nextCurrentProject
|
|
431
|
-
};
|
|
469
|
+
});
|
|
432
470
|
log.success(messages.projects.list());
|
|
471
|
+
log.raw("");
|
|
433
472
|
this.HandleFormattingAndOutput(projects, () => {
|
|
434
|
-
for (const project of projects
|
|
473
|
+
for (const project of projects.sort(
|
|
474
|
+
(a, b) => a.id.localeCompare(b.id)
|
|
475
|
+
)) {
|
|
476
|
+
let color;
|
|
477
|
+
try {
|
|
478
|
+
color = import_chalk.default.keyword(project.color);
|
|
479
|
+
} catch (ex) {
|
|
480
|
+
color = import_chalk.default.white;
|
|
481
|
+
}
|
|
435
482
|
console.log(
|
|
436
|
-
|
|
483
|
+
`${nextCurrentProject === project.id ? `>> ${log.boldText(color(project.id))}` : ` ${color(project.id)}`} ${log.infoText(
|
|
484
|
+
`[${project.supportedLanguages.map(
|
|
485
|
+
(l) => l === project.primaryLanguage ? `*${log.boldText(l)}` : l
|
|
486
|
+
).join(" ")}]`
|
|
487
|
+
)}`
|
|
437
488
|
);
|
|
438
489
|
}
|
|
439
490
|
});
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
491
|
+
if (!this.SetProject(nextCurrentProject))
|
|
492
|
+
log.warning(messages.projects.tip());
|
|
493
|
+
}
|
|
494
|
+
if (projectsErr) {
|
|
495
|
+
log.error(messages.projects.noList());
|
|
496
|
+
log.error(projectsErr.message);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
};
|
|
500
|
+
PrintProject = async (projectId = this.currentProject) => {
|
|
501
|
+
const { log, messages, session } = this;
|
|
502
|
+
const contensis = await this.ConnectContensis();
|
|
503
|
+
if (contensis) {
|
|
504
|
+
const [projectsErr, projects] = await (0, import_await_to_js.default)(
|
|
505
|
+
contensis.projects.GetSourceProjects()
|
|
506
|
+
);
|
|
507
|
+
const foundProject = projects == null ? void 0 : projects.find(
|
|
508
|
+
(p) => p.id.toLowerCase() === projectId.toLowerCase()
|
|
509
|
+
);
|
|
510
|
+
if (foundProject) {
|
|
511
|
+
log.raw("");
|
|
512
|
+
this.HandleFormattingAndOutput(foundProject, log.object);
|
|
447
513
|
}
|
|
448
514
|
if (projectsErr) {
|
|
449
515
|
log.error(messages.projects.noList());
|
|
@@ -451,8 +517,8 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
451
517
|
}
|
|
452
518
|
}
|
|
453
519
|
};
|
|
454
|
-
SetProject =
|
|
455
|
-
const {
|
|
520
|
+
SetProject = (projectId = "website") => {
|
|
521
|
+
const { env, log, messages, session } = this;
|
|
456
522
|
let nextProjectId;
|
|
457
523
|
if ((env == null ? void 0 : env.projects.length) > 0 && (env == null ? void 0 : env.lastUserId)) {
|
|
458
524
|
nextProjectId = env.projects.find(
|
|
@@ -460,10 +526,9 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
460
526
|
);
|
|
461
527
|
if (nextProjectId) {
|
|
462
528
|
env.currentProject = nextProjectId;
|
|
463
|
-
session.
|
|
464
|
-
environments: cache.environments
|
|
465
|
-
});
|
|
529
|
+
session.UpdateEnv(env);
|
|
466
530
|
log.success(messages.projects.set(projectId));
|
|
531
|
+
log.raw("");
|
|
467
532
|
} else {
|
|
468
533
|
log.error(messages.projects.failedSet(projectId));
|
|
469
534
|
}
|
|
@@ -473,8 +538,8 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
473
538
|
}
|
|
474
539
|
return nextProjectId;
|
|
475
540
|
};
|
|
476
|
-
SetVersion =
|
|
477
|
-
const {
|
|
541
|
+
SetVersion = (versionStatus) => {
|
|
542
|
+
const { env, log, messages, session } = this;
|
|
478
543
|
if (!["latest", "published"].includes(versionStatus)) {
|
|
479
544
|
log.error(messages.version.invalid(versionStatus));
|
|
480
545
|
return false;
|
|
@@ -484,10 +549,7 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
484
549
|
return false;
|
|
485
550
|
}
|
|
486
551
|
if ((env == null ? void 0 : env.projects.length) > 0 && (env == null ? void 0 : env.lastUserId)) {
|
|
487
|
-
|
|
488
|
-
session.Update({
|
|
489
|
-
environments: cache.environments
|
|
490
|
-
});
|
|
552
|
+
session.UpdateEnv({ versionStatus });
|
|
491
553
|
log.success(messages.version.set(this.currentEnv, versionStatus));
|
|
492
554
|
return true;
|
|
493
555
|
} else {
|
|
@@ -496,26 +558,11 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
496
558
|
return false;
|
|
497
559
|
}
|
|
498
560
|
};
|
|
499
|
-
HydrateContensis = async () => {
|
|
500
|
-
const { log } = this;
|
|
501
|
-
if (!this.contensis)
|
|
502
|
-
await this.ConnectContensis();
|
|
503
|
-
if (this.contensis) {
|
|
504
|
-
const [contensisErr, models] = await (0, import_await_to_js.default)(
|
|
505
|
-
this.contensis.models.HydrateContensisRepositories()
|
|
506
|
-
);
|
|
507
|
-
if (contensisErr) {
|
|
508
|
-
log.error(contensisErr.message);
|
|
509
|
-
return contensisErr;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
};
|
|
513
561
|
PrintApiKeys = async () => {
|
|
514
562
|
const { currentEnv, log, messages } = this;
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
const [keysErr, apiKeys] = await this.contensis.apiKeys.GetKeys();
|
|
563
|
+
const contensis = await this.ConnectContensis();
|
|
564
|
+
if (contensis) {
|
|
565
|
+
const [keysErr, apiKeys] = await contensis.apiKeys.GetKeys();
|
|
519
566
|
if (Array.isArray(apiKeys)) {
|
|
520
567
|
log.success(messages.keys.list(currentEnv));
|
|
521
568
|
this.HandleFormattingAndOutput(apiKeys, () => {
|
|
@@ -543,22 +590,23 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
543
590
|
};
|
|
544
591
|
CreateApiKey = async (name, description) => {
|
|
545
592
|
const { currentEnv, log, messages } = this;
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
const [err, key] = await this.contensis.apiKeys.CreateKey(
|
|
550
|
-
name,
|
|
551
|
-
description
|
|
552
|
-
);
|
|
593
|
+
const contensis = await this.ConnectContensis();
|
|
594
|
+
if (contensis) {
|
|
595
|
+
const [err, key] = await contensis.apiKeys.CreateKey(name, description);
|
|
553
596
|
if (key) {
|
|
554
597
|
log.success(messages.keys.created(currentEnv, name));
|
|
555
598
|
console.log(
|
|
556
|
-
` - ${
|
|
599
|
+
` - ${import_chalk.default.bold(key.name)} [${key.dateModified.toString().substring(0, 10)} ${key.modifiedBy}]`
|
|
600
|
+
);
|
|
601
|
+
if (key.description)
|
|
602
|
+
console.log(` ${log.infoText(key.description)}`);
|
|
603
|
+
console.log(` ${import_chalk.default.bold.grey`id`}: ${key.id}`);
|
|
604
|
+
console.log(
|
|
605
|
+
` ${import_chalk.default.bold.grey`sharedSecret`}: ${key.sharedSecret}`
|
|
557
606
|
);
|
|
558
|
-
console.log(
|
|
559
|
-
|
|
607
|
+
console.log("");
|
|
608
|
+
log.help(messages.keys.tip());
|
|
560
609
|
}
|
|
561
|
-
console.log("");
|
|
562
610
|
if (err) {
|
|
563
611
|
log.error(messages.keys.failedCreate(currentEnv, name), err);
|
|
564
612
|
}
|
|
@@ -566,10 +614,9 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
566
614
|
};
|
|
567
615
|
RemoveApiKey = async (id) => {
|
|
568
616
|
const { currentEnv, log, messages } = this;
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
const [err, key] = await this.contensis.apiKeys.RemoveKey(id);
|
|
617
|
+
const contensis = await this.ConnectContensis({ commit: true });
|
|
618
|
+
if (contensis) {
|
|
619
|
+
const [err, key] = await contensis.apiKeys.RemoveKey(id);
|
|
573
620
|
if (!err) {
|
|
574
621
|
log.success(messages.keys.removed(currentEnv, id));
|
|
575
622
|
console.log("");
|
|
@@ -578,25 +625,348 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
578
625
|
}
|
|
579
626
|
}
|
|
580
627
|
};
|
|
581
|
-
|
|
628
|
+
PrintRoles = async () => {
|
|
629
|
+
const { currentEnv, log, messages } = this;
|
|
630
|
+
const contensis = await this.ConnectContensis();
|
|
631
|
+
if (contensis) {
|
|
632
|
+
const [rolesErr, roles] = await (0, import_await_to_js.default)(contensis.roles.GetRoles());
|
|
633
|
+
if (Array.isArray(roles)) {
|
|
634
|
+
log.success(messages.roles.list(currentEnv));
|
|
635
|
+
if (!roles.length)
|
|
636
|
+
log.help(messages.roles.noneExist());
|
|
637
|
+
this.HandleFormattingAndOutput(roles, () => {
|
|
638
|
+
var _a, _b, _c, _d, _e;
|
|
639
|
+
for (const {
|
|
640
|
+
id,
|
|
641
|
+
name,
|
|
642
|
+
description,
|
|
643
|
+
enabled,
|
|
644
|
+
assignments,
|
|
645
|
+
permissions
|
|
646
|
+
} of roles) {
|
|
647
|
+
const color = enabled ? (s) => s : log.infoText;
|
|
648
|
+
console.log(color(` - ${import_chalk.default.bold(name)} ${log.infoText(id)}`));
|
|
649
|
+
if (description)
|
|
650
|
+
console.log(log.infoText(` ${description}`));
|
|
651
|
+
if (enabled === false)
|
|
652
|
+
console.log(` ${import_chalk.default.bold.grey("enabled")}: false`);
|
|
653
|
+
if ((_a = assignments.groups) == null ? void 0 : _a.length)
|
|
654
|
+
console.log(
|
|
655
|
+
` ${import_chalk.default.bold.grey("groups")}: ${assignments.groups.join(
|
|
656
|
+
", "
|
|
657
|
+
)}`
|
|
658
|
+
);
|
|
659
|
+
if ((_b = assignments.users) == null ? void 0 : _b.length)
|
|
660
|
+
console.log(
|
|
661
|
+
` ${import_chalk.default.bold.grey("users")}: ${assignments.users.join(
|
|
662
|
+
", "
|
|
663
|
+
)}`
|
|
664
|
+
);
|
|
665
|
+
if ((_c = assignments.apiKeys) == null ? void 0 : _c.length)
|
|
666
|
+
console.log(
|
|
667
|
+
` ${import_chalk.default.bold.grey("keys")}: ${assignments.apiKeys.join(
|
|
668
|
+
", "
|
|
669
|
+
)}`
|
|
670
|
+
);
|
|
671
|
+
if ((_d = permissions.entries) == null ? void 0 : _d.length) {
|
|
672
|
+
console.log(` ${import_chalk.default.bold.grey("entries")}:`);
|
|
673
|
+
for (const p of permissions.entries)
|
|
674
|
+
console.log(
|
|
675
|
+
` ${p.id}: ${log.infoText(
|
|
676
|
+
p.actions.length > 2 ? p.actions.length : p.actions.join(", ")
|
|
677
|
+
)}`
|
|
678
|
+
);
|
|
679
|
+
}
|
|
680
|
+
if ((_e = permissions.contentTypes) == null ? void 0 : _e.length)
|
|
681
|
+
console.log(
|
|
682
|
+
` ${import_chalk.default.bold.grey(
|
|
683
|
+
"contentTypes"
|
|
684
|
+
)}: ${permissions.contentTypes.map(
|
|
685
|
+
(p) => `${p.id} [${p.actions.join(",")}] ${p.languages.join(
|
|
686
|
+
" "
|
|
687
|
+
)}`
|
|
688
|
+
).join(", ")}`
|
|
689
|
+
);
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
if (rolesErr) {
|
|
694
|
+
log.error(messages.roles.noList(currentEnv));
|
|
695
|
+
log.error((0, import_json.jsonFormatter)(rolesErr));
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
PrintRole = async (roleNameOrId) => {
|
|
700
|
+
const { currentEnv, log, messages } = this;
|
|
701
|
+
const contensis = await this.ConnectContensis();
|
|
702
|
+
if (contensis) {
|
|
703
|
+
const [rolesErr, roles] = await (0, import_await_to_js.default)(contensis.roles.GetRoles());
|
|
704
|
+
if (Array.isArray(roles)) {
|
|
705
|
+
log.success(messages.roles.list(currentEnv));
|
|
706
|
+
const role = (0, import_find.findByIdOrName)(roles, roleNameOrId);
|
|
707
|
+
if (role)
|
|
708
|
+
this.HandleFormattingAndOutput(role, log.object);
|
|
709
|
+
else
|
|
710
|
+
log.error(messages.roles.failedGet(currentEnv, roleNameOrId));
|
|
711
|
+
}
|
|
712
|
+
if (rolesErr) {
|
|
713
|
+
log.error(messages.roles.noList(currentEnv));
|
|
714
|
+
log.error((0, import_json.jsonFormatter)(rolesErr));
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
CreateRole = async (role) => {
|
|
719
|
+
const { currentEnv, log, messages } = this;
|
|
720
|
+
const contensis = await this.ConnectContensis();
|
|
721
|
+
if (contensis) {
|
|
722
|
+
const [err, created] = await contensis.roles.CreateRole(role);
|
|
723
|
+
if (created) {
|
|
724
|
+
log.success(
|
|
725
|
+
messages.roles.created(currentEnv, role.id || role.name || "")
|
|
726
|
+
);
|
|
727
|
+
this.HandleFormattingAndOutput(created, log.object);
|
|
728
|
+
log.help(messages.roles.tip());
|
|
729
|
+
return role.id;
|
|
730
|
+
}
|
|
731
|
+
if (err) {
|
|
732
|
+
log.error(
|
|
733
|
+
messages.roles.failedCreate(currentEnv, role.id || role.name || ""),
|
|
734
|
+
err
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
UpdateRole = async (roleNameOrId, role) => {
|
|
740
|
+
const { currentEnv, log, messages } = this;
|
|
741
|
+
const contensis = await this.ConnectContensis();
|
|
742
|
+
if (contensis) {
|
|
743
|
+
const [rolesErr, roles] = await (0, import_await_to_js.default)(contensis.roles.GetRoles());
|
|
744
|
+
if (Array.isArray(roles)) {
|
|
745
|
+
log.success(messages.roles.list(currentEnv));
|
|
746
|
+
const existingRole = (0, import_find.findByIdOrName)(roles, roleNameOrId, true);
|
|
747
|
+
if (existingRole) {
|
|
748
|
+
log.info(messages.roles.setPayload());
|
|
749
|
+
log.object(role);
|
|
750
|
+
log.raw(``);
|
|
751
|
+
const [updateErr, updated] = await contensis.roles.UpdateRole(
|
|
752
|
+
existingRole.id,
|
|
753
|
+
role
|
|
754
|
+
);
|
|
755
|
+
if (updateErr)
|
|
756
|
+
log.error(messages.roles.failedSet(currentEnv, roleNameOrId));
|
|
757
|
+
else {
|
|
758
|
+
log.success(messages.roles.set());
|
|
759
|
+
this.HandleFormattingAndOutput(updated, log.object);
|
|
760
|
+
}
|
|
761
|
+
} else {
|
|
762
|
+
log.error(messages.roles.failedGet(currentEnv, roleNameOrId));
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
if (rolesErr) {
|
|
766
|
+
log.error(messages.roles.noList(currentEnv));
|
|
767
|
+
log.error((0, import_json.jsonFormatter)(rolesErr));
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
RemoveRole = async (roleNameOrId) => {
|
|
772
|
+
const { currentEnv, log, messages } = this;
|
|
773
|
+
const contensis = await this.ConnectContensis();
|
|
774
|
+
if (contensis) {
|
|
775
|
+
const [rolesErr, roles] = await (0, import_await_to_js.default)(contensis.roles.GetRoles());
|
|
776
|
+
if (Array.isArray(roles)) {
|
|
777
|
+
log.success(messages.roles.list(currentEnv));
|
|
778
|
+
const existingRole = (0, import_find.findByIdOrName)(roles, roleNameOrId, true);
|
|
779
|
+
if (existingRole) {
|
|
780
|
+
const [deleteErr] = await contensis.roles.RemoveRole(existingRole.id);
|
|
781
|
+
if (deleteErr)
|
|
782
|
+
log.error(messages.roles.failedRemove(currentEnv, roleNameOrId));
|
|
783
|
+
else
|
|
784
|
+
log.success(messages.roles.removed(currentEnv, roleNameOrId));
|
|
785
|
+
} else {
|
|
786
|
+
log.error(messages.roles.failedGet(currentEnv, roleNameOrId));
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
if (rolesErr) {
|
|
790
|
+
log.error(messages.roles.noList(currentEnv));
|
|
791
|
+
log.error((0, import_json.jsonFormatter)(rolesErr));
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
CreateProject = async (project) => {
|
|
796
|
+
const { currentEnv, log, messages } = this;
|
|
797
|
+
const contensis = await this.ConnectContensis();
|
|
798
|
+
if (contensis) {
|
|
799
|
+
const [err, created] = await contensis.projects.CreateProject(project);
|
|
800
|
+
if (created) {
|
|
801
|
+
log.success(messages.projects.created(currentEnv, project.id));
|
|
802
|
+
this.HandleFormattingAndOutput(created, () => {
|
|
803
|
+
this.SetProject(project.id);
|
|
804
|
+
this.PrintProjects();
|
|
805
|
+
});
|
|
806
|
+
return project.id;
|
|
807
|
+
}
|
|
808
|
+
if (err) {
|
|
809
|
+
log.error(messages.projects.failedCreate(currentEnv, project.id), err);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
UpdateProject = async (project) => {
|
|
814
|
+
const { currentEnv, currentProject, log, messages } = this;
|
|
815
|
+
const contensis = await this.ConnectContensis();
|
|
816
|
+
if (contensis) {
|
|
817
|
+
const [err, updated] = await contensis.projects.UpdateProject({
|
|
818
|
+
id: currentProject,
|
|
819
|
+
...project
|
|
820
|
+
});
|
|
821
|
+
if (updated) {
|
|
822
|
+
log.success(messages.projects.updated(currentEnv, currentProject));
|
|
823
|
+
this.HandleFormattingAndOutput(updated, log.object);
|
|
824
|
+
return updated.id;
|
|
825
|
+
}
|
|
826
|
+
if (err) {
|
|
827
|
+
log.error(
|
|
828
|
+
messages.projects.failedUpdate(currentEnv, currentProject),
|
|
829
|
+
err
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
PrintContentModels = async (modelIds = []) => {
|
|
835
|
+
const { currentProject, log, messages } = this;
|
|
836
|
+
const contensis = await this.ConnectContensis();
|
|
837
|
+
if (contensis) {
|
|
838
|
+
const models = await contensis.models.contentModels();
|
|
839
|
+
const contentTypes = await contensis.models.contentTypes();
|
|
840
|
+
const components = await contensis.models.components();
|
|
841
|
+
const returnModels = (modelIds == null ? void 0 : modelIds.length) ? models == null ? void 0 : models.filter(
|
|
842
|
+
(m) => modelIds.some((id) => id.toLowerCase() === m.id.toLowerCase())
|
|
843
|
+
) : void 0;
|
|
844
|
+
const contentTypeIds = Array.from(
|
|
845
|
+
/* @__PURE__ */ new Set([
|
|
846
|
+
...(returnModels || models || []).map((m) => m.id),
|
|
847
|
+
...(returnModels || models || []).map((m) => {
|
|
848
|
+
var _a, _b;
|
|
849
|
+
return ((_b = (_a = m.dependencies) == null ? void 0 : _a.contentTypes) == null ? void 0 : _b.map((c) => c[0])) || [];
|
|
850
|
+
}).flat()
|
|
851
|
+
])
|
|
852
|
+
);
|
|
853
|
+
const componentIds = Array.from(
|
|
854
|
+
new Set(
|
|
855
|
+
(returnModels || models || []).map((m) => {
|
|
856
|
+
var _a, _b;
|
|
857
|
+
return ((_b = (_a = m.dependencies) == null ? void 0 : _a.components) == null ? void 0 : _b.map((c) => c[0])) || [];
|
|
858
|
+
}).flat()
|
|
859
|
+
)
|
|
860
|
+
);
|
|
861
|
+
const contentModelBackup = [
|
|
862
|
+
...contentTypes.filter(
|
|
863
|
+
(c) => contentTypeIds.map((i) => i.toLowerCase()).includes(c.id.toLowerCase())
|
|
864
|
+
),
|
|
865
|
+
...components.filter(
|
|
866
|
+
(c) => componentIds.map((i) => i.toLowerCase()).includes(c.id.toLowerCase())
|
|
867
|
+
)
|
|
868
|
+
];
|
|
869
|
+
if (Array.isArray(returnModels)) {
|
|
870
|
+
log.success(messages.models.list(currentProject));
|
|
871
|
+
this.HandleFormattingAndOutput(contentModelBackup, () => {
|
|
872
|
+
for (const model of returnModels) {
|
|
873
|
+
log.raw("");
|
|
874
|
+
log.object(model);
|
|
875
|
+
}
|
|
876
|
+
log.raw("");
|
|
877
|
+
});
|
|
878
|
+
} else {
|
|
879
|
+
log.success(
|
|
880
|
+
messages.models.get(currentProject, (models == null ? void 0 : models.length.toString()) || "0")
|
|
881
|
+
);
|
|
882
|
+
log.raw("");
|
|
883
|
+
if (models == null ? void 0 : models.length) {
|
|
884
|
+
this.HandleFormattingAndOutput(contentModelBackup, () => {
|
|
885
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
886
|
+
for (const model of models) {
|
|
887
|
+
const components2 = ((_a = model.components) == null ? void 0 : _a.length) || 0;
|
|
888
|
+
const contentTypes2 = ((_b = model.contentTypes) == null ? void 0 : _b.length) || 0;
|
|
889
|
+
const dependencies = (((_d = (_c = model.dependencies) == null ? void 0 : _c.components) == null ? void 0 : _d.length) || 0) + (((_f = (_e = model.dependencies) == null ? void 0 : _e.contentTypes) == null ? void 0 : _f.length) || 0);
|
|
890
|
+
const dependencyOf = (((_h = (_g = model.dependencyOf) == null ? void 0 : _g.components) == null ? void 0 : _h.length) || 0) + (((_j = (_i = model.dependencyOf) == null ? void 0 : _i.contentTypes) == null ? void 0 : _j.length) || 0);
|
|
891
|
+
const hasAny = components2 + contentTypes2 + dependencies + dependencyOf;
|
|
892
|
+
log.raw(
|
|
893
|
+
` - ${log.highlightText(log.boldText(model.id))} ${hasAny ? log.infoText(
|
|
894
|
+
`{ ${components2 ? `components: ${components2}, ` : ""}${contentTypes2 ? `contentTypes: ${contentTypes2}, ` : ""}${dependencies ? `references: ${dependencies}, ` : ""}${dependencyOf ? `required by: ${dependencyOf}` : ""} }`
|
|
895
|
+
) : ""}`
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
log.raw("");
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
ImportContentModels = async ({
|
|
905
|
+
commit,
|
|
906
|
+
fromFile
|
|
907
|
+
}) => {
|
|
582
908
|
const { currentProject, log, messages } = this;
|
|
583
|
-
|
|
584
|
-
if (
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
909
|
+
const fileData = fromFile ? (0, import_file_provider.readJsonFile)(fromFile) || [] : [];
|
|
910
|
+
if (typeof fileData === "string")
|
|
911
|
+
throw new Error(`Import file format must be of type JSON`);
|
|
912
|
+
const contensis = await this.ConnectContensisImport({
|
|
913
|
+
commit,
|
|
914
|
+
fromFile,
|
|
915
|
+
importDataType: "models"
|
|
916
|
+
});
|
|
917
|
+
if (contensis) {
|
|
918
|
+
log.line();
|
|
919
|
+
if (contensis.isPreview) {
|
|
920
|
+
console.log(log.successText(` -- IMPORT PREVIEW -- `));
|
|
921
|
+
} else {
|
|
922
|
+
console.log(log.warningText(` *** COMMITTING IMPORT *** `));
|
|
923
|
+
}
|
|
924
|
+
const [migrateErr, result] = await contensis.MigrateContentModels();
|
|
925
|
+
if (migrateErr)
|
|
926
|
+
(0, import_logger.logError)(migrateErr);
|
|
927
|
+
else
|
|
928
|
+
this.HandleFormattingAndOutput(result, () => {
|
|
929
|
+
if (!commit) {
|
|
930
|
+
log.raw(log.boldText(`
|
|
931
|
+
Content types:`));
|
|
932
|
+
if (!result.contentTypes)
|
|
933
|
+
log.info(`- None returned
|
|
934
|
+
`);
|
|
935
|
+
else
|
|
936
|
+
(0, import_console.printModelMigrationAnalysis)(this, result.contentTypes);
|
|
937
|
+
log.raw(log.boldText(`
|
|
938
|
+
Components:`));
|
|
939
|
+
if (!result.components)
|
|
940
|
+
log.info(`- None returned
|
|
941
|
+
`);
|
|
942
|
+
else
|
|
943
|
+
(0, import_console.printModelMigrationAnalysis)(this, result.components);
|
|
944
|
+
} else {
|
|
945
|
+
const migrateResult = result;
|
|
946
|
+
log.raw(log.boldText(`
|
|
947
|
+
Content types:`));
|
|
948
|
+
(0, import_console.printModelMigrationResult)(
|
|
949
|
+
this,
|
|
950
|
+
migrateResult[currentProject].contentTypes
|
|
951
|
+
);
|
|
952
|
+
log.raw(log.boldText(`
|
|
953
|
+
Components:`));
|
|
954
|
+
(0, import_console.printModelMigrationResult)(
|
|
955
|
+
this,
|
|
956
|
+
migrateResult[currentProject].components
|
|
957
|
+
);
|
|
958
|
+
}
|
|
959
|
+
});
|
|
591
960
|
} else {
|
|
592
|
-
log.warning(messages.
|
|
961
|
+
log.warning(messages.models.noList(currentProject));
|
|
962
|
+
log.help(messages.connect.tip());
|
|
593
963
|
}
|
|
594
964
|
};
|
|
595
965
|
PrintContentTypes = async () => {
|
|
596
966
|
const { currentProject, log, messages } = this;
|
|
597
|
-
await this.
|
|
598
|
-
if (
|
|
599
|
-
const
|
|
967
|
+
const contensis = await this.ConnectContensis();
|
|
968
|
+
if (contensis) {
|
|
969
|
+
const contentTypes = await contensis.models.contentTypes();
|
|
600
970
|
if (Array.isArray(contentTypes)) {
|
|
601
971
|
log.success(messages.contenttypes.list(currentProject));
|
|
602
972
|
this.HandleFormattingAndOutput(contentTypes, () => {
|
|
@@ -613,9 +983,9 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
613
983
|
};
|
|
614
984
|
PrintContentType = async (contentTypeId) => {
|
|
615
985
|
const { currentProject, log, messages } = this;
|
|
616
|
-
await this.
|
|
617
|
-
if (
|
|
618
|
-
const
|
|
986
|
+
const contensis = await this.ConnectContensis();
|
|
987
|
+
if (contensis) {
|
|
988
|
+
const contentTypes = await contensis.models.contentTypes();
|
|
619
989
|
if (Array.isArray(contentTypes)) {
|
|
620
990
|
const contentType = contentTypes.find(
|
|
621
991
|
(c) => c.id.toLowerCase() === contentTypeId.toLowerCase()
|
|
@@ -635,15 +1005,12 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
635
1005
|
};
|
|
636
1006
|
RemoveContentTypes = async (contentTypeIds, commit = false) => {
|
|
637
1007
|
const { currentProject, log, messages } = this;
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
const [err, result] = await this.contensis.DeleteContentTypes(
|
|
645
|
-
contentTypeIds
|
|
646
|
-
);
|
|
1008
|
+
const contensis = await this.ConnectContensisImport({
|
|
1009
|
+
commit,
|
|
1010
|
+
importDataType: "user-input"
|
|
1011
|
+
});
|
|
1012
|
+
if (contensis) {
|
|
1013
|
+
const [err, result] = await contensis.DeleteContentTypes(contentTypeIds);
|
|
647
1014
|
if (err) {
|
|
648
1015
|
log.error(
|
|
649
1016
|
messages.contenttypes.failedRemove(
|
|
@@ -657,7 +1024,7 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
657
1024
|
messages.contenttypes.removed(
|
|
658
1025
|
currentProject,
|
|
659
1026
|
contentTypeIds.join('", "'),
|
|
660
|
-
!
|
|
1027
|
+
!contensis.isPreview
|
|
661
1028
|
)
|
|
662
1029
|
);
|
|
663
1030
|
this.HandleFormattingAndOutput(
|
|
@@ -677,15 +1044,15 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
677
1044
|
throw new Error(`Import file format must be of type JSON`);
|
|
678
1045
|
if (!Array.isArray(fileData))
|
|
679
1046
|
fileData = [fileData];
|
|
680
|
-
await this.ConnectContensisImport({
|
|
1047
|
+
const contensis = await this.ConnectContensisImport({
|
|
681
1048
|
commit,
|
|
682
|
-
|
|
1049
|
+
importDataType: fromFile ? "user-input" : void 0
|
|
683
1050
|
});
|
|
684
|
-
if (
|
|
1051
|
+
if (contensis) {
|
|
685
1052
|
for (const contentType of fileData) {
|
|
686
1053
|
contentType.projectId = currentProject;
|
|
687
1054
|
delete contentType.uuid;
|
|
688
|
-
const [err, created, createStatus] = await
|
|
1055
|
+
const [err, created, createStatus] = await contensis.models.targetRepos[currentProject].repo.UpsertContentType(false, contentType);
|
|
689
1056
|
if (err)
|
|
690
1057
|
log.error(err.message, err);
|
|
691
1058
|
if (createStatus) {
|
|
@@ -702,11 +1069,54 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
702
1069
|
}
|
|
703
1070
|
}
|
|
704
1071
|
};
|
|
1072
|
+
DiffModels = async ({
|
|
1073
|
+
fromFile
|
|
1074
|
+
}, modelIds = []) => {
|
|
1075
|
+
const { log } = this;
|
|
1076
|
+
let fileData = fromFile ? (0, import_file_provider.readJsonFile)(fromFile) || [] : [];
|
|
1077
|
+
if (typeof fileData === "string")
|
|
1078
|
+
throw new Error(`Import file format must be of type JSON`);
|
|
1079
|
+
if (!Array.isArray(fileData))
|
|
1080
|
+
fileData = [fileData];
|
|
1081
|
+
const contensis = await this.ConnectContensisImport({
|
|
1082
|
+
fromFile,
|
|
1083
|
+
importDataType: "models"
|
|
1084
|
+
});
|
|
1085
|
+
if (contensis) {
|
|
1086
|
+
const [err, result] = await (0, import_await_to_js.default)(
|
|
1087
|
+
contensis.models.Diff(fileData.length ? fileData : modelIds)
|
|
1088
|
+
);
|
|
1089
|
+
if (err)
|
|
1090
|
+
log.error(err.message, err);
|
|
1091
|
+
if (result)
|
|
1092
|
+
this.HandleFormattingAndOutput(result, () => {
|
|
1093
|
+
var _a;
|
|
1094
|
+
log.success(
|
|
1095
|
+
`Queried models ${log.infoText(
|
|
1096
|
+
`"${(_a = result.query.modelIds) == null ? void 0 : _a.join(", ")}"`
|
|
1097
|
+
)}
|
|
1098
|
+
`
|
|
1099
|
+
);
|
|
1100
|
+
log.raw(log.boldText(`Content types:`));
|
|
1101
|
+
if (!result.contentTypes)
|
|
1102
|
+
log.info(`- None returned
|
|
1103
|
+
`);
|
|
1104
|
+
else
|
|
1105
|
+
(0, import_console.printModelMigrationAnalysis)(this, result.contentTypes);
|
|
1106
|
+
log.raw(log.boldText(`Components:`));
|
|
1107
|
+
if (!result.components)
|
|
1108
|
+
log.info(`- None returned
|
|
1109
|
+
`);
|
|
1110
|
+
else
|
|
1111
|
+
(0, import_console.printModelMigrationAnalysis)(this, result.components);
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
};
|
|
705
1115
|
PrintComponents = async () => {
|
|
706
1116
|
const { currentProject, log, messages } = this;
|
|
707
|
-
await this.
|
|
708
|
-
if (
|
|
709
|
-
const
|
|
1117
|
+
const contensis = await this.ConnectContensis();
|
|
1118
|
+
if (contensis) {
|
|
1119
|
+
const components = await contensis.models.components();
|
|
710
1120
|
if (Array.isArray(components)) {
|
|
711
1121
|
log.success(messages.components.list(currentProject));
|
|
712
1122
|
this.HandleFormattingAndOutput(components, () => {
|
|
@@ -723,9 +1133,9 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
723
1133
|
};
|
|
724
1134
|
PrintComponent = async (componentId) => {
|
|
725
1135
|
const { currentProject, log, messages } = this;
|
|
726
|
-
await this.
|
|
727
|
-
if (
|
|
728
|
-
const
|
|
1136
|
+
const contensis = await this.ConnectContensis();
|
|
1137
|
+
if (contensis) {
|
|
1138
|
+
const components = await contensis.models.components();
|
|
729
1139
|
if (Array.isArray(components)) {
|
|
730
1140
|
const component = components.find(
|
|
731
1141
|
(c) => c.id.toLowerCase() === componentId.toLowerCase()
|
|
@@ -741,13 +1151,12 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
741
1151
|
};
|
|
742
1152
|
RemoveComponents = async (componentIds, commit = false) => {
|
|
743
1153
|
const { currentProject, log, messages } = this;
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
const [err, result] = await this.contensis.DeleteContentTypes(
|
|
1154
|
+
const contensis = await this.ConnectContensisImport({
|
|
1155
|
+
commit,
|
|
1156
|
+
importDataType: "user-input"
|
|
1157
|
+
});
|
|
1158
|
+
if (contensis) {
|
|
1159
|
+
const [err, result] = await contensis.DeleteContentTypes(
|
|
751
1160
|
void 0,
|
|
752
1161
|
componentIds
|
|
753
1162
|
);
|
|
@@ -764,7 +1173,7 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
764
1173
|
messages.components.removed(
|
|
765
1174
|
currentProject,
|
|
766
1175
|
componentIds.join('", "'),
|
|
767
|
-
!
|
|
1176
|
+
!contensis.isPreview
|
|
768
1177
|
)
|
|
769
1178
|
);
|
|
770
1179
|
this.HandleFormattingAndOutput(
|
|
@@ -784,15 +1193,15 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
784
1193
|
throw new Error(`Import file format must be of type JSON`);
|
|
785
1194
|
if (!Array.isArray(fileData))
|
|
786
1195
|
fileData = [fileData];
|
|
787
|
-
await this.ConnectContensisImport({
|
|
1196
|
+
const contensis = await this.ConnectContensisImport({
|
|
788
1197
|
commit,
|
|
789
|
-
|
|
1198
|
+
importDataType: fromFile ? "user-input" : void 0
|
|
790
1199
|
});
|
|
791
|
-
if (
|
|
1200
|
+
if (contensis) {
|
|
792
1201
|
for (const component of fileData) {
|
|
793
1202
|
component.projectId = currentProject;
|
|
794
1203
|
delete component.uuid;
|
|
795
|
-
const [err, created, createStatus] = await
|
|
1204
|
+
const [err, created, createStatus] = await contensis.models.targetRepos[currentProject].repo.UpsertComponent(false, component);
|
|
796
1205
|
if (err)
|
|
797
1206
|
log.error(err.message, err);
|
|
798
1207
|
if (createStatus) {
|
|
@@ -809,33 +1218,37 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
809
1218
|
}
|
|
810
1219
|
}
|
|
811
1220
|
};
|
|
812
|
-
|
|
813
|
-
var _a
|
|
814
|
-
const { currentEnv, log, messages } = this;
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
if (this.contensis.isPreview) {
|
|
1221
|
+
RemoveEntries = async (commit = false) => {
|
|
1222
|
+
var _a;
|
|
1223
|
+
const { currentEnv, currentProject, log, messages } = this;
|
|
1224
|
+
const contensis = await this.ConnectContensisImport({
|
|
1225
|
+
commit,
|
|
1226
|
+
importDataType: "user-input"
|
|
1227
|
+
});
|
|
1228
|
+
if (contensis) {
|
|
1229
|
+
if (contensis.isPreview) {
|
|
822
1230
|
console.log(log.successText(` -- PREVIEW -- `));
|
|
823
1231
|
} else {
|
|
824
1232
|
console.log(log.warningText(` *** COMMITTING DELETE *** `));
|
|
825
1233
|
}
|
|
826
|
-
const [err, result] = await
|
|
1234
|
+
const [err, result] = await contensis.DeleteEntries();
|
|
827
1235
|
if (result)
|
|
828
1236
|
this.HandleFormattingAndOutput(result, () => {
|
|
829
|
-
(0, import_console.printMigrateResult)(this, result, {
|
|
1237
|
+
(0, import_console.printMigrateResult)(this, result, {
|
|
1238
|
+
action: "delete",
|
|
1239
|
+
showAllEntries: true
|
|
1240
|
+
});
|
|
830
1241
|
});
|
|
831
|
-
if (!err && (!commit &&
|
|
832
|
-
log.success(messages.entries.removed(currentEnv,
|
|
833
|
-
if (!commit)
|
|
1242
|
+
if (!err && (!commit && result.entriesToMigrate[currentProject].totalCount || commit && ((_a = result.migrateResult) == null ? void 0 : _a.deleted))) {
|
|
1243
|
+
log.success(messages.entries.removed(currentEnv, commit));
|
|
1244
|
+
if (!commit) {
|
|
1245
|
+
log.raw(``);
|
|
834
1246
|
log.help(messages.entries.commitTip());
|
|
1247
|
+
}
|
|
835
1248
|
} else {
|
|
836
|
-
log.error(messages.entries.failedRemove(currentEnv
|
|
837
|
-
if (!
|
|
838
|
-
log.help(messages.entries.notFound(
|
|
1249
|
+
log.error(messages.entries.failedRemove(currentEnv), err);
|
|
1250
|
+
if (!result.entriesToMigrate[currentProject].totalCount)
|
|
1251
|
+
log.help(messages.entries.notFound(currentEnv));
|
|
839
1252
|
}
|
|
840
1253
|
}
|
|
841
1254
|
};
|
|
@@ -843,90 +1256,191 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
843
1256
|
withDependents = false
|
|
844
1257
|
}) => {
|
|
845
1258
|
const { currentProject, log, messages } = this;
|
|
846
|
-
await this.ConnectContensis();
|
|
847
|
-
if (
|
|
1259
|
+
const contensis = await this.ConnectContensis();
|
|
1260
|
+
if (contensis) {
|
|
848
1261
|
log.line();
|
|
849
|
-
const entries = await
|
|
1262
|
+
const entries = await contensis.GetEntries({ withDependents });
|
|
850
1263
|
this.HandleFormattingAndOutput(
|
|
851
1264
|
entries,
|
|
852
1265
|
() => {
|
|
853
|
-
var _a
|
|
1266
|
+
var _a;
|
|
854
1267
|
return (0, import_migratortron.logEntriesTable)(
|
|
855
1268
|
entries,
|
|
856
1269
|
currentProject,
|
|
857
|
-
(
|
|
1270
|
+
(_a = contensis.payload.query) == null ? void 0 : _a.fields
|
|
858
1271
|
);
|
|
859
1272
|
}
|
|
860
1273
|
);
|
|
861
1274
|
} else {
|
|
862
|
-
log.warning(messages.
|
|
1275
|
+
log.warning(messages.models.noList(currentProject));
|
|
863
1276
|
log.help(messages.connect.tip());
|
|
864
1277
|
}
|
|
865
1278
|
};
|
|
866
1279
|
ImportEntries = async ({
|
|
867
1280
|
commit,
|
|
868
|
-
fromFile
|
|
1281
|
+
fromFile,
|
|
1282
|
+
logOutput
|
|
869
1283
|
}) => {
|
|
870
|
-
|
|
871
|
-
const
|
|
872
|
-
|
|
873
|
-
throw new Error(`Import file format must be of type JSON`);
|
|
874
|
-
await this.ConnectContensisImport({
|
|
1284
|
+
var _a, _b, _c, _d, _e;
|
|
1285
|
+
const { currentEnv, currentProject, log, messages } = this;
|
|
1286
|
+
const contensis = await this.ConnectContensisImport({
|
|
875
1287
|
commit,
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
fileDataType: "entries"
|
|
1288
|
+
fromFile,
|
|
1289
|
+
importDataType: "entries"
|
|
879
1290
|
});
|
|
880
|
-
if (
|
|
1291
|
+
if (contensis) {
|
|
881
1292
|
log.line();
|
|
882
|
-
if (
|
|
1293
|
+
if (contensis.isPreview) {
|
|
883
1294
|
console.log(log.successText(` -- IMPORT PREVIEW -- `));
|
|
884
1295
|
} else {
|
|
885
1296
|
console.log(log.warningText(` *** COMMITTING IMPORT *** `));
|
|
886
1297
|
}
|
|
887
|
-
const [
|
|
888
|
-
if (
|
|
889
|
-
(0, import_logger.logError)(
|
|
1298
|
+
const [err, result] = await contensis.MigrateEntries();
|
|
1299
|
+
if (err)
|
|
1300
|
+
(0, import_logger.logError)(err);
|
|
890
1301
|
else
|
|
891
|
-
this.HandleFormattingAndOutput(
|
|
892
|
-
(0, import_console.printMigrateResult)(this,
|
|
1302
|
+
this.HandleFormattingAndOutput(result, () => {
|
|
1303
|
+
(0, import_console.printMigrateResult)(this, result, {
|
|
1304
|
+
showAllEntries: logOutput === "all",
|
|
1305
|
+
showChangedEntries: logOutput === "changes"
|
|
1306
|
+
});
|
|
893
1307
|
});
|
|
1308
|
+
if (!err && !((_a = result.errors) == null ? void 0 : _a.length) && (!commit && result.entriesToMigrate[currentProject].totalCount || commit && (((_b = result.migrateResult) == null ? void 0 : _b.created) || ((_c = result.migrateResult) == null ? void 0 : _c.updated)))) {
|
|
1309
|
+
log.success(
|
|
1310
|
+
messages.entries.imported(
|
|
1311
|
+
currentEnv,
|
|
1312
|
+
commit,
|
|
1313
|
+
commit ? (((_d = result.migrateResult) == null ? void 0 : _d.created) || 0) + (((_e = result.migrateResult) == null ? void 0 : _e.updated) || 0) : result.entriesToMigrate[currentProject].totalCount
|
|
1314
|
+
)
|
|
1315
|
+
);
|
|
1316
|
+
if (!commit) {
|
|
1317
|
+
log.raw(``);
|
|
1318
|
+
log.help(messages.entries.commitTip());
|
|
1319
|
+
}
|
|
1320
|
+
} else {
|
|
1321
|
+
log.error(messages.entries.failedImport(currentEnv), err);
|
|
1322
|
+
if (!result.entriesToMigrate[currentProject].totalCount)
|
|
1323
|
+
log.help(messages.entries.notFound(currentEnv));
|
|
1324
|
+
}
|
|
894
1325
|
} else {
|
|
895
|
-
log.warning(messages.
|
|
1326
|
+
log.warning(messages.models.noList(currentProject));
|
|
896
1327
|
log.help(messages.connect.tip());
|
|
897
1328
|
}
|
|
898
1329
|
};
|
|
899
|
-
|
|
1330
|
+
GetNodes = async (rootPath, depth = 0) => {
|
|
1331
|
+
const { currentProject, log, messages } = this;
|
|
1332
|
+
const contensis = await this.ConnectContensis();
|
|
1333
|
+
if (contensis) {
|
|
1334
|
+
log.line();
|
|
1335
|
+
const [err] = await (0, import_await_to_js.default)(
|
|
1336
|
+
contensis.content.sourceRepo.nodes.GetNodes(rootPath, depth)
|
|
1337
|
+
);
|
|
1338
|
+
if (err) {
|
|
1339
|
+
log.error(messages.nodes.failedGet(currentProject), err);
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
const root = contensis.content.sourceRepo.nodes.tree;
|
|
1343
|
+
log.success(messages.nodes.get(currentProject, rootPath, depth));
|
|
1344
|
+
const outputNode = (node, spaces) => `${node.entry ? log.highlightText("e") : log.infoText("-")}${node.isCanonical ? log.highlightText("c") : log.infoText("-")}${node.includeInMenu ? log.highlightText("m") : log.infoText("-")}${spaces}${node.isCanonical ? log.boldText(`/${node.slug}`) : `/${node.slug}`}${node.entry ? ` ${log.helpText(node.entry.sys.contentTypeId)}` : ""}${node.childCount ? ` +${node.childCount}` : ``} ${log.infoText(node.displayName)}`;
|
|
1345
|
+
this.HandleFormattingAndOutput(root, () => {
|
|
1346
|
+
log.object({ ...root, children: void 0 });
|
|
1347
|
+
log.raw("");
|
|
1348
|
+
log.info(
|
|
1349
|
+
`${log.highlightText("e")} = has entry; ${log.highlightText(
|
|
1350
|
+
"c"
|
|
1351
|
+
)} = canonical; ${log.highlightText("m")} = include in menu`
|
|
1352
|
+
);
|
|
1353
|
+
log.line();
|
|
1354
|
+
const outputChildren = (root2, depth2 = 2) => {
|
|
1355
|
+
let str = "";
|
|
1356
|
+
for (const node of root2 == null ? void 0 : root2.children) {
|
|
1357
|
+
str += `${outputNode(node, Array(depth2 + 1).join(" "))}
|
|
1358
|
+
`;
|
|
1359
|
+
if ("children" in node)
|
|
1360
|
+
str += outputChildren(node, depth2 + 1);
|
|
1361
|
+
}
|
|
1362
|
+
return str;
|
|
1363
|
+
};
|
|
1364
|
+
const children = outputChildren(root);
|
|
1365
|
+
log.limits(
|
|
1366
|
+
`${outputNode(root, " ")}${children ? `
|
|
1367
|
+
${children}` : ""}`,
|
|
1368
|
+
100
|
|
1369
|
+
);
|
|
1370
|
+
});
|
|
1371
|
+
} else {
|
|
1372
|
+
log.warning(messages.models.noList(currentProject));
|
|
1373
|
+
log.help(messages.connect.tip());
|
|
1374
|
+
}
|
|
1375
|
+
};
|
|
1376
|
+
PrintWebhookSubscriptions = async (subscriptionIdsOrNames) => {
|
|
900
1377
|
const { currentEnv, log, messages } = this;
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
const
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
}
|
|
910
|
-
) : Array.isArray(subscriptionIds) ? webhooks.filter((w) => subscriptionIds == null ? void 0 : subscriptionIds.some((id) => id === w.id)) : webhooks;
|
|
911
|
-
if (Array.isArray(filteredResults)) {
|
|
912
|
-
this.HandleFormattingAndOutput(filteredResults, () => {
|
|
913
|
-
log.success(messages.webhooks.list(currentEnv));
|
|
914
|
-
for (const {
|
|
915
|
-
id,
|
|
916
|
-
description,
|
|
917
|
-
method,
|
|
918
|
-
name: name2,
|
|
919
|
-
version,
|
|
920
|
-
url: url2
|
|
921
|
-
} of filteredResults) {
|
|
922
|
-
console.log(
|
|
923
|
-
` - ${name2}${description ? ` (${description})` : ""} [${version.modified.toString().substring(0, 10)} ${version.modifiedBy}]`
|
|
924
|
-
);
|
|
925
|
-
console.log(` ${id}`);
|
|
926
|
-
console.log(` [${method}] ${url2}`);
|
|
1378
|
+
const contensis = await this.ConnectContensis();
|
|
1379
|
+
if (contensis) {
|
|
1380
|
+
const [webhooksErr, webhooks] = await contensis.subscriptions.webhooks.GetSubscriptions();
|
|
1381
|
+
const filteredResults = (subscriptionIdsOrNames == null ? void 0 : subscriptionIdsOrNames.length) ? webhooks == null ? void 0 : webhooks.filter(
|
|
1382
|
+
(w) => (subscriptionIdsOrNames == null ? void 0 : subscriptionIdsOrNames.some(
|
|
1383
|
+
(idname) => {
|
|
1384
|
+
var _a;
|
|
1385
|
+
return (_a = w.name) == null ? void 0 : _a.toLowerCase().includes(idname.toLowerCase());
|
|
927
1386
|
}
|
|
928
|
-
|
|
929
|
-
|
|
1387
|
+
)) || (subscriptionIdsOrNames == null ? void 0 : subscriptionIdsOrNames.some(
|
|
1388
|
+
(id) => id.toLowerCase() === w.id.toLowerCase()
|
|
1389
|
+
))
|
|
1390
|
+
) : webhooks;
|
|
1391
|
+
if (Array.isArray(filteredResults)) {
|
|
1392
|
+
log.success(messages.webhooks.list(currentEnv));
|
|
1393
|
+
if (!(webhooks == null ? void 0 : webhooks.length))
|
|
1394
|
+
log.warning(messages.webhooks.noneExist());
|
|
1395
|
+
else {
|
|
1396
|
+
this.HandleFormattingAndOutput(filteredResults, () => {
|
|
1397
|
+
for (const {
|
|
1398
|
+
id,
|
|
1399
|
+
description,
|
|
1400
|
+
method,
|
|
1401
|
+
name,
|
|
1402
|
+
version,
|
|
1403
|
+
url: url2,
|
|
1404
|
+
enabled,
|
|
1405
|
+
topics,
|
|
1406
|
+
templates,
|
|
1407
|
+
headers
|
|
1408
|
+
} of filteredResults) {
|
|
1409
|
+
console.log(
|
|
1410
|
+
log.infoText(
|
|
1411
|
+
` ${import_chalk.default.bold.white`- ${name}`} ${id} [${(version.modified || version.created).toString().substring(0, 10)} ${version.modifiedBy || version.createdBy}]`
|
|
1412
|
+
)
|
|
1413
|
+
);
|
|
1414
|
+
if (description)
|
|
1415
|
+
console.log(log.infoText` ${description}`);
|
|
1416
|
+
console.log(` ${log.infoText`[${method}]`} ${url2}`);
|
|
1417
|
+
if (headers && Object.keys(headers).length) {
|
|
1418
|
+
console.log(` ${log.infoText`headers`}:`);
|
|
1419
|
+
for (const [key, { value, secret }] of Object.entries(headers))
|
|
1420
|
+
console.log(
|
|
1421
|
+
` ${import_chalk.default.bold.gray(key)}: ${secret ? "\u{1F910}" : value}`
|
|
1422
|
+
);
|
|
1423
|
+
}
|
|
1424
|
+
if (topics == null ? void 0 : topics.length)
|
|
1425
|
+
if ((topics == null ? void 0 : topics.length) === 1)
|
|
1426
|
+
console.log(
|
|
1427
|
+
` ${log.infoText`topics`}: ${topics.map((t) => JSON.stringify(t)).join(" ").replaceAll('"', "").replaceAll(",", " ").replaceAll("{", "").replaceAll("}", "")}`
|
|
1428
|
+
);
|
|
1429
|
+
else {
|
|
1430
|
+
console.log(` ${log.infoText`topics`}:`);
|
|
1431
|
+
log.objectRecurse(topics, 1, " ");
|
|
1432
|
+
}
|
|
1433
|
+
if (templates && Object.keys(templates).length)
|
|
1434
|
+
console.log(
|
|
1435
|
+
` ${log.infoText`templates`}: ${Object.keys(
|
|
1436
|
+
templates
|
|
1437
|
+
).join(" ")}`
|
|
1438
|
+
);
|
|
1439
|
+
if (enabled === false)
|
|
1440
|
+
console.log(` ${log.infoText`enabled`}: ${enabled}`);
|
|
1441
|
+
}
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
930
1444
|
}
|
|
931
1445
|
if (webhooksErr) {
|
|
932
1446
|
log.error(messages.webhooks.noList(currentEnv));
|
|
@@ -935,14 +1449,13 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
935
1449
|
}
|
|
936
1450
|
};
|
|
937
1451
|
PrintBlocks = async () => {
|
|
938
|
-
const { currentEnv, log, messages } = this;
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
const [err, blocks] = await this.contensis.blocks.GetBlocks();
|
|
1452
|
+
const { currentEnv, env, log, messages } = this;
|
|
1453
|
+
const contensis = await this.ConnectContensis();
|
|
1454
|
+
if (contensis) {
|
|
1455
|
+
const [err, blocks] = await contensis.blocks.GetBlocks();
|
|
943
1456
|
if (Array.isArray(blocks)) {
|
|
944
1457
|
this.HandleFormattingAndOutput(blocks, () => {
|
|
945
|
-
log.success(messages.blocks.list(currentEnv));
|
|
1458
|
+
log.success(messages.blocks.list(currentEnv, env.currentProject));
|
|
946
1459
|
for (const {
|
|
947
1460
|
id,
|
|
948
1461
|
description,
|
|
@@ -960,6 +1473,7 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
960
1473
|
);
|
|
961
1474
|
}
|
|
962
1475
|
});
|
|
1476
|
+
return blocks;
|
|
963
1477
|
}
|
|
964
1478
|
if (err) {
|
|
965
1479
|
log.error(messages.blocks.noList(currentEnv));
|
|
@@ -969,10 +1483,9 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
969
1483
|
};
|
|
970
1484
|
PrintBlockVersions = async (blockId, branch, version) => {
|
|
971
1485
|
const { currentEnv, env, log, messages } = this;
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
const [err, blocks] = await this.contensis.blocks.GetBlockVersions(
|
|
1486
|
+
const contensis = await this.ConnectContensis();
|
|
1487
|
+
if (contensis) {
|
|
1488
|
+
const [err, blocks] = await contensis.blocks.GetBlockVersions(
|
|
976
1489
|
blockId,
|
|
977
1490
|
branch,
|
|
978
1491
|
version
|
|
@@ -980,7 +1493,7 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
980
1493
|
if (blocks) {
|
|
981
1494
|
this.HandleFormattingAndOutput(blocks, () => {
|
|
982
1495
|
log.success(
|
|
983
|
-
messages.blocks.get(
|
|
1496
|
+
messages.blocks.get(blockId, currentEnv, env.currentProject)
|
|
984
1497
|
);
|
|
985
1498
|
for (const block of blocks)
|
|
986
1499
|
(0, import_console.printBlockVersion)(
|
|
@@ -994,6 +1507,7 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
994
1507
|
} : void 0
|
|
995
1508
|
);
|
|
996
1509
|
});
|
|
1510
|
+
return blocks;
|
|
997
1511
|
}
|
|
998
1512
|
if (err) {
|
|
999
1513
|
log.error(messages.blocks.noList(currentEnv, env.currentProject));
|
|
@@ -1003,17 +1517,18 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
1003
1517
|
};
|
|
1004
1518
|
PushBlock = async (block) => {
|
|
1005
1519
|
const { currentEnv, env, log, messages } = this;
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1520
|
+
log.info(
|
|
1521
|
+
messages.blocks.tryPush(
|
|
1522
|
+
block.id,
|
|
1523
|
+
block.source.branch,
|
|
1524
|
+
currentEnv,
|
|
1525
|
+
env.currentProject
|
|
1526
|
+
)
|
|
1011
1527
|
);
|
|
1012
1528
|
console.log((0, import_json.jsonFormatter)(block));
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
const [err, blockVersion] = await this.contensis.blocks.PushBlockVersion(
|
|
1529
|
+
const contensis = await this.ConnectContensis();
|
|
1530
|
+
if (contensis) {
|
|
1531
|
+
const [err, blockVersion] = await contensis.blocks.PushBlockVersion(
|
|
1017
1532
|
block
|
|
1018
1533
|
);
|
|
1019
1534
|
if (!err) {
|
|
@@ -1025,7 +1540,6 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
1025
1540
|
env.currentProject
|
|
1026
1541
|
)
|
|
1027
1542
|
);
|
|
1028
|
-
console.log((0, import_json.jsonFormatter)(blockVersion));
|
|
1029
1543
|
}
|
|
1030
1544
|
if (blockVersion) {
|
|
1031
1545
|
this.HandleFormattingAndOutput(blockVersion, () => {
|
|
@@ -1036,70 +1550,283 @@ Exiting contensis-cli with exit code: ${exitCode}
|
|
|
1036
1550
|
throw new Error(
|
|
1037
1551
|
messages.blocks.failedPush(block.id, currentEnv, env.currentProject)
|
|
1038
1552
|
);
|
|
1553
|
+
} else {
|
|
1554
|
+
throw new Error(
|
|
1555
|
+
messages.blocks.failedPush(block.id, currentEnv, env.currentProject)
|
|
1556
|
+
);
|
|
1039
1557
|
}
|
|
1040
1558
|
};
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
if (
|
|
1046
|
-
|
|
1559
|
+
GetLatestBlockVersion = async (blockId, branch = "default") => {
|
|
1560
|
+
var _a;
|
|
1561
|
+
const { contensis, log, messages } = this;
|
|
1562
|
+
const [getErr, blockVersions] = await (contensis == null ? void 0 : contensis.blocks.GetBlockVersions(blockId, branch)) || [];
|
|
1563
|
+
if (getErr) {
|
|
1564
|
+
return [getErr, void 0];
|
|
1565
|
+
}
|
|
1566
|
+
let blockVersionNo = "latest";
|
|
1567
|
+
try {
|
|
1568
|
+
blockVersionNo = `${(_a = blockVersions == null ? void 0 : blockVersions[0]) == null ? void 0 : _a.version.versionNo}`;
|
|
1569
|
+
if (!Number.isNaN(blockVersionNo) && Number(blockVersionNo) > 0)
|
|
1570
|
+
return [null, blockVersionNo];
|
|
1571
|
+
else
|
|
1572
|
+
throw new Error(`'${blockVersionNo}' is not a valid version number`);
|
|
1573
|
+
} catch (parseVersionEx) {
|
|
1574
|
+
log.info(
|
|
1575
|
+
`Request for blockId: ${blockId}, branch: ${branch}, version: latest`
|
|
1576
|
+
);
|
|
1577
|
+
log.info(
|
|
1578
|
+
`Get block versions response was: ${(0, import_util.tryStringify)(blockVersions)}`
|
|
1579
|
+
);
|
|
1580
|
+
log.error(messages.blocks.failedParsingVersion());
|
|
1581
|
+
return [parseVersionEx, void 0];
|
|
1582
|
+
}
|
|
1583
|
+
};
|
|
1584
|
+
ExecuteBlockAction = async (action, blockId, version = "latest") => {
|
|
1585
|
+
const { currentEnv, env, log, messages } = this;
|
|
1586
|
+
const contensis = await this.ConnectContensis();
|
|
1587
|
+
if (contensis) {
|
|
1588
|
+
let actionOnBlockVersion = version;
|
|
1589
|
+
if (action === "release" && version === "latest") {
|
|
1590
|
+
const [getErr, blockVersion2] = await this.GetLatestBlockVersion(
|
|
1591
|
+
blockId
|
|
1592
|
+
);
|
|
1593
|
+
if (getErr) {
|
|
1594
|
+
throw new Error(
|
|
1595
|
+
`${messages.blocks.noList(
|
|
1596
|
+
currentEnv,
|
|
1597
|
+
env.currentProject
|
|
1598
|
+
)} (${getErr})`
|
|
1599
|
+
);
|
|
1600
|
+
} else if (blockVersion2) {
|
|
1601
|
+
actionOnBlockVersion = blockVersion2;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
const [err, blockVersion] = await contensis.blocks.BlockAction(
|
|
1605
|
+
blockId,
|
|
1606
|
+
action,
|
|
1607
|
+
actionOnBlockVersion
|
|
1608
|
+
);
|
|
1609
|
+
if (blockVersion) {
|
|
1610
|
+
this.HandleFormattingAndOutput(blockVersion, () => {
|
|
1611
|
+
log.success(
|
|
1612
|
+
messages.blocks.actionComplete(
|
|
1613
|
+
action,
|
|
1614
|
+
blockId,
|
|
1615
|
+
currentEnv,
|
|
1616
|
+
env.currentProject
|
|
1617
|
+
)
|
|
1618
|
+
);
|
|
1619
|
+
(0, import_console.printBlockVersion)(this, blockVersion);
|
|
1620
|
+
});
|
|
1621
|
+
}
|
|
1622
|
+
if (err) {
|
|
1623
|
+
log.error((0, import_json.jsonFormatter)(err));
|
|
1624
|
+
throw new Error(
|
|
1625
|
+
messages.blocks.actionFailed(
|
|
1626
|
+
action,
|
|
1627
|
+
blockId,
|
|
1628
|
+
currentEnv,
|
|
1629
|
+
env.currentProject
|
|
1630
|
+
)
|
|
1631
|
+
);
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
PrintBlockLogs = async (blockId, branch, version, dataCenter, follow = false) => {
|
|
1636
|
+
const { currentEnv, env, log, messages } = this;
|
|
1637
|
+
const contensis = await this.ConnectContensis();
|
|
1638
|
+
if (contensis) {
|
|
1639
|
+
log.success(
|
|
1640
|
+
messages.blocks.getLogs(blockId, branch, currentEnv, env.currentProject)
|
|
1641
|
+
);
|
|
1642
|
+
const [err, blockLogs] = await contensis.blocks.GetBlockLogs({
|
|
1047
1643
|
blockId,
|
|
1048
1644
|
branchId: branch,
|
|
1049
1645
|
version,
|
|
1050
1646
|
dataCenter
|
|
1051
1647
|
});
|
|
1052
|
-
if (
|
|
1053
|
-
|
|
1054
|
-
|
|
1648
|
+
if (err) {
|
|
1649
|
+
log.error(
|
|
1650
|
+
messages.blocks.failedGetLogs(blockId, currentEnv, env.currentProject)
|
|
1651
|
+
);
|
|
1652
|
+
log.error((0, import_json.jsonFormatter)(err));
|
|
1653
|
+
} else if (blockLogs) {
|
|
1654
|
+
const removeTrailingNewline = (logs) => logs.endsWith("\n") ? logs.slice(0, logs.length - 1) : logs;
|
|
1655
|
+
const renderLogs = removeTrailingNewline(blockLogs);
|
|
1656
|
+
this.HandleFormattingAndOutput(renderLogs, () => {
|
|
1055
1657
|
console.log(
|
|
1056
|
-
` - ${blockId} ${branch} ${Number(version) ? `v${version}` : version} [${dataCenter}]`
|
|
1658
|
+
` - ${blockId} ${branch} ${Number(version) ? `v${version}` : version} ${dataCenter ? `[${dataCenter}]` : ""}`
|
|
1057
1659
|
);
|
|
1058
1660
|
log.line();
|
|
1059
|
-
console.log(log.infoText(
|
|
1060
|
-
|
|
1661
|
+
console.log(log.infoText(renderLogs));
|
|
1662
|
+
});
|
|
1663
|
+
let following = follow;
|
|
1664
|
+
let alreadyShown = blockLogs;
|
|
1665
|
+
let needsNewLine = false;
|
|
1666
|
+
let counter = 0;
|
|
1667
|
+
const listeners = process.listeners("SIGINT");
|
|
1668
|
+
process.removeAllListeners("SIGINT");
|
|
1669
|
+
process.on("SIGINT", () => {
|
|
1670
|
+
import_logger.Logger.warning(
|
|
1671
|
+
messages.blocks.stopFollow(blockId, currentEnv, env.currentProject)
|
|
1672
|
+
);
|
|
1673
|
+
stopFollowing();
|
|
1674
|
+
});
|
|
1675
|
+
let delay = (0, import_timers.promiseDelay)(5 * 1e3, null);
|
|
1676
|
+
const stopFollowing = () => {
|
|
1677
|
+
following = false;
|
|
1678
|
+
delay.cancel();
|
|
1679
|
+
process.removeAllListeners("SIGINT");
|
|
1680
|
+
for (const listener of listeners)
|
|
1681
|
+
process.addListener("SIGINT", listener);
|
|
1682
|
+
};
|
|
1683
|
+
while (following) {
|
|
1684
|
+
if (counter++ > 300) {
|
|
1685
|
+
import_logger.Logger.warning(
|
|
1686
|
+
messages.blocks.timeoutFollow(
|
|
1687
|
+
blockId,
|
|
1688
|
+
currentEnv,
|
|
1689
|
+
env.currentProject
|
|
1690
|
+
)
|
|
1691
|
+
);
|
|
1692
|
+
stopFollowing();
|
|
1693
|
+
}
|
|
1694
|
+
await delay.wait();
|
|
1695
|
+
const [lastErr, lastLogs] = following ? await contensis.blocks.GetBlockLogs({
|
|
1696
|
+
blockId,
|
|
1697
|
+
branchId: branch,
|
|
1698
|
+
version,
|
|
1699
|
+
dataCenter
|
|
1700
|
+
}) : [null, null];
|
|
1701
|
+
if (lastLogs) {
|
|
1702
|
+
const difference = (0, import_diff.diffLogStrings)(lastLogs, alreadyShown);
|
|
1703
|
+
if (difference) {
|
|
1704
|
+
if (needsNewLine) {
|
|
1705
|
+
console.log("");
|
|
1706
|
+
}
|
|
1707
|
+
const render = removeTrailingNewline(difference);
|
|
1708
|
+
console.log(log.infoText(render));
|
|
1709
|
+
alreadyShown += `${render}
|
|
1710
|
+
`;
|
|
1711
|
+
needsNewLine = false;
|
|
1712
|
+
} else {
|
|
1713
|
+
process.stdout.write(".");
|
|
1714
|
+
needsNewLine = true;
|
|
1715
|
+
}
|
|
1716
|
+
} else if (lastErr) {
|
|
1717
|
+
process.stdout.write("x");
|
|
1718
|
+
needsNewLine = true;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
};
|
|
1724
|
+
PrintProxies = async (proxyId) => {
|
|
1725
|
+
const { currentEnv, env, log, messages } = this;
|
|
1726
|
+
const contensis = await this.ConnectContensis();
|
|
1727
|
+
if (contensis) {
|
|
1728
|
+
const [err, proxies] = await contensis.proxies.GetProxies(
|
|
1729
|
+
proxyId
|
|
1730
|
+
);
|
|
1731
|
+
if (Array.isArray(proxies)) {
|
|
1732
|
+
this.HandleFormattingAndOutput(proxies, () => {
|
|
1733
|
+
log.success(messages.proxies.list(currentEnv, env.currentProject));
|
|
1734
|
+
for (const { id, name, description, endpoints, version } of proxies) {
|
|
1735
|
+
console.log(
|
|
1736
|
+
` - ${name} [${version.versionNo}] ${id} ${log.infoText`${description}`}`
|
|
1737
|
+
);
|
|
1738
|
+
for (const [language, endpoint] of Object.entries(
|
|
1739
|
+
endpoints
|
|
1740
|
+
))
|
|
1741
|
+
console.log(
|
|
1742
|
+
` - ${log.infoText`language: ${language}
|
|
1743
|
+
server: ${endpoint.server}
|
|
1744
|
+
headers.host: ${endpoint.headers.host}
|
|
1745
|
+
ssl: ${endpoint.ssl}`}`
|
|
1746
|
+
);
|
|
1747
|
+
}
|
|
1061
1748
|
});
|
|
1062
1749
|
}
|
|
1063
1750
|
if (err) {
|
|
1064
|
-
log.error(messages.
|
|
1751
|
+
log.error(messages.proxies.noList(currentEnv, env.currentProject));
|
|
1752
|
+
log.error((0, import_json.jsonFormatter)(err));
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
};
|
|
1756
|
+
PrintRenderers = async (rendererId) => {
|
|
1757
|
+
const { currentEnv, env, log, messages } = this;
|
|
1758
|
+
const contensis = await this.ConnectContensis();
|
|
1759
|
+
if (contensis) {
|
|
1760
|
+
const [err, renderers] = await contensis.renderers.GetRenderers(
|
|
1761
|
+
rendererId
|
|
1762
|
+
);
|
|
1763
|
+
if (Array.isArray(renderers)) {
|
|
1764
|
+
this.HandleFormattingAndOutput(renderers, () => {
|
|
1765
|
+
log.success(messages.renderers.list(currentEnv, env.currentProject));
|
|
1766
|
+
for (const {
|
|
1767
|
+
id,
|
|
1768
|
+
description,
|
|
1769
|
+
assignedContentTypes,
|
|
1770
|
+
rules,
|
|
1771
|
+
version
|
|
1772
|
+
} of renderers) {
|
|
1773
|
+
console.log(
|
|
1774
|
+
` - ${id} [${version.versionNo}] ${log.infoText`${description}`}`
|
|
1775
|
+
);
|
|
1776
|
+
if (assignedContentTypes == null ? void 0 : assignedContentTypes.length)
|
|
1777
|
+
console.log(
|
|
1778
|
+
log.infoText` assignedContentTypes: ${assignedContentTypes.join(
|
|
1779
|
+
", "
|
|
1780
|
+
)}`
|
|
1781
|
+
);
|
|
1782
|
+
for (const rule of rules)
|
|
1783
|
+
if (rule.return)
|
|
1784
|
+
console.log(
|
|
1785
|
+
log.infoText` ${rule.return.endpointId ? "endpointId" : "blockId"}: ${rule.return.endpointId || rule.return.blockId}`
|
|
1786
|
+
);
|
|
1787
|
+
}
|
|
1788
|
+
});
|
|
1789
|
+
}
|
|
1790
|
+
if (err) {
|
|
1791
|
+
log.error(messages.renderers.noList(currentEnv, env.currentProject));
|
|
1065
1792
|
log.error((0, import_json.jsonFormatter)(err));
|
|
1066
1793
|
}
|
|
1067
1794
|
}
|
|
1068
1795
|
};
|
|
1069
1796
|
HandleFormattingAndOutput = (obj, logFn) => {
|
|
1070
1797
|
const { format, log, messages, output } = this;
|
|
1798
|
+
if (!format) {
|
|
1799
|
+
logFn(obj);
|
|
1800
|
+
} else if (format === "csv") {
|
|
1801
|
+
log.raw("");
|
|
1802
|
+
log.raw(log.infoText((0, import_csv.csvFormatter)(obj)));
|
|
1803
|
+
} else if (format === "xml") {
|
|
1804
|
+
log.raw("");
|
|
1805
|
+
log.raw(log.infoText((0, import_xml.xmlFormatter)(obj)));
|
|
1806
|
+
} else if (format === "json") {
|
|
1807
|
+
log.raw("");
|
|
1808
|
+
log.raw(log.infoText((0, import_json.jsonFormatter)(obj)));
|
|
1809
|
+
}
|
|
1810
|
+
log.raw("");
|
|
1071
1811
|
if (output) {
|
|
1072
1812
|
let writeString = "";
|
|
1813
|
+
const isText = !(0, import_util.tryParse)(obj) && typeof obj === "string";
|
|
1073
1814
|
if (format === "csv") {
|
|
1074
1815
|
writeString = (0, import_csv.csvFormatter)(obj);
|
|
1075
1816
|
} else if (format === "xml") {
|
|
1076
1817
|
writeString = (0, import_xml.xmlFormatter)(obj);
|
|
1077
1818
|
} else
|
|
1078
|
-
writeString = (0, import_json.jsonFormatter)(obj);
|
|
1819
|
+
writeString = isText ? obj : (0, import_json.jsonFormatter)(obj);
|
|
1079
1820
|
if (writeString) {
|
|
1080
1821
|
import_fs.default.writeFileSync(output, writeString);
|
|
1081
|
-
log.success(messages.app.fileOutput(format, output));
|
|
1822
|
+
log.success(messages.app.fileOutput(isText ? "text" : format, output));
|
|
1082
1823
|
} else {
|
|
1083
1824
|
log.info(messages.app.noFileOutput());
|
|
1084
1825
|
}
|
|
1085
|
-
} else {
|
|
1086
|
-
if (!format) {
|
|
1087
|
-
logFn(obj);
|
|
1088
|
-
} else if (format === "csv") {
|
|
1089
|
-
log.raw("");
|
|
1090
|
-
log.raw(log.infoText((0, import_csv.csvFormatter)(obj)));
|
|
1091
|
-
} else if (format === "xml") {
|
|
1092
|
-
log.raw("");
|
|
1093
|
-
log.raw(log.infoText((0, import_xml.xmlFormatter)(obj)));
|
|
1094
|
-
} else if (format === "json") {
|
|
1095
|
-
log.raw("");
|
|
1096
|
-
log.raw(log.infoText((0, import_json.jsonFormatter)(obj)));
|
|
1097
|
-
}
|
|
1098
|
-
log.raw("");
|
|
1099
1826
|
}
|
|
1100
1827
|
};
|
|
1101
1828
|
}
|
|
1102
|
-
const cliCommand = (commandArgs, outputOpts
|
|
1829
|
+
const cliCommand = (commandArgs, outputOpts, contensisOpts = {}) => {
|
|
1103
1830
|
return new ContensisCli(["", "", ...commandArgs], outputOpts, contensisOpts);
|
|
1104
1831
|
};
|
|
1105
1832
|
var ContensisCliService_default = ContensisCli;
|