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.
- package/README.md +2 -1
- package/bin/arc.js +1 -85
- package/dist/account.js +197 -0
- package/dist/action/build/tool.js +65 -0
- package/dist/action/delete/tool.js +46 -0
- package/dist/action/deploy/rebuilt.js +25 -0
- package/dist/action/deploy/result.js +36 -0
- package/dist/action/deploy/timeout.js +18 -0
- package/dist/action/deploy/tool-git.js +54 -0
- package/dist/action/deploy/tool.js +54 -0
- package/dist/action/deploy/wait.js +104 -0
- package/dist/action/function/tool.js +127 -0
- package/dist/action/game.js +61 -0
- package/dist/action/init/manifest.js +64 -0
- package/dist/action/init/tool-patch.js +15 -0
- package/dist/action/init/tool.js +64 -0
- package/dist/action/inspect/tool.js +13 -0
- package/dist/action/key/tool.js +87 -0
- package/dist/action/login/flow.js +69 -0
- package/dist/action/login/tool.js +8 -0
- package/dist/action/logout/tool.js +8 -0
- package/dist/action/open/tool.js +29 -0
- package/dist/action/pack/limits.js +46 -0
- package/dist/action/pack/tool.js +150 -0
- package/dist/action/pack/unsound.js +51 -0
- package/dist/action/play/tool.js +83 -0
- package/dist/action/predeploy/ac.js +75 -0
- package/dist/action/predeploy/game.js +12 -0
- package/dist/action/predeploy/git.js +151 -0
- package/dist/action/predeploy/pm.js +20 -0
- package/dist/action/predeploy/published.js +54 -0
- package/dist/action/predeploy/secrets.js +35 -0
- package/dist/action/predeploy/tool-git.js +108 -0
- package/dist/action/predeploy/tool.js +16 -0
- package/dist/action/secret/tool.js +91 -0
- package/dist/action/serve/tool.js +249 -0
- package/dist/action/validate/checked.js +28 -0
- package/dist/action/validate/tool.js +56 -0
- package/dist/action/validate/unknown.js +58 -0
- package/dist/action/validate/unsound.js +99 -0
- package/dist/action/whoami/tool.js +7 -0
- package/dist/api.js +160 -0
- package/dist/arc.js +41 -0
- package/dist/cli/argv.js +61 -0
- package/dist/cli/channel.js +29 -0
- package/dist/cli/command.js +163 -0
- package/dist/cli/confirm.js +39 -0
- package/dist/cli/options.js +62 -0
- package/dist/cli/rc.js +103 -0
- package/dist/cli/yargs.js +40 -0
- package/dist/command/build.js +68 -0
- package/dist/command/delete.js +66 -0
- package/dist/command/deploy.js +308 -0
- package/dist/command/function/index.js +17 -0
- package/dist/command/function/pause.js +18 -0
- package/dist/command/function/resume.js +18 -0
- package/dist/command/function/run.js +41 -0
- package/dist/command/function/secret/index.js +15 -0
- package/dist/command/function/secret/list.js +27 -0
- package/dist/command/function/secret/name.js +8 -0
- package/dist/command/function/secret/remove.js +26 -0
- package/dist/command/function/secret/run.js +52 -0
- package/dist/command/function/secret/set.js +48 -0
- package/dist/command/function/status.js +40 -0
- package/dist/command/init.js +128 -0
- package/dist/command/inspect.js +38 -0
- package/dist/command/login.js +108 -0
- package/dist/command/logout.js +24 -0
- package/dist/command/open.js +48 -0
- package/dist/command/pack.js +90 -0
- package/dist/command/play.js +80 -0
- package/dist/command/serve.js +176 -0
- package/dist/command/server/index.js +17 -0
- package/dist/command/server/key/create.js +36 -0
- package/dist/command/server/key/index.js +15 -0
- package/dist/command/server/key/list.js +34 -0
- package/dist/command/server/key/revoke.js +24 -0
- package/dist/command/server/key/run.js +54 -0
- package/dist/command/validate.js +47 -0
- package/dist/command/whoami.js +55 -0
- package/dist/commands.js +93 -0
- package/dist/config/ai.js +2 -0
- package/dist/config/art.js +13 -0
- package/dist/config/audience.js +2 -0
- package/dist/config/code.js +129 -0
- package/dist/config/file.js +13 -0
- package/dist/config/genre.js +19 -0
- package/{src → dist}/config/html.js +2 -7
- package/dist/config/image.js +5 -0
- package/dist/config/input.js +11 -0
- package/dist/config/json.js +23 -0
- package/dist/config/limit.js +14 -0
- package/dist/config/orientation.js +11 -0
- package/dist/config/package.js +8 -0
- package/dist/config/product.js +14 -0
- package/dist/config/template.js +37 -0
- package/dist/config/uri.js +18 -0
- package/dist/config/url.js +11 -0
- package/dist/config/video.js +5 -0
- package/dist/config/visibility.js +2 -0
- package/dist/config/workflow.js +7 -0
- package/dist/parser/env.js +61 -0
- package/dist/parser/given.js +8 -0
- package/dist/parser/manifest.js +45 -0
- package/dist/parser/media.js +57 -0
- package/dist/parser/project.js +129 -0
- package/dist/parser/readme-file.js +44 -0
- package/dist/parser/readme.js +70 -0
- package/dist/parser/sections.js +92 -0
- package/dist/parser/self.js +16 -0
- package/dist/phrase/account.js +35 -0
- package/dist/phrase/common.js +130 -0
- package/dist/phrase/deploy.js +184 -0
- package/dist/phrase/function.js +135 -0
- package/dist/phrase/game.js +27 -0
- package/dist/phrase/index.js +15 -0
- package/dist/phrase/init.js +53 -0
- package/dist/phrase/internal.js +61 -0
- package/dist/phrase/manifest.js +120 -0
- package/dist/phrase/media.js +90 -0
- package/dist/phrase/pack.js +69 -0
- package/dist/phrase/serve.js +84 -0
- package/dist/phrase/server.js +38 -0
- package/dist/runner/bundle.js +95 -0
- package/dist/runner/outbound.js +69 -0
- package/dist/schema/check/game.js +29 -0
- package/dist/schema/check/workflow.js +57 -0
- package/dist/schema/game.js +462 -0
- package/dist/schema/message.js +61 -0
- package/dist/schema/readme.js +27 -0
- package/dist/schema/runner.js +43 -0
- package/dist/schema/server.js +91 -0
- package/dist/schema/workflow.js +99 -0
- package/dist/serve/files.js +39 -0
- package/dist/serve/game.js +172 -0
- package/dist/serve/page.js +490 -0
- package/dist/serve/reload.js +55 -0
- package/dist/serve/remote.js +114 -0
- package/dist/serve/runner.js +296 -0
- package/dist/serve/server.js +163 -0
- package/dist/serve/ticket.js +232 -0
- package/dist/util/bytes.js +16 -0
- package/dist/util/chars.js +19 -0
- package/dist/util/command.js +11 -0
- package/dist/util/delay.js +36 -0
- package/dist/util/doc.js +59 -0
- package/dist/util/error.js +35 -0
- package/dist/util/http.js +13 -0
- package/dist/util/image.js +64 -0
- package/dist/util/links.js +45 -0
- package/dist/util/lockfile.js +17 -0
- package/dist/util/log.js +101 -0
- package/dist/util/md.js +37 -0
- package/dist/util/media.js +27 -0
- package/dist/util/objs.js +29 -0
- package/dist/util/os.js +13 -0
- package/dist/util/output.js +133 -0
- package/dist/util/paths.js +8 -0
- package/dist/util/progress.js +57 -0
- package/dist/util/promise.js +18 -0
- package/dist/util/request.js +91 -0
- package/dist/util/s3.js +67 -0
- package/dist/util/schema.js +151 -0
- package/dist/util/screenshot.js +24 -0
- package/dist/util/shell.js +64 -0
- package/dist/util/size.js +32 -0
- package/dist/util/spinner.js +35 -0
- package/dist/util/strs.js +46 -0
- package/dist/util/table.js +18 -0
- package/dist/util/term.js +21 -0
- package/dist/util/time.js +16 -0
- package/dist/util/toml.js +28 -0
- package/{src → dist}/util/uris.js +8 -14
- package/dist/util/video.js +113 -0
- package/dist/util/zip.js +62 -0
- package/npm-shrinkwrap.json +3256 -0
- package/package.json +42 -40
- package/bin/arc-build.js +0 -139
- package/bin/arc-default.js +0 -65
- package/bin/arc-deploy.js +0 -456
- package/bin/arc-init.js +0 -187
- package/bin/arc-inspect.js +0 -97
- package/bin/arc-login.js +0 -165
- package/bin/arc-logout.js +0 -75
- package/bin/arc-open.js +0 -104
- package/bin/arc-pack.js +0 -146
- package/bin/arc-play.js +0 -140
- package/bin/arc-serve.js +0 -214
- package/bin/arc-validate.js +0 -112
- package/bin/arc-whoami.js +0 -119
- package/src/account.js +0 -249
- package/src/action/build/tool.js +0 -80
- package/src/action/deploy/tool-git.js +0 -90
- package/src/action/deploy/tool.js +0 -88
- package/src/action/deploy/wait.js +0 -151
- package/src/action/init/manifest.js +0 -83
- package/src/action/init/tool-patch.js +0 -32
- package/src/action/init/tool.js +0 -97
- package/src/action/inspect/tool.js +0 -26
- package/src/action/login/flow.js +0 -101
- package/src/action/login/tool.js +0 -16
- package/src/action/logout/tool.js +0 -15
- package/src/action/open/tool.js +0 -38
- package/src/action/pack/limits.js +0 -51
- package/src/action/pack/tool.js +0 -171
- package/src/action/pack/unsound.js +0 -69
- package/src/action/play/tool.js +0 -109
- package/src/action/predeploy/ac.js +0 -112
- package/src/action/predeploy/git.js +0 -223
- package/src/action/predeploy/pm.js +0 -37
- package/src/action/predeploy/published.js +0 -82
- package/src/action/predeploy/tool-git.js +0 -154
- package/src/action/predeploy/tool.js +0 -29
- package/src/action/serve/tool.js +0 -209
- package/src/action/validate/checked.js +0 -37
- package/src/action/validate/tool.js +0 -67
- package/src/action/validate/unknown.js +0 -86
- package/src/action/validate/unsound.js +0 -138
- package/src/action/whoami/tool.js +0 -15
- package/src/api.js +0 -163
- package/src/cli/build.js +0 -15
- package/src/cli/deploy.js +0 -21
- package/src/cli/init.js +0 -17
- package/src/cli/inspect.js +0 -15
- package/src/cli/login.js +0 -15
- package/src/cli/logout.js +0 -15
- package/src/cli/open.js +0 -15
- package/src/cli/pack.js +0 -15
- package/src/cli/play.js +0 -15
- package/src/cli/predeploy.js +0 -21
- package/src/cli/serve.js +0 -15
- package/src/cli/validate.js +0 -15
- package/src/cli/whoami.js +0 -15
- package/src/config/ai.js +0 -5
- package/src/config/art.js +0 -16
- package/src/config/audience.js +0 -5
- package/src/config/code.js +0 -142
- package/src/config/file.js +0 -23
- package/src/config/genre.js +0 -22
- package/src/config/image.js +0 -7
- package/src/config/input.js +0 -14
- package/src/config/limit.js +0 -21
- package/src/config/orientation.js +0 -14
- package/src/config/package.js +0 -5
- package/src/config/product.js +0 -5
- package/src/config/template.js +0 -45
- package/src/config/uri.js +0 -27
- package/src/config/url.js +0 -20
- package/src/config/video.js +0 -7
- package/src/config/visibility.js +0 -5
- package/src/config/workflow.js +0 -18
- package/src/parser/env.js +0 -84
- package/src/parser/given.js +0 -17
- package/src/parser/manifest.js +0 -80
- package/src/parser/media.js +0 -90
- package/src/parser/project.js +0 -166
- package/src/parser/readme-file.js +0 -76
- package/src/parser/readme.js +0 -96
- package/src/parser/sections.js +0 -107
- package/src/parser/self.js +0 -27
- package/src/phrase.js +0 -1294
- package/src/schema/check/game.js +0 -61
- package/src/schema/check/workflow.js +0 -99
- package/src/schema/game.js +0 -649
- package/src/schema/message.js +0 -85
- package/src/schema/readme.js +0 -44
- package/src/schema/workflow.js +0 -150
- package/src/serve/files.js +0 -61
- package/src/serve/game.js +0 -191
- package/src/serve/page.js +0 -345
- package/src/serve/reload.js +0 -68
- package/src/serve/remote.js +0 -121
- package/src/serve/server.js +0 -128
- package/src/util/argv.js +0 -116
- package/src/util/bytes.js +0 -25
- package/src/util/chars.js +0 -30
- package/src/util/command.js +0 -18
- package/src/util/delay.js +0 -52
- package/src/util/doc.js +0 -72
- package/src/util/error.js +0 -50
- package/src/util/http.js +0 -25
- package/src/util/image.js +0 -93
- package/src/util/links.js +0 -78
- package/src/util/lockfile.js +0 -35
- package/src/util/log.js +0 -149
- package/src/util/md.js +0 -61
- package/src/util/media.js +0 -40
- package/src/util/objs.js +0 -45
- package/src/util/os.js +0 -27
- package/src/util/output.js +0 -174
- package/src/util/paths.js +0 -21
- package/src/util/progress.js +0 -85
- package/src/util/promise.js +0 -29
- package/src/util/rc.js +0 -144
- package/src/util/request.js +0 -89
- package/src/util/s3.js +0 -92
- package/src/util/schema.js +0 -189
- package/src/util/screenshot.js +0 -37
- package/src/util/shell.js +0 -84
- package/src/util/size.js +0 -53
- package/src/util/spinner.js +0 -52
- package/src/util/strs.js +0 -73
- package/src/util/term.js +0 -28
- package/src/util/time.js +0 -29
- package/src/util/toml.js +0 -14
- package/src/util/video.js +0 -157
- package/src/util/zip.js +0 -88
- /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,150 @@
|
|
|
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 { given } from "../../parser/given.js";
|
|
11
|
+
import { deployDirMissing, packageIndexMissing, packagePathReserved, packageTooLarge, runnerNotBuilt, unableToFind, } from "../../phrase/index.js";
|
|
12
|
+
import { ZIP_SIZE } from "../../config/limit.js";
|
|
13
|
+
import { check, measure } from "./limits.js";
|
|
14
|
+
import { handle, tool } from "../../config/product.js";
|
|
15
|
+
import { toMb } from "../../util/size.js";
|
|
16
|
+
import { unsound } from "./unsound.js";
|
|
17
|
+
import { Zip } from "../../util/zip.js";
|
|
18
|
+
// [use]
|
|
19
|
+
const parse = path.parse;
|
|
20
|
+
const resolve = path.resolve;
|
|
21
|
+
// [declare]
|
|
22
|
+
const TOOL = tool;
|
|
23
|
+
// [declare]
|
|
24
|
+
const MAIN = "index.html";
|
|
25
|
+
const MANIFEST = PACKAGED;
|
|
26
|
+
const OUTPUT = `.${TOOL}/package`;
|
|
27
|
+
// the folder every build's origin keeps for Arcadible's own files, such as
|
|
28
|
+
// the script games include, in any letter case.
|
|
29
|
+
const RESERVED = handle;
|
|
30
|
+
// [declare]
|
|
31
|
+
const SIZE_PARTIAL = ZIP_SIZE;
|
|
32
|
+
// [function]
|
|
33
|
+
// the first path at the build's root that's Arcadible's, if it has one: a
|
|
34
|
+
// folder named like the reserved one, or the manifest or media that packing
|
|
35
|
+
// adds, as `arc validate` checks deploy_dir. A folder ends with "/".
|
|
36
|
+
function findReserved(zip) {
|
|
37
|
+
return zip
|
|
38
|
+
.entries()
|
|
39
|
+
.map((entry) => entry.name.split("/"))
|
|
40
|
+
.map((parts) => (parts.length > 1 ? `${parts[0]}/` : String(parts[0])))
|
|
41
|
+
.find((name) => name.toLowerCase() === `${RESERVED}/` ||
|
|
42
|
+
name === MANIFEST ||
|
|
43
|
+
name === `${MEDIA}/`);
|
|
44
|
+
}
|
|
45
|
+
// [function]
|
|
46
|
+
// the files' own limits come first, since they name what to fix, such as
|
|
47
|
+
// the one file over 64 MB that makes the zip too large.
|
|
48
|
+
function verifyPartial(zip) {
|
|
49
|
+
if (!zip.has(MAIN)) {
|
|
50
|
+
throw new ArcError(PACKAGE_INDEX_MISSING, packageIndexMissing(MAIN));
|
|
51
|
+
}
|
|
52
|
+
const reserved = findReserved(zip);
|
|
53
|
+
if (reserved) {
|
|
54
|
+
throw new ArcError(PACKAGE_PATH_RESERVED, packagePathReserved(reserved));
|
|
55
|
+
}
|
|
56
|
+
check(zip.entries());
|
|
57
|
+
if (zip.stat().size > SIZE_PARTIAL) {
|
|
58
|
+
throw new ArcError(PACKAGE_TOO_LARGE, packageTooLarge(toMb(SIZE_PARTIAL)));
|
|
59
|
+
}
|
|
60
|
+
return zip;
|
|
61
|
+
}
|
|
62
|
+
// [function]
|
|
63
|
+
function verifyTotal(zip) {
|
|
64
|
+
check(zip.entries());
|
|
65
|
+
return zip;
|
|
66
|
+
}
|
|
67
|
+
// [function]
|
|
68
|
+
// `deployDir` when the input is deploy_dir, rather than a folder --input
|
|
69
|
+
// named: a missing deploy_dir means the build hasn't written it.
|
|
70
|
+
function pack(name, game, { deployDir, inputPath, mediaPath, onWarning, outputPath, runner, server, }) {
|
|
71
|
+
const zip = new Zip(name);
|
|
72
|
+
return pathExists(inputPath)
|
|
73
|
+
.then((existsInput) => {
|
|
74
|
+
if (!existsInput) {
|
|
75
|
+
throw deployDir
|
|
76
|
+
? new ArcError(DEPLOY_DIR_MISSING, deployDirMissing(inputPath))
|
|
77
|
+
: new ArcError(PATH_NOT_FOUND, unableToFind(inputPath));
|
|
78
|
+
}
|
|
79
|
+
// held to the limits by its sizes on disk, before any of it is read
|
|
80
|
+
check(measure(inputPath));
|
|
81
|
+
zip.addDir(inputPath);
|
|
82
|
+
return zip;
|
|
83
|
+
})
|
|
84
|
+
.then(verifyPartial)
|
|
85
|
+
.then(() => pathExists(mediaPath))
|
|
86
|
+
.then((existsMedia) => {
|
|
87
|
+
if (existsMedia) {
|
|
88
|
+
zip.addDir(mediaPath, MEDIA);
|
|
89
|
+
}
|
|
90
|
+
// the game's own servers go with it, when it declares any: the build
|
|
91
|
+
// keeps them, and a ticket is only ever for one of them. A runner goes
|
|
92
|
+
// as what it may reach, never where its code was.
|
|
93
|
+
zip.addJson(MANIFEST, {
|
|
94
|
+
game,
|
|
95
|
+
...(runner
|
|
96
|
+
? {
|
|
97
|
+
function: {
|
|
98
|
+
outbound_hosts: runner.table.outbound_hosts ?? [],
|
|
99
|
+
secrets: runner.table.secrets ?? [],
|
|
100
|
+
},
|
|
101
|
+
}
|
|
102
|
+
: {}),
|
|
103
|
+
...(Array.isArray(server?.origins) && server.origins.length
|
|
104
|
+
? { server }
|
|
105
|
+
: {}),
|
|
106
|
+
});
|
|
107
|
+
return runner ? pathExists(runner.built) : false;
|
|
108
|
+
})
|
|
109
|
+
.then((built) => {
|
|
110
|
+
// the runner's bundle, as `arc build` wrote it, in the folder every
|
|
111
|
+
// build's origin keeps for Arcadible's own files, which is never served
|
|
112
|
+
if (runner && !built) {
|
|
113
|
+
throw new ArcError(PATH_NOT_FOUND, runnerNotBuilt());
|
|
114
|
+
}
|
|
115
|
+
if (runner) {
|
|
116
|
+
zip.addFile(runner.built, PACKED);
|
|
117
|
+
}
|
|
118
|
+
return zip;
|
|
119
|
+
})
|
|
120
|
+
.then(verifyTotal)
|
|
121
|
+
.then((file) => {
|
|
122
|
+
if (onWarning) {
|
|
123
|
+
unsound(file.entries()).forEach(onWarning);
|
|
124
|
+
}
|
|
125
|
+
file.write(outputPath);
|
|
126
|
+
return { path: outputPath, ...file.stat() };
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
// [function]
|
|
130
|
+
// `onWarning` gets each of the package's warnings, such as a `.env` file
|
|
131
|
+
// in it, as a command's own. The project is one that passed validation, so
|
|
132
|
+
// its deploy_dir is a path.
|
|
133
|
+
export function packTool({ input, onWarning, output, ...conf }) {
|
|
134
|
+
const root = conf.root;
|
|
135
|
+
return given(conf).then(({ function: runner, game, server, workflow }) => {
|
|
136
|
+
const name = String(game.handle ?? game.id);
|
|
137
|
+
const file = output ?? `${OUTPUT}/${name}-v${String(game.version)}.zip`;
|
|
138
|
+
const deployDir = resolve(root, String(workflow.deploy_dir));
|
|
139
|
+
const inputPath = resolve(root, input ?? String(workflow.deploy_dir));
|
|
140
|
+
return pack(parse(file).name, game, {
|
|
141
|
+
deployDir: inputPath === deployDir,
|
|
142
|
+
inputPath,
|
|
143
|
+
mediaPath: resolve(root, MEDIA),
|
|
144
|
+
onWarning,
|
|
145
|
+
outputPath: resolve(root, file),
|
|
146
|
+
runner: runner ? { built: resolve(root, BUILT), table: runner } : null,
|
|
147
|
+
server,
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
@@ -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,83 @@
|
|
|
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 { self } from "../../parser/self.js";
|
|
9
|
+
// [function]
|
|
10
|
+
// the game, `select`ed, or null when the API can't be reached. It rejects
|
|
11
|
+
// when the game isn't on Arcadible: its builds can't say, since a game that
|
|
12
|
+
// doesn't exist has none.
|
|
13
|
+
function findGame(id, select) {
|
|
14
|
+
return discoverGame(id, { select }).catch((err) => {
|
|
15
|
+
if (err instanceof HttpError && err.status === 404) {
|
|
16
|
+
throw new ArcError(GAME_NOT_FOUND, gameNotFound(id));
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
// [function]
|
|
22
|
+
function fallbackIf(fallback) {
|
|
23
|
+
return { fallback, release: fallback ? STAGING : PRODUCTION };
|
|
24
|
+
}
|
|
25
|
+
// [function]
|
|
26
|
+
// the release to play. A chosen one is used as is. Without one, it's
|
|
27
|
+
// production, or staging when the game has no production release yet. When
|
|
28
|
+
// the API can't be reached, it's production.
|
|
29
|
+
function resolveRelease(id, release) {
|
|
30
|
+
if (release) {
|
|
31
|
+
return Promise.resolve({ fallback: false, release });
|
|
32
|
+
}
|
|
33
|
+
return discoverGameBuilds(id, {
|
|
34
|
+
channel: PRODUCTION,
|
|
35
|
+
select: "version",
|
|
36
|
+
}).then((builds) => fallbackIf(!builds?.length), () => fallbackIf(false));
|
|
37
|
+
}
|
|
38
|
+
// [function]
|
|
39
|
+
function target(id, orientation, release) {
|
|
40
|
+
return resolveRelease(id, release).then(({ fallback, release: chosen }) => ({
|
|
41
|
+
fallback,
|
|
42
|
+
orientation: orientation ?? "natural",
|
|
43
|
+
url: playUrl(id, chosen),
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
// [function]
|
|
47
|
+
// another game: its orientation comes from the API, or natural when the API
|
|
48
|
+
// can't be reached.
|
|
49
|
+
function play(id, release) {
|
|
50
|
+
if (!id) {
|
|
51
|
+
return Promise.resolve(null);
|
|
52
|
+
}
|
|
53
|
+
return findGame(id, "orientation").then((game) => target(id, game?.orientation, release));
|
|
54
|
+
}
|
|
55
|
+
// [function]
|
|
56
|
+
// this project's game: its orientation comes from the manifest. With a
|
|
57
|
+
// chosen release, it makes no API call.
|
|
58
|
+
function playSelf(root, release) {
|
|
59
|
+
return self(root)
|
|
60
|
+
.then((game) => {
|
|
61
|
+
const named = game?.handle ?? game?.id;
|
|
62
|
+
if (!game || !named) {
|
|
63
|
+
return Promise.resolve([null, null]);
|
|
64
|
+
}
|
|
65
|
+
// a handle or an id as the manifest has it.
|
|
66
|
+
const id = String(named);
|
|
67
|
+
return Promise.all([
|
|
68
|
+
release ? null : findGame(id, "id"),
|
|
69
|
+
target(id, game.orientation, release),
|
|
70
|
+
]);
|
|
71
|
+
})
|
|
72
|
+
.then(([, found]) => found);
|
|
73
|
+
}
|
|
74
|
+
// [function]
|
|
75
|
+
export function playTool({ game: id, release, root, }, { onPlayFetch }) {
|
|
76
|
+
if (onPlayFetch) {
|
|
77
|
+
onPlayFetch({ game: id });
|
|
78
|
+
}
|
|
79
|
+
if (id === "self") {
|
|
80
|
+
return playSelf(root, release);
|
|
81
|
+
}
|
|
82
|
+
return play(id, release);
|
|
83
|
+
}
|
|
@@ -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,12 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
// [function]
|
|
3
|
+
// the fields a release goes by, of a project that passed validation, so its
|
|
4
|
+
// id and version are strings, and its handle is one when it has one. Each is
|
|
5
|
+
// read as it's written into a path or a message, as text.
|
|
6
|
+
export function releasing(game) {
|
|
7
|
+
return {
|
|
8
|
+
handle: (game.handle ?? null) === null ? null : String(game.handle),
|
|
9
|
+
id: String(game.id),
|
|
10
|
+
version: String(game.version),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -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
|
+
}
|