arcadible 1.0.23 → 1.0.25

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 (320) 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 +61 -0
  5. package/dist/action/delete/tool.js +47 -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 +49 -0
  10. package/dist/action/deploy/tool.js +49 -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 +62 -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 +88 -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 +30 -0
  23. package/dist/action/pack/limits.js +46 -0
  24. package/dist/action/pack/tool.js +148 -0
  25. package/dist/action/pack/unsound.js +51 -0
  26. package/dist/action/play/tool.js +84 -0
  27. package/dist/action/predeploy/ac.js +75 -0
  28. package/dist/action/predeploy/game.js +6 -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 +103 -0
  34. package/dist/action/predeploy/tool.js +14 -0
  35. package/dist/action/secret/tool.js +91 -0
  36. package/dist/action/serve/tool.js +270 -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/value/tool.js +216 -0
  42. package/dist/action/whoami/tool.js +7 -0
  43. package/dist/api.js +312 -0
  44. package/dist/arc.js +41 -0
  45. package/dist/cli/argv.js +61 -0
  46. package/dist/cli/channel.js +29 -0
  47. package/dist/cli/command.js +163 -0
  48. package/dist/cli/confirm.js +39 -0
  49. package/dist/cli/options.js +62 -0
  50. package/dist/cli/rc.js +103 -0
  51. package/dist/cli/yargs.js +40 -0
  52. package/dist/command/build.js +68 -0
  53. package/dist/command/delete.js +66 -0
  54. package/dist/command/deploy.js +308 -0
  55. package/dist/command/function/index.js +17 -0
  56. package/dist/command/function/pause.js +18 -0
  57. package/dist/command/function/resume.js +18 -0
  58. package/dist/command/function/run.js +41 -0
  59. package/dist/command/function/secret/index.js +15 -0
  60. package/dist/command/function/secret/list.js +27 -0
  61. package/dist/command/function/secret/name.js +8 -0
  62. package/dist/command/function/secret/remove.js +26 -0
  63. package/dist/command/function/secret/run.js +52 -0
  64. package/dist/command/function/secret/set.js +48 -0
  65. package/dist/command/function/status.js +40 -0
  66. package/dist/command/init.js +128 -0
  67. package/dist/command/inspect.js +39 -0
  68. package/dist/command/login.js +108 -0
  69. package/dist/command/logout.js +24 -0
  70. package/dist/command/open.js +49 -0
  71. package/dist/command/pack.js +90 -0
  72. package/dist/command/play.js +81 -0
  73. package/dist/command/serve.js +177 -0
  74. package/dist/command/server/index.js +17 -0
  75. package/dist/command/server/key/create.js +36 -0
  76. package/dist/command/server/key/index.js +15 -0
  77. package/dist/command/server/key/list.js +34 -0
  78. package/dist/command/server/key/revoke.js +24 -0
  79. package/dist/command/server/key/run.js +54 -0
  80. package/dist/command/validate.js +47 -0
  81. package/dist/command/value/get.js +21 -0
  82. package/dist/command/value/index.js +19 -0
  83. package/dist/command/value/key.js +8 -0
  84. package/dist/command/value/list.js +41 -0
  85. package/dist/command/value/remove.js +26 -0
  86. package/dist/command/value/set.js +62 -0
  87. package/dist/command/value/usage.js +69 -0
  88. package/dist/command/whoami.js +55 -0
  89. package/dist/commands.js +100 -0
  90. package/dist/config/ai.js +2 -0
  91. package/dist/config/art.js +13 -0
  92. package/dist/config/audience.js +2 -0
  93. package/dist/config/code.js +129 -0
  94. package/dist/config/file.js +13 -0
  95. package/dist/config/genre.js +19 -0
  96. package/{src → dist}/config/html.js +2 -7
  97. package/dist/config/image.js +5 -0
  98. package/dist/config/input.js +11 -0
  99. package/dist/config/json.js +23 -0
  100. package/dist/config/limit.js +14 -0
  101. package/dist/config/orientation.js +11 -0
  102. package/dist/config/package.js +8 -0
  103. package/dist/config/product.js +14 -0
  104. package/dist/config/template.js +37 -0
  105. package/dist/config/uri.js +18 -0
  106. package/dist/config/url.js +11 -0
  107. package/dist/config/video.js +5 -0
  108. package/dist/config/visibility.js +2 -0
  109. package/dist/config/workflow.js +7 -0
  110. package/dist/parser/env.js +61 -0
  111. package/dist/parser/given.js +8 -0
  112. package/dist/parser/manifest.js +45 -0
  113. package/dist/parser/media.js +57 -0
  114. package/dist/parser/project.js +129 -0
  115. package/dist/parser/readme-file.js +44 -0
  116. package/dist/parser/readme.js +70 -0
  117. package/dist/parser/sections.js +92 -0
  118. package/dist/parser/self.js +16 -0
  119. package/dist/phrase/account.js +35 -0
  120. package/dist/phrase/common.js +139 -0
  121. package/dist/phrase/deploy.js +192 -0
  122. package/dist/phrase/function.js +139 -0
  123. package/dist/phrase/game.js +27 -0
  124. package/dist/phrase/index.js +16 -0
  125. package/dist/phrase/init.js +53 -0
  126. package/dist/phrase/internal.js +61 -0
  127. package/dist/phrase/manifest.js +120 -0
  128. package/dist/phrase/media.js +90 -0
  129. package/dist/phrase/pack.js +69 -0
  130. package/dist/phrase/serve.js +84 -0
  131. package/dist/phrase/server.js +38 -0
  132. package/dist/phrase/value.js +55 -0
  133. package/dist/runner/bundle.js +45 -0
  134. package/dist/runner/entry.js +57 -0
  135. package/dist/runner/outbound.js +69 -0
  136. package/dist/schema/check/game.js +29 -0
  137. package/dist/schema/check/workflow.js +57 -0
  138. package/dist/schema/game.js +462 -0
  139. package/dist/schema/message.js +61 -0
  140. package/dist/schema/readme.js +27 -0
  141. package/dist/schema/runner.js +43 -0
  142. package/dist/schema/server.js +91 -0
  143. package/dist/schema/workflow.js +99 -0
  144. package/dist/serve/files.js +39 -0
  145. package/dist/serve/game.js +172 -0
  146. package/dist/serve/page.js +689 -0
  147. package/dist/serve/reload.js +55 -0
  148. package/dist/serve/remote.js +114 -0
  149. package/dist/serve/runner.js +303 -0
  150. package/dist/serve/server.js +169 -0
  151. package/dist/serve/ticket.js +232 -0
  152. package/dist/serve/values.js +317 -0
  153. package/dist/util/bytes.js +16 -0
  154. package/dist/util/chars.js +19 -0
  155. package/dist/util/command.js +11 -0
  156. package/dist/util/delay.js +36 -0
  157. package/dist/util/doc.js +59 -0
  158. package/dist/util/error.js +35 -0
  159. package/dist/util/http.js +13 -0
  160. package/dist/util/image.js +64 -0
  161. package/dist/util/links.js +45 -0
  162. package/dist/util/lockfile.js +17 -0
  163. package/dist/util/log.js +101 -0
  164. package/dist/util/md.js +37 -0
  165. package/dist/util/media.js +27 -0
  166. package/dist/util/objs.js +46 -0
  167. package/dist/util/os.js +13 -0
  168. package/dist/util/output.js +133 -0
  169. package/dist/util/paths.js +8 -0
  170. package/dist/util/progress.js +57 -0
  171. package/dist/util/promise.js +18 -0
  172. package/dist/util/request.js +103 -0
  173. package/dist/util/s3.js +67 -0
  174. package/dist/util/schema.js +151 -0
  175. package/dist/util/screenshot.js +24 -0
  176. package/dist/util/shape.js +49 -0
  177. package/dist/util/shell.js +64 -0
  178. package/dist/util/size.js +32 -0
  179. package/dist/util/spinner.js +35 -0
  180. package/dist/util/strs.js +46 -0
  181. package/dist/util/table.js +18 -0
  182. package/dist/util/term.js +21 -0
  183. package/dist/util/time.js +16 -0
  184. package/dist/util/toml.js +28 -0
  185. package/{src → dist}/util/uris.js +8 -14
  186. package/dist/util/video.js +113 -0
  187. package/dist/util/zip.js +62 -0
  188. package/npm-shrinkwrap.json +3256 -0
  189. package/package.json +41 -39
  190. package/bin/arc-build.js +0 -139
  191. package/bin/arc-default.js +0 -65
  192. package/bin/arc-deploy.js +0 -456
  193. package/bin/arc-init.js +0 -187
  194. package/bin/arc-inspect.js +0 -97
  195. package/bin/arc-login.js +0 -165
  196. package/bin/arc-logout.js +0 -75
  197. package/bin/arc-open.js +0 -104
  198. package/bin/arc-pack.js +0 -146
  199. package/bin/arc-play.js +0 -140
  200. package/bin/arc-serve.js +0 -214
  201. package/bin/arc-validate.js +0 -112
  202. package/bin/arc-whoami.js +0 -119
  203. package/src/account.js +0 -249
  204. package/src/action/build/tool.js +0 -80
  205. package/src/action/deploy/tool-git.js +0 -90
  206. package/src/action/deploy/tool.js +0 -88
  207. package/src/action/deploy/wait.js +0 -151
  208. package/src/action/init/manifest.js +0 -83
  209. package/src/action/init/tool-patch.js +0 -32
  210. package/src/action/init/tool.js +0 -97
  211. package/src/action/inspect/tool.js +0 -26
  212. package/src/action/login/flow.js +0 -101
  213. package/src/action/login/tool.js +0 -16
  214. package/src/action/logout/tool.js +0 -15
  215. package/src/action/open/tool.js +0 -38
  216. package/src/action/pack/limits.js +0 -51
  217. package/src/action/pack/tool.js +0 -171
  218. package/src/action/pack/unsound.js +0 -69
  219. package/src/action/play/tool.js +0 -109
  220. package/src/action/predeploy/ac.js +0 -112
  221. package/src/action/predeploy/git.js +0 -223
  222. package/src/action/predeploy/pm.js +0 -37
  223. package/src/action/predeploy/published.js +0 -82
  224. package/src/action/predeploy/tool-git.js +0 -154
  225. package/src/action/predeploy/tool.js +0 -29
  226. package/src/action/serve/tool.js +0 -209
  227. package/src/action/validate/checked.js +0 -37
  228. package/src/action/validate/tool.js +0 -67
  229. package/src/action/validate/unknown.js +0 -86
  230. package/src/action/validate/unsound.js +0 -138
  231. package/src/action/whoami/tool.js +0 -15
  232. package/src/api.js +0 -163
  233. package/src/cli/build.js +0 -15
  234. package/src/cli/deploy.js +0 -21
  235. package/src/cli/init.js +0 -17
  236. package/src/cli/inspect.js +0 -15
  237. package/src/cli/login.js +0 -15
  238. package/src/cli/logout.js +0 -15
  239. package/src/cli/open.js +0 -15
  240. package/src/cli/pack.js +0 -15
  241. package/src/cli/play.js +0 -15
  242. package/src/cli/predeploy.js +0 -21
  243. package/src/cli/serve.js +0 -15
  244. package/src/cli/validate.js +0 -15
  245. package/src/cli/whoami.js +0 -15
  246. package/src/config/ai.js +0 -5
  247. package/src/config/art.js +0 -16
  248. package/src/config/audience.js +0 -5
  249. package/src/config/code.js +0 -142
  250. package/src/config/file.js +0 -23
  251. package/src/config/genre.js +0 -22
  252. package/src/config/image.js +0 -7
  253. package/src/config/input.js +0 -14
  254. package/src/config/limit.js +0 -21
  255. package/src/config/orientation.js +0 -14
  256. package/src/config/package.js +0 -5
  257. package/src/config/product.js +0 -5
  258. package/src/config/template.js +0 -45
  259. package/src/config/uri.js +0 -27
  260. package/src/config/url.js +0 -20
  261. package/src/config/video.js +0 -7
  262. package/src/config/visibility.js +0 -5
  263. package/src/config/workflow.js +0 -18
  264. package/src/parser/env.js +0 -84
  265. package/src/parser/given.js +0 -17
  266. package/src/parser/manifest.js +0 -80
  267. package/src/parser/media.js +0 -90
  268. package/src/parser/project.js +0 -166
  269. package/src/parser/readme-file.js +0 -76
  270. package/src/parser/readme.js +0 -96
  271. package/src/parser/sections.js +0 -107
  272. package/src/parser/self.js +0 -27
  273. package/src/phrase.js +0 -1294
  274. package/src/schema/check/game.js +0 -61
  275. package/src/schema/check/workflow.js +0 -99
  276. package/src/schema/game.js +0 -649
  277. package/src/schema/message.js +0 -85
  278. package/src/schema/readme.js +0 -44
  279. package/src/schema/workflow.js +0 -150
  280. package/src/serve/files.js +0 -61
  281. package/src/serve/game.js +0 -191
  282. package/src/serve/page.js +0 -345
  283. package/src/serve/reload.js +0 -68
  284. package/src/serve/remote.js +0 -121
  285. package/src/serve/server.js +0 -128
  286. package/src/util/argv.js +0 -116
  287. package/src/util/bytes.js +0 -25
  288. package/src/util/chars.js +0 -30
  289. package/src/util/command.js +0 -18
  290. package/src/util/delay.js +0 -52
  291. package/src/util/doc.js +0 -72
  292. package/src/util/error.js +0 -50
  293. package/src/util/http.js +0 -25
  294. package/src/util/image.js +0 -93
  295. package/src/util/links.js +0 -78
  296. package/src/util/lockfile.js +0 -35
  297. package/src/util/log.js +0 -149
  298. package/src/util/md.js +0 -61
  299. package/src/util/media.js +0 -40
  300. package/src/util/objs.js +0 -45
  301. package/src/util/os.js +0 -27
  302. package/src/util/output.js +0 -174
  303. package/src/util/paths.js +0 -21
  304. package/src/util/progress.js +0 -85
  305. package/src/util/promise.js +0 -29
  306. package/src/util/rc.js +0 -144
  307. package/src/util/request.js +0 -89
  308. package/src/util/s3.js +0 -92
  309. package/src/util/schema.js +0 -189
  310. package/src/util/screenshot.js +0 -37
  311. package/src/util/shell.js +0 -84
  312. package/src/util/size.js +0 -53
  313. package/src/util/spinner.js +0 -52
  314. package/src/util/strs.js +0 -73
  315. package/src/util/term.js +0 -28
  316. package/src/util/time.js +0 -29
  317. package/src/util/toml.js +0 -14
  318. package/src/util/video.js +0 -157
  319. package/src/util/zip.js +0 -88
  320. /package/{src/serve → assets}/favicon.ico +0 -0
