arcadible 1.0.23 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- 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 +41 -39
- 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
package/README.md
CHANGED
|
@@ -50,6 +50,7 @@ Your repository is the store page: `arcadible.toml` holds the game's settings, `
|
|
|
50
50
|
| `arc deploy` | Validates, builds, packages, and publishes, directly or through GitHub Actions |
|
|
51
51
|
| `arc play` | Plays a deployed game from any channel or version |
|
|
52
52
|
| `arc open` | Opens a game's store page |
|
|
53
|
+
| `arc delete` | Deletes the project's game from Arcadible, for good, asking first |
|
|
53
54
|
| `arc login` | Logs in to Arcadible with a device code |
|
|
54
55
|
| `arc logout` | Logs out |
|
|
55
56
|
| `arc whoami` | Shows the account you're logged in to |
|
package/bin/arc.js
CHANGED
|
@@ -1,86 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// [import]
|
|
5
|
-
|
|
6
|
-
const fs = require("fs-extra");
|
|
7
|
-
|
|
8
|
-
// [import]
|
|
9
|
-
|
|
10
|
-
const cfgpackage = require("../src/config/package");
|
|
11
|
-
const cfgproduct = require("../src/config/product");
|
|
12
|
-
const log = require("../src/util/log");
|
|
13
|
-
const phrase = require("../src/phrase");
|
|
14
|
-
|
|
15
|
-
// [use]
|
|
16
|
-
|
|
17
|
-
const pathExists = fs.pathExists;
|
|
18
|
-
const realpath = fs.realpath;
|
|
19
|
-
|
|
20
|
-
// [declare]
|
|
21
|
-
|
|
22
|
-
const BIN = cfgpackage.bin;
|
|
23
|
-
const TOOL = cfgproduct.tool;
|
|
24
|
-
|
|
25
|
-
// [function]
|
|
26
|
-
|
|
27
|
-
const dispatch = function (argv) {
|
|
28
|
-
const args = [...argv];
|
|
29
|
-
const subcmds = Object.keys(BIN)
|
|
30
|
-
.filter((key) => key !== TOOL)
|
|
31
|
-
.map((key) => key.slice(TOOL.length + 1));
|
|
32
|
-
if (!subcmds.includes(args[2])) {
|
|
33
|
-
args.splice(2, 0, "default");
|
|
34
|
-
}
|
|
35
|
-
return args;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// [function]
|
|
39
|
-
|
|
40
|
-
const normalize = function (argv) {
|
|
41
|
-
const args = [...argv];
|
|
42
|
-
args[1] = args[1].endsWith(".js")
|
|
43
|
-
? args[1].replace(/\.js$/u, `-${args[2]}.js`)
|
|
44
|
-
: args[1].concat(`-${args[2]}`);
|
|
45
|
-
args.splice(2, 1);
|
|
46
|
-
return args;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// [function]
|
|
50
|
-
|
|
51
|
-
// the script's own path, through any links: npm links only package.json's
|
|
52
|
-
// `bin` entries, so a command's sibling, such as `arc-default`, is found
|
|
53
|
-
// beside the real script, not beside the link that started it.
|
|
54
|
-
const resolve = function (argv) {
|
|
55
|
-
// left as it is when it can't be resolved, and reported as not found
|
|
56
|
-
return realpath(argv[1])
|
|
57
|
-
.catch(() => argv[1])
|
|
58
|
-
.then((file) => [argv[0], file, ...argv.slice(2)]);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// [function]
|
|
62
|
-
|
|
63
|
-
const main = function (argv, load) {
|
|
64
|
-
return resolve(argv).then((resolved) => {
|
|
65
|
-
const args = normalize(dispatch(resolved));
|
|
66
|
-
pathExists(args[1], (err, exists) => {
|
|
67
|
-
if (err || !exists) {
|
|
68
|
-
log.hd(phrase.aborted("command"));
|
|
69
|
-
log.pd(phrase.unableToFind(args[1]));
|
|
70
|
-
process.exit(1);
|
|
71
|
-
}
|
|
72
|
-
const command = load(args[1]);
|
|
73
|
-
command.main(args);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
// [start]
|
|
79
|
-
|
|
80
|
-
if (require.main === module) {
|
|
81
|
-
main(process.argv, require);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// [export]
|
|
85
|
-
|
|
86
|
-
module.exports = { main };
|
|
2
|
+
import "../dist/arc.js";
|
package/dist/account.js
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { chmod, mkdir, readFile, unlink, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
// [import]
|
|
5
|
+
import { auth, postAuthLogout, postAuthRefresh, } from "./api.js";
|
|
6
|
+
import { SESSION_EXPIRED } from "./config/code.js";
|
|
7
|
+
import { ArcError } from "./util/error.js";
|
|
8
|
+
import { HttpError } from "./util/http.js";
|
|
9
|
+
import { sessionExpired } from "./phrase/index.js";
|
|
10
|
+
import { deepSort, isTable } from "./util/objs.js";
|
|
11
|
+
import { configDir } from "./util/os.js";
|
|
12
|
+
import { title, tool } from "./config/product.js";
|
|
13
|
+
// [declare]
|
|
14
|
+
const DIR_MODE = 0o700;
|
|
15
|
+
const FILE = "account.json";
|
|
16
|
+
const FILE_MODE = 0o600;
|
|
17
|
+
// [declare]
|
|
18
|
+
// the statuses that mean the refresh token itself was refused.
|
|
19
|
+
const REJECTED = [400, 401, 403];
|
|
20
|
+
// [declare]
|
|
21
|
+
const TOKEN_USER = { display_name: `${title} Token`, id: null };
|
|
22
|
+
const TOOL = tool;
|
|
23
|
+
// [define]
|
|
24
|
+
const dir = join(configDir(), TOOL);
|
|
25
|
+
const file = join(dir, FILE);
|
|
26
|
+
// [function]
|
|
27
|
+
// whether a failure is the file system's, with this code, such as ENOENT.
|
|
28
|
+
function isCode(ex, code) {
|
|
29
|
+
return isTable(ex) && ex["code"] === code;
|
|
30
|
+
}
|
|
31
|
+
// [function]
|
|
32
|
+
function expired(session) {
|
|
33
|
+
// a session without an expiry never compares as expired, as the first
|
|
34
|
+
// CLI's `undefined <= …` didn't.
|
|
35
|
+
return Number(session.expires_at) <= Math.floor(Date.now() / 1000) + 60;
|
|
36
|
+
}
|
|
37
|
+
// [function]
|
|
38
|
+
// the session is a credential, so only its owner can read it: the directory
|
|
39
|
+
// is 0700 and the file 0600. `mode` only applies when a file is created, so
|
|
40
|
+
// both are also set on every save, which fixes an older, readable file. The
|
|
41
|
+
// modes are ignored on Windows, where %LOCALAPPDATA% is already private.
|
|
42
|
+
export function save(current) {
|
|
43
|
+
return mkdir(dir, { mode: DIR_MODE, recursive: true })
|
|
44
|
+
.then(() => chmod(dir, DIR_MODE))
|
|
45
|
+
.then(() => writeFile(file, JSON.stringify(deepSort(current), null, 2), {
|
|
46
|
+
encoding: "utf8",
|
|
47
|
+
mode: FILE_MODE,
|
|
48
|
+
}))
|
|
49
|
+
.then(() => chmod(file, FILE_MODE))
|
|
50
|
+
.then(() => current);
|
|
51
|
+
}
|
|
52
|
+
// [function]
|
|
53
|
+
export function remove() {
|
|
54
|
+
return unlink(file).catch((ex) => {
|
|
55
|
+
if (isCode(ex, "ENOENT")) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
throw ex;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// [function]
|
|
62
|
+
// the error for a session that can't be used again, once it's removed, so
|
|
63
|
+
// arc whoami no longer names its account.
|
|
64
|
+
function expire(ex) {
|
|
65
|
+
return remove().then(() => {
|
|
66
|
+
throw new ArcError(SESSION_EXPIRED, sessionExpired(), {
|
|
67
|
+
cause: ex,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
// [function]
|
|
72
|
+
// renews the session. When the refresh token is rejected, the session can't
|
|
73
|
+
// be used again: it's removed, and the error says to log in.
|
|
74
|
+
function refresh({ session, ...current }) {
|
|
75
|
+
const form = new FormData();
|
|
76
|
+
form.append("refresh_token", String(session.refresh_token));
|
|
77
|
+
return postAuthRefresh(form).then((data) => save({ ...current, session: data }), (ex) => {
|
|
78
|
+
if (ex instanceof HttpError && REJECTED.includes(ex.status)) {
|
|
79
|
+
return expire(ex);
|
|
80
|
+
}
|
|
81
|
+
throw ex;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
// [function]
|
|
85
|
+
// the saved file as an account, when it holds a session: the file is the
|
|
86
|
+
// CLI's own, as `save` wrote it, so what its session and user hold is taken
|
|
87
|
+
// as it is.
|
|
88
|
+
function isAccount(saved) {
|
|
89
|
+
return isTable(saved) && isTable(saved["session"]);
|
|
90
|
+
}
|
|
91
|
+
// [function]
|
|
92
|
+
// the saved file as it is, or null when there's none.
|
|
93
|
+
function readSaved() {
|
|
94
|
+
return readFile(file, "utf8")
|
|
95
|
+
.then((text) => JSON.parse(text))
|
|
96
|
+
.catch((ex) => {
|
|
97
|
+
// a session file cut short (a full disk, a crash while saving) is no
|
|
98
|
+
// session: `arc login` writes a new one
|
|
99
|
+
if (isCode(ex, "ENOENT") || ex instanceof SyntaxError) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
throw ex;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
// [function]
|
|
106
|
+
function getSaved(onRefresh) {
|
|
107
|
+
return readSaved().then((current) => {
|
|
108
|
+
if (!isAccount(current)) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
if (!expired(current.session)) {
|
|
112
|
+
return current;
|
|
113
|
+
}
|
|
114
|
+
// the handler starts its spinner, then refreshes.
|
|
115
|
+
return onRefresh ? onRefresh(() => refresh(current)) : null;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
// [function]
|
|
119
|
+
// the account an ARCADIBLE_TOKEN stands for. The API doesn't describe a
|
|
120
|
+
// token's user yet, so this is a placeholder with a real user's shape, to be
|
|
121
|
+
// replaced by the API's answer without changing it.
|
|
122
|
+
function fromToken(token) {
|
|
123
|
+
return { session: { access_token: token }, token: true, user: TOKEN_USER };
|
|
124
|
+
}
|
|
125
|
+
// [function]
|
|
126
|
+
// the account commands use: ARCADIBLE_TOKEN when it's set, which takes
|
|
127
|
+
// precedence over the saved session, or else the saved session, refreshed if
|
|
128
|
+
// needed.
|
|
129
|
+
export function get(onRefresh) {
|
|
130
|
+
const token = process.env["ARCADIBLE_TOKEN"];
|
|
131
|
+
if (token) {
|
|
132
|
+
return Promise.resolve(fromToken(token));
|
|
133
|
+
}
|
|
134
|
+
return getSaved(onRefresh);
|
|
135
|
+
}
|
|
136
|
+
// [function]
|
|
137
|
+
// a failed request's handler for commands that send the saved session's
|
|
138
|
+
// token. The API refuses it (401) only when Supabase does: for a deleted
|
|
139
|
+
// account, or a token that expired by the server's clock though not by
|
|
140
|
+
// this one's. A refresh tells them apart: refused, the session is over, so
|
|
141
|
+
// it's removed and the error says to log in (session_expired); renewed, the
|
|
142
|
+
// session is kept, and the request's own error stands, so running the
|
|
143
|
+
// command again works. An ARCADIBLE_TOKEN's refusal stays as it is, since
|
|
144
|
+
// logging in doesn't change the token.
|
|
145
|
+
export function ended(current) {
|
|
146
|
+
return (ex) => {
|
|
147
|
+
if (!current?.session ||
|
|
148
|
+
current.token ||
|
|
149
|
+
!(ex instanceof HttpError) ||
|
|
150
|
+
ex.status !== 401) {
|
|
151
|
+
throw ex;
|
|
152
|
+
}
|
|
153
|
+
return refresh(current).then(() => {
|
|
154
|
+
throw ex;
|
|
155
|
+
}, (refreshEx) => {
|
|
156
|
+
throw refreshEx instanceof ArcError ? refreshEx : ex;
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
// [function]
|
|
161
|
+
// an access token for the saved session to end with: its own, or a refreshed
|
|
162
|
+
// one when it's expired, which isn't saved, since the session is ending.
|
|
163
|
+
function accessToken(session) {
|
|
164
|
+
if (!expired(session)) {
|
|
165
|
+
return Promise.resolve(session.access_token);
|
|
166
|
+
}
|
|
167
|
+
const form = new FormData();
|
|
168
|
+
form.append("refresh_token", String(session.refresh_token));
|
|
169
|
+
return postAuthRefresh(form).then((data) => data.access_token);
|
|
170
|
+
}
|
|
171
|
+
// [function]
|
|
172
|
+
function revoke(session) {
|
|
173
|
+
return accessToken(session).then((access) => postAuthLogout(null, auth(access)));
|
|
174
|
+
}
|
|
175
|
+
// [function]
|
|
176
|
+
// a logout: the saved session ended on the server, so its refresh token stops
|
|
177
|
+
// working, then removed. Never an error: a refused refresh means the session
|
|
178
|
+
// was already over, and a failure to reach the API (offline, an outage)
|
|
179
|
+
// leaves it to expire after 90 idle days, while the file is removed either
|
|
180
|
+
// way. It ends only the saved session: never an ARCADIBLE_TOKEN, nor any
|
|
181
|
+
// other session. It resolves with the user whose session it was, or null
|
|
182
|
+
// when there was none to end.
|
|
183
|
+
export function end() {
|
|
184
|
+
return readSaved()
|
|
185
|
+
.then((current) => {
|
|
186
|
+
if (!isAccount(current)) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
const user = isTable(current.user) ? current.user : null;
|
|
190
|
+
if (!current.session.refresh_token) {
|
|
191
|
+
return user;
|
|
192
|
+
}
|
|
193
|
+
return revoke(current.session).then(() => user, () => user);
|
|
194
|
+
})
|
|
195
|
+
.catch(() => null)
|
|
196
|
+
.then((user) => remove().then(() => user));
|
|
197
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import cp from "node:child_process";
|
|
3
|
+
import { resolve as resolvePath } from "node:path";
|
|
4
|
+
// [import]
|
|
5
|
+
import { pathExists } from "fs-extra";
|
|
6
|
+
// [import]
|
|
7
|
+
import { BUILD_FAILED } from "../../config/code.js";
|
|
8
|
+
import { given } from "../../parser/given.js";
|
|
9
|
+
import * as phrase from "../../phrase/index.js";
|
|
10
|
+
import { BUILT, bundle } from "../../runner/bundle.js";
|
|
11
|
+
import { buildCommand } from "../../util/command.js";
|
|
12
|
+
import { ArcError } from "../../util/error.js";
|
|
13
|
+
// [function]
|
|
14
|
+
// a build's output has no limit: exec's default maxBuffer, 1 MB, would kill a
|
|
15
|
+
// verbose build that otherwise succeeds. `exec` is called through the module,
|
|
16
|
+
// so the tests' fake of it applies.
|
|
17
|
+
function execBuild(command, { cwdPath }) {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
cp.exec(command, { cwd: cwdPath, maxBuffer: Infinity }, (err, stdout, stderr) => {
|
|
20
|
+
if (err) {
|
|
21
|
+
const { code, signal } = err;
|
|
22
|
+
reject(new ArcError(BUILD_FAILED, phrase.buildFailed({ code, signal, stderr, stdout }), { cause: err }));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
resolve();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// [function]
|
|
30
|
+
// runs the build, and resolves with deploy_dir's path. It resolves with null
|
|
31
|
+
// when there's no build to run, and with `{ missing }` when the build ran but
|
|
32
|
+
// didn't create deploy_dir.
|
|
33
|
+
function build(command, { cwdPath, outputPath }) {
|
|
34
|
+
return command
|
|
35
|
+
? execBuild(command, { cwdPath })
|
|
36
|
+
.then(() => pathExists(outputPath))
|
|
37
|
+
.then((exists) => (exists ? { path: outputPath } : { missing: outputPath }))
|
|
38
|
+
: Promise.resolve(null);
|
|
39
|
+
}
|
|
40
|
+
// [function]
|
|
41
|
+
// the game's runner, bundled after the project's own build, which may have
|
|
42
|
+
// written the code it's made from: resolves with the bundle's path, or null
|
|
43
|
+
// for a game with none.
|
|
44
|
+
function buildRunner(root, main) {
|
|
45
|
+
return typeof main === "string"
|
|
46
|
+
? bundle({
|
|
47
|
+
main: resolvePath(root, main),
|
|
48
|
+
outfile: resolvePath(root, BUILT),
|
|
49
|
+
})
|
|
50
|
+
: Promise.resolve(null);
|
|
51
|
+
}
|
|
52
|
+
// [function]
|
|
53
|
+
// builds the project: its own build, then its runner, when it has one. The
|
|
54
|
+
// result is the build's, with `function`, the bundle's path, beside it. The
|
|
55
|
+
// project is one that passed validation, so its deploy_dir is a path.
|
|
56
|
+
export async function buildTool(conf) {
|
|
57
|
+
const root = conf.root;
|
|
58
|
+
const { function: runner, workflow } = await given(conf);
|
|
59
|
+
const artifact = await build(buildCommand(workflow.build), {
|
|
60
|
+
cwdPath: root,
|
|
61
|
+
outputPath: resolvePath(root, String(workflow.deploy_dir)),
|
|
62
|
+
});
|
|
63
|
+
const bundled = await buildRunner(root, runner?.main);
|
|
64
|
+
return bundled ? { ...artifact, function: bundled } : artifact;
|
|
65
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// deleting a game: the project's own, on Arcadible, by its owner. It's gone
|
|
2
|
+
// for players at once, with every build, and it can't be undone. Nothing in
|
|
3
|
+
// the project changes.
|
|
4
|
+
import { deleteGame } from "../../api.js";
|
|
5
|
+
import { GAME_ID_MISSING, GAME_UNAVAILABLE } from "../../config/code.js";
|
|
6
|
+
import { ArcError } from "../../util/error.js";
|
|
7
|
+
import { headersOf, isStatus } from "../game.js";
|
|
8
|
+
import { given } from "../../parser/given.js";
|
|
9
|
+
import { gameIdMissing, gameUndeletable } from "../../phrase/index.js";
|
|
10
|
+
// [function]
|
|
11
|
+
// a value of the manifest's as a name, when it's text with something in it.
|
|
12
|
+
function text(value) {
|
|
13
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
14
|
+
}
|
|
15
|
+
// [function]
|
|
16
|
+
// the game the project names, which must have an id: a game is deleted by
|
|
17
|
+
// its id, never by a handle, which another game could come to hold.
|
|
18
|
+
export function named(conf) {
|
|
19
|
+
return given(conf).then(({ game }) => {
|
|
20
|
+
if (!game.id) {
|
|
21
|
+
throw new ArcError(GAME_ID_MISSING, gameIdMissing());
|
|
22
|
+
}
|
|
23
|
+
const id = String(game.id);
|
|
24
|
+
return { id, title: text(game.title) ?? text(game.handle) ?? id };
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// [function]
|
|
28
|
+
// deletes the game, as the logged-in account, and resolves with `{ game }`,
|
|
29
|
+
// its id. One the API doesn't find for this account (never deployed, deleted
|
|
30
|
+
// already, or another account's) is unavailable, as it is to the other
|
|
31
|
+
// commands a game's owner runs.
|
|
32
|
+
export async function deleteTool(current, { id }) {
|
|
33
|
+
const headers = headersOf(current);
|
|
34
|
+
try {
|
|
35
|
+
await deleteGame(id, null, headers);
|
|
36
|
+
return { game: id };
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
if (isStatus(err, 404)) {
|
|
40
|
+
throw new ArcError(GAME_UNAVAILABLE, gameUndeletable(id), {
|
|
41
|
+
cause: err,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// the project once arc deploy's build has run.
|
|
2
|
+
import { VALIDATION_FAILED } from "../../config/code.js";
|
|
3
|
+
import { ArcError } from "../../util/error.js";
|
|
4
|
+
import { issuesAfterBuild } from "../../phrase/index.js";
|
|
5
|
+
import { project } from "../../parser/project.js";
|
|
6
|
+
import { validateTool } from "../validate/tool.js";
|
|
7
|
+
// [function]
|
|
8
|
+
// whether a project is checked, which it is when validating it found no
|
|
9
|
+
// issues (action/validate/checked.ts).
|
|
10
|
+
function isChecked(_parsed, issues) {
|
|
11
|
+
return !issues.length;
|
|
12
|
+
}
|
|
13
|
+
// [function]
|
|
14
|
+
// A build can write files the manifest reads, such as art, so the project is
|
|
15
|
+
// parsed and validated again after one runs: resolves with it, or rejects as
|
|
16
|
+
// validation_failed with its issues in `data`. Its warnings aren't listed
|
|
17
|
+
// again.
|
|
18
|
+
export async function rebuilt(root) {
|
|
19
|
+
const parsed = await project(root);
|
|
20
|
+
const validated = await validateTool({ project: parsed, root });
|
|
21
|
+
if (!isChecked(parsed, validated.issues)) {
|
|
22
|
+
throw new ArcError(VALIDATION_FAILED, issuesAfterBuild(validated.issues.length), { data: { issues: validated.issues } });
|
|
23
|
+
}
|
|
24
|
+
return parsed;
|
|
25
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// what arc deploy prints of a deploy and its release.
|
|
2
|
+
import { published } from "../../util/links.js";
|
|
3
|
+
// [function]
|
|
4
|
+
// what the deploy prints. The game and release are for waiting, not
|
|
5
|
+
// printing. `held` when the handle rules held the handle back from this
|
|
6
|
+
// release, so the game's links are by id.
|
|
7
|
+
export function resultOf(deployed, { built, git, held, warnings, }) {
|
|
8
|
+
const { channel, store, url } = held
|
|
9
|
+
? published({ id: deployed.game, version: deployed.version.to })
|
|
10
|
+
: deployed;
|
|
11
|
+
return {
|
|
12
|
+
...(git ? {} : { built }),
|
|
13
|
+
channel,
|
|
14
|
+
store,
|
|
15
|
+
...("tag" in deployed ? { tag: deployed.tag } : {}),
|
|
16
|
+
url,
|
|
17
|
+
version: deployed.version,
|
|
18
|
+
warnings,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
// [function]
|
|
22
|
+
// the release, as `--json` prints it.
|
|
23
|
+
export function releaseJson(row) {
|
|
24
|
+
if (!row) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
build: row.build,
|
|
29
|
+
channel: row.channel,
|
|
30
|
+
id: row.id,
|
|
31
|
+
message: row.message,
|
|
32
|
+
reason: row.reason,
|
|
33
|
+
status: row.status,
|
|
34
|
+
version: row.version,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// arc deploy's `--timeout`: how long `--wait` waits, and what it may be.
|
|
2
|
+
// [import]
|
|
3
|
+
import { ARGUMENT_INVALID } from "../../config/code.js";
|
|
4
|
+
import { ArcError } from "../../util/error.js";
|
|
5
|
+
import { timeoutInvalid } from "../../phrase/index.js";
|
|
6
|
+
// [declare]
|
|
7
|
+
// how long `--wait` waits, in seconds. A git release waits on its GitHub
|
|
8
|
+
// workflow first.
|
|
9
|
+
export const TIMEOUT = { direct: 300, git: 900 };
|
|
10
|
+
// [function]
|
|
11
|
+
// fails unless the timeout is a number of seconds above 0: otherwise the
|
|
12
|
+
// wait would never end.
|
|
13
|
+
export function checkTimeout(timeout) {
|
|
14
|
+
if (Number.isFinite(timeout) && timeout > 0) {
|
|
15
|
+
return Promise.resolve();
|
|
16
|
+
}
|
|
17
|
+
return Promise.reject(new ArcError(ARGUMENT_INVALID, timeoutInvalid()));
|
|
18
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { GIT_TAG_CREATE_FAILED, GIT_TAG_PUSH_FAILED, } from "../../config/code.js";
|
|
3
|
+
import { ArcError } from "../../util/error.js";
|
|
4
|
+
import { releasing } from "../predeploy/game.js";
|
|
5
|
+
import { git, stderrOf, tagOf } from "../predeploy/git.js";
|
|
6
|
+
import { given } from "../../parser/given.js";
|
|
7
|
+
import { gitTagCreateFailed, gitTagPushFailed, versionPrerelease, versionRelease, } from "../../phrase/index.js";
|
|
8
|
+
import { channel, PRODUCTION, published, } from "../../util/links.js";
|
|
9
|
+
// [function]
|
|
10
|
+
function createTag(root, version) {
|
|
11
|
+
const message = channel(version) === PRODUCTION
|
|
12
|
+
? versionRelease(version)
|
|
13
|
+
: versionPrerelease(version);
|
|
14
|
+
return git(root, ["tag", "-a", tagOf(version), "-m", message]).then(() => null, (err) => {
|
|
15
|
+
throw new ArcError(GIT_TAG_CREATE_FAILED, gitTagCreateFailed(version, stderrOf(err)), { cause: err });
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
// [function]
|
|
19
|
+
// deletes the local tag, then fails with `failed` whether or not it could.
|
|
20
|
+
function untag(root, version, failed) {
|
|
21
|
+
const fail = () => {
|
|
22
|
+
throw failed;
|
|
23
|
+
};
|
|
24
|
+
return git(root, ["tag", "-d", tagOf(version)]).then(fail, fail);
|
|
25
|
+
}
|
|
26
|
+
// [function]
|
|
27
|
+
// the local tag is deleted when the push fails, so trying again isn't
|
|
28
|
+
// blocked by a tag that was never released.
|
|
29
|
+
function pushTag(root, version) {
|
|
30
|
+
return git(root, ["push", "origin", tagOf(version)]).then(() => null, (err) => untag(root, version, new ArcError(GIT_TAG_PUSH_FAILED, gitTagPushFailed(version, stderrOf(err)), {
|
|
31
|
+
cause: err,
|
|
32
|
+
})));
|
|
33
|
+
}
|
|
34
|
+
// [function]
|
|
35
|
+
// tags the version and pushes the tag: the Arcadible GitHub App publishes
|
|
36
|
+
// the release that the workflow builds from it.
|
|
37
|
+
export function deployToolGit(conf, { onDeployBegin }) {
|
|
38
|
+
if (onDeployBegin) {
|
|
39
|
+
onDeployBegin();
|
|
40
|
+
}
|
|
41
|
+
return given(conf)
|
|
42
|
+
.then(({ game: parsed }) => {
|
|
43
|
+
const game = releasing(parsed);
|
|
44
|
+
return createTag(conf.root, game.version)
|
|
45
|
+
.then(() => pushTag(conf.root, game.version))
|
|
46
|
+
.then(() => game);
|
|
47
|
+
})
|
|
48
|
+
.then((game) => ({
|
|
49
|
+
...published(game),
|
|
50
|
+
game: game.id,
|
|
51
|
+
tag: tagOf(game.version),
|
|
52
|
+
version: { to: game.version },
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { auth, postUpload } from "../../api.js";
|
|
3
|
+
import { DEPLOY_RATE_LIMITED, GAME_UNAVAILABLE } from "../../config/code.js";
|
|
4
|
+
import { ArcError } from "../../util/error.js";
|
|
5
|
+
import { releasing } from "../predeploy/game.js";
|
|
6
|
+
import { given } from "../../parser/given.js";
|
|
7
|
+
import { HttpError } from "../../util/http.js";
|
|
8
|
+
import { deployRateLimited, gameUnavailable } from "../../phrase/index.js";
|
|
9
|
+
import { published } from "../../util/links.js";
|
|
10
|
+
import { upload as s3Upload } from "../../util/s3.js";
|
|
11
|
+
// [function]
|
|
12
|
+
// asks the API for an upload link, then sends the zip to it, and resolves
|
|
13
|
+
// with the upload.
|
|
14
|
+
function uploadBuild(current, artifact, { id, version }, onProgress) {
|
|
15
|
+
const form = new FormData();
|
|
16
|
+
form.append("artifact", id);
|
|
17
|
+
form.append("version", version);
|
|
18
|
+
form.append("sha256", artifact.sha256);
|
|
19
|
+
form.append("size", String(artifact.size));
|
|
20
|
+
return postUpload(form, null, auth(current?.session?.access_token)).then((upload) => s3Upload(upload.upload_url, artifact, onProgress).then(() => upload), (err) => {
|
|
21
|
+
// the API refuses a game that was deleted or is another account's
|
|
22
|
+
// (403), and the same version deployed again within 5 minutes (429).
|
|
23
|
+
if (err instanceof HttpError && err.status === 403) {
|
|
24
|
+
throw new ArcError(GAME_UNAVAILABLE, gameUnavailable(id), {
|
|
25
|
+
cause: err,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (err instanceof HttpError && err.status === 429) {
|
|
29
|
+
throw new ArcError(DEPLOY_RATE_LIMITED, deployRateLimited(version), {
|
|
30
|
+
cause: err,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
throw err;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
// [function]
|
|
37
|
+
export function deployTool(current, artifact, conf, { onDeployBegin, onUploadProgress }) {
|
|
38
|
+
if (onDeployBegin) {
|
|
39
|
+
onDeployBegin({ root: conf.root });
|
|
40
|
+
}
|
|
41
|
+
return given(conf)
|
|
42
|
+
.then(({ game: parsed }) => {
|
|
43
|
+
const game = releasing(parsed);
|
|
44
|
+
return uploadBuild(current, artifact, game, onUploadProgress).then((upload) => ({ game, upload }));
|
|
45
|
+
})
|
|
46
|
+
.then(({ game, upload }) => ({
|
|
47
|
+
...published(game),
|
|
48
|
+
game: game.id,
|
|
49
|
+
// a direct deploy's release shares its upload's id, which `--wait`
|
|
50
|
+
// follows.
|
|
51
|
+
release: upload.id,
|
|
52
|
+
version: { to: game.version },
|
|
53
|
+
}));
|
|
54
|
+
}
|