@azure/api-management-custom-widgets-scaffolder 1.0.0-beta.3 → 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.
Files changed (88) hide show
  1. package/LICENSE +17 -17
  2. package/README.md +2 -2
  3. package/bin/{execute.js → execute.cjs} +120 -494
  4. package/bin/execute.cjs.map +1 -0
  5. package/bin/templates/react/package.json.mustache +1 -1
  6. package/bin/templates/typescript/package.json.mustache +1 -1
  7. package/bin/templates/vue/package.json.mustache +1 -1
  8. package/dist/commonjs/bin/execute-configs.d.ts +15 -0
  9. package/dist/commonjs/bin/execute-configs.d.ts.map +1 -0
  10. package/dist/commonjs/bin/execute-configs.js +157 -0
  11. package/dist/commonjs/bin/execute-configs.js.map +1 -0
  12. package/dist/commonjs/bin/execute-helpers.d.ts +12 -0
  13. package/dist/commonjs/bin/execute-helpers.d.ts.map +1 -0
  14. package/dist/commonjs/bin/execute-helpers.js +50 -0
  15. package/dist/commonjs/bin/execute-helpers.js.map +1 -0
  16. package/dist/commonjs/bin/execute.d.ts +3 -0
  17. package/dist/commonjs/bin/execute.d.ts.map +1 -0
  18. package/dist/commonjs/bin/execute.js +48 -0
  19. package/dist/commonjs/bin/execute.js.map +1 -0
  20. package/dist/commonjs/generateProject.d.ts +10 -0
  21. package/dist/commonjs/generateProject.d.ts.map +1 -0
  22. package/dist/commonjs/generateProject.js +74 -0
  23. package/dist/commonjs/generateProject.js.map +1 -0
  24. package/dist/commonjs/getTemplates.d.ts +3 -0
  25. package/dist/commonjs/getTemplates.d.ts.map +1 -0
  26. package/dist/commonjs/getTemplates.js +21 -0
  27. package/dist/commonjs/getTemplates.js.map +1 -0
  28. package/dist/commonjs/index.d.ts +7 -0
  29. package/dist/commonjs/index.d.ts.map +1 -0
  30. package/dist/commonjs/index.js +17 -0
  31. package/dist/commonjs/index.js.map +1 -0
  32. package/dist/commonjs/package.json +3 -0
  33. package/{types/latest/api-management-custom-widgets-scaffolder.d.ts → dist/commonjs/scaffolding.d.ts} +54 -74
  34. package/dist/commonjs/scaffolding.d.ts.map +1 -0
  35. package/dist/commonjs/scaffolding.js +35 -0
  36. package/dist/commonjs/scaffolding.js.map +1 -0
  37. package/dist/commonjs/sourceDir-cjs.cjs.map +1 -0
  38. package/dist/commonjs/sourceDir-cjs.d.cts.map +1 -0
  39. package/dist/commonjs/sourceDir.d.ts +2 -0
  40. package/dist/commonjs/sourceDir.js +7 -0
  41. package/dist/commonjs/tsdoc-metadata.json +11 -0
  42. package/dist/esm/bin/execute-configs.d.ts +15 -0
  43. package/dist/esm/bin/execute-configs.d.ts.map +1 -0
  44. package/dist/esm/bin/execute-configs.js +150 -0
  45. package/dist/esm/bin/execute-configs.js.map +1 -0
  46. package/dist/esm/bin/execute-helpers.d.ts +12 -0
  47. package/dist/esm/bin/execute-helpers.d.ts.map +1 -0
  48. package/{dist-esm/src → dist/esm}/bin/execute-helpers.js +3 -3
  49. package/dist/esm/bin/execute-helpers.js.map +1 -0
  50. package/dist/esm/bin/execute.d.ts +3 -0
  51. package/dist/esm/bin/execute.d.ts.map +1 -0
  52. package/{dist-esm/src → dist/esm}/bin/execute.js +4 -4
  53. package/dist/esm/bin/execute.js.map +1 -0
  54. package/dist/esm/generateProject.d.ts +10 -0
  55. package/dist/esm/generateProject.d.ts.map +1 -0
  56. package/{dist-esm/src → dist/esm}/generateProject.js +10 -9
  57. package/dist/esm/generateProject.js.map +1 -0
  58. package/dist/esm/getTemplates.d.ts +3 -0
  59. package/dist/esm/getTemplates.d.ts.map +1 -0
  60. package/{dist-esm/src → dist/esm}/getTemplates.js +5 -4
  61. package/dist/esm/getTemplates.js.map +1 -0
  62. package/dist/esm/index.d.ts +7 -0
  63. package/dist/esm/index.d.ts.map +1 -0
  64. package/dist/esm/index.js +8 -0
  65. package/dist/esm/index.js.map +1 -0
  66. package/dist/esm/package.json +3 -0
  67. package/dist/esm/scaffolding.d.ts +54 -0
  68. package/dist/esm/scaffolding.d.ts.map +1 -0
  69. package/{dist-esm/src → dist/esm}/scaffolding.js +3 -2
  70. package/dist/esm/scaffolding.js.map +1 -0
  71. package/dist/esm/sourceDir.d.ts +2 -0
  72. package/dist/esm/sourceDir.d.ts.map +1 -0
  73. package/dist/esm/sourceDir.js +8 -0
  74. package/dist/esm/sourceDir.js.map +1 -0
  75. package/package.json +70 -72
  76. package/dist/index.js +0 -122
  77. package/dist/index.js.map +0 -1
  78. package/dist-esm/src/bin/execute-configs.js +0 -139
  79. package/dist-esm/src/bin/execute-configs.js.map +0 -1
  80. package/dist-esm/src/bin/execute-helpers.js.map +0 -1
  81. package/dist-esm/src/bin/execute.js.map +0 -1
  82. package/dist-esm/src/generateProject.browser.js +0 -6
  83. package/dist-esm/src/generateProject.browser.js.map +0 -1
  84. package/dist-esm/src/generateProject.js.map +0 -1
  85. package/dist-esm/src/getTemplates.js.map +0 -1
  86. package/dist-esm/src/index.js +0 -8
  87. package/dist-esm/src/index.js.map +0 -1
  88. package/dist-esm/src/scaffolding.js.map +0 -1
