@swipt/cli 0.1.0-nightly.97 → 0.1.0-nightly.99

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 (247) hide show
  1. package/dist/availability.d.ts +3 -1
  2. package/dist/availability.js +173 -151
  3. package/dist/availability.js.map +1 -1
  4. package/dist/cli/cli.js +52 -66
  5. package/dist/cli/cli.js.map +1 -1
  6. package/dist/cli/command.d.ts +9 -0
  7. package/dist/cli/command.js.map +1 -1
  8. package/dist/cli/commands/data/clear.js +2 -2
  9. package/dist/cli/commands/data/clear.js.map +1 -1
  10. package/dist/cli/commands/data/data.js +2 -2
  11. package/dist/cli/commands/data/data.js.map +1 -1
  12. package/dist/cli/commands/data/list.js +3 -3
  13. package/dist/cli/commands/data/list.js.map +1 -1
  14. package/dist/cli/commands/data/operand.js.map +1 -1
  15. package/dist/cli/commands/data/read.js +4 -7
  16. package/dist/cli/commands/data/read.js.map +1 -1
  17. package/dist/cli/commands/data/remove.js +3 -3
  18. package/dist/cli/commands/data/remove.js.map +1 -1
  19. package/dist/cli/commands/data/write.js +2 -2
  20. package/dist/cli/commands/data/write.js.map +1 -1
  21. package/dist/cli/commands/device/add.js +2 -2
  22. package/dist/cli/commands/device/add.js.map +1 -1
  23. package/dist/cli/commands/device/device.js +2 -2
  24. package/dist/cli/commands/device/device.js.map +1 -1
  25. package/dist/cli/commands/device/list.js +2 -2
  26. package/dist/cli/commands/device/list.js.map +1 -1
  27. package/dist/cli/commands/device/logs.js +44 -46
  28. package/dist/cli/commands/device/logs.js.map +1 -1
  29. package/dist/cli/commands/device/remove.js +2 -2
  30. package/dist/cli/commands/device/remove.js.map +1 -1
  31. package/dist/cli/commands/device/stop.js +3 -3
  32. package/dist/cli/commands/device/stop.js.map +1 -1
  33. package/dist/cli/commands/driver/driver.js +6 -6
  34. package/dist/cli/commands/driver/driver.js.map +1 -1
  35. package/dist/cli/commands/flags.js +9 -9
  36. package/dist/cli/commands/flags.js.map +1 -1
  37. package/dist/cli/commands/index.js +2 -2
  38. package/dist/cli/commands/index.js.map +1 -1
  39. package/dist/cli/commands/project/build.js +2 -2
  40. package/dist/cli/commands/project/build.js.map +1 -1
  41. package/dist/cli/commands/project/create.js +3 -3
  42. package/dist/cli/commands/project/create.js.map +1 -1
  43. package/dist/cli/commands/project/deploy.js +2 -2
  44. package/dist/cli/commands/project/deploy.js.map +1 -1
  45. package/dist/cli/commands/project/develop.js +19 -19
  46. package/dist/cli/commands/project/develop.js.map +1 -1
  47. package/dist/cli/commands/project/project.js +2 -2
  48. package/dist/cli/commands/project/project.js.map +1 -1
  49. package/dist/cli/commands/project/source.js +62 -37
  50. package/dist/cli/commands/project/source.js.map +1 -1
  51. package/dist/cli/commands/repl/api.js +2 -2
  52. package/dist/cli/commands/repl/api.js.map +1 -1
  53. package/dist/cli/commands/repl/repl.js +4 -4
  54. package/dist/cli/commands/repl/repl.js.map +1 -1
  55. package/dist/cli/commands/repl/reset.js +2 -2
  56. package/dist/cli/commands/repl/reset.js.map +1 -1
  57. package/dist/cli/commands/repl/run.js +5 -5
  58. package/dist/cli/commands/repl/run.js.map +1 -1
  59. package/dist/cli/commands/sideload/install.js +4 -4
  60. package/dist/cli/commands/sideload/install.js.map +1 -1
  61. package/dist/cli/commands/sideload/setup.js +3 -3
  62. package/dist/cli/commands/sideload/setup.js.map +1 -1
  63. package/dist/cli/commands/sideload/sideload.js +2 -2
  64. package/dist/cli/commands/sideload/sideload.js.map +1 -1
  65. package/dist/cli/commands/sideload/uninstall.js +2 -2
  66. package/dist/cli/commands/sideload/uninstall.js.map +1 -1
  67. package/dist/cli/commands/sideload/update.js +3 -3
  68. package/dist/cli/commands/sideload/update.js.map +1 -1
  69. package/dist/cli/commands/swiplet/call.js +6 -6
  70. package/dist/cli/commands/swiplet/call.js.map +1 -1
  71. package/dist/cli/commands/swiplet/install.js +3 -3
  72. package/dist/cli/commands/swiplet/install.js.map +1 -1
  73. package/dist/cli/commands/swiplet/list.js +8 -8
  74. package/dist/cli/commands/swiplet/list.js.map +1 -1
  75. package/dist/cli/commands/swiplet/remove.js +3 -3
  76. package/dist/cli/commands/swiplet/remove.js.map +1 -1
  77. package/dist/cli/commands/swiplet/service/disable.js +3 -3
  78. package/dist/cli/commands/swiplet/service/disable.js.map +1 -1
  79. package/dist/cli/commands/swiplet/service/enable.js +3 -3
  80. package/dist/cli/commands/swiplet/service/enable.js.map +1 -1
  81. package/dist/cli/commands/swiplet/service/service.js +2 -2
  82. package/dist/cli/commands/swiplet/service/service.js.map +1 -1
  83. package/dist/cli/commands/swiplet/service/services.js +2 -2
  84. package/dist/cli/commands/swiplet/service/services.js.map +1 -1
  85. package/dist/cli/commands/swiplet/service/watch.js +2 -2
  86. package/dist/cli/commands/swiplet/service/watch.js.map +1 -1
  87. package/dist/cli/commands/swiplet/show.js +6 -6
  88. package/dist/cli/commands/swiplet/show.js.map +1 -1
  89. package/dist/cli/commands/swiplet/swiplet.js +4 -4
  90. package/dist/cli/commands/swiplet/swiplet.js.map +1 -1
  91. package/dist/cli/commands/version/version.js +2 -2
  92. package/dist/cli/commands/version/version.js.map +1 -1
  93. package/dist/cli/deploy.js +9 -7
  94. package/dist/cli/deploy.js.map +1 -1
  95. package/dist/cli/session.js.map +1 -1
  96. package/dist/client.d.ts +145 -7
  97. package/dist/client.js +20 -22
  98. package/dist/client.js.map +1 -1
  99. package/dist/connection.d.ts +292 -25
  100. package/dist/connection.js +36 -35
  101. package/dist/connection.js.map +1 -1
  102. package/dist/driver.d.ts +62 -23
  103. package/dist/driver.js +29 -33
  104. package/dist/driver.js.map +1 -1
  105. package/dist/i18n.d.ts +2 -5
  106. package/dist/i18n.js +15 -13
  107. package/dist/i18n.js.map +1 -1
  108. package/dist/i18next.d.ts +7 -0
  109. package/dist/ignore.d.ts +14 -7
  110. package/dist/ignore.js +13 -14
  111. package/dist/ignore.js.map +1 -1
  112. package/dist/mdns.d.ts +2 -2
  113. package/dist/mdns.js +1 -1
  114. package/dist/mdns.js.map +1 -1
  115. package/dist/metro.d.ts +19 -5
  116. package/dist/metro.js +61 -63
  117. package/dist/metro.js.map +1 -1
  118. package/dist/output.d.ts +29 -14
  119. package/dist/output.js +17 -15
  120. package/dist/output.js.map +1 -1
  121. package/dist/passcode.d.ts +12 -8
  122. package/dist/passcode.js +18 -18
  123. package/dist/passcode.js.map +1 -1
  124. package/dist/project.d.ts +20 -10
  125. package/dist/project.js +72 -49
  126. package/dist/project.js.map +1 -1
  127. package/dist/proto/common_pb.d.ts +240 -0
  128. package/dist/proto/common_pb.js +7 -2
  129. package/dist/proto/common_pb.js.map +1 -1
  130. package/dist/proto/logs_pb.d.ts +38 -0
  131. package/dist/proto/repl_pb.d.ts +96 -0
  132. package/dist/proto/swiplets_pb.d.ts +361 -0
  133. package/dist/proto/swiplets_pb.js +7 -2
  134. package/dist/proto/swiplets_pb.js.map +1 -1
  135. package/dist/proto/system_pb.d.ts +33 -0
  136. package/dist/resources.d.ts +400 -0
  137. package/dist/serve.d.ts +9 -1
  138. package/dist/serve.js +17 -16
  139. package/dist/serve.js.map +1 -1
  140. package/dist/sideload.d.ts +27 -14
  141. package/dist/sideload.js +102 -89
  142. package/dist/sideload.js.map +1 -1
  143. package/dist/swipt-app.d.ts +19 -9
  144. package/dist/swipt-app.js +1 -1
  145. package/dist/swipt-app.js.map +1 -1
  146. package/locales/ar/translation.json +413 -0
  147. package/locales/bg/translation.json +397 -0
  148. package/locales/bn/translation.json +397 -0
  149. package/locales/ca/translation.json +401 -0
  150. package/locales/cs/translation.json +405 -0
  151. package/locales/da/translation.json +397 -0
  152. package/locales/de/translation.json +397 -0
  153. package/locales/el/translation.json +397 -0
  154. package/locales/en/translation.json +397 -0
  155. package/locales/es/translation.json +401 -0
  156. package/locales/es-419/translation.json +401 -0
  157. package/locales/fi/translation.json +397 -0
  158. package/locales/fr/translation.json +401 -0
  159. package/locales/fr-CA/translation.json +401 -0
  160. package/locales/gu/translation.json +397 -0
  161. package/locales/he/translation.json +401 -0
  162. package/locales/hi/translation.json +397 -0
  163. package/locales/hr/translation.json +401 -0
  164. package/locales/hu/translation.json +397 -0
  165. package/locales/id/translation.json +393 -0
  166. package/locales/it/translation.json +401 -0
  167. package/locales/ja/translation.json +393 -0
  168. package/locales/kk/translation.json +397 -0
  169. package/locales/kn/translation.json +397 -0
  170. package/locales/ko/translation.json +393 -0
  171. package/locales/lt/translation.json +405 -0
  172. package/locales/ml/translation.json +397 -0
  173. package/locales/mr/translation.json +397 -0
  174. package/locales/ms/translation.json +393 -0
  175. package/locales/nb/translation.json +397 -0
  176. package/locales/nl/translation.json +397 -0
  177. package/locales/or/translation.json +397 -0
  178. package/locales/pa/translation.json +397 -0
  179. package/locales/pl/translation.json +405 -0
  180. package/locales/pt-BR/translation.json +401 -0
  181. package/locales/pt-PT/translation.json +401 -0
  182. package/locales/ro/translation.json +401 -0
  183. package/locales/ru/translation.json +405 -0
  184. package/locales/sk/translation.json +405 -0
  185. package/locales/sl/translation.json +405 -0
  186. package/locales/sv/translation.json +397 -0
  187. package/locales/ta/translation.json +397 -0
  188. package/locales/te/translation.json +397 -0
  189. package/locales/th/translation.json +393 -0
  190. package/locales/tr/translation.json +397 -0
  191. package/locales/uk/translation.json +405 -0
  192. package/locales/ur/translation.json +397 -0
  193. package/locales/vi/translation.json +397 -0
  194. package/locales/zh-HK/translation.json +393 -0
  195. package/locales/zh-Hans/translation.json +393 -0
  196. package/locales/zh-Hant/translation.json +393 -0
  197. package/package.json +14 -9
  198. package/locales/ar.json +0 -311
  199. package/locales/bg.json +0 -295
  200. package/locales/bn.json +0 -295
  201. package/locales/ca.json +0 -299
  202. package/locales/cs.json +0 -303
  203. package/locales/da.json +0 -295
  204. package/locales/de.json +0 -295
  205. package/locales/el.json +0 -295
  206. package/locales/es-419.json +0 -299
  207. package/locales/es.json +0 -299
  208. package/locales/fi.json +0 -295
  209. package/locales/fr-CA.json +0 -299
  210. package/locales/fr.json +0 -299
  211. package/locales/gu.json +0 -295
  212. package/locales/he.json +0 -299
  213. package/locales/hi.json +0 -295
  214. package/locales/hr.json +0 -299
  215. package/locales/hu.json +0 -295
  216. package/locales/id.json +0 -283
  217. package/locales/it.json +0 -299
  218. package/locales/ja.json +0 -283
  219. package/locales/kk.json +0 -295
  220. package/locales/kn.json +0 -295
  221. package/locales/ko.json +0 -283
  222. package/locales/lt.json +0 -303
  223. package/locales/ml.json +0 -295
  224. package/locales/mr.json +0 -295
  225. package/locales/ms.json +0 -283
  226. package/locales/nb.json +0 -295
  227. package/locales/nl.json +0 -295
  228. package/locales/or.json +0 -295
  229. package/locales/pa.json +0 -295
  230. package/locales/pl.json +0 -303
  231. package/locales/pt-BR.json +0 -299
  232. package/locales/pt-PT.json +0 -299
  233. package/locales/ro.json +0 -299
  234. package/locales/ru.json +0 -303
  235. package/locales/sk.json +0 -303
  236. package/locales/sl.json +0 -303
  237. package/locales/sv.json +0 -295
  238. package/locales/ta.json +0 -295
  239. package/locales/te.json +0 -295
  240. package/locales/th.json +0 -283
  241. package/locales/tr.json +0 -295
  242. package/locales/uk.json +0 -303
  243. package/locales/ur.json +0 -295
  244. package/locales/vi.json +0 -295
  245. package/locales/zh-HK.json +0 -283
  246. package/locales/zh-Hans.json +0 -283
  247. package/locales/zh-Hant.json +0 -283
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","names":[],"sources":["../../../../src/cli/commands/project/build.ts"],"sourcesContent":["import path from \"node:path\";\n\nimport { tr } from \"../../../i18n\";\nimport { buildProject } from \"../../../project\";\nimport { defineCommand } from \"../../command\";\n\nexport const build = defineCommand({\n name: \"build\",\n use: \"build [PROJECT]\",\n short: tr(\"Bundle the project into dist/<swiplet.id>.swiplet\"),\n args: [0, 1],\n run: async ({ args }) => {\n const { archive } = await buildProject(path.resolve(args[0] ?? \".\"));\n console.log(path.relative(process.cwd(), archive));\n },\n});\n"],"mappings":";;;;;AAMA,MAAa,QAAQ,cAAc;CACjC,MAAM;CACN,KAAK;CACL,OAAO,GAAG,mDAAmD;CAC7D,MAAM,CAAC,GAAG,CAAC;CACX,KAAK,OAAO,EAAE,WAAW;EACvB,MAAM,EAAE,YAAY,MAAM,aAAa,KAAK,QAAQ,KAAK,MAAM,GAAG,CAAC;EACnE,QAAQ,IAAI,KAAK,SAAS,QAAQ,IAAI,GAAG,OAAO,CAAC;CACnD;AACF,CAAC"}
1
+ {"version":3,"file":"build.js","names":[],"sources":["../../../../src/cli/commands/project/build.ts"],"sourcesContent":["import path from \"node:path\";\n\nimport { t } from \"../../../i18n\";\nimport { buildProject } from \"../../../project\";\nimport { defineCommand } from \"../../command\";\n\nexport const build = defineCommand({\n name: \"build\",\n use: \"build [PROJECT]\",\n short: t(\"commands.project.build.description\"),\n args: [0, 1],\n run: async ({ args }) => {\n const { archive } = await buildProject(path.resolve(args[0] ?? \".\"));\n console.log(path.relative(process.cwd(), archive));\n },\n});\n"],"mappings":";;;;;AAMA,MAAa,QAAQ,cAAc;CACjC,MAAM;CACN,KAAK;CACL,OAAO,EAAE,oCAAoC;CAC7C,MAAM,CAAC,GAAG,CAAC;CACX,KAAK,OAAO,EAAE,WAAW;EACvB,MAAM,EAAE,YAAY,MAAM,aAAa,KAAK,QAAQ,KAAK,MAAM,GAAG,CAAC;EACnE,QAAQ,IAAI,KAAK,SAAS,QAAQ,IAAI,GAAG,OAAO,CAAC;CACnD;AACF,CAAC"}
@@ -1,4 +1,4 @@
1
- import { tr } from "../../../i18n.js";
1
+ import { t } from "../../../i18n.js";
2
2
  import { defineCommand } from "../../command.js";
