arcadible 1.0.23 → 1.0.24

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 (308) hide show
  1. package/README.md +1 -0
  2. package/bin/arc.js +1 -85
  3. package/dist/account.js +197 -0
  4. package/dist/action/build/tool.js +65 -0
  5. package/dist/action/delete/tool.js +46 -0
  6. package/dist/action/deploy/rebuilt.js +25 -0
  7. package/dist/action/deploy/result.js +36 -0
  8. package/dist/action/deploy/timeout.js +18 -0
  9. package/dist/action/deploy/tool-git.js +54 -0
  10. package/dist/action/deploy/tool.js +54 -0
  11. package/dist/action/deploy/wait.js +104 -0
  12. package/dist/action/function/tool.js +127 -0
  13. package/dist/action/game.js +61 -0
  14. package/dist/action/init/manifest.js +64 -0
  15. package/dist/action/init/tool-patch.js +15 -0
  16. package/dist/action/init/tool.js +64 -0
  17. package/dist/action/inspect/tool.js +13 -0
  18. package/dist/action/key/tool.js +87 -0
  19. package/dist/action/login/flow.js +69 -0
  20. package/dist/action/login/tool.js +8 -0
  21. package/dist/action/logout/tool.js +8 -0
  22. package/dist/action/open/tool.js +29 -0
  23. package/dist/action/pack/limits.js +46 -0
  24. package/dist/action/pack/tool.js +150 -0
  25. package/dist/action/pack/unsound.js +51 -0
  26. package/dist/action/play/tool.js +83 -0
  27. package/dist/action/predeploy/ac.js +75 -0
  28. package/dist/action/predeploy/game.js +12 -0
  29. package/dist/action/predeploy/git.js +151 -0
  30. package/dist/action/predeploy/pm.js +20 -0
  31. package/dist/action/predeploy/published.js +54 -0
  32. package/dist/action/predeploy/secrets.js +35 -0
  33. package/dist/action/predeploy/tool-git.js +108 -0
  34. package/dist/action/predeploy/tool.js +16 -0
  35. package/dist/action/secret/tool.js +91 -0
  36. package/dist/action/serve/tool.js +249 -0
  37. package/dist/action/validate/checked.js +28 -0
  38. package/dist/action/validate/tool.js +56 -0
  39. package/dist/action/validate/unknown.js +58 -0
  40. package/dist/action/validate/unsound.js +99 -0
  41. package/dist/action/whoami/tool.js +7 -0
  42. package/dist/api.js +160 -0
  43. package/dist/arc.js +41 -0
  44. package/dist/cli/argv.js +61 -0
  45. package/dist/cli/channel.js +29 -0
  46. package/dist/cli/command.js +163 -0
  47. package/dist/cli/confirm.js +39 -0
  48. package/dist/cli/options.js +62 -0
  49. package/dist/cli/rc.js +103 -0
  50. package/dist/cli/yargs.js +40 -0
  51. package/dist/command/build.js +68 -0
  52. package/dist/command/delete.js +66 -0
  53. package/dist/command/deploy.js +308 -0
  54. package/dist/command/function/index.js +17 -0
  55. package/dist/command/function/pause.js +18 -0
  56. package/dist/command/function/resume.js +18 -0
  57. package/dist/command/function/run.js +41 -0
  58. package/dist/command/function/secret/index.js +15 -0
  59. package/dist/command/function/secret/list.js +27 -0
  60. package/dist/command/function/secret/name.js +8 -0
  61. package/dist/command/function/secret/remove.js +26 -0
  62. package/dist/command/function/secret/run.js +52 -0
  63. package/dist/command/function/secret/set.js +48 -0
  64. package/dist/command/function/status.js +40 -0
  65. package/dist/command/init.js +128 -0
  66. package/dist/command/inspect.js +38 -0
  67. package/dist/command/login.js +108 -0
  68. package/dist/command/logout.js +24 -0
  69. package/dist/command/open.js +48 -0
  70. package/dist/command/pack.js +90 -0
  71. package/dist/command/play.js +80 -0
  72. package/dist/command/serve.js +176 -0
  73. package/dist/command/server/index.js +17 -0
  74. package/dist/command/server/key/create.js +36 -0
  75. package/dist/command/server/key/index.js +15 -0
  76. package/dist/command/server/key/list.js +34 -0
  77. package/dist/command/server/key/revoke.js +24 -0
  78. package/dist/command/server/key/run.js +54 -0
  79. package/dist/command/validate.js +47 -0
  80. package/dist/command/whoami.js +55 -0
  81. package/dist/commands.js +93 -0
  82. package/dist/config/ai.js +2 -0
  83. package/dist/config/art.js +13 -0
  84. package/dist/config/audience.js +2 -0
  85. package/dist/config/code.js +129 -0
  86. package/dist/config/file.js +13 -0
  87. package/dist/config/genre.js +19 -0
  88. package/{src → dist}/config/html.js +2 -7
  89. package/dist/config/image.js +5 -0
  90. package/dist/config/input.js +11 -0
  91. package/dist/config/json.js +23 -0
  92. package/dist/config/limit.js +14 -0
  93. package/dist/config/orientation.js +11 -0
  94. package/dist/config/package.js +8 -0
  95. package/dist/config/product.js +14 -0
  96. package/dist/config/template.js +37 -0
  97. package/dist/config/uri.js +18 -0
  98. package/dist/config/url.js +11 -0
  99. package/dist/config/video.js +5 -0
  100. package/dist/config/visibility.js +2 -0
  101. package/dist/config/workflow.js +7 -0
  102. package/dist/parser/env.js +61 -0
  103. package/dist/parser/given.js +8 -0
  104. package/dist/parser/manifest.js +45 -0
  105. package/dist/parser/media.js +57 -0
  106. package/dist/parser/project.js +129 -0
  107. package/dist/parser/readme-file.js +44 -0
  108. package/dist/parser/readme.js +70 -0
  109. package/dist/parser/sections.js +92 -0
  110. package/dist/parser/self.js +16 -0
  111. package/dist/phrase/account.js +35 -0
  112. package/dist/phrase/common.js +130 -0
  113. package/dist/phrase/deploy.js +184 -0
  114. package/dist/phrase/function.js +135 -0
  115. package/dist/phrase/game.js +27 -0
  116. package/dist/phrase/index.js +15 -0
  117. package/dist/phrase/init.js +53 -0
  118. package/dist/phrase/internal.js +61 -0
  119. package/dist/phrase/manifest.js +120 -0
  120. package/dist/phrase/media.js +90 -0
  121. package/dist/phrase/pack.js +69 -0
  122. package/dist/phrase/serve.js +84 -0
  123. package/dist/phrase/server.js +38 -0
  124. package/dist/runner/bundle.js +95 -0
  125. package/dist/runner/outbound.js +69 -0
  126. package/dist/schema/check/game.js +29 -0
  127. package/dist/schema/check/workflow.js +57 -0
  128. package/dist/schema/game.js +462 -0
  129. package/dist/schema/message.js +61 -0
  130. package/dist/schema/readme.js +27 -0
  131. package/dist/schema/runner.js +43 -0
  132. package/dist/schema/server.js +91 -0
  133. package/dist/schema/workflow.js +99 -0
  134. package/dist/serve/files.js +39 -0
  135. package/dist/serve/game.js +172 -0
  136. package/dist/serve/page.js +490 -0
  137. package/dist/serve/reload.js +55 -0
  138. package/dist/serve/remote.js +114 -0
  139. package/dist/serve/runner.js +296 -0
  140. package/dist/serve/server.js +163 -0
  141. package/dist/serve/ticket.js +232 -0
  142. package/dist/util/bytes.js +16 -0
  143. package/dist/util/chars.js +19 -0
  144. package/dist/util/command.js +11 -0
  145. package/dist/util/delay.js +36 -0
  146. package/dist/util/doc.js +59 -0
  147. package/dist/util/error.js +35 -0
  148. package/dist/util/http.js +13 -0
  149. package/dist/util/image.js +64 -0
  150. package/dist/util/links.js +45 -0
  151. package/dist/util/lockfile.js +17 -0
  152. package/dist/util/log.js +101 -0
  153. package/dist/util/md.js +37 -0
  154. package/dist/util/media.js +27 -0
  155. package/dist/util/objs.js +29 -0
  156. package/dist/util/os.js +13 -0
  157. package/dist/util/output.js +133 -0
  158. package/dist/util/paths.js +8 -0
  159. package/dist/util/progress.js +57 -0
  160. package/dist/util/promise.js +18 -0
  161. package/dist/util/request.js +91 -0
  162. package/dist/util/s3.js +67 -0
  163. package/dist/util/schema.js +151 -0
  164. package/dist/util/screenshot.js +24 -0
  165. package/dist/util/shell.js +64 -0
  166. package/dist/util/size.js +32 -0
  167. package/dist/util/spinner.js +35 -0
  168. package/dist/util/strs.js +46 -0
  169. package/dist/util/table.js +18 -0
  170. package/dist/util/term.js +21 -0
  171. package/dist/util/time.js +16 -0
  172. package/dist/util/toml.js +28 -0
  173. package/{src → dist}/util/uris.js +8 -14
  174. package/dist/util/video.js +113 -0
  175. package/dist/util/zip.js +62 -0
  176. package/npm-shrinkwrap.json +3256 -0
  177. package/package.json +41 -39
  178. package/bin/arc-build.js +0 -139
  179. package/bin/arc-default.js +0 -65
  180. package/bin/arc-deploy.js +0 -456
  181. package/bin/arc-init.js +0 -187
  182. package/bin/arc-inspect.js +0 -97
  183. package/bin/arc-login.js +0 -165
  184. package/bin/arc-logout.js +0 -75
  185. package/bin/arc-open.js +0 -104
  186. package/bin/arc-pack.js +0 -146
  187. package/bin/arc-play.js +0 -140
  188. package/bin/arc-serve.js +0 -214
  189. package/bin/arc-validate.js +0 -112
  190. package/bin/arc-whoami.js +0 -119
  191. package/src/account.js +0 -249
  192. package/src/action/build/tool.js +0 -80
  193. package/src/action/deploy/tool-git.js +0 -90
  194. package/src/action/deploy/tool.js +0 -88
  195. package/src/action/deploy/wait.js +0 -151
  196. package/src/action/init/manifest.js +0 -83
  197. package/src/action/init/tool-patch.js +0 -32
  198. package/src/action/init/tool.js +0 -97
  199. package/src/action/inspect/tool.js +0 -26
  200. package/src/action/login/flow.js +0 -101
  201. package/src/action/login/tool.js +0 -16
  202. package/src/action/logout/tool.js +0 -15
  203. package/src/action/open/tool.js +0 -38
  204. package/src/action/pack/limits.js +0 -51
  205. package/src/action/pack/tool.js +0 -171
  206. package/src/action/pack/unsound.js +0 -69
  207. package/src/action/play/tool.js +0 -109
  208. package/src/action/predeploy/ac.js +0 -112
  209. package/src/action/predeploy/git.js +0 -223
  210. package/src/action/predeploy/pm.js +0 -37
  211. package/src/action/predeploy/published.js +0 -82
  212. package/src/action/predeploy/tool-git.js +0 -154
  213. package/src/action/predeploy/tool.js +0 -29
  214. package/src/action/serve/tool.js +0 -209
  215. package/src/action/validate/checked.js +0 -37
  216. package/src/action/validate/tool.js +0 -67
  217. package/src/action/validate/unknown.js +0 -86
  218. package/src/action/validate/unsound.js +0 -138
  219. package/src/action/whoami/tool.js +0 -15
  220. package/src/api.js +0 -163
  221. package/src/cli/build.js +0 -15
  222. package/src/cli/deploy.js +0 -21
  223. package/src/cli/init.js +0 -17
  224. package/src/cli/inspect.js +0 -15
  225. package/src/cli/login.js +0 -15
  226. package/src/cli/logout.js +0 -15
  227. package/src/cli/open.js +0 -15
  228. package/src/cli/pack.js +0 -15
  229. package/src/cli/play.js +0 -15
  230. package/src/cli/predeploy.js +0 -21
  231. package/src/cli/serve.js +0 -15
  232. package/src/cli/validate.js +0 -15
  233. package/src/cli/whoami.js +0 -15
  234. package/src/config/ai.js +0 -5
  235. package/src/config/art.js +0 -16
  236. package/src/config/audience.js +0 -5
  237. package/src/config/code.js +0 -142
  238. package/src/config/file.js +0 -23
  239. package/src/config/genre.js +0 -22
  240. package/src/config/image.js +0 -7
  241. package/src/config/input.js +0 -14
  242. package/src/config/limit.js +0 -21
  243. package/src/config/orientation.js +0 -14
  244. package/src/config/package.js +0 -5
  245. package/src/config/product.js +0 -5
  246. package/src/config/template.js +0 -45
  247. package/src/config/uri.js +0 -27
  248. package/src/config/url.js +0 -20
  249. package/src/config/video.js +0 -7
  250. package/src/config/visibility.js +0 -5
  251. package/src/config/workflow.js +0 -18
  252. package/src/parser/env.js +0 -84
  253. package/src/parser/given.js +0 -17
  254. package/src/parser/manifest.js +0 -80
  255. package/src/parser/media.js +0 -90
  256. package/src/parser/project.js +0 -166
  257. package/src/parser/readme-file.js +0 -76
  258. package/src/parser/readme.js +0 -96
  259. package/src/parser/sections.js +0 -107
  260. package/src/parser/self.js +0 -27
  261. package/src/phrase.js +0 -1294
  262. package/src/schema/check/game.js +0 -61
  263. package/src/schema/check/workflow.js +0 -99
  264. package/src/schema/game.js +0 -649
  265. package/src/schema/message.js +0 -85
  266. package/src/schema/readme.js +0 -44
  267. package/src/schema/workflow.js +0 -150
  268. package/src/serve/files.js +0 -61
  269. package/src/serve/game.js +0 -191
  270. package/src/serve/page.js +0 -345
  271. package/src/serve/reload.js +0 -68
  272. package/src/serve/remote.js +0 -121
  273. package/src/serve/server.js +0 -128
  274. package/src/util/argv.js +0 -116
  275. package/src/util/bytes.js +0 -25
  276. package/src/util/chars.js +0 -30
  277. package/src/util/command.js +0 -18
  278. package/src/util/delay.js +0 -52
  279. package/src/util/doc.js +0 -72
  280. package/src/util/error.js +0 -50
  281. package/src/util/http.js +0 -25
  282. package/src/util/image.js +0 -93
  283. package/src/util/links.js +0 -78
  284. package/src/util/lockfile.js +0 -35
  285. package/src/util/log.js +0 -149
  286. package/src/util/md.js +0 -61
  287. package/src/util/media.js +0 -40
  288. package/src/util/objs.js +0 -45
  289. package/src/util/os.js +0 -27
  290. package/src/util/output.js +0 -174
  291. package/src/util/paths.js +0 -21
  292. package/src/util/progress.js +0 -85
  293. package/src/util/promise.js +0 -29
  294. package/src/util/rc.js +0 -144
  295. package/src/util/request.js +0 -89
  296. package/src/util/s3.js +0 -92
  297. package/src/util/schema.js +0 -189
  298. package/src/util/screenshot.js +0 -37
  299. package/src/util/shell.js +0 -84
  300. package/src/util/size.js +0 -53
  301. package/src/util/spinner.js +0 -52
  302. package/src/util/strs.js +0 -73
  303. package/src/util/term.js +0 -28
  304. package/src/util/time.js +0 -29
  305. package/src/util/toml.js +0 -14
  306. package/src/util/video.js +0 -157
  307. package/src/util/zip.js +0 -88
  308. /package/{src/serve → assets}/favicon.ico +0 -0
