wp-studio 1.7.7-alpha1

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 (48) hide show
  1. package/LICENSE.md +257 -0
  2. package/README.md +87 -0
  3. package/dist/cli/_events-BeOo0LuG.js +116 -0
  4. package/dist/cli/appdata-07CF2rhg.js +21090 -0
  5. package/dist/cli/archive-xDmkN4wb.js +15942 -0
  6. package/dist/cli/browser-CgWK-yoe.js +44 -0
  7. package/dist/cli/certificate-manager-DdBumKZp.js +250 -0
  8. package/dist/cli/create-BHVhkvTx.js +80 -0
  9. package/dist/cli/create-ZS29BDDi.js +40999 -0
  10. package/dist/cli/delete-BgQn-elT.js +56 -0
  11. package/dist/cli/delete-g8pgaLna.js +132 -0
  12. package/dist/cli/get-wordpress-version-BwSCJujO.js +18 -0
  13. package/dist/cli/index-7pbG_s_U.js +434 -0
  14. package/dist/cli/index-BXRYeCYG.js +1393 -0
  15. package/dist/cli/index-T3F1GwxX.js +2668 -0
  16. package/dist/cli/is-errno-exception-t38xF2pB.js +6 -0
  17. package/dist/cli/list-BE_UBjL5.js +105 -0
  18. package/dist/cli/list-DKz0XxM7.js +1032 -0
  19. package/dist/cli/logger-actions-OaIvl-ai.js +45 -0
  20. package/dist/cli/login-B4PkfKOu.js +82 -0
  21. package/dist/cli/logout-BC9gKlTj.js +48 -0
  22. package/dist/cli/main.js +5 -0
  23. package/dist/cli/mu-plugins-GEfKsl5U.js +530 -0
  24. package/dist/cli/passwords-DyzWd9Xi.js +80 -0
  25. package/dist/cli/process-manager-daemon.js +327 -0
  26. package/dist/cli/process-manager-ipc-AUZeYYDT.js +454 -0
  27. package/dist/cli/proxy-daemon.js +197 -0
  28. package/dist/cli/run-wp-cli-command-BctnMDWG.js +88 -0
  29. package/dist/cli/sequential-BQFuixXz.js +46 -0
  30. package/dist/cli/server-files-C_oy-mnI.js +26 -0
  31. package/dist/cli/set-DknhAZpw.js +327 -0
  32. package/dist/cli/site-utils-CfsabjUn.js +243 -0
  33. package/dist/cli/snapshots-6XE53y_F.js +874 -0
  34. package/dist/cli/sqlite-integration-H4OwSlwR.js +83 -0
  35. package/dist/cli/start-CRJqm09_.js +90 -0
  36. package/dist/cli/status-CWNHIOaY.js +44 -0
  37. package/dist/cli/status-CWWx9jYF.js +110 -0
  38. package/dist/cli/stop-CQosmjqA.js +117 -0
  39. package/dist/cli/update-BgL2HKHW.js +101 -0
  40. package/dist/cli/validation-error-DqLxqQuA.js +40 -0
  41. package/dist/cli/wordpress-server-child.js +514 -0
  42. package/dist/cli/wordpress-server-ipc-Dwsg9jSb.js +140 -0
  43. package/dist/cli/wordpress-server-manager-CtiuJqEb.js +566 -0
  44. package/dist/cli/wordpress-version-utils-B6UVeTh_.js +51 -0
  45. package/dist/cli/wp-UGSnlkN0.js +103 -0
  46. package/package.json +73 -0
  47. package/patches/@wp-playground+wordpress+3.1.12.patch +28 -0
  48. package/scripts/postinstall-npm.mjs +38 -0
