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