@swipt/cli 0.1.0-nightly.77 → 0.1.0-nightly.79

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 (68) hide show
  1. package/dist/availability.d.ts +5 -0
  2. package/dist/availability.js +349 -0
  3. package/dist/availability.js.map +1 -0
  4. package/dist/client.d.ts +25 -0
  5. package/dist/client.js +248 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/connection.d.ts +24 -0
  8. package/dist/connection.js +293 -0
  9. package/dist/connection.js.map +1 -0
  10. package/dist/coredevice.d.ts +22 -0
  11. package/dist/coredevice.js +329 -0
  12. package/dist/coredevice.js.map +1 -0
  13. package/dist/device.d.ts +130 -0
  14. package/dist/device.js +539 -0
  15. package/dist/device.js.map +1 -0
  16. package/dist/i18n.d.ts +2 -0
  17. package/dist/i18n.js +57 -0
  18. package/dist/i18n.js.map +1 -0
  19. package/dist/ignore.d.ts +8 -0
  20. package/dist/ignore.js +112 -0
  21. package/dist/ignore.js.map +1 -0
  22. package/dist/metro.d.ts +10 -0
  23. package/dist/metro.js +349 -0
  24. package/dist/metro.js.map +1 -0
  25. package/dist/output.d.ts +20 -0
  26. package/dist/output.js +116 -0
  27. package/dist/output.js.map +1 -0
  28. package/dist/project.d.ts +18 -0
  29. package/dist/project.js +696 -0
  30. package/dist/project.js.map +1 -0
  31. package/dist/proto/common_pb.js +34 -0
  32. package/dist/proto/common_pb.js.map +1 -0
  33. package/dist/proto/logs_pb.js +15 -0
  34. package/dist/proto/logs_pb.js.map +1 -0
  35. package/dist/proto/repl_pb.js +15 -0
  36. package/dist/proto/repl_pb.js.map +1 -0
  37. package/dist/proto/swiplets_pb.js +28 -0
  38. package/dist/proto/swiplets_pb.js.map +1 -0
  39. package/dist/proto/system_pb.js +15 -0
  40. package/dist/proto/system_pb.js.map +1 -0
  41. package/dist/sideload.d.ts +17 -0
  42. package/dist/sideload.js +1098 -0
  43. package/dist/sideload.js.map +1 -0
  44. package/dist/swipt.d.ts +1 -0
  45. package/dist/swipt.js +631 -0
  46. package/dist/swipt.js.map +1 -0
  47. package/dist/version.d.ts +2 -0
  48. package/dist/version.js +15 -0
  49. package/dist/version.js.map +1 -0
  50. package/package.json +21 -7
  51. package/availability.mjs +0 -642
  52. package/client.mjs +0 -375
  53. package/connection.mjs +0 -450
  54. package/coredevice.mjs +0 -478
  55. package/device.mjs +0 -837
  56. package/i18n.mjs +0 -71
  57. package/ignore.mjs +0 -149
  58. package/metro.mjs +0 -432
  59. package/output.mjs +0 -177
  60. package/project.mjs +0 -1013
  61. package/proto/common_pb.js +0 -98
  62. package/proto/logs_pb.js +0 -34
  63. package/proto/repl_pb.js +0 -55
  64. package/proto/swiplets_pb.js +0 -179
  65. package/proto/system_pb.js +0 -27
  66. package/sideload.mjs +0 -1696
  67. package/swipt.mjs +0 -726
  68. package/version.mjs +0 -16
