contensis-cli 1.1.2-beta.3 → 1.1.2-beta.5
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/mappers/DevRequests-to-RequestHanderCliArgs.js +46 -28
- package/dist/mappers/DevRequests-to-RequestHanderCliArgs.js.map +3 -3
- package/dist/services/ContensisCliService.js +7 -0
- package/dist/services/ContensisCliService.js.map +2 -2
- package/dist/util/api-ids.js +110 -0
- package/dist/util/api-ids.js.map +7 -0
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -3
- package/src/mappers/DevRequests-to-RequestHanderCliArgs.ts +55 -34
- package/src/services/ContensisCliService.ts +9 -0
- package/src/util/api-ids.ts +111 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var api_ids_exports = {};
|
|
20
|
+
__export(api_ids_exports, {
|
|
21
|
+
isApiId: () => isApiId,
|
|
22
|
+
sanitiseId: () => sanitiseId,
|
|
23
|
+
sanitiseIds: () => sanitiseIds,
|
|
24
|
+
toApiId: () => toApiId
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(api_ids_exports);
|
|
27
|
+
const sanitiseId = (id) => id.split(".").map((part) => toApiId(part, "camelCase", true)).join(".");
|
|
28
|
+
const sanitiseIds = (arr) => arr.map(sanitiseId);
|
|
29
|
+
function isApiId(id, mode) {
|
|
30
|
+
if (!id) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
const validChars = mode === "camelCase" ? /[^a-zA-Z0-9]/g : /[^a-z0-9-]/g;
|
|
34
|
+
if (id !== id.replace(validChars, "")) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (!id.substr(0, 1).replace(/[^a-z]/g, "")) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
function toApiId(name, mode, isId) {
|
|
43
|
+
if (!name) {
|
|
44
|
+
return name;
|
|
45
|
+
}
|
|
46
|
+
const validChars = mode === "camelCase" ? /[^a-zA-Z0-9 ]/g : /[^a-zA-Z0-9 -]/g;
|
|
47
|
+
let id = name.replace(validChars, "");
|
|
48
|
+
id = id.replace(/-/g, " ");
|
|
49
|
+
id = id.trim();
|
|
50
|
+
const noStart = "0123456789 ".split("");
|
|
51
|
+
id = id.split("").reduce(
|
|
52
|
+
(prev, char) => prev || !noStart.includes(char) ? prev + char : prev,
|
|
53
|
+
""
|
|
54
|
+
);
|
|
55
|
+
return mode === "camelCase" ? toCamelCase(id, isId) : toSnakeCase(id);
|
|
56
|
+
}
|
|
57
|
+
function toSnakeCase(sentence) {
|
|
58
|
+
sentence = (sentence || "").trim();
|
|
59
|
+
if (!sentence) {
|
|
60
|
+
return sentence;
|
|
61
|
+
}
|
|
62
|
+
sentence = sentence.toLowerCase();
|
|
63
|
+
return sentence.split(" ").filter((w) => !!w).join("-");
|
|
64
|
+
}
|
|
65
|
+
function toCamelCase(sentence, isId) {
|
|
66
|
+
sentence = (sentence || "").trim();
|
|
67
|
+
if (!sentence) {
|
|
68
|
+
return sentence;
|
|
69
|
+
}
|
|
70
|
+
if (sentence.length < 2) {
|
|
71
|
+
return sentence.toLowerCase();
|
|
72
|
+
}
|
|
73
|
+
const words = sentence.split(" ");
|
|
74
|
+
if (isId && words.length === 1) {
|
|
75
|
+
return words[0].substr(0, 1).toLowerCase() + words[0].substr(1);
|
|
76
|
+
}
|
|
77
|
+
const result = words.filter((w) => !!w).map(
|
|
78
|
+
(w, index) => index === 0 ? firstWordToCamelCase(w) : wordToCamelCase(w)
|
|
79
|
+
).join("");
|
|
80
|
+
return result.split(".").map((w, index) => index === 0 ? w : wordToCamelCase(w)).join(".");
|
|
81
|
+
}
|
|
82
|
+
function firstWordToCamelCase(word) {
|
|
83
|
+
return isUpperCase(word) ? word.toLowerCase() : lowerCaseInitialCapitalLettersExceptLast(word);
|
|
84
|
+
}
|
|
85
|
+
function wordToCamelCase(word) {
|
|
86
|
+
return word.substr(0, 1).toUpperCase() + word.substr(1);
|
|
87
|
+
}
|
|
88
|
+
function lowerCaseInitialCapitalLettersExceptLast(value) {
|
|
89
|
+
return value.split("").reduce((prev, char, index) => {
|
|
90
|
+
if (index === 0) {
|
|
91
|
+
char = char.toLowerCase();
|
|
92
|
+
} else if (isUpperCase(char)) {
|
|
93
|
+
if (index + 1 < value.length && isUpperCase(value.charAt(index + 1))) {
|
|
94
|
+
char = char.toLowerCase();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return prev + char;
|
|
98
|
+
}, "");
|
|
99
|
+
}
|
|
100
|
+
function isUpperCase(value) {
|
|
101
|
+
return value === value.toUpperCase();
|
|
102
|
+
}
|
|
103
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
+
0 && (module.exports = {
|
|
105
|
+
isApiId,
|
|
106
|
+
sanitiseId,
|
|
107
|
+
sanitiseIds,
|
|
108
|
+
toApiId
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=api-ids.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/util/api-ids.ts"],
|
|
4
|
+
"sourcesContent": ["export const sanitiseId = (id: string) =>\n id\n .split('.')\n .map(part => toApiId(part, 'camelCase', true))\n .join('.');\n\nexport const sanitiseIds = (arr: string[]) => arr.map(sanitiseId);\n\n// borrowed from packages\\contensis\\components\\app\\src\\utils.ts\n\nexport function isApiId(id: string, mode: 'camelCase' | 'snake-case'): boolean {\n if (!id) {\n return false;\n }\n const validChars = mode === 'camelCase' ? /[^a-zA-Z0-9]/g : /[^a-z0-9-]/g;\n if (id !== id.replace(validChars, '')) {\n return false;\n }\n if (!id.substr(0, 1).replace(/[^a-z]/g, '')) {\n return false;\n }\n return true;\n}\n\nexport function toApiId(\n name: string,\n mode: 'camelCase' | 'snake-case',\n isId: boolean\n) {\n if (!name) {\n return name;\n }\n const validChars =\n mode === 'camelCase' ? /[^a-zA-Z0-9 ]/g : /[^a-zA-Z0-9 -]/g;\n let id = name.replace(validChars, '');\n id = id.replace(/-/g, ' ');\n id = id.trim();\n\n const noStart = '0123456789 '.split('');\n id = id\n .split('')\n .reduce(\n (prev, char) => (prev || !noStart.includes(char) ? prev + char : prev),\n ''\n );\n return mode === 'camelCase' ? toCamelCase(id, isId) : toSnakeCase(id);\n}\n\nfunction toSnakeCase(sentence: string): string {\n sentence = (sentence || '').trim();\n if (!sentence) {\n return sentence;\n }\n sentence = sentence.toLowerCase();\n return sentence\n .split(' ')\n .filter(w => !!w)\n .join('-');\n}\n\nfunction toCamelCase(sentence: string, isId: boolean): string {\n sentence = (sentence || '').trim();\n if (!sentence) {\n return sentence;\n }\n if (sentence.length < 2) {\n return sentence.toLowerCase();\n }\n const words = sentence.split(' ');\n if (isId && words.length === 1) {\n return words[0].substr(0, 1).toLowerCase() + words[0].substr(1);\n }\n const result = words\n .filter(w => !!w)\n .map((w, index) =>\n index === 0 ? firstWordToCamelCase(w) : wordToCamelCase(w)\n )\n .join('');\n\n return result\n .split('.')\n .map((w, index) => (index === 0 ? w : wordToCamelCase(w)))\n .join('.');\n}\n\nfunction firstWordToCamelCase(word: string) {\n return isUpperCase(word)\n ? word.toLowerCase()\n : lowerCaseInitialCapitalLettersExceptLast(word);\n}\n\nfunction wordToCamelCase(word: string) {\n return word.substr(0, 1).toUpperCase() + word.substr(1);\n}\n\nfunction lowerCaseInitialCapitalLettersExceptLast(value: string): string {\n return value.split('').reduce((prev, char, index) => {\n if (index === 0) {\n char = char.toLowerCase();\n } else if (isUpperCase(char)) {\n if (index + 1 < value.length && isUpperCase(value.charAt(index + 1))) {\n char = char.toLowerCase();\n }\n }\n return prev + char;\n }, '');\n}\n\nfunction isUpperCase(value: string): boolean {\n return value === value.toUpperCase();\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,aAAa,CAAC,OACzB,GACG,MAAM,GAAG,EACT,IAAI,UAAQ,QAAQ,MAAM,aAAa,IAAI,CAAC,EAC5C,KAAK,GAAG;AAEN,MAAM,cAAc,CAAC,QAAkB,IAAI,IAAI,UAAU;AAIzD,SAAS,QAAQ,IAAY,MAA2C;AAC7E,MAAI,CAAC,IAAI;AACP,WAAO;AAAA,EACT;AACA,QAAM,aAAa,SAAS,cAAc,kBAAkB;AAC5D,MAAI,OAAO,GAAG,QAAQ,YAAY,EAAE,GAAG;AACrC,WAAO;AAAA,EACT;AACA,MAAI,CAAC,GAAG,OAAO,GAAG,CAAC,EAAE,QAAQ,WAAW,EAAE,GAAG;AAC3C,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEO,SAAS,QACd,MACA,MACA,MACA;AACA,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AACA,QAAM,aACJ,SAAS,cAAc,mBAAmB;AAC5C,MAAI,KAAK,KAAK,QAAQ,YAAY,EAAE;AACpC,OAAK,GAAG,QAAQ,MAAM,GAAG;AACzB,OAAK,GAAG,KAAK;AAEb,QAAM,UAAU,cAAc,MAAM,EAAE;AACtC,OAAK,GACF,MAAM,EAAE,EACR;AAAA,IACC,CAAC,MAAM,SAAU,QAAQ,CAAC,QAAQ,SAAS,IAAI,IAAI,OAAO,OAAO;AAAA,IACjE;AAAA,EACF;AACF,SAAO,SAAS,cAAc,YAAY,IAAI,IAAI,IAAI,YAAY,EAAE;AACtE;AAEA,SAAS,YAAY,UAA0B;AAC7C,cAAY,YAAY,IAAI,KAAK;AACjC,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AACA,aAAW,SAAS,YAAY;AAChC,SAAO,SACJ,MAAM,GAAG,EACT,OAAO,OAAK,CAAC,CAAC,CAAC,EACf,KAAK,GAAG;AACb;AAEA,SAAS,YAAY,UAAkB,MAAuB;AAC5D,cAAY,YAAY,IAAI,KAAK;AACjC,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AACA,MAAI,SAAS,SAAS,GAAG;AACvB,WAAO,SAAS,YAAY;AAAA,EAC9B;AACA,QAAM,QAAQ,SAAS,MAAM,GAAG;AAChC,MAAI,QAAQ,MAAM,WAAW,GAAG;AAC9B,WAAO,MAAM,GAAG,OAAO,GAAG,CAAC,EAAE,YAAY,IAAI,MAAM,GAAG,OAAO,CAAC;AAAA,EAChE;AACA,QAAM,SAAS,MACZ,OAAO,OAAK,CAAC,CAAC,CAAC,EACf;AAAA,IAAI,CAAC,GAAG,UACP,UAAU,IAAI,qBAAqB,CAAC,IAAI,gBAAgB,CAAC;AAAA,EAC3D,EACC,KAAK,EAAE;AAEV,SAAO,OACJ,MAAM,GAAG,EACT,IAAI,CAAC,GAAG,UAAW,UAAU,IAAI,IAAI,gBAAgB,CAAC,CAAE,EACxD,KAAK,GAAG;AACb;AAEA,SAAS,qBAAqB,MAAc;AAC1C,SAAO,YAAY,IAAI,IACnB,KAAK,YAAY,IACjB,yCAAyC,IAAI;AACnD;AAEA,SAAS,gBAAgB,MAAc;AACrC,SAAO,KAAK,OAAO,GAAG,CAAC,EAAE,YAAY,IAAI,KAAK,OAAO,CAAC;AACxD;AAEA,SAAS,yCAAyC,OAAuB;AACvE,SAAO,MAAM,MAAM,EAAE,EAAE,OAAO,CAAC,MAAM,MAAM,UAAU;AACnD,QAAI,UAAU,GAAG;AACf,aAAO,KAAK,YAAY;AAAA,IAC1B,WAAW,YAAY,IAAI,GAAG;AAC5B,UAAI,QAAQ,IAAI,MAAM,UAAU,YAAY,MAAM,OAAO,QAAQ,CAAC,CAAC,GAAG;AACpE,eAAO,KAAK,YAAY;AAAA,MAC1B;AAAA,IACF;AACA,WAAO,OAAO;AAAA,EAChB,GAAG,EAAE;AACP;AAEA,SAAS,YAAY,OAAwB;AAC3C,SAAO,UAAU,MAAM,YAAY;AACrC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/version.js
CHANGED
|
@@ -21,7 +21,7 @@ __export(version_exports, {
|
|
|
21
21
|
LIB_VERSION: () => LIB_VERSION
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(version_exports);
|
|
24
|
-
const LIB_VERSION = "1.1.2-beta.
|
|
24
|
+
const LIB_VERSION = "1.1.2-beta.5";
|
|
25
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
26
|
0 && (module.exports = {
|
|
27
27
|
LIB_VERSION
|
package/dist/version.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/version.ts"],
|
|
4
|
-
"sourcesContent": ["export const LIB_VERSION = \"1.1.2-beta.
|
|
4
|
+
"sourcesContent": ["export const LIB_VERSION = \"1.1.2-beta.5\";\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "contensis-cli",
|
|
3
|
-
"version": "1.1.2-beta.
|
|
3
|
+
"version": "1.1.2-beta.5",
|
|
4
4
|
"description": "A fully featured Contensis command line interface with a shell UI provides simple and intuitive ways to manage or profile your content in any NodeJS terminal.",
|
|
5
5
|
"repository": "https://github.com/contensis/cli",
|
|
6
6
|
"homepage": "https://github.com/contensis/cli/tree/main/packages/contensis-cli#readme",
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"app-root-path": "^3.1.0",
|
|
29
29
|
"chalk": "^4.1.2",
|
|
30
30
|
"commander": "^9.4.1",
|
|
31
|
-
"contensis-management-api": "^2.1.2",
|
|
32
31
|
"csv": "^6.1.0",
|
|
33
32
|
"dayjs": "^1.11.6",
|
|
34
33
|
"diff": "^5.1.0",
|
|
@@ -40,7 +39,7 @@
|
|
|
40
39
|
"jsonpath-mapper": "^1.1.0",
|
|
41
40
|
"keytar": "^7.9.0",
|
|
42
41
|
"lodash": "^4.17.21",
|
|
43
|
-
"migratortron": "^1.0.0-beta.
|
|
42
|
+
"migratortron": "^1.0.0-beta.40",
|
|
44
43
|
"nanospinner": "^1.1.0",
|
|
45
44
|
"node-fetch": "^2.6.7",
|
|
46
45
|
"parse-git-config": "^3.0.0",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ContensisMigrationService } from 'migratortron';
|
|
2
|
+
import PQueue from 'p-queue';
|
|
2
3
|
import ContensisCli from '~/services/ContensisCliService';
|
|
3
4
|
|
|
4
5
|
type EndpointJson = {
|
|
@@ -32,6 +33,8 @@ type RendererRuleJson = {
|
|
|
32
33
|
interface ISiteConfigYaml {
|
|
33
34
|
alias: string;
|
|
34
35
|
projectId: string;
|
|
36
|
+
iisHostname: string;
|
|
37
|
+
podClusterId: string;
|
|
35
38
|
accessToken: string; // needed?
|
|
36
39
|
clientId: string;
|
|
37
40
|
sharedSecret: string;
|
|
@@ -55,10 +58,14 @@ class RequestHandlerArgs {
|
|
|
55
58
|
};
|
|
56
59
|
|
|
57
60
|
buildSiteConfig = async () => {
|
|
58
|
-
const { currentEnv, currentProject, env, log, messages } = this.cli;
|
|
61
|
+
const { currentEnv, currentProject, env, log, messages, urls } = this.cli;
|
|
62
|
+
const contensis = await this.cli.ConnectContensis();
|
|
63
|
+
|
|
59
64
|
const siteConfig: ISiteConfigYaml = {
|
|
60
65
|
alias: currentEnv,
|
|
61
66
|
projectId: currentProject,
|
|
67
|
+
iisHostname: urls?.iisPreviewWeb.split('//')[1] || '',
|
|
68
|
+
podClusterId: 'hq',
|
|
62
69
|
accessToken: '',
|
|
63
70
|
clientId: '',
|
|
64
71
|
sharedSecret: '',
|
|
@@ -74,39 +81,43 @@ class RequestHandlerArgs {
|
|
|
74
81
|
// const blocksRaw = await cli.PrintBlocks();
|
|
75
82
|
|
|
76
83
|
const blocks: BlockJson[] = [];
|
|
84
|
+
const queue = new PQueue({ concurrency: 4 });
|
|
77
85
|
for (const block of blocksRaw || []) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (err || versions?.length === 0)
|
|
85
|
-
log.warning(
|
|
86
|
-
messages.blocks.noGet(
|
|
87
|
-
block.id,
|
|
88
|
-
'default',
|
|
89
|
-
'latest',
|
|
90
|
-
currentEnv,
|
|
91
|
-
env.currentProject
|
|
92
|
-
)
|
|
86
|
+
queue.add(async () => {
|
|
87
|
+
// Retrieve block version
|
|
88
|
+
const [err, versions] = await contensis.blocks.GetBlockVersions(
|
|
89
|
+
block.id,
|
|
90
|
+
'default',
|
|
91
|
+
'latest'
|
|
93
92
|
);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
+
});
|
|
105
115
|
}
|
|
116
|
+
|
|
117
|
+
await queue.onIdle();
|
|
106
118
|
return blocks;
|
|
107
119
|
};
|
|
108
120
|
|
|
109
|
-
const contensis = await this.cli.ConnectContensis();
|
|
110
121
|
if (contensis) {
|
|
111
122
|
const [blocks, renderers] = await Promise.all([
|
|
112
123
|
getBlocks(contensis),
|
|
@@ -114,12 +125,14 @@ class RequestHandlerArgs {
|
|
|
114
125
|
]);
|
|
115
126
|
|
|
116
127
|
siteConfig.blocks = blocks;
|
|
117
|
-
siteConfig.renderers = renderers?.[1]
|
|
118
|
-
id
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
+
}));
|
|
123
136
|
}
|
|
124
137
|
return siteConfig;
|
|
125
138
|
};
|
|
@@ -139,6 +152,10 @@ class RequestHandlerArgs {
|
|
|
139
152
|
args.push('--alias', cli.currentEnv);
|
|
140
153
|
if (!args.find(a => a === '--project-api-id'))
|
|
141
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);
|
|
142
159
|
if (!args.find(a => a === '--blocks-json'))
|
|
143
160
|
args.push('--blocks-json', JSON.stringify(siteConfig.blocks));
|
|
144
161
|
if (!args.find(a => a === '--renderers-json'))
|
|
@@ -171,6 +188,10 @@ class RequestHandlerArgs {
|
|
|
171
188
|
this.siteConfig?.blocks[blockIndex]
|
|
172
189
|
) {
|
|
173
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');
|
|
174
195
|
}
|
|
175
196
|
}
|
|
176
197
|
};
|
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
tryStringify,
|
|
37
37
|
url,
|
|
38
38
|
} from '~/util';
|
|
39
|
+
import { sanitiseIds } from '~/util/api-ids';
|
|
39
40
|
import {
|
|
40
41
|
printBlockVersion,
|
|
41
42
|
printEntriesMigrateResult,
|
|
@@ -142,6 +143,14 @@ class ContensisCli {
|
|
|
142
143
|
this.session = new SessionCacheProvider();
|
|
143
144
|
|
|
144
145
|
this.contensisOpts = contensisOpts;
|
|
146
|
+
|
|
147
|
+
// Explicitly sanitise supplied fields to api-friendly ids
|
|
148
|
+
if (Array.isArray(this.contensisOpts.query?.fields)) {
|
|
149
|
+
this.contensisOpts.query.fields = sanitiseIds(
|
|
150
|
+
this.contensisOpts.query.fields
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
145
154
|
this.format = outputOpts?.format;
|
|
146
155
|
this.output =
|
|
147
156
|
outputOpts?.output && path.join(process.cwd(), outputOpts.output);
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
export const sanitiseId = (id: string) =>
|
|
2
|
+
id
|
|
3
|
+
.split('.')
|
|
4
|
+
.map(part => toApiId(part, 'camelCase', true))
|
|
5
|
+
.join('.');
|
|
6
|
+
|
|
7
|
+
export const sanitiseIds = (arr: string[]) => arr.map(sanitiseId);
|
|
8
|
+
|
|
9
|
+
// borrowed from packages\contensis\components\app\src\utils.ts
|
|
10
|
+
|
|
11
|
+
export function isApiId(id: string, mode: 'camelCase' | 'snake-case'): boolean {
|
|
12
|
+
if (!id) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const validChars = mode === 'camelCase' ? /[^a-zA-Z0-9]/g : /[^a-z0-9-]/g;
|
|
16
|
+
if (id !== id.replace(validChars, '')) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (!id.substr(0, 1).replace(/[^a-z]/g, '')) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function toApiId(
|
|
26
|
+
name: string,
|
|
27
|
+
mode: 'camelCase' | 'snake-case',
|
|
28
|
+
isId: boolean
|
|
29
|
+
) {
|
|
30
|
+
if (!name) {
|
|
31
|
+
return name;
|
|
32
|
+
}
|
|
33
|
+
const validChars =
|
|
34
|
+
mode === 'camelCase' ? /[^a-zA-Z0-9 ]/g : /[^a-zA-Z0-9 -]/g;
|
|
35
|
+
let id = name.replace(validChars, '');
|
|
36
|
+
id = id.replace(/-/g, ' ');
|
|
37
|
+
id = id.trim();
|
|
38
|
+
|
|
39
|
+
const noStart = '0123456789 '.split('');
|
|
40
|
+
id = id
|
|
41
|
+
.split('')
|
|
42
|
+
.reduce(
|
|
43
|
+
(prev, char) => (prev || !noStart.includes(char) ? prev + char : prev),
|
|
44
|
+
''
|
|
45
|
+
);
|
|
46
|
+
return mode === 'camelCase' ? toCamelCase(id, isId) : toSnakeCase(id);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function toSnakeCase(sentence: string): string {
|
|
50
|
+
sentence = (sentence || '').trim();
|
|
51
|
+
if (!sentence) {
|
|
52
|
+
return sentence;
|
|
53
|
+
}
|
|
54
|
+
sentence = sentence.toLowerCase();
|
|
55
|
+
return sentence
|
|
56
|
+
.split(' ')
|
|
57
|
+
.filter(w => !!w)
|
|
58
|
+
.join('-');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function toCamelCase(sentence: string, isId: boolean): string {
|
|
62
|
+
sentence = (sentence || '').trim();
|
|
63
|
+
if (!sentence) {
|
|
64
|
+
return sentence;
|
|
65
|
+
}
|
|
66
|
+
if (sentence.length < 2) {
|
|
67
|
+
return sentence.toLowerCase();
|
|
68
|
+
}
|
|
69
|
+
const words = sentence.split(' ');
|
|
70
|
+
if (isId && words.length === 1) {
|
|
71
|
+
return words[0].substr(0, 1).toLowerCase() + words[0].substr(1);
|
|
72
|
+
}
|
|
73
|
+
const result = words
|
|
74
|
+
.filter(w => !!w)
|
|
75
|
+
.map((w, index) =>
|
|
76
|
+
index === 0 ? firstWordToCamelCase(w) : wordToCamelCase(w)
|
|
77
|
+
)
|
|
78
|
+
.join('');
|
|
79
|
+
|
|
80
|
+
return result
|
|
81
|
+
.split('.')
|
|
82
|
+
.map((w, index) => (index === 0 ? w : wordToCamelCase(w)))
|
|
83
|
+
.join('.');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function firstWordToCamelCase(word: string) {
|
|
87
|
+
return isUpperCase(word)
|
|
88
|
+
? word.toLowerCase()
|
|
89
|
+
: lowerCaseInitialCapitalLettersExceptLast(word);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function wordToCamelCase(word: string) {
|
|
93
|
+
return word.substr(0, 1).toUpperCase() + word.substr(1);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function lowerCaseInitialCapitalLettersExceptLast(value: string): string {
|
|
97
|
+
return value.split('').reduce((prev, char, index) => {
|
|
98
|
+
if (index === 0) {
|
|
99
|
+
char = char.toLowerCase();
|
|
100
|
+
} else if (isUpperCase(char)) {
|
|
101
|
+
if (index + 1 < value.length && isUpperCase(value.charAt(index + 1))) {
|
|
102
|
+
char = char.toLowerCase();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return prev + char;
|
|
106
|
+
}, '');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function isUpperCase(value: string): boolean {
|
|
110
|
+
return value === value.toUpperCase();
|
|
111
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = "1.1.2-beta.
|
|
1
|
+
export const LIB_VERSION = "1.1.2-beta.5";
|