contensis-cli 1.1.2-beta.0 → 1.1.2-beta.10
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/dist/commands/copy.js +70 -0
- package/dist/commands/copy.js.map +7 -0
- package/dist/commands/create.js.map +2 -2
- package/dist/commands/dev.js +11 -4
- package/dist/commands/dev.js.map +2 -2
- package/dist/commands/get.js +1 -0
- package/dist/commands/get.js.map +2 -2
- package/dist/commands/globalOptions.js +24 -3
- package/dist/commands/globalOptions.js.map +2 -2
- package/dist/commands/import.js +1 -6
- package/dist/commands/import.js.map +2 -2
- package/dist/commands/index.js +7 -3
- package/dist/commands/index.js.map +2 -2
- package/dist/factories/RequestHandlerFactory.js +214 -0
- package/dist/factories/RequestHandlerFactory.js.map +7 -0
- package/dist/localisation/en-GB.js +30 -5
- package/dist/localisation/en-GB.js.map +2 -2
- package/dist/mappers/DevRequests-to-RequestHanderCliArgs.js +159 -0
- package/dist/mappers/DevRequests-to-RequestHanderCliArgs.js.map +7 -0
- package/dist/providers/GitHubCliModuleProvider.js +117 -0
- package/dist/providers/GitHubCliModuleProvider.js.map +7 -0
- package/dist/providers/HttpProvider.js +72 -0
- package/dist/providers/HttpProvider.js.map +7 -0
- package/dist/providers/ManifestProvider.js +53 -0
- package/dist/providers/ManifestProvider.js.map +7 -0
- package/dist/providers/file-provider.js +14 -0
- package/dist/providers/file-provider.js.map +2 -2
- package/dist/services/ContensisAuthService.js +19 -11
- package/dist/services/ContensisAuthService.js.map +2 -2
- package/dist/services/ContensisCliService.js +88 -14
- package/dist/services/ContensisCliService.js.map +2 -2
- package/dist/services/ContensisDevService.js +34 -58
- package/dist/services/ContensisDevService.js.map +3 -3
- package/dist/shell.js +1 -0
- package/dist/shell.js.map +2 -2
- package/dist/util/api-ids.js +110 -0
- package/dist/util/api-ids.js.map +7 -0
- package/dist/util/console.printer.js.map +2 -2
- package/dist/util/debug.js +29 -0
- package/dist/util/debug.js.map +7 -0
- package/dist/util/fetch.js +65 -0
- package/dist/util/fetch.js.map +7 -0
- package/dist/util/index.js.map +1 -1
- package/dist/util/logger.js.map +2 -2
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +5 -3
- package/src/commands/copy.ts +79 -0
- package/src/commands/create.ts +0 -1
- package/src/commands/dev.ts +14 -6
- package/src/commands/get.ts +12 -11
- package/src/commands/globalOptions.ts +25 -2
- package/src/commands/import.ts +4 -8
- package/src/commands/index.ts +7 -3
- package/src/factories/RequestHandlerFactory.ts +246 -0
- package/src/localisation/en-GB.ts +55 -12
- package/src/mappers/DevRequests-to-RequestHanderCliArgs.ts +200 -0
- package/src/providers/GitHubCliModuleProvider.ts +127 -0
- package/src/providers/HttpProvider.ts +50 -0
- package/src/providers/ManifestProvider.ts +43 -0
- package/src/providers/file-provider.ts +13 -0
- package/src/services/ContensisAuthService.ts +23 -14
- package/src/services/ContensisCliService.ts +112 -15
- package/src/services/ContensisDevService.ts +52 -87
- package/src/shell.ts +2 -1
- package/src/util/api-ids.ts +111 -0
- package/src/util/console.printer.ts +2 -1
- package/src/util/debug.ts +1 -0
- package/src/util/fetch.ts +74 -0
- package/src/util/index.ts +1 -1
- package/src/util/logger.ts +0 -1
- package/src/version.ts +1 -1
- package/dist/mappers/DevRequests-to-RequestHanderSiteConfigYaml.js +0 -56
- package/dist/mappers/DevRequests-to-RequestHanderSiteConfigYaml.js.map +0 -7
- package/src/mappers/DevRequests-to-RequestHanderSiteConfigYaml.ts +0 -44
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Command, Option } from 'commander';
|
|
2
|
+
import { MigrateRequest } from 'migratortron';
|
|
2
3
|
import { url } from '~/util';
|
|
3
4
|
|
|
4
5
|
// Map various input options into a request to be processed
|
|
5
6
|
// by Migratortron / Contensis import library
|
|
6
|
-
export const mapContensisOpts = (opts: any = {}) => ({
|
|
7
|
+
export const mapContensisOpts = (opts: any = {}): MigrateRequest => ({
|
|
7
8
|
source:
|
|
8
9
|
opts.sourceAlias || opts.sourceProjectId
|
|
9
10
|
? {
|
|
@@ -14,6 +15,8 @@ export const mapContensisOpts = (opts: any = {}) => ({
|
|
|
14
15
|
}
|
|
15
16
|
: undefined,
|
|
16
17
|
models: opts.modelIds,
|
|
18
|
+
copyField: opts.copyField,
|
|
19
|
+
// convert various cli options into MigrateRequest.query format
|
|
17
20
|
query:
|
|
18
21
|
opts.id ||
|
|
19
22
|
opts.entryIds ||
|
|
@@ -23,7 +26,8 @@ export const mapContensisOpts = (opts: any = {}) => ({
|
|
|
23
26
|
opts.paths ||
|
|
24
27
|
opts.assetType ||
|
|
25
28
|
opts.contentType ||
|
|
26
|
-
opts.dataFormat
|
|
29
|
+
opts.dataFormat ||
|
|
30
|
+
opts.deliveryApi
|
|
27
31
|
? {
|
|
28
32
|
assetTypes: opts.assetType,
|
|
29
33
|
contentTypeIds: opts.contentType,
|
|
@@ -33,11 +37,13 @@ export const mapContensisOpts = (opts: any = {}) => ({
|
|
|
33
37
|
includePaths: opts.paths,
|
|
34
38
|
orderBy: opts.orderBy,
|
|
35
39
|
searchTerm: opts.phrase,
|
|
40
|
+
useDelivery: opts.deliveryApi,
|
|
36
41
|
}
|
|
37
42
|
: undefined,
|
|
38
43
|
zenQL: opts.zenql,
|
|
39
44
|
transformGuids: !opts.preserveGuids,
|
|
40
45
|
ignoreErrors: opts.ignoreErrors,
|
|
46
|
+
concurrency: opts.concurrency ? Number(opts.concurrency) : undefined,
|
|
41
47
|
});
|
|
42
48
|
|
|
43
49
|
/* Output options */
|
|
@@ -81,6 +87,11 @@ const sharedSecret = new Option(
|
|
|
81
87
|
);
|
|
82
88
|
|
|
83
89
|
/* Entry get options */
|
|
90
|
+
export const delivery = new Option(
|
|
91
|
+
'-delivery --delivery-api',
|
|
92
|
+
'use delivery api to get the entries'
|
|
93
|
+
);
|
|
94
|
+
|
|
84
95
|
export const zenql = new Option(
|
|
85
96
|
'-q --zenql <zenql>',
|
|
86
97
|
'get entries with a supplied ZenQL statement'
|
|
@@ -121,6 +132,18 @@ export const ignoreErrors = new Option(
|
|
|
121
132
|
'commit the import ignoring any reported errors'
|
|
122
133
|
).default(false);
|
|
123
134
|
|
|
135
|
+
export const outputEntries = new Option(
|
|
136
|
+
'-oe --output-entries <outputEntries>',
|
|
137
|
+
'which details of the entries included in the import to output'
|
|
138
|
+
)
|
|
139
|
+
.choices(['errors', 'changes', 'all'])
|
|
140
|
+
.default('errors');
|
|
141
|
+
|
|
142
|
+
export const concurrency = new Option(
|
|
143
|
+
'-conc --concurrency <concurrency>',
|
|
144
|
+
'the number of entries to load in parallel'
|
|
145
|
+
).default(2);
|
|
146
|
+
|
|
124
147
|
export const addConnectOptions = (program: Command) =>
|
|
125
148
|
program.addOption(alias.hideHelp()).addOption(project.hideHelp());
|
|
126
149
|
|
package/src/commands/import.ts
CHANGED
|
@@ -2,9 +2,11 @@ import { Command, Option } from 'commander';
|
|
|
2
2
|
import { cliCommand } from '~/services/ContensisCliService';
|
|
3
3
|
import {
|
|
4
4
|
commit,
|
|
5
|
+
concurrency,
|
|
5
6
|
getEntryOptions,
|
|
6
7
|
ignoreErrors,
|
|
7
8
|
mapContensisOpts,
|
|
9
|
+
outputEntries,
|
|
8
10
|
} from './globalOptions';
|
|
9
11
|
|
|
10
12
|
export const makeImportCommand = () => {
|
|
@@ -113,14 +115,8 @@ Example call:
|
|
|
113
115
|
'-preserve --preserve-guids',
|
|
114
116
|
'include this flag when you are importing entries that you have previously exported and wish to update'
|
|
115
117
|
)
|
|
116
|
-
.addOption(
|
|
117
|
-
|
|
118
|
-
'-oe --output-entries <outputEntries>',
|
|
119
|
-
'which details of the entries included in the import to output'
|
|
120
|
-
)
|
|
121
|
-
.choices(['errors', 'changes', 'all'])
|
|
122
|
-
.default('errors')
|
|
123
|
-
)
|
|
118
|
+
.addOption(concurrency)
|
|
119
|
+
.addOption(outputEntries)
|
|
124
120
|
.addOption(ignoreErrors)
|
|
125
121
|
.addHelpText(
|
|
126
122
|
'after',
|
package/src/commands/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Command } from 'commander';
|
|
|
2
2
|
import { Logger } from '~/util/logger';
|
|
3
3
|
import { LIB_VERSION } from '~/version';
|
|
4
4
|
import { makeConnectCommand } from './connect';
|
|
5
|
+
import { makeCopyCommand } from './copy';
|
|
5
6
|
import { makeCreateCommand } from './create';
|
|
6
7
|
import { makeDevCommand } from './dev';
|
|
7
8
|
import { makeDiffCommand } from './diff';
|
|
@@ -49,6 +50,9 @@ const commands = () => {
|
|
|
49
50
|
program.addCommand(
|
|
50
51
|
addGlobalOptions(makeCreateCommand()).copyInheritedSettings(program)
|
|
51
52
|
);
|
|
53
|
+
program.addCommand(
|
|
54
|
+
addGlobalOptions(makeCopyCommand()).copyInheritedSettings(program)
|
|
55
|
+
);
|
|
52
56
|
program.addCommand(
|
|
53
57
|
addConnectOptions(
|
|
54
58
|
addAuthenticationOptions(makeDevCommand())
|
|
@@ -58,9 +62,9 @@ const commands = () => {
|
|
|
58
62
|
addGlobalOptions(makeExecuteCommand()).copyInheritedSettings(program)
|
|
59
63
|
);
|
|
60
64
|
program.addCommand(
|
|
61
|
-
addGlobalOptions(
|
|
62
|
-
|
|
63
|
-
)
|
|
65
|
+
addGlobalOptions(addImportOptions(makeDiffCommand())).copyInheritedSettings(
|
|
66
|
+
program
|
|
67
|
+
)
|
|
64
68
|
);
|
|
65
69
|
program.addCommand(
|
|
66
70
|
addGlobalOptions(makeGetCommand()).copyInheritedSettings(program)
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import { createSpinner } from 'nanospinner';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { LogMessages } from '~/localisation/en-GB';
|
|
6
|
+
import GitHubCliModuleProvider from '~/providers/GitHubCliModuleProvider';
|
|
7
|
+
|
|
8
|
+
import ManifestProvider from '~/providers/ManifestProvider';
|
|
9
|
+
import { appRootDir, checkDir, joinPath } from '~/providers/file-provider';
|
|
10
|
+
import { isDebug } from '~/util/debug';
|
|
11
|
+
import { Logger } from '~/util/logger';
|
|
12
|
+
|
|
13
|
+
export class RequestHandlerFactory {
|
|
14
|
+
debug = isDebug();
|
|
15
|
+
log = Logger;
|
|
16
|
+
messages = LogMessages;
|
|
17
|
+
manifest = new ManifestProvider(); // Load cli-manifest.json
|
|
18
|
+
|
|
19
|
+
basePath = path.join(appRootDir);
|
|
20
|
+
name = 'request-handler-localdevelopment';
|
|
21
|
+
cmd = 'Zengenti.Contensis.RequestHandler.LocalDevelopment';
|
|
22
|
+
|
|
23
|
+
prerelease;
|
|
24
|
+
version; // pass in a specific release version to run
|
|
25
|
+
|
|
26
|
+
get exePath() {
|
|
27
|
+
return path.join(this.basePath, `${this.name}-${this.moduleInfo.version}`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get moduleInfo() {
|
|
31
|
+
return (
|
|
32
|
+
this.manifest.getModule(this.name) || {
|
|
33
|
+
github: 'contensis/request-handler-localdevelopment',
|
|
34
|
+
version: '*',
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
constructor(version?: string, prerelease = false) {
|
|
40
|
+
this.prerelease = prerelease;
|
|
41
|
+
this.version = version;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Use the factory to create a request handler instance
|
|
45
|
+
// handling the download and updating of the external binary
|
|
46
|
+
async Create() {
|
|
47
|
+
const { moduleInfo, version } = this;
|
|
48
|
+
const downloadImmediately =
|
|
49
|
+
!moduleInfo?.version || moduleInfo?.version === '*' || this.version;
|
|
50
|
+
|
|
51
|
+
if (downloadImmediately) {
|
|
52
|
+
// Create cli-manifest.json
|
|
53
|
+
this.manifest.writeModule(this.name, this.moduleInfo);
|
|
54
|
+
|
|
55
|
+
// Download for first time use (await)
|
|
56
|
+
await this.CheckUpdate({ verbose: true, version });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Apply any downloaded/pending update so we launch that version
|
|
60
|
+
await this.ApplyUpdate();
|
|
61
|
+
|
|
62
|
+
// Fire an async update check and continue working in the background (do not await)
|
|
63
|
+
if (!downloadImmediately) this.CheckUpdate();
|
|
64
|
+
|
|
65
|
+
// Return a RequestHandler ready to invoke
|
|
66
|
+
return this.CreateInvoke(this);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
CreateInvoke(self = this) {
|
|
70
|
+
// Hoist the vars we need from `this` as we lose scope
|
|
71
|
+
// when the function is returned from the Create() method
|
|
72
|
+
const { debug, log, messages, cmd, exePath } = self;
|
|
73
|
+
|
|
74
|
+
// Invoke request handler method
|
|
75
|
+
return async (args: string[]) => {
|
|
76
|
+
const child = spawn(joinPath(exePath, cmd), args, { stdio: 'inherit' });
|
|
77
|
+
|
|
78
|
+
if (args?.length && debug)
|
|
79
|
+
log.warning(
|
|
80
|
+
`Spawning process with supplied args: ${JSON.stringify(
|
|
81
|
+
child.spawnargs,
|
|
82
|
+
null,
|
|
83
|
+
2
|
|
84
|
+
)}`
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
let isRunning = false;
|
|
88
|
+
|
|
89
|
+
// Log child output through event listeners
|
|
90
|
+
child?.stdout?.on('data', data => {
|
|
91
|
+
isRunning = true;
|
|
92
|
+
log.raw(data);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
child?.stderr?.on('data', data => {
|
|
96
|
+
log.error(data);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
child.on('spawn', () => {
|
|
100
|
+
isRunning = true;
|
|
101
|
+
log.help(messages.devrequests.spawn());
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
child.on('exit', code => {
|
|
105
|
+
isRunning = false;
|
|
106
|
+
|
|
107
|
+
log[code === 0 ? 'success' : 'warning'](
|
|
108
|
+
messages.devrequests.exited(code)
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
child.on('error', error => {
|
|
113
|
+
isRunning = false;
|
|
114
|
+
log.error(messages.devrequests.errored(error));
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
118
|
+
|
|
119
|
+
// keep the method running until we can return
|
|
120
|
+
while (true === true) {
|
|
121
|
+
if (!isRunning) return;
|
|
122
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async CheckUpdate({
|
|
128
|
+
verbose = false,
|
|
129
|
+
version,
|
|
130
|
+
}: { verbose?: boolean; version?: string } = {}) {
|
|
131
|
+
const { cmd, debug, log, manifest, messages, moduleInfo } = this;
|
|
132
|
+
|
|
133
|
+
const github = new GitHubCliModuleProvider(moduleInfo.github);
|
|
134
|
+
|
|
135
|
+
// Find latest version
|
|
136
|
+
const release = await github.FindLatestRelease(version);
|
|
137
|
+
|
|
138
|
+
if (verbose || debug)
|
|
139
|
+
if (release)
|
|
140
|
+
log.info(
|
|
141
|
+
`${messages.devrequests.install.download(
|
|
142
|
+
moduleInfo.github,
|
|
143
|
+
release.tag_name
|
|
144
|
+
)}\n${release.html_url}`
|
|
145
|
+
);
|
|
146
|
+
else
|
|
147
|
+
log.warning(messages.devrequests.install.notFound(moduleInfo.github));
|
|
148
|
+
|
|
149
|
+
const downloadSpecificRelease =
|
|
150
|
+
version && !checkDir('c') && release?.tag_name;
|
|
151
|
+
|
|
152
|
+
// Should we download an update?
|
|
153
|
+
if (
|
|
154
|
+
(release?.tag_name &&
|
|
155
|
+
![moduleInfo.version, moduleInfo.install].includes(release.tag_name)) ||
|
|
156
|
+
downloadSpecificRelease
|
|
157
|
+
) {
|
|
158
|
+
// Download platform-specific release asset
|
|
159
|
+
const downloadPath = path.join(
|
|
160
|
+
this.basePath,
|
|
161
|
+
`${this.name}-${release.tag_name}`
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// add spinner while downloading
|
|
165
|
+
const spinner = createSpinner(
|
|
166
|
+
messages.devrequests.install.downloading(
|
|
167
|
+
moduleInfo.github,
|
|
168
|
+
release.tag_name
|
|
169
|
+
)
|
|
170
|
+
);
|
|
171
|
+
if (verbose || debug) {
|
|
172
|
+
spinner.start();
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
await github.DownloadRelease(release, {
|
|
176
|
+
cmd,
|
|
177
|
+
path: downloadPath,
|
|
178
|
+
// Map NodeJS os platform to release asset name
|
|
179
|
+
platforms: [
|
|
180
|
+
['win32', 'win-x64'],
|
|
181
|
+
['darwin', 'osx-x64'],
|
|
182
|
+
['linux', 'linux-x64'],
|
|
183
|
+
],
|
|
184
|
+
});
|
|
185
|
+
} catch (ex: any) {
|
|
186
|
+
spinner.error();
|
|
187
|
+
log.error(
|
|
188
|
+
messages.devrequests.install.downloadFail(
|
|
189
|
+
moduleInfo.github,
|
|
190
|
+
release.tag_name
|
|
191
|
+
),
|
|
192
|
+
ex
|
|
193
|
+
);
|
|
194
|
+
} finally {
|
|
195
|
+
if (verbose || debug)
|
|
196
|
+
spinner.success({
|
|
197
|
+
text: messages.devrequests.install.downloaded(
|
|
198
|
+
moduleInfo.github,
|
|
199
|
+
release.tag_name
|
|
200
|
+
),
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
if (!version) {
|
|
204
|
+
// Update module info with downloaded release
|
|
205
|
+
this.moduleInfo.install = release.tag_name;
|
|
206
|
+
// Write module info update to manifest so it installs on next invoke
|
|
207
|
+
manifest.writeModule(this.name, this.moduleInfo);
|
|
208
|
+
} else {
|
|
209
|
+
// Set module version in memory so the request handler
|
|
210
|
+
// will be invoked with this version this time only
|
|
211
|
+
this.moduleInfo.version = release.tag_name;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async ApplyUpdate() {
|
|
218
|
+
const { manifest, messages, moduleInfo } = this;
|
|
219
|
+
|
|
220
|
+
if (moduleInfo.install && moduleInfo.version !== moduleInfo.install) {
|
|
221
|
+
let { apply } =
|
|
222
|
+
moduleInfo.version === '*'
|
|
223
|
+
? { apply: true }
|
|
224
|
+
: await inquirer.prompt({
|
|
225
|
+
name: 'apply',
|
|
226
|
+
type: 'confirm',
|
|
227
|
+
message: messages.devrequests.install.applyUpdate(
|
|
228
|
+
moduleInfo.install,
|
|
229
|
+
moduleInfo.version
|
|
230
|
+
),
|
|
231
|
+
default: 'Y',
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
if (apply) {
|
|
235
|
+
moduleInfo.version = moduleInfo.install;
|
|
236
|
+
delete moduleInfo.install;
|
|
237
|
+
manifest.writeModule(this.name, this.moduleInfo);
|
|
238
|
+
|
|
239
|
+
// TODO: clean up user folder by deleting old version(s)}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export const createRequestHandler = (version?: string) =>
|
|
246
|
+
new RequestHandlerFactory(version).Create();
|
|
@@ -341,10 +341,36 @@ export const LogMessages = {
|
|
|
341
341
|
return Logger.infoText(status);
|
|
342
342
|
}
|
|
343
343
|
},
|
|
344
|
-
get: (
|
|
345
|
-
|
|
344
|
+
get: (
|
|
345
|
+
id: string,
|
|
346
|
+
branch: string,
|
|
347
|
+
version: string,
|
|
348
|
+
env: string,
|
|
349
|
+
projectId?: string
|
|
350
|
+
) =>
|
|
351
|
+
`[${env}] ${
|
|
352
|
+
version && version !== 'latest'
|
|
353
|
+
? `Found v${version}`
|
|
354
|
+
: 'Latest block versions'
|
|
355
|
+
} for ${Logger.infoText(`${branch}/`)}${Logger.highlightText(
|
|
356
|
+
id
|
|
357
|
+
)} in project ${projectId}\n`,
|
|
358
|
+
noGet: (
|
|
359
|
+
id: string,
|
|
360
|
+
branch: string,
|
|
361
|
+
version: string,
|
|
362
|
+
env: string,
|
|
363
|
+
projectId?: string
|
|
364
|
+
) =>
|
|
365
|
+
`[${env}] Did not find ${
|
|
366
|
+
version ? `v${version}` : 'any block versions'
|
|
367
|
+
} for ${Logger.highlightText(id)} in branch ${Logger.infoText(
|
|
368
|
+
branch
|
|
369
|
+
)} in ${Logger.infoText(projectId)} project`,
|
|
370
|
+
noGetTip: () =>
|
|
371
|
+
`Check the available blocks and branches in this project by running "list blocks"`,
|
|
346
372
|
list: (env: string, projectId?: string) =>
|
|
347
|
-
`[${env}] Blocks in project ${projectId}
|
|
373
|
+
`[${env}] Blocks in project ${projectId}\n`,
|
|
348
374
|
noList: (env: string, projectId?: string) =>
|
|
349
375
|
`[${env}] Cannot retrieve blocks in project ${projectId}`,
|
|
350
376
|
getLogs: (id: string, branch: string, env: string, projectId?: string) =>
|
|
@@ -367,15 +393,6 @@ export const LogMessages = {
|
|
|
367
393
|
`[${env}] Unable to push block ${Logger.highlightText(
|
|
368
394
|
id
|
|
369
395
|
)} in project ${projectId}`,
|
|
370
|
-
latestVersion: (
|
|
371
|
-
version: string,
|
|
372
|
-
id: string,
|
|
373
|
-
env: string,
|
|
374
|
-
projectId?: string
|
|
375
|
-
) =>
|
|
376
|
-
`[${env}] Found latest block version ${Logger.highlightText(
|
|
377
|
-
id
|
|
378
|
-
)} in project ${projectId} ${Logger.highlightText(version)}`,
|
|
379
396
|
failedParsingVersion: () =>
|
|
380
397
|
`Did not find a "version.versionNo" in response`,
|
|
381
398
|
actionComplete: (
|
|
@@ -586,4 +603,30 @@ export const LogMessages = {
|
|
|
586
603
|
'my-awesome-website'
|
|
587
604
|
)}`,
|
|
588
605
|
},
|
|
606
|
+
devrequests: {
|
|
607
|
+
install: {
|
|
608
|
+
notFound: (repo: string) =>
|
|
609
|
+
`Could not find a release in ${repo} repo - please check github`,
|
|
610
|
+
download: (repo: string, version: string) => `Found release ${version}`,
|
|
611
|
+
downloading: (repo: string, version: string) =>
|
|
612
|
+
`Downloading ${repo} ${version}`,
|
|
613
|
+
downloadFail: (repo: string, version: string) =>
|
|
614
|
+
`Problem downloading release ${version} from ${repo}`,
|
|
615
|
+
downloaded: (repo: string, version: string) =>
|
|
616
|
+
`Downloaded ${repo} ${version}`,
|
|
617
|
+
applyUpdate: (version: string, existing: string) =>
|
|
618
|
+
`Use updated version ${version} ${Logger.infoText(
|
|
619
|
+
`(replaces ${existing})`
|
|
620
|
+
)}?`,
|
|
621
|
+
},
|
|
622
|
+
launch: () => `Launching request handler for local development`,
|
|
623
|
+
overrideBlock: () => `Which block will you be running?`,
|
|
624
|
+
overrideUri: () => `How to access your development site`,
|
|
625
|
+
spawn: () =>
|
|
626
|
+
`If you see a firewall popup requesting network access, it is safe to approve`,
|
|
627
|
+
exited: (code: number | null) =>
|
|
628
|
+
`Request handler exited with code ${code}\n`,
|
|
629
|
+
errored: (error: Error) =>
|
|
630
|
+
`Could not launch request handler due to error \n${error}`,
|
|
631
|
+
},
|
|
589
632
|
};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { ContensisMigrationService } from 'migratortron';
|
|
2
|
+
import PQueue from 'p-queue';
|
|
3
|
+
import ContensisCli from '~/services/ContensisCliService';
|
|
4
|
+
|
|
5
|
+
type EndpointJson = {
|
|
6
|
+
id: string;
|
|
7
|
+
path: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type BlockJson = {
|
|
11
|
+
id: string;
|
|
12
|
+
baseUri: string;
|
|
13
|
+
staticPaths: string[];
|
|
14
|
+
endpoints: EndpointJson[];
|
|
15
|
+
versionNo: number;
|
|
16
|
+
branch: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type RendererJson = {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
rules: RendererRuleJson[];
|
|
23
|
+
assignedContentTypes: string[];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type RendererRuleJson = {
|
|
27
|
+
return?: {
|
|
28
|
+
blockId?: string;
|
|
29
|
+
endpointId?: string | null;
|
|
30
|
+
version?: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
interface ISiteConfigYaml {
|
|
34
|
+
alias: string;
|
|
35
|
+
projectId: string;
|
|
36
|
+
iisHostname: string;
|
|
37
|
+
podClusterId: string;
|
|
38
|
+
accessToken: string; // needed?
|
|
39
|
+
clientId: string;
|
|
40
|
+
sharedSecret: string;
|
|
41
|
+
blocks: BlockJson[];
|
|
42
|
+
renderers: RendererJson[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
class RequestHandlerArgs {
|
|
46
|
+
private cli;
|
|
47
|
+
args?: string[];
|
|
48
|
+
siteConfig?: ISiteConfigYaml;
|
|
49
|
+
|
|
50
|
+
constructor(cli: ContensisCli) {
|
|
51
|
+
this.cli = cli;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Create = async () => {
|
|
55
|
+
this.siteConfig = await this.buildSiteConfig();
|
|
56
|
+
await this.cli.Login(this.cli.env.lastUserId, { silent: true }); // to hydrate the auth service
|
|
57
|
+
this.args = this.getArgs();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
buildSiteConfig = async () => {
|
|
61
|
+
const { currentEnv, currentProject, env, log, messages, urls } = this.cli;
|
|
62
|
+
const contensis = await this.cli.ConnectContensis();
|
|
63
|
+
|
|
64
|
+
const siteConfig: ISiteConfigYaml = {
|
|
65
|
+
alias: currentEnv,
|
|
66
|
+
projectId: currentProject,
|
|
67
|
+
iisHostname: urls?.iisPreviewWeb.split('//')[1] || '',
|
|
68
|
+
podClusterId: 'hq',
|
|
69
|
+
accessToken: '',
|
|
70
|
+
clientId: '',
|
|
71
|
+
sharedSecret: '',
|
|
72
|
+
blocks: [],
|
|
73
|
+
renderers: [],
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const getBlocks = async (contensis: ContensisMigrationService) => {
|
|
77
|
+
const [err, blocksRaw] = await contensis.blocks.GetBlocks();
|
|
78
|
+
if (err)
|
|
79
|
+
log.error(messages.blocks.noList(currentEnv, env.currentProject));
|
|
80
|
+
|
|
81
|
+
// const blocksRaw = await cli.PrintBlocks();
|
|
82
|
+
|
|
83
|
+
const blocks: BlockJson[] = [];
|
|
84
|
+
const queue = new PQueue({ concurrency: 4 });
|
|
85
|
+
for (const block of blocksRaw || []) {
|
|
86
|
+
queue.add(async () => {
|
|
87
|
+
// Retrieve block version
|
|
88
|
+
const [err, versions] = await contensis.blocks.GetBlockVersions(
|
|
89
|
+
block.id,
|
|
90
|
+
'default',
|
|
91
|
+
'latest'
|
|
92
|
+
);
|
|
93
|
+
if (err || versions?.length === 0)
|
|
94
|
+
log.warning(
|
|
95
|
+
messages.blocks.noGet(
|
|
96
|
+
block.id,
|
|
97
|
+
'default',
|
|
98
|
+
'latest',
|
|
99
|
+
currentEnv,
|
|
100
|
+
env.currentProject
|
|
101
|
+
)
|
|
102
|
+
);
|
|
103
|
+
if (versions?.[0]) {
|
|
104
|
+
const v = versions[0];
|
|
105
|
+
blocks.push({
|
|
106
|
+
id: v.id,
|
|
107
|
+
baseUri: v.previewUrl,
|
|
108
|
+
staticPaths: v.staticPaths,
|
|
109
|
+
endpoints: v.endpoints,
|
|
110
|
+
versionNo: v.version.versionNo,
|
|
111
|
+
branch: v.source.branch,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
await queue.onIdle();
|
|
118
|
+
return blocks;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
if (contensis) {
|
|
122
|
+
const [blocks, renderers] = await Promise.all([
|
|
123
|
+
getBlocks(contensis),
|
|
124
|
+
contensis.renderers.GetRenderers(),
|
|
125
|
+
]);
|
|
126
|
+
|
|
127
|
+
siteConfig.blocks = blocks;
|
|
128
|
+
siteConfig.renderers = renderers?.[1]
|
|
129
|
+
?.filter(r => blocks.find(b => b.id === r.id))
|
|
130
|
+
.map(r => ({
|
|
131
|
+
id: r.id,
|
|
132
|
+
name: r.name,
|
|
133
|
+
assignedContentTypes: r.assignedContentTypes,
|
|
134
|
+
rules: r.rules,
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
return siteConfig;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
getArgs = (overrideArgs: string[] = []) => {
|
|
141
|
+
const args = overrideArgs
|
|
142
|
+
? typeof overrideArgs?.[0] === 'string' &&
|
|
143
|
+
overrideArgs[0].includes(' ', 2)
|
|
144
|
+
? overrideArgs[0].split(' ')
|
|
145
|
+
: overrideArgs
|
|
146
|
+
: []; // args could be [ '-c .\\site_config.yaml' ] or [ '-c', '.\\site_config.yaml' ]
|
|
147
|
+
|
|
148
|
+
const { cli, siteConfig } = this;
|
|
149
|
+
if (siteConfig) {
|
|
150
|
+
// Add required args
|
|
151
|
+
if (!args.find(a => a === '--alias'))
|
|
152
|
+
args.push('--alias', cli.currentEnv);
|
|
153
|
+
if (!args.find(a => a === '--project-api-id'))
|
|
154
|
+
args.push('--project-api-id', cli.currentProject);
|
|
155
|
+
if (!args.find(a => a === '--iis-hostname'))
|
|
156
|
+
args.push('--iis-hostname', siteConfig.iisHostname);
|
|
157
|
+
if (!args.find(a => a === '--pod-cluster-id'))
|
|
158
|
+
args.push('--pod-cluster-id', siteConfig.podClusterId);
|
|
159
|
+
if (!args.find(a => a === '--blocks-json'))
|
|
160
|
+
args.push('--blocks-json', JSON.stringify(siteConfig.blocks));
|
|
161
|
+
if (!args.find(a => a === '--renderers-json'))
|
|
162
|
+
args.push('--renderers-json', JSON.stringify(siteConfig.renderers));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const client = cli.auth?.clientDetails;
|
|
166
|
+
if (client) {
|
|
167
|
+
if (!args.find(a => a === '--client-id') && 'clientId' in client)
|
|
168
|
+
args.push('--client-id', client.clientId);
|
|
169
|
+
if (!args.find(a => a === '--client-secret') && 'clientSecret' in client)
|
|
170
|
+
args.push('--client-secret', client.clientSecret);
|
|
171
|
+
if (!args.find(a => a === '--username') && 'username' in client)
|
|
172
|
+
args.push('--username', client.username);
|
|
173
|
+
if (!args.find(a => a === '--password') && 'password' in client)
|
|
174
|
+
args.push('--password', client.password);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return args;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
overrideBlock = (blockId: string, overrideUri: string) => {
|
|
181
|
+
if (blockId && blockId !== 'none') {
|
|
182
|
+
const blockIndex = this.siteConfig?.blocks.findIndex(
|
|
183
|
+
b => b.id.toLowerCase() === blockId.toLowerCase()
|
|
184
|
+
);
|
|
185
|
+
if (
|
|
186
|
+
typeof blockIndex === 'number' &&
|
|
187
|
+
!isNaN(blockIndex) &&
|
|
188
|
+
this.siteConfig?.blocks[blockIndex]
|
|
189
|
+
) {
|
|
190
|
+
this.siteConfig.blocks[blockIndex].baseUri = overrideUri;
|
|
191
|
+
// this.siteConfig.blocks[blockIndex].staticPaths.push(
|
|
192
|
+
// ...['/static/*', '/image-library/*']
|
|
193
|
+
// );
|
|
194
|
+
this.siteConfig.blocks[blockIndex].staticPaths.push('/*.js');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export default RequestHandlerArgs;
|