@swipt/cli 0.1.0-nightly.83 → 0.1.0-nightly.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/swipt.js +9 -0
- package/dist/bin/swipt.js.map +1 -0
- package/dist/cli/cli.js +184 -0
- package/dist/cli/cli.js.map +1 -0
- package/dist/cli/command.js +5 -0
- package/dist/cli/command.js.map +1 -0
- package/dist/cli/commands/data/clear.js +27 -0
- package/dist/cli/commands/data/clear.js.map +1 -0
- package/dist/cli/commands/data/data.js +22 -0
- package/dist/cli/commands/data/data.js.map +1 -0
- package/dist/cli/commands/data/index.js +1 -0
- package/dist/cli/commands/data/list.js +37 -0
- package/dist/cli/commands/data/list.js.map +1 -0
- package/dist/cli/commands/data/operand.js +5 -0
- package/dist/cli/commands/data/operand.js.map +1 -0
- package/dist/cli/commands/data/read.js +122 -0
- package/dist/cli/commands/data/read.js.map +1 -0
- package/dist/cli/commands/data/remove.js +30 -0
- package/dist/cli/commands/data/remove.js.map +1 -0
- package/dist/cli/commands/data/write.js +37 -0
- package/dist/cli/commands/data/write.js.map +1 -0
- package/dist/cli/commands/device/add.js +14 -0
- package/dist/cli/commands/device/add.js.map +1 -0
- package/dist/cli/commands/device/device.js +22 -0
- package/dist/cli/commands/device/device.js.map +1 -0
- package/dist/cli/commands/device/index.js +1 -0
- package/dist/cli/commands/device/list.js +13 -0
- package/dist/cli/commands/device/list.js.map +1 -0
- package/dist/cli/commands/device/logs.js +104 -0
- package/dist/cli/commands/device/logs.js.map +1 -0
- package/dist/cli/commands/device/remove.js +14 -0
- package/dist/cli/commands/device/remove.js.map +1 -0
- package/dist/cli/commands/device/stop.js +19 -0
- package/dist/cli/commands/device/stop.js.map +1 -0
- package/dist/cli/commands/flags.js +57 -0
- package/dist/cli/commands/flags.js.map +1 -0
- package/dist/cli/commands/index.js +30 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/project/build.js +18 -0
- package/dist/cli/commands/project/build.js.map +1 -0
- package/dist/cli/commands/project/create.js +109 -0
- package/dist/cli/commands/project/create.js.map +1 -0
- package/dist/cli/commands/project/deploy.js +23 -0
- package/dist/cli/commands/project/deploy.js.map +1 -0
- package/dist/cli/commands/project/develop.js +146 -0
- package/dist/cli/commands/project/develop.js.map +1 -0
- package/dist/cli/commands/project/index.js +1 -0
- package/dist/cli/commands/project/project.js +22 -0
- package/dist/cli/commands/project/project.js.map +1 -0
- package/dist/cli/commands/project/source.js +126 -0
- package/dist/cli/commands/project/source.js.map +1 -0
- package/dist/cli/commands/repl/api.js +16 -0
- package/dist/cli/commands/repl/api.js.map +1 -0
- package/dist/cli/commands/repl/index.js +1 -0
- package/dist/cli/commands/repl/repl.js +29 -0
- package/dist/cli/commands/repl/repl.js.map +1 -0
- package/dist/cli/commands/repl/reset.js +14 -0
- package/dist/cli/commands/repl/reset.js.map +1 -0
- package/dist/cli/commands/repl/run.js +108 -0
- package/dist/cli/commands/repl/run.js.map +1 -0
- package/dist/cli/commands/sideload/index.js +1 -0
- package/dist/cli/commands/sideload/install.js +19 -0
- package/dist/cli/commands/sideload/install.js.map +1 -0
- package/dist/cli/commands/sideload/setup.js +18 -0
- package/dist/cli/commands/sideload/setup.js.map +1 -0
- package/dist/cli/commands/sideload/sideload.js +22 -0
- package/dist/cli/commands/sideload/sideload.js.map +1 -0
- package/dist/cli/commands/sideload/uninstall.js +13 -0
- package/dist/cli/commands/sideload/uninstall.js.map +1 -0
- package/dist/cli/commands/sideload/update.js +19 -0
- package/dist/cli/commands/sideload/update.js.map +1 -0
- package/dist/cli/commands/swiplet/call.js +57 -0
- package/dist/cli/commands/swiplet/call.js.map +1 -0
- package/dist/cli/commands/swiplet/index.js +1 -0
- package/dist/cli/commands/swiplet/install.js +21 -0
- package/dist/cli/commands/swiplet/install.js.map +1 -0
- package/dist/cli/commands/swiplet/list.js +42 -0
- package/dist/cli/commands/swiplet/list.js.map +1 -0
- package/dist/cli/commands/swiplet/remove.js +18 -0
- package/dist/cli/commands/swiplet/remove.js.map +1 -0
- package/dist/cli/commands/swiplet/service/disable.js +18 -0
- package/dist/cli/commands/swiplet/service/disable.js.map +1 -0
- package/dist/cli/commands/swiplet/service/enable.js +18 -0
- package/dist/cli/commands/swiplet/service/enable.js.map +1 -0
- package/dist/cli/commands/swiplet/service/index.js +1 -0
- package/dist/cli/commands/swiplet/service/service.js +18 -0
- package/dist/cli/commands/swiplet/service/service.js.map +1 -0
- package/dist/cli/commands/swiplet/service/services.js +21 -0
- package/dist/cli/commands/swiplet/service/services.js.map +1 -0
- package/dist/cli/commands/swiplet/service/watch.js +16 -0
- package/dist/cli/commands/swiplet/service/watch.js.map +1 -0
- package/dist/cli/commands/swiplet/show.js +38 -0
- package/dist/cli/commands/swiplet/show.js.map +1 -0
- package/dist/cli/commands/swiplet/swiplet.js +42 -0
- package/dist/cli/commands/swiplet/swiplet.js.map +1 -0
- package/dist/cli/commands/version/index.js +1 -0
- package/dist/cli/commands/version/version.js +17 -0
- package/dist/cli/commands/version/version.js.map +1 -0
- package/dist/cli/deploy.js +20 -0
- package/dist/cli/deploy.js.map +1 -0
- package/dist/cli/io.js +7 -0
- package/dist/cli/io.js.map +1 -0
- package/dist/cli/session.js +6 -0
- package/dist/cli/session.js.map +1 -0
- package/dist/metro.js +1 -1
- package/dist/project.d.ts +2 -3
- package/dist/project.js +2 -203
- package/dist/project.js.map +1 -1
- package/package.json +5 -5
- package/dist/device.d.ts +0 -130
- package/dist/device.js +0 -539
- package/dist/device.js.map +0 -1
- package/dist/swipt.js +0 -631
- package/dist/swipt.js.map +0 -1
- /package/dist/{swipt.d.ts → bin/swipt.d.ts} +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { main } from "../cli/cli.js";
|
|
3
|
+
// src/bin/swipt.ts
|
|
4
|
+
await main();
|
|
5
|
+
await Promise.all([process.stdout, process.stderr].map((stream) => new Promise((resolve) => stream.write("", resolve))));
|
|
6
|
+
process.exit();
|
|
7
|
+
export {};
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=swipt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swipt.js","names":[],"sources":["../../src/bin/swipt.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { main } from \"../cli/cli\";\n\nawait main();\nawait Promise.all(\n [process.stdout, process.stderr].map(\n (stream) => new Promise((resolve) => stream.write(\"\", resolve)),\n ),\n);\nprocess.exit();\n"],"mappings":";;;AAGA,MAAM,KAAK;AACX,MAAM,QAAQ,IACZ,CAAC,QAAQ,QAAQ,QAAQ,MAAM,CAAC,CAAC,KAC9B,WAAW,IAAI,SAAS,YAAY,OAAO,MAAM,IAAI,OAAO,CAAC,CAChE,CACF;AACA,QAAQ,KAAK"}
|
package/dist/cli/cli.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { Code, RpcError, UsageError } from "../client.js";
|
|
2
|
+
import { withToken } from "../connection.js";
|
|
3
|
+
import { tr } from "../i18n.js";
|
|
4
|
+
import { FalseResult } from "../output.js";
|
|
5
|
+
import { root } from "./commands/index.js";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
// src/cli/cli.ts
|
|
8
|
+
const globalOptions = { help: {
|
|
9
|
+
type: "boolean",
|
|
10
|
+
short: "h",
|
|
11
|
+
help: tr("help")
|
|
12
|
+
} };
|
|
13
|
+
const parseOptions = (options) => Object.fromEntries(Object.entries(options ?? {}).map(([name, option]) => [name, {
|
|
14
|
+
type: option.type,
|
|
15
|
+
...option.short ? { short: option.short } : {}
|
|
16
|
+
}]));
|
|
17
|
+
function allOptions(command, collected = {}) {
|
|
18
|
+
Object.assign(collected, parseOptions(command.options));
|
|
19
|
+
for (const child of command.commands ?? []) allOptions(child, collected);
|
|
20
|
+
return collected;
|
|
21
|
+
}
|
|
22
|
+
function usage(trail) {
|
|
23
|
+
const command = trail.at(-1);
|
|
24
|
+
const name = trail.map((it) => it.name).join(" ");
|
|
25
|
+
const lines = [command.short, ""];
|
|
26
|
+
if (command.commands) {
|
|
27
|
+
lines.push(tr("usage: {usage}", { usage: `${name} COMMAND` }), "", tr("commands:"));
|
|
28
|
+
lines.push(...columns(command.commands.map((child) => [` ${child.use ?? child.name}`, child.short])).split("\n"));
|
|
29
|
+
} else lines.push(tr("usage: {usage}", { usage: `${trail.slice(0, -1).map((it) => it.name).join(" ")} ${command.use ?? command.name}`.replace(/ +/g, " ") }));
|
|
30
|
+
if (command.description) lines.push("", ...command.description);
|
|
31
|
+
const options = {
|
|
32
|
+
...trail.reduce((found, it) => ({
|
|
33
|
+
...found,
|
|
34
|
+
...it.options
|
|
35
|
+
}), {}),
|
|
36
|
+
...globalOptions
|
|
37
|
+
};
|
|
38
|
+
lines.push("", tr("options:"));
|
|
39
|
+
lines.push(...columns(Object.entries(options).map(([option, it]) => [` ${it.short ? `-${it.short}, ` : ""}--${option}${it.value ? ` ${it.value}` : ""}`, it.help])).split("\n"));
|
|
40
|
+
return lines.join("\n");
|
|
41
|
+
}
|
|
42
|
+
function columns(rows) {
|
|
43
|
+
const width = Math.max(...rows.map((row) => row[0].length));
|
|
44
|
+
return rows.map((row) => `${row[0].padEnd(width + 2)}${row[1]}`).join("\n");
|
|
45
|
+
}
|
|
46
|
+
function resolve(argv) {
|
|
47
|
+
const loose = parseArgs({
|
|
48
|
+
args: argv,
|
|
49
|
+
options: {
|
|
50
|
+
...parseOptions(globalOptions),
|
|
51
|
+
...allOptions(root)
|
|
52
|
+
},
|
|
53
|
+
allowPositionals: true,
|
|
54
|
+
strict: false,
|
|
55
|
+
tokens: true
|
|
56
|
+
});
|
|
57
|
+
const positionals = loose.tokens.filter((token) => token.kind === "positional");
|
|
58
|
+
const trail = [root];
|
|
59
|
+
let consumed = 0;
|
|
60
|
+
let help = positionals[0]?.value === "help";
|
|
61
|
+
if (help) consumed++;
|
|
62
|
+
while (trail.at(-1).commands) {
|
|
63
|
+
const current = trail.at(-1);
|
|
64
|
+
const word = positionals[consumed]?.value;
|
|
65
|
+
if (word === void 0) {
|
|
66
|
+
if (help || loose.values.help || current !== root || argv.length === 0) return {
|
|
67
|
+
trail,
|
|
68
|
+
help: true
|
|
69
|
+
};
|
|
70
|
+
throw new UsageError(tr("a command is missing"));
|
|
71
|
+
}
|
|
72
|
+
const found = current.commands.find((it) => it.name === word);
|
|
73
|
+
if (!found) throw new UsageError(tr("unknown command {name} for {parent}", {
|
|
74
|
+
name: JSON.stringify(word),
|
|
75
|
+
parent: JSON.stringify(trail.map((it) => it.name).join(" "))
|
|
76
|
+
}));
|
|
77
|
+
trail.push(found);
|
|
78
|
+
consumed++;
|
|
79
|
+
}
|
|
80
|
+
const command = trail.at(-1);
|
|
81
|
+
const options = trail.reduce((found, it) => ({
|
|
82
|
+
...found,
|
|
83
|
+
...it.options
|
|
84
|
+
}), {});
|
|
85
|
+
const first = positionals[consumed];
|
|
86
|
+
const verbatim = first !== void 0 && command.passthrough?.(first.value) ? first.index + 1 : argv.length;
|
|
87
|
+
let parsed;
|
|
88
|
+
try {
|
|
89
|
+
parsed = parseArgs({
|
|
90
|
+
args: argv.slice(0, verbatim),
|
|
91
|
+
options: {
|
|
92
|
+
...parseOptions(globalOptions),
|
|
93
|
+
...parseOptions(options)
|
|
94
|
+
},
|
|
95
|
+
allowPositionals: true,
|
|
96
|
+
strict: true
|
|
97
|
+
});
|
|
98
|
+
} catch (error) {
|
|
99
|
+
const option = error.message.match(/^Unknown option '(-[^']*)'/)?.[1];
|
|
100
|
+
throw new UsageError(option === void 0 ? error.message : tr("{option} is not an option of {command}", {
|
|
101
|
+
option,
|
|
102
|
+
command: JSON.stringify(trail.map((it) => it.name).join(" "))
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
if (parsed.values.help) help = true;
|
|
106
|
+
const args = [...parsed.positionals.slice(consumed), ...argv.slice(verbatim)];
|
|
107
|
+
if (!help && (args.length < command.args[0] || args.length > command.args[1])) {
|
|
108
|
+
const [least, most] = command.args;
|
|
109
|
+
throw new UsageError(least === most ? tr("accepts {count} arg(s), received {received}", {
|
|
110
|
+
count: least,
|
|
111
|
+
received: args.length
|
|
112
|
+
}) : most === Infinity ? tr("accepts at least {count} arg(s), received {received}", {
|
|
113
|
+
count: least,
|
|
114
|
+
received: args.length
|
|
115
|
+
}) : tr("accepts between {least} and {count} arg(s), received {received}", {
|
|
116
|
+
least,
|
|
117
|
+
count: most,
|
|
118
|
+
received: args.length
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
trail,
|
|
123
|
+
help,
|
|
124
|
+
args,
|
|
125
|
+
values: parsed.values
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function printError(error, target, operation) {
|
|
129
|
+
let exit = 1;
|
|
130
|
+
let message = error.message;
|
|
131
|
+
if (error instanceof UsageError) exit = 2;
|
|
132
|
+
else if (error instanceof RpcError) switch (error.code) {
|
|
133
|
+
case Code.Unavailable:
|
|
134
|
+
exit = 5;
|
|
135
|
+
message = tr("Swipt at {url} is unreachable: {message}", {
|
|
136
|
+
url: target.url,
|
|
137
|
+
message
|
|
138
|
+
});
|
|
139
|
+
break;
|
|
140
|
+
case Code.Unauthenticated:
|
|
141
|
+
message = tr("{message}; connect with the URL from Swipt › Developer: swipt device add {url}", {
|
|
142
|
+
message,
|
|
143
|
+
url: withToken(target.url)
|
|
144
|
+
});
|
|
145
|
+
break;
|
|
146
|
+
case Code.Unimplemented: message = tr("Swipt at {url} does not have this command; update Swipt", { url: target.url });
|
|
147
|
+
}
|
|
148
|
+
console.error(tr("error: {message}", { message: operation === void 0 ? message : `${operation}: ${message}` }));
|
|
149
|
+
if (exit === 2) console.error(tr("run \"swipt help\" for usage"));
|
|
150
|
+
return exit;
|
|
151
|
+
}
|
|
152
|
+
async function main() {
|
|
153
|
+
const interrupt = new AbortController();
|
|
154
|
+
const interrupted = () => interrupt.abort();
|
|
155
|
+
process.once("SIGINT", interrupted);
|
|
156
|
+
process.once("SIGTERM", interrupted);
|
|
157
|
+
const target = { url: "" };
|
|
158
|
+
try {
|
|
159
|
+
const resolved = resolve(process.argv.slice(2));
|
|
160
|
+
if (resolved.help) {
|
|
161
|
+
console.log(usage(resolved.trail));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const command = resolved.trail.at(-1);
|
|
165
|
+
const values = command.parse ? command.parse(resolved.values) : resolved.values;
|
|
166
|
+
await command.run({
|
|
167
|
+
args: resolved.args,
|
|
168
|
+
options: values,
|
|
169
|
+
target,
|
|
170
|
+
signal: interrupt.signal,
|
|
171
|
+
printError: (error, operation) => printError(error, target, operation)
|
|
172
|
+
});
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if (error instanceof FalseResult) process.exitCode = 1;
|
|
175
|
+
else if (interrupt.signal.aborted || error.name === "ExitPromptError") process.exitCode = 130;
|
|
176
|
+
else process.exitCode = printError(error, target);
|
|
177
|
+
} finally {
|
|
178
|
+
process.off("SIGINT", interrupted);
|
|
179
|
+
process.off("SIGTERM", interrupted);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
export { main };
|
|
183
|
+
|
|
184
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","names":["connection.withToken"],"sources":["../../src/cli/cli.ts"],"sourcesContent":["import { parseArgs } from \"node:util\";\n\nimport { Code, RpcError, UsageError } from \"../client\";\nimport * as connection from \"../connection\";\nimport { tr } from \"../i18n\";\nimport { FalseResult } from \"../output\";\nimport type { Command, Options } from \"./command\";\nimport { root } from \"./commands\";\n\nconst globalOptions: Options = {\n help: { type: \"boolean\", short: \"h\", help: tr(\"help\") },\n};\n\nconst parseOptions = (options: Options) =>\n Object.fromEntries(\n Object.entries(options ?? {}).map(([name, option]) => [\n name,\n { type: option.type, ...(option.short ? { short: option.short } : {}) },\n ]),\n );\n\nfunction allOptions(command: Command, collected = {}) {\n Object.assign(collected, parseOptions(command.options));\n for (const child of command.commands ?? []) {\n allOptions(child, collected);\n }\n return collected;\n}\n\nfunction usage(trail: Command[]) {\n const command = trail.at(-1);\n const name = trail.map((it) => it.name).join(\" \");\n const lines = [command.short, \"\"];\n if (command.commands) {\n lines.push(\n tr(\"usage: {usage}\", { usage: `${name} COMMAND` }),\n \"\",\n tr(\"commands:\"),\n );\n lines.push(\n ...columns(\n command.commands.map((child) => [\n ` ${child.use ?? child.name}`,\n child.short,\n ]),\n ).split(\"\\n\"),\n );\n } else {\n lines.push(\n tr(\"usage: {usage}\", {\n usage: `${trail\n .slice(0, -1)\n .map((it) => it.name)\n .join(\" \")} ${command.use ?? command.name}`.replace(/ +/g, \" \"),\n }),\n );\n }\n if (command.description) {\n lines.push(\"\", ...command.description);\n }\n const options: Options = {\n ...trail.reduce((found, it) => ({ ...found, ...it.options }), {}),\n ...globalOptions,\n };\n lines.push(\"\", tr(\"options:\"));\n lines.push(\n ...columns(\n Object.entries(options).map(([option, it]) => [\n ` ${it.short ? `-${it.short}, ` : \"\"}--${option}${it.value ? ` ${it.value}` : \"\"}`,\n it.help,\n ]),\n ).split(\"\\n\"),\n );\n return lines.join(\"\\n\");\n}\n\nfunction columns(rows) {\n const width = Math.max(...rows.map((row) => row[0].length));\n return rows.map((row) => `${row[0].padEnd(width + 2)}${row[1]}`).join(\"\\n\");\n}\n\nfunction resolve(argv) {\n const loose = parseArgs({\n args: argv,\n options: { ...parseOptions(globalOptions), ...allOptions(root) },\n allowPositionals: true,\n strict: false,\n tokens: true,\n });\n const positionals = loose.tokens.filter(\n (token) => token.kind === \"positional\",\n );\n const trail = [root];\n let consumed = 0;\n let help = positionals[0]?.value === \"help\";\n if (help) {\n consumed++;\n }\n while (trail.at(-1).commands) {\n const current = trail.at(-1);\n const word = positionals[consumed]?.value;\n if (word === undefined) {\n if (help || loose.values.help || current !== root || argv.length === 0) {\n return { trail, help: true };\n }\n throw new UsageError(tr(\"a command is missing\"));\n }\n const found = current.commands.find((it) => it.name === word);\n if (!found) {\n throw new UsageError(\n tr(\"unknown command {name} for {parent}\", {\n name: JSON.stringify(word),\n parent: JSON.stringify(trail.map((it) => it.name).join(\" \")),\n }),\n );\n }\n trail.push(found);\n consumed++;\n }\n const command = trail.at(-1);\n const options: Options = trail.reduce(\n (found, it) => ({ ...found, ...it.options }),\n {},\n );\n const first = positionals[consumed];\n const verbatim =\n first !== undefined && command.passthrough?.(first.value)\n ? first.index + 1\n : argv.length;\n let parsed;\n try {\n parsed = parseArgs({\n args: argv.slice(0, verbatim),\n options: { ...parseOptions(globalOptions), ...parseOptions(options) },\n allowPositionals: true,\n strict: true,\n });\n } catch (error) {\n const option = error.message.match(/^Unknown option '(-[^']*)'/)?.[1];\n throw new UsageError(\n option === undefined\n ? error.message\n : tr(\"{option} is not an option of {command}\", {\n option,\n command: JSON.stringify(trail.map((it) => it.name).join(\" \")),\n }),\n );\n }\n if (parsed.values.help) {\n help = true;\n }\n const args = [...parsed.positionals.slice(consumed), ...argv.slice(verbatim)];\n if (\n !help &&\n (args.length < command.args[0] || args.length > command.args[1])\n ) {\n const [least, most] = command.args;\n throw new UsageError(\n least === most\n ? tr(\"accepts {count} arg(s), received {received}\", {\n count: least,\n received: args.length,\n })\n : most === Infinity\n ? tr(\"accepts at least {count} arg(s), received {received}\", {\n count: least,\n received: args.length,\n })\n : tr(\n \"accepts between {least} and {count} arg(s), received {received}\",\n { least, count: most, received: args.length },\n ),\n );\n }\n return { trail, help, args, values: parsed.values };\n}\n\nfunction printError(error, target, operation?) {\n let exit = 1;\n let message = error.message;\n if (error instanceof UsageError) {\n exit = 2;\n } else if (error instanceof RpcError) {\n switch (error.code) {\n case Code.Unavailable:\n exit = 5;\n message = tr(\"Swipt at {url} is unreachable: {message}\", {\n url: target.url,\n message,\n });\n break;\n case Code.Unauthenticated:\n message = tr(\n \"{message}; connect with the URL from Swipt › Developer: swipt device add {url}\",\n { message, url: connection.withToken(target.url) },\n );\n break;\n case Code.Unimplemented:\n message = tr(\n \"Swipt at {url} does not have this command; update Swipt\",\n { url: target.url },\n );\n break;\n }\n }\n console.error(\n tr(\"error: {message}\", {\n message: operation === undefined ? message : `${operation}: ${message}`,\n }),\n );\n if (exit === 2) {\n console.error(tr('run \"swipt help\" for usage'));\n }\n return exit;\n}\n\nexport async function main() {\n const interrupt = new AbortController();\n const interrupted = () => interrupt.abort();\n process.once(\"SIGINT\", interrupted);\n process.once(\"SIGTERM\", interrupted);\n const target = { url: \"\" };\n try {\n const resolved = resolve(process.argv.slice(2));\n if (resolved.help) {\n console.log(usage(resolved.trail));\n return;\n }\n const command = resolved.trail.at(-1);\n const values = command.parse\n ? command.parse(resolved.values)\n : resolved.values;\n await command.run({\n args: resolved.args,\n options: values,\n target,\n signal: interrupt.signal,\n printError: (error, operation) => printError(error, target, operation),\n });\n } catch (error) {\n if (error instanceof FalseResult) {\n process.exitCode = 1;\n } else if (interrupt.signal.aborted || error.name === \"ExitPromptError\") {\n process.exitCode = 130;\n } else {\n process.exitCode = printError(error, target);\n }\n } finally {\n process.off(\"SIGINT\", interrupted);\n process.off(\"SIGTERM\", interrupted);\n }\n}\n"],"mappings":";;;;;;;AASA,MAAM,gBAAyB,EAC7B,MAAM;CAAE,MAAM;CAAW,OAAO;CAAK,MAAM,GAAG,MAAM;AAAE,EACxD;AAEA,MAAM,gBAAgB,YACpB,OAAO,YACL,OAAO,QAAQ,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,YAAY,CACpD,MACA;CAAE,MAAM,OAAO;CAAM,GAAI,OAAO,QAAQ,EAAE,OAAO,OAAO,MAAM,IAAI,CAAC;AAAG,CACxE,CAAC,CACH;AAEF,SAAS,WAAW,SAAkB,YAAY,CAAC,GAAG;CACpD,OAAO,OAAO,WAAW,aAAa,QAAQ,OAAO,CAAC;CACtD,KAAK,MAAM,SAAS,QAAQ,YAAY,CAAC,GACvC,WAAW,OAAO,SAAS;CAE7B,OAAO;AACT;AAEA,SAAS,MAAM,OAAkB;CAC/B,MAAM,UAAU,MAAM,GAA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;CACpC;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","names":[],"sources":["../../src/cli/command.ts"],"sourcesContent":["export interface Option {\n type: \"string\" | \"boolean\";\n short?: string;\n value?: string;\n help: string;\n}\n\nexport type Options = Record<string, Option>;\n\nexport interface Command {\n name: string;\n use?: string;\n short: string;\n description?: string[];\n args?: [least: number, most: number];\n options?: Options;\n commands?: Command[];\n passthrough?: (word: string) => boolean;\n parse?: (values: Record<string, any>) => Record<string, any>;\n run?: (context: any) => unknown;\n}\n\nexport const defineCommand = (command: Command): Command => command;\n"],"mappings":";AAsBA,MAAa,iBAAiB,YAA8B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { tr } from "../../../i18n.js";
|
|
2
|
+
import { defineCommand } from "../../command.js";
|
|
3
|
+
import { session } from "../../session.js";
|
|
4
|
+
import { operandCount } from "./operand.js";
|
|
5
|
+
// src/cli/commands/data/clear.ts
|
|
6
|
+
const clearFiles = (target) => (context) => session(context, async (client) => {
|
|
7
|
+
const { id } = target(context.args);
|
|
8
|
+
const { files } = await client.swiplets.listDataFiles({ swipletId: id }, { signal: context.signal });
|
|
9
|
+
for (const file of files) await client.swiplets.removeDataFile({
|
|
10
|
+
swipletId: id,
|
|
11
|
+
path: file.path,
|
|
12
|
+
recursive: true
|
|
13
|
+
}, { signal: context.signal });
|
|
14
|
+
});
|
|
15
|
+
const clear = (operand, target) => {
|
|
16
|
+
const before = operandCount(operand);
|
|
17
|
+
return defineCommand({
|
|
18
|
+
name: "clear",
|
|
19
|
+
use: `clear ${operand}`.trimEnd(),
|
|
20
|
+
short: tr("Remove every data file, keeping the data directory"),
|
|
21
|
+
args: [before, before],
|
|
22
|
+
run: clearFiles(target)
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
export { clear };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=clear.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clear.js","names":[],"sources":["../../../../src/cli/commands/data/clear.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\nimport { session } from \"../../session\";\nimport { operandCount } from \"./operand\";\n\nconst clearFiles = (target) => (context) =>\n session(context, async (client) => {\n const { id } = target(context.args);\n const { files } = await client.swiplets.listDataFiles(\n { swipletId: id },\n { signal: context.signal },\n );\n for (const file of files) {\n await client.swiplets.removeDataFile(\n { swipletId: id, path: file.path, recursive: true },\n { signal: context.signal },\n );\n }\n });\n\nexport const clear = (operand, target) => {\n const before = operandCount(operand);\n return defineCommand({\n name: \"clear\",\n use: `clear ${operand}`.trimEnd(),\n short: tr(\"Remove every data file, keeping the data directory\"),\n args: [before, before],\n run: clearFiles(target),\n });\n};\n"],"mappings":";;;;;AAKA,MAAM,cAAc,YAAY,YAC9B,QAAQ,SAAS,OAAO,WAAW;CACjC,MAAM,EAAE,OAAO,OAAO,QAAQ,IAAI;CAClC,MAAM,EAAE,UAAU,MAAM,OAAO,SAAS,cACtC,EAAE,WAAW,GAAG,GAChB,EAAE,QAAQ,QAAQ,OAAO,CAC3B;CACA,KAAK,MAAM,QAAQ,OACjB,MAAM,OAAO,SAAS,eACpB;EAAE,WAAW;EAAI,MAAM,KAAK;EAAM,WAAW;CAAK,GAClD,EAAE,QAAQ,QAAQ,OAAO,CAC3B;AAEJ,CAAC;AAEH,MAAa,SAAS,SAAS,WAAW;CACxC,MAAM,SAAS,aAAa,OAAO;CACnC,OAAO,cAAc;EACnB,MAAM;EACN,KAAK,SAAS,UAAU,QAAQ;EAChC,OAAO,GAAG,oDAAoD;EAC9D,MAAM,CAAC,QAAQ,MAAM;EACrB,KAAK,WAAW,MAAM;CACxB,CAAC;AACH"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { tr } from "../../../i18n.js";
|
|
2
|
+
import { defineCommand } from "../../command.js";
|
|
3
|
+
import { clear } from "./clear.js";
|
|
4
|
+
import { list } from "./list.js";
|
|
5
|
+
import { read } from "./read.js";
|
|
6
|
+
import { remove } from "./remove.js";
|
|
7
|
+
import { write } from "./write.js";
|
|
8
|
+
// src/cli/commands/data/data.ts
|
|
9
|
+
const data = (operand, target) => defineCommand({
|
|
10
|
+
name: "data",
|
|
11
|
+
short: operand === "" ? tr("Manage the files in the data directory of the REPL") : tr("Manage the files in the data directory of a swiplet"),
|
|
12
|
+
commands: [
|
|
13
|
+
list(operand, target),
|
|
14
|
+
read(operand, target),
|
|
15
|
+
write(operand, target),
|
|
16
|
+
remove(operand, target),
|
|
17
|
+
clear(operand, target)
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
export { data };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.js","names":[],"sources":["../../../../src/cli/commands/data/data.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\nimport { clear } from \"./clear\";\nimport { list } from \"./list\";\nimport { read } from \"./read\";\nimport { remove } from \"./remove\";\nimport { write } from \"./write\";\n\n// operand is \"\" for the REPL and \"ID \" for a swiplet, which takes the swiplet\n// ID before the path.\nexport const data = (operand, target) =>\n defineCommand({\n name: \"data\",\n short:\n operand === \"\"\n ? tr(\"Manage the files in the data directory of the REPL\")\n : tr(\"Manage the files in the data directory of a swiplet\"),\n commands: [\n list(operand, target),\n read(operand, target),\n write(operand, target),\n remove(operand, target),\n clear(operand, target),\n ],\n });\n"],"mappings":";;;;;;;;AAUA,MAAa,QAAQ,SAAS,WAC5B,cAAc;CACZ,MAAM;CACN,OACE,YAAY,KACR,GAAG,oDAAoD,IACvD,GAAG,qDAAqD;CAC9D,UAAU;EACR,KAAK,SAAS,MAAM;EACpB,KAAK,SAAS,MAAM;EACpB,MAAM,SAAS,MAAM;EACrB,OAAO,SAAS,MAAM;EACtB,MAAM,SAAS,MAAM;CACvB;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { data } from "./data.js";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { tr } from "../../../i18n.js";
|
|
2
|
+
import { columns, dateTime } from "../../../output.js";
|
|
3
|
+
import { defineCommand } from "../../command.js";
|
|
4
|
+
import { session } from "../../session.js";
|
|
5
|
+
import { operandCount } from "./operand.js";
|
|
6
|
+
// src/cli/commands/data/list.ts
|
|
7
|
+
const listFiles = (target) => (context) => session(context, async (client) => {
|
|
8
|
+
const { id, args: [directory = ""] } = target(context.args);
|
|
9
|
+
const { files } = await client.swiplets.listDataFiles({
|
|
10
|
+
swipletId: id,
|
|
11
|
+
path: directory,
|
|
12
|
+
recursive: context.options.recursive
|
|
13
|
+
}, { signal: context.signal });
|
|
14
|
+
const rows = files.map((file) => [
|
|
15
|
+
file.directory ? "-" : String(file.size),
|
|
16
|
+
dateTime(file.modified),
|
|
17
|
+
file.directory ? `${file.path}/` : file.path
|
|
18
|
+
]);
|
|
19
|
+
if (rows.length > 0) console.log(columns(rows));
|
|
20
|
+
});
|
|
21
|
+
const list = (operand, target) => {
|
|
22
|
+
const before = operandCount(operand);
|
|
23
|
+
return defineCommand({
|
|
24
|
+
name: "list",
|
|
25
|
+
use: `list ${operand}[PATH]`,
|
|
26
|
+
short: tr("List data files"),
|
|
27
|
+
args: [before, before + 1],
|
|
28
|
+
options: { recursive: {
|
|
29
|
+
type: "boolean",
|
|
30
|
+
help: tr("include subdirectories")
|
|
31
|
+
} },
|
|
32
|
+
run: listFiles(target)
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export { list };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.js","names":[],"sources":["../../../../src/cli/commands/data/list.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport { columns, dateTime } from \"../../../output\";\nimport { defineCommand } from \"../../command\";\nimport { session } from \"../../session\";\nimport { operandCount } from \"./operand\";\n\nconst listFiles = (target) => (context) =>\n session(context, async (client) => {\n const {\n id,\n args: [directory = \"\"],\n } = target(context.args);\n const { files } = await client.swiplets.listDataFiles(\n {\n swipletId: id,\n path: directory,\n recursive: context.options.recursive,\n },\n { signal: context.signal },\n );\n const rows = files.map((file) => [\n file.directory ? \"-\" : String(file.size),\n dateTime(file.modified),\n file.directory ? `${file.path}/` : file.path,\n ]);\n if (rows.length > 0) {\n console.log(columns(rows));\n }\n });\n\nexport const list = (operand, target) => {\n const before = operandCount(operand);\n return defineCommand({\n name: \"list\",\n use: `list ${operand}[PATH]`,\n short: tr(\"List data files\"),\n args: [before, before + 1],\n options: {\n recursive: { type: \"boolean\", help: tr(\"include subdirectories\") },\n },\n run: listFiles(target),\n });\n};\n"],"mappings":";;;;;;AAMA,MAAM,aAAa,YAAY,YAC7B,QAAQ,SAAS,OAAO,WAAW;CACjC,MAAM,EACJ,IACA,MAAM,CAAC,YAAY,QACjB,OAAO,QAAQ,IAAI;CACvB,MAAM,EAAE,UAAU,MAAM,OAAO,SAAS,cACtC;EACE,WAAW;EACX,MAAM;EACN,WAAW,QAAQ,QAAQ;CAC7B,GACA,EAAE,QAAQ,QAAQ,OAAO,CAC3B;CACA,MAAM,OAAO,MAAM,KAAK,SAAS;EAC/B,KAAK,YAAY,MAAM,OAAO,KAAK,IAAI;EACvC,SAAS,KAAK,QAAQ;EACtB,KAAK,YAAY,GAAG,KAAK,KAAK,KAAK,KAAK;CAC1C,CAAC;CACD,IAAI,KAAK,SAAS,GAChB,QAAQ,IAAI,QAAQ,IAAI,CAAC;AAE7B,CAAC;AAEH,MAAa,QAAQ,SAAS,WAAW;CACvC,MAAM,SAAS,aAAa,OAAO;CACnC,OAAO,cAAc;EACnB,MAAM;EACN,KAAK,QAAQ,QAAQ;EACrB,OAAO,GAAG,iBAAiB;EAC3B,MAAM,CAAC,QAAQ,SAAS,CAAC;EACzB,SAAS,EACP,WAAW;GAAE,MAAM;GAAW,MAAM,GAAG,wBAAwB;EAAE,EACnE;EACA,KAAK,UAAU,MAAM;CACvB,CAAC;AACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operand.js","names":[],"sources":["../../../../src/cli/commands/data/operand.ts"],"sourcesContent":["export const operandCount = (operand) => (operand === \"\" ? 0 : 1);\n"],"mappings":";AAAA,MAAa,gBAAgB,YAAa,YAAY,KAAK,IAAI"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { UsageError } from "../../../client.js";
|
|
2
|
+
import { tr } from "../../../i18n.js";
|
|
3
|
+
import { defineCommand } from "../../command.js";
|
|
4
|
+
import { session } from "../../session.js";
|
|
5
|
+
import { operandCount } from "./operand.js";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
// src/cli/commands/data/read.ts
|
|
9
|
+
const isLocal = (name) => {
|
|
10
|
+
const normalized = path.posix.normalize(name);
|
|
11
|
+
return !path.posix.isAbsolute(normalized) && normalized !== ".." && !normalized.startsWith("../");
|
|
12
|
+
};
|
|
13
|
+
var FileSink = class {
|
|
14
|
+
files = /* @__PURE__ */ new Map();
|
|
15
|
+
saved = 0;
|
|
16
|
+
constructor(root) {
|
|
17
|
+
this.root = root;
|
|
18
|
+
}
|
|
19
|
+
target(name) {
|
|
20
|
+
if (!isLocal(name)) throw new Error(`the server sent the path ${name}, which leaves the output directory`);
|
|
21
|
+
return path.join(this.root, ...name.split("/"));
|
|
22
|
+
}
|
|
23
|
+
begin(name, directory) {
|
|
24
|
+
const target = this.target(name);
|
|
25
|
+
if (directory) {
|
|
26
|
+
fs.mkdirSync(target, { recursive: true });
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
30
|
+
const previous = this.files.get(name);
|
|
31
|
+
if (previous !== void 0) fs.closeSync(previous);
|
|
32
|
+
this.files.set(name, fs.openSync(target, "w"));
|
|
33
|
+
this.saved++;
|
|
34
|
+
}
|
|
35
|
+
write(name, offset, data) {
|
|
36
|
+
const file = this.files.get(name);
|
|
37
|
+
if (file === void 0) throw new Error(`the server sent data for ${name} before announcing it`);
|
|
38
|
+
fs.writeSync(file, data, 0, data.length, Number(offset));
|
|
39
|
+
}
|
|
40
|
+
close() {
|
|
41
|
+
for (const file of this.files.values()) fs.closeSync(file);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const printSaved = (target, count) => console.error(tr("saved {count} file(s) to {path}", {
|
|
45
|
+
count,
|
|
46
|
+
path: target
|
|
47
|
+
}));
|
|
48
|
+
const readFile = (target) => (context) => session(context, async (client) => {
|
|
49
|
+
const { id, wholeDirectory, subdirectory, args: [given] } = target(context.args);
|
|
50
|
+
const output = context.options.output ?? "";
|
|
51
|
+
const requested = path.posix.normalize(`/${given}`).replace(/^\/+|\/+$/g, "");
|
|
52
|
+
const printing = output === "" || output === "-";
|
|
53
|
+
const directory = () => new UsageError(requested === "" ? wholeDirectory(JSON.stringify(given)) : subdirectory(JSON.stringify(requested)));
|
|
54
|
+
const relativeTo = (name) => name.slice(requested.length).replace(/^\//, "");
|
|
55
|
+
let sink;
|
|
56
|
+
let single;
|
|
57
|
+
const contents = [];
|
|
58
|
+
try {
|
|
59
|
+
for await (const response of client.swiplets.readDataFile({
|
|
60
|
+
swipletId: id,
|
|
61
|
+
path: given
|
|
62
|
+
}, { signal: context.signal })) if (response.part.case === "file") {
|
|
63
|
+
const file = response.part.value;
|
|
64
|
+
if (file.path === requested && !file.directory) {
|
|
65
|
+
single = file;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (!sink) {
|
|
69
|
+
if (printing) throw directory();
|
|
70
|
+
sink = new FileSink(output);
|
|
71
|
+
}
|
|
72
|
+
sink.begin(relativeTo(file.path), file.directory);
|
|
73
|
+
} else if (response.part.case === "chunk") {
|
|
74
|
+
const chunk = response.part.value;
|
|
75
|
+
if (single && chunk.path === single.path) {
|
|
76
|
+
contents.push(chunk.data);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (!sink) throw new Error(`the server sent data for ${chunk.path} before announcing it`);
|
|
80
|
+
sink.write(relativeTo(chunk.path), chunk.offset, chunk.data);
|
|
81
|
+
}
|
|
82
|
+
} finally {
|
|
83
|
+
sink?.close();
|
|
84
|
+
}
|
|
85
|
+
if (sink) {
|
|
86
|
+
printSaved(sink.root, sink.saved);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!single) {
|
|
90
|
+
if (printing) throw directory();
|
|
91
|
+
fs.mkdirSync(output, { recursive: true });
|
|
92
|
+
printSaved(output, 0);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const data = Buffer.concat(contents);
|
|
96
|
+
if (printing) {
|
|
97
|
+
process.stdout.write(data);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
let destination = output;
|
|
101
|
+
if (fs.existsSync(destination) && fs.statSync(destination).isDirectory()) destination = path.join(destination, path.posix.basename(single.path));
|
|
102
|
+
fs.writeFileSync(destination, data);
|
|
103
|
+
printSaved(destination, 1);
|
|
104
|
+
});
|
|
105
|
+
const read = (operand, target) => {
|
|
106
|
+
const before = operandCount(operand);
|
|
107
|
+
return defineCommand({
|
|
108
|
+
name: "read",
|
|
109
|
+
use: `read ${operand}PATH`,
|
|
110
|
+
short: tr("Read a data file or directory"),
|
|
111
|
+
args: [before + 1, before + 1],
|
|
112
|
+
options: { output: {
|
|
113
|
+
type: "string",
|
|
114
|
+
value: "PATH",
|
|
115
|
+
help: tr("destination")
|
|
116
|
+
} },
|
|
117
|
+
run: readFile(target)
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
export { read };
|
|
121
|
+
|
|
122
|
+
//# sourceMappingURL=read.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.js","names":[],"sources":["../../../../src/cli/commands/data/read.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport { UsageError } from \"../../../client\";\nimport { tr } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\nimport { session } from \"../../session\";\nimport { operandCount } from \"./operand\";\n\nconst isLocal = (name) => {\n const normalized = path.posix.normalize(name);\n return (\n !path.posix.isAbsolute(normalized) &&\n normalized !== \"..\" &&\n !normalized.startsWith(\"../\")\n );\n};\n\nclass FileSink {\n declare root: string;\n files = new Map();\n saved = 0;\n\n constructor(root) {\n this.root = root;\n }\n\n target(name) {\n if (!isLocal(name)) {\n throw new Error(\n `the server sent the path ${name}, which leaves the output directory`,\n );\n }\n return path.join(this.root, ...name.split(\"/\"));\n }\n\n begin(name, directory) {\n const target = this.target(name);\n if (directory) {\n fs.mkdirSync(target, { recursive: true });\n return;\n }\n fs.mkdirSync(path.dirname(target), { recursive: true });\n const previous = this.files.get(name);\n if (previous !== undefined) {\n fs.closeSync(previous);\n }\n this.files.set(name, fs.openSync(target, \"w\"));\n this.saved++;\n }\n\n write(name, offset, data) {\n const file = this.files.get(name);\n if (file === undefined) {\n throw new Error(`the server sent data for ${name} before announcing it`);\n }\n fs.writeSync(file, data, 0, data.length, Number(offset));\n }\n\n close() {\n for (const file of this.files.values()) {\n fs.closeSync(file);\n }\n }\n}\n\nconst printSaved = (target, count) =>\n console.error(tr(\"saved {count} file(s) to {path}\", { count, path: target }));\n\nconst readFile = (target) => (context) =>\n session(context, async (client) => {\n const {\n id,\n wholeDirectory,\n subdirectory,\n args: [given],\n } = target(context.args);\n const output = context.options.output ?? \"\";\n const requested = path.posix\n .normalize(`/${given}`)\n .replace(/^\\/+|\\/+$/g, \"\");\n const printing = output === \"\" || output === \"-\";\n const directory = () =>\n new UsageError(\n requested === \"\"\n ? wholeDirectory(JSON.stringify(given))\n : subdirectory(JSON.stringify(requested)),\n );\n const relativeTo = (name) =>\n name.slice(requested.length).replace(/^\\//, \"\");\n let sink;\n let single;\n const contents = [];\n try {\n for await (const response of client.swiplets.readDataFile(\n { swipletId: id, path: given },\n { signal: context.signal },\n )) {\n if (response.part.case === \"file\") {\n const file = response.part.value;\n if (file.path === requested && !file.directory) {\n single = file;\n continue;\n }\n if (!sink) {\n if (printing) {\n throw directory();\n }\n sink = new FileSink(output);\n }\n sink.begin(relativeTo(file.path), file.directory);\n } else if (response.part.case === \"chunk\") {\n const chunk = response.part.value;\n if (single && chunk.path === single.path) {\n contents.push(chunk.data);\n continue;\n }\n if (!sink) {\n throw new Error(\n `the server sent data for ${chunk.path} before announcing it`,\n );\n }\n sink.write(relativeTo(chunk.path), chunk.offset, chunk.data);\n }\n }\n } finally {\n sink?.close();\n }\n if (sink) {\n printSaved(sink.root, sink.saved);\n return;\n }\n if (!single) {\n if (printing) {\n throw directory();\n }\n fs.mkdirSync(output, { recursive: true });\n printSaved(output, 0);\n return;\n }\n const data = Buffer.concat(contents);\n if (printing) {\n process.stdout.write(data);\n return;\n }\n let destination = output;\n if (fs.existsSync(destination) && fs.statSync(destination).isDirectory()) {\n destination = path.join(destination, path.posix.basename(single.path));\n }\n fs.writeFileSync(destination, data);\n printSaved(destination, 1);\n });\n\nexport const read = (operand, target) => {\n const before = operandCount(operand);\n return defineCommand({\n name: \"read\",\n use: `read ${operand}PATH`,\n short: tr(\"Read a data file or directory\"),\n args: [before + 1, before + 1],\n options: {\n output: { type: \"string\", value: \"PATH\", help: tr(\"destination\") },\n },\n run: readFile(target),\n });\n};\n"],"mappings":";;;;;;;;AASA,MAAM,WAAW,SAAS;CACxB,MAAM,aAAa,KAAK,MAAM,UAAU,IAAI;CAC5C,OACE,CAAC,KAAK,MAAM,WAAW,UAAU,KACjC,eAAe,QACf,CAAC,WAAW,WAAW,KAAK;AAEhC;AAEA,IAAM,WAAN,MAAe;CAEb,wBAAQ,IAAI,IAAI;CAChB,QAAQ;CAER,YAAY,MAAM;EAChB,KAAK,OAAO;CACd;CAEA,OAAO,MAAM;EACX,IAAI,CAAC,QAAQ,IAAI,GACf,MAAM,IAAI,MACR,4BAA4B,KAAK,oCACnC;EAEF,OAAO,KAAK,KAAK,KAAK,MAAM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GACrE,cAAc,KAAK,KAAK,aAAa,KAAK,MAAM,SAAS,OAAO,IAAI,CAAC;CAEvE,GAAG,cAAc,aAAa,IAAI;CAClC,WAAW,aAAa,CAAC;AAC3B,CAAC;AAEH,MAAa,QAAQ,SAAS,WAAW;CACvC,MAAM,SAAS,aAAa,OAAO;CACnC,OAAO,cAAc;EACnB,MAAM;EACN,KAAK,QAAQ,QAAQ;EACrB,OAAO,GAAG,+BAA+B;EACzC,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;EAC7B,SAAS,EACP,QAAQ;GAAE,MAAM;GAAU,OAAO;GAAQ,MAAM,GAAG,aAAa;EAAE,EACnE;EACA,KAAK,SAAS,MAAM;CACtB,CAAC;AACH"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { tr } from "../../../i18n.js";
|
|
2
|
+
import { defineCommand } from "../../command.js";
|
|
3
|
+
import { session } from "../../session.js";
|
|
4
|
+
import { operandCount } from "./operand.js";
|
|
5
|
+
// src/cli/commands/data/remove.ts
|
|
6
|
+
const removeFile = (target) => (context) => session(context, async (client) => {
|
|
7
|
+
const { id, args: [name] } = target(context.args);
|
|
8
|
+
await client.swiplets.removeDataFile({
|
|
9
|
+
swipletId: id,
|
|
10
|
+
path: name,
|
|
11
|
+
recursive: context.options.recursive
|
|
12
|
+
}, { signal: context.signal });
|
|
13
|
+
});
|
|
14
|
+
const remove = (operand, target) => {
|
|
15
|
+
const before = operandCount(operand);
|
|
16
|
+
return defineCommand({
|
|
17
|
+
name: "remove",
|
|
18
|
+
use: `remove ${operand}PATH`,
|
|
19
|
+
short: tr("Remove a data file"),
|
|
20
|
+
args: [before + 1, before + 1],
|
|
21
|
+
options: { recursive: {
|
|
22
|
+
type: "boolean",
|
|
23
|
+
help: tr("include directory contents")
|
|
24
|
+
} },
|
|
25
|
+
run: removeFile(target)
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
export { remove };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=remove.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove.js","names":[],"sources":["../../../../src/cli/commands/data/remove.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\nimport { session } from \"../../session\";\nimport { operandCount } from \"./operand\";\n\nconst removeFile = (target) => (context) =>\n session(context, async (client) => {\n const {\n id,\n args: [name],\n } = target(context.args);\n await client.swiplets.removeDataFile(\n { swipletId: id, path: name, recursive: context.options.recursive },\n { signal: context.signal },\n );\n });\n\nexport const remove = (operand, target) => {\n const before = operandCount(operand);\n return defineCommand({\n name: \"remove\",\n use: `remove ${operand}PATH`,\n short: tr(\"Remove a data file\"),\n args: [before + 1, before + 1],\n options: {\n recursive: {\n type: \"boolean\",\n help: tr(\"include directory contents\"),\n },\n },\n run: removeFile(target),\n });\n};\n"],"mappings":";;;;;AAKA,MAAM,cAAc,YAAY,YAC9B,QAAQ,SAAS,OAAO,WAAW;CACjC,MAAM,EACJ,IACA,MAAM,CAAC,UACL,OAAO,QAAQ,IAAI;CACvB,MAAM,OAAO,SAAS,eACpB;EAAE,WAAW;EAAI,MAAM;EAAM,WAAW,QAAQ,QAAQ;CAAU,GAClE,EAAE,QAAQ,QAAQ,OAAO,CAC3B;AACF,CAAC;AAEH,MAAa,UAAU,SAAS,WAAW;CACzC,MAAM,SAAS,aAAa,OAAO;CACnC,OAAO,cAAc;EACnB,MAAM;EACN,KAAK,UAAU,QAAQ;EACvB,OAAO,GAAG,oBAAoB;EAC9B,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;EAC7B,SAAS,EACP,WAAW;GACT,MAAM;GACN,MAAM,GAAG,4BAA4B;EACvC,EACF;EACA,KAAK,WAAW,MAAM;CACxB,CAAC;AACH"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { tr } from "../../../i18n.js";
|
|
2
|
+
import { defineCommand } from "../../command.js";
|
|
3
|
+
import { readStdin, uploadChunk } from "../../io.js";
|
|
4
|
+
import { session } from "../../session.js";
|
|
5
|
+
import { operandCount } from "./operand.js";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
// src/cli/commands/data/write.ts
|
|
8
|
+
const writeFile = (target) => (context) => session(context, async (client) => {
|
|
9
|
+
const { id, args: [name, file] } = target(context.args);
|
|
10
|
+
const data = file === void 0 || file === "-" ? readStdin() : fs.readFileSync(file);
|
|
11
|
+
await client.swiplets.writeDataFile((async function* () {
|
|
12
|
+
yield { part: {
|
|
13
|
+
case: "header",
|
|
14
|
+
value: {
|
|
15
|
+
swipletId: id,
|
|
16
|
+
path: name
|
|
17
|
+
}
|
|
18
|
+
} };
|
|
19
|
+
for (let offset = 0; offset < data.length; offset += uploadChunk) yield { part: {
|
|
20
|
+
case: "data",
|
|
21
|
+
value: data.subarray(offset, offset + uploadChunk)
|
|
22
|
+
} };
|
|
23
|
+
})(), { signal: context.signal });
|
|
24
|
+
});
|
|
25
|
+
const write = (operand, target) => {
|
|
26
|
+
const before = operandCount(operand);
|
|
27
|
+
return defineCommand({
|
|
28
|
+
name: "write",
|
|
29
|
+
use: `write ${operand}PATH [FILE | -]`,
|
|
30
|
+
short: tr("Write a data file"),
|
|
31
|
+
args: [before + 1, before + 2],
|
|
32
|
+
run: writeFile(target)
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
export { write };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=write.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.js","names":[],"sources":["../../../../src/cli/commands/data/write.ts"],"sourcesContent":["import fs from \"node:fs\";\n\nimport { tr } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\nimport { readStdin, uploadChunk } from \"../../io\";\nimport { session } from \"../../session\";\nimport { operandCount } from \"./operand\";\n\nconst writeFile = (target) => (context) =>\n session(context, async (client) => {\n const {\n id,\n args: [name, file],\n } = target(context.args);\n const data =\n file === undefined || file === \"-\" ? readStdin() : fs.readFileSync(file);\n await client.swiplets.writeDataFile(\n (async function* () {\n yield {\n part: { case: \"header\", value: { swipletId: id, path: name } },\n };\n for (let offset = 0; offset < data.length; offset += uploadChunk) {\n yield {\n part: {\n case: \"data\",\n value: data.subarray(offset, offset + uploadChunk),\n },\n };\n }\n })(),\n { signal: context.signal },\n );\n });\n\nexport const write = (operand, target) => {\n const before = operandCount(operand);\n return defineCommand({\n name: \"write\",\n use: `write ${operand}PATH [FILE | -]`,\n short: tr(\"Write a data file\"),\n args: [before + 1, before + 2],\n run: writeFile(target),\n });\n};\n"],"mappings":";;;;;;;AAQA,MAAM,aAAa,YAAY,YAC7B,QAAQ,SAAS,OAAO,WAAW;CACjC,MAAM,EACJ,IACA,MAAM,CAAC,MAAM,UACX,OAAO,QAAQ,IAAI;CACvB,MAAM,OACJ,SAAS,KAAA,KAAa,SAAS,MAAM,UAAU,IAAI,GAAG,aAAa,IAAI;CACzE,MAAM,OAAO,SAAS,eACnB,mBAAmB;EAClB,MAAM,EACJ,MAAM;GAAE,MAAM;GAAU,OAAO;IAAE,WAAW;IAAI,MAAM;GAAK;EAAE,EAC/D;EACA,KAAK,IAAI,SAAS,GAAG,SAAS,KAAK,QAAQ,UAAU,aACnD,MAAM,EACJ,MAAM;GACJ,MAAM;GACN,OAAO,KAAK,SAAS,QAAQ,SAAS,WAAW;EACnD,EACF;CAEJ,EAAA,CAAG,GACH,EAAE,QAAQ,QAAQ,OAAO,CAC3B;AACF,CAAC;AAEH,MAAa,SAAS,SAAS,WAAW;CACxC,MAAM,SAAS,aAAa,OAAO;CACnC,OAAO,cAAc;EACnB,MAAM;EACN,KAAK,SAAS,QAAQ;EACtB,OAAO,GAAG,mBAAmB;EAC7B,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;EAC7B,KAAK,UAAU,MAAM;CACvB,CAAC;AACH"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { add as add$1 } from "../../../connection.js";
|
|
2
|
+
import { tr } from "../../../i18n.js";
|
|
3
|
+
import { defineCommand } from "../../command.js";
|
|
4
|
+
// src/cli/commands/device/add.ts
|
|
5
|
+
const add = defineCommand({
|
|
6
|
+
name: "add",
|
|
7
|
+
use: "add URL",
|
|
8
|
+
short: tr("Add a device by its URL; needed when it is remote or requires a token"),
|
|
9
|
+
args: [1, 1],
|
|
10
|
+
run: add$1
|
|
11
|
+
});
|
|
12
|
+
export { add };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=add.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add.js","names":["connection.add"],"sources":["../../../../src/cli/commands/device/add.ts"],"sourcesContent":["import * as connection from \"../../../connection\";\nimport { tr } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\n\nexport const add = defineCommand({\n name: \"add\",\n use: \"add URL\",\n short: tr(\n \"Add a device by its URL; needed when it is remote or requires a token\",\n ),\n args: [1, 1],\n run: connection.add,\n});\n"],"mappings":";;;;AAIA,MAAa,MAAM,cAAc;CAC/B,MAAM;CACN,KAAK;CACL,OAAO,GACL,uEACF;CACA,MAAM,CAAC,GAAG,CAAC;CACX,KAAKA;AACP,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { tr } from "../../../i18n.js";
|
|
2
|
+
import { defineCommand } from "../../command.js";
|
|
3
|
+
import { add } from "./add.js";
|
|
4
|
+
import { list } from "./list.js";
|
|
5
|
+
import { logs } from "./logs.js";
|
|
6
|
+
import { remove } from "./remove.js";
|
|
7
|
+
import { stop } from "./stop.js";
|
|
8
|
+
// src/cli/commands/device/device.ts
|
|
9
|
+
const device = defineCommand({
|
|
10
|
+
name: "device",
|
|
11
|
+
short: tr("Manage the devices and read their logs"),
|
|
12
|
+
commands: [
|
|
13
|
+
list,
|
|
14
|
+
add,
|
|
15
|
+
remove,
|
|
16
|
+
stop,
|
|
17
|
+
logs
|
|
18
|
+
]
|
|
19
|
+
});
|
|
20
|
+
export { device };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=device.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device.js","names":[],"sources":["../../../../src/cli/commands/device/device.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\nimport { add } from \"./add\";\nimport { list } from \"./list\";\nimport { logs } from \"./logs\";\nimport { remove } from \"./remove\";\nimport { stop } from \"./stop\";\n\nexport const device = defineCommand({\n name: \"device\",\n short: tr(\"Manage the devices and read their logs\"),\n commands: [list, add, remove, stop, logs],\n});\n"],"mappings":";;;;;;;;AAQA,MAAa,SAAS,cAAc;CAClC,MAAM;CACN,OAAO,GAAG,wCAAwC;CAClD,UAAU;EAAC;EAAM;EAAK;EAAQ;EAAM;CAAI;AAC1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { device } from "./device.js";
|