@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.
Files changed (115) hide show
  1. package/dist/bin/swipt.js +9 -0
  2. package/dist/bin/swipt.js.map +1 -0
  3. package/dist/cli/cli.js +184 -0
  4. package/dist/cli/cli.js.map +1 -0
  5. package/dist/cli/command.js +5 -0
  6. package/dist/cli/command.js.map +1 -0
  7. package/dist/cli/commands/data/clear.js +27 -0
  8. package/dist/cli/commands/data/clear.js.map +1 -0
  9. package/dist/cli/commands/data/data.js +22 -0
  10. package/dist/cli/commands/data/data.js.map +1 -0
  11. package/dist/cli/commands/data/index.js +1 -0
  12. package/dist/cli/commands/data/list.js +37 -0
  13. package/dist/cli/commands/data/list.js.map +1 -0
  14. package/dist/cli/commands/data/operand.js +5 -0
  15. package/dist/cli/commands/data/operand.js.map +1 -0
  16. package/dist/cli/commands/data/read.js +122 -0
  17. package/dist/cli/commands/data/read.js.map +1 -0
  18. package/dist/cli/commands/data/remove.js +30 -0
  19. package/dist/cli/commands/data/remove.js.map +1 -0
  20. package/dist/cli/commands/data/write.js +37 -0
  21. package/dist/cli/commands/data/write.js.map +1 -0
  22. package/dist/cli/commands/device/add.js +14 -0
  23. package/dist/cli/commands/device/add.js.map +1 -0
  24. package/dist/cli/commands/device/device.js +22 -0
  25. package/dist/cli/commands/device/device.js.map +1 -0
  26. package/dist/cli/commands/device/index.js +1 -0
  27. package/dist/cli/commands/device/list.js +13 -0
  28. package/dist/cli/commands/device/list.js.map +1 -0
  29. package/dist/cli/commands/device/logs.js +104 -0
  30. package/dist/cli/commands/device/logs.js.map +1 -0
  31. package/dist/cli/commands/device/remove.js +14 -0
  32. package/dist/cli/commands/device/remove.js.map +1 -0
  33. package/dist/cli/commands/device/stop.js +19 -0
  34. package/dist/cli/commands/device/stop.js.map +1 -0
  35. package/dist/cli/commands/flags.js +57 -0
  36. package/dist/cli/commands/flags.js.map +1 -0
  37. package/dist/cli/commands/index.js +30 -0
  38. package/dist/cli/commands/index.js.map +1 -0
  39. package/dist/cli/commands/project/build.js +18 -0
  40. package/dist/cli/commands/project/build.js.map +1 -0
  41. package/dist/cli/commands/project/create.js +109 -0
  42. package/dist/cli/commands/project/create.js.map +1 -0
  43. package/dist/cli/commands/project/deploy.js +23 -0
  44. package/dist/cli/commands/project/deploy.js.map +1 -0
  45. package/dist/cli/commands/project/develop.js +146 -0
  46. package/dist/cli/commands/project/develop.js.map +1 -0
  47. package/dist/cli/commands/project/index.js +1 -0
  48. package/dist/cli/commands/project/project.js +22 -0
  49. package/dist/cli/commands/project/project.js.map +1 -0
  50. package/dist/cli/commands/project/source.js +126 -0
  51. package/dist/cli/commands/project/source.js.map +1 -0
  52. package/dist/cli/commands/repl/api.js +16 -0
  53. package/dist/cli/commands/repl/api.js.map +1 -0
  54. package/dist/cli/commands/repl/index.js +1 -0
  55. package/dist/cli/commands/repl/repl.js +29 -0
  56. package/dist/cli/commands/repl/repl.js.map +1 -0
  57. package/dist/cli/commands/repl/reset.js +14 -0
  58. package/dist/cli/commands/repl/reset.js.map +1 -0
  59. package/dist/cli/commands/repl/run.js +108 -0
  60. package/dist/cli/commands/repl/run.js.map +1 -0
  61. package/dist/cli/commands/sideload/index.js +1 -0
  62. package/dist/cli/commands/sideload/install.js +19 -0
  63. package/dist/cli/commands/sideload/install.js.map +1 -0
  64. package/dist/cli/commands/sideload/setup.js +18 -0
  65. package/dist/cli/commands/sideload/setup.js.map +1 -0
  66. package/dist/cli/commands/sideload/sideload.js +22 -0
  67. package/dist/cli/commands/sideload/sideload.js.map +1 -0
  68. package/dist/cli/commands/sideload/uninstall.js +13 -0
  69. package/dist/cli/commands/sideload/uninstall.js.map +1 -0
  70. package/dist/cli/commands/sideload/update.js +19 -0
  71. package/dist/cli/commands/sideload/update.js.map +1 -0
  72. package/dist/cli/commands/swiplet/call.js +57 -0
  73. package/dist/cli/commands/swiplet/call.js.map +1 -0
  74. package/dist/cli/commands/swiplet/index.js +1 -0
  75. package/dist/cli/commands/swiplet/install.js +21 -0
  76. package/dist/cli/commands/swiplet/install.js.map +1 -0
  77. package/dist/cli/commands/swiplet/list.js +42 -0
  78. package/dist/cli/commands/swiplet/list.js.map +1 -0
  79. package/dist/cli/commands/swiplet/remove.js +18 -0
  80. package/dist/cli/commands/swiplet/remove.js.map +1 -0
  81. package/dist/cli/commands/swiplet/service/disable.js +18 -0
  82. package/dist/cli/commands/swiplet/service/disable.js.map +1 -0
  83. package/dist/cli/commands/swiplet/service/enable.js +18 -0
  84. package/dist/cli/commands/swiplet/service/enable.js.map +1 -0
  85. package/dist/cli/commands/swiplet/service/index.js +1 -0
  86. package/dist/cli/commands/swiplet/service/service.js +18 -0
  87. package/dist/cli/commands/swiplet/service/service.js.map +1 -0
  88. package/dist/cli/commands/swiplet/service/services.js +21 -0
  89. package/dist/cli/commands/swiplet/service/services.js.map +1 -0
  90. package/dist/cli/commands/swiplet/service/watch.js +16 -0
  91. package/dist/cli/commands/swiplet/service/watch.js.map +1 -0
  92. package/dist/cli/commands/swiplet/show.js +38 -0
  93. package/dist/cli/commands/swiplet/show.js.map +1 -0
  94. package/dist/cli/commands/swiplet/swiplet.js +42 -0
  95. package/dist/cli/commands/swiplet/swiplet.js.map +1 -0
  96. package/dist/cli/commands/version/index.js +1 -0
  97. package/dist/cli/commands/version/version.js +17 -0
  98. package/dist/cli/commands/version/version.js.map +1 -0
  99. package/dist/cli/deploy.js +20 -0
  100. package/dist/cli/deploy.js.map +1 -0
  101. package/dist/cli/io.js +7 -0
  102. package/dist/cli/io.js.map +1 -0
  103. package/dist/cli/session.js +6 -0
  104. package/dist/cli/session.js.map +1 -0
  105. package/dist/metro.js +1 -1
  106. package/dist/project.d.ts +2 -3
  107. package/dist/project.js +2 -203
  108. package/dist/project.js.map +1 -1
  109. package/package.json +5 -5
  110. package/dist/device.d.ts +0 -130
  111. package/dist/device.js +0 -539
  112. package/dist/device.js.map +0 -1
  113. package/dist/swipt.js +0 -631
  114. package/dist/swipt.js.map +0 -1
  115. /package/dist/{swipt.d.ts → bin/swipt.d.ts} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.js","names":[],"sources":["../../../../src/cli/commands/project/project.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\nimport { build } from \"./build\";\nimport { create } from \"./create\";\nimport { deploy } from \"./deploy\";\nimport { develop } from \"./develop\";\nimport { source } from \"./source\";\n\nexport const project = defineCommand({\n name: \"project\",\n short: tr(\"Make, build and deploy swiplet projects\"),\n commands: [create, build, source, deploy, develop],\n});\n"],"mappings":";;;;;;;;AAQA,MAAa,UAAU,cAAc;CACnC,MAAM;CACN,OAAO,GAAG,yCAAyC;CACnD,UAAU;EAAC;EAAQ;EAAO;EAAQ;EAAQ;CAAO;AACnD,CAAC"}