package/output.mjs DELETED
@@ -1,177 +0,0 @@
1
- import { styleText } from "node:util";
2
-
3
- import { timestampDate } from "@bufbuild/protobuf/wkt";
4
- import select from "@inquirer/select";
5
- import stringWidth from "string-width";
6
-
7
- import { tr } from "./i18n.mjs";
8
- import { LogLevel, LogLevelSchema } from "./proto/common_pb.js";
9
- import { ServiceStatus } from "./proto/swiplets_pb.js";
10
-
11
- export class FalseResult extends Error {}
12
-
13
- export const selectTheme = {
14
- style: {
15
- keysHelpTip: () =>
16
- [
17
- [`↑↓`, tr("navigate")],
18
- [`⏎`, tr("select")],
19
- ]
20
- .map(
21
- ([key, action]) =>
22
- `${styleText("bold", key)} ${styleText("dim", action)}`,
23
- )
24
- .join(styleText("dim", " • ")),
25
- },
26
- };
27
-
28
- export const interactive = (context) =>
29
- context.options.device === undefined &&
30
- context.options.team === undefined &&
31
- process.stdin.isTTY &&
32
- process.stderr.isTTY;
33
-
34
- export function choose(context, message, choices, failure) {
35
- if (!interactive(context)) {
36
- throw failure;
37
- }
38
- return select(
39
- { message, choices, theme: selectTheme },
40
- { output: process.stderr, signal: context.signal },
41
- );
42
- }
43
-
44
- const spinner = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏";
45
-
46
- export async function step(label, run, { transient = false } = {}) {
47
- const stream = process.stderr;
48
- if (!stream.isTTY) {
49
- console.error(label);
50
- return run(() => {});
51
- }
52
- const style = (format, text) => styleText(format, text, { stream });
53
- const started = Date.now();
54
- const elapsed = () => {
55
- const seconds = Math.floor((Date.now() - started) / 1000);
56
- return seconds > 0 ? style("dim", ` ${seconds}s`) : "";
57
- };
58
- const draw = (line) => stream.write(`\r\x1b[?7l\x1b[2K${line}\x1b[?7h`);
59
- let detail = "";
60
- let frame = 0;
61
- const render = () => {
62
- frame = (frame + 1) % spinner.length;
63
- draw(
64
- `${style("cyan", spinner[frame])} ${label}${detail && style("dim", ` ${detail}`)}${elapsed()}`,
65
- );
66
- };
67
- stream.write("\x1b[?25l");
68
- render();
69
- const timer = setInterval(render, 80);
70
- try {
71
- const result = await run((text) => {
72
- detail = text;
73
- });
74
- clearInterval(timer);
75
- draw(transient ? "" : `${style("green", "✔")} ${label}${elapsed()}\n`);
76
- return result;
77
- } catch (error) {
78
- clearInterval(timer);
79
- draw(`${style("red", "✖")} ${label}${elapsed()}\n`);
80
- throw error;
81
- } finally {
82
- stream.write("\x1b[?25h");
83
- }
84
- }
85
-
86
- const levelName = (level) =>
87
- level === LogLevel.UNSPECIFIED
88
- ? "info"
89
- : LogLevelSchema.value[level].name.slice("LOG_LEVEL_".length).toLowerCase();
90
-
91
- const pad = (value, width) => String(value).padStart(width, "0");
92
-
93
- export function clockTime(timestamp) {
94
- const at = timestampDate(timestamp);
95
- return `${pad(at.getHours(), 2)}:${pad(at.getMinutes(), 2)}:${pad(at.getSeconds(), 2)}.${pad(at.getMilliseconds(), 3)}`;
96
- }
97
-
98
- export function dateTime(timestamp) {
99
- const at = timestampDate(timestamp);
100
- return `${at.getFullYear()}-${pad(at.getMonth() + 1, 2)}-${pad(at.getDate(), 2)} ${pad(at.getHours(), 2)}:${pad(at.getMinutes(), 2)}:${pad(at.getSeconds(), 2)}`;
101
- }
102
-
103
- export function columns(rows) {
104
- const widths = [];
105
- for (const row of rows) {
106
- row.forEach((cell, index) => {
107
- widths[index] = Math.max(widths[index] ?? 0, stringWidth(cell));
108
- });
109
- }
110
- return rows
111
- .map((row) =>
112
- row
113
- .map((cell, index) =>
114
- index === row.length - 1
115
- ? cell
116
- : cell + " ".repeat(widths[index] + 2 - stringWidth(cell)),
117
- )
118
- .join("")
119
- .trimEnd(),
120
- )
121
- .join("\n");
122
- }
123
-
124
- const frameText = (frame) => {
125
- const position = `${frame.file}:${frame.line}:${frame.column}`;
126
- return frame.function === "" ? position : `${frame.function} (${position})`;
127
- };
128
-
129
- export const failureText = (failure) =>
130
- [
131
- `${failure.name}: ${failure.message}`,
132
- ...failure.stack.map((frame) => ` at ${frameText(frame)}`),
133
- ].join("\n");
134
-
135
- export function printScriptError(failure) {
136
- console.error(tr("error: {message}", { message: failureText(failure) }));
137
- return new FalseResult();
138
- }
139
-
140
- export function printLog(entry, toStdout) {
141
- const message =
142
- entry.tag === "" ? entry.message : `${entry.tag}: ${entry.message}`;
143
- (toStdout ? console.log : console.error)(
144
- clockTime(entry.time),
145
- levelName(entry.level).toUpperCase(),
146
- message,
147
- );
148
- }
149
-
150
- const serviceStatuses = {
151
- [ServiceStatus.UNSPECIFIED]: tr("stopped"),
152
- [ServiceStatus.STOPPED]: tr("stopped"),
153
- [ServiceStatus.STARTING]: tr("starting"),
154
- [ServiceStatus.RUNNING]: tr("running"),
155
- [ServiceStatus.FAILED]: tr("failed"),
156
- };
157
-
158
- export const serviceEnabledText = (enabled) =>
159
- enabled ? tr("enabled") : tr("disabled");
160
-
161
- export const serviceStatusText = (status) => serviceStatuses[status];
162
-
163
- export function serviceText(id, state) {
164
- const enabled = serviceEnabledText(state?.enabled);
165
- const status = serviceStatuses[state?.status ?? ServiceStatus.UNSPECIFIED];
166
- let text = state?.since
167
- ? tr("{enabled}, {status} since {time}", {
168
- enabled,
169
- status,
170
- time: clockTime(state.since),
171
- })
172
- : tr("{enabled}, {status}", { enabled, status });
173
- if (state?.error) {
174
- text += `: ${failureText(state.error)}`;
175
- }
176
- return text;
177
- }