@@ -1,26 +1,22 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var inquirer = require('inquirer');
5
4
  var Parser = require('yargs-parser');
6
- var assert = require('assert');
5
+ require('assert');
7
6
  var path = require('path');
8
7
  var fs = require('fs');
9
8
  var util = require('util');
10
9
  var url = require('url');
11
10
  var chalk = require('chalk');
11
+ var node_path = require('node:path');
12
+ var node_url = require('node:url');
13
+ var fs$1 = require('node:fs/promises');
12
14
  var glob = require('glob');
13
15
  var mustache = require('mustache');
14
16
 
15
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
-
17
- var inquirer__default = /*#__PURE__*/_interopDefaultLegacy(inquirer);
18
- var Parser__default = /*#__PURE__*/_interopDefaultLegacy(Parser);
19
- var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
20
- var mustache__default = /*#__PURE__*/_interopDefaultLegacy(mustache);
21
-
17
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
22
18
  // Copyright (c) Microsoft Corporation.
23
- // Licensed under the MIT license.
19
+ // Licensed under the MIT License.
24
20
  /**
25
21
  * Unique identifier under which is specified which port to use for injecting locally hosted custom widget to a running DevPortal instance.
26
22
  */
@@ -33,10 +29,11 @@ const OVERRIDE_DEFAULT_PORT = 3000;
33
29
  const TECHNOLOGIES = ["typescript", "react", "vue"];
34
30
  /**
35
31
  * Converts user defined name of a custom widget to a unique ID, which is in context of Dev Portal known as "name".
32
+ * Prefix "cw-" to avoid conflicts with existing widgets.
36
33
  *
37
34
  * @param displayName - User defined name of the custom widget.
38
35
  */