@@ -0,0 +1,126 @@
1
+ import { tr } from "../../../i18n.js";
2
+ import { idPattern } from "../../../project.js";
3
+ import { defineCommand } from "../../command.js";
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+ import { execFileSync } from "node:child_process";
7
+ import { createHash } from "node:crypto";
8
+ // src/cli/commands/project/source.ts
9
+ const manifestEntry = /^(?:[^/]+\/)?manifest\.json$/;
10
+ function loadSource(root) {
11
+ const manifest = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
12
+ const config = manifest.source ?? {};
13
+ for (const field of [
14
+ "name",
15
+ "image",
16
+ "url"
17
+ ]) if (config[field] !== void 0 && typeof config[field] !== "string") throw new Error(tr("\"{field}\" in package.json must be a string", { field: `source.${field}` }));
18
+ const localizedNames = config.localizedNames ?? {};
19
+ if (localizedNames === null || typeof localizedNames !== "object" || !Object.values(localizedNames).every((name) => typeof name === "string")) throw new Error(tr("\"source.localizedNames\" in package.json must map languages to names"));
20
+ if (config.icon !== void 0 && (typeof config.icon?.symbol !== "string" || config.icon.color !== void 0 && typeof config.icon.color !== "string")) throw new Error(tr("\"source.icon\" in package.json must have a symbol and may have a color"));
21
+ let prefix;
22
+ if (config.url !== void 0) try {
23
+ prefix = new URL(config.url.endsWith("/") ? config.url : `${config.url}/`);
24
+ } catch {
25
+ throw new Error(tr("\"source.url\" in package.json is not an absolute URL"));
26
+ }
27
+ const workspaces = Array.isArray(manifest.workspaces) ? manifest.workspaces : manifest.workspaces?.packages ?? [];
28
+ return {
29
+ root,
30
+ config,
31
+ localizedNames,
32
+ prefix,
33
+ workspaces
34
+ };
35
+ }
36
+ function workspaceSwiplets(source) {
37
+ const files = [];
38
+ for (const pattern of source.workspaces) for (const directory of fs.globSync(pattern, { cwd: source.root }).sort()) {
39
+ const project = path.join(source.root, directory, "package.json");
40
+ if (!fs.existsSync(project)) continue;
41
+ const id = JSON.parse(fs.readFileSync(project, "utf8")).swiplet?.id;
42
+ if (typeof id !== "string") continue;
43
+ const built = path.join(source.root, directory, "dist", `${id}.swiplet`);
44
+ if (!fs.existsSync(built)) throw new Error(tr("{file} is missing; build {directory} first", {
45
+ file: path.relative(source.root, built),
46
+ directory
47
+ }));
48
+ files.push(built);
49
+ }
50
+ return files;
51
+ }
52
+ function readSwiplet(file) {
53
+ const entry = execFileSync("unzip", ["-Z1", file], { encoding: "utf8" }).split("\n").filter((name) => manifestEntry.test(name)).sort((a, b) => a.length - b.length)[0];
54
+ if (entry === void 0) throw new Error(`${file} has no manifest.json`);
55
+ const manifest = JSON.parse(execFileSync("unzip", [
56
+ "-p",
57
+ file,
58
+ entry
59
+ ], { encoding: "utf8" }));
60
+ if (typeof manifest.id !== "string" || !idPattern.test(manifest.id)) throw new Error(`${file} has no valid swiplet id in its manifest`);
61
+ return {
62
+ file,
63
+ manifest,
64
+ data: fs.readFileSync(file)
65
+ };
66
+ }
67
+ function sourceCommand(root, given) {
68
+ const source = loadSource(root);
69
+ const files = given.length > 0 ? given.map((file) => path.resolve(file)) : workspaceSwiplets(source);
70
+ if (files.length === 0) throw new Error(tr("package.json lists no workspaces with swiplets; name the swiplets to list"));
71
+ const swiplets = /* @__PURE__ */ new Map();
72
+ for (const read of files.map(readSwiplet)) {
73
+ const { id } = read.manifest;
74
+ if (swiplets.has(id)) throw new Error(tr("{id} is both {first} and {second}", {
75
+ id,
76
+ first: swiplets.get(id).file,
77
+ second: read.file
78
+ }));
79
+ swiplets.set(id, read);
80
+ }
81
+ const image = source.config.image === void 0 ? void 0 : {
82
+ name: path.basename(source.config.image),
83
+ data: fs.readFileSync(path.resolve(root, source.config.image))
84
+ };
85
+ const located = (name) => source.prefix ? new URL(name, source.prefix).href : name;
86
+ const dist = path.join(root, "dist");
87
+ fs.rmSync(dist, {
88
+ recursive: true,
89
+ force: true
90
+ });
91
+ fs.mkdirSync(dist, { recursive: true });
92
+ const entries = [...swiplets.keys()].map((id) => {
93
+ const { manifest, data } = swiplets.get(id);
94
+ const name = `${id}.swiplet`;
95
+ fs.writeFileSync(path.join(dist, name), data);
96
+ return {
97
+ ...manifest,
98
+ url: located(name),
99
+ size: data.length,
100
+ sha256: createHash("sha256").update(data).digest("hex")
101
+ };
102
+ });
103
+ if (image) fs.writeFileSync(path.join(dist, image.name), image.data);
104
+ const index = {
105
+ ...source.config.name ? { name: source.config.name } : {},
106
+ ...Object.keys(source.localizedNames).length > 0 ? { localizedNames: source.localizedNames } : {},
107
+ ...source.config.icon ? { icon: {
108
+ symbol: source.config.icon.symbol,
109
+ ...source.config.icon.color ? { color: source.config.icon.color } : {}
110
+ } } : {},
111
+ ...image ? { image: located(image.name) } : {},
112
+ swiplets: entries
113
+ };
114
+ fs.writeFileSync(path.join(dist, "swiplets.json"), `${JSON.stringify(index, null, 2)}\n`);
115
+ console.log(path.relative(process.cwd(), path.join(dist, "swiplets.json")));
116
+ }
117
+ const source = defineCommand({
118
+ name: "source",
119
+ use: "source [SWIPLET...]",
120
+ short: tr("Collect the built swiplets into dist/ with a swiplets.json"),
121
+ args: [0, Infinity],
122
+ run: ({ args }) => sourceCommand(process.cwd(), args)
123
+ });
124
+ export { source };
125
+
126
+ //# sourceMappingURL=source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.js","names":[],"sources":["../../../../src/cli/commands/project/source.ts"],"sourcesContent":["import { execFileSync } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport { tr } from \"../../../i18n\";\nimport { idPattern } from \"../../../project\";\nimport { defineCommand } from \"../../command\";\n\nconst manifestEntry = /^(?:[^/]+\\/)?manifest\\.json$/;\n\nfunction loadSource(root) {\n const manifest = JSON.parse(\n fs.readFileSync(path.join(root, \"package.json\"), \"utf8\"),\n );\n const config = manifest.source ?? {};\n for (const field of [\"name\", \"image\", \"url\"]) {\n if (config[field] !== undefined && typeof config[field] !== \"string\") {\n throw new Error(\n tr('\"{field}\" in package.json must be a string', {\n field: `source.${field}`,\n }),\n );\n }\n }\n const localizedNames = config.localizedNames ?? {};\n if (\n localizedNames === null ||\n typeof localizedNames !== \"object\" ||\n !Object.values(localizedNames).every((name) => typeof name === \"string\")\n ) {\n throw new Error(\n tr('\"source.localizedNames\" in package.json must map languages to names'),\n );\n }\n if (\n config.icon !== undefined &&\n (typeof config.icon?.symbol !== \"string\" ||\n (config.icon.color !== undefined &&\n typeof config.icon.color !== \"string\"))\n ) {\n throw new Error(\n tr(\n '\"source.icon\" in package.json must have a symbol and may have a color',\n ),\n );\n }\n let prefix;\n if (config.url !== undefined) {\n try {\n prefix = new URL(\n config.url.endsWith(\"/\") ? config.url : `${config.url}/`,\n );\n } catch {\n throw new Error(\n tr('\"source.url\" in package.json is not an absolute URL'),\n );\n }\n }\n const workspaces = Array.isArray(manifest.workspaces)\n ? manifest.workspaces\n : (manifest.workspaces?.packages ?? []);\n return { root, config, localizedNames, prefix, workspaces };\n}\n\nfunction workspaceSwiplets(source) {\n const files = [];\n for (const pattern of source.workspaces) {\n for (const directory of fs.globSync(pattern, { cwd: source.root }).sort()) {\n const project = path.join(source.root, directory, \"package.json\");\n if (!fs.existsSync(project)) {\n continue;\n }\n const id = JSON.parse(fs.readFileSync(project, \"utf8\")).swiplet?.id;\n if (typeof id !== \"string\") {\n continue;\n }\n const built = path.join(source.root, directory, \"dist\", `${id}.swiplet`);\n if (!fs.existsSync(built)) {\n throw new Error(\n tr(\"{file} is missing; build {directory} first\", {\n file: path.relative(source.root, built),\n directory,\n }),\n );\n }\n files.push(built);\n }\n }\n return files;\n}\n\nfunction readSwiplet(file) {\n const entry = execFileSync(\"unzip\", [\"-Z1\", file], { encoding: \"utf8\" })\n .split(\"\\n\")\n .filter((name) => manifestEntry.test(name))\n .sort((a, b) => a.length - b.length)[0];\n if (entry === undefined) {\n throw new Error(`${file} has no manifest.json`);\n }\n const manifest = JSON.parse(\n execFileSync(\"unzip\", [\"-p\", file, entry], { encoding: \"utf8\" }),\n );\n if (typeof manifest.id !== \"string\" || !idPattern.test(manifest.id)) {\n throw new Error(`${file} has no valid swiplet id in its manifest`);\n }\n return { file, manifest, data: fs.readFileSync(file) };\n}\n\nfunction sourceCommand(root, given) {\n const source = loadSource(root);\n const files =\n given.length > 0\n ? given.map((file) => path.resolve(file))\n : workspaceSwiplets(source);\n if (files.length === 0) {\n throw new Error(\n tr(\n \"package.json lists no workspaces with swiplets; name the swiplets to list\",\n ),\n );\n }\n const swiplets = new Map();\n for (const read of files.map(readSwiplet)) {\n const { id } = read.manifest;\n if (swiplets.has(id)) {\n throw new Error(\n tr(\"{id} is both {first} and {second}\", {\n id,\n first: swiplets.get(id).file,\n second: read.file,\n }),\n );\n }\n swiplets.set(id, read);\n }\n const image =\n source.config.image === undefined\n ? undefined\n : {\n name: path.basename(source.config.image),\n data: fs.readFileSync(path.resolve(root, source.config.image)),\n };\n const located = (name) =>\n source.prefix ? new URL(name, source.prefix).href : name;\n const dist = path.join(root, \"dist\");\n fs.rmSync(dist, { recursive: true, force: true });\n fs.mkdirSync(dist, { recursive: true });\n const entries = [...swiplets.keys()].map((id) => {\n const { manifest, data } = swiplets.get(id);\n const name = `${id}.swiplet`;\n fs.writeFileSync(path.join(dist, name), data);\n return {\n ...manifest,\n url: located(name),\n size: data.length,\n sha256: createHash(\"sha256\").update(data).digest(\"hex\"),\n };\n });\n if (image) {\n fs.writeFileSync(path.join(dist, image.name), image.data);\n }\n const index = {\n ...(source.config.name ? { name: source.config.name } : {}),\n ...(Object.keys(source.localizedNames).length > 0\n ? { localizedNames: source.localizedNames }\n : {}),\n ...(source.config.icon\n ? {\n icon: {\n symbol: source.config.icon.symbol,\n ...(source.config.icon.color\n ? { color: source.config.icon.color }\n : {}),\n },\n }\n : {}),\n ...(image ? { image: located(image.name) } : {}),\n swiplets: entries,\n };\n fs.writeFileSync(\n path.join(dist, \"swiplets.json\"),\n `${JSON.stringify(index, null, 2)}\\n`,\n );\n console.log(path.relative(process.cwd(), path.join(dist, \"swiplets.json\")));\n}\n\nexport const source = defineCommand({\n name: \"source\",\n use: \"source [SWIPLET...]\",\n short: tr(\"Collect the built swiplets into dist/ with a swiplets.json\"),\n args: [0, Infinity],\n run: ({ args }) => sourceCommand(process.cwd(), args),\n});\n"],"mappings":";;;;;;;;AASA,MAAM,gBAAgB;AAEtB,SAAS,WAAW,MAAM;CACxB,MAAM,WAAW,KAAK,MACpB,GAAG,aAAa,KAAK,KAAK,MAAM,cAAc,GAAG,MAAM,CACzD;CACA,MAAM,SAAS,SAAS,UAAU,CAAC;CACnC,KAAK,MAAM,SAAS;EAAC;EAAQ;EAAS;CAAK,GACzC,IAAI,OAAO,WAAW,KAAA,KAAa,OAAO,OAAO,WAAW,UAC1D,MAAM,IAAI,MACR,GAAG,gDAA8C,EAC/C,OAAO,UAAU,QACnB,CAAC,CACH;CAGJ,MAAM,iBAAiB,OAAO,kBAAkB,CAAC;CACjD,IACE,mBAAmB,QACnB,OAAO,mBAAmB,YAC1B,CAAC,OAAO,OAAO,cAAc,CAAC,CAAC,OAAO,SAAS,OAAO,SAAS,QAAQ,GAEvE,MAAM,IAAI,MACR,GAAG,uEAAqE,CAC1E;CAEF,IACE,OAAO,SAAS,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AM,eAAe,CAAC,CAAC;AAC5E;AAEA,MAAa,SAAS,cAAc;CAClC,MAAM;CACN,KAAK;CACL,OAAO,GAAG,4DAA4D;CACtE,MAAM,CAAC,GAAG,QAAQ;CAClB,MAAM,EAAE,WAAW,cAAc,QAAQ,IAAI,GAAG,IAAI;AACtD,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { tr } from "../../../i18n.js";
2
+ import { defineCommand } from "../../command.js";
3
+ import { session } from "../../session.js";
4
+ // src/cli/commands/repl/api.ts
5
+ const printDeclarations = (context) => session(context, async (client) => {
6
+ process.stdout.write((await client.repl.getDeclarations({}, { signal: context.signal })).typescript);
7
+ });
8
+ const api = defineCommand({
9
+ name: "api",
10
+ short: tr("Print the TypeScript declarations of the globals and modules"),
11
+ args: [0, 0],
12
+ run: printDeclarations
13
+ });
14
+ export { api };
15
+
16
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","names":[],"sources":["../../../../src/cli/commands/repl/api.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\nimport { session } from \"../../session\";\n\nconst printDeclarations = (context) =>\n session(context, async (client) => {\n process.stdout.write(\n (await client.repl.getDeclarations({}, { signal: context.signal }))\n .typescript,\n );\n });\n\nexport const api = defineCommand({\n name: \"api\",\n short: tr(\"Print the TypeScript declarations of the globals and modules\"),\n args: [0, 0],\n run: printDeclarations,\n});\n"],"mappings":";;;;AAIA,MAAM,qBAAqB,YACzB,QAAQ,SAAS,OAAO,WAAW;CACjC,QAAQ,OAAO,OACZ,MAAM,OAAO,KAAK,gBAAgB,CAAC,GAAG,EAAE,QAAQ,QAAQ,OAAO,CAAC,EAAA,CAC9D,UACL;AACF,CAAC;AAEH,MAAa,MAAM,cAAc;CAC/B,MAAM;CACN,OAAO,GAAG,8DAA8D;CACxE,MAAM,CAAC,GAAG,CAAC;CACX,KAAK;AACP,CAAC"}
@@ -0,0 +1 @@
1
+ export { repl } from "./repl.js";
@@ -0,0 +1,29 @@
1
+ import { tr } from "../../../i18n.js";
2
+ import { defineCommand } from "../../command.js";
3
+ import "../data/index.js";
4
+ import { data } from "../data/data.js";
5
+ import { deviceOption } from "../flags.js";
6
+ import { api } from "./api.js";
7
+ import { reset } from "./reset.js";
8
+ import { run } from "./run.js";
9
+ // src/cli/commands/repl/repl.ts
10
+ const replData = (args) => ({
11
+ id: "@repl",
12
+ wholeDirectory: (name) => tr("{path} names the data directory of the REPL; save it with --output DIRECTORY", { path: name }),
13
+ subdirectory: (name) => tr("{path} is a directory in the data directory of the REPL; save it with --output DIRECTORY", { path: name }),
14
+ args
15
+ });
16
+ const repl = defineCommand({
17
+ name: "repl",
18
+ short: tr("Run JavaScript in the REPL session on the device"),
19
+ options: deviceOption,
20
+ commands: [
21
+ run,
22
+ reset,
23
+ api,
24
+ data("", replData)
25
+ ]
26
+ });
27
+ export { repl };
28
+
29
+ //# sourceMappingURL=repl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repl.js","names":[],"sources":["../../../../src/cli/commands/repl/repl.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\nimport { data } from \"../data\";\nimport { deviceOption } from \"../flags\";\nimport { api } from \"./api\";\nimport { reset } from \"./reset\";\nimport { run } from \"./run\";\n\nconst replData = (args) => ({\n id: \"@repl\",\n wholeDirectory: (name) =>\n tr(\n \"{path} names the data directory of the REPL; save it with --output DIRECTORY\",\n { path: name },\n ),\n subdirectory: (name) =>\n tr(\n \"{path} is a directory in the data directory of the REPL; save it with --output DIRECTORY\",\n { path: name },\n ),\n args,\n});\n\nexport const repl = defineCommand({\n name: \"repl\",\n short: tr(\"Run JavaScript in the REPL session on the device\"),\n options: deviceOption,\n commands: [run, reset, api, data(\"\", replData)],\n});\n"],"mappings":";;;;;;;;;AAQA,MAAM,YAAY,UAAU;CAC1B,IAAI;CACJ,iBAAiB,SACf,GACE,gFACA,EAAE,MAAM,KAAK,CACf;CACF,eAAe,SACb,GACE,4FACA,EAAE,MAAM,KAAK,CACf;CACF;AACF;AAEA,MAAa,OAAO,cAAc;CAChC,MAAM;CACN,OAAO,GAAG,kDAAkD;CAC5D,SAAS;CACT,UAAU;EAAC;EAAK;EAAO;EAAK,KAAK,IAAI,QAAQ;CAAC;AAChD,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { tr } from "../../../i18n.js";
2
+ import { defineCommand } from "../../command.js";
3
+ import { session } from "../../session.js";
4
+ // src/cli/commands/repl/reset.ts
5
+ const resetSession = (context) => session(context, (client) => client.repl.reset({}, { signal: context.signal }));
6
+ const reset = defineCommand({
7
+ name: "reset",
8
+ short: tr("Reset the session"),
9
+ args: [0, 0],
10
+ run: resetSession
11
+ });
12
+ export { reset };
13
+
14
+ //# sourceMappingURL=reset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reset.js","names":[],"sources":["../../../../src/cli/commands/repl/reset.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\nimport { session } from \"../../session\";\n\nconst resetSession = (context) =>\n session(context, (client) =>\n client.repl.reset({}, { signal: context.signal }),\n );\n\nexport const reset = defineCommand({\n name: \"reset\",\n short: tr(\"Reset the session\"),\n args: [0, 0],\n run: resetSession,\n});\n"],"mappings":";;;;AAIA,MAAM,gBAAgB,YACpB,QAAQ,UAAU,WAChB,OAAO,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,QAAQ,OAAO,CAAC,CAClD;AAEF,MAAa,QAAQ,cAAc;CACjC,MAAM;CACN,OAAO,GAAG,mBAAmB;CAC7B,MAAM,CAAC,GAAG,CAAC;CACX,KAAK;AACP,CAAC"}
@@ -0,0 +1,108 @@
1
+ import { UsageError } from "../../../client.js";
2
+ import { tr } from "../../../i18n.js";
3
+ import { printScriptError } from "../../../output.js";
4
+ import "../../../proto/common_pb.js";
5
+ import { defineCommand } from "../../command.js";
6
+ import { readStdin } from "../../io.js";
7
+ import { session } from "../../session.js";
8
+ import fs from "node:fs";
9
+ import path from "node:path";
10
+ import os from "node:os";
11
+ import crypto from "node:crypto";
12
+ // src/cli/commands/repl/run.ts
13
+ const isFile = (name) => {
14
+ try {
15
+ return fs.statSync(name).isFile();
16
+ } catch {
17
+ return false;
18
+ }
19
+ };
20
+ const isProgram = (first) => first === "-" || isFile(first);
21
+ function readScript([first, ...args]) {
22
+ if (first === void 0 || first === "-") return {
23
+ code: readStdin().toString(),
24
+ args,
25
+ program: true,
26
+ file: "input.js"
27
+ };
28
+ if (isFile(first)) return {
29
+ code: fs.readFileSync(first, "utf8"),
30
+ args,
31
+ program: true,
32
+ file: first
33
+ };
34
+ if (args.length > 0) throw new UsageError(tr("{argument} is not a file, and CODE takes no ARG", { argument: JSON.stringify(first) }));
35
+ return {
36
+ code: first,
37
+ args,
38
+ program: false,
39
+ file: "input.js"
40
+ };
41
+ }
42
+ var ImageSink = class {
43
+ directory = "";
44
+ constructor(output) {
45
+ this.output = output;
46
+ }
47
+ save(data) {
48
+ if (this.directory === "") {
49
+ if (this.output !== void 0 && this.output !== "") {
50
+ this.directory = path.resolve(this.output);
51
+ fs.mkdirSync(this.directory, { recursive: true });
52
+ } else this.directory = fs.mkdtempSync(path.join(os.tmpdir(), "swipt-repl-"));
53
+ }
54
+ const name = path.join(this.directory, `image-${crypto.randomBytes(5).toString("hex")}.png`);
55
+ fs.writeFileSync(name, data);
56
+ return name;
57
+ }
58
+ };
59
+ async function runScript(context) {
60
+ const { args, options, signal } = context;
61
+ const script = readScript(args);
62
+ await session(context, async (client) => {
63
+ const images = new ImageSink(options.output);
64
+ let failure;
65
+ for await (const response of client.repl.execute({
66
+ code: script.code,
67
+ args: script.args,
68
+ program: script.program
69
+ }, { signal })) switch (response.part.case) {
70
+ case "console": {
71
+ const output = response.part.value;
72
+ (output.level === 1 || output.level === 2 ? console.error : console.log)(output.text);
73
+ break;
74
+ }
75
+ case "value":
76
+ console.log(response.part.value.text);
77
+ break;
78
+ case "image":
79
+ console.log(`[image: ${images.save(response.part.value)}]`);
80
+ break;
81
+ case "error": failure = response.part.value;
82
+ }
83
+ if (failure) throw printScriptError({
84
+ ...failure,
85
+ stack: failure.stack.map((frame) => frame.file === "input.js" ? {
86
+ ...frame,
87
+ file: script.file
88
+ } : frame)
89
+ });
90
+ });
91
+ }
92
+ const run = defineCommand({
93
+ name: "run",
94
+ use: "run [CODE | FILE [ARG...] | - [ARG...]]",
95
+ short: tr("Run a JavaScript expression or program on the device"),
96
+ description: [tr("The first argument is FILE when it names an existing file and CODE otherwise; options go before it."), tr("CODE is an expression whose value is printed. FILE, or standard input given as - or no argument, is a program, and only its console output is printed.")],
97
+ args: [0, Infinity],
98
+ passthrough: isProgram,
99
+ options: { output: {
100
+ type: "string",
101
+ value: "DIRECTORY",
102
+ help: tr("image directory (default: a new temporary directory)")
103
+ } },
104
+ run: runScript
105
+ });
106
+ export { run };
107
+
108
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","names":[],"sources":["../../../../src/cli/commands/repl/run.ts"],"sourcesContent":["import crypto from \"node:crypto\";\nimport fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\n\nimport { UsageError } from \"../../../client\";\nimport { tr } from \"../../../i18n\";\nimport { printScriptError } from \"../../../output\";\nimport { LogLevel } from \"../../../proto/common_pb\";\nimport { defineCommand } from \"../../command\";\nimport { readStdin } from \"../../io\";\nimport { session } from \"../../session\";\n\nconst isFile = (name) => {\n try {\n return fs.statSync(name).isFile();\n } catch {\n return false;\n }\n};\n\nconst isProgram = (first) => first === \"-\" || isFile(first);\n\nfunction readScript([first, ...args]) {\n if (first === undefined || first === \"-\") {\n return {\n code: readStdin().toString(),\n args,\n program: true,\n file: \"input.js\",\n };\n }\n if (isFile(first)) {\n return {\n code: fs.readFileSync(first, \"utf8\"),\n args,\n program: true,\n file: first,\n };\n }\n if (args.length > 0) {\n throw new UsageError(\n tr(\"{argument} is not a file, and CODE takes no ARG\", {\n argument: JSON.stringify(first),\n }),\n );\n }\n return { code: first, args, program: false, file: \"input.js\" };\n}\n\nclass ImageSink {\n declare output: string | undefined;\n directory = \"\";\n\n constructor(output) {\n this.output = output;\n }\n\n save(data) {\n if (this.directory === \"\") {\n if (this.output !== undefined && this.output !== \"\") {\n this.directory = path.resolve(this.output);\n fs.mkdirSync(this.directory, { recursive: true });\n } else {\n this.directory = fs.mkdtempSync(path.join(os.tmpdir(), \"swipt-repl-\"));\n }\n }\n const name = path.join(\n this.directory,\n `image-${crypto.randomBytes(5).toString(\"hex\")}.png`,\n );\n fs.writeFileSync(name, data);\n return name;\n }\n}\n\nasync function runScript(context) {\n const { args, options, signal } = context;\n const script = readScript(args);\n await session(context, async (client) => {\n const images = new ImageSink(options.output);\n let failure;\n for await (const response of client.repl.execute(\n { code: script.code, args: script.args, program: script.program },\n { signal },\n )) {\n switch (response.part.case) {\n case \"console\": {\n const output = response.part.value;\n (output.level === LogLevel.ERROR || output.level === LogLevel.WARN\n ? console.error\n : console.log)(output.text);\n break;\n }\n case \"value\":\n console.log(response.part.value.text);\n break;\n case \"image\":\n console.log(`[image: ${images.save(response.part.value)}]`);\n break;\n case \"error\":\n failure = response.part.value;\n break;\n }\n }\n if (failure) {\n throw printScriptError({\n ...failure,\n stack: failure.stack.map((frame) =>\n frame.file === \"input.js\" ? { ...frame, file: script.file } : frame,\n ),\n });\n }\n });\n}\n\nexport const run = defineCommand({\n name: \"run\",\n use: \"run [CODE | FILE [ARG...] | - [ARG...]]\",\n short: tr(\"Run a JavaScript expression or program on the device\"),\n description: [\n tr(\n \"The first argument is FILE when it names an existing file and CODE otherwise; options go before it.\",\n ),\n tr(\n \"CODE is an expression whose value is printed. FILE, or standard input given as - or no argument, is a program, and only its console output is printed.\",\n ),\n ],\n args: [0, Infinity],\n passthrough: isProgram,\n options: {\n output: {\n type: \"string\",\n value: \"DIRECTORY\",\n help: tr(\"image directory (default: a new temporary directory)\"),\n },\n },\n run: runScript,\n});\n"],"mappings":";;;;;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AAQ,SAAS,OAAO,WAAW;EACvC,MAAM,SAAS,IAAI,UAAU,QAAQ,MAAM;EAC3C,IAAI;EACJ,WAAW,MAAM,YAAY,OAAO,KAAK,QACvC;GAAE,MAAM,OAAO;GAAM,MAAM,OAAO;GAAM,SAAS,OAAO;EAAQ,GAChE,EAAE,OAAO,CACX,GACE,QAAQ,SAAS,KAAK,MAAtB;GACE,KAAK,WAAW;IACd,MAAM,SAAS,SAAS,KAAK;IAC7B,CAAC,OAAO,UAAA,KAA4B,OAAO,UAAA,IACvC,QAAQ,QACR,QAAQ,IAAA,CAAK,OAAO,IAAI;IAC5B;GACF;GACA,KAAK;IACH,QAAQ,IAAI,SAAS,KAAK,MAAM,IAAI;IACpC;GACF,KAAK;IACH,QAAQ,IAAI,WAAW,OAAO,KAAK,SAAS,KAAK,KAAK,EAAE,EAAE;IAC1D;GACF,KAAK,SACH,UAAU,SAAS,KAAK;EAE5B;EAEF,IAAI,SACF,MAAM,iBAAiB;GACrB,GAAG;GACH,OAAO,QAAQ,MAAM,KAAK,UACxB,MAAM,SAAS,aAAa;IAAE,GAAG;IAAO,MAAM,OAAO;GAAK,IAAI,KAChE;EACF,CAAC;CAEL,CAAC;AACH;AAEA,MAAa,MAAM,cAAc;CAC/B,MAAM;CACN,KAAK;CACL,OAAO,GAAG,sDAAsD;CAChE,aAAa,CACX,GACE,qGACF,GACA,GACE,wJACF,CACF;CACA,MAAM,CAAC,GAAG,QAAQ;CAClB,aAAa;CACb,SAAS,EACP,QAAQ;EACN,MAAM;EACN,OAAO;EACP,MAAM,GAAG,sDAAsD;CACjE,EACF;CACA,KAAK;AACP,CAAC"}
@@ -0,0 +1 @@
1
+ export { sideload } from "./sideload.js";
@@ -0,0 +1,19 @@
1
+ import { tr } from "../../../i18n.js";
2
+ import { install as install$1 } from "../../../sideload.js";
3
+ import { defineCommand } from "../../command.js";
4
+ import { nightlyOption, passcodeOptions, setupOptions } from "../flags.js";
5
+ // src/cli/commands/sideload/install.ts
6
+ const install = defineCommand({
7
+ name: "install",
8
+ short: tr("Install Swipt"),
9
+ args: [0, 0],
10
+ options: {
11
+ ...passcodeOptions(tr("set up auto-unlock with this passcode")),
12
+ ...nightlyOption,
13
+ ...setupOptions
14
+ },
15
+ run: install$1
16
+ });
17
+ export { install };
18
+
19
+ //# sourceMappingURL=install.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.js","names":["sideload.install"],"sources":["../../../../src/cli/commands/sideload/install.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport * as sideload from \"../../../sideload\";\nimport { defineCommand } from \"../../command\";\nimport { nightlyOption, passcodeOptions, setupOptions } from \"../flags\";\n\nexport const install = defineCommand({\n name: \"install\",\n short: tr(\"Install Swipt\"),\n args: [0, 0],\n options: {\n ...passcodeOptions(tr(\"set up auto-unlock with this passcode\")),\n ...nightlyOption,\n ...setupOptions,\n },\n run: sideload.install,\n});\n"],"mappings":";;;;;AAKA,MAAa,UAAU,cAAc;CACnC,MAAM;CACN,OAAO,GAAG,eAAe;CACzB,MAAM,CAAC,GAAG,CAAC;CACX,SAAS;EACP,GAAG,gBAAgB,GAAG,uCAAuC,CAAC;EAC9D,GAAG;EACH,GAAG;CACL;CACA,KAAKA;AACP,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { tr } from "../../../i18n.js";
2
+ import { setup as setup$1 } from "../../../sideload.js";
3
+ import { defineCommand } from "../../command.js";
4
+ import { passcodeOptions, setupStepOptions } from "../flags.js";
5
+ // src/cli/commands/sideload/setup.ts
6
+ const setup = defineCommand({
7
+ name: "setup",
8
+ short: tr("Set up Swipt"),
9
+ args: [0, 0],
10
+ options: {
11
+ ...passcodeOptions(tr("set up auto-unlock with this passcode")),
12
+ ...setupStepOptions
13
+ },
14
+ run: setup$1
15
+ });
16
+ export { setup };
17
+
18
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.js","names":["sideload.setup"],"sources":["../../../../src/cli/commands/sideload/setup.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport * as sideload from \"../../../sideload\";\nimport { defineCommand } from \"../../command\";\nimport { passcodeOptions, setupStepOptions } from \"../flags\";\n\nexport const setup = defineCommand({\n name: \"setup\",\n short: tr(\"Set up Swipt\"),\n args: [0, 0],\n options: {\n ...passcodeOptions(tr(\"set up auto-unlock with this passcode\")),\n ...setupStepOptions,\n },\n run: sideload.setup,\n});\n"],"mappings":";;;;;AAKA,MAAa,QAAQ,cAAc;CACjC,MAAM;CACN,OAAO,GAAG,cAAc;CACxB,MAAM,CAAC,GAAG,CAAC;CACX,SAAS;EACP,GAAG,gBAAgB,GAAG,uCAAuC,CAAC;EAC9D,GAAG;CACL;CACA,KAAKA;AACP,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { tr } from "../../../i18n.js";
2
+ import { defineCommand } from "../../command.js";
3
+ import { sideloadOptions } from "../flags.js";
4
+ import { install } from "./install.js";
5
+ import { setup } from "./setup.js";
6
+ import { uninstall } from "./uninstall.js";
7
+ import { update } from "./update.js";
8
+ // src/cli/commands/sideload/sideload.ts
9
+ const sideload = defineCommand({
10
+ name: "sideload",
11
+ short: tr("Sideload Swipt"),
12
+ options: sideloadOptions,
13
+ commands: [
14
+ install,
15
+ update,
16
+ setup,
17
+ uninstall
18
+ ]
19
+ });
20
+ export { sideload };
21
+
22
+ //# sourceMappingURL=sideload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sideload.js","names":[],"sources":["../../../../src/cli/commands/sideload/sideload.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\nimport { sideloadOptions } from \"../flags\";\nimport { install } from \"./install\";\nimport { setup } from \"./setup\";\nimport { uninstall } from \"./uninstall\";\nimport { update } from \"./update\";\n\nexport const sideload = defineCommand({\n name: \"sideload\",\n short: tr(\"Sideload Swipt\"),\n options: sideloadOptions,\n commands: [install, update, setup, uninstall],\n});\n"],"mappings":";;;;;;;;AAQA,MAAa,WAAW,cAAc;CACpC,MAAM;CACN,OAAO,GAAG,gBAAgB;CAC1B,SAAS;CACT,UAAU;EAAC;EAAS;EAAQ;EAAO;CAAS;AAC9C,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { tr } from "../../../i18n.js";
2
+ import { uninstall as uninstall$1 } from "../../../sideload.js";
3
+ import { defineCommand } from "../../command.js";
4
+ // src/cli/commands/sideload/uninstall.ts
5
+ const uninstall = defineCommand({
6
+ name: "uninstall",
7
+ short: tr("Remove Swipt"),
8
+ args: [0, 0],
9
+ run: uninstall$1
10
+ });
11
+ export { uninstall };
12
+
13
+ //# sourceMappingURL=uninstall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uninstall.js","names":["sideload.uninstall"],"sources":["../../../../src/cli/commands/sideload/uninstall.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport * as sideload from \"../../../sideload\";\nimport { defineCommand } from \"../../command\";\n\nexport const uninstall = defineCommand({\n name: \"uninstall\",\n short: tr(\"Remove Swipt\"),\n args: [0, 0],\n run: sideload.uninstall,\n});\n"],"mappings":";;;;AAIA,MAAa,YAAY,cAAc;CACrC,MAAM;CACN,OAAO,GAAG,cAAc;CACxB,MAAM,CAAC,GAAG,CAAC;CACX,KAAKA;AACP,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { tr } from "../../../i18n.js";
2
+ import { update as update$1 } from "../../../sideload.js";
3
+ import { defineCommand } from "../../command.js";
4
+ import { nightlyOption, passcodeOptions, setupOptions } from "../flags.js";
5
+ // src/cli/commands/sideload/update.ts
6
+ const update = defineCommand({
7
+ name: "update",
8
+ short: tr("Update or renew Swipt"),
9
+ args: [0, 0],
10
+ options: {
11
+ ...passcodeOptions(tr("unlock device with this passcode")),
12
+ ...nightlyOption,
13
+ ...setupOptions
14
+ },
15
+ run: update$1
16
+ });
17
+ export { update };
18
+
19
+ //# sourceMappingURL=update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.js","names":["sideload.update"],"sources":["../../../../src/cli/commands/sideload/update.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport * as sideload from \"../../../sideload\";\nimport { defineCommand } from \"../../command\";\nimport { nightlyOption, passcodeOptions, setupOptions } from \"../flags\";\n\nexport const update = defineCommand({\n name: \"update\",\n short: tr(\"Update or renew Swipt\"),\n args: [0, 0],\n options: {\n ...passcodeOptions(tr(\"unlock device with this passcode\")),\n ...nightlyOption,\n ...setupOptions,\n },\n run: sideload.update,\n});\n"],"mappings":";;;;;AAKA,MAAa,SAAS,cAAc;CAClC,MAAM;CACN,OAAO,GAAG,uBAAuB;CACjC,MAAM,CAAC,GAAG,CAAC;CACX,SAAS;EACP,GAAG,gBAAgB,GAAG,kCAAkC,CAAC;EACzD,GAAG;EACH,GAAG;CACL;CACA,KAAKA;AACP,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { UsageError } from "../../../client.js";
2
+ import { tr } from "../../../i18n.js";
3
+ import { printLog, printScriptError } from "../../../output.js";
4
+ import { defineCommand } from "../../command.js";
5
+ import { readStdin } from "../../io.js";
6
+ import { session } from "../../session.js";
7
+ import fs from "node:fs";
8
+ import { fromJson, toJson } from "@bufbuild/protobuf";
9
+ import { ValueSchema } from "@bufbuild/protobuf/wkt";
10
+ // src/cli/commands/swiplet/call.ts
11
+ function readInput(value) {
12
+ if (value === void 0 || value === "") return;
13
+ let data = value;
14
+ try {
15
+ if (value === "-") data = readStdin().toString();
16
+ else if (value.startsWith("@")) data = fs.readFileSync(value.slice(1), "utf8");
17
+ } catch (error) {
18
+ throw new Error(`read --input: ${error.message}`);
19
+ }
20
+ try {
21
+ return fromJson(ValueSchema, JSON.parse(data));
22
+ } catch (error) {
23
+ throw new UsageError(tr("--input is not JSON: {error}", { error: error.message }));
24
+ }
25
+ }
26
+ const callAction = (context) => session(context, async (client) => {
27
+ const [id, action] = context.args;
28
+ const input = readInput(context.options.input);
29
+ let result;
30
+ for await (const response of client.swiplets.callAction({
31
+ swipletId: id,
32
+ action,
33
+ input
34
+ }, { signal: context.signal })) if (response.part.case === "log") printLog(response.part.value, false);
35
+ else if (response.part.case === "result") result = response.part.value;
36
+ if (result?.outcome.case === "output") {
37
+ console.log(JSON.stringify(toJson(ValueSchema, result.outcome.value), null, 2));
38
+ return;
39
+ }
40
+ if (result?.outcome.case === "error") throw printScriptError(result.outcome.value);
41
+ throw new Error("the server sent no result");
42
+ });
43
+ const call = defineCommand({
44
+ name: "call",
45
+ use: "call ID ACTION",
46
+ short: tr("Call a swiplet action"),
47
+ args: [2, 2],
48
+ options: { input: {
49
+ type: "string",
50
+ value: "JSON",
51
+ help: tr("input JSON, @FILE or -")
52
+ } },
53
+ run: callAction
54
+ });
55
+ export { call };
56
+
57
+ //# sourceMappingURL=call.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"call.js","names":[],"sources":["../../../../src/cli/commands/swiplet/call.ts"],"sourcesContent":["import fs from \"node:fs\";\n\nimport { fromJson, toJson } from \"@bufbuild/protobuf\";\nimport { ValueSchema } from \"@bufbuild/protobuf/wkt\";\n\nimport { UsageError } from \"../../../client\";\nimport { tr } from \"../../../i18n\";\nimport { printLog, printScriptError } from \"../../../output\";\nimport { defineCommand } from \"../../command\";\nimport { readStdin } from \"../../io\";\nimport { session } from \"../../session\";\n\nfunction readInput(value) {\n if (value === undefined || value === \"\") {\n return undefined;\n }\n let data = value;\n try {\n if (value === \"-\") {\n data = readStdin().toString();\n } else if (value.startsWith(\"@\")) {\n data = fs.readFileSync(value.slice(1), \"utf8\");\n }\n } catch (error) {\n throw new Error(`read --input: ${error.message}`);\n }\n try {\n return fromJson(ValueSchema, JSON.parse(data));\n } catch (error) {\n throw new UsageError(\n tr(\"--input is not JSON: {error}\", { error: error.message }),\n );\n }\n}\n\nconst callAction = (context) =>\n session(context, async (client) => {\n const [id, action] = context.args;\n const input = readInput(context.options.input);\n let result;\n for await (const response of client.swiplets.callAction(\n { swipletId: id, action, input },\n { signal: context.signal },\n )) {\n if (response.part.case === \"log\") {\n printLog(response.part.value, false);\n } else if (response.part.case === \"result\") {\n result = response.part.value;\n }\n }\n if (result?.outcome.case === \"output\") {\n console.log(\n JSON.stringify(toJson(ValueSchema, result.outcome.value), null, 2),\n );\n return;\n }\n if (result?.outcome.case === \"error\") {\n throw printScriptError(result.outcome.value);\n }\n throw new Error(\"the server sent no result\");\n });\n\nexport const call = defineCommand({\n name: \"call\",\n use: \"call ID ACTION\",\n short: tr(\"Call a swiplet action\"),\n args: [2, 2],\n options: {\n input: {\n type: \"string\",\n value: \"JSON\",\n help: tr(\"input JSON, @FILE or -\"),\n },\n },\n run: callAction,\n});\n"],"mappings":";;;;;;;;;;AAYA,SAAS,UAAU,OAAO;CACxB,IAAI,UAAU,KAAA,KAAa,UAAU,IACnC;CAEF,IAAI,OAAO;CACX,IAAI;EACF,IAAI,UAAU,KACZ,OAAO,UAAU,CAAC,CAAC,SAAS;OACvB,IAAI,MAAM,WAAW,GAAG,GAC7B,OAAO,GAAG,aAAa,MAAM,MAAM,CAAC,GAAG,MAAM;CAEjD,SAAS,OAAO;EACd,MAAM,IAAI,MAAM,iBAAiB,MAAM,SAAS;CAClD;CACA,IAAI;EACF,OAAO,SAAS,aAAa,KAAK,MAAM,IAAI,CAAC;CAC/C,SAAS,OAAO;EACd,MAAM,IAAI,WACR,GAAG,gCAAgC,EAAE,OAAO,MAAM,QAAQ,CAAC,CAC7D;CACF;AACF;AAEA,MAAM,cAAc,YAClB,QAAQ,SAAS,OAAO,WAAW;CACjC,MAAM,CAAC,IAAI,UAAU,QAAQ;CAC7B,MAAM,QAAQ,UAAU,QAAQ,QAAQ,KAAK;CAC7C,IAAI;CACJ,WAAW,MAAM,YAAY,OAAO,SAAS,WAC3C;EAAE,WAAW;EAAI;EAAQ;CAAM,GAC/B,EAAE,QAAQ,QAAQ,OAAO,CAC3B,GACE,IAAI,SAAS,KAAK,SAAS,OACzB,SAAS,SAAS,KAAK,OAAO,KAAK;MAC9B,IAAI,SAAS,KAAK,SAAS,UAChC,SAAS,SAAS,KAAK;CAG3B,IAAI,QAAQ,QAAQ,SAAS,UAAU;EACrC,QAAQ,IACN,KAAK,UAAU,OAAO,aAAa,OAAO,QAAQ,KAAK,GAAG,MAAM,CAAC,CACnE;EACA;CACF;CACA,IAAI,QAAQ,QAAQ,SAAS,SAC3B,MAAM,iBAAiB,OAAO,QAAQ,KAAK;CAE7C,MAAM,IAAI,MAAM,2BAA2B;AAC7C,CAAC;AAEH,MAAa,OAAO,cAAc;CAChC,MAAM;CACN,KAAK;CACL,OAAO,GAAG,uBAAuB;CACjC,MAAM,CAAC,GAAG,CAAC;CACX,SAAS,EACP,OAAO;EACL,MAAM;EACN,OAAO;EACP,MAAM,GAAG,wBAAwB;CACnC,EACF;CACA,KAAK;AACP,CAAC"}
@@ -0,0 +1 @@
1
+ export { swiplet } from "./swiplet.js";
@@ -0,0 +1,21 @@
1
+ import { tr } from "../../../i18n.js";
2
+ import { defineCommand } from "../../command.js";
3
+ import { deploy, printDeployed } from "../../deploy.js";
4
+ import { session } from "../../session.js";
5
+ import fs from "node:fs";
6
+ // src/cli/commands/swiplet/install.ts
7
+ async function installArchive(context) {
8
+ const [archive] = context.args;
9
+ if (!fs.existsSync(archive)) throw new Error(tr("there is no archive at {path}", { path: archive }));
10
+ await session(context, async (client) => printDeployed(await deploy(client, archive, context.signal), true));
11
+ }
12
+ const install = defineCommand({
13
+ name: "install",
14
+ use: "install ARCHIVE",
15
+ short: tr("Install a swiplet archive"),
16
+ args: [1, 1],
17
+ run: installArchive
18
+ });
19
+ export { install };
20
+
21
+ //# sourceMappingURL=install.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install.js","names":[],"sources":["../../../../src/cli/commands/swiplet/install.ts"],"sourcesContent":["import fs from \"node:fs\";\n\nimport { tr } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\nimport { deploy, printDeployed } from \"../../deploy\";\nimport { session } from \"../../session\";\n\nasync function installArchive(context) {\n const [archive] = context.args;\n if (!fs.existsSync(archive)) {\n throw new Error(tr(\"there is no archive at {path}\", { path: archive }));\n }\n await session(context, async (client) =>\n printDeployed(await deploy(client, archive, context.signal), true),\n );\n}\n\nexport const install = defineCommand({\n name: \"install\",\n use: \"install ARCHIVE\",\n short: tr(\"Install a swiplet archive\"),\n args: [1, 1],\n run: installArchive,\n});\n"],"mappings":";;;;;;AAOA,eAAe,eAAe,SAAS;CACrC,MAAM,CAAC,WAAW,QAAQ;CAC1B,IAAI,CAAC,GAAG,WAAW,OAAO,GACxB,MAAM,IAAI,MAAM,GAAG,iCAAiC,EAAE,MAAM,QAAQ,CAAC,CAAC;CAExE,MAAM,QAAQ,SAAS,OAAO,WAC5B,cAAc,MAAM,OAAO,QAAQ,SAAS,QAAQ,MAAM,GAAG,IAAI,CACnE;AACF;AAEA,MAAa,UAAU,cAAc;CACnC,MAAM;CACN,KAAK;CACL,OAAO,GAAG,2BAA2B;CACrC,MAAM,CAAC,GAAG,CAAC;CACX,KAAK;AACP,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { tr } from "../../../i18n.js";
2
+ import { columns, serviceEnabledText, serviceStatusText } from "../../../output.js";
3
+ import { defineCommand } from "../../command.js";
4
+ import { session } from "../../session.js";
5
+ // src/cli/commands/swiplet/list.ts
6
+ const listSwiplets = (context) => session(context, async (client) => {
7
+ const { swiplets } = await client.swiplets.listSwiplets({}, { signal: context.signal });
8
+ const rows = swiplets.map((swiplet) => {
9
+ let service = "";
10
+ let status = "";
11
+ if (swiplet.service) {
12
+ service = serviceEnabledText(swiplet.service.enabled);
13
+ status = serviceStatusText(swiplet.service.status);
14
+ if (swiplet.service.error) status += `: ${swiplet.service.error.name}: ${swiplet.service.error.message}`;
15
+ }
16
+ return [
17
+ swiplet.id,
18
+ swiplet.title,
19
+ swiplet.version,
20
+ swiplet.actions.map((action) => action.name).join(","),
21
+ service,
22
+ status
23
+ ];
24
+ });
25
+ console.log(columns([[
26
+ tr("ID"),
27
+ tr("TITLE"),
28
+ tr("VERSION"),
29
+ tr("ACTIONS"),
30
+ tr("SERVICE"),
31
+ tr("STATUS")
32
+ ], ...rows]));
33
+ });
34
+ const list = defineCommand({
35
+ name: "list",
36
+ short: tr("List the swiplets"),
37
+ args: [0, 0],
38
+ run: listSwiplets
39
+ });
40
+ export { list };
41
+
42
+ //# sourceMappingURL=list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.js","names":[],"sources":["../../../../src/cli/commands/swiplet/list.ts"],"sourcesContent":["import { tr } from \"../../../i18n\";\nimport {\n columns,\n serviceEnabledText,\n serviceStatusText,\n} from \"../../../output\";\nimport { defineCommand } from \"../../command\";\nimport { session } from \"../../session\";\n\nconst listSwiplets = (context) =>\n session(context, async (client) => {\n const { swiplets } = await client.swiplets.listSwiplets(\n {},\n { signal: context.signal },\n );\n const rows = swiplets.map((swiplet) => {\n let service = \"\";\n let status = \"\";\n if (swiplet.service) {\n service = serviceEnabledText(swiplet.service.enabled);\n status = serviceStatusText(swiplet.service.status);\n if (swiplet.service.error) {\n status += `: ${swiplet.service.error.name}: ${swiplet.service.error.message}`;\n }\n }\n return [\n swiplet.id,\n swiplet.title,\n swiplet.version,\n swiplet.actions.map((action) => action.name).join(\",\"),\n service,\n status,\n ];\n });\n console.log(\n columns([\n [\n tr(\"ID\"),\n tr(\"TITLE\"),\n tr(\"VERSION\"),\n tr(\"ACTIONS\"),\n tr(\"SERVICE\"),\n tr(\"STATUS\"),\n ],\n ...rows,\n ]),\n );\n });\n\nexport const list = defineCommand({\n name: \"list\",\n short: tr(\"List the swiplets\"),\n args: [0, 0],\n run: listSwiplets,\n});\n"],"mappings":";;;;;AASA,MAAM,gBAAgB,YACpB,QAAQ,SAAS,OAAO,WAAW;CACjC,MAAM,EAAE,aAAa,MAAM,OAAO,SAAS,aACzC,CAAC,GACD,EAAE,QAAQ,QAAQ,OAAO,CAC3B;CACA,MAAM,OAAO,SAAS,KAAK,YAAY;EACrC,IAAI,UAAU;EACd,IAAI,SAAS;EACb,IAAI,QAAQ,SAAS;GACnB,UAAU,mBAAmB,QAAQ,QAAQ,OAAO;GACpD,SAAS,kBAAkB,QAAQ,QAAQ,MAAM;GACjD,IAAI,QAAQ,QAAQ,OAClB,UAAU,KAAK,QAAQ,QAAQ,MAAM,KAAK,IAAI,QAAQ,QAAQ,MAAM;EAExE;EACA,OAAO;GACL,QAAQ;GACR,QAAQ;GACR,QAAQ;GACR,QAAQ,QAAQ,KAAK,WAAW,OAAO,IAAI,CAAC,CAAC,KAAK,GAAG;GACrD;GACA;EACF;CACF,CAAC;CACD,QAAQ,IACN,QAAQ,CACN;EACE,GAAG,IAAI;EACP,GAAG,OAAO;EACV,GAAG,SAAS;EACZ,GAAG,SAAS;EACZ,GAAG,SAAS;EACZ,GAAG,QAAQ;CACb,GACA,GAAG,IACL,CAAC,CACH;AACF,CAAC;AAEH,MAAa,OAAO,cAAc;CAChC,MAAM;CACN,OAAO,GAAG,mBAAmB;CAC7B,MAAM,CAAC,GAAG,CAAC;CACX,KAAK;AACP,CAAC"}