@@ -0,0 +1,15 @@
1
+ // arc function secret: a function's secrets, the values a game's function
2
+ // needs and its repository mustn't hold. `set` takes the value from standard
3
+ // input, or asks for it at a terminal, so it's never an argument, in a
4
+ // shell's history or a process list.
5
+ // [import]
6
+ import { defineCommand } from "../../../cli/command.js";
7
+ import list from "./list.js";
8
+ import remove from "./remove.js";
9
+ import set from "./set.js";
10
+ // [export]
11
+ export default defineCommand({
12
+ commands: [set, list, remove],
13
+ name: "secret",
14
+ summary: "Set, list, and remove the function's secrets",
15
+ });
@@ -0,0 +1,27 @@
1
+ // [import]
2
+ import { defineCommand } from "../../../cli/command.js";
3
+ import { secretNone } from "../../../phrase/index.js";
4
+ import { p } from "../../../util/log.js";
5
+ import { CHANNEL_SHOWS, CWD, JSON_OUTPUT, QUIET, } from "../../../cli/options.js";
6
+ import { run } from "./run.js";
7
+ import { day, table } from "../../../util/table.js";
8
+ import { list } from "../../../action/secret/tool.js";
9
+ // [function]
10
+ // the secrets as a table, a row each.
11
+ function rows(secrets) {
12
+ return table([
13
+ ["NAME", "CHANNEL", "SET"],
14
+ ...secrets.map((each) => [each.name, each.channel, day(each.updated_at)]),
15
+ ]);
16
+ }
17
+ // [export]
18
+ export default defineCommand({
19
+ name: "list",
20
+ options: { ...CHANNEL_SHOWS, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
21
+ run(argv, aborting) {
22
+ return run(argv, aborting, list, (secrets) => {
23
+ p(secrets.length ? rows(secrets) : secretNone());
24
+ });
25
+ },
26
+ summary: "List the game's secrets, never their values",
27
+ });
@@ -0,0 +1,8 @@
1
+ // [import]
2
+ // [declare]
3
+ // `<name>`, of the commands that take one secret.
4
+ export const NAME = {
5
+ describe: "The secret's name, as the manifest declares it",
6
+ required: true,
7
+ type: "string",
8
+ };
@@ -0,0 +1,26 @@
1
+ // [import]
2
+ import { defineCommand } from "../../../cli/command.js";
3
+ import { secretRemoved, secretRemoveQuestion } from "../../../phrase/index.js";
4
+ import { p } from "../../../util/log.js";
5
+ import { NAME } from "./name.js";
6
+ import { CHANNEL, CWD, JSON_OUTPUT, QUIET, YES } from "../../../cli/options.js";
7
+ import { run } from "./run.js";
8
+ import { remove } from "../../../action/secret/tool.js";
9
+ // [export]
10
+ export default defineCommand({
11
+ name: "remove",
12
+ options: { ...CHANNEL, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD, yes: YES },
13
+ positionals: { name: NAME },
14
+ run(argv, aborting) {
15
+ return run(argv, aborting, (current, conf) => remove(current, { ...conf, name: argv.name }), (gone) => {
16
+ p(secretRemoved(gone));
17
+ }, `arc function secret remove ${argv.name}`, (where) => ({
18
+ question: secretRemoveQuestion({
19
+ channel: String(where),
20
+ name: argv.name,
21
+ }),
22
+ usage: `arc function secret remove ${argv.name} --${where}`,
23
+ }));
24
+ },
25
+ summary: "Remove a secret",
26
+ });
@@ -0,0 +1,52 @@
1
+ // what `arc function secret`'s commands share: running one as the logged-in
2
+ // account.
3
+ // [import]
4
+ import { resolve as resolvePath } from "node:path";
5
+ // [import]
6
+ import { ended } from "../../../account.js";
7
+ import { of } from "../../../cli/channel.js";
8
+ import { sure, } from "../../../cli/confirm.js";
9
+ import { confirmDeclined } from "../../../phrase/index.js";
10
+ import { p } from "../../../util/log.js";
11
+ import { print } from "../../../util/output.js";
12
+ import { SpinnerWheel } from "../../../util/spinner.js";
13
+ import { whoami } from "../../../action/whoami/tool.js";
14
+ // [function]
15
+ // runs one command as the logged-in account, and prints what `shown` makes
16
+ // of its result. `usage` is the command as it's typed, for one that changes
17
+ // something, which then needs a channel. `question(channel)` is asked first,
18
+ // for one that can't be undone (src/cli/confirm.ts). A session that was
19
+ // refused is refreshed, so the failure says to log in again.
20
+ export async function run(argv, aborting, command, shown, usage = null, question = null) {
21
+ const json = argv.json;
22
+ const quiet = argv.quiet;
23
+ const sw = new SpinnerWheel("Checking… %s");
24
+ aborting.sw = sw;
25
+ const handler = {
26
+ onAccountRefresh(refresh) {
27
+ sw.start(json || quiet);
28
+ return refresh();
29
+ },
30
+ };
31
+ // the channel first, so a command given none says so before anything else
32
+ const where = of(argv, usage);
33
+ if (question && !(await sure(argv, question(where)))) {
34
+ // a no at the prompt changes nothing, and isn't a failure
35
+ if (!quiet) {
36
+ p(confirmDeclined());
37
+ }
38
+ return;
39
+ }
40
+ const current = await whoami({}, handler);
41
+ sw.stop(true);
42
+ const result = await command(current, {
43
+ channel: where,
44
+ root: resolvePath(process.cwd(), argv.cwd),
45
+ }).catch(ended(current));
46
+ if (json) {
47
+ print(result);
48
+ }
49
+ else if (!quiet) {
50
+ shown(result);
51
+ }
52
+ }
@@ -0,0 +1,48 @@
1
+ // [import]
2
+ import { password } from "@inquirer/prompts";
3
+ // [import]
4
+ import { defineCommand } from "../../../cli/command.js";
5
+ import { secretPrompt, secretSet } from "../../../phrase/index.js";
6
+ import { p } from "../../../util/log.js";
7
+ import { NAME } from "./name.js";
8
+ import { CHANNEL, CWD, JSON_OUTPUT, QUIET } from "../../../cli/options.js";
9
+ import { run } from "./run.js";
10
+ import { set } from "../../../action/secret/tool.js";
11
+ // [function]
12
+ // a secret's value: typed at a terminal, unseen, or all of standard input,
13
+ // without the line end a shell's `echo` adds. With `--json` there's no one
14
+ // to ask (src/cli/confirm.ts), so at a terminal it's no value, which fails
15
+ // as an empty standard input does.
16
+ function valueOf(name, json) {
17
+ if (process.stdin.isTTY) {
18
+ return json
19
+ ? Promise.resolve("")
20
+ : password({ mask: true, message: secretPrompt(name) });
21
+ }
22
+ return new Promise((resolve, reject) => {
23
+ const chunks = [];
24
+ process.stdin.on("data", (chunk) => chunks.push(chunk));
25
+ process.stdin.on("error", reject);
26
+ process.stdin.on("end", () => {
27
+ resolve(Buffer.concat(chunks)
28
+ .toString("utf8")
29
+ .replace(/\r?\n$/u, ""));
30
+ });
31
+ });
32
+ }
33
+ // [export]
34
+ export default defineCommand({
35
+ name: "set",
36
+ options: { ...CHANNEL, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
37
+ positionals: { name: NAME },
38
+ run(argv, aborting) {
39
+ return run(argv, aborting, (current, conf) => set(current, {
40
+ ...conf,
41
+ name: argv.name,
42
+ value: () => valueOf(argv.name, argv.json),
43
+ }), (kept) => {
44
+ p(secretSet(kept));
45
+ }, `arc function secret set ${argv.name}`);
46
+ },
47
+ summary: "Set a secret, its value from standard input",
48
+ });
@@ -0,0 +1,40 @@
1
+ // [import]
2
+ import { defineCommand } from "../../cli/command.js";
3
+ import { functionMonth, functionState } from "../../phrase/index.js";
4
+ import { p } from "../../util/log.js";
5
+ import { CHANNEL_SHOWS, CWD, JSON_OUTPUT, QUIET } from "../../cli/options.js";
6
+ import { run } from "./run.js";
7
+ import { table } from "../../util/table.js";
8
+ import { status } from "../../action/function/tool.js";
9
+ // [function]
10
+ // a count as it's read: 1,000,000.
11
+ function count(value) {
12
+ return value.toLocaleString("en-US");
13
+ }
14
+ // [function]
15
+ // each channel's function as a table, a row each.
16
+ function rows(channels) {
17
+ return table([
18
+ ["CHANNEL", "STATUS", "REQUESTS"],
19
+ ...channels.map((each) => [
20
+ each.channel,
21
+ functionState(each),
22
+ count(each.requests),
23
+ ]),
24
+ ]);
25
+ }
26
+ // [export]
27
+ export default defineCommand({
28
+ name: "status",
29
+ options: { ...CHANNEL_SHOWS, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
30
+ run(argv, aborting) {
31
+ return run(argv, aborting, status, ({ channels, month }) => {
32
+ p(rows(channels));
33
+ p(functionMonth({
34
+ allowance: month.allowance === null ? null : count(month.allowance),
35
+ requests: count(month.requests),
36
+ }));
37
+ });
38
+ },
39
+ summary: "Show whether the game's function is running, and its usage this month",
40
+ });
@@ -0,0 +1,128 @@
1
+ // [import]
2
+ import { resolve } from "node:path";
3
+ // [import]
4
+ import fs from "fs-extra";
5
+ import { select } from "@inquirer/prompts";
6
+ // [import]
7
+ import { TEMPLATE_MISSING } from "../config/code.js";
8
+ import { defineCommand } from "../cli/command.js";
9
+ import { ArcError } from "../util/error.js";
10
+ import { initialized, initializedNoStarter, templateMissing, } from "../phrase/index.js";
11
+ import { hs, p } from "../util/log.js";
12
+ import { CWD, JSON_OUTPUT, QUIET } from "../cli/options.js";
13
+ import { print } from "../util/output.js";
14
+ import { SpinnerWheel } from "../util/spinner.js";
15
+ import { choices, fallback, message } from "../config/template.js";
16
+ import { initTool } from "../action/init/tool.js";
17
+ import { initToolPatch } from "../action/init/tool-patch.js";
18
+ // [use]
19
+ const pathExists = fs.pathExists;
20
+ // [function]
21
+ function handler({ json, quiet, sw, }) {
22
+ return {
23
+ onInitBegin() {
24
+ sw.start(json || quiet);
25
+ },
26
+ };
27
+ }
28
+ // [function]
29
+ function patch(cwd, project) {
30
+ // project may be absolute, as action/init/tool.ts resolves it.
31
+ return pathExists(resolve(process.cwd(), cwd, project));
32
+ }
33
+ // [function]
34
+ async function prompt({ cwd, project, template, yes, }) {
35
+ const patched = await patch(cwd, project);
36
+ if (patched || yes) {
37
+ return { patch: patched, template: template ?? fallback };
38
+ }
39
+ if (!template) {
40
+ // without a terminal, the prompt would read end-of-input and exit.
41
+ if (!process.stdin.isTTY) {
42
+ throw new ArcError(TEMPLATE_MISSING, templateMissing());
43
+ }
44
+ const answer = await select({
45
+ choices,
46
+ default: fallback,
47
+ message,
48
+ });
49
+ return { patch: patched, template: answer };
50
+ }
51
+ return { patch: patched, template };
52
+ }
53
+ // [function]
54
+ // whether a prompt ended because it was cancelled (Ctrl+C).
55
+ function cancelled(ex) {
56
+ return ex instanceof Error && ex.name === "ExitPromptError";
57
+ }
58
+ // [export]
59
+ export default defineCommand({
60
+ name: "init",
61
+ options: {
62
+ template: {
63
+ alias: "t",
64
+ describe: [
65
+ "Project template",
66
+ "Public GitHub repository, or a folder in one (user/repo[/folder])",
67
+ ].join("\n"),
68
+ rc: true,
69
+ type: "string",
70
+ },
71
+ yes: {
72
+ alias: "y",
73
+ default: false,
74
+ describe: "Accept prompt defaults",
75
+ rc: true,
76
+ type: "boolean",
77
+ },
78
+ json: JSON_OUTPUT,
79
+ quiet: QUIET,
80
+ cwd: CWD,
81
+ },
82
+ positionals: {
83
+ project: {
84
+ default: ".",
85
+ describe: "Project directory",
86
+ rc: true,
87
+ type: "string",
88
+ },
89
+ },
90
+ async run(argv, aborting) {
91
+ const json = argv.json;
92
+ const quiet = argv.quiet;
93
+ // a string from the command line; `.arcrc` can give anything.
94
+ const project = String(argv.project);
95
+ const prompted = await prompt({
96
+ cwd: argv.cwd,
97
+ project,
98
+ template: argv.template,
99
+ yes: argv.yes,
100
+ }).catch((ex) => {
101
+ if (cancelled(ex)) {
102
+ process.exit(130);
103
+ }
104
+ throw ex;
105
+ });
106
+ const sw = new SpinnerWheel("Initializing… %s");
107
+ aborting.sw = sw;
108
+ const conf = { project, root: resolve(process.cwd(), argv.cwd) };
109
+ const handlers = handler({ json, quiet, sw });
110
+ const made = prompted.patch
111
+ ? await initToolPatch(conf, handlers)
112
+ : await initTool({ ...conf, template: String(prompted.template) }, handlers);
113
+ if (json) {
114
+ print({ project: made });
115
+ }
116
+ else if (!quiet) {
117
+ sw.stop(true);
118
+ hs(initialized());
119
+ if (prompted.patch) {
120
+ p(initializedNoStarter());
121
+ }
122
+ print(made, { nl: true, toml: true });
123
+ }
124
+ // degit sometimes hangs, so exit once stdout is written.
125
+ return 0;
126
+ },
127
+ summary: "Initialize a project",
128
+ });
@@ -0,0 +1,38 @@
1
+ // [import]
2
+ import { resolve } from "node:path";
3
+ // [import]
4
+ import { defineCommand } from "../cli/command.js";
5
+ import { CWD, JSON_OUTPUT, QUIET } from "../cli/options.js";
6
+ import { print } from "../util/output.js";
7
+ import { inspectTool } from "../action/inspect/tool.js";
8
+ // [export]
9
+ export default defineCommand({
10
+ name: "inspect",
11
+ options: { json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
12
+ positionals: {
13
+ selector: {
14
+ default: null,
15
+ describe: "Property selector",
16
+ rc: true,
17
+ type: "string",
18
+ },
19
+ },
20
+ async run(argv) {
21
+ // a string from the command line; `.arcrc` can give anything.
22
+ const selector = argv.selector == null ? null : String(argv.selector);
23
+ const data = await inspectTool({
24
+ root: resolve(process.cwd(), argv.cwd),
25
+ selector,
26
+ });
27
+ if (argv.json) {
28
+ print(data);
29
+ return;
30
+ }
31
+ // with --quiet, whether the project can be read is the exit code's to
32
+ // say.
33
+ if (!argv.quiet) {
34
+ print(data, { key: selector, toml: true });
35
+ }
36
+ },
37
+ summary: "Print the resolved manifest",
38
+ });
@@ -0,0 +1,108 @@
1
+ // [import]
2
+ import qrcode from "qrcode-terminal";
3
+ // [import]
4
+ import { defineCommand } from "../cli/command.js";
5
+ import { LOGIN_FAILED } from "../config/code.js";
6
+ import { ArcError } from "../util/error.js";
7
+ import { loggedIn, loggingIn, loginFailed, pressEnterToOpen, } from "../phrase/index.js";
8
+ import { h, nlp, p, result } from "../util/log.js";
9
+ import { title } from "../config/product.js";
10
+ import { launch } from "../util/shell.js";
11
+ import { SpinnerWheel } from "../util/spinner.js";
12
+ import { login } from "../action/login/tool.js";
13
+ // [function]
14
+ function onLoginEnter(fn) {
15
+ const stdin = process.stdin;
16
+ if (!stdin.isTTY) {
17
+ return;
18
+ }
19
+ const cleanup = function () {
20
+ stdin.setRawMode(false);
21
+ stdin.pause();
22
+ stdin.removeAllListeners("data");
23
+ };
24
+ stdin.setRawMode(true);
25
+ stdin.resume();
26
+ stdin.once("data", (buf) => {
27
+ cleanup();
28
+ if (buf[0] === 3) {
29
+ process.kill(process.pid, "SIGINT");
30
+ return;
31
+ }
32
+ if (buf[0] === 13) {
33
+ fn();
34
+ }
35
+ });
36
+ }
37
+ // [function]
38
+ // `shown` is called once the link is printed, so a failure after it starts
39
+ // after a blank line.
40
+ function handler({ browser, qrcode: qr, shown, sw, }) {
41
+ return {
42
+ onLoginCreated({ code: dac, secret, url }) {
43
+ sw.stop(true);
44
+ shown();
45
+ const link = `${url}/${secret}`;
46
+ p(loggingIn());
47
+ qrcode.generate(link, { small: true }, (code) => {
48
+ if (qr) {
49
+ p(code);
50
+ }
51
+ nlp(url);
52
+ h(dac.toUpperCase());
53
+ // a key press can only be read from a terminal.
54
+ if (browser && process.stdin.isTTY) {
55
+ nlp(pressEnterToOpen());
56
+ onLoginEnter(() => {
57
+ void launch(link);
58
+ });
59
+ }
60
+ });
61
+ },
62
+ };
63
+ }
64
+ // [export]
65
+ export default defineCommand({
66
+ name: "login",
67
+ options: {
68
+ browser: {
69
+ default: true,
70
+ describe: "Open a web browser on Enter",
71
+ rc: true,
72
+ type: "boolean",
73
+ },
74
+ qrcode: {
75
+ default: true,
76
+ describe: "Show a QR code",
77
+ rc: true,
78
+ type: "boolean",
79
+ },
80
+ },
81
+ async run(argv, aborting) {
82
+ const sw = new SpinnerWheel("Logging in… %s");
83
+ aborting.sw = sw;
84
+ sw.start();
85
+ try {
86
+ const current = await login({}, handler({
87
+ browser: argv.browser,
88
+ qrcode: argv.qrcode,
89
+ shown() {
90
+ aborting.nl = true;
91
+ },
92
+ sw,
93
+ }));
94
+ const user = current?.user;
95
+ if (!user) {
96
+ throw new ArcError(LOGIN_FAILED, loginFailed());
97
+ }
98
+ sw.stop(true);
99
+ process.stdin.pause();
100
+ result(loggedIn(), [user.display_name], { nl: true });
101
+ }
102
+ catch (ex) {
103
+ process.stdin.pause();
104
+ throw ex;
105
+ }
106
+ },
107
+ summary: `Log in to ${title}`,
108
+ });
@@ -0,0 +1,24 @@
1
+ // [import]
2
+ import { defineCommand } from "../cli/command.js";
3
+ import { loggedOut } from "../phrase/index.js";
4
+ import { hs } from "../util/log.js";
5
+ import { JSON_OUTPUT, QUIET } from "../cli/options.js";
6
+ import { print } from "../util/output.js";
7
+ import { title } from "../config/product.js";
8
+ import { logout } from "../action/logout/tool.js";
9
+ // [export]
10
+ export default defineCommand({
11
+ name: "logout",
12
+ options: { json: JSON_OUTPUT, quiet: QUIET },
13
+ async run(argv) {
14
+ // the account it logged out of, or null when no one was logged in.
15
+ const user = await logout();
16
+ if (argv.json) {
17
+ print({ user });
18
+ }
19
+ else if (!argv.quiet) {
20
+ hs(loggedOut());
21
+ }
22
+ },
23
+ summary: `Log out of ${title}`,
24
+ });
@@ -0,0 +1,48 @@
1
+ // [import]
2
+ import { resolve } from "node:path";
3
+ // [import]
4
+ import { GAME_ID_MISSING } from "../config/code.js";
5
+ import { defineCommand } from "../cli/command.js";
6
+ import { ArcError } from "../util/error.js";
7
+ import { gameIdMissing } from "../phrase/index.js";
8
+ import { BROWSER, CWD, JSON_OUTPUT, QUIET } from "../cli/options.js";
9
+ import { launched, print } from "../util/output.js";
10
+ import { launch } from "../util/shell.js";
11
+ import { openTool } from "../action/open/tool.js";
12
+ import { HOST_APP_STORE } from "../config/uri.js";
13
+ // [export]
14
+ export default defineCommand({
15
+ name: "open",
16
+ options: { browser: BROWSER, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
17
+ positionals: {
18
+ game: {
19
+ default: "self",
20
+ describe: "Game handle or ID",
21
+ rc: true,
22
+ type: "string",
23
+ },
24
+ },
25
+ async run(argv) {
26
+ const data = await openTool({
27
+ // a string from the command line; `.arcrc` can give anything.
28
+ game: argv.game ? String(argv.game) : null,
29
+ root: resolve(process.cwd(), argv.cwd),
30
+ });
31
+ if (!data) {
32
+ throw new ArcError(GAME_ID_MISSING, gameIdMissing());
33
+ }
34
+ const { page, url } = data;
35
+ const where = await (argv.browser
36
+ ? launch(url)
37
+ : launch(`${HOST_APP_STORE}${page}`, url));
38
+ if (argv.json) {
39
+ // where it opened (app, browser, or null when it couldn't), and the
40
+ // store page's URL.
41
+ print({ opened: where, url });
42
+ }
43
+ else if (!argv.quiet) {
44
+ launched(where, url);
45
+ }
46
+ },
47
+ summary: "Open a game's store page",
48
+ });
@@ -0,0 +1,90 @@
1
+ // [import]
2
+ import path from "node:path";
3
+ // [import]
4
+ import { checked } from "../action/validate/checked.js";
5
+ import { defineCommand } from "../cli/command.js";
6
+ import { packed as packedHeading } from "../phrase/index.js";
7
+ import { hs, pw } from "../util/log.js";
8
+ import { CWD, JSON_OUTPUT, QUIET } from "../cli/options.js";
9
+ import { print, warn, warning } from "../util/output.js";
10
+ import { SpinnerWheel } from "../util/spinner.js";
11
+ import { packTool } from "../action/pack/tool.js";
12
+ // [use]
13
+ const resolve = path.resolve;
14
+ // [function]
15
+ // a path option's value: `.arcrc` can set it, to a string, or to anything in
16
+ // JSON, which is read as text. None is null.
17
+ function pathOf(value) {
18
+ return (value ?? null) === null ? null : String(value);
19
+ }
20
+ // [export]
21
+ export default defineCommand({
22
+ name: "pack",
23
+ options: {
24
+ input: {
25
+ alias: "i",
26
+ default: null,
27
+ describe: "Pack this directory instead of deploy_dir",
28
+ rc: true,
29
+ type: "string",
30
+ },
31
+ output: {
32
+ alias: "o",
33
+ default: null,
34
+ describe: "Write the zip to this path",
35
+ rc: true,
36
+ type: "string",
37
+ },
38
+ json: JSON_OUTPUT,
39
+ quiet: QUIET,
40
+ cwd: CWD,
41
+ },
42
+ async run(argv, aborting) {
43
+ const json = argv.json;
44
+ const quiet = argv.quiet;
45
+ const root = resolve(process.cwd(), argv.cwd);
46
+ // what --json lists under `warnings`: arc validate's, then the package's.
47
+ let warnings = [];
48
+ aborting.data = { warnings };
49
+ const packed = [];
50
+ let sw = new SpinnerWheel("Validating… %s");
51
+ aborting.sw = sw;
52
+ sw.start(json || quiet);
53
+ // the project, parsed once for both steps.
54
+ const parsed = await checked(root, (found) => {
55
+ warnings = found;
56
+ aborting.data = { warnings };
57
+ });
58
+ sw.stop(true);
59
+ warn(warnings, { json, quiet });
60
+ sw = new SpinnerWheel("Packing… %s");
61
+ aborting.sw = sw;
62
+ sw.start(json || quiet);
63
+ const artifact = await packTool({
64
+ input: pathOf(argv.input),
65
+ // the package's own, printed once it's packed.
66
+ onWarning({ code, message }) {
67
+ packed.push(warning(code, message));
68
+ },
69
+ output: pathOf(argv.output),
70
+ project: parsed,
71
+ root,
72
+ });
73
+ warnings = [...warnings, ...packed];
74
+ aborting.data = { warnings };
75
+ if (!json && !quiet && packed.length) {
76
+ sw.stop(true);
77
+ packed.forEach((each) => pw(each.message));
78
+ }
79
+ if (json) {
80
+ print({ artifact, warnings });
81
+ return;
82
+ }
83
+ if (!quiet) {
84
+ sw.stop(true);
85
+ hs(packedHeading());
86
+ print(artifact, { nl: true, toml: true });
87
+ }
88
+ },
89
+ summary: "Pack the game into a zip",
90
+ });