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
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var DevRequests_to_RequestHanderCliArgs_exports = {};
|
|
26
|
+
__export(DevRequests_to_RequestHanderCliArgs_exports, {
|
|
27
|
+
default: () => DevRequests_to_RequestHanderCliArgs_default
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(DevRequests_to_RequestHanderCliArgs_exports);
|
|
30
|
+
var import_p_queue = __toESM(require("p-queue"));
|
|
31
|
+
class RequestHandlerArgs {
|
|
32
|
+
cli;
|
|
33
|
+
args;
|
|
34
|
+
siteConfig;
|
|
35
|
+
constructor(cli) {
|
|
36
|
+
this.cli = cli;
|
|
37
|
+
}
|
|
38
|
+
Create = async () => {
|
|
39
|
+
this.siteConfig = await this.buildSiteConfig();
|
|
40
|
+
await this.cli.Login(this.cli.env.lastUserId, { silent: true });
|
|
41
|
+
this.args = this.getArgs();
|
|
42
|
+
};
|
|
43
|
+
buildSiteConfig = async () => {
|
|
44
|
+
var _a;
|
|
45
|
+
const { currentEnv, currentProject, env, log, messages, urls } = this.cli;
|
|
46
|
+
const contensis = await this.cli.ConnectContensis();
|
|
47
|
+
const siteConfig = {
|
|
48
|
+
alias: currentEnv,
|
|
49
|
+
projectId: currentProject,
|
|
50
|
+
iisHostname: (urls == null ? void 0 : urls.iisPreviewWeb.split("//")[1]) || "",
|
|
51
|
+
podClusterId: "hq",
|
|
52
|
+
accessToken: "",
|
|
53
|
+
clientId: "",
|
|
54
|
+
sharedSecret: "",
|
|
55
|
+
blocks: [],
|
|
56
|
+
renderers: []
|
|
57
|
+
};
|
|
58
|
+
const getBlocks = async (contensis2) => {
|
|
59
|
+
const [err, blocksRaw] = await contensis2.blocks.GetBlocks();
|
|
60
|
+
if (err)
|
|
61
|
+
log.error(messages.blocks.noList(currentEnv, env.currentProject));
|
|
62
|
+
const blocks = [];
|
|
63
|
+
const queue = new import_p_queue.default({ concurrency: 4 });
|
|
64
|
+
for (const block of blocksRaw || []) {
|
|
65
|
+
queue.add(async () => {
|
|
66
|
+
const [err2, versions] = await contensis2.blocks.GetBlockVersions(
|
|
67
|
+
block.id,
|
|
68
|
+
"default",
|
|
69
|
+
"latest"
|
|
70
|
+
);
|
|
71
|
+
if (err2 || (versions == null ? void 0 : versions.length) === 0)
|
|
72
|
+
log.warning(
|
|
73
|
+
messages.blocks.noGet(
|
|
74
|
+
block.id,
|
|
75
|
+
"default",
|
|
76
|
+
"latest",
|
|
77
|
+
currentEnv,
|
|
78
|
+
env.currentProject
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
if (versions == null ? void 0 : versions[0]) {
|
|
82
|
+
const v = versions[0];
|
|
83
|
+
blocks.push({
|
|
84
|
+
id: v.id,
|
|
85
|
+
baseUri: v.previewUrl,
|
|
86
|
+
staticPaths: v.staticPaths,
|
|
87
|
+
endpoints: v.endpoints,
|
|
88
|
+
versionNo: v.version.versionNo,
|
|
89
|
+
branch: v.source.branch
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
await queue.onIdle();
|
|
95
|
+
return blocks;
|
|
96
|
+
};
|
|
97
|
+
if (contensis) {
|
|
98
|
+
const [blocks, renderers] = await Promise.all([
|
|
99
|
+
getBlocks(contensis),
|
|
100
|
+
contensis.renderers.GetRenderers()
|
|
101
|
+
]);
|
|
102
|
+
siteConfig.blocks = blocks;
|
|
103
|
+
siteConfig.renderers = (_a = renderers == null ? void 0 : renderers[1]) == null ? void 0 : _a.filter((r) => blocks.find((b) => b.id === r.id)).map((r) => ({
|
|
104
|
+
id: r.id,
|
|
105
|
+
name: r.name,
|
|
106
|
+
assignedContentTypes: r.assignedContentTypes,
|
|
107
|
+
rules: r.rules
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
return siteConfig;
|
|
111
|
+
};
|
|
112
|
+
getArgs = (overrideArgs = []) => {
|
|
113
|
+
var _a;
|
|
114
|
+
const args = overrideArgs ? typeof (overrideArgs == null ? void 0 : overrideArgs[0]) === "string" && overrideArgs[0].includes(" ", 2) ? overrideArgs[0].split(" ") : overrideArgs : [];
|
|
115
|
+
const { cli, siteConfig } = this;
|
|
116
|
+
if (siteConfig) {
|
|
117
|
+
if (!args.find((a) => a === "--alias"))
|
|
118
|
+
args.push("--alias", cli.currentEnv);
|
|
119
|
+
if (!args.find((a) => a === "--project-api-id"))
|
|
120
|
+
args.push("--project-api-id", cli.currentProject);
|
|
121
|
+
if (!args.find((a) => a === "--iis-hostname"))
|
|
122
|
+
args.push("--iis-hostname", siteConfig.iisHostname);
|
|
123
|
+
if (!args.find((a) => a === "--pod-cluster-id"))
|
|
124
|
+
args.push("--pod-cluster-id", siteConfig.podClusterId);
|
|
125
|
+
if (!args.find((a) => a === "--blocks-json"))
|
|
126
|
+
args.push("--blocks-json", JSON.stringify(siteConfig.blocks));
|
|
127
|
+
if (!args.find((a) => a === "--renderers-json"))
|
|
128
|
+
args.push("--renderers-json", JSON.stringify(siteConfig.renderers));
|
|
129
|
+
}
|
|
130
|
+
const client = (_a = cli.auth) == null ? void 0 : _a.clientDetails;
|
|
131
|
+
if (client) {
|
|
132
|
+
if (!args.find((a) => a === "--client-id") && "clientId" in client)
|
|
133
|
+
args.push("--client-id", client.clientId);
|
|
134
|
+
if (!args.find((a) => a === "--client-secret") && "clientSecret" in client)
|
|
135
|
+
args.push("--client-secret", client.clientSecret);
|
|
136
|
+
if (!args.find((a) => a === "--username") && "username" in client)
|
|
137
|
+
args.push("--username", client.username);
|
|
138
|
+
if (!args.find((a) => a === "--password") && "password" in client)
|
|
139
|
+
args.push("--password", client.password);
|
|
140
|
+
}
|
|
141
|
+
return args;
|
|
142
|
+
};
|
|
143
|
+
overrideBlock = (blockId, overrideUri) => {
|
|
144
|
+
var _a, _b;
|
|
145
|
+
if (blockId && blockId !== "none") {
|
|
146
|
+
const blockIndex = (_a = this.siteConfig) == null ? void 0 : _a.blocks.findIndex(
|
|
147
|
+
(b) => b.id.toLowerCase() === blockId.toLowerCase()
|
|
148
|
+
);
|
|
149
|
+
if (typeof blockIndex === "number" && !isNaN(blockIndex) && ((_b = this.siteConfig) == null ? void 0 : _b.blocks[blockIndex])) {
|
|
150
|
+
this.siteConfig.blocks[blockIndex].baseUri = overrideUri;
|
|
151
|
+
this.siteConfig.blocks[blockIndex].staticPaths.push("/*.js");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
var DevRequests_to_RequestHanderCliArgs_default = RequestHandlerArgs;
|
|
157
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
158
|
+
0 && (module.exports = {});
|
|
159
|
+
//# sourceMappingURL=DevRequests-to-RequestHanderCliArgs.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/mappers/DevRequests-to-RequestHanderCliArgs.ts"],
|
|
4
|
+
"sourcesContent": ["import { ContensisMigrationService } from 'migratortron';\nimport PQueue from 'p-queue';\nimport ContensisCli from '~/services/ContensisCliService';\n\ntype EndpointJson = {\n id: string;\n path: string;\n};\n\ntype BlockJson = {\n id: string;\n baseUri: string;\n staticPaths: string[];\n endpoints: EndpointJson[];\n versionNo: number;\n branch: string;\n};\n\ntype RendererJson = {\n id: string;\n name: string;\n rules: RendererRuleJson[];\n assignedContentTypes: string[];\n};\n\ntype RendererRuleJson = {\n return?: {\n blockId?: string;\n endpointId?: string | null;\n version?: string;\n };\n};\ninterface ISiteConfigYaml {\n alias: string;\n projectId: string;\n iisHostname: string;\n podClusterId: string;\n accessToken: string; // needed?\n clientId: string;\n sharedSecret: string;\n blocks: BlockJson[];\n renderers: RendererJson[];\n}\n\nclass RequestHandlerArgs {\n private cli;\n args?: string[];\n siteConfig?: ISiteConfigYaml;\n\n constructor(cli: ContensisCli) {\n this.cli = cli;\n }\n\n Create = async () => {\n this.siteConfig = await this.buildSiteConfig();\n await this.cli.Login(this.cli.env.lastUserId, { silent: true }); // to hydrate the auth service\n this.args = this.getArgs();\n };\n\n buildSiteConfig = async () => {\n const { currentEnv, currentProject, env, log, messages, urls } = this.cli;\n const contensis = await this.cli.ConnectContensis();\n\n const siteConfig: ISiteConfigYaml = {\n alias: currentEnv,\n projectId: currentProject,\n iisHostname: urls?.iisPreviewWeb.split('//')[1] || '',\n podClusterId: 'hq',\n accessToken: '',\n clientId: '',\n sharedSecret: '',\n blocks: [],\n renderers: [],\n };\n\n const getBlocks = async (contensis: ContensisMigrationService) => {\n const [err, blocksRaw] = await contensis.blocks.GetBlocks();\n if (err)\n log.error(messages.blocks.noList(currentEnv, env.currentProject));\n\n // const blocksRaw = await cli.PrintBlocks();\n\n const blocks: BlockJson[] = [];\n const queue = new PQueue({ concurrency: 4 });\n for (const block of blocksRaw || []) {\n queue.add(async () => {\n // Retrieve block version\n const [err, versions] = await contensis.blocks.GetBlockVersions(\n block.id,\n 'default',\n 'latest'\n );\n if (err || versions?.length === 0)\n log.warning(\n messages.blocks.noGet(\n block.id,\n 'default',\n 'latest',\n currentEnv,\n env.currentProject\n )\n );\n if (versions?.[0]) {\n const v = versions[0];\n blocks.push({\n id: v.id,\n baseUri: v.previewUrl,\n staticPaths: v.staticPaths,\n endpoints: v.endpoints,\n versionNo: v.version.versionNo,\n branch: v.source.branch,\n });\n }\n });\n }\n\n await queue.onIdle();\n return blocks;\n };\n\n if (contensis) {\n const [blocks, renderers] = await Promise.all([\n getBlocks(contensis),\n contensis.renderers.GetRenderers(),\n ]);\n\n siteConfig.blocks = blocks;\n siteConfig.renderers = renderers?.[1]\n ?.filter(r => blocks.find(b => b.id === r.id))\n .map(r => ({\n id: r.id,\n name: r.name,\n assignedContentTypes: r.assignedContentTypes,\n rules: r.rules,\n }));\n }\n return siteConfig;\n };\n\n getArgs = (overrideArgs: string[] = []) => {\n const args = overrideArgs\n ? typeof overrideArgs?.[0] === 'string' &&\n overrideArgs[0].includes(' ', 2)\n ? overrideArgs[0].split(' ')\n : overrideArgs\n : []; // args could be [ '-c .\\\\site_config.yaml' ] or [ '-c', '.\\\\site_config.yaml' ]\n\n const { cli, siteConfig } = this;\n if (siteConfig) {\n // Add required args\n if (!args.find(a => a === '--alias'))\n args.push('--alias', cli.currentEnv);\n if (!args.find(a => a === '--project-api-id'))\n args.push('--project-api-id', cli.currentProject);\n if (!args.find(a => a === '--iis-hostname'))\n args.push('--iis-hostname', siteConfig.iisHostname);\n if (!args.find(a => a === '--pod-cluster-id'))\n args.push('--pod-cluster-id', siteConfig.podClusterId);\n if (!args.find(a => a === '--blocks-json'))\n args.push('--blocks-json', JSON.stringify(siteConfig.blocks));\n if (!args.find(a => a === '--renderers-json'))\n args.push('--renderers-json', JSON.stringify(siteConfig.renderers));\n }\n\n const client = cli.auth?.clientDetails;\n if (client) {\n if (!args.find(a => a === '--client-id') && 'clientId' in client)\n args.push('--client-id', client.clientId);\n if (!args.find(a => a === '--client-secret') && 'clientSecret' in client)\n args.push('--client-secret', client.clientSecret);\n if (!args.find(a => a === '--username') && 'username' in client)\n args.push('--username', client.username);\n if (!args.find(a => a === '--password') && 'password' in client)\n args.push('--password', client.password);\n }\n\n return args;\n };\n\n overrideBlock = (blockId: string, overrideUri: string) => {\n if (blockId && blockId !== 'none') {\n const blockIndex = this.siteConfig?.blocks.findIndex(\n b => b.id.toLowerCase() === blockId.toLowerCase()\n );\n if (\n typeof blockIndex === 'number' &&\n !isNaN(blockIndex) &&\n this.siteConfig?.blocks[blockIndex]\n ) {\n this.siteConfig.blocks[blockIndex].baseUri = overrideUri;\n // this.siteConfig.blocks[blockIndex].staticPaths.push(\n // ...['/static/*', '/image-library/*']\n // );\n this.siteConfig.blocks[blockIndex].staticPaths.push('/*.js');\n }\n }\n };\n}\n\nexport default RequestHandlerArgs;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAmB;AA2CnB,MAAM,mBAAmB;AAAA,EACf;AAAA,EACR;AAAA,EACA;AAAA,EAEA,YAAY,KAAmB;AAC7B,SAAK,MAAM;AAAA,EACb;AAAA,EAEA,SAAS,YAAY;AACnB,SAAK,aAAa,MAAM,KAAK,gBAAgB;AAC7C,UAAM,KAAK,IAAI,MAAM,KAAK,IAAI,IAAI,YAAY,EAAE,QAAQ,KAAK,CAAC;AAC9D,SAAK,OAAO,KAAK,QAAQ;AAAA,EAC3B;AAAA,EAEA,kBAAkB,YAAY;AA3DhC;AA4DI,UAAM,EAAE,YAAY,gBAAgB,KAAK,KAAK,UAAU,KAAK,IAAI,KAAK;AACtE,UAAM,YAAY,MAAM,KAAK,IAAI,iBAAiB;AAElD,UAAM,aAA8B;AAAA,MAClC,OAAO;AAAA,MACP,WAAW;AAAA,MACX,cAAa,6BAAM,cAAc,MAAM,MAAM,OAAM;AAAA,MACnD,cAAc;AAAA,MACd,aAAa;AAAA,MACb,UAAU;AAAA,MACV,cAAc;AAAA,MACd,QAAQ,CAAC;AAAA,MACT,WAAW,CAAC;AAAA,IACd;AAEA,UAAM,YAAY,OAAOA,eAAyC;AAChE,YAAM,CAAC,KAAK,SAAS,IA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,KAAK,OAAK,MAAM,YAAY,KAAK,cAAc;AACvD,aAAK,KAAK,cAAc,OAAO,QAAQ;AAAA,IAC3C;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,gBAAgB,CAAC,SAAiB,gBAAwB;AAnL5D;AAoLI,QAAI,WAAW,YAAY,QAAQ;AACjC,YAAM,cAAa,UAAK,eAAL,mBAAiB,OAAO;AAAA,QACzC,OAAK,EAAE,GAAG,YAAY,MAAM,QAAQ,YAAY;AAAA;AAElD,UACE,OAAO,eAAe,YACtB,CAAC,MAAM,UAAU,OACjB,UAAK,eAAL,mBAAiB,OAAO,cACxB;AACA,aAAK,WAAW,OAAO,YAAY,UAAU;AAI7C,aAAK,WAAW,OAAO,YAAY,YAAY,KAAK,OAAO;AAAA,MAC7D;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,8CAAQ;",
|
|
6
|
+
"names": ["contensis", "PQueue", "err"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var GitHubCliModuleProvider_exports = {};
|
|
26
|
+
__export(GitHubCliModuleProvider_exports, {
|
|
27
|
+
default: () => GitHubCliModuleProvider_default
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(GitHubCliModuleProvider_exports);
|
|
30
|
+
var import_os = __toESM(require("os"));
|
|
31
|
+
var import_adm_zip = __toESM(require("adm-zip"));
|
|
32
|
+
var import_HttpProvider = __toESM(require("../providers/HttpProvider"));
|
|
33
|
+
var import_file_provider = require("./file-provider");
|
|
34
|
+
var import_fetch = require("../util/fetch");
|
|
35
|
+
class GitHubCliModuleProvider {
|
|
36
|
+
http;
|
|
37
|
+
repo;
|
|
38
|
+
baseUrl = "https://api.github.com/repos";
|
|
39
|
+
get releases_url() {
|
|
40
|
+
return `${this.baseUrl}/${this.repo}/releases`;
|
|
41
|
+
}
|
|
42
|
+
get latest_release_url() {
|
|
43
|
+
return `${this.baseUrl}/${this.repo}/releases/latest`;
|
|
44
|
+
}
|
|
45
|
+
download;
|
|
46
|
+
constructor(repo) {
|
|
47
|
+
this.http = new import_HttpProvider.default();
|
|
48
|
+
this.repo = repo;
|
|
49
|
+
}
|
|
50
|
+
async FindLatestRelease(version) {
|
|
51
|
+
const { http, latest_release_url, releases_url } = this;
|
|
52
|
+
const responses = await Promise.all([
|
|
53
|
+
http.get(latest_release_url, {
|
|
54
|
+
doRetry: (0, import_fetch.doRetry)({ silent: true })
|
|
55
|
+
}),
|
|
56
|
+
http.get(releases_url)
|
|
57
|
+
]);
|
|
58
|
+
const [latestErr, latest, latestResponse] = responses[0];
|
|
59
|
+
const [releasesErr, releases] = responses[1];
|
|
60
|
+
if (releasesErr) {
|
|
61
|
+
throw new Error(`Unable to get releases`, { cause: releasesErr });
|
|
62
|
+
} else if (!releases || releases.length === 0)
|
|
63
|
+
throw new Error(`No releases available`);
|
|
64
|
+
else if (version) {
|
|
65
|
+
const release = releases.find(
|
|
66
|
+
(r) => r.tag_name.toLowerCase() === version.toLowerCase()
|
|
67
|
+
);
|
|
68
|
+
if (release)
|
|
69
|
+
return release;
|
|
70
|
+
else
|
|
71
|
+
throw new Error(`No release for ${version} found`);
|
|
72
|
+
} else if (latestErr && !latest) {
|
|
73
|
+
if ((latestResponse == null ? void 0 : latestResponse.status) === 404 && (releases == null ? void 0 : releases.length)) {
|
|
74
|
+
const release = releases.find((r) => r.prerelease) || releases[0];
|
|
75
|
+
if (release)
|
|
76
|
+
return release;
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
return latest;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async DownloadRelease(release, {
|
|
83
|
+
cmd,
|
|
84
|
+
path,
|
|
85
|
+
platforms,
|
|
86
|
+
unzip = true
|
|
87
|
+
}) {
|
|
88
|
+
const platform = platforms.find((p) => p[0] === import_os.default.platform()) || [
|
|
89
|
+
import_os.default.platform(),
|
|
90
|
+
import_os.default.platform()
|
|
91
|
+
];
|
|
92
|
+
const asset = release.assets.find(
|
|
93
|
+
(r) => r.name.toLowerCase().includes(platform[1])
|
|
94
|
+
);
|
|
95
|
+
if (asset) {
|
|
96
|
+
const filePath = (0, import_file_provider.joinPath)(path, asset.name);
|
|
97
|
+
(0, import_file_provider.removeDirectory)(path);
|
|
98
|
+
(0, import_file_provider.checkDir)(filePath);
|
|
99
|
+
await this.http.downloadFile(asset.browser_download_url, filePath);
|
|
100
|
+
if (unzip && asset.name.endsWith(".zip")) {
|
|
101
|
+
const zipFile = new import_adm_zip.default(filePath);
|
|
102
|
+
zipFile.extractAllTo(path);
|
|
103
|
+
(0, import_file_provider.removeFile)(filePath);
|
|
104
|
+
}
|
|
105
|
+
if (import_os.default.platform() !== "win32")
|
|
106
|
+
(0, import_file_provider.addExecutePermission)((0, import_file_provider.joinPath)(path, cmd));
|
|
107
|
+
} else
|
|
108
|
+
throw new Error(
|
|
109
|
+
`no asset found in release ${release.tag_name} for platform ${import_os.default.platform()}
|
|
110
|
+
${release.html_url}`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
var GitHubCliModuleProvider_default = GitHubCliModuleProvider;
|
|
115
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
+
0 && (module.exports = {});
|
|
117
|
+
//# sourceMappingURL=GitHubCliModuleProvider.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/providers/GitHubCliModuleProvider.ts"],
|
|
4
|
+
"sourcesContent": ["import os from 'os';\nimport Zip from 'adm-zip';\nimport type { Endpoints } from '@octokit/types';\nimport HttpProvider from '~/providers/HttpProvider';\nimport {\n addExecutePermission,\n checkDir,\n joinPath,\n removeDirectory,\n removeFile,\n} from './file-provider';\nimport { doRetry } from '~/util/fetch';\n\ntype GitHubApiRelease =\n Endpoints['GET /repos/{owner}/{repo}/releases/latest']['response']['data'];\n\nclass GitHubCliModuleProvider {\n http: HttpProvider;\n repo: string;\n baseUrl = 'https://api.github.com/repos';\n\n get releases_url() {\n return `${this.baseUrl}/${this.repo}/releases`;\n }\n get latest_release_url() {\n return `${this.baseUrl}/${this.repo}/releases/latest`;\n }\n\n download?: {\n tag: string;\n name: string;\n url: string;\n browser_url: string;\n };\n\n constructor(repo: string) {\n this.http = new HttpProvider();\n this.repo = repo;\n }\n\n async FindLatestRelease(version?: string) {\n const { http, latest_release_url, releases_url } = this;\n // return latest tag version is:\n\n const responses = await Promise.all([\n http.get<GitHubApiRelease>(latest_release_url, {\n doRetry: doRetry({ silent: true }),\n }),\n http.get<GitHubApiRelease[]>(releases_url),\n ]);\n\n const [latestErr, latest, latestResponse] = responses[0];\n const [releasesErr, releases] = responses[1];\n\n if (releasesErr) {\n throw new Error(`Unable to get releases`, { cause: releasesErr });\n } else if (!releases || releases.length === 0)\n throw new Error(`No releases available`);\n else if (version) {\n const release = releases.find(\n r => r.tag_name.toLowerCase() === version.toLowerCase()\n );\n if (release) return release;\n else throw new Error(`No release for ${version} found`);\n } else if (latestErr && !latest) {\n if (latestResponse?.status === 404 && releases?.length) {\n // No latest release, check releases for prerelease version, fallback to last release\n const release = releases.find(r => r.prerelease) || releases[0];\n\n if (release) return release;\n }\n } else {\n return latest;\n }\n }\n\n async DownloadRelease(\n release: GitHubApiRelease,\n {\n cmd,\n path,\n platforms,\n unzip = true,\n }: {\n cmd: string;\n path: string;\n unzip?: boolean;\n platforms: [NodeJS.Platform, string][];\n }\n ) {\n // find os-specific asset\n const platform = platforms.find(p => p[0] === os.platform()) || [\n os.platform(),\n os.platform(),\n ];\n\n const asset = release.assets.find(r =>\n r.name.toLowerCase().includes(platform[1])\n );\n\n // download asset\n if (asset) {\n const filePath = joinPath(path, asset.name);\n removeDirectory(path);\n checkDir(filePath);\n await this.http.downloadFile(asset.browser_download_url, filePath);\n\n if (unzip && asset.name.endsWith('.zip')) {\n // unzip the downloaded file\n const zipFile = new Zip(filePath);\n zipFile.extractAllTo(path);\n\n // delete the downloaded zip file\n removeFile(filePath);\n }\n\n if (os.platform() !== 'win32') addExecutePermission(joinPath(path, cmd));\n } else\n throw new Error(\n `no asset found in release ${\n release.tag_name\n } for platform ${os.platform()}\\n${release.html_url}`\n );\n }\n}\n\nexport default GitHubCliModuleProvider;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AACf,qBAAgB;AAEhB,0BAAyB;AACzB,2BAMO;AACP,mBAAwB;AAKxB,MAAM,wBAAwB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,UAAU;AAA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AAAA,IACA,QAAQ;AAAA,EACV,GAMA;AAEA,UAAM,WAAW,UAAU,KAAK,OAAK,EAAE,OAAO,UAAAC,QAAG,SAAS,CAAC,KAAK;AAAA,MAC9D,UAAAA,QAAG,SAAS;AAAA,MACZ,UAAAA,QAAG,SAAS;AAAA,IACd;AAEA,UAAM,QAAQ,QAAQ,OAAO;AAAA,MAAK,OAChC,EAAE,KAAK,YAAY,EAAE,SAAS,SAAS,EAAE;AAAA,IAC3C;AAGA,QAAI,OAAO;AACT,YAAM,eAAW,+BAAS,MAAM,MAAM,IAAI;AAC1C,gDAAgB,IAAI;AACpB,yCAAS,QAAQ;AACjB,YAAM,KAAK,KAAK,aAAa,MAAM,sBAAsB,QAAQ;AAEjE,UAAI,SAAS,MAAM,KAAK,SAAS,MAAM,GAAG;AAExC,cAAM,UAAU,IAAI,eAAAC,QAAI,QAAQ;AAChC,gBAAQ,aAAa,IAAI;AAGzB,6CAAW,QAAQ;AAAA,MACrB;AAEA,UAAI,UAAAD,QAAG,SAAS,MAAM;AAAS,2DAAqB,+BAAS,MAAM,GAAG,CAAC;AAAA,IACzE;AACE,YAAM,IAAI;AAAA,QACR,6BACE,QAAQ,yBACO,UAAAA,QAAG,SAAS;AAAA,EAAM,QAAQ;AAAA,MAC7C;AAAA,EACJ;AACF;AAEA,IAAO,kCAAQ;",
|
|
6
|
+
"names": ["HttpProvider", "os", "Zip"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to2, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to2, key) && key !== except)
|
|
16
|
+
__defProp(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to2;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var HttpProvider_exports = {};
|
|
26
|
+
__export(HttpProvider_exports, {
|
|
27
|
+
default: () => HttpProvider_default
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(HttpProvider_exports);
|
|
30
|
+
var import_await_to_js = __toESM(require("await-to-js"));
|
|
31
|
+
var import_fs = __toESM(require("fs"));
|
|
32
|
+
var import_stream = require("stream");
|
|
33
|
+
var import_promises = require("stream/promises");
|
|
34
|
+
var import_util = require("../util");
|
|
35
|
+
var import_fetch = require("../util/fetch");
|
|
36
|
+
class HttpProvider {
|
|
37
|
+
constructor() {
|
|
38
|
+
}
|
|
39
|
+
async get(url, init = {}) {
|
|
40
|
+
return this.fetch(url, { method: "GET", ...init });
|
|
41
|
+
}
|
|
42
|
+
async fetch(uri, init = {}) {
|
|
43
|
+
const [error, response] = await (0, import_await_to_js.default)((0, import_fetch.enhancedFetch)(uri, init));
|
|
44
|
+
if (response && !error) {
|
|
45
|
+
const [bodyError, text] = await (0, import_await_to_js.default)(response.text());
|
|
46
|
+
if (bodyError)
|
|
47
|
+
return [bodyError, void 0, response];
|
|
48
|
+
if ((0, import_util.isJson)(text)) {
|
|
49
|
+
const err = !response.status || !response.ok ? (0, import_util.tryParse)(text) : void 0;
|
|
50
|
+
const payload = response.status && response.ok ? (0, import_util.tryParse)(text) : void 0;
|
|
51
|
+
return [err, payload, response];
|
|
52
|
+
}
|
|
53
|
+
return [
|
|
54
|
+
response.ok ? null : new Error(text),
|
|
55
|
+
response.ok ? text : void 0,
|
|
56
|
+
response
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
return [error, void 0, response];
|
|
60
|
+
}
|
|
61
|
+
async downloadFile(url, destination) {
|
|
62
|
+
const res = await fetch(url);
|
|
63
|
+
if (res.ok && res.body !== null) {
|
|
64
|
+
const fileStream = import_fs.default.createWriteStream(destination, { flags: "wx" });
|
|
65
|
+
await (0, import_promises.finished)(import_stream.Readable.fromWeb(res.body).pipe(fileStream));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
var HttpProvider_default = HttpProvider;
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {});
|
|
72
|
+
//# sourceMappingURL=HttpProvider.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/providers/HttpProvider.ts"],
|
|
4
|
+
"sourcesContent": ["import to from 'await-to-js';\nimport { FetchInit } from 'enterprise-fetch';\nimport fs from 'fs';\nimport { Readable } from 'stream';\nimport { finished } from 'stream/promises';\n\nimport { isJson, tryParse } from '~/util';\nimport { enhancedFetch } from '~/util/fetch';\nclass HttpProvider {\n constructor() {}\n\n async get<T = any>(url: string, init: FetchInit = {}) {\n return this.fetch<T>(url, { method: 'GET', ...init });\n }\n\n async fetch<T = any>(\n uri: string,\n init: FetchInit = {}\n ): Promise<[Error | null, T | undefined, Response | undefined]> {\n const [error, response] = await to(enhancedFetch(uri, init));\n\n if (response && !error) {\n const [bodyError, text] = await to(response.text());\n if (bodyError) return [bodyError, undefined, response];\n if (isJson(text)) {\n const err =\n !response.status || !response.ok ? tryParse(text) : undefined;\n const payload =\n response.status && response.ok ? tryParse(text) : undefined;\n return [err, payload, response];\n }\n return [\n response.ok ? null : new Error(text),\n response.ok ? (text as unknown as T) : undefined,\n response,\n ];\n }\n return [error, undefined, response];\n }\n\n async downloadFile(url: string, destination: string) {\n const res = await fetch(url);\n if (res.ok && res.body !== null) {\n const fileStream = fs.createWriteStream(destination, { flags: 'wx' });\n await finished(Readable.fromWeb(res.body as any).pipe(fileStream));\n }\n }\n}\n\nexport default HttpProvider;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAe;AAEf,gBAAe;AACf,oBAAyB;AACzB,sBAAyB;AAEzB,kBAAiC;AACjC,mBAA8B;AAC9B,MAAM,aAAa;AAAA,EACjB,cAAc;AAAA,EAAC;AAAA,EAEf,MAAM,IAAa,KAAa,OAAkB,CAAC,GAAG;AACpD,WAAO,KAAK,MAAS,KAAK,EAAE,QAAQ,OAAO,GAAG,KAAK,CAAC;AAAA,EACtD;AAAA,EAEA,MAAM,MACJ,KACA,OAAkB,CAAC,GAC2C;AAC9D,UAAM,CAAC,OAAO,QAAQ,IAAI,UAAM,mBAAAA,aAAG,4BAAc,KAAK,IAAI,CAAC;AAE3D,QAAI,YAAY,CAAC,OAAO;AACtB,YAAM,CAAC,WAAW,IAAI,IAAI,UAAM,mBAAAA,SAAG,SAAS,KAAK,CAAC;AAClD,UAAI;AAAW,eAAO,CAAC,WAAW,QAAW,QAAQ;AACrD,cAAI,oBAAO,IAAI,GAAG;AAChB,cAAM,MACJ,CAAC,SAAS,UAAU,CAAC,SAAS,SAAK,sBAAS,IAAI,IAAI;AACtD,cAAM,UACJ,SAAS,UAAU,SAAS,SAAK,sBAAS,IAAI,IAAI;AACpD,eAAO,CAAC,KAAK,SAAS,QAAQ;AAAA,MAChC;AACA,aAAO;AAAA,QACL,SAAS,KAAK,OAAO,IAAI,MAAM,IAAI;AAAA,QACnC,SAAS,KAAM,OAAwB;AAAA,QACvC;AAAA,MACF;AAAA,IACF;AACA,WAAO,CAAC,OAAO,QAAW,QAAQ;AAAA,EACpC;AAAA,EAEA,MAAM,aAAa,KAAa,aAAqB;AACnD,UAAM,MAAM,MAAM,MAAM,GAAG;AAC3B,QAAI,IAAI,MAAM,IAAI,SAAS,MAAM;AAC/B,YAAM,aAAa,UAAAC,QAAG,kBAAkB,aAAa,EAAE,OAAO,KAAK,CAAC;AACpE,gBAAM,0BAAS,uBAAS,QAAQ,IAAI,IAAW,EAAE,KAAK,UAAU,CAAC;AAAA,IACnE;AAAA,EACF;AACF;AAEA,IAAO,uBAAQ;",
|
|
6
|
+
"names": ["to", "fs"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 ManifestProvider_exports = {};
|
|
20
|
+
__export(ManifestProvider_exports, {
|
|
21
|
+
default: () => ManifestProvider_default
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(ManifestProvider_exports);
|
|
24
|
+
var import_util = require("../util");
|
|
25
|
+
var import_file_provider = require("./file-provider");
|
|
26
|
+
const MANIFEST_PATH = (0, import_file_provider.appPath)("cli-manifest.json");
|
|
27
|
+
class ManifestProvider {
|
|
28
|
+
manifest;
|
|
29
|
+
constructor() {
|
|
30
|
+
const manifest = (0, import_util.tryParse)((0, import_file_provider.readFile)(MANIFEST_PATH));
|
|
31
|
+
this.manifest = manifest || {};
|
|
32
|
+
}
|
|
33
|
+
get() {
|
|
34
|
+
return this.manifest;
|
|
35
|
+
}
|
|
36
|
+
getModule(name) {
|
|
37
|
+
var _a;
|
|
38
|
+
return (_a = this.manifest) == null ? void 0 : _a[name];
|
|
39
|
+
}
|
|
40
|
+
writeModule(name, moduleInfo) {
|
|
41
|
+
if (this.manifest)
|
|
42
|
+
this.manifest[name] = moduleInfo;
|
|
43
|
+
else
|
|
44
|
+
this.manifest = {
|
|
45
|
+
[name]: moduleInfo
|
|
46
|
+
};
|
|
47
|
+
(0, import_file_provider.writeFile)(MANIFEST_PATH, JSON.stringify(this.manifest, null, 2));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
var ManifestProvider_default = ManifestProvider;
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {});
|
|
53
|
+
//# sourceMappingURL=ManifestProvider.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/providers/ManifestProvider.ts"],
|
|
4
|
+
"sourcesContent": ["import { tryParse } from '~/util';\nimport { appPath, readFile, writeFile } from './file-provider';\n\nexport type CliModule = {\n github: string;\n version: string;\n install?: string;\n cmd?: string;\n};\n\ntype CliManifest = {\n [moduleName: string]: CliModule;\n};\n\nconst MANIFEST_PATH = appPath('cli-manifest.json');\n\nclass ManifestProvider {\n private manifest: CliManifest;\n\n constructor() {\n const manifest = tryParse(readFile(MANIFEST_PATH));\n this.manifest = manifest || {};\n }\n\n get() {\n return this.manifest;\n }\n\n getModule(name: string) {\n return this.manifest?.[name];\n }\n writeModule(name: string, moduleInfo: CliModule) {\n if (this.manifest) this.manifest[name] = moduleInfo;\n else\n this.manifest = {\n [name]: moduleInfo,\n };\n\n writeFile(MANIFEST_PATH, JSON.stringify(this.manifest, null, 2));\n }\n}\n\nexport default ManifestProvider;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAyB;AACzB,2BAA6C;AAa7C,MAAM,oBAAgB,8BAAQ,mBAAmB;AAEjD,MAAM,iBAAiB;AAAA,EACb;AAAA,EAER,cAAc;AACZ,UAAM,eAAW,0BAAS,+BAAS,aAAa,CAAC;AACjD,SAAK,WAAW,YAAY,CAAC;AAAA,EAC/B;AAAA,EAEA,MAAM;AACJ,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,UAAU,MAAc;AA5B1B;AA6BI,YAAO,UAAK,aAAL,mBAAgB;AAAA,EACzB;AAAA,EACA,YAAY,MAAc,YAAuB;AAC/C,QAAI,KAAK;AAAU,WAAK,SAAS,QAAQ;AAAA;AAEvC,WAAK,WAAW;AAAA,QACd,CAAC,OAAO;AAAA,MACV;AAEF,wCAAU,eAAe,KAAK,UAAU,KAAK,UAAU,MAAM,CAAC,CAAC;AAAA,EACjE;AACF;AAEA,IAAO,2BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -24,14 +24,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var file_provider_exports = {};
|
|
26
26
|
__export(file_provider_exports, {
|
|
27
|
+
addExecutePermission: () => addExecutePermission,
|
|
27
28
|
appPath: () => appPath,
|
|
28
29
|
appRootDir: () => appRootDir,
|
|
29
30
|
checkDir: () => checkDir,
|
|
30
31
|
cwdPath: () => cwdPath,
|
|
32
|
+
joinPath: () => joinPath,
|
|
31
33
|
moveFile: () => moveFile,
|
|
32
34
|
readFile: () => readFile,
|
|
33
35
|
readFileAsJSON: () => readFileAsJSON,
|
|
34
36
|
readFiles: () => readFiles,
|
|
37
|
+
removeDirectory: () => removeDirectory,
|
|
35
38
|
removeFile: () => removeFile,
|
|
36
39
|
writeFile: () => writeFile
|
|
37
40
|
});
|
|
@@ -77,6 +80,12 @@ const removeFile = (filePath) => {
|
|
|
77
80
|
import_fs.default.rmSync(directoryPath);
|
|
78
81
|
}
|
|
79
82
|
};
|
|
83
|
+
const removeDirectory = (filePath) => {
|
|
84
|
+
const directoryPath = appPath(filePath);
|
|
85
|
+
if (import_fs.default.existsSync(directoryPath)) {
|
|
86
|
+
import_fs.default.rmSync(directoryPath, { force: true, recursive: true });
|
|
87
|
+
}
|
|
88
|
+
};
|
|
80
89
|
const moveFile = (file, fromPath, toPath) => {
|
|
81
90
|
const from = import_path.default.join(appRootDir, `${fromPath}${file}`);
|
|
82
91
|
const to = import_path.default.join(appRootDir, `${toPath}${file}`);
|
|
@@ -104,6 +113,8 @@ const checkDir = (filePath) => {
|
|
|
104
113
|
};
|
|
105
114
|
const appPath = (filePath) => import_path.default.isAbsolute(filePath) ? filePath : import_path.default.join(appRootDir, filePath);
|
|
106
115
|
const cwdPath = (filePath) => import_path.default.isAbsolute(filePath) ? filePath : import_path.default.join(process.cwd(), filePath);
|
|
116
|
+
const joinPath = import_path.default.join;
|
|
117
|
+
const addExecutePermission = (filePath) => import_fs.default.chmodSync(filePath, import_fs.default.constants.S_IRWXU);
|
|
107
118
|
const detectFileType = (fromFile) => {
|
|
108
119
|
const fileData = readFile(fromFile);
|
|
109
120
|
if (!fileData)
|
|
@@ -144,14 +155,17 @@ const readFileAsJSON = async (fromFile) => {
|
|
|
144
155
|
};
|
|
145
156
|
// Annotate the CommonJS export names for ESM import in node:
|
|
146
157
|
0 && (module.exports = {
|
|
158
|
+
addExecutePermission,
|
|
147
159
|
appPath,
|
|
148
160
|
appRootDir,
|
|
149
161
|
checkDir,
|
|
150
162
|
cwdPath,
|
|
163
|
+
joinPath,
|
|
151
164
|
moveFile,
|
|
152
165
|
readFile,
|
|
153
166
|
readFileAsJSON,
|
|
154
167
|
readFiles,
|
|
168
|
+
removeDirectory,
|
|
155
169
|
removeFile,
|
|
156
170
|
writeFile
|
|
157
171
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/providers/file-provider.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from 'fs';\nimport { homedir } from 'os';\nimport path from 'path';\nimport { tryParse } from '~/util';\nimport { csvToJson, detectCsv } from '~/util/csv.formatter';\nimport { unflattenObject } from '~/util/json.formatter';\nimport { Logger } from '~/util/logger';\nimport { xmlToJson } from '~/util/xml.formatter';\n\nconst userHomeDir = homedir();\n\nexport const appRootDir =\n process.env.CONTAINER_CONTEXT === 'true'\n ? process.cwd()\n : path.join(userHomeDir, '.contensis/');\n\nexport const readFile = (filePath: string) => {\n const directoryPath = appPath(filePath);\n if (fs.existsSync(directoryPath)) {\n const file = fs.readFileSync(directoryPath, 'utf8');\n return file;\n } else {\n return undefined;\n }\n};\n\nexport const readFiles = (directory: string, createDirectory = true) => {\n const directoryPath = appPath(directory);\n if (fs.existsSync(directoryPath)) {\n const files = fs.readdirSync(directoryPath);\n return files;\n } else if (createDirectory) {\n fs.mkdirSync(directoryPath, { recursive: true });\n return [];\n } else {\n throw new Error(`ENOENT: Directory does not exist ${directoryPath}`);\n // return undefined;\n }\n};\n\nexport const writeFile = (filePath: string, content: string) => {\n const directoryPath = appPath(filePath);\n fs.writeFileSync(directoryPath, content, { encoding: 'utf-8' });\n};\n\nexport const removeFile = (filePath: string) => {\n const directoryPath = appPath(filePath);\n if (fs.existsSync(directoryPath)) {\n fs.rmSync(directoryPath);\n }\n};\n\nexport const moveFile = (file: string, fromPath: string, toPath: string) => {\n const from = path.join(appRootDir, `${fromPath}${file}`);\n const to = path.join(appRootDir, `${toPath}${file}`);\n if (fs.existsSync(from)) {\n checkDir(toPath);\n // if (!fs.existsSync(toPath)) fs.mkdirSync(toPath, { recursive: true });\n\n fs.rename(from, to, err => {\n if (err)\n console.error(\n `Could not rename file \"${file}\" from: ${fromPath} to: ${toPath}`,\n err\n );\n console.info(`Renamed file \"${file}\" from: ${fromPath} to: ${toPath}`);\n });\n } else {\n console.error(\n `Could not rename file \"${file}\" from: ${fromPath} to: ${toPath}\\nFile does not exist!`\n );\n }\n};\n\nexport const checkDir = (filePath: string) => {\n const directoryPath = path.dirname(appPath(filePath));\n if (!fs.existsSync(directoryPath))\n fs.mkdirSync(directoryPath, { recursive: true });\n};\n\nexport const appPath = (filePath: string) =>\n path.isAbsolute(filePath) ? filePath : path.join(appRootDir, filePath);\n\nexport const cwdPath = (filePath: string) =>\n path.isAbsolute(filePath) ? filePath : path.join(process.cwd(), filePath);\n\ntype DetectedFileType =\n | { type: 'json'; contents: any }\n | { type: 'xml' | 'csv'; contents: string };\n\nconst detectFileType = (fromFile: string): DetectedFileType | undefined => {\n const fileData = readFile(fromFile);\n if (!fileData) throw new Error(`Unable to read file at ${fromFile}`);\n try {\n // if XML\n if (fileData.startsWith('<')) return { contents: fileData, type: 'xml' };\n\n // if JSON\n const jsonData = tryParse(fileData);\n if (jsonData) return { contents: jsonData, type: 'json' };\n\n // if CSV\n const csv = detectCsv(fileData);\n if (csv) return { contents: fileData, type: 'csv' };\n } catch (ex) {\n Logger.error(`Problem detecting file type ${fromFile}`, ex);\n }\n};\n\nexport const readFileAsJSON = async <T = any>(\n fromFile: string\n): Promise<T | undefined> => {\n const detectedFile = detectFileType(cwdPath(fromFile));\n if (!detectedFile) return undefined;\n try {\n switch (detectedFile.type) {\n case 'csv': {\n const flatJson = await csvToJson(detectedFile.contents);\n const unflattenedJson = flatJson.map(record => unflattenObject(record));\n return unflattenedJson as T;\n }\n case 'xml':\n return (await xmlToJson(detectedFile.contents)) as T;\n\n case 'json':\n default:\n return detectedFile.contents;\n }\n } catch (ex) {\n Logger.error(`Problem converting file from ${detectedFile.type}`, ex);\n }\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AACf,gBAAwB;AACxB,kBAAiB;AACjB,kBAAyB;AACzB,iBAAqC;AACrC,kBAAgC;AAChC,oBAAuB;AACvB,iBAA0B;AAE1B,MAAM,kBAAc,mBAAQ;AAErB,MAAM,aACX,QAAQ,IAAI,sBAAsB,SAC9B,QAAQ,IAAI,IACZ,YAAAA,QAAK,KAAK,aAAa,aAAa;AAEnC,MAAM,WAAW,CAAC,aAAqB;AAC5C,QAAM,gBAAgB,QAAQ,QAAQ;AACtC,MAAI,UAAAC,QAAG,WAAW,aAAa,GAAG;AAChC,UAAM,OAAO,UAAAA,QAAG,aAAa,eAAe,MAAM;AAClD,WAAO;AAAA,EACT,OAAO;AACL,WAAO;AAAA,EACT;AACF;AAEO,MAAM,YAAY,CAAC,WAAmB,kBAAkB,SAAS;AACtE,QAAM,gBAAgB,QAAQ,SAAS;AACvC,MAAI,UAAAA,QAAG,WAAW,aAAa,GAAG;AAChC,UAAM,QAAQ,UAAAA,QAAG,YAAY,aAAa;AAC1C,WAAO;AAAA,EACT,WAAW,iBAAiB;AAC1B,cAAAA,QAAG,UAAU,eAAe,EAAE,WAAW,KAAK,CAAC;AAC/C,WAAO,CAAC;AAAA,EACV,OAAO;AACL,UAAM,IAAI,MAAM,oCAAoC,eAAe;AAAA,EAErE;AACF;AAEO,MAAM,YAAY,CAAC,UAAkB,YAAoB;AAC9D,QAAM,gBAAgB,QAAQ,QAAQ;AACtC,YAAAA,QAAG,cAAc,eAAe,SA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} from '~/util/csv.formatter';\nimport { unflattenObject } from '~/util/json.formatter';\nimport { Logger } from '~/util/logger';\nimport { xmlToJson } from '~/util/xml.formatter';\n\nconst userHomeDir = homedir();\n\nexport const appRootDir =\n process.env.CONTAINER_CONTEXT === 'true'\n ? process.cwd()\n : path.join(userHomeDir, '.contensis/');\n\nexport const readFile = (filePath: string) => {\n const directoryPath = appPath(filePath);\n if (fs.existsSync(directoryPath)) {\n const file = fs.readFileSync(directoryPath, 'utf8');\n return file;\n } else {\n return undefined;\n }\n};\n\nexport const readFiles = (directory: string, createDirectory = true) => {\n const directoryPath = appPath(directory);\n if (fs.existsSync(directoryPath)) {\n const files = fs.readdirSync(directoryPath);\n return files;\n } else if (createDirectory) {\n fs.mkdirSync(directoryPath, { recursive: true });\n return [];\n } else {\n throw new Error(`ENOENT: Directory does not exist ${directoryPath}`);\n // return undefined;\n }\n};\n\nexport const writeFile = (filePath: string, content: string) => {\n const directoryPath = appPath(filePath);\n fs.writeFileSync(directoryPath, content, { encoding: 'utf-8' });\n};\n\nexport const removeFile = (filePath: string) => {\n const directoryPath = appPath(filePath);\n if (fs.existsSync(directoryPath)) {\n fs.rmSync(directoryPath);\n }\n};\n\nexport const removeDirectory = (filePath: string) => {\n const directoryPath = appPath(filePath);\n if (fs.existsSync(directoryPath)) {\n fs.rmSync(directoryPath, { force: true, recursive: true });\n }\n};\n\nexport const moveFile = (file: string, fromPath: string, toPath: string) => {\n const from = path.join(appRootDir, `${fromPath}${file}`);\n const to = path.join(appRootDir, `${toPath}${file}`);\n if (fs.existsSync(from)) {\n checkDir(toPath);\n // if (!fs.existsSync(toPath)) fs.mkdirSync(toPath, { recursive: true });\n\n fs.rename(from, to, err => {\n if (err)\n console.error(\n `Could not rename file \"${file}\" from: ${fromPath} to: ${toPath}`,\n err\n );\n console.info(`Renamed file \"${file}\" from: ${fromPath} to: ${toPath}`);\n });\n } else {\n console.error(\n `Could not rename file \"${file}\" from: ${fromPath} to: ${toPath}\\nFile does not exist!`\n );\n }\n};\n\nexport const checkDir = (filePath: string) => {\n const directoryPath = path.dirname(appPath(filePath));\n if (!fs.existsSync(directoryPath))\n fs.mkdirSync(directoryPath, { recursive: true });\n};\n\nexport const appPath = (filePath: string) =>\n path.isAbsolute(filePath) ? filePath : path.join(appRootDir, filePath);\n\nexport const cwdPath = (filePath: string) =>\n path.isAbsolute(filePath) ? filePath : path.join(process.cwd(), filePath);\n\nexport const joinPath = path.join;\n\nexport const addExecutePermission = (filePath: string) =>\n // Fails in windows with `TypeError [ERR_INVALID_ARG_TYPE]: The \"mode\" argument must be of type number. Received undefined`\n fs.chmodSync(filePath, fs.constants.S_IRWXU);\n\ntype DetectedFileType =\n | { type: 'json'; contents: any }\n | { type: 'xml' | 'csv'; contents: string };\n\nconst detectFileType = (fromFile: string): DetectedFileType | undefined => {\n const fileData = readFile(fromFile);\n if (!fileData) throw new Error(`Unable to read file at ${fromFile}`);\n try {\n // if XML\n if (fileData.startsWith('<')) return { contents: fileData, type: 'xml' };\n\n // if JSON\n const jsonData = tryParse(fileData);\n if (jsonData) return { contents: jsonData, type: 'json' };\n\n // if CSV\n const csv = detectCsv(fileData);\n if (csv) return { contents: fileData, type: 'csv' };\n } catch (ex) {\n Logger.error(`Problem detecting file type ${fromFile}`, ex);\n }\n};\n\nexport const readFileAsJSON = async <T = any>(\n fromFile: string\n): Promise<T | undefined> => {\n const detectedFile = detectFileType(cwdPath(fromFile));\n if (!detectedFile) return undefined;\n try {\n switch (detectedFile.type) {\n case 'csv': {\n const flatJson = await csvToJson(detectedFile.contents);\n const unflattenedJson = flatJson.map(record => unflattenObject(record));\n return unflattenedJson as T;\n }\n case 'xml':\n return (await xmlToJson(detectedFile.contents)) as T;\n\n case 'json':\n default:\n return detectedFile.contents;\n }\n } catch (ex) {\n Logger.error(`Problem converting file from ${detectedFile.type}`, ex);\n }\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;A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;AACzE,QAAM,WAAW,SAAS,QAAQ;AAClC,MAAI,CAAC;AAAU,UAAM,IAAI,MAAM,0BAA0B,UAAU;AACnE,MAAI;AAEF,QAAI,SAAS,WAAW,GAAG;AAAG,aAAO,EAAE,UAAU,UAAU,MAAM,MAAM;AAGvE,UAAM,eAAW,sBAAS,QAAQ;AAClC,QAAI;AAAU,aAAO,EAAE,UAAU,UAAU,MAAM,OAAO;AAGxD,UAAM,UAAM,sBAAU,QAAQ;AAC9B,QAAI;AAAK,aAAO,EAAE,UAAU,UAAU,MAAM,MAAM;AAAA,EACpD,SAAS,IAAP;AACA,yBAAO,MAAM,+BAA+B,YAAY,EAAE;AAAA,EAC5D;AACF;AAEO,MAAM,iBAAiB,OAC5B,aAC2B;AAC3B,QAAM,eAAe,eAAe,QAAQ,QAAQ,CAAC;AACrD,MAAI,CAAC;AAAc,WAAO;AAC1B,MAAI;AACF,YAAQ,aAAa;AAAA,WACd,OAAO;AACV,cAAM,WAAW,UAAM,sBAAU,aAAa,QAAQ;AACtD,cAAM,kBAAkB,SAAS,IAAI,gBAAU,6BAAgB,MAAM,CAAC;AACtE,eAAO;AAAA,MACT;AAAA,WACK;AACH,eAAQ,UAAM,sBAAU,aAAa,QAAQ;AAAA,WAE1C;AAAA;AAEH,eAAO,aAAa;AAAA;AAAA,EAE1B,SAAS,IAAP;AACA,yBAAO,MAAM,gCAAgC,aAAa,QAAQ,EAAE;AAAA,EACtE;AACF;",
|
|
6
6
|
"names": ["path", "fs"]
|
|
7
7
|
}
|
|
@@ -24,6 +24,13 @@ module.exports = __toCommonJS(ContensisAuthService_exports);
|
|
|
24
24
|
var import_client = require("contensis-management-api/lib/client");
|
|
25
25
|
class ContensisAuthService {
|
|
26
26
|
client;
|
|
27
|
+
credentials;
|
|
28
|
+
get clientType() {
|
|
29
|
+
return this.credentials.clientType;
|
|
30
|
+
}
|
|
31
|
+
get clientDetails() {
|
|
32
|
+
return this.credentials.clientDetails;
|
|
33
|
+
}
|
|
27
34
|
constructor({
|
|
28
35
|
clientId = "",
|
|
29
36
|
clientSecret = "",
|
|
@@ -33,35 +40,36 @@ class ContensisAuthService {
|
|
|
33
40
|
projectId,
|
|
34
41
|
rootUrl
|
|
35
42
|
}) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
credentials = {
|
|
43
|
+
if (clientId && clientSecret)
|
|
44
|
+
this.credentials = {
|
|
39
45
|
clientType: "client_credentials",
|
|
40
46
|
clientDetails: {
|
|
41
47
|
clientId,
|
|
42
48
|
clientSecret
|
|
43
49
|
}
|
|
44
50
|
};
|
|
45
|
-
|
|
46
|
-
credentials = {
|
|
51
|
+
else if (username && password)
|
|
52
|
+
this.credentials = {
|
|
47
53
|
clientType: "contensis_classic",
|
|
48
54
|
clientDetails: {
|
|
49
55
|
username,
|
|
50
56
|
password
|
|
51
57
|
}
|
|
52
58
|
};
|
|
53
|
-
|
|
54
|
-
credentials = {
|
|
59
|
+
else if (refreshToken)
|
|
60
|
+
this.credentials = {
|
|
55
61
|
clientType: "contensis_classic_refresh_token",
|
|
56
62
|
clientDetails: {
|
|
57
63
|
refreshToken
|
|
58
64
|
}
|
|
59
65
|
};
|
|
60
|
-
|
|
61
|
-
credentials = {
|
|
62
|
-
|
|
66
|
+
else
|
|
67
|
+
this.credentials = {
|
|
68
|
+
clientType: "none",
|
|
69
|
+
clientDetails: { refreshToken: "" }
|
|
70
|
+
};
|
|
63
71
|
this.client = import_client.NodejsClient.create({
|
|
64
|
-
...credentials,
|
|
72
|
+
...this.credentials,
|
|
65
73
|
projectId,
|
|
66
74
|
rootUrl
|
|
67
75
|
});
|