@@ -0,0 +1,1032 @@
1
+ import { P as PreviewCommandLoggerAction } from "./logger-actions-OaIvl-ai.js";
2
+ import { __, sprintf, _n } from "@wordpress/i18n";
3
+ import CliTable3 from "cli-table3";
4
+ import { a as Logger, k as getSiteByFolder, g as getAuthToken, L as LoggerError } from "./appdata-07CF2rhg.js";
5
+ import { c as constructFrom, d as differenceInCalendarDays, m as millisecondsInWeek, e as enUS, g as getSnapshotsFromAppdata, i as isSnapshotExpired, f as formatDurationUntilExpiry } from "./snapshots-6XE53y_F.js";
6
+ import { s as startOfWeek, t as toDate, a as getDefaultOptions, b as getColumnWidths } from "./index-7pbG_s_U.js";
7
+ function startOfISOWeek(date) {
8
+ return startOfWeek(date, { weekStartsOn: 1 });
9
+ }
10
+ function getISOWeekYear(date) {
11
+ const _date = toDate(date);
12
+ const year = _date.getFullYear();
13
+ const fourthOfJanuaryOfNextYear = constructFrom(date, 0);
14
+ fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
15
+ fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
16
+ const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
17
+ const fourthOfJanuaryOfThisYear = constructFrom(date, 0);
18
+ fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
19
+ fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
20
+ const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
21
+ if (_date.getTime() >= startOfNextYear.getTime()) {
22
+ return year + 1;
23
+ } else if (_date.getTime() >= startOfThisYear.getTime()) {
24
+ return year;
25
+ } else {
26
+ return year - 1;
27
+ }
28
+ }
29
+ function startOfISOWeekYear(date) {
30
+ const year = getISOWeekYear(date);
31
+ const fourthOfJanuary = constructFrom(date, 0);
32
+ fourthOfJanuary.setFullYear(year, 0, 4);
33
+ fourthOfJanuary.setHours(0, 0, 0, 0);
34
+ return startOfISOWeek(fourthOfJanuary);
35
+ }
36
+ function isDate(value) {
37
+ return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
38
+ }
39
+ function isValid(date) {
40
+ if (!isDate(date) && typeof date !== "number") {
41
+ return false;
42
+ }
43
+ const _date = toDate(date);
44
+ return !isNaN(Number(_date));
45
+ }
46
+ function startOfYear(date) {
47
+ const cleanDate = toDate(date);
48
+ const _date = constructFrom(date, 0);
49
+ _date.setFullYear(cleanDate.getFullYear(), 0, 1);
50
+ _date.setHours(0, 0, 0, 0);
51
+ return _date;
52
+ }
53
+ function getDayOfYear(date) {
54
+ const _date = toDate(date);
55
+ const diff = differenceInCalendarDays(_date, startOfYear(_date));
56
+ const dayOfYear = diff + 1;
57
+ return dayOfYear;
58
+ }
59
+ function getISOWeek(date) {
60
+ const _date = toDate(date);
61
+ const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
62
+ return Math.round(diff / millisecondsInWeek) + 1;
63
+ }
64
+ function getWeekYear(date, options) {
65
+ const _date = toDate(date);
66
+ const year = _date.getFullYear();
67
+ const defaultOptions = getDefaultOptions();
68
+ const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions.firstWeekContainsDate ?? defaultOptions.locale?.options?.firstWeekContainsDate ?? 1;
69
+ const firstWeekOfNextYear = constructFrom(date, 0);
70
+ firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
71
+ firstWeekOfNextYear.setHours(0, 0, 0, 0);
72
+ const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
73
+ const firstWeekOfThisYear = constructFrom(date, 0);
74
+ firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
75
+ firstWeekOfThisYear.setHours(0, 0, 0, 0);
76
+ const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
77
+ if (_date.getTime() >= startOfNextYear.getTime()) {
78
+ return year + 1;
79
+ } else if (_date.getTime() >= startOfThisYear.getTime()) {
80
+ return year;
81
+ } else {
82
+ return year - 1;
83
+ }
84
+ }
85
+ function startOfWeekYear(date, options) {
86
+ const defaultOptions = getDefaultOptions();
87
+ const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions.firstWeekContainsDate ?? defaultOptions.locale?.options?.firstWeekContainsDate ?? 1;
88
+ const year = getWeekYear(date, options);
89
+ const firstWeek = constructFrom(date, 0);
90
+ firstWeek.setFullYear(year, 0, firstWeekContainsDate);
91
+ firstWeek.setHours(0, 0, 0, 0);
92
+ const _date = startOfWeek(firstWeek, options);
93
+ return _date;
94
+ }
95
+ function getWeek(date, options) {
96
+ const _date = toDate(date);
97
+ const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
98
+ return Math.round(diff / millisecondsInWeek) + 1;
99
+ }
100
+ function addLeadingZeros(number, targetLength) {
101
+ const sign = number < 0 ? "-" : "";
102
+ const output = Math.abs(number).toString().padStart(targetLength, "0");
103
+ return sign + output;
104
+ }
105
+ const lightFormatters = {
106
+ // Year
107
+ y(date, token) {
108
+ const signedYear = date.getFullYear();
109
+ const year = signedYear > 0 ? signedYear : 1 - signedYear;
110
+ return addLeadingZeros(token === "yy" ? year % 100 : year, token.length);
111
+ },
112
+ // Month
113
+ M(date, token) {
114
+ const month = date.getMonth();
115
+ return token === "M" ? String(month + 1) : addLeadingZeros(month + 1, 2);
116
+ },
117
+ // Day of the month
118
+ d(date, token) {
119
+ return addLeadingZeros(date.getDate(), token.length);
120
+ },
121
+ // AM or PM
122
+ a(date, token) {
123
+ const dayPeriodEnumValue = date.getHours() / 12 >= 1 ? "pm" : "am";
124
+ switch (token) {
125
+ case "a":
126
+ case "aa":
127
+ return dayPeriodEnumValue.toUpperCase();
128
+ case "aaa":
129
+ return dayPeriodEnumValue;
130
+ case "aaaaa":
131
+ return dayPeriodEnumValue[0];
132
+ case "aaaa":
133
+ default:
134
+ return dayPeriodEnumValue === "am" ? "a.m." : "p.m.";
135
+ }
136
+ },
137
+ // Hour [1-12]
138
+ h(date, token) {
139
+ return addLeadingZeros(date.getHours() % 12 || 12, token.length);
140
+ },
141
+ // Hour [0-23]
142
+ H(date, token) {
143
+ return addLeadingZeros(date.getHours(), token.length);
144
+ },
145
+ // Minute
146
+ m(date, token) {
147
+ return addLeadingZeros(date.getMinutes(), token.length);
148
+ },
149
+ // Second
150
+ s(date, token) {
151
+ return addLeadingZeros(date.getSeconds(), token.length);
152
+ },
153
+ // Fraction of second
154
+ S(date, token) {
155
+ const numberOfDigits = token.length;
156
+ const milliseconds = date.getMilliseconds();
157
+ const fractionalSeconds = Math.trunc(
158
+ milliseconds * Math.pow(10, numberOfDigits - 3)
159
+ );
160
+ return addLeadingZeros(fractionalSeconds, token.length);
161
+ }
162
+ };
163
+ const dayPeriodEnum = {
164
+ midnight: "midnight",
165
+ noon: "noon",
166
+ morning: "morning",
167
+ afternoon: "afternoon",
168
+ evening: "evening",
169
+ night: "night"
170
+ };
171
+ const formatters = {
172
+ // Era
173
+ G: function(date, token, localize) {
174
+ const era = date.getFullYear() > 0 ? 1 : 0;
175
+ switch (token) {
176
+ // AD, BC
177
+ case "G":
178
+ case "GG":
179
+ case "GGG":
180
+ return localize.era(era, { width: "abbreviated" });
181
+ // A, B
182
+ case "GGGGG":
183
+ return localize.era(era, { width: "narrow" });
184
+ // Anno Domini, Before Christ
185
+ case "GGGG":
186
+ default:
187
+ return localize.era(era, { width: "wide" });
188
+ }
189
+ },
190
+ // Year
191
+ y: function(date, token, localize) {
192
+ if (token === "yo") {
193
+ const signedYear = date.getFullYear();
194
+ const year = signedYear > 0 ? signedYear : 1 - signedYear;
195
+ return localize.ordinalNumber(year, { unit: "year" });
196
+ }
197
+ return lightFormatters.y(date, token);
198
+ },
199
+ // Local week-numbering year
200
+ Y: function(date, token, localize, options) {
201
+ const signedWeekYear = getWeekYear(date, options);
202
+ const weekYear = signedWeekYear > 0 ? signedWeekYear : 1 - signedWeekYear;
203
+ if (token === "YY") {
204
+ const twoDigitYear = weekYear % 100;
205
+ return addLeadingZeros(twoDigitYear, 2);
206
+ }
207
+ if (token === "Yo") {
208
+ return localize.ordinalNumber(weekYear, { unit: "year" });
209
+ }
210
+ return addLeadingZeros(weekYear, token.length);
211
+ },
212
+ // ISO week-numbering year
213
+ R: function(date, token) {
214
+ const isoWeekYear = getISOWeekYear(date);
215
+ return addLeadingZeros(isoWeekYear, token.length);
216
+ },
217
+ // Extended year. This is a single number designating the year of this calendar system.
218
+ // The main difference between `y` and `u` localizers are B.C. years:
219
+ // | Year | `y` | `u` |
220
+ // |------|-----|-----|
221
+ // | AC 1 | 1 | 1 |
222
+ // | BC 1 | 1 | 0 |
223
+ // | BC 2 | 2 | -1 |
224
+ // Also `yy` always returns the last two digits of a year,
225
+ // while `uu` pads single digit years to 2 characters and returns other years unchanged.
226
+ u: function(date, token) {
227
+ const year = date.getFullYear();
228
+ return addLeadingZeros(year, token.length);
229
+ },
230
+ // Quarter
231
+ Q: function(date, token, localize) {
232
+ const quarter = Math.ceil((date.getMonth() + 1) / 3);
233
+ switch (token) {
234
+ // 1, 2, 3, 4
235
+ case "Q":
236
+ return String(quarter);
237
+ // 01, 02, 03, 04
238
+ case "QQ":
239
+ return addLeadingZeros(quarter, 2);
240
+ // 1st, 2nd, 3rd, 4th
241
+ case "Qo":
242
+ return localize.ordinalNumber(quarter, { unit: "quarter" });
243
+ // Q1, Q2, Q3, Q4
244
+ case "QQQ":
245
+ return localize.quarter(quarter, {
246
+ width: "abbreviated",
247
+ context: "formatting"
248
+ });
249
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
250
+ case "QQQQQ":
251
+ return localize.quarter(quarter, {
252
+ width: "narrow",
253
+ context: "formatting"
254
+ });
255
+ // 1st quarter, 2nd quarter, ...
256
+ case "QQQQ":
257
+ default:
258
+ return localize.quarter(quarter, {
259
+ width: "wide",
260
+ context: "formatting"
261
+ });
262
+ }
263
+ },
264
+ // Stand-alone quarter
265
+ q: function(date, token, localize) {
266
+ const quarter = Math.ceil((date.getMonth() + 1) / 3);
267
+ switch (token) {
268
+ // 1, 2, 3, 4
269
+ case "q":
270
+ return String(quarter);
271
+ // 01, 02, 03, 04
272
+ case "qq":
273
+ return addLeadingZeros(quarter, 2);
274
+ // 1st, 2nd, 3rd, 4th
275
+ case "qo":
276
+ return localize.ordinalNumber(quarter, { unit: "quarter" });
277
+ // Q1, Q2, Q3, Q4
278
+ case "qqq":
279
+ return localize.quarter(quarter, {
280
+ width: "abbreviated",
281
+ context: "standalone"
282
+ });
283
+ // 1, 2, 3, 4 (narrow quarter; could be not numerical)
284
+ case "qqqqq":
285
+ return localize.quarter(quarter, {
286
+ width: "narrow",
287
+ context: "standalone"
288
+ });
289
+ // 1st quarter, 2nd quarter, ...
290
+ case "qqqq":
291
+ default:
292
+ return localize.quarter(quarter, {
293
+ width: "wide",
294
+ context: "standalone"
295
+ });
296
+ }
297
+ },
298
+ // Month
299
+ M: function(date, token, localize) {
300
+ const month = date.getMonth();
301
+ switch (token) {
302
+ case "M":
303
+ case "MM":
304
+ return lightFormatters.M(date, token);
305
+ // 1st, 2nd, ..., 12th
306
+ case "Mo":
307
+ return localize.ordinalNumber(month + 1, { unit: "month" });
308
+ // Jan, Feb, ..., Dec
309
+ case "MMM":
310
+ return localize.month(month, {
311
+ width: "abbreviated",
312
+ context: "formatting"
313
+ });
314
+ // J, F, ..., D
315
+ case "MMMMM":
316
+ return localize.month(month, {
317
+ width: "narrow",
318
+ context: "formatting"
319
+ });
320
+ // January, February, ..., December
321
+ case "MMMM":
322
+ default:
323
+ return localize.month(month, { width: "wide", context: "formatting" });
324
+ }
325
+ },
326
+ // Stand-alone month
327
+ L: function(date, token, localize) {
328
+ const month = date.getMonth();
329
+ switch (token) {
330
+ // 1, 2, ..., 12
331
+ case "L":
332
+ return String(month + 1);
333
+ // 01, 02, ..., 12
334
+ case "LL":
335
+ return addLeadingZeros(month + 1, 2);
336
+ // 1st, 2nd, ..., 12th
337
+ case "Lo":
338
+ return localize.ordinalNumber(month + 1, { unit: "month" });
339
+ // Jan, Feb, ..., Dec
340
+ case "LLL":
341
+ return localize.month(month, {
342
+ width: "abbreviated",
343
+ context: "standalone"
344
+ });
345
+ // J, F, ..., D
346
+ case "LLLLL":
347
+ return localize.month(month, {
348
+ width: "narrow",
349
+ context: "standalone"
350
+ });
351
+ // January, February, ..., December
352
+ case "LLLL":
353
+ default:
354
+ return localize.month(month, { width: "wide", context: "standalone" });
355
+ }
356
+ },
357
+ // Local week of year
358
+ w: function(date, token, localize, options) {
359
+ const week = getWeek(date, options);
360
+ if (token === "wo") {
361
+ return localize.ordinalNumber(week, { unit: "week" });
362
+ }
363
+ return addLeadingZeros(week, token.length);
364
+ },
365
+ // ISO week of year
366
+ I: function(date, token, localize) {
367
+ const isoWeek = getISOWeek(date);
368
+ if (token === "Io") {
369
+ return localize.ordinalNumber(isoWeek, { unit: "week" });
370
+ }
371
+ return addLeadingZeros(isoWeek, token.length);
372
+ },
373
+ // Day of the month
374
+ d: function(date, token, localize) {
375
+ if (token === "do") {
376
+ return localize.ordinalNumber(date.getDate(), { unit: "date" });
377
+ }
378
+ return lightFormatters.d(date, token);
379
+ },
380
+ // Day of year
381
+ D: function(date, token, localize) {
382
+ const dayOfYear = getDayOfYear(date);
383
+ if (token === "Do") {
384
+ return localize.ordinalNumber(dayOfYear, { unit: "dayOfYear" });
385
+ }
386
+ return addLeadingZeros(dayOfYear, token.length);
387
+ },
388
+ // Day of week
389
+ E: function(date, token, localize) {
390
+ const dayOfWeek = date.getDay();
391
+ switch (token) {
392
+ // Tue
393
+ case "E":
394
+ case "EE":
395
+ case "EEE":
396
+ return localize.day(dayOfWeek, {
397
+ width: "abbreviated",
398
+ context: "formatting"
399
+ });
400
+ // T
401
+ case "EEEEE":
402
+ return localize.day(dayOfWeek, {
403
+ width: "narrow",
404
+ context: "formatting"
405
+ });
406
+ // Tu
407
+ case "EEEEEE":
408
+ return localize.day(dayOfWeek, {
409
+ width: "short",
410
+ context: "formatting"
411
+ });
412
+ // Tuesday
413
+ case "EEEE":
414
+ default:
415
+ return localize.day(dayOfWeek, {
416
+ width: "wide",
417
+ context: "formatting"
418
+ });
419
+ }
420
+ },
421
+ // Local day of week
422
+ e: function(date, token, localize, options) {
423
+ const dayOfWeek = date.getDay();
424
+ const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
425
+ switch (token) {
426
+ // Numerical value (Nth day of week with current locale or weekStartsOn)
427
+ case "e":
428
+ return String(localDayOfWeek);
429
+ // Padded numerical value
430
+ case "ee":
431
+ return addLeadingZeros(localDayOfWeek, 2);
432
+ // 1st, 2nd, ..., 7th
433
+ case "eo":
434
+ return localize.ordinalNumber(localDayOfWeek, { unit: "day" });
435
+ case "eee":
436
+ return localize.day(dayOfWeek, {
437
+ width: "abbreviated",
438
+ context: "formatting"
439
+ });
440
+ // T
441
+ case "eeeee":
442
+ return localize.day(dayOfWeek, {
443
+ width: "narrow",
444
+ context: "formatting"
445
+ });
446
+ // Tu
447
+ case "eeeeee":
448
+ return localize.day(dayOfWeek, {
449
+ width: "short",
450
+ context: "formatting"
451
+ });
452
+ // Tuesday
453
+ case "eeee":
454
+ default:
455
+ return localize.day(dayOfWeek, {
456
+ width: "wide",
457
+ context: "formatting"
458
+ });
459
+ }
460
+ },
461
+ // Stand-alone local day of week
462
+ c: function(date, token, localize, options) {
463
+ const dayOfWeek = date.getDay();
464
+ const localDayOfWeek = (dayOfWeek - options.weekStartsOn + 8) % 7 || 7;
465
+ switch (token) {
466
+ // Numerical value (same as in `e`)
467
+ case "c":
468
+ return String(localDayOfWeek);
469
+ // Padded numerical value
470
+ case "cc":
471
+ return addLeadingZeros(localDayOfWeek, token.length);
472
+ // 1st, 2nd, ..., 7th
473
+ case "co":
474
+ return localize.ordinalNumber(localDayOfWeek, { unit: "day" });
475
+ case "ccc":
476
+ return localize.day(dayOfWeek, {
477
+ width: "abbreviated",
478
+ context: "standalone"
479
+ });
480
+ // T
481
+ case "ccccc":
482
+ return localize.day(dayOfWeek, {
483
+ width: "narrow",
484
+ context: "standalone"
485
+ });
486
+ // Tu
487
+ case "cccccc":
488
+ return localize.day(dayOfWeek, {
489
+ width: "short",
490
+ context: "standalone"
491
+ });
492
+ // Tuesday
493
+ case "cccc":
494
+ default:
495
+ return localize.day(dayOfWeek, {
496
+ width: "wide",
497
+ context: "standalone"
498
+ });
499
+ }
500
+ },
501
+ // ISO day of week
502
+ i: function(date, token, localize) {
503
+ const dayOfWeek = date.getDay();
504
+ const isoDayOfWeek = dayOfWeek === 0 ? 7 : dayOfWeek;
505
+ switch (token) {
506
+ // 2
507
+ case "i":
508
+ return String(isoDayOfWeek);
509
+ // 02
510
+ case "ii":
511
+ return addLeadingZeros(isoDayOfWeek, token.length);
512
+ // 2nd
513
+ case "io":
514
+ return localize.ordinalNumber(isoDayOfWeek, { unit: "day" });
515
+ // Tue
516
+ case "iii":
517
+ return localize.day(dayOfWeek, {
518
+ width: "abbreviated",
519
+ context: "formatting"
520
+ });
521
+ // T
522
+ case "iiiii":
523
+ return localize.day(dayOfWeek, {
524
+ width: "narrow",
525
+ context: "formatting"
526
+ });
527
+ // Tu
528
+ case "iiiiii":
529
+ return localize.day(dayOfWeek, {
530
+ width: "short",
531
+ context: "formatting"
532
+ });
533
+ // Tuesday
534
+ case "iiii":
535
+ default:
536
+ return localize.day(dayOfWeek, {
537
+ width: "wide",
538
+ context: "formatting"
539
+ });
540
+ }
541
+ },
542
+ // AM or PM
543
+ a: function(date, token, localize) {
544
+ const hours = date.getHours();
545
+ const dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
546
+ switch (token) {
547
+ case "a":
548
+ case "aa":
549
+ return localize.dayPeriod(dayPeriodEnumValue, {
550
+ width: "abbreviated",
551
+ context: "formatting"
552
+ });
553
+ case "aaa":
554
+ return localize.dayPeriod(dayPeriodEnumValue, {
555
+ width: "abbreviated",
556
+ context: "formatting"
557
+ }).toLowerCase();
558
+ case "aaaaa":
559
+ return localize.dayPeriod(dayPeriodEnumValue, {
560
+ width: "narrow",
561
+ context: "formatting"
562
+ });
563
+ case "aaaa":
564
+ default:
565
+ return localize.dayPeriod(dayPeriodEnumValue, {
566
+ width: "wide",
567
+ context: "formatting"
568
+ });
569
+ }
570
+ },
571
+ // AM, PM, midnight, noon
572
+ b: function(date, token, localize) {
573
+ const hours = date.getHours();
574
+ let dayPeriodEnumValue;
575
+ if (hours === 12) {
576
+ dayPeriodEnumValue = dayPeriodEnum.noon;
577
+ } else if (hours === 0) {
578
+ dayPeriodEnumValue = dayPeriodEnum.midnight;
579
+ } else {
580
+ dayPeriodEnumValue = hours / 12 >= 1 ? "pm" : "am";
581
+ }
582
+ switch (token) {
583
+ case "b":
584
+ case "bb":
585
+ return localize.dayPeriod(dayPeriodEnumValue, {
586
+ width: "abbreviated",
587
+ context: "formatting"
588
+ });
589
+ case "bbb":
590
+ return localize.dayPeriod(dayPeriodEnumValue, {
591
+ width: "abbreviated",
592
+ context: "formatting"
593
+ }).toLowerCase();
594
+ case "bbbbb":
595
+ return localize.dayPeriod(dayPeriodEnumValue, {
596
+ width: "narrow",
597
+ context: "formatting"
598
+ });
599
+ case "bbbb":
600
+ default:
601
+ return localize.dayPeriod(dayPeriodEnumValue, {
602
+ width: "wide",
603
+ context: "formatting"
604
+ });
605
+ }
606
+ },
607
+ // in the morning, in the afternoon, in the evening, at night
608
+ B: function(date, token, localize) {
609
+ const hours = date.getHours();
610
+ let dayPeriodEnumValue;
611
+ if (hours >= 17) {
612
+ dayPeriodEnumValue = dayPeriodEnum.evening;
613
+ } else if (hours >= 12) {
614
+ dayPeriodEnumValue = dayPeriodEnum.afternoon;
615
+ } else if (hours >= 4) {
616
+ dayPeriodEnumValue = dayPeriodEnum.morning;
617
+ } else {
618
+ dayPeriodEnumValue = dayPeriodEnum.night;
619
+ }
620
+ switch (token) {
621
+ case "B":
622
+ case "BB":
623
+ case "BBB":
624
+ return localize.dayPeriod(dayPeriodEnumValue, {
625
+ width: "abbreviated",
626
+ context: "formatting"
627
+ });
628
+ case "BBBBB":
629
+ return localize.dayPeriod(dayPeriodEnumValue, {
630
+ width: "narrow",
631
+ context: "formatting"
632
+ });
633
+ case "BBBB":
634
+ default:
635
+ return localize.dayPeriod(dayPeriodEnumValue, {
636
+ width: "wide",
637
+ context: "formatting"
638
+ });
639
+ }
640
+ },
641
+ // Hour [1-12]
642
+ h: function(date, token, localize) {
643
+ if (token === "ho") {
644
+ let hours = date.getHours() % 12;
645
+ if (hours === 0) hours = 12;
646
+ return localize.ordinalNumber(hours, { unit: "hour" });
647
+ }
648
+ return lightFormatters.h(date, token);
649
+ },
650
+ // Hour [0-23]
651
+ H: function(date, token, localize) {
652
+ if (token === "Ho") {
653
+ return localize.ordinalNumber(date.getHours(), { unit: "hour" });
654
+ }
655
+ return lightFormatters.H(date, token);
656
+ },
657
+ // Hour [0-11]
658
+ K: function(date, token, localize) {
659
+ const hours = date.getHours() % 12;
660
+ if (token === "Ko") {
661
+ return localize.ordinalNumber(hours, { unit: "hour" });
662
+ }
663
+ return addLeadingZeros(hours, token.length);
664
+ },
665
+ // Hour [1-24]
666
+ k: function(date, token, localize) {
667
+ let hours = date.getHours();
668
+ if (hours === 0) hours = 24;
669
+ if (token === "ko") {
670
+ return localize.ordinalNumber(hours, { unit: "hour" });
671
+ }
672
+ return addLeadingZeros(hours, token.length);
673
+ },
674
+ // Minute
675
+ m: function(date, token, localize) {
676
+ if (token === "mo") {
677
+ return localize.ordinalNumber(date.getMinutes(), { unit: "minute" });
678
+ }
679
+ return lightFormatters.m(date, token);
680
+ },
681
+ // Second
682
+ s: function(date, token, localize) {
683
+ if (token === "so") {
684
+ return localize.ordinalNumber(date.getSeconds(), { unit: "second" });
685
+ }
686
+ return lightFormatters.s(date, token);
687
+ },
688
+ // Fraction of second
689
+ S: function(date, token) {
690
+ return lightFormatters.S(date, token);
691
+ },
692
+ // Timezone (ISO-8601. If offset is 0, output is always `'Z'`)
693
+ X: function(date, token, _localize) {
694
+ const timezoneOffset = date.getTimezoneOffset();
695
+ if (timezoneOffset === 0) {
696
+ return "Z";
697
+ }
698
+ switch (token) {
699
+ // Hours and optional minutes
700
+ case "X":
701
+ return formatTimezoneWithOptionalMinutes(timezoneOffset);
702
+ // Hours, minutes and optional seconds without `:` delimiter
703
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
704
+ // so this token always has the same output as `XX`
705
+ case "XXXX":
706
+ case "XX":
707
+ return formatTimezone(timezoneOffset);
708
+ // Hours, minutes and optional seconds with `:` delimiter
709
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
710
+ // so this token always has the same output as `XXX`
711
+ case "XXXXX":
712
+ case "XXX":
713
+ // Hours and minutes with `:` delimiter
714
+ default:
715
+ return formatTimezone(timezoneOffset, ":");
716
+ }
717
+ },
718
+ // Timezone (ISO-8601. If offset is 0, output is `'+00:00'` or equivalent)
719
+ x: function(date, token, _localize) {
720
+ const timezoneOffset = date.getTimezoneOffset();
721
+ switch (token) {
722
+ // Hours and optional minutes
723
+ case "x":
724
+ return formatTimezoneWithOptionalMinutes(timezoneOffset);
725
+ // Hours, minutes and optional seconds without `:` delimiter
726
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
727
+ // so this token always has the same output as `xx`
728
+ case "xxxx":
729
+ case "xx":
730
+ return formatTimezone(timezoneOffset);
731
+ // Hours, minutes and optional seconds with `:` delimiter
732
+ // Note: neither ISO-8601 nor JavaScript supports seconds in timezone offsets
733
+ // so this token always has the same output as `xxx`
734
+ case "xxxxx":
735
+ case "xxx":
736
+ // Hours and minutes with `:` delimiter
737
+ default:
738
+ return formatTimezone(timezoneOffset, ":");
739
+ }
740
+ },
741
+ // Timezone (GMT)
742
+ O: function(date, token, _localize) {
743
+ const timezoneOffset = date.getTimezoneOffset();
744
+ switch (token) {
745
+ // Short
746
+ case "O":
747
+ case "OO":
748
+ case "OOO":
749
+ return "GMT" + formatTimezoneShort(timezoneOffset, ":");
750
+ // Long
751
+ case "OOOO":
752
+ default:
753
+ return "GMT" + formatTimezone(timezoneOffset, ":");
754
+ }
755
+ },
756
+ // Timezone (specific non-location)
757
+ z: function(date, token, _localize) {
758
+ const timezoneOffset = date.getTimezoneOffset();
759
+ switch (token) {
760
+ // Short
761
+ case "z":
762
+ case "zz":
763
+ case "zzz":
764
+ return "GMT" + formatTimezoneShort(timezoneOffset, ":");
765
+ // Long
766
+ case "zzzz":
767
+ default:
768
+ return "GMT" + formatTimezone(timezoneOffset, ":");
769
+ }
770
+ },
771
+ // Seconds timestamp
772
+ t: function(date, token, _localize) {
773
+ const timestamp = Math.trunc(date.getTime() / 1e3);
774
+ return addLeadingZeros(timestamp, token.length);
775
+ },
776
+ // Milliseconds timestamp
777
+ T: function(date, token, _localize) {
778
+ const timestamp = date.getTime();
779
+ return addLeadingZeros(timestamp, token.length);
780
+ }
781
+ };
782
+ function formatTimezoneShort(offset, delimiter = "") {
783
+ const sign = offset > 0 ? "-" : "+";
784
+ const absOffset = Math.abs(offset);
785
+ const hours = Math.trunc(absOffset / 60);
786
+ const minutes = absOffset % 60;
787
+ if (minutes === 0) {
788
+ return sign + String(hours);
789
+ }
790
+ return sign + String(hours) + delimiter + addLeadingZeros(minutes, 2);
791
+ }
792
+ function formatTimezoneWithOptionalMinutes(offset, delimiter) {
793
+ if (offset % 60 === 0) {
794
+ const sign = offset > 0 ? "-" : "+";
795
+ return sign + addLeadingZeros(Math.abs(offset) / 60, 2);
796
+ }
797
+ return formatTimezone(offset, delimiter);
798
+ }
799
+ function formatTimezone(offset, delimiter = "") {
800
+ const sign = offset > 0 ? "-" : "+";
801
+ const absOffset = Math.abs(offset);
802
+ const hours = addLeadingZeros(Math.trunc(absOffset / 60), 2);
803
+ const minutes = addLeadingZeros(absOffset % 60, 2);
804
+ return sign + hours + delimiter + minutes;
805
+ }
806
+ const dateLongFormatter = (pattern, formatLong) => {
807
+ switch (pattern) {
808
+ case "P":
809
+ return formatLong.date({ width: "short" });
810
+ case "PP":
811
+ return formatLong.date({ width: "medium" });
812
+ case "PPP":
813
+ return formatLong.date({ width: "long" });
814
+ case "PPPP":
815
+ default:
816
+ return formatLong.date({ width: "full" });
817
+ }
818
+ };
819
+ const timeLongFormatter = (pattern, formatLong) => {
820
+ switch (pattern) {
821
+ case "p":
822
+ return formatLong.time({ width: "short" });
823
+ case "pp":
824
+ return formatLong.time({ width: "medium" });
825
+ case "ppp":
826
+ return formatLong.time({ width: "long" });
827
+ case "pppp":
828
+ default:
829
+ return formatLong.time({ width: "full" });
830
+ }
831
+ };
832
+ const dateTimeLongFormatter = (pattern, formatLong) => {
833
+ const matchResult = pattern.match(/(P+)(p+)?/) || [];
834
+ const datePattern = matchResult[1];
835
+ const timePattern = matchResult[2];
836
+ if (!timePattern) {
837
+ return dateLongFormatter(pattern, formatLong);
838
+ }
839
+ let dateTimeFormat;
840
+ switch (datePattern) {
841
+ case "P":
842
+ dateTimeFormat = formatLong.dateTime({ width: "short" });
843
+ break;
844
+ case "PP":
845
+ dateTimeFormat = formatLong.dateTime({ width: "medium" });
846
+ break;
847
+ case "PPP":
848
+ dateTimeFormat = formatLong.dateTime({ width: "long" });
849
+ break;
850
+ case "PPPP":
851
+ default:
852
+ dateTimeFormat = formatLong.dateTime({ width: "full" });
853
+ break;
854
+ }
855
+ return dateTimeFormat.replace("{{date}}", dateLongFormatter(datePattern, formatLong)).replace("{{time}}", timeLongFormatter(timePattern, formatLong));
856
+ };
857
+ const longFormatters = {
858
+ p: timeLongFormatter,
859
+ P: dateTimeLongFormatter
860
+ };
861
+ const dayOfYearTokenRE = /^D+$/;
862
+ const weekYearTokenRE = /^Y+$/;
863
+ const throwTokens = ["D", "DD", "YY", "YYYY"];
864
+ function isProtectedDayOfYearToken(token) {
865
+ return dayOfYearTokenRE.test(token);
866
+ }
867
+ function isProtectedWeekYearToken(token) {
868
+ return weekYearTokenRE.test(token);
869
+ }
870
+ function warnOrThrowProtectedError(token, format2, input) {
871
+ const _message = message(token, format2, input);
872
+ console.warn(_message);
873
+ if (throwTokens.includes(token)) throw new RangeError(_message);
874
+ }
875
+ function message(token, format2, input) {
876
+ const subject = token[0] === "Y" ? "years" : "days of the month";
877
+ return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format2}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
878
+ }
879
+ const formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
880
+ const longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
881
+ const escapedStringRegExp = /^'([^]*?)'?$/;
882
+ const doubleQuoteRegExp = /''/g;
883
+ const unescapedLatinCharacterRegExp = /[a-zA-Z]/;
884
+ function format(date, formatStr, options) {
885
+ const defaultOptions = getDefaultOptions();
886
+ const locale = defaultOptions.locale ?? enUS;
887
+ const firstWeekContainsDate = defaultOptions.firstWeekContainsDate ?? defaultOptions.locale?.options?.firstWeekContainsDate ?? 1;
888
+ const weekStartsOn = defaultOptions.weekStartsOn ?? defaultOptions.locale?.options?.weekStartsOn ?? 0;
889
+ const originalDate = toDate(date);
890
+ if (!isValid(originalDate)) {
891
+ throw new RangeError("Invalid time value");
892
+ }
893
+ let parts = formatStr.match(longFormattingTokensRegExp).map((substring) => {
894
+ const firstCharacter = substring[0];
895
+ if (firstCharacter === "p" || firstCharacter === "P") {
896
+ const longFormatter = longFormatters[firstCharacter];
897
+ return longFormatter(substring, locale.formatLong);
898
+ }
899
+ return substring;
900
+ }).join("").match(formattingTokensRegExp).map((substring) => {
901
+ if (substring === "''") {
902
+ return { isToken: false, value: "'" };
903
+ }
904
+ const firstCharacter = substring[0];
905
+ if (firstCharacter === "'") {
906
+ return { isToken: false, value: cleanEscapedString(substring) };
907
+ }
908
+ if (formatters[firstCharacter]) {
909
+ return { isToken: true, value: substring };
910
+ }
911
+ if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
912
+ throw new RangeError(
913
+ "Format string contains an unescaped latin alphabet character `" + firstCharacter + "`"
914
+ );
915
+ }
916
+ return { isToken: false, value: substring };
917
+ });
918
+ if (locale.localize.preprocessor) {
919
+ parts = locale.localize.preprocessor(originalDate, parts);
920
+ }
921
+ const formatterOptions = {
922
+ firstWeekContainsDate,
923
+ weekStartsOn,
924
+ locale
925
+ };
926
+ return parts.map((part) => {
927
+ if (!part.isToken) return part.value;
928
+ const token = part.value;
929
+ if (isProtectedWeekYearToken(token) || isProtectedDayOfYearToken(token)) {
930
+ warnOrThrowProtectedError(token, formatStr, String(date));
931
+ }
932
+ const formatter = formatters[token[0]];
933
+ return formatter(originalDate, token, locale.localize, formatterOptions);
934
+ }).join("");
935
+ }
936
+ function cleanEscapedString(input) {
937
+ const matched = input.match(escapedStringRegExp);
938
+ if (!matched) {
939
+ return input;
940
+ }
941
+ return matched[1].replace(doubleQuoteRegExp, "'");
942
+ }
943
+ async function runCommand(siteFolder, outputFormat) {
944
+ const logger = new Logger();
945
+ try {
946
+ logger.reportStart(PreviewCommandLoggerAction.VALIDATE, __("Validating…"));
947
+ await getSiteByFolder(siteFolder);
948
+ const token = await getAuthToken();
949
+ logger.reportSuccess(__("Validation successful"), true);
950
+ logger.reportStart(PreviewCommandLoggerAction.LOAD, __("Loading preview sites…"));
951
+ const snapshots = await getSnapshotsFromAppdata(token.id, siteFolder);
952
+ if (snapshots.length === 0) {
953
+ logger.reportSuccess(__("No preview sites found"));
954
+ return;
955
+ }
956
+ const expiredSnapshots = snapshots.filter(isSnapshotExpired);
957
+ const snapshotsMessage = sprintf(
958
+ _n("Found %d preview site", "Found %d preview sites", snapshots.length),
959
+ snapshots.length
960
+ );
961
+ if (expiredSnapshots.length > 0) {
962
+ const expiredSnapshotsMessage = sprintf(
963
+ /* translators: This string is appended to "Found %d preview sites" if there are expired preview sites */
964
+ _n("(%d expired)", "(%d expired)", expiredSnapshots.length),
965
+ expiredSnapshots.length
966
+ );
967
+ logger.reportSuccess(`${snapshotsMessage} ${expiredSnapshotsMessage}`);
968
+ } else {
969
+ logger.reportSuccess(snapshotsMessage);
970
+ }
971
+ if (outputFormat === "table") {
972
+ const colWidths = getColumnWidths([0.4, 0.25, 0.175, 0.175]);
973
+ const table = new CliTable3({
974
+ head: [__("URL"), __("Site Name"), __("Updated"), __("Expires in")],
975
+ wordWrap: true,
976
+ wrapOnWordBoundary: false,
977
+ colWidths,
978
+ style: {
979
+ head: [],
980
+ border: []
981
+ }
982
+ });
983
+ for (const snapshot of snapshots) {
984
+ const durationUntilExpiry = formatDurationUntilExpiry(snapshot.date);
985
+ const url = `https://${snapshot.url}`;
986
+ table.push([
987
+ { href: url, content: url },
988
+ snapshot.name,
989
+ format(snapshot.date, "yyyy-MM-dd HH:mm"),
990
+ durationUntilExpiry
991
+ ]);
992
+ }
993
+ console.log(table.toString());
994
+ } else {
995
+ const output = snapshots.map((snapshot) => ({
996
+ url: `https://${snapshot.url}`,
997
+ name: snapshot.name,
998
+ date: format(snapshot.date, "yyyy-MM-dd HH:mm"),
999
+ expiresIn: formatDurationUntilExpiry(snapshot.date)
1000
+ }));
1001
+ console.log(JSON.stringify(output, null, 2));
1002
+ }
1003
+ } catch (error) {
1004
+ if (error instanceof LoggerError) {
1005
+ logger.reportError(error);
1006
+ } else {
1007
+ const loggerError = new LoggerError(__("Failed to load preview sites"), error);
1008
+ logger.reportError(loggerError);
1009
+ }
1010
+ }
1011
+ }
1012
+ const registerCommand = (yargs) => {
1013
+ return yargs.command({
1014
+ command: "list",
1015
+ describe: __("List preview sites"),
1016
+ builder: (yargs2) => {
1017
+ return yargs2.option("format", {
1018
+ type: "string",
1019
+ choices: ["table", "json"],
1020
+ default: "table",
1021
+ description: __("Output format")
1022
+ });
1023
+ },
1024
+ handler: async (argv) => {
1025
+ await runCommand(argv.path, argv.format);
1026
+ }
1027
+ });
1028
+ };
1029
+ export {
1030
+ registerCommand,
1031
+ runCommand
1032
+ };