@azure/api-management-custom-widgets-scaffolder 1.0.0-beta.4 → 1.0.0-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/LICENSE +17 -17
- package/README.md +2 -2
- package/bin/{execute.js → execute.cjs} +111 -484
- package/bin/execute.cjs.map +1 -0
- package/bin/templates/react/package.json.mustache +1 -1
- package/bin/templates/typescript/package.json.mustache +1 -1
- package/bin/templates/vue/package.json.mustache +1 -1
- package/dist/commonjs/bin/execute-configs.d.ts +15 -0
- package/dist/commonjs/bin/execute-configs.d.ts.map +1 -0
- package/dist/commonjs/bin/execute-configs.js +157 -0
- package/dist/commonjs/bin/execute-configs.js.map +1 -0
- package/dist/commonjs/bin/execute-helpers.d.ts +12 -0
- package/dist/commonjs/bin/execute-helpers.d.ts.map +1 -0
- package/dist/commonjs/bin/execute-helpers.js +50 -0
- package/dist/commonjs/bin/execute-helpers.js.map +1 -0
- package/dist/commonjs/bin/execute.d.ts +3 -0
- package/dist/commonjs/bin/execute.d.ts.map +1 -0
- package/dist/commonjs/bin/execute.js +48 -0
- package/dist/commonjs/bin/execute.js.map +1 -0
- package/dist/commonjs/generateProject.d.ts +10 -0
- package/dist/commonjs/generateProject.d.ts.map +1 -0
- package/dist/commonjs/generateProject.js +74 -0
- package/dist/commonjs/generateProject.js.map +1 -0
- package/dist/commonjs/getTemplates.d.ts +3 -0
- package/dist/commonjs/getTemplates.d.ts.map +1 -0
- package/dist/commonjs/getTemplates.js +21 -0
- package/dist/commonjs/getTemplates.js.map +1 -0
- package/dist/commonjs/index.d.ts +7 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +17 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/{types/latest/api-management-custom-widgets-scaffolder.d.ts → dist/commonjs/scaffolding.d.ts} +54 -75
- package/dist/commonjs/scaffolding.d.ts.map +1 -0
- package/dist/commonjs/scaffolding.js +35 -0
- package/dist/commonjs/scaffolding.js.map +1 -0
- package/dist/commonjs/sourceDir-cjs.cjs.map +1 -0
- package/dist/commonjs/sourceDir-cjs.d.cts.map +1 -0
- package/dist/commonjs/sourceDir.d.ts +2 -0
- package/dist/commonjs/sourceDir.js +7 -0
- package/dist/commonjs/tsdoc-metadata.json +11 -0
- package/dist/esm/bin/execute-configs.d.ts +15 -0
- package/dist/esm/bin/execute-configs.d.ts.map +1 -0
- package/dist/esm/bin/execute-configs.js +150 -0
- package/dist/esm/bin/execute-configs.js.map +1 -0
- package/dist/esm/bin/execute-helpers.d.ts +12 -0
- package/dist/esm/bin/execute-helpers.d.ts.map +1 -0
- package/{dist-esm/src → dist/esm}/bin/execute-helpers.js +3 -3
- package/dist/esm/bin/execute-helpers.js.map +1 -0
- package/dist/esm/bin/execute.d.ts +3 -0
- package/dist/esm/bin/execute.d.ts.map +1 -0
- package/{dist-esm/src → dist/esm}/bin/execute.js +4 -4
- package/dist/esm/bin/execute.js.map +1 -0
- package/dist/esm/generateProject.d.ts +10 -0
- package/dist/esm/generateProject.d.ts.map +1 -0
- package/{dist-esm/src → dist/esm}/generateProject.js +10 -9
- package/dist/esm/generateProject.js.map +1 -0
- package/dist/esm/getTemplates.d.ts +3 -0
- package/dist/esm/getTemplates.d.ts.map +1 -0
- package/{dist-esm/src → dist/esm}/getTemplates.js +5 -4
- package/dist/esm/getTemplates.js.map +1 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/scaffolding.d.ts +54 -0
- package/dist/esm/scaffolding.d.ts.map +1 -0
- package/{dist-esm/src → dist/esm}/scaffolding.js +1 -1
- package/{dist-esm/src → dist/esm}/scaffolding.js.map +1 -1
- package/dist/esm/sourceDir.d.ts +2 -0
- package/dist/esm/sourceDir.d.ts.map +1 -0
- package/dist/esm/sourceDir.js +8 -0
- package/dist/esm/sourceDir.js.map +1 -0
- package/package.json +70 -71
- package/dist/index.js +0 -125
- package/dist/index.js.map +0 -1
- package/dist-esm/src/bin/execute-configs.js +0 -139
- package/dist-esm/src/bin/execute-configs.js.map +0 -1
- package/dist-esm/src/bin/execute-helpers.js.map +0 -1
- package/dist-esm/src/bin/execute.js.map +0 -1
- package/dist-esm/src/generateProject.browser.js +0 -6
- package/dist-esm/src/generateProject.browser.js.map +0 -1
- package/dist-esm/src/generateProject.js.map +0 -1
- package/dist-esm/src/getTemplates.js.map +0 -1
- package/dist-esm/src/index.js +0 -8
- package/dist-esm/src/index.js.map +0 -1
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { TECHNOLOGIES } from "../scaffolding.js";
|
|
4
|
+
export const fieldIdToName = {
|
|
5
|
+
displayName: "Widget display name",
|
|
6
|
+
technology: "Technology",
|
|
7
|
+
iconUrl: "iconUrl",
|
|
8
|
+
resourceId: "Azure API Management resource ID (following format: subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.ApiManagement/service/<api-management service-name>)",
|
|
9
|
+
managementApiEndpoint: "Management API hostname",
|
|
10
|
+
apiVersion: "Management API version",
|
|
11
|
+
openUrl: "Developer portal URL",
|
|
12
|
+
configAdvancedTenantId: "Tenant ID",
|
|
13
|
+
configAdvancedRedirectUri: "Redirect URI",
|
|
14
|
+
};
|
|
15
|
+
export const prefixUrlProtocol = (value) => /https?:\/\//.test(value) ? value : `https://${value}`;
|
|
16
|
+
const validateRequired = (name, msg = `The “${name}” parameter is required.`) => (input) => (input != null && input !== "") || msg;
|
|
17
|
+
const validateUrl = (name, msg = (input) => `Provided “${name}” parameter value (“${prefixUrlProtocol(input)}”) isn’t a valid URL. Use the correct URL format, e.g., https://contoso.com.`) => (input) => {
|
|
18
|
+
try {
|
|
19
|
+
new URL(prefixUrlProtocol(input));
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
return msg(prefixUrlProtocol(input));
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
export const validateWidgetConfig = {
|
|
27
|
+
displayName: validateRequired(fieldIdToName.displayName),
|
|
28
|
+
technology: (input) => {
|
|
29
|
+
const required = validateRequired(fieldIdToName.technology)(input);
|
|
30
|
+
if (required !== true)
|
|
31
|
+
return required;
|
|
32
|
+
if (TECHNOLOGIES.includes(input)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return ("Provided “technology” parameter value isn’t correct. Use one of the following: " +
|
|
37
|
+
TECHNOLOGIES.join(", "));
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
export const validateDeployConfig = {
|
|
42
|
+
resourceId: (input) => {
|
|
43
|
+
const required = validateRequired(fieldIdToName.resourceId)(input);
|
|
44
|
+
if (required !== true)
|
|
45
|
+
return required;
|
|
46
|
+
const regex = /^\/?subscriptions\/[^/]+\/resourceGroups\/[^/]+\/providers\/Microsoft\.ApiManagement\/service\/[^/]+\/?$/;
|
|
47
|
+
return input === "test" || regex.test(input)
|
|
48
|
+
? true
|
|
49
|
+
: "Resource ID needs to be a valid Azure resource ID. For example, subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/contoso-group/providers/Microsoft.ApiManagement/service/contoso-apis.";
|
|
50
|
+
},
|
|
51
|
+
managementApiEndpoint: (input) => validateRequired(fieldIdToName.managementApiEndpoint)(input),
|
|
52
|
+
};
|
|
53
|
+
export const validateMiscConfig = {
|
|
54
|
+
openUrl: (input) => {
|
|
55
|
+
if (!input)
|
|
56
|
+
return true;
|
|
57
|
+
return validateUrl(fieldIdToName.openUrl)(input);
|
|
58
|
+
},
|
|
59
|
+
configAdvancedTenantId: () => {
|
|
60
|
+
return true;
|
|
61
|
+
},
|
|
62
|
+
configAdvancedRedirectUri: (input) => {
|
|
63
|
+
if (!input)
|
|
64
|
+
return true;
|
|
65
|
+
return validateUrl(fieldIdToName.openUrl)(input);
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
export const promptWidgetConfig = async (partial) => {
|
|
69
|
+
const inquirerImport = await import("inquirer");
|
|
70
|
+
const inquirer = inquirerImport.default;
|
|
71
|
+
return inquirer.prompt([
|
|
72
|
+
{
|
|
73
|
+
name: "displayName",
|
|
74
|
+
type: "input",
|
|
75
|
+
message: fieldIdToName.displayName,
|
|
76
|
+
validate: validateWidgetConfig.displayName,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "technology",
|
|
80
|
+
type: "list",
|
|
81
|
+
message: fieldIdToName.technology,
|
|
82
|
+
choices: [
|
|
83
|
+
{ name: "React", value: "react" },
|
|
84
|
+
{ name: "Vue", value: "vue" },
|
|
85
|
+
{ name: "TypeScript", value: "typescript" },
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
], partial);
|
|
89
|
+
};
|
|
90
|
+
export const promptServiceInformation = async (partial) => {
|
|
91
|
+
const inquirerImport = await import("inquirer");
|
|
92
|
+
const inquirer = inquirerImport.default;
|
|
93
|
+
return inquirer.prompt([
|
|
94
|
+
{
|
|
95
|
+
name: "resourceId",
|
|
96
|
+
type: "input",
|
|
97
|
+
message: fieldIdToName.resourceId,
|
|
98
|
+
validate: validateDeployConfig.resourceId,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "managementApiEndpoint",
|
|
102
|
+
type: "list",
|
|
103
|
+
message: fieldIdToName.managementApiEndpoint,
|
|
104
|
+
choices: [
|
|
105
|
+
{
|
|
106
|
+
name: "management.azure.com (if you're not sure what to select, use this option)",
|
|
107
|
+
value: "management.azure.com",
|
|
108
|
+
},
|
|
109
|
+
{ name: "management.usgovcloudapi.net", value: "management.usgovcloudapi.net" },
|
|
110
|
+
{ name: "management.chinacloudapi.cn", value: "management.chinacloudapi.cn" },
|
|
111
|
+
],
|
|
112
|
+
transformer: prefixUrlProtocol,
|
|
113
|
+
validate: validateDeployConfig.managementApiEndpoint,
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: "apiVersion",
|
|
117
|
+
type: "input",
|
|
118
|
+
message: fieldIdToName.apiVersion + " (optional; e.g., 2021-08-01)",
|
|
119
|
+
},
|
|
120
|
+
], partial);
|
|
121
|
+
};
|
|
122
|
+
export const promptMiscConfig = async (partial) => {
|
|
123
|
+
const inquirerImport = await import("inquirer");
|
|
124
|
+
const inquirer = inquirerImport.default;
|
|
125
|
+
return inquirer.prompt([
|
|
126
|
+
{
|
|
127
|
+
name: "openUrl",
|
|
128
|
+
type: "input",
|
|
129
|
+
message: fieldIdToName.openUrl +
|
|
130
|
+
" for widget development and testing (optional; e.g., https://contoso.developer.azure-api.net/ or http://localhost:8080)",
|
|
131
|
+
transformer: prefixUrlProtocol,
|
|
132
|
+
validate: validateMiscConfig.openUrl,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: "configAdvancedTenantId",
|
|
136
|
+
type: "input",
|
|
137
|
+
message: fieldIdToName.configAdvancedTenantId +
|
|
138
|
+
" to be used in Azure Identity InteractiveBrowserCredential class (optional)",
|
|
139
|
+
validate: validateMiscConfig.openUrl,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "configAdvancedRedirectUri",
|
|
143
|
+
type: "input",
|
|
144
|
+
message: fieldIdToName.configAdvancedRedirectUri +
|
|
145
|
+
" to be used in Azure Identity InteractiveBrowserCredential class (optional; default is http://localhost:1337)",
|
|
146
|
+
validate: validateMiscConfig.openUrl,
|
|
147
|
+
},
|
|
148
|
+
], partial);
|
|
149
|
+
};
|
|
150
|
+
//# sourceMappingURL=execute-configs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute-configs.js","sourceRoot":"","sources":["../../../src/bin/execute-configs.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,YAAY,EAAE,MAAM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Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Configs, ServiceInformation, Options, WidgetConfig } from \"../scaffolding.js\";\nimport { TECHNOLOGIES } from \"../scaffolding.js\";\n\nexport const fieldIdToName: Record<\n keyof (WidgetConfig & ServiceInformation & Options) | string,\n string\n> = {\n displayName: \"Widget display name\",\n technology: \"Technology\",\n iconUrl: \"iconUrl\",\n\n resourceId:\n \"Azure API Management resource ID (following format: subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.ApiManagement/service/<api-management service-name>)\",\n managementApiEndpoint: \"Management API hostname\",\n apiVersion: \"Management API version\",\n\n openUrl: \"Developer portal URL\",\n configAdvancedTenantId: \"Tenant ID\",\n configAdvancedRedirectUri: \"Redirect URI\",\n};\n\nexport const prefixUrlProtocol = (value: string): string =>\n /https?:\\/\\//.test(value) ? value : `https://${value}`;\n\nconst validateRequired =\n (name: string, msg: string = `The “${name}” parameter is required.`) =>\n (input: unknown) =>\n (input != null && input !== \"\") || msg;\n\nconst validateUrl =\n (\n name: string,\n msg = (input: string) =>\n `Provided “${name}” parameter value (“${prefixUrlProtocol(\n input,\n )}”) isn’t a valid URL. Use the correct URL format, e.g., https://contoso.com.`,\n ) =>\n (input: string) => {\n try {\n new URL(prefixUrlProtocol(input));\n return true;\n } catch (e) {\n return msg(prefixUrlProtocol(input));\n }\n };\n\nexport type ReplaceTypesPreserveOptional<T extends Record<any, any>, V> = {\n [Key in keyof T]: T[Key] extends undefined ? V | undefined : V;\n};\n\nexport type ValidateFnc = (input: string) => boolean | string;\nexport type Validate<C extends Configs> = ReplaceTypesPreserveOptional<C, ValidateFnc>;\n\nexport const validateWidgetConfig: Validate<WidgetConfig> = {\n displayName: validateRequired(fieldIdToName.displayName),\n technology: (input) => {\n const required = validateRequired(fieldIdToName.technology)(input);\n if (required !== true) return required;\n\n if (TECHNOLOGIES.includes(input as any)) {\n return true;\n } else {\n return (\n \"Provided “technology” parameter value isn’t correct. Use one of the following: \" +\n TECHNOLOGIES.join(\", \")\n );\n }\n },\n};\n\nexport const validateDeployConfig: Validate<ServiceInformation> = {\n resourceId: (input) => {\n const required = validateRequired(fieldIdToName.resourceId)(input);\n if (required !== true) return required;\n\n const regex =\n /^\\/?subscriptions\\/[^/]+\\/resourceGroups\\/[^/]+\\/providers\\/Microsoft\\.ApiManagement\\/service\\/[^/]+\\/?$/;\n return input === \"test\" || regex.test(input)\n ? true\n : \"Resource ID needs to be a valid Azure resource ID. For example, subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/contoso-group/providers/Microsoft.ApiManagement/service/contoso-apis.\";\n },\n managementApiEndpoint: (input) => validateRequired(fieldIdToName.managementApiEndpoint)(input),\n};\n\nexport const validateMiscConfig: Validate<Options> = {\n openUrl: (input) => {\n if (!input) return true;\n return validateUrl(fieldIdToName.openUrl)(input);\n },\n configAdvancedTenantId: () => {\n return true;\n },\n configAdvancedRedirectUri: (input) => {\n if (!input) return true;\n return validateUrl(fieldIdToName.openUrl)(input);\n },\n};\n\nexport const promptWidgetConfig = async (partial: Partial<WidgetConfig>): Promise<WidgetConfig> => {\n const inquirerImport = await import(\"inquirer\");\n const inquirer = inquirerImport.default;\n return inquirer.prompt(\n [\n {\n name: \"displayName\",\n type: \"input\",\n message: fieldIdToName.displayName,\n validate: validateWidgetConfig.displayName,\n },\n {\n name: \"technology\",\n type: \"list\",\n message: fieldIdToName.technology,\n choices: [\n { name: \"React\", value: \"react\" },\n { name: \"Vue\", value: \"vue\" },\n { name: \"TypeScript\", value: \"typescript\" },\n ],\n },\n ],\n partial,\n );\n};\n\nexport const promptServiceInformation = async (\n partial: Partial<ServiceInformation>,\n): Promise<ServiceInformation> => {\n const inquirerImport = await import(\"inquirer\");\n const inquirer = inquirerImport.default;\n return inquirer.prompt(\n [\n {\n name: \"resourceId\",\n type: \"input\",\n message: fieldIdToName.resourceId,\n validate: validateDeployConfig.resourceId,\n },\n {\n name: \"managementApiEndpoint\",\n type: \"list\",\n message: fieldIdToName.managementApiEndpoint,\n choices: [\n {\n name: \"management.azure.com (if you're not sure what to select, use this option)\",\n value: \"management.azure.com\",\n },\n { name: \"management.usgovcloudapi.net\", value: \"management.usgovcloudapi.net\" },\n { name: \"management.chinacloudapi.cn\", value: \"management.chinacloudapi.cn\" },\n ],\n transformer: prefixUrlProtocol,\n validate: validateDeployConfig.managementApiEndpoint,\n },\n {\n name: \"apiVersion\",\n type: \"input\",\n message: fieldIdToName.apiVersion + \" (optional; e.g., 2021-08-01)\",\n },\n ],\n partial,\n );\n};\n\nexport const promptMiscConfig = async (partial: Partial<Options>): Promise<Options> => {\n const inquirerImport = await import(\"inquirer\");\n const inquirer = inquirerImport.default;\n return inquirer.prompt(\n [\n {\n name: \"openUrl\",\n type: \"input\",\n message:\n fieldIdToName.openUrl +\n \" for widget development and testing (optional; e.g., https://contoso.developer.azure-api.net/ or http://localhost:8080)\",\n transformer: prefixUrlProtocol,\n validate: validateMiscConfig.openUrl,\n },\n {\n name: \"configAdvancedTenantId\",\n type: \"input\",\n message:\n fieldIdToName.configAdvancedTenantId +\n \" to be used in Azure Identity InteractiveBrowserCredential class (optional)\",\n validate: validateMiscConfig.openUrl,\n },\n {\n name: \"configAdvancedRedirectUri\",\n type: \"input\",\n message:\n fieldIdToName.configAdvancedRedirectUri +\n \" to be used in Azure Identity InteractiveBrowserCredential class (optional; default is http://localhost:1337)\",\n validate: validateMiscConfig.openUrl,\n },\n ],\n partial,\n );\n};\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ReplaceTypesPreserveOptional, Validate, ValidateFnc } from "./execute-configs.js";
|
|
2
|
+
import type { Configs } from "../scaffolding.js";
|
|
3
|
+
import yargsParser from "yargs-parser";
|
|
4
|
+
export declare const extractConfigFromArgs: <TConfig extends Configs>(argv: yargsParser.Arguments, validateConfig: Validate<TConfig>, red: (msg: string) => void) => {
|
|
5
|
+
configPartial: Partial<TConfig>;
|
|
6
|
+
missing: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type Log = (msg: string) => void;
|
|
9
|
+
type Config = <C extends Configs>(promptForConfig: (partial: Partial<C>) => Promise<C>, validateConfig: ReplaceTypesPreserveOptional<C, ValidateFnc>) => Promise<C>;
|
|
10
|
+
export declare const buildGetConfig: (gray: Log, red: Log) => Config;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=execute-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute-helpers.d.ts","sourceRoot":"","sources":["../../../src/bin/execute-helpers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,4BAA4B,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEhG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC,eAAO,MAAM,qBAAqB,GAAI,OAAO,SAAS,OAAO,EAC3D,MAAM,WAAW,CAAC,SAAS,EAC3B,gBAAgB,QAAQ,CAAC,OAAO,CAAC,EACjC,KAAK,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,KACzB;IAAE,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAuBrD,CAAC;AAEF,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;AACxC,KAAK,MAAM,GAAG,CAAC,CAAC,SAAS,OAAO,EAC9B,eAAe,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EACpD,cAAc,EAAE,4BAA4B,CAAC,CAAC,EAAE,WAAW,CAAC,KACzD,OAAO,CAAC,CAAC,CAAC,CAAC;AAEhB,eAAO,MAAM,cAAc,GAAI,MAAM,GAAG,EAAE,KAAK,GAAG,KAAG,MAkBpD,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT
|
|
3
|
-
import { fieldIdToName
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { fieldIdToName } from "./execute-configs.js";
|
|
4
4
|
import { hideBin } from "yargs/helpers";
|
|
5
5
|
import yargsParser from "yargs-parser";
|
|
6
6
|
export const extractConfigFromArgs = (argv, validateConfig, red) => {
|
|
@@ -36,7 +36,7 @@ export const buildGetConfig = (gray, red) => {
|
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
38
|
gray("Retrieved from the command parameters");
|
|
39
|
-
Object.entries(configPartial).forEach(([key, value]) =>
|
|
39
|
+
Object.entries(configPartial).forEach(([key, value]) => value != null && gray(`${fieldIdToName[key] ?? key}: ${value}`));
|
|
40
40
|
return configPartial;
|
|
41
41
|
}
|
|
42
42
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute-helpers.js","sourceRoot":"","sources":["../../../src/bin/execute-helpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,WAAW,MAAM,cAAc,CAAC;AAEvC,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,IAA2B,EAC3B,cAAiC,EACjC,GAA0B,EAC6B,EAAE;IACzD,MAAM,aAAa,GAAqB,EAAE,CAAC;IAC3C,IAAI,OAAO,GAAY,KAAK,CAAC;IAE7B,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,EAAE;QAClD,MAAM,QAAQ,GAAG,CAAgB,CAAC;QAClC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;QACxB,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAEjC,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,GAAG,aAAa,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC,CAClF,CAAC;YACF,OAAO,aAAkB,CAAC;QAC5B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ReplaceTypesPreserveOptional, Validate, ValidateFnc } from \"./execute-configs.js\";\nimport { fieldIdToName } from \"./execute-configs.js\";\nimport type { Configs } from \"../scaffolding.js\";\nimport { hideBin } from \"yargs/helpers\";\nimport yargsParser from \"yargs-parser\";\n\nexport const extractConfigFromArgs = <TConfig extends Configs>(\n argv: yargsParser.Arguments,\n validateConfig: Validate<TConfig>,\n red: (msg: string) => void,\n): { configPartial: Partial<TConfig>; missing: boolean } => {\n const configPartial: Partial<TConfig> = {};\n let missing: boolean = false;\n\n Object.entries(validateConfig).forEach(([key, v]) => {\n const validate = v as ValidateFnc;\n const value = argv[key];\n const response = validate(value);\n\n if (response === true) {\n if (value !== null && value !== undefined) {\n configPartial[key as keyof typeof validateConfig] = value;\n }\n } else if (value === null || value === undefined) {\n missing = true;\n } else {\n missing = true;\n red(`\"${value}\" is not a valid value for \"${key}\"`);\n if (typeof response === \"string\") red(response);\n }\n });\n\n return { configPartial, missing };\n};\n\nexport type Log = (msg: string) => void;\ntype Config = <C extends Configs>(\n promptForConfig: (partial: Partial<C>) => Promise<C>,\n validateConfig: ReplaceTypesPreserveOptional<C, ValidateFnc>,\n) => Promise<C>;\n\nexport const buildGetConfig = (gray: Log, red: Log): Config => {\n const argv = yargsParser(hideBin(process.argv));\n return async <C extends Configs>(\n promptForConfig: (partial: Partial<C>) => Promise<C>,\n validateConfig: Validate<C>,\n ) => {\n const { configPartial, missing } = extractConfigFromArgs(argv, validateConfig, red);\n\n if (missing || !Object.values(configPartial).length) {\n return promptForConfig(configPartial);\n } else {\n gray(\"Retrieved from the command parameters\");\n Object.entries(configPartial).forEach(\n ([key, value]) => value != null && gray(`${fieldIdToName[key] ?? key}: ${value}`),\n );\n return configPartial as C;\n }\n };\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../../../src/bin/execute.ts"],"names":[],"mappings":""}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Copyright (c) Microsoft Corporation.
|
|
3
|
-
// Licensed under the MIT
|
|
4
|
-
import { buildGetConfig } from "./execute-helpers";
|
|
5
|
-
import { prefixUrlProtocol, promptServiceInformation, promptMiscConfig, promptWidgetConfig, validateDeployConfig, validateMiscConfig, validateWidgetConfig, } from "./execute-configs";
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
import { buildGetConfig } from "./execute-helpers.js";
|
|
5
|
+
import { prefixUrlProtocol, promptServiceInformation, promptMiscConfig, promptWidgetConfig, validateDeployConfig, validateMiscConfig, validateWidgetConfig, } from "./execute-configs.js";
|
|
6
6
|
import chalk from "chalk";
|
|
7
|
-
import { generateProject } from "../generateProject";
|
|
7
|
+
import { generateProject } from "../generateProject.js";
|
|
8
8
|
const log = console.log;
|
|
9
9
|
const white = (msg) => log(chalk.white(msg));
|
|
10
10
|
const green = (msg) => log(chalk.green(msg));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/bin/execute.ts"],"names":[],"mappings":";AAEA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,GAAG,GAAG,OAAO,CAA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pD,kBAAkB,CAAC,UAAU,GAAG,kBAAkB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7E,CAAC;IACD,IAAI,kBAAkB,CAAC,UAAU,KAAK,EAAE,EAAE,CAAC;QACzC,OAAO,kBAAkB,CAAC,UAAU,CAAC;IACvC,CAAC;IAED,kBAAkB,CAAC,qBAAqB,GAAG,iBAAiB,CAC1D,kBAAkB,CAAC,qBAAqB,CACzC,CAAC;IAEF,UAAU,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO;QACrC,CAAC,CAAC,iBAAiB,CAAC,UAAU,CAAC,OAAO,CAAC;QACvC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC;IAEvB,OAAO,eAAe,CAAC,YAAY,EAAE,kBAAkB,EAAE,UAAU,CAAC;SACjE,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,wEAAwE,CAAC,CAAC;SAC3F,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC;AAED,IAAI,EAAE;KACH,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAC3B,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\n// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { Log } from \"./execute-helpers.js\";\nimport { buildGetConfig } from \"./execute-helpers.js\";\nimport {\n prefixUrlProtocol,\n promptServiceInformation,\n promptMiscConfig,\n promptWidgetConfig,\n validateDeployConfig,\n validateMiscConfig,\n validateWidgetConfig,\n} from \"./execute-configs.js\";\nimport chalk from \"chalk\";\nimport { generateProject } from \"../generateProject.js\";\n\nconst log = console.log;\nconst white: Log = (msg) => log(chalk.white(msg));\nconst green: Log = (msg) => log(chalk.green(msg));\nconst red: Log = (msg) => log(chalk.red(msg));\nconst gray: Log = (msg) => log(chalk.gray(msg));\n\nasync function main(): Promise<void> {\n green(\n \"\\nThis tool generates code scaffold for custom widgets in the Azure API Management’s developer portal. Learn more at https://aka.ms/apimdocs/portal/customwidgets.\\n\",\n );\n\n const getConfig = buildGetConfig(gray, red);\n\n white(\"Specify the custom widget configuration.\");\n const widgetConfig = await getConfig(promptWidgetConfig, validateWidgetConfig);\n white(\"Specify the Azure API Management service configuration.\");\n const serviceInformation = await getConfig(promptServiceInformation, validateDeployConfig);\n white(\"Specify other options\");\n const miscConfig = await getConfig(promptMiscConfig, validateMiscConfig);\n\n if (serviceInformation.resourceId[0] === \"/\") {\n serviceInformation.resourceId = serviceInformation.resourceId.slice(1);\n }\n if (serviceInformation.resourceId.slice(-1) === \"/\") {\n serviceInformation.resourceId = serviceInformation.resourceId.slice(0, -1);\n }\n if (serviceInformation.apiVersion === \"\") {\n delete serviceInformation.apiVersion;\n }\n\n serviceInformation.managementApiEndpoint = prefixUrlProtocol(\n serviceInformation.managementApiEndpoint,\n );\n\n miscConfig.openUrl = miscConfig.openUrl\n ? prefixUrlProtocol(miscConfig.openUrl)\n : miscConfig.openUrl;\n\n return generateProject(widgetConfig, serviceInformation, miscConfig)\n .then(() => green(\"\\nThe custom widget’s code scaffold has been successfully generated.\\n\"))\n .catch(console.error);\n}\n\nmain()\n .then(() => process.exit(0))\n .catch((err) => {\n console.error(err);\n process.exit(1);\n });\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ServiceInformation, Options, WidgetConfig } from "./scaffolding.js";
|
|
2
|
+
/**
|
|
3
|
+
* Generates a scaffold project of Custom widget for API Managements' Dev Portal.
|
|
4
|
+
*
|
|
5
|
+
* @param widgetConfig - JSON object with data required by DevPortal to handle a widget integration.
|
|
6
|
+
* @param deploymentConfig - JSON object with data for deployment.
|
|
7
|
+
* @param options - JSON object with other data, which will not be stored in the DevPortal.
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateProject(widgetConfig: WidgetConfig, deploymentConfig: ServiceInformation, options?: Options): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=generateProject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateProject.d.ts","sourceRoot":"","sources":["../../src/generateProject.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAelF;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,YAAY,EAAE,YAAY,EAC1B,gBAAgB,EAAE,kBAAkB,EACpC,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,IAAI,CAAC,CA8Df"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT
|
|
3
|
-
import { OVERRIDE_DEFAULT_PORT, OVERRIDE_PORT_KEY, displayNameToName, widgetFolderName, } from "./scaffolding";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { OVERRIDE_DEFAULT_PORT, OVERRIDE_PORT_KEY, displayNameToName, widgetFolderName, } from "./scaffolding.js";
|
|
4
|
+
import { sourceDir } from "./sourceDir.js";
|
|
5
|
+
import { join as joinPath, parse as parsePath } from "node:path";
|
|
6
|
+
import fs from "node:fs/promises";
|
|
7
|
+
import { getTemplates } from "./getTemplates.js";
|
|
7
8
|
import mustache from "mustache";
|
|
8
9
|
const templateSuffix = ".mustache";
|
|
9
10
|
/**
|
|
@@ -41,19 +42,19 @@ export async function generateProject(widgetConfig, deploymentConfig, options =
|
|
|
41
42
|
fileData = mustache.render(fileData, {
|
|
42
43
|
name,
|
|
43
44
|
displayName: widgetConfig.displayName,
|
|
44
|
-
config: JSON.stringify(
|
|
45
|
+
config: JSON.stringify({ ...widgetConfig, name }, null, "\t"),
|
|
45
46
|
configDeploy: JSON.stringify(deploymentConfig, null, "\t"),
|
|
46
47
|
configAdditional: JSON.stringify(configAdditional, null, "\t"),
|
|
47
48
|
serverSettings: JSON.stringify(serverSettings, null, "\t"),
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
51
|
let relativePath = file;
|
|
51
|
-
if (
|
|
52
|
+
if (sourceDir.includes("\\")) {
|
|
52
53
|
relativePath = relativePath.replace(/\//g, "\\");
|
|
53
54
|
}
|
|
54
55
|
relativePath = relativePath
|
|
55
|
-
.replace(joinPath(
|
|
56
|
-
.replace(joinPath(
|
|
56
|
+
.replace(joinPath(sourceDir, "..", "templates", "_shared"), "")
|
|
57
|
+
.replace(joinPath(sourceDir, "..", "templates", widgetConfig.technology), "")
|
|
57
58
|
.replace(templateSuffix, "");
|
|
58
59
|
const newFilePath = joinPath(process.cwd(), widgetFolderName(name), relativePath);
|
|
59
60
|
const dir = parsePath(newFilePath).dir;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateProject.js","sourceRoot":"","sources":["../../src/generateProject.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,MAAM,cAAc,GAAG,WAAW,CAAC;AAEnC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,YAA0B,EAC1B,gBAAoC,EACpC,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,CAAC;QACzC,MAAM,EAAE,CAAC,SAAS,CAAC,WAAW,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC1D,CAAC,CAAC;IAEF,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IAC9D,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5C,MAAM,cAAc,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO;AACT,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ServiceInformation, Options, WidgetConfig } from \"./scaffolding.js\";\nimport {\n OVERRIDE_DEFAULT_PORT,\n OVERRIDE_PORT_KEY,\n displayNameToName,\n widgetFolderName,\n} from \"./scaffolding.js\";\nimport { sourceDir } from \"./sourceDir.js\";\nimport { join as joinPath, parse as parsePath } from \"node:path\";\nimport fs from \"node:fs/promises\";\nimport { getTemplates } from \"./getTemplates.js\";\nimport mustache from \"mustache\";\n\nconst templateSuffix = \".mustache\";\n\n/**\n * Generates a scaffold project of Custom widget for API Managements' Dev Portal.\n *\n * @param widgetConfig - JSON object with data required by DevPortal to handle a widget integration.\n * @param deploymentConfig - JSON object with data for deployment.\n * @param options - JSON object with other data, which will not be stored in the DevPortal.\n */\nexport async function generateProject(\n widgetConfig: WidgetConfig,\n deploymentConfig: ServiceInformation,\n options: Options = {},\n): Promise<void> {\n const { openUrl, configAdvancedTenantId, configAdvancedRedirectUri } = options;\n const openUrlParsed = openUrl ? new URL(openUrl) : null;\n if (openUrlParsed) {\n openUrlParsed.searchParams.append(OVERRIDE_PORT_KEY, String(OVERRIDE_DEFAULT_PORT));\n }\n\n const name = displayNameToName(widgetConfig.displayName);\n const serverSettings = {\n port: OVERRIDE_DEFAULT_PORT,\n open: openUrlParsed ? openUrlParsed.toString() : true,\n };\n\n const configAdditional = {\n interactiveBrowserCredentialOptions: { redirectUri: \"http://localhost:1337\" } as {\n redirectUri: string;\n tenantId?: string;\n },\n };\n if (configAdvancedTenantId) {\n configAdditional.interactiveBrowserCredentialOptions.tenantId = configAdvancedTenantId;\n }\n if (configAdvancedRedirectUri) {\n configAdditional.interactiveBrowserCredentialOptions.redirectUri = configAdvancedRedirectUri;\n }\n\n const renderTemplate = async (file: string): Promise<void> => {\n const isTemplate = file.endsWith(templateSuffix);\n const encoding = file.endsWith(\".ttf\") ? \"binary\" : \"utf8\";\n let fileData = await fs.readFile(file, { encoding });\n if (isTemplate) {\n fileData = mustache.render(fileData, {\n name,\n displayName: widgetConfig.displayName,\n config: JSON.stringify({ ...widgetConfig, name }, null, \"\\t\"),\n configDeploy: JSON.stringify(deploymentConfig, null, \"\\t\"),\n configAdditional: JSON.stringify(configAdditional, null, \"\\t\"),\n serverSettings: JSON.stringify(serverSettings, null, \"\\t\"),\n });\n }\n\n let relativePath = file;\n if (sourceDir.includes(\"\\\\\")) {\n relativePath = relativePath.replace(/\\//g, \"\\\\\");\n }\n relativePath = relativePath\n .replace(joinPath(sourceDir, \"..\", \"templates\", \"_shared\"), \"\")\n .replace(joinPath(sourceDir, \"..\", \"templates\", widgetConfig.technology), \"\")\n .replace(templateSuffix, \"\");\n const newFilePath = joinPath(process.cwd(), widgetFolderName(name), relativePath);\n const dir = parsePath(newFilePath).dir;\n\n await fs.mkdir(dir, { recursive: true });\n await fs.writeFile(newFilePath, fileData, { encoding });\n };\n\n const templates = await getTemplates(widgetConfig.technology);\n for (const file of Object.values(templates)) {\n await renderTemplate(file);\n }\n\n return;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTemplates.d.ts","sourceRoot":"","sources":["../../src/getTemplates.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAKrD,wBAAsB,YAAY,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAQ5E"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
3
|
import { glob } from "glob";
|
|
4
|
-
import { join as pathJoin } from "path";
|
|
4
|
+
import { join as pathJoin } from "node:path";
|
|
5
|
+
import { sourceDir } from "./sourceDir.js";
|
|
5
6
|
export async function getTemplates(template) {
|
|
6
|
-
const sharedFiles = await getFiles(pathJoin(
|
|
7
|
-
const templateFiles = await getFiles(pathJoin(
|
|
7
|
+
const sharedFiles = await getFiles(pathJoin(sourceDir, "..", "templates", "_shared", "**", "**", "*.*"));
|
|
8
|
+
const templateFiles = await getFiles(pathJoin(sourceDir, "..", "templates", template, "**", "**", "*.*"));
|
|
8
9
|
return [...sharedFiles, ...templateFiles];
|
|
9
10
|
}
|
|
10
11
|
async function getFiles(path) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTemplates.js","sourceRoot":"","sources":["../../src/getTemplates.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,QAAsB;IACvD,MAAM,WAAW,GAAG,MAAM,QAAQ,CAChC,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CACrE,CAAC;IACF,MAAM,aAAa,GAAG,MAAM,QAAQ,CAClC,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CACpE,CAAC;IACF,OAAO,CAAC,GAAG,WAAW,EAAE,GAAG,aAAa,CAAC,CAAC;AAC5C,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,IAAY;IAClC,iHAAiH;IACjH,kEAAkE;IAClE,wGAAwG;IACxG,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAChD,OAAO,IAAI,CAAC,cAAc,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { ScaffoldTech } from \"./scaffolding.js\";\nimport { glob } from \"glob\";\nimport { join as pathJoin } from \"node:path\";\nimport { sourceDir } from \"./sourceDir.js\";\n\nexport async function getTemplates(template: ScaffoldTech): Promise<string[]> {\n const sharedFiles = await getFiles(\n pathJoin(sourceDir, \"..\", \"templates\", \"_shared\", \"**\", \"**\", \"*.*\"),\n );\n const templateFiles = await getFiles(\n pathJoin(sourceDir, \"..\", \"templates\", template, \"**\", \"**\", \"*.*\"),\n );\n return [...sharedFiles, ...templateFiles];\n}\n\nasync function getFiles(path: string): Promise<string[]> {\n // Starting from glob v8 `\\` is only used as an escape character, and never as a path separator in glob patterns.\n // Glob pattern paths must use forward-slashes as path separators.\n // See https://github.com/isaacs/node-glob/blob/af57da21c7722bb6edb687ccd4ad3b99d3e7a333/changelog.md#80\n const normalizedPath = path.replace(/\\\\/g, \"/\");\n return glob(normalizedPath, { dot: true });\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation https://aka.ms/apimdocs/portal/customwidgets
|
|
3
|
+
*/
|
|
4
|
+
export { OVERRIDE_PORT_KEY, OVERRIDE_DEFAULT_PORT, TECHNOLOGIES, displayNameToName, widgetFolderName, } from "./scaffolding.js";
|
|
5
|
+
export { generateProject } from "./generateProject.js";
|
|
6
|
+
export type { WidgetConfig as CustomWidgetCommonConfig, ServiceInformation as DeploymentConfig, Options, ScaffoldTech, } from "./scaffolding.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA;;GAEG;AAEH,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EACV,YAAY,IAAI,wBAAwB,EACxC,kBAAkB,IAAI,gBAAgB,EACtC,OAAO,EACP,YAAY,GACb,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
/**
|
|
4
|
+
* @packageDocumentation https://aka.ms/apimdocs/portal/customwidgets
|
|
5
|
+
*/
|
|
6
|
+
export { OVERRIDE_PORT_KEY, OVERRIDE_DEFAULT_PORT, TECHNOLOGIES, displayNameToName, widgetFolderName, } from "./scaffolding.js";
|
|
7
|
+
export { generateProject } from "./generateProject.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;GAEG;AAEH,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * @packageDocumentation https://aka.ms/apimdocs/portal/customwidgets\n */\n\nexport {\n OVERRIDE_PORT_KEY,\n OVERRIDE_DEFAULT_PORT,\n TECHNOLOGIES,\n displayNameToName,\n widgetFolderName,\n} from \"./scaffolding.js\";\nexport { generateProject } from \"./generateProject.js\";\nexport type {\n WidgetConfig as CustomWidgetCommonConfig,\n ServiceInformation as DeploymentConfig,\n Options,\n ScaffoldTech,\n} from \"./scaffolding.js\";\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unique identifier under which is specified which port to use for injecting locally hosted custom widget to a running DevPortal instance.
|
|
3
|
+
*/
|
|
4
|
+
export declare const OVERRIDE_PORT_KEY = "MS_APIM_CW_localhost_port";
|
|
5
|
+
/**
|
|
6
|
+
* Default port for running local dev server on.
|
|
7
|
+
*/
|
|
8
|
+
export declare const OVERRIDE_DEFAULT_PORT = 3000;
|
|
9
|
+
/** All supported technologies to scaffold a widget in. */
|
|
10
|
+
export type ScaffoldTech = "typescript" | "react" | "vue";
|
|
11
|
+
/** List of all supported technologies to scaffold a widget in. */
|
|
12
|
+
export declare const TECHNOLOGIES: ScaffoldTech[];
|
|
13
|
+
/** Main data which DevPortal needs for every custom widget. */
|
|
14
|
+
export interface WidgetConfig {
|
|
15
|
+
/** Name of the custom widget which is displayed in DevPortal. */
|
|
16
|
+
displayName: string;
|
|
17
|
+
/** Technology to use to scaffold the widget. */
|
|
18
|
+
technology: ScaffoldTech;
|
|
19
|
+
/** Optional URL for a custom icon, which will be displayed in DevPortal widget list. */
|
|
20
|
+
iconUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Data needed for deployment. */
|
|
23
|
+
export interface ServiceInformation {
|
|
24
|
+
/** Management API endpoint to use (e.g. management.azure.com). */
|
|
25
|
+
managementApiEndpoint: string;
|
|
26
|
+
/** resourceId of your APIM service, must be in this format: subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.ApiManagement/service/<service-name> */
|
|
27
|
+
resourceId: string;
|
|
28
|
+
/** optional override which API version to use during deployment */
|
|
29
|
+
apiVersion?: string;
|
|
30
|
+
}
|
|
31
|
+
/** Miscellaneous data for scaffolding of a custom widget which will not be stored in DevPortal. */
|
|
32
|
+
export interface Options {
|
|
33
|
+
/** The URL to open after development server of the widget is started (URL of your Developer Portal). If you don't want to use this feature, set it to `false`. If you want to open just the widget page, set it to `true`. */
|
|
34
|
+
openUrl?: string;
|
|
35
|
+
/** advance configuration option for the deploy function - tenant ID for InteractiveBrowserCredentialNodeOptions */
|
|
36
|
+
configAdvancedTenantId?: string;
|
|
37
|
+
/** advance configuration option for the deploy function - redirect URI for InteractiveBrowserCredentialNodeOptions */
|
|
38
|
+
configAdvancedRedirectUri?: string;
|
|
39
|
+
}
|
|
40
|
+
export type Configs = WidgetConfig | ServiceInformation | Options;
|
|
41
|
+
/**
|
|
42
|
+
* Converts user defined name of a custom widget to a unique ID, which is in context of Dev Portal known as "name".
|
|
43
|
+
* Prefix "cw-" to avoid conflicts with existing widgets.
|
|
44
|
+
*
|
|
45
|
+
* @param displayName - User defined name of the custom widget.
|
|
46
|
+
*/
|
|
47
|
+
export declare const displayNameToName: (displayName: string) => string;
|
|
48
|
+
/**
|
|
49
|
+
* Returns name of the folder for widget project.
|
|
50
|
+
*
|
|
51
|
+
* @param name - name of the widget
|
|
52
|
+
*/
|
|
53
|
+
export declare const widgetFolderName: (name: string) => string;
|
|
54
|
+
//# sourceMappingURL=scaffolding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scaffolding.d.ts","sourceRoot":"","sources":["../../src/scaffolding.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,iBAAiB,8BAA8B,CAAC;AAC7D;;GAEG;AACH,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,0DAA0D;AAC1D,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,OAAO,GAAG,KAAK,CAAC;AAE1D,kEAAkE;AAClE,eAAO,MAAM,YAAY,EAAE,YAAY,EAAmC,CAAC;AAE3E,gEAAg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E,CAC/D,kBAAkB,CAChB,CAAC,KAAK,GAAG,WAAW,CAAC;KAClB,SAAS,CAAC,KAAK,CAAC;KAChB,WAAW,EAAE;KACb,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;KAC/B,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAC/B,CAAC;AAEJ;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,+BAA+B,IAAI,EAAE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT
|
|
1
|
+
{"version":3,"file":"scaffolding.js","sourceRoot":"","sources":["../../src/scaffolding.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,2BAA2B,CAAC;AAC7D;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAK1C,kEAAkE;AAClE,MAAM,CAAC,MAAM,YAAY,GAAmB,CAAC,YAAY,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAkC3E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,WAAmB,EAAU,EAAE,CAC/D,kBAAkB,CAChB,CAAC,KAAK,GAAG,WAAW,CAAC;KAClB,SAAS,CAAC,KAAK,CAAC;KAChB,WAAW,EAAE;KACb,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;KAC/B,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAC/B,CAAC;AAEJ;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,+BAA+B,IAAI,EAAE,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Unique identifier under which is specified which port to use for injecting locally hosted custom widget to a running DevPortal instance.\n */\nexport const OVERRIDE_PORT_KEY = \"MS_APIM_CW_localhost_port\";\n/**\n * Default port for running local dev server on.\n */\nexport const OVERRIDE_DEFAULT_PORT = 3000;\n\n/** All supported technologies to scaffold a widget in. */\nexport type ScaffoldTech = \"typescript\" | \"react\" | \"vue\";\n\n/** List of all supported technologies to scaffold a widget in. */\nexport const TECHNOLOGIES: ScaffoldTech[] = [\"typescript\", \"react\", \"vue\"];\n\n/** Main data which DevPortal needs for every custom widget. */\nexport interface WidgetConfig {\n /** Name of the custom widget which is displayed in DevPortal. */\n displayName: string;\n /** Technology to use to scaffold the widget. */\n technology: ScaffoldTech;\n /** Optional URL for a custom icon, which will be displayed in DevPortal widget list. */\n iconUrl?: string;\n}\n\n/** Data needed for deployment. */\nexport interface ServiceInformation {\n /** Management API endpoint to use (e.g. management.azure.com). */\n managementApiEndpoint: string;\n /** resourceId of your APIM service, must be in this format: subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.ApiManagement/service/<service-name> */\n resourceId: string;\n /** optional override which API version to use during deployment */\n apiVersion?: string;\n}\n\n/** Miscellaneous data for scaffolding of a custom widget which will not be stored in DevPortal. */\nexport interface Options {\n /** The URL to open after development server of the widget is started (URL of your Developer Portal). If you don't want to use this feature, set it to `false`. If you want to open just the widget page, set it to `true`. */\n openUrl?: string;\n /** advance configuration option for the deploy function - tenant ID for InteractiveBrowserCredentialNodeOptions */\n configAdvancedTenantId?: string;\n /** advance configuration option for the deploy function - redirect URI for InteractiveBrowserCredentialNodeOptions */\n configAdvancedRedirectUri?: string;\n}\n\nexport type Configs = WidgetConfig | ServiceInformation | Options;\n\n/**\n * Converts user defined name of a custom widget to a unique ID, which is in context of Dev Portal known as \"name\".\n * Prefix \"cw-\" to avoid conflicts with existing widgets.\n *\n * @param displayName - User defined name of the custom widget.\n */\nexport const displayNameToName = (displayName: string): string =>\n encodeURIComponent(\n (\"cw-\" + displayName)\n .normalize(\"NFD\")\n .toLowerCase()\n .replace(/[\\u0300-\\u036f]/g, \"\")\n .replace(/[^a-z0-9-]/g, \"-\"),\n );\n\n/**\n * Returns name of the folder for widget project.\n *\n * @param name - name of the widget\n */\nexport const widgetFolderName = (name: string): string => `azure-api-management-widget-${name}`;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sourceDir.d.ts","sourceRoot":"","sources":["../../src/sourceDir.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,SAAS,QAA0C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
export const sourceDir = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
//# sourceMappingURL=sourceDir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sourceDir.js","sourceRoot":"","sources":["../../src/sourceDir.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,6DAA6D;AAC7D,aAAa;AACb,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { dirname } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nexport const sourceDir = dirname(fileURLToPath(import.meta.url));\n"]}
|