@@ -0,0 +1,46 @@
1
+ // [import]
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ // [import]
5
+ import { PACKAGE_FILE_TOO_LARGE, PACKAGE_TOO_MANY_FILES, PACKAGE_UNCOMPRESSED_TOO_LARGE, } from "../../config/code.js";
6
+ import { ArcError } from "../../util/error.js";
7
+ import { packageFileTooLarge, packageTooManyFiles, packageUncompressedTooLarge, } from "../../phrase/index.js";
8
+ import { FILE_SIZE, FILES, TOTAL_SIZE } from "../../config/limit.js";
9
+ import { toMb } from "../../util/size.js";
10
+ // [declare]
11
+ export const MAX_FILES = FILES;
12
+ export const MAX_FILE_SIZE = FILE_SIZE;
13
+ export const MAX_TOTAL_SIZE = TOTAL_SIZE;
14
+ // [function]
15
+ // checks a zip's files against the limits, and throws for the first one it
16
+ // breaks: a file over 64 MB, more than 10,000 files, or over 256 MB in all.
17
+ export function check(entries) {
18
+ const large = entries.find((entry) => entry.size > MAX_FILE_SIZE);
19
+ if (large) {
20
+ throw new ArcError(PACKAGE_FILE_TOO_LARGE, packageFileTooLarge(large.name, toMb(MAX_FILE_SIZE)));
21
+ }
22
+ if (entries.length > MAX_FILES) {
23
+ throw new ArcError(PACKAGE_TOO_MANY_FILES, packageTooManyFiles(MAX_FILES));
24
+ }
25
+ const total = entries.reduce((sum, entry) => sum + entry.size, 0);
26
+ if (total > MAX_TOTAL_SIZE) {
27
+ throw new ArcError(PACKAGE_UNCOMPRESSED_TOO_LARGE, packageUncompressedTooLarge(toMb(MAX_TOTAL_SIZE)));
28
+ }
29
+ }
30
+ // [function]
31
+ // a folder's files as `check` takes them, each with its size on disk, read
32
+ // from the file system and not the files: a folder is held to the limits
33
+ // before any of it is read into memory. A file over 64 MB is then refused
34
+ // at once, and nothing that large is held when the command exits, which
35
+ // matters: Node 24 can hang in `process.exit` with that much just allocated
36
+ // (TODO.md, Known bugs).
37
+ export function measure(dir, under = "") {
38
+ return fs.readdirSync(dir).flatMap((name) => {
39
+ const file = path.join(dir, name);
40
+ const stat = fs.statSync(file);
41
+ const entry = under ? `${under}/${name}` : name;
42
+ return stat.isDirectory()
43
+ ? measure(file, entry)
44
+ : [{ name: entry, size: stat.size }];
45
+ });
46
+ }
@@ -0,0 +1,148 @@
1
+ // [import]
2
+ import path from "node:path";
3
+ // [import]
4
+ import { pathExists } from "fs-extra";
5
+ // [import]
6
+ import { BUILT, PACKED } from "../../runner/bundle.js";
7
+ import { DEPLOY_DIR_MISSING, PACKAGE_INDEX_MISSING, PACKAGE_PATH_RESERVED, PACKAGE_TOO_LARGE, PATH_NOT_FOUND, } from "../../config/code.js";
8
+ import { ArcError } from "../../util/error.js";
9
+ import { MEDIA, PACKAGED } from "../../config/file.js";
10
+ import { deployDirMissing, packageIndexMissing, packagePathReserved, packageTooLarge, runnerNotBuilt, unableToFind, } from "../../phrase/index.js";
11
+ import { ZIP_SIZE } from "../../config/limit.js";
12
+ import { check, measure } from "./limits.js";
13
+ import { handle, tool } from "../../config/product.js";
14
+ import { toMb } from "../../util/size.js";
15
+ import { unsound } from "./unsound.js";
16
+ import { Zip } from "../../util/zip.js";
17
+ // [use]
18
+ const parse = path.parse;
19
+ const resolve = path.resolve;
20
+ // [declare]
21
+ const TOOL = tool;
22
+ // [declare]
23
+ const MAIN = "index.html";
24
+ const MANIFEST = PACKAGED;
25
+ const OUTPUT = `.${TOOL}/package`;
26
+ // the folder every build's origin keeps for Arcadible's own files, such as
27
+ // the script games include, in any letter case.
28
+ const RESERVED = handle;
29
+ // [declare]
30
+ const SIZE_PARTIAL = ZIP_SIZE;
31
+ // [function]
32
+ // the first path at the build's root that's Arcadible's, if it has one: a
33
+ // folder named like the reserved one, or the manifest or media that packing
34
+ // adds, as `arc validate` checks deploy_dir. A folder ends with "/".
35
+ function findReserved(zip) {
36
+ return zip
37
+ .entries()
38
+ .map((entry) => entry.name.split("/"))
39
+ .map((parts) => (parts.length > 1 ? `${parts[0]}/` : String(parts[0])))
40
+ .find((name) => name.toLowerCase() === `${RESERVED}/` ||
41
+ name === MANIFEST ||
42
+ name === `${MEDIA}/`);
43
+ }
44
+ // [function]
45
+ // the files' own limits come first, since they name what to fix, such as
46
+ // the one file over 64 MB that makes the zip too large.
47
+ function verifyPartial(zip) {
48
+ if (!zip.has(MAIN)) {
49
+ throw new ArcError(PACKAGE_INDEX_MISSING, packageIndexMissing(MAIN));
50
+ }
51
+ const reserved = findReserved(zip);
52
+ if (reserved) {
53
+ throw new ArcError(PACKAGE_PATH_RESERVED, packagePathReserved(reserved));
54
+ }
55
+ check(zip.entries());
56
+ if (zip.stat().size > SIZE_PARTIAL) {
57
+ throw new ArcError(PACKAGE_TOO_LARGE, packageTooLarge(toMb(SIZE_PARTIAL)));
58
+ }
59
+ return zip;
60
+ }
61
+ // [function]
62
+ function verifyTotal(zip) {
63
+ check(zip.entries());
64
+ return zip;
65
+ }
66
+ // [function]
67
+ // `deployDir` when the input is deploy_dir, rather than a folder --input
68
+ // named: a missing deploy_dir means the build hasn't written it.
69
+ function pack(name, game, { deployDir, inputPath, mediaPath, onWarning, outputPath, runner, server, }) {
70
+ const zip = new Zip(name);
71
+ return pathExists(inputPath)
72
+ .then((existsInput) => {
73
+ if (!existsInput) {
74
+ throw deployDir
75
+ ? new ArcError(DEPLOY_DIR_MISSING, deployDirMissing(inputPath))
76
+ : new ArcError(PATH_NOT_FOUND, unableToFind(inputPath));
77
+ }
78
+ // held to the limits by its sizes on disk, before any of it is read
79
+ check(measure(inputPath));
80
+ zip.addDir(inputPath);
81
+ return zip;
82
+ })
83
+ .then(verifyPartial)
84
+ .then(() => pathExists(mediaPath))
85
+ .then((existsMedia) => {
86
+ if (existsMedia) {
87
+ zip.addDir(mediaPath, MEDIA);
88
+ }
89
+ // the game's own servers go with it, when it declares any: the build
90
+ // keeps them, and a ticket is only ever for one of them. A runner goes
91
+ // as what it may reach, never where its code was.
92
+ zip.addJson(MANIFEST, {
93
+ game,
94
+ ...(runner
95
+ ? {
96
+ function: {
97
+ outbound_hosts: runner.table.outbound_hosts ?? [],
98
+ secrets: runner.table.secrets ?? [],
99
+ },
100
+ }
101
+ : {}),
102
+ ...(Array.isArray(server?.origins) && server.origins.length
103
+ ? { server }
104
+ : {}),
105
+ });
106
+ return runner ? pathExists(runner.built) : false;
107
+ })
108
+ .then((built) => {
109
+ // the runner's bundle, as `arc build` wrote it, in the folder every
110
+ // build's origin keeps for Arcadible's own files, which is never served
111
+ if (runner && !built) {
112
+ throw new ArcError(PATH_NOT_FOUND, runnerNotBuilt());
113
+ }
114
+ if (runner) {
115
+ zip.addFile(runner.built, PACKED);
116
+ }
117
+ return zip;
118
+ })
119
+ .then(verifyTotal)
120
+ .then((file) => {
121
+ if (onWarning) {
122
+ unsound(file.entries()).forEach(onWarning);
123
+ }
124
+ file.write(outputPath);
125
+ return { path: outputPath, ...file.stat() };
126
+ });
127
+ }
128
+ // [function]
129
+ // `onWarning` gets each of the package's warnings, such as a `.env` file
130
+ // in it, as a command's own. The project is one that passed validation, so
131
+ // its deploy_dir is a path.
132
+ export function packTool({ input, onWarning, output, ...conf }) {
133
+ const root = conf.root;
134
+ const { function: runner, game, server, workflow } = conf.project;
135
+ const name = game.handle ?? game.id;
136
+ const file = output ?? `${OUTPUT}/${name}-v${game.version}.zip`;
137
+ const deployDir = resolve(root, workflow.deploy_dir);
138
+ const inputPath = resolve(root, input ?? workflow.deploy_dir);
139
+ return pack(parse(file).name, game, {
140
+ deployDir: inputPath === deployDir,
141
+ inputPath,
142
+ mediaPath: resolve(root, MEDIA),
143
+ onWarning,
144
+ outputPath: resolve(root, file),
145
+ runner: runner ? { built: resolve(root, BUILT), table: runner } : null,
146
+ server,
147
+ });
148
+ }
@@ -0,0 +1,51 @@
1
+ // [import]
2
+ import path from "node:path";
3
+ // [import]
4
+ import { WARNING } from "../../config/code.js";
5
+ import { packageFileDev, packageFilePrivate } from "../../phrase/index.js";
6
+ // [use]
7
+ const posixBasename = path.posix.basename;
8
+ // [declare]
9
+ // the files any player could download that are almost never meant to be
10
+ // public, kept short on purpose, to grow later (OUTPUT.md, Codes): a `.env`
11
+ // file other than an example of one, and a git repository.
12
+ const ENV = /^\.env(?:\..+)?$/u;
13
+ const ENV_EXAMPLE = /\.(?:example|sample|template)$/u;
14
+ const GIT = ".git";
15
+ // the folder of a project's installed packages, at the package's root.
16
+ const MODULES = "node_modules/";
17
+ // [function]
18
+ // the private files among the package's, each once: a `.env` file by its
19
+ // path, and a git repository by its folder.
20
+ function privates(names) {
21
+ const found = names.flatMap((name) => {
22
+ const parts = name.split("/");
23
+ const git = parts.slice(0, -1).indexOf(GIT);
24
+ if (git !== -1) {
25
+ return [`${parts.slice(0, git + 1).join("/")}/`];
26
+ }
27
+ const base = posixBasename(name);
28
+ return ENV.test(base) && !ENV_EXAMPLE.test(base) ? [name] : [];
29
+ });
30
+ return [...new Set(found)].sort();
31
+ }
32
+ // [function]
33
+ // the packed files' warnings, as a command's own (`onWarning`): what the
34
+ // package holds, never a guess at how it's served (OUTPUT.md, Codes).
35
+ export function unsound(entries) {
36
+ const names = entries.map((entry) => entry.name);
37
+ return [
38
+ ...(names.some((name) => name.startsWith(MODULES))
39
+ ? [
40
+ {
41
+ code: WARNING.PACKAGE_FILE_DEV,
42
+ message: packageFileDev(MODULES),
43
+ },
44
+ ]
45
+ : []),
46
+ ...privates(names).map((file) => ({
47
+ code: WARNING.PACKAGE_FILE_PRIVATE,
48
+ message: packageFilePrivate(file),
49
+ })),
50
+ ];
51
+ }
@@ -0,0 +1,84 @@
1
+ // [import]
2
+ import { discoverGame, discoverGameBuilds } from "../../api.js";
3
+ import { GAME_NOT_FOUND } from "../../config/code.js";
4
+ import { ArcError } from "../../util/error.js";
5
+ import { HttpError } from "../../util/http.js";
6
+ import { gameNotFound } from "../../phrase/index.js";
7
+ import { playUrl, PRODUCTION, STAGING } from "../../util/links.js";
8
+ import { textOf } from "../../util/objs.js";
9
+ import { self } from "../../parser/self.js";
10
+ // [function]
11
+ // the game, `select`ed, or null when the API can't be reached. It rejects
12
+ // when the game isn't on Arcadible: its builds can't say, since a game that
13
+ // doesn't exist has none.
14
+ function findGame(id, select) {
15
+ return discoverGame(id, { select }).catch((err) => {
16
+ if (err instanceof HttpError && err.status === 404) {
17
+ throw new ArcError(GAME_NOT_FOUND, gameNotFound(id));
18
+ }
19
+ return null;
20
+ });
21
+ }
22
+ // [function]
23
+ function fallbackIf(fallback) {
24
+ return { fallback, release: fallback ? STAGING : PRODUCTION };
25
+ }
26
+ // [function]
27
+ // the release to play. A chosen one is used as is. Without one, it's
28
+ // production, or staging when the game has no production release yet. When
29
+ // the API can't be reached, it's production.
30
+ function resolveRelease(id, release) {
31
+ if (release) {
32
+ return Promise.resolve({ fallback: false, release });
33
+ }
34
+ return discoverGameBuilds(id, {
35
+ channel: PRODUCTION,
36
+ select: "version",
37
+ }).then((builds) => fallbackIf(!builds?.length), () => fallbackIf(false));
38
+ }
39
+ // [function]
40
+ function target(id, orientation, release) {
41
+ return resolveRelease(id, release).then(({ fallback, release: chosen }) => ({
42
+ fallback,
43
+ orientation: orientation ?? "natural",
44
+ url: playUrl(id, chosen),
45
+ }));
46
+ }
47
+ // [function]
48
+ // another game: its orientation comes from the API, or natural when the API
49
+ // can't be reached.
50
+ function play(id, release) {
51
+ if (!id) {
52
+ return Promise.resolve(null);
53
+ }
54
+ return findGame(id, "orientation").then((game) => target(id, game?.orientation, release));
55
+ }
56
+ // [function]
57
+ // this project's game: its orientation comes from the manifest. With a
58
+ // chosen release, it makes no API call.
59
+ function playSelf(root, release) {
60
+ return self(root)
61
+ .then((game) => {
62
+ const named = game?.handle ?? game?.id;
63
+ if (!game || !named) {
64
+ return Promise.resolve([null, null]);
65
+ }
66
+ // a handle or an id as the manifest has it.
67
+ const id = textOf(named);
68
+ return Promise.all([
69
+ release ? null : findGame(id, "id"),
70
+ target(id, game.orientation, release),
71
+ ]);
72
+ })
73
+ .then(([, found]) => found);
74
+ }
75
+ // [function]
76
+ export function playTool({ game: id, release, root, }, { onPlayFetch }) {
77
+ if (onPlayFetch) {
78
+ onPlayFetch({ game: id });
79
+ }
80
+ if (id === "self") {
81
+ return playSelf(root, release);
82
+ }
83
+ return play(id, release);
84
+ }
@@ -0,0 +1,75 @@
1
+ // [import]
2
+ import { auth, discoverGame, gameBuild, gameHandle } from "../../api.js";
3
+ import { GAME_HANDLE_TAKEN, GAME_UNAVAILABLE, WARNING, } from "../../config/code.js";
4
+ import { ArcError } from "../../util/error.js";
5
+ import { HttpError } from "../../util/http.js";
6
+ import { gameHandleLapsed, gameHandleLimit, gameHandleTaken, gameUnavailable, } from "../../phrase/index.js";
7
+ import { channel } from "../../util/links.js";
8
+ import { refuse } from "./published.js";
9
+ // [function]
10
+ // a lookup's failure, passed over when it's a 404: nothing there to refuse.
11
+ function ignoreMissing(err) {
12
+ if (!(err instanceof HttpError) || err.status !== 404) {
13
+ throw err;
14
+ }
15
+ }
16
+ // [function]
17
+ // fails when the game is another account's. A game the API doesn't find
18
+ // passes: it isn't on Arcadible yet, or it was deleted, which the upload
19
+ // refuses.
20
+ function ensureOwned(current, id) {
21
+ return discoverGame(id).then((game) => {
22
+ // a token's account isn't known yet; the server checks ownership when
23
+ // it authorizes the upload.
24
+ if (!current?.token && game.account !== current?.user.id) {
25
+ throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id));
26
+ }
27
+ }, ignoreMissing);
28
+ }
29
+ // [function]
30
+ // fails when the handle is taken: another game's, held for another account,
31
+ // or reserved. When the handle rules keep it from this release (the limit on
32
+ // unreleased games' handles, or one that lapsed from this account), it warns
33
+ // and deploys anyway, as the game keeps the handle it has, or none, and
34
+ // resolves with true. A game without a handle has none to check.
35
+ function ensureHandle(current, { handle, id, version }, handler) {
36
+ if (handle === null) {
37
+ return Promise.resolve(null);
38
+ }
39
+ const warn = (code, message) => {
40
+ if (handler?.onWarning) {
41
+ handler.onWarning({ code, message });
42
+ }
43
+ };
44
+ return gameHandle(id, handle, { channel: channel(version) }, auth(current?.session.access_token)).then(({ status }) => {
45
+ if (status === "taken") {
46
+ throw new ArcError(GAME_HANDLE_TAKEN, gameHandleTaken(handle));
47
+ }
48
+ if (status === "limit") {
49
+ warn(WARNING.GAME_HANDLE_LIMIT_REACHED, gameHandleLimit(handle));
50
+ return true;
51
+ }
52
+ if (status === "lapsed") {
53
+ warn(WARNING.GAME_HANDLE_LAPSED, gameHandleLapsed(handle));
54
+ return true;
55
+ }
56
+ return false;
57
+ }, ignoreMissing);
58
+ }
59
+ // [function]
60
+ // resolves with the game once its id is free or already its own, and its
61
+ // handle, if it has one, isn't taken; `held` when the rules hold the handle
62
+ // back from this release, so its links are by id.
63
+ export function ensureId(current, game, handler) {
64
+ return ensureOwned(current, game.id)
65
+ .then(() => ensureHandle(current, game, handler))
66
+ .then((held) => ({ ...game, held: Boolean(held) }));
67
+ }
68
+ // [function]
69
+ // resolves with the game, or fails when its version is already published.
70
+ export function ensureUnpublished(current, game) {
71
+ const { id, version } = game;
72
+ return gameBuild(id, version, null, auth(current?.session.access_token))
73
+ .then(() => refuse(id, version), ignoreMissing)
74
+ .then(() => game);
75
+ }
@@ -0,0 +1,6 @@
1
+ // [import]
2
+ // [function]
3
+ // the fields a release goes by, of a project that passed validation.
4
+ export function releasing(game) {
5
+ return { handle: game.handle ?? null, id: game.id, version: game.version };
6
+ }
@@ -0,0 +1,151 @@
1
+ // [import]
2
+ import cp from "node:child_process";
3
+ // [import]
4
+ import { GIT_REMOTE_MISSING, GIT_REMOTE_UNREACHABLE, GIT_REPO_MISSING, GIT_TAG_EXISTS, GIT_UNCOMMITTED, PROJECT_NOT_REPO_ROOT, WORKFLOW_MISSING, } from "../../config/code.js";
5
+ import { ArcError } from "../../util/error.js";
6
+ import { WORKFLOW } from "../../config/file.js";
7
+ import { gitRemoteMissing, gitRemoteUnreachable, gitRepoMissing, gitTagExists, gitUncommitted, projectNotRepoRoot, workflowMissing, } from "../../phrase/index.js";
8
+ import { isTable } from "../../util/objs.js";
9
+ import { handle } from "../../config/product.js";
10
+ // [declare]
11
+ const HANDLE = handle;
12
+ const PREFIX = `${HANDLE}/release/v`;
13
+ // a remote's URL: `scheme://[user@]host/path`, or scp-like
14
+ // `[user@]host:path`. A path on this machine is neither.
15
+ const URL_REMOTE = /^[a-z][a-z0-9+.-]*:\/\/(?:[^@/\s]+@)?[^/\s]+\/(\S+)$/iu;
16
+ const URL_SCP = /^(?:[^@/\s]+@)?[^:/\s]{2,}:(?!\/)(\S+)$/u;
17
+ // the names GitHub allows: an account's, and a repository's.
18
+ const NAME_OWNER = /^[A-Za-z0-9-]{1,39}$/u;
19
+ const NAME_REPO = /^[A-Za-z0-9._-]{1,100}$/u;
20
+ // [function]
21
+ // runs git in `root`, and resolves with its stdout. A failure rejects with
22
+ // git's error, with what it printed as `stderr`. `execFile` is called
23
+ // through the module, so the tests' fake of it applies.
24
+ export function git(root, args) {
25
+ return new Promise((resolve, reject) => {
26
+ cp.execFile("git", ["-C", root, ...args], (err, stdout, stderr) => {
27
+ if (err) {
28
+ const failed = Object.assign(err, { stderr });
29
+ reject(failed);
30
+ return;
31
+ }
32
+ resolve(stdout);
33
+ });
34
+ });
35
+ }
36
+ // [function]
37
+ // what git printed as it failed, from the error `git` rejects with.
38
+ export function stderrOf(err) {
39
+ return isTable(err) && typeof err["stderr"] === "string"
40
+ ? err["stderr"]
41
+ : undefined;
42
+ }
43
+ // [function]
44
+ // a rejection handler that replaces git's error with `code` and `message`,
45
+ // keeping it as the cause.
46
+ export function failWith(code, message) {
47
+ return (err) => {
48
+ throw new ArcError(code, message, { cause: err });
49
+ };
50
+ }
51
+ // [function]
52
+ // the release tag of a version.
53
+ export function tagOf(version) {
54
+ return `${PREFIX}${version}`;
55
+ }
56
+ // [function]
57
+ // fails on any change that isn't committed: staged, unstaged, or untracked.
58
+ // ignored files don't count. The release is built from HEAD, so anything
59
+ // uncommitted wouldn't be part of it.
60
+ export function ensureClean(root) {
61
+ return git(root, ["status", "--porcelain"]).then((stdout) => {
62
+ if (stdout.trim()) {
63
+ throw new ArcError(GIT_UNCOMMITTED, gitUncommitted());
64
+ }
65
+ });
66
+ }
67
+ // [function]
68
+ // fails with git_remote_missing when there's no origin, and with
69
+ // git_remote_unreachable when it's there but can't be reached.
70
+ export function ensureRemote(root) {
71
+ return git(root, ["remote", "get-url", "origin"])
72
+ .then(() => null, failWith(GIT_REMOTE_MISSING, gitRemoteMissing()))
73
+ .then(() => git(root, ["ls-remote", "origin"]))
74
+ .then(() => null,
75
+ // git_remote_missing passes through.
76
+ (err) => {
77
+ if (err instanceof ArcError) {
78
+ throw err;
79
+ }
80
+ return failWith(GIT_REMOTE_UNREACHABLE, gitRemoteUnreachable())(err);
81
+ });
82
+ }
83
+ // [function]
84
+ export function ensureRepo(root) {
85
+ return git(root, ["rev-parse", "--is-inside-work-tree"]).then(() => null, failWith(GIT_REPO_MISSING, gitRepoMissing()));
86
+ }
87
+ // [function]
88
+ // fails when the project isn't the repository's top level: the release
89
+ // workflow builds from the root, so a project in a directory below it would
90
+ // fail on GitHub, or release the root's game.
91
+ export function ensureRoot(root) {
92
+ return git(root, ["rev-parse", "--show-prefix"]).then((stdout) => {
93
+ const prefix = stdout.trim();
94
+ if (prefix) {
95
+ throw new ArcError(PROJECT_NOT_REPO_ROOT, projectNotRepoRoot(prefix));
96
+ }
97
+ });
98
+ }
99
+ // [function]
100
+ // fails when HEAD has no release workflow, which Arcadible checks for when the
101
+ // tag arrives (workflow_missing).
102
+ export function ensureWorkflow(root) {
103
+ return git(root, ["cat-file", "-e", `HEAD:${WORKFLOW}`]).then(() => null, failWith(WORKFLOW_MISSING, workflowMissing(WORKFLOW)));
104
+ }
105
+ // [function]
106
+ // a remote URL's repository, as { owner, name }: the last two parts of its
107
+ // path. The host isn't checked, so an SSH alias for GitHub works too. Null
108
+ // for a path on this machine, or one that isn't owner/name.
109
+ export function repoOf(url) {
110
+ const path = URL_REMOTE.exec(url)?.[1] ?? URL_SCP.exec(url)?.[1] ?? null;
111
+ if (!path) {
112
+ return null;
113
+ }
114
+ const parts = path
115
+ .replace(/\/+$/u, "")
116
+ .replace(/\.git$/u, "")
117
+ .split("/");
118
+ if (parts.length < 2) {
119
+ return null;
120
+ }
121
+ const [owner = "", name = ""] = parts.slice(-2);
122
+ return NAME_OWNER.test(owner) && NAME_REPO.test(name)
123
+ ? { name, owner }
124
+ : null;
125
+ }
126
+ // [function]
127
+ // origin's repository, from its URL as configured (before any `insteadOf`),
128
+ // or null when it has none, or it isn't a repository on a host.
129
+ export function originRepo(root) {
130
+ return git(root, ["config", "--get", "remote.origin.url"]).then((stdout) => repoOf(stdout.trim()), () => null);
131
+ }
132
+ // [function]
133
+ function hasTagLocal(root, tag) {
134
+ return git(root, ["tag", "--list", tag]).then((stdout) => Boolean(stdout.trim()));
135
+ }
136
+ // [function]
137
+ function hasTagRemote(root, tag) {
138
+ return git(root, ["ls-remote", "--tags", "origin", `refs/tags/${tag}`]).then((stdout) => Boolean(stdout.trim()), failWith(GIT_REMOTE_UNREACHABLE, gitRemoteUnreachable()));
139
+ }
140
+ // [function]
141
+ // fails when the version's tag exists, locally or on origin.
142
+ export function ensureTagFree(root, version) {
143
+ const tag = tagOf(version);
144
+ return hasTagLocal(root, tag)
145
+ .then((local) => local || hasTagRemote(root, tag))
146
+ .then((exists) => {
147
+ if (exists) {
148
+ throw new ArcError(GIT_TAG_EXISTS, gitTagExists(version));
149
+ }
150
+ });
151
+ }
@@ -0,0 +1,20 @@
1
+ // [import]
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ // [import]
5
+ import { LOCKFILE_MISSING } from "../../config/code.js";
6
+ import { ArcError } from "../../util/error.js";
7
+ import { lockfileMissing } from "../../phrase/index.js";
8
+ import { detect } from "../../util/lockfile.js";
9
+ // [use]
10
+ const existsSync = fs.existsSync;
11
+ const join = path.join;
12
+ // [function]
13
+ // fails when there's a package.json without a lockfile: the release workflow
14
+ // installs exactly what the lockfile pins.
15
+ export function ensureLockFile(root) {
16
+ if (existsSync(join(root, "package.json")) && !detect(root)) {
17
+ return Promise.reject(new ArcError(LOCKFILE_MISSING, lockfileMissing()));
18
+ }
19
+ return Promise.resolve();
20
+ }
@@ -0,0 +1,54 @@
1
+ // [import]
2
+ import semver from "semver";
3
+ // [import]
4
+ import { discoverGameBuilds } from "../../api.js";
5
+ import { VERSION_EXISTS } from "../../config/code.js";
6
+ import { ArcError } from "../../util/error.js";
7
+ import { versionExists as versionExistsPhrase } from "../../phrase/index.js";
8
+ import { PRODUCTION, STAGING } from "../../util/links.js";
9
+ // [use]
10
+ const inc = semver.inc;
11
+ const prerelease = semver.prerelease;
12
+ const rcompare = semver.rcompare;
13
+ // [function]
14
+ // the newest version published to a channel, or null when there's none or
15
+ // when Arcadible can't say. builds come newest first, one per request.
16
+ function latest(id, channel) {
17
+ return discoverGameBuilds(id, { channel, select: "channel,version" }).then((builds) => builds?.find((build) => build.channel === channel)?.version ?? null, () => null);
18
+ }
19
+ // [function]
20
+ // a version to suggest instead: the next patch after the newest release, or
21
+ // for a prerelease, the next prerelease after the newest one.
22
+ export function next(version, { production, staging }) {
23
+ if (prerelease(version) === null) {
24
+ const [top = version] = [version, production]
25
+ .filter((each) => Boolean(each))
26
+ .sort(rcompare);
27
+ return inc(top, "patch");
28
+ }
29
+ const [top = version] = [version, staging]
30
+ .filter((each) => Boolean(each))
31
+ .sort(rcompare);
32
+ return prerelease(top) === null
33
+ ? `${inc(top, "patch")}-beta.1`
34
+ : inc(top, "prerelease");
35
+ }
36
+ // [function]
37
+ // the error for a version that's already published, naming what's newest on
38
+ // each channel and a version to bump to.
39
+ function versionExists(id, version) {
40
+ return Promise.all([latest(id, PRODUCTION), latest(id, STAGING)]).then(([production, staging]) => {
41
+ const found = { production, staging };
42
+ return new ArcError(VERSION_EXISTS, versionExistsPhrase(version, {
43
+ ...found,
44
+ next: next(version, found),
45
+ }));
46
+ });
47
+ }
48
+ // [function]
49
+ // rejects with versionExists's error.
50
+ export function refuse(id, version) {
51
+ return versionExists(id, version).then((err) => {
52
+ throw err;
53
+ });
54
+ }
@@ -0,0 +1,35 @@
1
+ // the secrets a build declares that have no value: a release never checks
2
+ // them, so a build can ship naming one (`[function] secrets`) with no value
3
+ // on its channel, and its function then reads nothing for it. A direct
4
+ // deploy can say so first, since it has the login that reads the game's
5
+ // secrets; `arc deploy git` has none, and never asks.
6
+ //
7
+ // Nothing calls this yet: what it finds is a warning, a warning has a code,
8
+ // and a code has an entry on the public Errors page, which says nothing of
9
+ // functions until they ship (TODO.md, Agreed next).
10
+ import { auth, gameFunctionSecrets } from "../../api.js";
11
+ import { channel } from "../../util/links.js";
12
+ // [function]
13
+ // the names `declared` (the manifest's `function.secrets`) that have no
14
+ // value on the channel the game's version goes to, in the order they're
15
+ // declared. With none declared, nothing is asked. When the game's secrets
16
+ // can't be read (offline, an API error, a game that isn't on Arcadible
17
+ // yet), it resolves with none, as the predeploy's other checks pass over
18
+ // what they can't answer: a warning states a fact, and there's none to
19
+ // state.
20
+ export async function unset(current, { id, version }, declared) {
21
+ const where = channel(version);
22
+ if (!declared?.length) {
23
+ return { channel: where, names: [] };
24
+ }
25
+ try {
26
+ const secrets = await gameFunctionSecrets(id, null, auth(current?.session.access_token));
27
+ const set = new Set((secrets ?? [])
28
+ .filter((secret) => secret.channel === where)
29
+ .map((secret) => secret.name));
30
+ return { channel: where, names: declared.filter((name) => !set.has(name)) };
31
+ }
32
+ catch {
33
+ return { channel: where, names: [] };
34
+ }
35
+ }