3
3
  import { createRequire } from "node:module";
4
4
  import fs from "node:fs";
@@ -89,7 +89,7 @@ export default function App() {
89
89
  const quote = (value) => process.platform === "win32" ? /^[\w.:\\/-]+$/.test(value) ? value : `"${value}"` : /^[\w@%+=:,./-]+$/.test(value) ? value : `'${value.replaceAll("'", "'\\''")}'`;
90
90
  function createCommand(directory) {
91
91
  const root = path.resolve(directory);
92
- if (fs.existsSync(root) && fs.readdirSync(root).length > 0) throw new Error(tr("{directory} isn't empty.", { directory }));
92
+ if (fs.existsSync(root) && fs.readdirSync(root).length > 0) throw new Error(t("commands.project.create.notEmpty", { directory }));
93
93
  for (const [file, template] of Object.entries(templates)) {
94
94
  fs.mkdirSync(path.dirname(path.join(root, file)), { recursive: true });
95
95
  fs.writeFileSync(path.join(root, file), template(path.basename(root)));
@@ -100,7 +100,7 @@ function createCommand(directory) {
100
100
  const create = defineCommand({
101
101
  name: "create",
102
102
  use: "create DIRECTORY",
103
- short: tr("Make a swiplet project in a new or empty directory"),
103
+ short: t("commands.project.create.description"),
104
104
  args: [1, 1],
105
105
  run: ({ args }) => createCommand(args[0])
106
106
  });
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","names":[],"sources":["../../../../src/cli/commands/project/create.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\n\nimport { tr } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\n\nconst { version } = JSON.parse(\n fs.readFileSync(new URL(\"../../../../package.json\", import.meta.url), \"utf8\"),\n);\nconst require = createRequire(import.meta.url);\nconst { peerDependencies } = require(\"@swipt/api/package.json\");\n\nconst swiptRange = version.includes(\"-\")\n ? version\n : `>=${version}-0 <=${version}`;\n\nconst idOf = (name) =>\n name\n .toLowerCase()\n .replace(/[^a-z0-9._-]+/g, \"-\")\n .replace(/^[._-]+/, \"\")\n .slice(0, 128)\n .replace(/[._-]+$/, \"\") || \"swiplet\";\n\nconst templates = {\n \"package.json\": (name) =>\n `${JSON.stringify(\n {\n name: idOf(name),\n version: \"0.1.0\",\n private: true,\n swiplet: {\n id: idOf(name),\n name,\n versionCode: 1,\n icon: { color: \"blue\", symbol: \"sparkles\" },\n app: \"./src/App.tsx\",\n extension: \"./src/extension.ts\",\n },\n scripts: { build: \"swipt project build\", check: \"tsc\" },\n dependencies: { zod: \"^4.6.7\" },\n devDependencies: {\n \"@swipt/api\": swiptRange,\n \"@swipt/cli\": swiptRange,\n typescript: \"^7.0.2\",\n ...Object.fromEntries(\n [\"@expo/ui\", \"@types/react\", \"react\"].map((name) => [\n name,\n peerDependencies[name],\n ]),\n ),\n },\n },\n null,\n 2,\n )}\\n`,\n \"tsconfig.json\": () =>\n `${JSON.stringify(\n {\n compilerOptions: {\n target: \"ES2022\",\n module: \"ESNext\",\n moduleResolution: \"Bundler\",\n jsx: \"react-jsx\",\n lib: [\"ES2023\", \"DOM\"],\n strict: true,\n noEmit: true,\n skipLibCheck: true,\n },\n },\n null,\n 2,\n )}\\n`,\n \".gitignore\": () => \"node_modules/\\ndist/\\n\",\n \"src/extension.ts\": () => `import * as device from \"@swipt/api/device\";\nimport { defineAction, defineExtension } from \"@swipt/api/swiplet\";\n\nexport default defineExtension({\n actions: {\n frontApp: defineAction({\n title: \"Find the App in Front\",\n run: (_, { signal }) => device.foregroundApplication.get({ signal }),\n }),\n },\n});\n`,\n \"src/App.tsx\":\n () => `import { Button, Form, Host, Section, Text } from \"@expo/ui/swift-ui\";\nimport { useState } from \"react\";\nimport { actions } from \"@swipt/api/swiplet\";\n\nimport type extension from \"./extension\";\n\nconst { frontApp } = actions<typeof extension>();\n\nexport default function App() {\n const [app, setApp] = useState(\"\");\n return (\n <Host style={{ flex: 1 }}>\n <Form>\n <Section>\n <Button label=\"Find the App in Front\" onPress={async () => setApp(await frontApp())} />\n {app === \"\" ? null : <Text>{app}</Text>}\n </Section>\n </Form>\n </Host>\n );\n}\n`,\n};\n\nconst quote = (value) =>\n process.platform === \"win32\"\n ? /^[\\w.:\\\\/-]+$/.test(value)\n ? value\n : `\"${value}\"`\n : /^[\\w@%+=:,./-]+$/.test(value)\n ? value\n : `'${value.replaceAll(\"'\", \"'\\\\''\")}'`;\n\nfunction createCommand(directory) {\n const root = path.resolve(directory);\n if (fs.existsSync(root) && fs.readdirSync(root).length > 0) {\n throw new Error(tr(\"{directory} isn't empty.\", { directory }));\n }\n for (const [file, template] of Object.entries(templates)) {\n fs.mkdirSync(path.dirname(path.join(root, file)), { recursive: true });\n fs.writeFileSync(path.join(root, file), template(path.basename(root)));\n }\n const manager = process.env.npm_config_user_agent?.split(\"/\")[0] ?? \"npm\";\n console.log(\n `cd ${quote(directory)}\\n${manager} install\\n${manager} run build`,\n );\n}\n\nexport const create = defineCommand({\n name: \"create\",\n use: \"create DIRECTORY\",\n short: tr(\"Make a swiplet project in a new or empty directory\"),\n args: [1, 1],\n run: ({ args }) => createCommand(args[0]),\n});\n"],"mappings":";;;;;;AAOA,MAAM,EAAE,YAAY,KAAK,MACvB,GAAG,aAAa,IAAI,IAAI,4BAA4B,YAAY,GAAG,GAAG,MAAM,CAC9E;AAEA,MAAM,EAAE,qBADQ,cAAc,YAAY,GACP,CAAC,CAAC,yBAAyB;AAE9D,MAAM,aAAa,QAAQ,SAAS,GAAG,IACnC,UACA,KAAK,QAAQ,OAAO;AAExB,MAAM,QAAQ,SACZ,KACG,YAAY,CAAC,CACb,QAAQ,kBAAkB,GAAG,CAAC,CAC9B,QAAQ,WAAW,EAAE,CAAC,CACtB,MAAM,GAAG,GAAG,CAAC,CACb,QAAQ,WAAW,EAAE,KAAK;AAE/B,MAAM,YAAY;CAChB,iBAAiB,SACf,GAAG,KAAK,UACN;EACE,MAAM,KAAK,IAAI;EACf,SAAS;EACT,SAAS;EACT,SAAS;GACP,IAAI,KAAK,IAAI;GACb;GACA,aAAa;GACb,MAAM;IAAE,OAAO;IAAQ,QAAQ;GAAW;GAC1C,KAAK;GACL,WAAW;EACb;EACA,SAAS;GAAE,OAAO;GAAuB,OAAO;EAAM;EACtD,cAAc,EAAE,KAAK,SAAS;EAC9B,iBAAiB;GACf,cAAc;GACd,cAAc;GACd,YAAY;GACZ,GAAG,OAAO,YACR;IAAC;IAAY;IAAgB;GAAO,CAAC,CAAC,KAAK,SAAS,CAClD,MACA,iBAAiB,KACnB,CAAC,CACH;EACF;CACF,GACA,MACA,CACF,EAAE;CACJ,uBACE,GAAG,KAAK,UACN,EACE,iBAAiB;EACf,QAAQ;EACR,QAAQ;EACR,kBAAkB;EAClB,KAAK;EACL,KAAK,CAAC,UAAU,KAAK;EACrB,QAAQ;EACR,QAAQ;EACR,cAAc;CAChB,EACF,GACA,MACA,CACF,EAAE;CACJ,oBAAoB;CACpB,0BAA0B;;;;;;;;;;;;CAY1B,qBACQ;;;;;;;;;;;;;;;;;;;;;;AAsBV;AAEA,MAAM,SAAS,UACb,QAAQ,aAAa,UACjB,gBAAgB,KAAK,KAAK,IACxB,QACA,IAAI,MAAM,KACZ,mBAAmB,KAAK,KAAK,IAC3B,QACA,IAAI,MAAM,WAAW,KAAK,OAAO,EAAE;AAE3C,SAAS,cAAc,WAAW;CAChC,MAAM,OAAO,KAAK,QAAQ,SAAS;CACnC,IAAI,GAAG,WAAW,IAAI,KAAK,GAAG,YAAY,IAAI,CAAC,CAAC,SAAS,GACvD,MAAM,IAAI,MAAM,GAAG,4BAA4B,EAAE,UAAU,CAAC,CAAC;CAE/D,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,SAAS,GAAG;EACxD,GAAG,UAAU,KAAK,QAAQ,KAAK,KAAK,MAAM,IAAI,CAAC,GAAG,EAAE,WAAW,KAAK,CAAC;EACrE,GAAG,cAAc,KAAK,KAAK,MAAM,IAAI,GAAG,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC;CACvE;CACA,MAAM,UAAU,QAAQ,IAAI,uBAAuB,MAAM,GAAG,CAAC,CAAC,MAAM;CACpE,QAAQ,IACN,MAAM,MAAM,SAAS,EAAE,IAAI,QAAQ,YAAY,QAAQ,WACzD;AACF;AAEA,MAAa,SAAS,cAAc;CAClC,MAAM;CACN,KAAK;CACL,OAAO,GAAG,oDAAoD;CAC9D,MAAM,CAAC,GAAG,CAAC;CACX,MAAM,EAAE,WAAW,cAAc,KAAK,EAAE;AAC1C,CAAC"}
1
+ {"version":3,"file":"create.js","names":[],"sources":["../../../../src/cli/commands/project/create.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\n\nimport { t } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\n\nconst { version }: { version: string } = JSON.parse(\n fs.readFileSync(new URL(\"../../../../package.json\", import.meta.url), \"utf8\"),\n);\nconst require = createRequire(import.meta.url);\nconst {\n peerDependencies,\n}: {\n peerDependencies: Partial<Record<string, string>>;\n} = require(\"@swipt/api/package.json\");\n\nconst swiptRange = version.includes(\"-\")\n ? version\n : `>=${version}-0 <=${version}`;\n\nconst idOf = (name: string) =>\n name\n .toLowerCase()\n .replace(/[^a-z0-9._-]+/g, \"-\")\n .replace(/^[._-]+/, \"\")\n .slice(0, 128)\n .replace(/[._-]+$/, \"\") || \"swiplet\";\n\nconst templates = {\n \"package.json\": (name: string) =>\n `${JSON.stringify(\n {\n name: idOf(name),\n version: \"0.1.0\",\n private: true,\n swiplet: {\n id: idOf(name),\n name,\n versionCode: 1,\n icon: { color: \"blue\", symbol: \"sparkles\" },\n app: \"./src/App.tsx\",\n extension: \"./src/extension.ts\",\n },\n scripts: { build: \"swipt project build\", check: \"tsc\" },\n dependencies: { zod: \"^4.6.7\" },\n devDependencies: {\n \"@swipt/api\": swiptRange,\n \"@swipt/cli\": swiptRange,\n typescript: \"^7.0.2\",\n ...Object.fromEntries(\n [\"@expo/ui\", \"@types/react\", \"react\"].map((name) => [\n name,\n peerDependencies[name],\n ]),\n ),\n },\n },\n null,\n 2,\n )}\\n`,\n \"tsconfig.json\": () =>\n `${JSON.stringify(\n {\n compilerOptions: {\n target: \"ES2022\",\n module: \"ESNext\",\n moduleResolution: \"Bundler\",\n jsx: \"react-jsx\",\n lib: [\"ES2023\", \"DOM\"],\n strict: true,\n noEmit: true,\n skipLibCheck: true,\n },\n },\n null,\n 2,\n )}\\n`,\n \".gitignore\": () => \"node_modules/\\ndist/\\n\",\n \"src/extension.ts\": () => `import * as device from \"@swipt/api/device\";\nimport { defineAction, defineExtension } from \"@swipt/api/swiplet\";\n\nexport default defineExtension({\n actions: {\n frontApp: defineAction({\n title: \"Find the App in Front\",\n run: (_, { signal }) => device.foregroundApplication.get({ signal }),\n }),\n },\n});\n`,\n \"src/App.tsx\":\n () => `import { Button, Form, Host, Section, Text } from \"@expo/ui/swift-ui\";\nimport { useState } from \"react\";\nimport { actions } from \"@swipt/api/swiplet\";\n\nimport type extension from \"./extension\";\n\nconst { frontApp } = actions<typeof extension>();\n\nexport default function App() {\n const [app, setApp] = useState(\"\");\n return (\n <Host style={{ flex: 1 }}>\n <Form>\n <Section>\n <Button label=\"Find the App in Front\" onPress={async () => setApp(await frontApp())} />\n {app === \"\" ? null : <Text>{app}</Text>}\n </Section>\n </Form>\n </Host>\n );\n}\n`,\n};\n\nconst quote = (value: string) =>\n process.platform === \"win32\"\n ? /^[\\w.:\\\\/-]+$/.test(value)\n ? value\n : `\"${value}\"`\n : /^[\\w@%+=:,./-]+$/.test(value)\n ? value\n : `'${value.replaceAll(\"'\", \"'\\\\''\")}'`;\n\nfunction createCommand(directory: string) {\n const root = path.resolve(directory);\n if (fs.existsSync(root) && fs.readdirSync(root).length > 0) {\n throw new Error(t(\"commands.project.create.notEmpty\", { directory }));\n }\n for (const [file, template] of Object.entries(templates)) {\n fs.mkdirSync(path.dirname(path.join(root, file)), { recursive: true });\n fs.writeFileSync(path.join(root, file), template(path.basename(root)));\n }\n const manager = process.env.npm_config_user_agent?.split(\"/\")[0] ?? \"npm\";\n console.log(\n `cd ${quote(directory)}\\n${manager} install\\n${manager} run build`,\n );\n}\n\nexport const create = defineCommand({\n name: \"create\",\n use: \"create DIRECTORY\",\n short: t(\"commands.project.create.description\"),\n args: [1, 1],\n run: ({ args }) => createCommand(args[0]),\n});\n"],"mappings":";;;;;;AAOA,MAAM,EAAE,YAAiC,KAAK,MAC5C,GAAG,aAAa,IAAI,IAAI,4BAA4B,YAAY,GAAG,GAAG,MAAM,CAC9E;AAEA,MAAM,EACJ,qBAFc,cAAc,YAAY,GAKhC,CAAC,CAAC,yBAAyB;AAErC,MAAM,aAAa,QAAQ,SAAS,GAAG,IACnC,UACA,KAAK,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,GACvD,MAAM,IAAI,MAAM,EAAE,oCAAoC,EAAE,UAAU,CAAC,CAAC;CAEtE,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,SAAS,GAAG;EACxD,GAAG,UAAU,KAAK,QAAQ,KAAK,KAAK,MAAM,IAAI,CAAC,GAAG,EAAE,WAAW,KAAK,CAAC;EACrE,GAAG,cAAc,KAAK,KAAK,MAAM,IAAI,GAAG,SAAS,KAAK,SAAS,IAAI,CAAC,CAAC;CACvE;CACA,MAAM,UAAU,QAAQ,IAAI,uBAAuB,MAAM,GAAG,CAAC,CAAC,MAAM;CACpE,QAAQ,IACN,MAAM,MAAM,SAAS,EAAE,IAAI,QAAQ,YAAY,QAAQ,WACzD;AACF;AAEA,MAAa,SAAS,cAAc;CAClC,MAAM;CACN,KAAK;CACL,OAAO,EAAE,qCAAqC;CAC9C,MAAM,CAAC,GAAG,CAAC;CACX,MAAM,EAAE,WAAW,cAAc,KAAK,EAAE;AAC1C,CAAC"}
@@ -1,4 +1,4 @@
1
- import { tr } from "../../../i18n.js";
1
+ import { t } from "../../../i18n.js";
2
2
  import { buildProject } from "../../../project.js";
3
3
  import { defineCommand } from "../../command.js";
4
4
  import { deploy as deploy$1, printDeployed } from "../../deploy.js";
@@ -13,7 +13,7 @@ async function deployProject(context) {
13
13
  const deploy = defineCommand({
14
14
  name: "deploy",
15
15
  use: "deploy [PROJECT]",
16
- short: tr("Build the project and install it on the device"),
16
+ short: t("commands.project.deploy.description"),
17
17
  args: [0, 1],
18
18
  options: deviceOption,
19
19
  run: deployProject
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.js","names":["deploySwiplet"],"sources":["../../../../src/cli/commands/project/deploy.ts"],"sourcesContent":["import path from \"node:path\";\n\nimport { tr } from \"../../../i18n\";\nimport { buildProject } from \"../../../project\";\nimport { defineCommand } from \"../../command\";\nimport { deploy as deploySwiplet, printDeployed } from \"../../deploy\";\nimport { session } from \"../../session\";\nimport { deviceOption } from \"../flags\";\n\nasync function deployProject(context) {\n const { archive } = await buildProject(path.resolve(context.args[0] ?? \".\"));\n await session(context, async (client) =>\n printDeployed(await deploySwiplet(client, archive, context.signal), true),\n );\n}\n\nexport const deploy = defineCommand({\n name: \"deploy\",\n use: \"deploy [PROJECT]\",\n short: tr(\"Build the project and install it on the device\"),\n args: [0, 1],\n options: deviceOption,\n run: deployProject,\n});\n"],"mappings":";;;;;;;;AASA,eAAe,cAAc,SAAS;CACpC,MAAM,EAAE,YAAY,MAAM,aAAa,KAAK,QAAQ,QAAQ,KAAK,MAAM,GAAG,CAAC;CAC3E,MAAM,QAAQ,SAAS,OAAO,WAC5B,cAAc,MAAMA,SAAc,QAAQ,SAAS,QAAQ,MAAM,GAAG,IAAI,CAC1E;AACF;AAEA,MAAa,SAAS,cAAc;CAClC,MAAM;CACN,KAAK;CACL,OAAO,GAAG,gDAAgD;CAC1D,MAAM,CAAC,GAAG,CAAC;CACX,SAAS;CACT,KAAK;AACP,CAAC"}
1
+ {"version":3,"file":"deploy.js","names":["deploySwiplet"],"sources":["../../../../src/cli/commands/project/deploy.ts"],"sourcesContent":["import path from \"node:path\";\n\nimport { t } from \"../../../i18n\";\nimport { buildProject } from \"../../../project\";\nimport { type Context, defineCommand } from \"../../command\";\nimport { deploy as deploySwiplet, printDeployed } from \"../../deploy\";\nimport { session } from \"../../session\";\nimport { deviceOption } from \"../flags\";\n\nasync function deployProject(context: Context<{ device?: string }>) {\n const { archive } = await buildProject(path.resolve(context.args[0] ?? \".\"));\n await session(context, async (client) =>\n printDeployed(await deploySwiplet(client, archive, context.signal), true),\n );\n}\n\nexport const deploy = defineCommand({\n name: \"deploy\",\n use: \"deploy [PROJECT]\",\n short: t(\"commands.project.deploy.description\"),\n args: [0, 1],\n options: deviceOption,\n run: deployProject,\n});\n"],"mappings":";;;;;;;;AASA,eAAe,cAAc,SAAuC;CAClE,MAAM,EAAE,YAAY,MAAM,aAAa,KAAK,QAAQ,QAAQ,KAAK,MAAM,GAAG,CAAC;CAC3E,MAAM,QAAQ,SAAS,OAAO,WAC5B,cAAc,MAAMA,SAAc,QAAQ,SAAS,QAAQ,MAAM,GAAG,IAAI,CAC1E;AACF;AAEA,MAAa,SAAS,cAAc;CAClC,MAAM;CACN,KAAK;CACL,OAAO,EAAE,qCAAqC;CAC9C,MAAM,CAAC,GAAG,CAAC;CACX,SAAS;CACT,KAAK;AACP,CAAC"}
@@ -1,16 +1,18 @@
1
1
  import { AvailabilityChecker } from "../../../availability.js";
2
2
  import { unauthenticated } from "../../../client.js";
3
3
  import { attach } from "../../../connection.js";
4
- import { tr } from "../../../i18n.js";
4
+ import { t } from "../../../i18n.js";
5
5
  import { Ignorer, relativePath } from "../../../ignore.js";
6
- import { printLog, serviceText } from "../../../output.js";
6
+ import { errorMessage, printLog, serviceText } from "../../../output.js";
7
7
  import { buildProject, loadProject } from "../../../project.js";
8
+ import { LogEntrySchema } from "../../../proto/common_pb.js";
8
9
  import "../../../proto/swiplets_pb.js";
9
10
  import { defineCommand } from "../../command.js";
10
11
  import { deploy, printDeployed } from "../../deploy.js";
11
12
  import { deviceOption } from "../flags.js";
12
13
  import fs from "node:fs";
13
14
  import path from "node:path";
15
+ import { create } from "@bufbuild/protobuf";
14
16
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
15
17
  // src/cli/commands/project/develop.ts
16
18
  const rebuildDelay = 300;
@@ -32,9 +34,10 @@ async function follow(signal, fatal, run) {
32
34
  fatal(error);
33
35
  return;
34
36
  }
35
- if (!signal.aborted && error.message !== reported) {
36
- reported = error.message;
37
- console.error(tr("error: {message}", { message: error.message }));
37
+ const message = errorMessage(error);
38
+ if (!signal.aborted && message !== reported) {
39
+ reported = message;
40
+ console.error(t("error", { message }));
38
41
  }
39
42
  }
40
43
  try {
@@ -51,18 +54,15 @@ async function developProject(context) {
51
54
  const client = await attach(context);
52
55
  const controller = new AbortController();
53
56
  const inner = AbortSignal.any([signal, controller.signal]);
54
- let fatalReject;
55
- const fatal = new Promise((_, reject) => {
56
- fatalReject = reject;
57
+ const fatal = Promise.withResolvers();
58
+ follow(inner, fatal.reject, async () => {
59
+ for await (const response of client.swiplets.watchServices({}, { signal: inner })) if (response.swipletId === project.config.id && response.service?.status === 4) console.error(`${response.swipletId}: ${serviceText(response.service)}`);
57
60
  });
58
- follow(inner, fatalReject, async () => {
59
- for await (const response of client.swiplets.watchServices({}, { signal: inner })) if (response.swipletId === project.config.id && response.service?.status === 4) console.error(`${response.swipletId}: ${serviceText(response.swipletId, response.service)}`);
60
- });
61
- if (!context.options["no-logs"]) follow(inner, fatalReject, async () => {
61
+ if (!context.options["no-logs"]) follow(inner, fatal.reject, async () => {
62
62
  for await (const response of client.logs.readLogs({
63
63
  swipletId: project.config.id,
64
64
  follow: true
65
- }, { signal: inner })) printLog(response.entry, false);
65
+ }, { signal: inner })) printLog(response.entry ?? create(LogEntrySchema), false);
66
66
  });
67
67
  let deployed = "";
68
68
  const checker = new AvailabilityChecker();
@@ -72,11 +72,11 @@ async function developProject(context) {
72
72
  try {
73
73
  built = await buildProject(root, checker);
74
74
  } catch (error) {
75
- if (!inner.aborted) console.error(tr("error: {message}", { message: error.message }));
75
+ if (!inner.aborted) printError(error);
76
76
  return;
77
77
  }
78
78
  if (built.digest === deployed) {
79
- console.error(tr("built in {elapsed}; nothing changed", { elapsed: elapsed(started) }));
79
+ console.error(t("commands.project.develop.unchanged", { elapsed: elapsed(started) }));
80
80
  return;
81
81
  }
82
82
  let result;
@@ -89,7 +89,7 @@ async function developProject(context) {
89
89
  }
90
90
  deployed = built.digest;
91
91
  printDeployed(result, false);
92
- console.error(tr("built and deployed in {elapsed}; watching {directory}", {
92
+ console.error(t("commands.project.develop.deployed", {
93
93
  elapsed: elapsed(started),
94
94
  directory: root
95
95
  }));
@@ -124,7 +124,7 @@ async function developProject(context) {
124
124
  }, { once: true });
125
125
  });
126
126
  try {
127
- await Promise.race([cycle().then(watch), fatal]);
127
+ await Promise.race([cycle().then(watch), fatal.promise]);
128
128
  } finally {
129
129
  controller.abort();
130
130
  checker.close();
@@ -133,13 +133,13 @@ async function developProject(context) {
133
133
  const develop = defineCommand({
134
134
  name: "develop",
135
135
  use: "develop [PROJECT]",
136
- short: tr("Build, install and follow a swiplet project as it changes"),
136
+ short: t("commands.project.develop.description"),
137
137
  args: [0, 1],
138
138
  options: {
139
139
  ...deviceOption,
140
140
  "no-logs": {
141
141
  type: "boolean",
142
- help: tr("without logs")
142
+ help: t("commands.project.develop.quiet")
143
143
  }
144
144
  },
145
145
  run: developProject
@@ -1 +1 @@
1
- {"version":3,"file":"develop.js","names":["sleep"],"sources":["../../../../src/cli/commands/project/develop.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { setTimeout as sleep } from \"node:timers/promises\";\n\nimport { AvailabilityChecker } from \"../../../availability\";\nimport { unauthenticated } from \"../../../client\";\nimport { attach } from \"../../../connection\";\nimport { tr } from \"../../../i18n\";\nimport { Ignorer, relativePath } from \"../../../ignore\";\nimport { printLog, serviceText } from \"../../../output\";\nimport { buildProject, loadProject } from \"../../../project\";\nimport { ServiceStatus } from \"../../../proto/swiplets_pb\";\nimport { defineCommand } from \"../../command\";\nimport { deploy, printDeployed } from \"../../deploy\";\nimport { deviceOption } from \"../flags\";\n\nconst rebuildDelay = 300;\nconst logReconnect = 2000;\n\nfunction elapsed(since) {\n const ms = Date.now() - since;\n if (ms < 1000) {\n return `${ms}ms`;\n }\n const seconds = ms / 1000;\n if (seconds < 60) {\n return `${Number(seconds.toFixed(3))}s`;\n }\n return `${Math.floor(seconds / 60)}m${Number((seconds % 60).toFixed(3))}s`;\n}\n\nasync function follow(signal, fatal, run) {\n let reported;\n while (!signal.aborted) {\n try {\n await run();\n } catch (error) {\n if (unauthenticated(error)) {\n fatal(error);\n return;\n }\n if (!signal.aborted && error.message !== reported) {\n reported = error.message;\n console.error(tr(\"error: {message}\", { message: error.message }));\n }\n }\n try {\n await sleep(logReconnect, undefined, { signal });\n } catch {\n return;\n }\n }\n}\n\nasync function developProject(context) {\n const { signal, printError } = context;\n const project = loadProject(path.resolve(context.args[0] ?? \".\"));\n const root = project.root;\n const client = await attach(context);\n const controller = new AbortController();\n const inner = AbortSignal.any([signal, controller.signal]);\n let fatalReject;\n const fatal = new Promise((_, reject) => {\n fatalReject = reject;\n });\n follow(inner, fatalReject, async () => {\n for await (const response of client.swiplets.watchServices(\n {},\n { signal: inner },\n )) {\n if (\n response.swipletId === project.config.id &&\n response.service?.status === ServiceStatus.FAILED\n ) {\n console.error(\n `${response.swipletId}: ${serviceText(response.swipletId, response.service)}`,\n );\n }\n }\n });\n if (!context.options[\"no-logs\"]) {\n follow(inner, fatalReject, async () => {\n for await (const response of client.logs.readLogs(\n { swipletId: project.config.id, follow: true },\n { signal: inner },\n )) {\n printLog(response.entry, false);\n }\n });\n }\n let deployed = \"\";\n const checker = new AvailabilityChecker();\n const cycle = async () => {\n const started = Date.now();\n let built;\n try {\n built = await buildProject(root, checker);\n } catch (error) {\n if (!inner.aborted) {\n console.error(tr(\"error: {message}\", { message: error.message }));\n }\n return;\n }\n if (built.digest === deployed) {\n console.error(\n tr(\"built in {elapsed}; nothing changed\", {\n elapsed: elapsed(started),\n }),\n );\n return;\n }\n let result;\n try {\n result = await deploy(client, built.archive, inner);\n } catch (error) {\n if (unauthenticated(error)) {\n throw error;\n }\n if (!inner.aborted) {\n printError(error, \"deploy\");\n }\n return;\n }\n deployed = built.digest;\n printDeployed(result, false);\n console.error(\n tr(\"built and deployed in {elapsed}; watching {directory}\", {\n elapsed: elapsed(started),\n directory: root,\n }),\n );\n };\n const watch = () =>\n new Promise<void>((resolve, reject) => {\n if (inner.aborted) {\n resolve();\n return;\n }\n let ignore = new Ignorer(root);\n let timer;\n const watcher = fs.watch(root, { recursive: true }, (_, filename) => {\n if (filename === null) {\n return;\n }\n const name = path.join(root, filename);\n if (path.basename(name) === \".gitignore\") {\n ignore = new Ignorer(root);\n }\n let isDirectory = false;\n try {\n isDirectory = fs.statSync(name).isDirectory();\n } catch {\n isDirectory = false;\n }\n const relative = relativePath(root, name);\n if (relative === \"\" || ignore.ignored(relative, isDirectory)) {\n return;\n }\n clearTimeout(timer);\n timer = setTimeout(() => cycle().catch(reject), rebuildDelay);\n });\n watcher.on(\"error\", (error) => printError(error, \"watch the project\"));\n inner.addEventListener(\n \"abort\",\n () => {\n clearTimeout(timer);\n watcher.close();\n resolve();\n },\n { once: true },\n );\n });\n try {\n await Promise.race([cycle().then(watch), fatal]);\n } finally {\n controller.abort();\n checker.close();\n }\n}\n\nexport const develop = defineCommand({\n name: \"develop\",\n use: \"develop [PROJECT]\",\n short: tr(\"Build, install and follow a swiplet project as it changes\"),\n args: [0, 1],\n options: {\n ...deviceOption,\n \"no-logs\": { type: \"boolean\", help: tr(\"without logs\") },\n },\n run: developProject,\n});\n"],"mappings":";;;;;;;;;;;;;;;AAgBA,MAAM,eAAe;AACrB,MAAM,eAAe;AAErB,SAAS,QAAQ,OAAO;CACtB,MAAM,KAAK,KAAK,IAAI,IAAI;CACxB,IAAI,KAAK,KACP,OAAO,GAAG,GAAG;CAEf,MAAM,UAAU,KAAK;CACrB,IAAI,UAAU,IACZ,OAAO,GAAG,OAAO,QAAQ,QAAQ,CAAC,CAAC,EAAE;CAEvC,OAAO,GAAG,KAAK,MAAM,UAAU,EAAE,EAAE,GAAG,QAAQ,UAAU,GAAA,CAAI,QAAQ,CAAC,CAAC,EAAE;AAC1E;AAEA,eAAe,OAAO,QAAQ,OAAO,KAAK;CACxC,IAAI;CACJ,OAAO,CAAC,OAAO,SAAS;EACtB,IAAI;GACF,MAAM,IAAI;EACZ,SAAS,OAAO;GACd,IAAI,gBAAgB,KAAK,GAAG;IAC1B,MAAM,KAAK;IACX;GACF;GACA,IAAI,CAAC,OAAO,WAAW,MAAM,YAAY,UAAU;IACjD,WAAW,MAAM;IACjB,QAAQ,MAAM,GAAG,oBAAoB,EAAE,SAAS,MAAM,QAAQ,CAAC,CAAC;GAClE;EACF;EACA,IAAI;GACF,MAAMA,aAAM,cAAc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AQ,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,KAAK,GAAG,KAAK,CAAC;CACjD,UAAU;EACR,WAAW,MAAM;EACjB,QAAQ,MAAM;CAChB;AACF;AAEA,MAAa,UAAU,cAAc;CACnC,MAAM;CACN,KAAK;CACL,OAAO,GAAG,2DAA2D;CACrE,MAAM,CAAC,GAAG,CAAC;CACX,SAAS;EACP,GAAG;EACH,WAAW;GAAE,MAAM;GAAW,MAAM,GAAG,cAAc;EAAE;CACzD;CACA,KAAK;AACP,CAAC"}
1
+ {"version":3,"file":"develop.js","names":["sleep"],"sources":["../../../../src/cli/commands/project/develop.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { setTimeout as sleep } from \"node:timers/promises\";\n\nimport { create } from \"@bufbuild/protobuf\";\n\nimport { AvailabilityChecker } from \"../../../availability\";\nimport { unauthenticated } from \"../../../client\";\nimport { attach } from \"../../../connection\";\nimport { t } from \"../../../i18n\";\nimport { Ignorer, relativePath } from \"../../../ignore\";\nimport { errorMessage, printLog, serviceText } from \"../../../output\";\nimport { buildProject, loadProject } from \"../../../project\";\nimport { LogEntrySchema } from \"../../../proto/common_pb\";\nimport { ServiceStatus } from \"../../../proto/swiplets_pb\";\nimport { type Context, defineCommand } from \"../../command\";\nimport { deploy, printDeployed } from \"../../deploy\";\nimport { deviceOption } from \"../flags\";\n\nconst rebuildDelay = 300;\nconst logReconnect = 2000;\n\nfunction elapsed(since: number) {\n const ms = Date.now() - since;\n if (ms < 1000) {\n return `${ms}ms`;\n }\n const seconds = ms / 1000;\n if (seconds < 60) {\n return `${Number(seconds.toFixed(3))}s`;\n }\n return `${Math.floor(seconds / 60)}m${Number((seconds % 60).toFixed(3))}s`;\n}\n\nasync function follow(\n signal: AbortSignal,\n fatal: (error: unknown) => void,\n run: () => Promise<void>,\n) {\n let reported: string | undefined;\n while (!signal.aborted) {\n try {\n await run();\n } catch (error) {\n if (unauthenticated(error)) {\n fatal(error);\n return;\n }\n const message = errorMessage(error);\n if (!signal.aborted && message !== reported) {\n reported = message;\n console.error(t(\"error\", { message }));\n }\n }\n try {\n await sleep(logReconnect, undefined, { signal });\n } catch {\n return;\n }\n }\n}\n\nasync function developProject(\n context: Context<{ device?: string; \"no-logs\"?: boolean }>,\n) {\n const { signal, printError } = context;\n const project = loadProject(path.resolve(context.args[0] ?? \".\"));\n const root = project.root;\n const client = await attach(context);\n const controller = new AbortController();\n const inner = AbortSignal.any([signal, controller.signal]);\n const fatal = Promise.withResolvers<never>();\n follow(inner, fatal.reject, async () => {\n for await (const response of client.swiplets.watchServices(\n {},\n { signal: inner },\n )) {\n if (\n response.swipletId === project.config.id &&\n response.service?.status === ServiceStatus.FAILED\n ) {\n console.error(\n `${response.swipletId}: ${serviceText(response.service)}`,\n );\n }\n }\n });\n if (!context.options[\"no-logs\"]) {\n follow(inner, fatal.reject, async () => {\n for await (const response of client.logs.readLogs(\n { swipletId: project.config.id, follow: true },\n { signal: inner },\n )) {\n printLog(response.entry ?? create(LogEntrySchema), false);\n }\n });\n }\n let deployed = \"\";\n const checker = new AvailabilityChecker();\n const cycle = async () => {\n const started = Date.now();\n let built;\n try {\n built = await buildProject(root, checker);\n } catch (error) {\n if (!inner.aborted) {\n printError(error);\n }\n return;\n }\n if (built.digest === deployed) {\n console.error(\n t(\"commands.project.develop.unchanged\", {\n elapsed: elapsed(started),\n }),\n );\n return;\n }\n let result;\n try {\n result = await deploy(client, built.archive, inner);\n } catch (error) {\n if (unauthenticated(error)) {\n throw error;\n }\n if (!inner.aborted) {\n printError(error, \"deploy\");\n }\n return;\n }\n deployed = built.digest;\n printDeployed(result, false);\n console.error(\n t(\"commands.project.develop.deployed\", {\n elapsed: elapsed(started),\n directory: root,\n }),\n );\n };\n const watch = () =>\n new Promise<void>((resolve, reject) => {\n if (inner.aborted) {\n resolve();\n return;\n }\n let ignore = new Ignorer(root);\n let timer: NodeJS.Timeout | undefined;\n const watcher = fs.watch(root, { recursive: true }, (_, filename) => {\n if (filename === null) {\n return;\n }\n const name = path.join(root, filename);\n if (path.basename(name) === \".gitignore\") {\n ignore = new Ignorer(root);\n }\n let isDirectory = false;\n try {\n isDirectory = fs.statSync(name).isDirectory();\n } catch {\n isDirectory = false;\n }\n const relative = relativePath(root, name);\n if (relative === \"\" || ignore.ignored(relative, isDirectory)) {\n return;\n }\n clearTimeout(timer);\n timer = setTimeout(() => cycle().catch(reject), rebuildDelay);\n });\n watcher.on(\"error\", (error) => printError(error, \"watch the project\"));\n inner.addEventListener(\n \"abort\",\n () => {\n clearTimeout(timer);\n watcher.close();\n resolve();\n },\n { once: true },\n );\n });\n try {\n await Promise.race([cycle().then(watch), fatal.promise]);\n } finally {\n controller.abort();\n checker.close();\n }\n}\n\nexport const develop = defineCommand({\n name: \"develop\",\n use: \"develop [PROJECT]\",\n short: t(\"commands.project.develop.description\"),\n args: [0, 1],\n options: {\n ...deviceOption,\n \"no-logs\": { type: \"boolean\", help: t(\"commands.project.develop.quiet\") },\n },\n run: developProject,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,MAAM,eAAe;AACrB,MAAM,eAAe;AAErB,SAAS,QAAQ,OAAe;CAC9B,MAAM,KAAK,KAAK,IAAI,IAAI;CACxB,IAAI,KAAK,KACP,OAAO,GAAG,GAAG;CAEf,MAAM,UAAU,KAAK;CACrB,IAAI,UAAU,IACZ,OAAO,GAAG,OAAO,QAAQ,QAAQ,CAAC,CAAC,EAAE;CAEvC,OAAO,GAAG,KAAK,MAAM,UAAU,EAAE,EAAE,GAAG,QAAQ,UAAU,GAAA,CAAI,QAAQ,CAAC,CAAC,EAAE;AAC1E;AAEA,eAAe,OACb,QACA,OACA,KACA;CACA,IAAI;CACJ,OAAO,CAAC,OAAO,SAAS;EACtB,IAAI;GACF,MAAM,IAAI;EACZ,SAAS,OAAO;GACd,IAAI,gBAAgB,KAAK,GAAG;IAC1B,MAAM,KAAK;IACX;GACF;GACA,MAAM,UAAU,aAAa,KAAK;GAClC,IAAI,CAAC,O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AE,MAAM,KAAK,CACf;CACF,CAAC;CACH,IAAI;EACF,MAAM,QAAQ,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,KAAK,GAAG,MAAM,OAAO,CAAC;CACzD,UAAU;EACR,WAAW,MAAM;EACjB,QAAQ,MAAM;CAChB;AACF;AAEA,MAAa,UAAU,cAAc;CACnC,MAAM;CACN,KAAK;CACL,OAAO,EAAE,sCAAsC;CAC/C,MAAM,CAAC,GAAG,CAAC;CACX,SAAS;EACP,GAAG;EACH,WAAW;GAAE,MAAM;GAAW,MAAM,EAAE,gCAAgC;EAAE;CAC1E;CACA,KAAK;AACP,CAAC"}
@@ -1,4 +1,4 @@
1
- import { tr } from "../../../i18n.js";
1
+ import { t } from "../../../i18n.js";
2
2
  import { defineCommand } from "../../command.js";
3
3
  import { build } from "./build.js";
4
4
  import { create } from "./create.js";
@@ -8,7 +8,7 @@ import { source } from "./source.js";
8
8
  // src/cli/commands/project/project.ts
9
9
  const project = defineCommand({
10
10
  name: "project",
11
- short: tr("Make, build and deploy swiplet projects"),
11
+ short: t("commands.project.description"),
12
12
  commands: [
13
13
  create,
14
14
  build,
@@ -1 +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"}
1
+ {"version":3,"file":"project.js","names":[],"sources":["../../../../src/cli/commands/project/project.ts"],"sourcesContent":["import { t } 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: t(\"commands.project.description\"),\n commands: [create, build, source, deploy, develop],\n});\n"],"mappings":";;;;;;;;AAQA,MAAa,UAAU,cAAc;CACnC,MAAM;CACN,OAAO,EAAE,8BAA8B;CACvC,UAAU;EAAC;EAAQ;EAAO;EAAQ;EAAQ;CAAO;AACnD,CAAC"}
@@ -1,4 +1,5 @@
1
- import { tr } from "../../../i18n.js";
1
+ import { t } from "../../../i18n.js";
2
+ import { errorMessage } from "../../../output.js";
2
3
  import { idPattern } from "../../../project.js";
3
4
  import { defineCommand } from "../../command.js";
4
5
  import fs from "node:fs";
@@ -6,29 +7,52 @@ import path from "node:path";
6
7
  import { createHash } from "node:crypto";
7
8
  import { strFromU8, unzipSync } from "fflate";
8
9
  // src/cli/commands/project/source.ts
10
+ const isRecord = (value) => typeof value === "object" && value !== null;
11
+ const isStringRecord = (value) => isRecord(value) && Object.values(value).every((name) => typeof name === "string");
12
+ function stringField(record, name, field) {
13
+ const value = record[name];
14
+ if (value !== void 0 && typeof value !== "string") throw new Error(t("project.invalidString", { field }));
15
+ return value;
16
+ }
17
+ function loadIcon(icon) {
18
+ if (icon === void 0) return;
19
+ if (!isRecord(icon) || typeof icon.symbol !== "string" || icon.color !== void 0 && typeof icon.color !== "string") throw new Error(t("commands.project.source.invalidIcon"));
20
+ return {
21
+ symbol: icon.symbol,
22
+ color: icon.color,
23
+ symbolColor: stringField(icon, "symbolColor", "source.icon.symbolColor")
24
+ };
25
+ }
26
+ function workspacePatterns(workspaces) {
27
+ const [field, patterns] = Array.isArray(workspaces) ? ["workspaces", workspaces] : isRecord(workspaces) && Array.isArray(workspaces.packages) ? ["workspaces.packages", workspaces.packages] : ["", []];
28
+ return patterns.map((pattern, index) => {
29
+ if (typeof pattern !== "string") throw new Error(t("project.invalidString", { field: `${field}[${index}]` }));
30
+ return pattern;
31
+ });
32
+ }
9
33
  function loadSource(root) {
10
- const manifest = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
11
- const config = manifest.source ?? {};
12
- for (const field of [
13
- "name",
14
- "image",
15
- "url"
16
- ]) if (config[field] !== void 0 && typeof config[field] !== "string") throw new Error(tr("\"{field}\" in package.json must be a string.", { field: `source.${field}` }));
34
+ const parsed = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
35
+ const manifest = isRecord(parsed) ? parsed : {};
36
+ const config = isRecord(manifest.source) ? manifest.source : {};
37
+ const name = stringField(config, "name", "source.name");
38
+ const image = stringField(config, "image", "source.image");
39
+ const url = stringField(config, "url", "source.url");
17
40
  const localizedNames = config.localizedNames ?? {};
18
- 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."));
19
- 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."));
20
- if (config.icon?.symbolColor !== void 0 && typeof config.icon.symbolColor !== "string") throw new Error(tr("\"{field}\" in package.json must be a string.", { field: "source.icon.symbolColor" }));
41
+ if (!isStringRecord(localizedNames)) throw new Error(t("commands.project.source.invalidLocalizedNames"));
42
+ const icon = loadIcon(config.icon);
21
43
  let prefix;
22
- if (config.url !== void 0) try {
23
- prefix = new URL(config.url.endsWith("/") ? config.url : `${config.url}/`);
44
+ if (url !== void 0) try {
45
+ prefix = new URL(url.endsWith("/") ? url : `${url}/`);
24
46
  } catch {
25
- throw new Error(tr("\"source.url\" in package.json isn't an absolute URL."));
47
+ throw new Error(t("commands.project.source.invalidURL"));
26
48
  }
27
- const workspaces = Array.isArray(manifest.workspaces) ? manifest.workspaces : manifest.workspaces?.packages ?? [];
49
+ const workspaces = workspacePatterns(manifest.workspaces);
28
50
  return {
29
51
  root,
30
- config,
52
+ name,
53
+ image,
31
54
  localizedNames,
55
+ icon,
32
56
  prefix,
33
57
  workspaces
34
58
  };
@@ -38,10 +62,11 @@ function workspaceSwiplets(source) {
38
62
  for (const pattern of source.workspaces) for (const directory of fs.globSync(pattern, { cwd: source.root }).sort()) {
39
63
  const project = path.join(source.root, directory, "package.json");
40
64
  if (!fs.existsSync(project)) continue;
41
- const id = JSON.parse(fs.readFileSync(project, "utf8")).swiplet?.id;
65
+ const manifest = JSON.parse(fs.readFileSync(project, "utf8"));
66
+ const id = isRecord(manifest) && isRecord(manifest.swiplet) ? manifest.swiplet.id : void 0;
42
67
  if (typeof id !== "string") continue;
43
68
  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.", {
69
+ if (!fs.existsSync(built)) throw new Error(t("commands.project.source.notBuilt", {
45
70
  file: path.relative(source.root, built),
46
71
  directory
47
72
  }));
@@ -55,13 +80,14 @@ function readSwiplet(file) {
55
80
  try {
56
81
  entry = unzipSync(data, { filter: ({ name }) => name === "manifest.json" })["manifest.json"];
57
82
  } catch (error) {
58
- throw new Error(`${file}: ${error.message}`);
83
+ throw new Error(`${file}: ${errorMessage(error)}`);
59
84
  }
60
85
  if (entry === void 0) throw new Error(`${file} has no manifest.json`);
61
86
  const manifest = JSON.parse(strFromU8(entry));
62
- if (typeof manifest.id !== "string" || !idPattern.test(manifest.id)) throw new Error(`${file} has no valid swiplet id in its manifest`);
87
+ if (!isRecord(manifest) || typeof manifest.id !== "string" || !idPattern.test(manifest.id)) throw new Error(`${file} has no valid swiplet id in its manifest`);
63
88
  return {
64
89
  file,
90
+ id: manifest.id,
65
91
  manifest,
66
92
  data
67
93
  };
@@ -69,20 +95,20 @@ function readSwiplet(file) {
69
95
  function sourceCommand(root, given) {
70
96
  const source = loadSource(root);
71
97
  const files = given.length > 0 ? given.map((file) => path.resolve(file)) : workspaceSwiplets(source);
72
- if (files.length === 0) throw new Error(tr("package.json lists no workspaces with swiplets; name the swiplets to list."));
98
+ if (files.length === 0) throw new Error(t("commands.project.source.noWorkspaces"));
73
99
  const swiplets = /* @__PURE__ */ new Map();
74
100
  for (const read of files.map(readSwiplet)) {
75
- const { id } = read.manifest;
76
- if (swiplets.has(id)) throw new Error(tr("{id} is both {first} and {second}", {
77
- id,
78
- first: swiplets.get(id).file,
101
+ const first = swiplets.get(read.id);
102
+ if (first !== void 0) throw new Error(t("commands.project.source.duplicateID", {
103
+ id: read.id,
104
+ first: first.file,
79
105
  second: read.file
80
106
  }));
81
- swiplets.set(id, read);
107
+ swiplets.set(read.id, read);
82
108
  }
83
- const image = source.config.image === void 0 ? void 0 : {
84
- name: path.basename(source.config.image),
85
- data: fs.readFileSync(path.resolve(root, source.config.image))
109
+ const image = source.image === void 0 ? void 0 : {
110
+ name: path.basename(source.image),
111
+ data: fs.readFileSync(path.resolve(root, source.image))
86
112
  };
87
113
  const located = (name) => source.prefix ? new URL(name, source.prefix).href : name;
88
114
  const dist = path.join(root, "dist");
@@ -91,8 +117,7 @@ function sourceCommand(root, given) {
91
117
  force: true
92
118
  });
93
119
  fs.mkdirSync(dist, { recursive: true });
94
- const entries = [...swiplets.keys()].map((id) => {
95
- const { manifest, data } = swiplets.get(id);
120
+ const entries = [...swiplets.values()].map(({ id, manifest, data }) => {
96
121
  const name = `${id}.swiplet`;
97
122
  fs.writeFileSync(path.join(dist, name), data);
98
123
  return {
@@ -104,12 +129,12 @@ function sourceCommand(root, given) {
104
129
  });
105
130
  if (image) fs.writeFileSync(path.join(dist, image.name), image.data);
106
131
  const index = {
107
- ...source.config.name ? { name: source.config.name } : {},
132
+ ...source.name ? { name: source.name } : {},
108
133
  ...Object.keys(source.localizedNames).length > 0 ? { localizedNames: source.localizedNames } : {},
109
- ...source.config.icon ? { icon: {
110
- symbol: source.config.icon.symbol,
111
- ...source.config.icon.color ? { color: source.config.icon.color } : {},
112
- ...source.config.icon.symbolColor ? { symbolColor: source.config.icon.symbolColor } : {}
134
+ ...source.icon ? { icon: {
135
+ symbol: source.icon.symbol,
136
+ ...source.icon.color ? { color: source.icon.color } : {},
137
+ ...source.icon.symbolColor ? { symbolColor: source.icon.symbolColor } : {}
113
138
  } } : {},
114
139
  ...image ? { image: located(image.name) } : {},
115
140
  swiplets: entries
@@ -120,7 +145,7 @@ function sourceCommand(root, given) {
120
145
  const source = defineCommand({
121
146
  name: "source",
122
147
  use: "source [SWIPLET...]",
123
- short: tr("Collect the built swiplets into dist/ with a swiplets.json"),
148
+ short: t("commands.project.source.description"),
124
149
  args: [0, Infinity],
125
150
  run: ({ args }) => sourceCommand(process.cwd(), args)
126
151
  });
@@ -1 +1 @@
1
- {"version":3,"file":"source.js","names":[],"sources":["../../../../src/cli/commands/project/source.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport { strFromU8, unzipSync } from \"fflate\";\n\nimport { tr } from \"../../../i18n\";\nimport { idPattern } from \"../../../project\";\nimport { defineCommand } from \"../../command\";\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(\n '\"source.localizedNames\" in package.json must map languages to names.',\n ),\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 if (\n config.icon?.symbolColor !== undefined &&\n typeof config.icon.symbolColor !== \"string\"\n ) {\n throw new Error(\n tr('\"{field}\" in package.json must be a string.', {\n field: \"source.icon.symbolColor\",\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 isn\\'t 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 data = fs.readFileSync(file);\n let entry;\n try {\n entry = unzipSync(data, {\n filter: ({ name }) => name === \"manifest.json\",\n })[\"manifest.json\"];\n } catch (error) {\n throw new Error(`${file}: ${error.message}`);\n }\n if (entry === undefined) {\n throw new Error(`${file} has no manifest.json`);\n }\n const manifest = JSON.parse(strFromU8(entry));\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 };\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 ...(source.config.icon.symbolColor\n ? { symbolColor: source.config.icon.symbolColor }\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":";;;;;;;;AAUA,SAAS,WAAW,MAAM;C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O,OAAO,EAAE,MAAM,OAAO,OAAO,KAAK,IAAI,CAAC;EACzD,GAAI,OAAO,KAAK,OAAO,cAAc,CAAC,CAAC,SAAS,IAC5C,EAAE,gBAAgB,OAAO,eAAe,IACxC,CAAC;EACL,GAAI,OAAO,OAAO,OACd,EACE,MAAM;GACJ,QAAQ,OAAO,OAAO,KAAK;GAC3B,GAAI,OAAO,OAAO,KAAK,QACnB,EAAE,OAAO,OAAO,OAAO,KAAK,MAAM,IAClC,CAAC;GACL,GAAI,OAAO,OAAO,KAAK,cACnB,EAAE,aAAa,OAAO,OAAO,KAAK,YAAY,IAC9C,CAAC;EACP,EACF,IACA,CAAC;EACL,GAAI,QAAQ,EAAE,OAAO,QAAQ,MAAM,IAAI,EAAE,IAAI,CAAC;EAC9C,UAAU;CACZ;CACA,GAAG,cACD,KAAK,KAAK,MAAM,eAAe,GAC/B,GAAG,KAAK,UAAU,OAAO,MAAM,CAAC,EAAE,GACpC;CACA,QAAQ,IAAI,KAAK,SAAS,QAAQ,IAAI,GAAG,KAAK,KAAK,MAAM,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"}
1
+ {"version":3,"file":"source.js","names":[],"sources":["../../../../src/cli/commands/project/source.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n\nimport { strFromU8, unzipSync } from \"fflate\";\n\nimport { t } from \"../../../i18n\";\nimport { errorMessage } from \"../../../output\";\nimport { idPattern } from \"../../../project\";\nimport { defineCommand } from \"../../command\";\n\ninterface Icon {\n symbol: string;\n color?: string;\n symbolColor?: string;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\nconst isStringRecord = (value: unknown): value is Record<string, string> =>\n isRecord(value) &&\n Object.values(value).every((name) => typeof name === \"string\");\n\nfunction stringField(\n record: Record<string, unknown>,\n name: string,\n field: string,\n) {\n const value = record[name];\n if (value !== undefined && typeof value !== \"string\") {\n throw new Error(t(\"project.invalidString\", { field }));\n }\n return value;\n}\n\nfunction loadIcon(icon: unknown): Icon | undefined {\n if (icon === undefined) {\n return undefined;\n }\n if (\n !isRecord(icon) ||\n typeof icon.symbol !== \"string\" ||\n (icon.color !== undefined && typeof icon.color !== \"string\")\n ) {\n throw new Error(t(\"commands.project.source.invalidIcon\"));\n }\n return {\n symbol: icon.symbol,\n color: icon.color,\n symbolColor: stringField(icon, \"symbolColor\", \"source.icon.symbolColor\"),\n };\n}\n\nfunction workspacePatterns(workspaces: unknown) {\n const [field, patterns] = Array.isArray(workspaces)\n ? [\"workspaces\", workspaces]\n : isRecord(workspaces) && Array.isArray(workspaces.packages)\n ? [\"workspaces.packages\", workspaces.packages]\n : [\"\", []];\n return patterns.map((pattern: unknown, index) => {\n if (typeof pattern !== \"string\") {\n throw new Error(\n t(\"project.invalidString\", { field: `${field}[${index}]` }),\n );\n }\n return pattern;\n });\n}\n\nfunction loadSource(root: string) {\n const parsed: unknown = JSON.parse(\n fs.readFileSync(path.join(root, \"package.json\"), \"utf8\"),\n );\n const manifest = isRecord(parsed) ? parsed : {};\n const config = isRecord(manifest.source) ? manifest.source : {};\n const name = stringField(config, \"name\", \"source.name\");\n const image = stringField(config, \"image\", \"source.image\");\n const url = stringField(config, \"url\", \"source.url\");\n const localizedNames = config.localizedNames ?? {};\n if (!isStringRecord(localizedNames)) {\n throw new Error(t(\"commands.project.source.invalidLocalizedNames\"));\n }\n const icon = loadIcon(config.icon);\n let prefix: URL | undefined;\n if (url !== undefined) {\n try {\n prefix = new URL(url.endsWith(\"/\") ? url : `${url}/`);\n } catch {\n throw new Error(t(\"commands.project.source.invalidURL\"));\n }\n }\n const workspaces = workspacePatterns(manifest.workspaces);\n return { root, name, image, localizedNames, icon, prefix, workspaces };\n}\n\nfunction workspaceSwiplets(source: ReturnType<typeof loadSource>) {\n const files: string[] = [];\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 manifest: unknown = JSON.parse(fs.readFileSync(project, \"utf8\"));\n const id =\n isRecord(manifest) && isRecord(manifest.swiplet)\n ? manifest.swiplet.id\n : undefined;\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 t(\"commands.project.source.notBuilt\", {\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: string) {\n const data = fs.readFileSync(file);\n let entry;\n try {\n entry = unzipSync(data, {\n filter: ({ name }) => name === \"manifest.json\",\n })[\"manifest.json\"];\n } catch (error) {\n throw new Error(`${file}: ${errorMessage(error)}`);\n }\n if (entry === undefined) {\n throw new Error(`${file} has no manifest.json`);\n }\n const manifest: unknown = JSON.parse(strFromU8(entry));\n if (\n !isRecord(manifest) ||\n typeof manifest.id !== \"string\" ||\n !idPattern.test(manifest.id)\n ) {\n throw new Error(`${file} has no valid swiplet id in its manifest`);\n }\n return { file, id: manifest.id, manifest, data };\n}\n\nfunction sourceCommand(root: string, given: string[]) {\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(t(\"commands.project.source.noWorkspaces\"));\n }\n const swiplets = new Map<string, ReturnType<typeof readSwiplet>>();\n for (const read of files.map(readSwiplet)) {\n const first = swiplets.get(read.id);\n if (first !== undefined) {\n throw new Error(\n t(\"commands.project.source.duplicateID\", {\n id: read.id,\n first: first.file,\n second: read.file,\n }),\n );\n }\n swiplets.set(read.id, read);\n }\n const image =\n source.image === undefined\n ? undefined\n : {\n name: path.basename(source.image),\n data: fs.readFileSync(path.resolve(root, source.image)),\n };\n const located = (name: string) =>\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.values()].map(({ id, manifest, data }) => {\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.name ? { name: source.name } : {}),\n ...(Object.keys(source.localizedNames).length > 0\n ? { localizedNames: source.localizedNames }\n : {}),\n ...(source.icon\n ? {\n icon: {\n symbol: source.icon.symbol,\n ...(source.icon.color ? { color: source.icon.color } : {}),\n ...(source.icon.symbolColor\n ? { symbolColor: source.icon.symbolColor }\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: t(\"commands.project.source.description\"),\n args: [0, Infinity],\n run: ({ args }) => sourceCommand(process.cwd(), args),\n});\n"],"mappings":";;;;;;;;;AAiBA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU;AAEzC,MAAM,kBAAkB,UACtB,SAAS,KAAK,KACd,OAAO,OAAO,KAAK,CAAC,CAAC,OAAO,SAAS,OAAO,SAAS,QAAQ;AAE/D,SAAS,YACP,QACA,MACA,OACA;CACA,MAAM,QAAQ,OAAO;CACrB,IAAI,UAAU,KAAA,KAAa,OAAO,UAAU,UAC1C,MAAM,IAAI,MAAM,EAAE,yBAAyB,EAAE,MAAM,C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Ac,QAAQ,IAAI,GAAG,IAAI;AACtD,CAAC"}
@@ -1,4 +1,4 @@
1
- import { tr } from "../../../i18n.js";
1
+ import { t } from "../../../i18n.js";
2
2
  import { defineCommand } from "../../command.js";
3
3
  import { session } from "../../session.js";
4
4
  // src/cli/commands/repl/api.ts
@@ -7,7 +7,7 @@ const printDeclarations = (context) => session(context, async (client) => {
7
7
  });
8
8
  const api = defineCommand({
9
9
  name: "api",
10
- short: tr("Print the TypeScript declarations of the globals and modules"),
10
+ short: t("commands.repl.api.description"),
11
11
  args: [0, 0],
12
12
  run: printDeclarations
13
13
  });
@@ -1 +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"}
1
+ {"version":3,"file":"api.js","names":[],"sources":["../../../../src/cli/commands/repl/api.ts"],"sourcesContent":["import { t } from \"../../../i18n\";\nimport { type Context, defineCommand } from \"../../command\";\nimport { session } from \"../../session\";\n\nconst printDeclarations = (context: Context<{ device?: string }>) =>\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: t(\"commands.repl.api.description\"),\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,EAAE,+BAA+B;CACxC,MAAM,CAAC,GAAG,CAAC;CACX,KAAK;AACP,CAAC"}
@@ -1,4 +1,4 @@
1
- import { tr } from "../../../i18n.js";
1
+ import { t } from "../../../i18n.js";
2
2
  import { defineCommand } from "../../command.js";
3
3
  import "../data/index.js";
4
4
  import { data } from "../data/data.js";
@@ -9,13 +9,13 @@ import { run } from "./run.js";
9
9
  // src/cli/commands/repl/repl.ts
10
10
  const replData = (args) => ({
11
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 }),
12
+ wholeDirectory: (name) => t("commands.repl.dataDirectory", { path: name }),
13
+ subdirectory: (name) => t("commands.repl.directory", { path: name }),
14
14
  args
15
15
  });
16
16
  const repl = defineCommand({
17
17
  name: "repl",
18
- short: tr("Run JavaScript in the REPL session on the device"),
18
+ short: t("commands.repl.description"),
19
19
  options: deviceOption,
20
20
  commands: [
21
21
  run,
@@ -1 +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"}
1
+ {"version":3,"file":"repl.js","names":[],"sources":["../../../../src/cli/commands/repl/repl.ts"],"sourcesContent":["import { t } from \"../../../i18n\";\nimport { defineCommand } from \"../../command\";\nimport { data } from \"../data\";\nimport type { DataTarget } from \"../data/operand\";\nimport { deviceOption } from \"../flags\";\nimport { api } from \"./api\";\nimport { reset } from \"./reset\";\nimport { run } from \"./run\";\n\nconst replData = (args: string[]): DataTarget => ({\n id: \"@repl\",\n wholeDirectory: (name) => t(\"commands.repl.dataDirectory\", { path: name }),\n subdirectory: (name) => t(\"commands.repl.directory\", { path: name }),\n args,\n});\n\nexport const repl = defineCommand({\n name: \"repl\",\n short: t(\"commands.repl.description\"),\n options: deviceOption,\n commands: [run, reset, api, data(\"\", replData)],\n});\n"],"mappings":";;;;;;;;;AASA,MAAM,YAAY,UAAgC;CAChD,IAAI;CACJ,iBAAiB,SAAS,EAAE,+BAA+B,EAAE,MAAM,KAAK,CAAC;CACzE,eAAe,SAAS,EAAE,2BAA2B,EAAE,MAAM,KAAK,CAAC;CACnE;AACF;AAEA,MAAa,OAAO,cAAc;CAChC,MAAM;CACN,OAAO,EAAE,2BAA2B;CACpC,SAAS;CACT,UAAU;EAAC;EAAK;EAAO;EAAK,KAAK,IAAI,QAAQ;CAAC;AAChD,CAAC"}
@@ -1,11 +1,11 @@
1
- import { tr } from "../../../i18n.js";
1
+ import { t } from "../../../i18n.js";
2
2
  import { defineCommand } from "../../command.js";
3
3
  import { session } from "../../session.js";
4
4
  // src/cli/commands/repl/reset.ts
5
5
  const resetSession = (context) => session(context, (client) => client.repl.reset({}, { signal: context.signal }));
6
6
  const reset = defineCommand({
7
7
  name: "reset",
8
- short: tr("Reset the session"),
8
+ short: t("commands.repl.reset.description"),
9
9
  args: [0, 0],
10
10
  run: resetSession
11
11
  });
@@ -1 +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"}
1
+ {"version":3,"file":"reset.js","names":[],"sources":["../../../../src/cli/commands/repl/reset.ts"],"sourcesContent":["import { t } from \"../../../i18n\";\nimport { type Context, defineCommand } from \"../../command\";\nimport { session } from \"../../session\";\n\nconst resetSession = (context: Context<{ device?: string }>) =>\n session(context, (client) =>\n client.repl.reset({}, { signal: context.signal }),\n );\n\nexport const reset = defineCommand({\n name: \"reset\",\n short: t(\"commands.repl.reset.description\"),\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,EAAE,iCAAiC;CAC1C,MAAM,CAAC,GAAG,CAAC;CACX,KAAK;AACP,CAAC"}