arcadible 1.0.22 → 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 +2 -1
  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 +42 -40
  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
@@ -1,85 +0,0 @@
1
- "use strict";
2
-
3
- // [import]
4
-
5
- const util = require("node:util");
6
-
7
- // [import]
8
-
9
- const chalk = require("chalk");
10
-
11
- // [import]
12
-
13
- const cfgurl = require("../config/url");
14
- const strs = require("../util/strs");
15
-
16
- // [use]
17
-
18
- const indentLines = strs.indentLines;
19
- const stripVTControlCharacters = util.stripVTControlCharacters;
20
-
21
- // [declare]
22
-
23
- // fields the CLI checks but the docs leave out until they ship, so their
24
- // issues have no link: `price`, until paid games do (ONE.md).
25
- const UNDOCUMENTED = new Set(["game.price"]);
26
-
27
- // [function]
28
-
29
- // the URL of a field's rules in the manifest reference, e.g. #game.title,
30
- // or null for an undocumented field.
31
- const link = function (table, field) {
32
- if (UNDOCUMENTED.has(`${table}.${field}`)) {
33
- return null;
34
- }
35
- return `${cfgurl.MANIFEST}#${table}.${field}`;
36
- };
37
-
38
- // [function]
39
-
40
- // `link`, as it's printed.
41
- const reference = function (table, field) {
42
- const url = link(table, field);
43
- return url && chalk.cyan.underline(url);
44
- };
45
-
46
- // [function]
47
-
48
- // an issue's message: the first line, then any detail lines and the field's
49
- // reference, indented beneath it. `code` is the rule's, from ISSUE in
50
- // config/code.js, which zod keeps in the issue's params.
51
- const message = function (table, field, lines, code) {
52
- const [first, ...rest] = [...lines, reference(table, field)].filter(
53
- (line) => line !== null,
54
- );
55
- return {
56
- message:
57
- [first, ...rest].length > 1
58
- ? [first, indentLines(rest.join("\n"))].join("\n")
59
- : first,
60
- ...(code ? { params: { code } } : {}),
61
- };
62
- };
63
-
64
- // [function]
65
-
66
- // `message`'s text back into its first line and details, without the
67
- // reference.
68
- const parse = function (text) {
69
- const [first, ...rest] = text.split("\n");
70
- const details = rest
71
- .map((line) => stripVTControlCharacters(line).trim())
72
- .filter((line) => !line.startsWith(cfgurl.MANIFEST));
73
- return { details, message: stripVTControlCharacters(first) };
74
- };
75
-
76
- // [function]
77
-
78
- // `message` for one table, e.g. messages("game")("title", ["Too long."]).
79
- const messages = function (table) {
80
- return (field, lines, code) => message(table, field, lines, code);
81
- };
82
-
83
- // [export]
84
-
85
- module.exports = { UNDOCUMENTED, link, message, messages, parse, reference };
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- // [import]
4
-
5
- const z = require("zod");
6
-
7
- // [import]
8
-
9
- const cfgcode = require("../config/code");
10
- const schemaMessage = require("./message");
11
-
12
- // [declare]
13
-
14
- const message = schemaMessage.messages("game");
15
-
16
- // [function]
17
-
18
- // the README's structure, from sections.split: anything after the title,
19
- // tagline, and bio must be framed by two `---` rules, the first and last of
20
- // which bound the description. Issues are reported on game.description.
21
- const main = function (value, { file }) {
22
- return z
23
- .object({ rules: z.number(), trailing: z.boolean() })
24
- .superRefine(({ rules, trailing }, ctx) => {
25
- if (trailing && rules < 2) {
26
- ctx.addIssue({
27
- code: "custom",
28
- path: ["description"],
29
- ...message(
30
- "description",
31
- [
32
- "Needs two --- rules around the description.",
33
- `${file} has content after its title, tagline, and bio.`,
34
- ],
35
- cfgcode.ISSUE.DESCRIPTION_RULES_MISSING,
36
- ),
37
- });
38
- }
39
- });
40
- };
41
-
42
- // [export]
43
-
44
- module.exports = main;
@@ -1,150 +0,0 @@
1
- "use strict";
2
-
3
- // [import]
4
-
5
- const z = require("zod");
6
-
7
- // [import]
8
-
9
- const cfgcode = require("../config/code");
10
- const cfgfile = require("../config/file");
11
- const cfgproduct = require("../config/product");
12
- const check = require("./check/workflow");
13
- const commands = require("../util/command");
14
- const phrase = require("../phrase");
15
- const schemaMessage = require("./message");
16
-
17
- // [use]
18
-
19
- const avoidsCheck = check.avoids;
20
- const buildCommand = commands.buildCommand;
21
- const ISSUE = cfgcode.ISSUE;
22
- const existsCheck = check.exists;
23
- const hasFileCheck = check.hasFile;
24
- const isInsideCheck = check.isInside;
25
- const isRelativeCheck = check.isRelative;
26
- const isRootCheck = check.isRoot;
27
- const lacksFilesCheck = check.lacksFiles;
28
- const lacksFolderCheck = check.lacksFolder;
29
-
30
- // [declare]
31
-
32
- const message = schemaMessage.messages("workflow");
33
- const MEDIA = cfgfile.MEDIA;
34
- const INDEX = "index.html";
35
- const RESERVED = [cfgfile.PACKAGED, MEDIA];
36
- // the folder every build's origin keeps for Arcadible's own files, such as
37
- // the script games include. arc pack checks it again after the build.
38
- const RESERVED_FOLDER = cfgproduct.handle;
39
-
40
- // [function]
41
-
42
- // whether `build` runs anything, as `arc build` runs it.
43
- const hasBuild = function (build) {
44
- return buildCommand(build) !== "";
45
- };
46
-
47
- // [function]
48
-
49
- // a value of neither type says what the matching kind expected, a list's for
50
- // a list and a string's otherwise, not the union's bare "Invalid input".
51
- const typeMessage = function (issue) {
52
- const branch = Array.isArray(issue.input) ? 1 : 0;
53
- return issue.errors?.[branch]?.[0]?.message;
54
- };
55
-
56
- // [function]
57
-
58
- const zBuild = function () {
59
- return z.union([z.string(), z.array(z.string())], { error: typeMessage });
60
- };
61
-
62
- // [function]
63
-
64
- // a directory inside the project with an index.html. Each check aborts the
65
- // rest when it fails, so one bad path gets one issue.
66
- const zDeployDir = function (root, { build }) {
67
- const field = "deploy_dir";
68
- return z
69
- .string()
70
- .min(1, {
71
- ...message(field, ["Must not be empty.", "Leave the field out instead."]),
72
- abort: true,
73
- })
74
- .refine((file) => isRelativeCheck(root, file), {
75
- ...message(field, ["Must be a relative path."], ISSUE.PATH_INVALID),
76
- abort: true,
77
- })
78
- .refine((file) => isInsideCheck(root, file), {
79
- ...message(field, ["Must be within the project."], ISSUE.PATH_INVALID),
80
- abort: true,
81
- })
82
- .refine((file) => !isRootCheck(root, file), {
83
- ...message(
84
- field,
85
- ["Must be a folder in the project, not its root."],
86
- ISSUE.PATH_INVALID,
87
- ),
88
- abort: true,
89
- })
90
- .refine((file) => avoidsCheck(root, file, MEDIA), {
91
- ...message(field, [`Must not be in ${MEDIA}.`], ISSUE.PATH_INVALID),
92
- abort: true,
93
- })
94
- .refine((file) => hasBuild(build) || existsCheck(root, file), {
95
- ...message(
96
- field,
97
- [
98
- "Must exist, since there's no build.",
99
- `Run ${phrase.cmdInspect()} for details.`,
100
- ],
101
- ISSUE.PATH_INVALID,
102
- ),
103
- abort: true,
104
- })
105
- .refine((file) => hasFileCheck(root, file, INDEX), {
106
- ...message(
107
- field,
108
- [`Must have an ${INDEX} at its root.`],
109
- ISSUE.INDEX_MISSING,
110
- ),
111
- abort: true,
112
- })
113
- .refine((file) => lacksFilesCheck(root, file, RESERVED), {
114
- ...message(
115
- field,
116
- [
117
- `Must not have ${RESERVED.join(" or ")} at its root.`,
118
- `They're reserved for the files ${cfgproduct.title} adds.`,
119
- ],
120
- ISSUE.PATH_INVALID,
121
- ),
122
- abort: true,
123
- })
124
- .refine((file) => lacksFolderCheck(root, file, RESERVED_FOLDER), {
125
- ...message(
126
- field,
127
- [
128
- `Must not have an ${RESERVED_FOLDER} folder at its root, in any letter case.`,
129
- `It's reserved for ${cfgproduct.title}'s own files.`,
130
- ],
131
- ISSUE.PATH_INVALID,
132
- ),
133
- abort: true,
134
- });
135
- };
136
-
137
- // [function]
138
-
139
- const main = function (value, { root }) {
140
- /* eslint-disable camelcase */
141
- return z.object({
142
- build: zBuild(),
143
- deploy_dir: zDeployDir(root, value),
144
- });
145
- /* eslint-enable camelcase */
146
- };
147
-
148
- // [export]
149
-
150
- module.exports = main;
@@ -1,61 +0,0 @@
1
- "use strict";
2
- // a game's files, read as Arcadible reads them from storage: by exact path,
3
- // letter case included, even on a disk that ignores it, such as a Mac's. The
4
- // server reads through `find`, so another source, such as a packed game,
5
- // can stand in for a folder.
6
-
7
- // [import]
8
-
9
- const fs = require("node:fs");
10
- const path = require("node:path");
11
-
12
- // [use]
13
-
14
- const createReadStream = fs.createReadStream;
15
- const join = path.join;
16
- const readdir = fs.promises.readdir;
17
- const stat = fs.promises.stat;
18
-
19
- // [function]
20
-
21
- // whether every segment of `segments` is named exactly so in `root`.
22
- const exactCase = async function (root, segments) {
23
- const found = await Promise.all(
24
- segments.map((segment, i) =>
25
- readdir(join(root, ...segments.slice(0, i))).then((names) =>
26
- names.includes(segment),
27
- ),
28
- ),
29
- );
30
- return found.every(Boolean);
31
- };
32
-
33
- // [function]
34
-
35
- // the files in `root`. `find(segments)` resolves with the file at that path,
36
- // as `{ size, mtime, open({ start, end }) }`, or null when there's none, or
37
- // it's a folder.
38
- const dirFiles = function (root) {
39
- return {
40
- async find(segments) {
41
- const file = join(root, ...segments);
42
- try {
43
- const info = await stat(file);
44
- if (!info.isFile() || !(await exactCase(root, segments))) {
45
- return null;
46
- }
47
- return {
48
- mtime: info.mtime,
49
- open: (range) => createReadStream(file, range),
50
- size: info.size,
51
- };
52
- } catch (ex) {
53
- return null;
54
- }
55
- },
56
- };
57
- };
58
-
59
- // [export]
60
-
61
- module.exports = { dirFiles };
package/src/serve/game.js DELETED
@@ -1,191 +0,0 @@
1
- "use strict";
2
- // the game's origin, as Arcadible's router and storage answer it
3
- // (app/src/cloudfront/io-arcadible-router): a path ending in / gets its
4
- // index.html, a path is found only with its exact letter case, /arcadible/
5
- // holds only Arcadible's own files, and each file has the type the release
6
- // pipeline gives it. The headers are the build origin's, but nothing is
7
- // cached, so a change shows on reload.
8
-
9
- // [import]
10
-
11
- const http = require("node:http");
12
- const path = require("node:path");
13
-
14
- // [import]
15
-
16
- const mime = require("mime-types");
17
- const parseRange = require("range-parser");
18
-
19
- // [use]
20
-
21
- const extname = path.extname;
22
-
23
- // [declare]
24
-
25
- const RESERVED = "arcadible";
26
-
27
- // [function]
28
-
29
- // the path's segments, decoded, or null for one that can't be a file's:
30
- // undecodable, or `.`, `..`, or holding a separator.
31
- const segmentsOf = function (pathname) {
32
- const segments = pathname.slice(1).split("/");
33
- try {
34
- const decoded = segments.map(decodeURIComponent);
35
- const unsafe = decoded.some(
36
- (s, i) =>
37
- s === "." ||
38
- s === ".." ||
39
- /[/\\\0]/u.test(s) ||
40
- (s === "" && i < decoded.length - 1),
41
- );
42
- return unsafe ? null : decoded;
43
- } catch (ex) {
44
- return null;
45
- }
46
- };
47
-
48
- // [function]
49
-
50
- const plain = function (res, status, headers = {}) {
51
- res.writeHead(status, {
52
- "content-type": "text/plain; charset=utf-8",
53
- ...headers,
54
- });
55
- res.end(`${http.STATUS_CODES[status]}\n`);
56
- };
57
-
58
- // [function]
59
-
60
- // the headers every response from the game's origin has, as Arcadible's: the
61
- // game is cross-origin isolated, and only the play page can frame it.
62
- const baseHeaders = function (page) {
63
- return {
64
- "cache-control": "no-store",
65
- "content-security-policy": `frame-ancestors ${page};`,
66
- "cross-origin-embedder-policy": "require-corp",
67
- "cross-origin-resource-policy": "cross-origin",
68
- "referrer-policy": "strict-origin-when-cross-origin",
69
- };
70
- };
71
-
72
- // [function]
73
-
74
- // a file from `files`, whole or the one range asked for. A range that can't be
75
- // satisfied is a 416; several ranges, or a malformed one, get the whole file.
76
- const sendFile = function (req, res, file, headers) {
77
- const size = file.size;
78
- const ranges = req.headers.range ? parseRange(size, req.headers.range) : -2;
79
- if (ranges === -1) {
80
- res.writeHead(416, { ...headers, "content-range": `bytes */${size}` });
81
- res.end();
82
- return;
83
- }
84
- const single =
85
- Array.isArray(ranges) && ranges.length === 1 ? ranges[0] : null;
86
- const range = single ?? { end: size - 1, start: 0 };
87
- const length = size ? range.end - range.start + 1 : 0;
88
- res.writeHead(single ? 206 : 200, {
89
- ...headers,
90
- "accept-ranges": "bytes",
91
- "content-length": length,
92
- "last-modified": file.mtime.toUTCString(),
93
- ...(single
94
- ? { "content-range": `bytes ${range.start}-${range.end}/${size}` }
95
- : {}),
96
- });
97
- if (req.method === "HEAD" || !length) {
98
- res.end();
99
- return;
100
- }
101
- // the file can go between finding and reading it, as a rebuild empties
102
- // deploy_dir: the headers are sent, so the response just ends
103
- const stream = file.open(range);
104
- stream.on("error", () => {
105
- res.destroy();
106
- });
107
- stream.pipe(res);
108
- };
109
-
110
- // [function]
111
-
112
- // ends the response with `body`, or with none for a HEAD request.
113
- const endWith = function (req, res, body) {
114
- if (req.method === "HEAD") {
115
- res.end();
116
- return;
117
- }
118
- res.end(body);
119
- };
120
-
121
- // [function]
122
-
123
- // one of Arcadible's files under /arcadible/, from `remote`. `onRemote` hears
124
- // of each, to say when it's a kept copy or can't be had.
125
- const sendRemote = function (req, res, { headers, name, onRemote, remote }) {
126
- return remote
127
- .get(name)
128
- .then((file) => {
129
- onRemote(name, file);
130
- if (!file) {
131
- plain(res, 404, headers);
132
- return;
133
- }
134
- res.writeHead(200, {
135
- ...headers,
136
- "content-length": file.body.length,
137
- "content-type": file.type,
138
- });
139
- endWith(req, res, file.body);
140
- })
141
- .catch((ex) => {
142
- onRemote(name, null, ex);
143
- plain(res, 502, headers);
144
- });
145
- };
146
-
147
- // [function]
148
-
149
- // the request handler for the game's origin. `page` is the play page's
150
- // origin, the only one that may frame the game.
151
- const gameHandler = function ({ files, onRemote = () => null, page, remote }) {
152
- return function (req, res) {
153
- const headers = baseHeaders(page);
154
- if (req.method !== "GET" && req.method !== "HEAD") {
155
- plain(res, 405, { ...headers, allow: "GET, HEAD" });
156
- return Promise.resolve();
157
- }
158
- const segments = segmentsOf(new URL(req.url, "http://game").pathname);
159
- if (!segments) {
160
- plain(res, 404, headers);
161
- return Promise.resolve();
162
- }
163
- // /arcadible/, in any letter case, is Arcadible's: only its exact path
164
- // reaches Arcadible's files.
165
- if (segments[0].toLowerCase() === RESERVED && segments.length > 1) {
166
- if (segments[0] !== RESERVED) {
167
- plain(res, 404, headers);
168
- return Promise.resolve();
169
- }
170
- const name = segments.slice(1).join("/");
171
- return sendRemote(req, res, { headers, name, onRemote, remote });
172
- }
173
- if (segments.at(-1) === "") {
174
- segments[segments.length - 1] = "index.html";
175
- }
176
- return files.find(segments).then((file) => {
177
- if (!file) {
178
- plain(res, 404, headers);
179
- return;
180
- }
181
- const type =
182
- mime.contentType(extname(segments.at(-1))) ||
183
- "application/octet-stream";
184
- sendFile(req, res, file, { ...headers, "content-type": type });
185
- });
186
- };
187
- };
188
-
189
- // [export]
190
-
191
- module.exports = { endWith, gameHandler };