39
- const displayNameToName = (displayName) => encodeURIComponent(displayName
36
+ const displayNameToName = (displayName) => encodeURIComponent(("cw-" + displayName)
40
37
  .normalize("NFD")
41
38
  .toLowerCase()
42
39
  .replace(/[\u0300-\u036f]/g, "")
@@ -49,6 +46,7 @@ const displayNameToName = (displayName) => encodeURIComponent(displayName
49
46
  const widgetFolderName = (name) => `azure-api-management-widget-${name}`;
50
47
 
51
48
  // Copyright (c) Microsoft Corporation.
49
+ // Licensed under the MIT License.
52
50
  const fieldIdToName = {
53
51
  displayName: "Widget display name",
54
52
  technology: "Technology",
@@ -113,86 +111,88 @@ const validateMiscConfig = {
113
111
  return validateUrl(fieldIdToName.openUrl)(input);
114
112
  },
115
113
  };
116
- const promptWidgetConfig = (partial) => inquirer__default["default"].prompt([
117
- {
118
- name: "displayName",
119
- type: "input",
120
- message: fieldIdToName.displayName,
121
- validate: validateWidgetConfig.displayName,
122
- },
123
- {
124
- name: "technology",
125
- type: "list",
126
- message: fieldIdToName.technology,
127
- choices: [
128
- { name: "React", value: "react" },
129
- { name: "Vue", value: "vue" },
130
- { name: "TypeScript", value: "typescript" },
131
- ],
132
- },
133
- ], partial);
134
- const promptServiceInformation = (partial) => inquirer__default["default"].prompt([
135
- {
136
- name: "resourceId",
137
- type: "input",
138
- message: fieldIdToName.resourceId,
139
- validate: validateDeployConfig.resourceId,
140
- },
141
- {
142
- name: "managementApiEndpoint",
143
- type: "list",
144
- message: fieldIdToName.managementApiEndpoint,
145
- choices: [
146
- {
147
- name: "management.azure.com (if you're not sure what to select, use this option)",
148
- value: "management.azure.com",
149
- },
150
- { name: "management.usgovcloudapi.net", value: "management.usgovcloudapi.net" },
151
- { name: "management.chinacloudapi.cn", value: "management.chinacloudapi.cn" },
152
- ],
153
- transformer: prefixUrlProtocol,
154
- validate: validateDeployConfig.managementApiEndpoint,
155
- },
156
- {
157
- name: "apiVersion",
158
- type: "input",
159
- message: fieldIdToName.apiVersion + " (optional; e.g., 2021-08-01)",
160
- },
161
- ], partial);
162
- const promptMiscConfig = (partial) => inquirer__default["default"].prompt([
163
- {
164
- name: "openUrl",
165
- type: "input",
166
- message: fieldIdToName.openUrl +
167
- " for widget development and testing (optional; e.g., https://contoso.developer.azure-api.net/ or http://localhost:8080)",
168
- transformer: prefixUrlProtocol,
169
- validate: validateMiscConfig.openUrl,
170
- },
171
- {
172
- name: "configAdvancedTenantId",
173
- type: "input",
174
- message: fieldIdToName.configAdvancedTenantId +
175
- " to be used in Azure Identity InteractiveBrowserCredential class (optional)",
176
- validate: validateMiscConfig.openUrl,
177
- },
178
- {
179
- name: "configAdvancedRedirectUri",
180
- type: "input",
181
- message: fieldIdToName.configAdvancedRedirectUri +
182
- " to be used in Azure Identity InteractiveBrowserCredential class (optional; default is http://localhost:1337)",
183
- validate: validateMiscConfig.openUrl,
184
- },
185
- ], partial);
186
-
187
- class YError extends Error {
188
- constructor(msg) {
189
- super(msg || 'yargs error');
190
- this.name = 'YError';
191
- if (Error.captureStackTrace) {
192
- Error.captureStackTrace(this, YError);
193
- }
194
- }
195
- }
114
+ const promptWidgetConfig = async (partial) => {
115
+ const inquirerImport = await import('inquirer');
116
+ const inquirer = inquirerImport.default;
117
+ return inquirer.prompt([
118
+ {
119
+ name: "displayName",
120
+ type: "input",
121
+ message: fieldIdToName.displayName,
122
+ validate: validateWidgetConfig.displayName,
123
+ },
124
+ {
125
+ name: "technology",
126
+ type: "list",
127
+ message: fieldIdToName.technology,
128
+ choices: [
129
+ { name: "React", value: "react" },
130
+ { name: "Vue", value: "vue" },
131
+ { name: "TypeScript", value: "typescript" },
132
+ ],
133
+ },
134
+ ], partial);
135
+ };
136
+ const promptServiceInformation = async (partial) => {
137
+ const inquirerImport = await import('inquirer');
138
+ const inquirer = inquirerImport.default;
139
+ return inquirer.prompt([
140
+ {
141
+ name: "resourceId",
142
+ type: "input",
143
+ message: fieldIdToName.resourceId,
144
+ validate: validateDeployConfig.resourceId,
145
+ },
146
+ {
147
+ name: "managementApiEndpoint",
148
+ type: "list",
149
+ message: fieldIdToName.managementApiEndpoint,
150
+ choices: [
151
+ {
152
+ name: "management.azure.com (if you're not sure what to select, use this option)",
153
+ value: "management.azure.com",
154
+ },
155
+ { name: "management.usgovcloudapi.net", value: "management.usgovcloudapi.net" },
156
+ { name: "management.chinacloudapi.cn", value: "management.chinacloudapi.cn" },
157
+ ],
158
+ transformer: prefixUrlProtocol,
159
+ validate: validateDeployConfig.managementApiEndpoint,
160
+ },
161
+ {
162
+ name: "apiVersion",
163
+ type: "input",
164
+ message: fieldIdToName.apiVersion + " (optional; e.g., 2021-08-01)",
165
+ },
166
+ ], partial);
167
+ };
168
+ const promptMiscConfig = async (partial) => {
169
+ const inquirerImport = await import('inquirer');
170
+ const inquirer = inquirerImport.default;
171
+ return inquirer.prompt([
172
+ {
173
+ name: "openUrl",
174
+ type: "input",
175
+ message: fieldIdToName.openUrl +
176
+ " for widget development and testing (optional; e.g., https://contoso.developer.azure-api.net/ or http://localhost:8080)",
177
+ transformer: prefixUrlProtocol,
178
+ validate: validateMiscConfig.openUrl,
179
+ },
180
+ {
181
+ name: "configAdvancedTenantId",
182
+ type: "input",
183
+ message: fieldIdToName.configAdvancedTenantId +
184
+ " to be used in Azure Identity InteractiveBrowserCredential class (optional)",
185
+ validate: validateMiscConfig.openUrl,
186
+ },
187
+ {
188
+ name: "configAdvancedRedirectUri",
189
+ type: "input",
190
+ message: fieldIdToName.configAdvancedRedirectUri +
191
+ " to be used in Azure Identity InteractiveBrowserCredential class (optional; default is http://localhost:1337)",
192
+ validate: validateMiscConfig.openUrl,
193
+ },
194
+ ], partial);
195
+ };
196
196
 
197
197
  function getProcessArgvBinIndex() {
198
198
  if (isBundledElectronApp())
@@ -208,352 +208,6 @@ function isElectronApp() {
208
208
  function hideBin(argv) {
209
209
  return argv.slice(getProcessArgvBinIndex() + 1);
210
210
  }
211
- function getProcessArgvBin() {
212
- return process.argv[getProcessArgvBinIndex()];
213
- }
214
-
215
- const align = {
216
- right: alignRight,
217
- center: alignCenter
218
- };
219
- const top = 0;
220
- const right = 1;
221
- const bottom = 2;
222
- const left = 3;
223
- class UI {
224
- constructor(opts) {
225
- var _a;
226
- this.width = opts.width;
227
- this.wrap = (_a = opts.wrap) !== null && _a !== void 0 ? _a : true;
228
- this.rows = [];
229
- }
230
- span(...args) {
231
- const cols = this.div(...args);
232
- cols.span = true;
233
- }
234
- resetOutput() {
235
- this.rows = [];
236
- }
237
- div(...args) {
238
- if (args.length === 0) {
239
- this.div('');
240
- }
241
- if (this.wrap && this.shouldApplyLayoutDSL(...args) && typeof args[0] === 'string') {
242
- return this.applyLayoutDSL(args[0]);
243
- }
244
- const cols = args.map(arg => {
245
- if (typeof arg === 'string') {
246
- return this.colFromString(arg);
247
- }
248
- return arg;
249
- });
250
- this.rows.push(cols);
251
- return cols;
252
- }
253
- shouldApplyLayoutDSL(...args) {
254
- return args.length === 1 && typeof args[0] === 'string' &&
255
- /[\t\n]/.test(args[0]);
256
- }
257
- applyLayoutDSL(str) {
258
- const rows = str.split('\n').map(row => row.split('\t'));
259
- let leftColumnWidth = 0;
260
- // simple heuristic for layout, make sure the
261
- // second column lines up along the left-hand.
262
- // don't allow the first column to take up more
263
- // than 50% of the screen.
264
- rows.forEach(columns => {
265
- if (columns.length > 1 && mixin.stringWidth(columns[0]) > leftColumnWidth) {
266
- leftColumnWidth = Math.min(Math.floor(this.width * 0.5), mixin.stringWidth(columns[0]));
267
- }
268
- });
269
- // generate a table:
270
- // replacing ' ' with padding calculations.
271
- // using the algorithmically generated width.
272
- rows.forEach(columns => {
273
- this.div(...columns.map((r, i) => {
274
- return {
275
- text: r.trim(),
276
- padding: this.measurePadding(r),
277
- width: (i === 0 && columns.length > 1) ? leftColumnWidth : undefined
278
- };
279
- }));
280
- });
281
- return this.rows[this.rows.length - 1];
282
- }
283
- colFromString(text) {
284
- return {
285
- text,
286
- padding: this.measurePadding(text)
287
- };
288
- }
289
- measurePadding(str) {
290
- // measure padding without ansi escape codes
291
- const noAnsi = mixin.stripAnsi(str);
292
- return [0, noAnsi.match(/\s*$/)[0].length, 0, noAnsi.match(/^\s*/)[0].length];
293
- }
294
- toString() {
295
- const lines = [];
296
- this.rows.forEach(row => {
297
- this.rowToString(row, lines);
298
- });
299
- // don't display any lines with the
300
- // hidden flag set.
301
- return lines
302
- .filter(line => !line.hidden)
303
- .map(line => line.text)
304
- .join('\n');
305
- }
306
- rowToString(row, lines) {
307
- this.rasterize(row).forEach((rrow, r) => {
308
- let str = '';
309
- rrow.forEach((col, c) => {
310
- const { width } = row[c]; // the width with padding.
311
- const wrapWidth = this.negatePadding(row[c]); // the width without padding.
312
- let ts = col; // temporary string used during alignment/padding.
313
- if (wrapWidth > mixin.stringWidth(col)) {
314
- ts += ' '.repeat(wrapWidth - mixin.stringWidth(col));
315
- }
316
- // align the string within its column.
317
- if (row[c].align && row[c].align !== 'left' && this.wrap) {
318
- const fn = align[row[c].align];
319
- ts = fn(ts, wrapWidth);
320
- if (mixin.stringWidth(ts) < wrapWidth) {
321
- ts += ' '.repeat((width || 0) - mixin.stringWidth(ts) - 1);
322
- }
323
- }
324
- // apply border and padding to string.
325
- const padding = row[c].padding || [0, 0, 0, 0];
326
- if (padding[left]) {
327
- str += ' '.repeat(padding[left]);
328
- }
329
- str += addBorder(row[c], ts, '| ');
330
- str += ts;
331
- str += addBorder(row[c], ts, ' |');
332
- if (padding[right]) {
333
- str += ' '.repeat(padding[right]);
334
- }
335
- // if prior row is span, try to render the
336
- // current row on the prior line.
337
- if (r === 0 && lines.length > 0) {
338
- str = this.renderInline(str, lines[lines.length - 1]);
339
- }
340
- });
341
- // remove trailing whitespace.
342
- lines.push({
343
- text: str.replace(/ +$/, ''),
344
- span: row.span
345
- });
346
- });
347
- return lines;
348
- }
349
- // if the full 'source' can render in
350
- // the target line, do so.
351
- renderInline(source, previousLine) {
352
- const match = source.match(/^ */);
353
- const leadingWhitespace = match ? match[0].length : 0;
354
- const target = previousLine.text;
355
- const targetTextWidth = mixin.stringWidth(target.trimRight());
356
- if (!previousLine.span) {
357
- return source;
358
- }
359
- // if we're not applying wrapping logic,
360
- // just always append to the span.
361
- if (!this.wrap) {
362
- previousLine.hidden = true;
363
- return target + source;
364
- }
365
- if (leadingWhitespace < targetTextWidth) {
366
- return source;
367
- }
368
- previousLine.hidden = true;
369
- return target.trimRight() + ' '.repeat(leadingWhitespace - targetTextWidth) + source.trimLeft();
370
- }
371
- rasterize(row) {
372
- const rrows = [];
373
- const widths = this.columnWidths(row);
374
- let wrapped;
375
- // word wrap all columns, and create
376
- // a data-structure that is easy to rasterize.
377
- row.forEach((col, c) => {
378
- // leave room for left and right padding.
379
- col.width = widths[c];
380
- if (this.wrap) {
381
- wrapped = mixin.wrap(col.text, this.negatePadding(col), { hard: true }).split('\n');
382
- }
383
- else {
384
- wrapped = col.text.split('\n');
385
- }
386
- if (col.border) {
387
- wrapped.unshift('.' + '-'.repeat(this.negatePadding(col) + 2) + '.');
388
- wrapped.push("'" + '-'.repeat(this.negatePadding(col) + 2) + "'");
389
- }
390
- // add top and bottom padding.
391
- if (col.padding) {
392
- wrapped.unshift(...new Array(col.padding[top] || 0).fill(''));
393
- wrapped.push(...new Array(col.padding[bottom] || 0).fill(''));
394
- }
395
- wrapped.forEach((str, r) => {
396
- if (!rrows[r]) {
397
- rrows.push([]);
398
- }
399
- const rrow = rrows[r];
400
- for (let i = 0; i < c; i++) {
401
- if (rrow[i] === undefined) {
402
- rrow.push('');
403
- }
404
- }
405
- rrow.push(str);
406
- });
407
- });
408
- return rrows;
409
- }
410
- negatePadding(col) {
411
- let wrapWidth = col.width || 0;
412
- if (col.padding) {
413
- wrapWidth -= (col.padding[left] || 0) + (col.padding[right] || 0);
414
- }
415
- if (col.border) {
416
- wrapWidth -= 4;
417
- }
418
- return wrapWidth;
419
- }
420
- columnWidths(row) {
421
- if (!this.wrap) {
422
- return row.map(col => {
423
- return col.width || mixin.stringWidth(col.text);
424
- });
425
- }
426
- let unset = row.length;
427
- let remainingWidth = this.width;
428
- // column widths can be set in config.
429
- const widths = row.map(col => {
430
- if (col.width) {
431
- unset--;
432
- remainingWidth -= col.width;
433
- return col.width;
434
- }
435
- return undefined;
436
- });
437
- // any unset widths should be calculated.
438
- const unsetWidth = unset ? Math.floor(remainingWidth / unset) : 0;
439
- return widths.map((w, i) => {
440
- if (w === undefined) {
441
- return Math.max(unsetWidth, _minWidth(row[i]));
442
- }
443
- return w;
444
- });
445
- }
446
- }
447
- function addBorder(col, ts, style) {
448
- if (col.border) {
449
- if (/[.']-+[.']/.test(ts)) {
450
- return '';
451
- }
452
- if (ts.trim().length !== 0) {
453
- return style;
454
- }
455
- return ' ';
456
- }
457
- return '';
458
- }
459
- // calculates the minimum width of
460
- // a column, based on padding preferences.
461
- function _minWidth(col) {
462
- const padding = col.padding || [];
463
- const minWidth = 1 + (padding[left] || 0) + (padding[right] || 0);
464
- if (col.border) {
465
- return minWidth + 4;
466
- }
467
- return minWidth;
468
- }
469
- function getWindowWidth() {
470
- /* istanbul ignore next: depends on terminal */
471
- if (typeof process === 'object' && process.stdout && process.stdout.columns) {
472
- return process.stdout.columns;
473
- }
474
- return 80;
475
- }
476
- function alignRight(str, width) {
477
- str = str.trim();
478
- const strWidth = mixin.stringWidth(str);
479
- if (strWidth < width) {
480
- return ' '.repeat(width - strWidth) + str;
481
- }
482
- return str;
483
- }
484
- function alignCenter(str, width) {
485
- str = str.trim();
486
- const strWidth = mixin.stringWidth(str);
487
- /* istanbul ignore next */
488
- if (strWidth >= width) {
489
- return str;
490
- }
491
- return ' '.repeat((width - strWidth) >> 1) + str;
492
- }
493
- let mixin;
494
- function cliui(opts, _mixin) {
495
- mixin = _mixin;
496
- return new UI({
497
- width: (opts === null || opts === void 0 ? void 0 : opts.width) || getWindowWidth(),
498
- wrap: opts === null || opts === void 0 ? void 0 : opts.wrap
499
- });
500
- }
501
-
502
- // Minimal replacement for ansi string helpers "wrap-ansi" and "strip-ansi".
503
- // to facilitate ESM and Deno modules.
504
- // TODO: look at porting https://www.npmjs.com/package/wrap-ansi to ESM.
505
- // The npm application
506
- // Copyright (c) npm, Inc. and Contributors
507
- // Licensed on the terms of The Artistic License 2.0
508
- // See: https://github.com/npm/cli/blob/4c65cd952bc8627811735bea76b9b110cc4fc80e/lib/utils/ansi-trim.js
509
- const ansi = new RegExp('\x1b(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|' +
510
- '\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)', 'g');
511
- function stripAnsi(str) {
512
- return str.replace(ansi, '');
513
- }
514
- function wrap(str, width) {
515
- const [start, end] = str.match(ansi) || ['', ''];
516
- str = stripAnsi(str);
517
- let wrapped = '';
518
- for (let i = 0; i < str.length; i++) {
519
- if (i !== 0 && (i % width) === 0) {
520
- wrapped += '\n';
521
- }
522
- wrapped += str.charAt(i);
523
- }
524
- if (start && end) {
525
- wrapped = `${start}${wrapped}${end}`;
526
- }
527
- return wrapped;
528
- }
529
-
530
- // Bootstrap cliui with CommonJS dependencies:
531
-
532
- function ui (opts) {
533
- return cliui(opts, {
534
- stringWidth: (str) => {
535
- return [...str].length
536
- },
537
- stripAnsi,
538
- wrap
539
- })
540
- }
541
-
542
- function escalade (start, callback) {
543
- let dir = path.resolve('.', start);
544
- let tmp, stats = fs.statSync(dir);
545
-
546
- if (!stats.isDirectory()) {
547
- dir = path.dirname(dir);
548
- }
549
-
550
- while (true) {
551
- tmp = callback(dir, fs.readdirSync(dir));
552
- if (tmp) return path.resolve(dir, tmp);
553
- dir = path.dirname(tmp = dir);
554
- if (tmp === dir) break;
555
- }
556
- }
557
211
 
558
212
  var shim$1 = {
559
213
  fs: {
@@ -751,60 +405,22 @@ const y18n = (opts) => {
751
405
  return y18n$1(opts, shim$1)
752
406
  };
753
407
 
754
- const REQUIRE_ERROR = 'require is not supported by ESM';
755
- const REQUIRE_DIRECTORY_ERROR = 'loading a directory of commands is not supported yet for ESM';
756
-
757
408
  let __dirname$1;
758
409
  try {
759
- __dirname$1 = url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('execute.js', document.baseURI).href)));
410
+ __dirname$1 = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('execute.cjs', document.baseURI).href)));
760
411
  } catch (e) {
761
412
  __dirname$1 = process.cwd();
762
413
  }
763
414
  const mainFilename = __dirname$1.substring(0, __dirname$1.lastIndexOf('node_modules'));
764
415
 
765
416
  ({
766
- assert: {
767
- notStrictEqual: assert.notStrictEqual,
768
- strictEqual: assert.strictEqual
769
- },
770
- cliui: ui,
771
- findUp: escalade,
772
- getEnv: (key) => {
773
- return process.env[key]
774
- },
775
- inspect: util.inspect,
776
- getCallerFile: () => {
777
- throw new YError(REQUIRE_DIRECTORY_ERROR)
778
- },
779
- getProcessArgvBin,
780
417
  mainFilename: mainFilename || process.cwd(),
781
- Parser: Parser__default["default"],
782
- path: {
783
- basename: path.basename,
784
- dirname: path.dirname,
785
- extname: path.extname,
786
- relative: path.relative,
787
- resolve: path.resolve
788
- },
789
418
  process: {
790
- argv: () => process.argv,
791
419
  cwd: process.cwd,
792
- emitWarning: (warning, type) => process.emitWarning(warning, type),
793
- execPath: () => process.execPath,
794
420
  exit: process.exit,
795
421
  nextTick: process.nextTick,
796
422
  stdColumns: typeof process.stdout.columns !== 'undefined' ? process.stdout.columns : null
797
423
  },
798
- readFileSync: fs.readFileSync,
799
- require: () => {
800
- throw new YError(REQUIRE_ERROR)
801
- },
802
- requireDirectory: () => {
803
- throw new YError(REQUIRE_DIRECTORY_ERROR)
804
- },
805
- stringWidth: (str) => {
806
- return [...str].length
807
- },
808
424
  y18n: y18n({
809
425
  directory: path.resolve(__dirname$1, '../../../locales'),
810
426
  updateFiles: false
@@ -812,6 +428,7 @@ const mainFilename = __dirname$1.substring(0, __dirname$1.lastIndexOf('node_modu
812
428
  });
813
429
 
814
430
  // Copyright (c) Microsoft Corporation.
431
+ // Licensed under the MIT License.
815
432
  const extractConfigFromArgs = (argv, validateConfig, red) => {
816
433
  const configPartial = {};
817
434
  let missing = false;
@@ -837,7 +454,7 @@ const extractConfigFromArgs = (argv, validateConfig, red) => {
837
454
  return { configPartial, missing };
838
455
  };
839
456
  const buildGetConfig = (gray, red) => {
840
- const argv = Parser__default["default"](hideBin(process.argv));
457
+ const argv = Parser(hideBin(process.argv));
841
458
  return async (promptForConfig, validateConfig) => {
842
459
  const { configPartial, missing } = extractConfigFromArgs(argv, validateConfig, red);
843
460
  if (missing || !Object.values(configPartial).length) {
@@ -845,16 +462,23 @@ const buildGetConfig = (gray, red) => {
845
462
  }
846
463
  else {
847
464
  gray("Retrieved from the command parameters");
848
- Object.entries(configPartial).forEach(([key, value]) => { var _a; return value != null && gray(`${(_a = fieldIdToName[key]) !== null && _a !== void 0 ? _a : key}: ${value}`); });
465
+ Object.entries(configPartial).forEach(([key, value]) => value != null && gray(`${fieldIdToName[key] ?? key}: ${value}`));
849
466
  return configPartial;
850
467
  }
851
468
  };
852
469
  };
853
470
 
854
471
  // Copyright (c) Microsoft Corporation.
472
+ // Licensed under the MIT License.
473
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
474
+ // @ts-ignore
475
+ const sourceDir = node_path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('execute.cjs', document.baseURI).href))));
476
+
477
+ // Copyright (c) Microsoft Corporation.
478
+ // Licensed under the MIT License.
855
479
  async function getTemplates(template) {
856
- const sharedFiles = await getFiles(path.join(__dirname, "templates", "_shared", "**", "**", "*.*"));
857
- const templateFiles = await getFiles(path.join(__dirname, "templates", template, "**", "**", "*.*"));
480
+ const sharedFiles = await getFiles(node_path.join(sourceDir, "..", "templates", "_shared", "**", "**", "*.*"));
481
+ const templateFiles = await getFiles(node_path.join(sourceDir, "..", "templates", template, "**", "**", "*.*"));
858
482
  return [...sharedFiles, ...templateFiles];
859
483
  }
860
484
  async function getFiles(path) {
@@ -866,6 +490,7 @@ async function getFiles(path) {
866
490
  }
867
491
 
868
492
  // Copyright (c) Microsoft Corporation.
493
+ // Licensed under the MIT License.
869
494
  const templateSuffix = ".mustache";
870
495
  /**
871
496
  * Generates a scaffold project of Custom widget for API Managements' Dev Portal.
@@ -897,29 +522,29 @@ async function generateProject(widgetConfig, deploymentConfig, options = {}) {
897
522
  const renderTemplate = async (file) => {
898
523
  const isTemplate = file.endsWith(templateSuffix);
899
524
  const encoding = file.endsWith(".ttf") ? "binary" : "utf8";
900
- let fileData = await fs.promises.readFile(file, { encoding });
525
+ let fileData = await fs$1.readFile(file, { encoding });
901
526
  if (isTemplate) {
902
- fileData = mustache__default["default"].render(fileData, {
527
+ fileData = mustache.render(fileData, {
903
528
  name,
904
529
  displayName: widgetConfig.displayName,
905
- config: JSON.stringify(Object.assign(Object.assign({}, widgetConfig), { name }), null, "\t"),
530
+ config: JSON.stringify({ ...widgetConfig, name }, null, "\t"),
906
531
  configDeploy: JSON.stringify(deploymentConfig, null, "\t"),
907
532
  configAdditional: JSON.stringify(configAdditional, null, "\t"),
908
533
  serverSettings: JSON.stringify(serverSettings, null, "\t"),
909
534
  });
910
535
  }
911
536
  let relativePath = file;
912
- if (__dirname.includes("\\")) {
537
+ if (sourceDir.includes("\\")) {
913
538
  relativePath = relativePath.replace(/\//g, "\\");
914
539
  }
915
540
  relativePath = relativePath
916
- .replace(path.join(__dirname, "templates", "_shared"), "")
917
- .replace(path.join(__dirname, "templates", widgetConfig.technology), "")
541
+ .replace(node_path.join(sourceDir, "..", "templates", "_shared"), "")
542
+ .replace(node_path.join(sourceDir, "..", "templates", widgetConfig.technology), "")
918
543
  .replace(templateSuffix, "");
919
- const newFilePath = path.join(process.cwd(), widgetFolderName(name), relativePath);
920
- const dir = path.parse(newFilePath).dir;
921
- await fs.promises.mkdir(dir, { recursive: true });
922
- await fs.promises.writeFile(newFilePath, fileData, { encoding });
544
+ const newFilePath = node_path.join(process.cwd(), widgetFolderName(name), relativePath);
545
+ const dir = node_path.parse(newFilePath).dir;
546
+ await fs$1.mkdir(dir, { recursive: true });
547
+ await fs$1.writeFile(newFilePath, fileData, { encoding });
923
548
  };
924
549
  const templates = await getTemplates(widgetConfig.technology);
925
550
  for (const file of Object.values(templates)) {
@@ -929,10 +554,10 @@ async function generateProject(widgetConfig, deploymentConfig, options = {}) {
929
554
  }
930
555
 
931
556
  const log = console.log;
932
- const white = (msg) => log(chalk__default["default"].white(msg));
933
- const green = (msg) => log(chalk__default["default"].green(msg));
934
- const red = (msg) => log(chalk__default["default"].red(msg));
935
- const gray = (msg) => log(chalk__default["default"].gray(msg));
557
+ const white = (msg) => log(chalk.white(msg));
558
+ const green = (msg) => log(chalk.green(msg));
559
+ const red = (msg) => log(chalk.red(msg));
560
+ const gray = (msg) => log(chalk.gray(msg));
936
561
  async function main() {
937
562
  green("\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");
938
563
  const getConfig = buildGetConfig(gray, red);
@@ -965,3 +590,4 @@ main()
965
590
  console.error(err);
966
591
  process.exit(1);
967
592
  });
593
+ //# sourceMappingURL=execute.cjs.map