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
package/dist/cli/rc.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
// [import]
|
|
6
|
+
import ini from "ini";
|
|
7
|
+
// [import]
|
|
8
|
+
import { cwd, json } from "./argv.js";
|
|
9
|
+
import { PARSE_FAILED } from "../config/code.js";
|
|
10
|
+
import { ArcError } from "../util/error.js";
|
|
11
|
+
import { aborted, unableToParse } from "../phrase/index.js";
|
|
12
|
+
import { isTable } from "../util/objs.js";
|
|
13
|
+
import { abort } from "../util/output.js";
|
|
14
|
+
// [function]
|
|
15
|
+
// the project's rc file: .<cmd>rc in the directory -C or --cwd names.
|
|
16
|
+
function config(cmd, args) {
|
|
17
|
+
return join(resolve(process.cwd(), cwd(args)), `.${cmd}rc`);
|
|
18
|
+
}
|
|
19
|
+
// [function]
|
|
20
|
+
// the nearest .<cmd>rc in the working directory or above it. Options are read
|
|
21
|
+
// before a command parses its arguments, so the files are read synchronously.
|
|
22
|
+
function nearest(cmd) {
|
|
23
|
+
let dir = process.cwd();
|
|
24
|
+
for (;;) {
|
|
25
|
+
const file = join(dir, `.${cmd}rc`);
|
|
26
|
+
if (existsSync(file)) {
|
|
27
|
+
return file;
|
|
28
|
+
}
|
|
29
|
+
if (dirname(dir) === dir) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
dir = dirname(dir);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// [function]
|
|
36
|
+
// the files `rc` reads, the lowest precedence first: system, then home, then
|
|
37
|
+
// the nearest one, then the project's.
|
|
38
|
+
function files(cmd, args) {
|
|
39
|
+
const home = homedir();
|
|
40
|
+
return [
|
|
41
|
+
...(process.platform === "win32"
|
|
42
|
+
? []
|
|
43
|
+
: [join("/etc", cmd, "config"), join("/etc", `${cmd}rc`)]),
|
|
44
|
+
join(home, ".config", cmd, "config"),
|
|
45
|
+
join(home, `.${cmd}`, "config"),
|
|
46
|
+
join(home, `.${cmd}rc`),
|
|
47
|
+
nearest(cmd),
|
|
48
|
+
config(cmd, args),
|
|
49
|
+
].filter((file) => file !== null);
|
|
50
|
+
}
|
|
51
|
+
// [function]
|
|
52
|
+
// ini parses anything, so a section header with no closing bracket, such as
|
|
53
|
+
// `[validate`, would become a key, and the options under it would be read
|
|
54
|
+
// outside their section. The first one's problem, or null.
|
|
55
|
+
function unclosedSection(str) {
|
|
56
|
+
const lines = str.split(/\r?\n/u).map((line) => line.trim());
|
|
57
|
+
const i = lines.findIndex((text) => text.startsWith("[") && !/^\[[^\]]*\]$/u.test(text));
|
|
58
|
+
return i === -1
|
|
59
|
+
? null
|
|
60
|
+
: `Line ${i + 1}: section header isn't closed: ${lines[i]}`;
|
|
61
|
+
}
|
|
62
|
+
// [function]
|
|
63
|
+
// a file's sections, INI or JSON, or nothing when it can't be read. A file
|
|
64
|
+
// that doesn't parse is `parse_failed`, naming the file.
|
|
65
|
+
function read(file) {
|
|
66
|
+
let str;
|
|
67
|
+
try {
|
|
68
|
+
str = readFileSync(file, "utf8");
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return {};
|
|
72
|
+
}
|
|
73
|
+
if (!/^\s*\{/u.test(str)) {
|
|
74
|
+
const unclosed = unclosedSection(str);
|
|
75
|
+
if (unclosed) {
|
|
76
|
+
throw new ArcError(PARSE_FAILED, unableToParse(file, unclosed));
|
|
77
|
+
}
|
|
78
|
+
return ini.parse(str);
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const data = JSON.parse(str);
|
|
82
|
+
return isTable(data) ? data : {};
|
|
83
|
+
}
|
|
84
|
+
catch (ex) {
|
|
85
|
+
throw new ArcError(PARSE_FAILED, unableToParse(file, ex instanceof Error ? ex.message : String(ex)), { cause: ex });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// [function]
|
|
89
|
+
// a command's section of .<cmd>rc, merged from the files `rc` reads. Unlike
|
|
90
|
+
// `rc`, environment variables and `--config` aren't read. Options are read
|
|
91
|
+
// before the command parses its arguments, so a file that doesn't parse
|
|
92
|
+
// aborts the command here, as `<Command> aborted.`, which never resolves.
|
|
93
|
+
export function findRc(cmd, subcmd, args) {
|
|
94
|
+
try {
|
|
95
|
+
return [...new Set(files(cmd, args))].reduce((found, file) => {
|
|
96
|
+
const section = read(file)[subcmd];
|
|
97
|
+
return { ...found, ...(isTable(section) ? section : {}) };
|
|
98
|
+
}, {});
|
|
99
|
+
}
|
|
100
|
+
catch (ex) {
|
|
101
|
+
return abort(aborted(subcmd), ex instanceof Error ? ex : new Error(String(ex)), { json: json(args) });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// yargs, in its CommonJS build. Its ES module build lays help out with a
|
|
2
|
+
// simpler text wrap of its own, which breaks a long line inside a word, and
|
|
3
|
+
// `--help` is held to the developer docs' usage blocks. `import` only
|
|
4
|
+
// reaches that build (yargs' `exports`), so this one is required.
|
|
5
|
+
// [import]
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
// [import]
|
|
8
|
+
import { isTable } from "../util/objs.js";
|
|
9
|
+
// [declare]
|
|
10
|
+
const require = createRequire(import.meta.url);
|
|
11
|
+
// [function]
|
|
12
|
+
function isFactory(value) {
|
|
13
|
+
return typeof value === "function";
|
|
14
|
+
}
|
|
15
|
+
// [function]
|
|
16
|
+
function isHelpers(value) {
|
|
17
|
+
return (isTable(value) &&
|
|
18
|
+
typeof value["hideBin"] === "function" &&
|
|
19
|
+
typeof value["Parser"] === "function");
|
|
20
|
+
}
|
|
21
|
+
// [function]
|
|
22
|
+
// a module of yargs', which is `what` when `is` says so.
|
|
23
|
+
function load(id, is) {
|
|
24
|
+
const loaded = require(id);
|
|
25
|
+
if (!is(loaded)) {
|
|
26
|
+
throw new TypeError(`${id} isn't what it was.`);
|
|
27
|
+
}
|
|
28
|
+
return loaded;
|
|
29
|
+
}
|
|
30
|
+
// [declare]
|
|
31
|
+
const helpers = load("yargs/helpers", isHelpers);
|
|
32
|
+
// [declare]
|
|
33
|
+
// the arguments after the binary's own.
|
|
34
|
+
export const hideBin = helpers.hideBin;
|
|
35
|
+
// [declare]
|
|
36
|
+
// yargs' own parser, for reading an option before a command parses.
|
|
37
|
+
export const Parser = helpers.Parser;
|
|
38
|
+
// [declare]
|
|
39
|
+
// a new parser for `args`.
|
|
40
|
+
export const yargs = load("yargs/yargs", isFactory);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
// [import]
|
|
4
|
+
import { checked } from "../action/validate/checked.js";
|
|
5
|
+
import { WARNING } from "../config/code.js";
|
|
6
|
+
import { defineCommand } from "../cli/command.js";
|
|
7
|
+
import { buildOutputMissing, buildSucceeded, nothingToDo, } from "../phrase/index.js";
|
|
8
|
+
import { hs, nlpw, result } from "../util/log.js";
|
|
9
|
+
import { CWD, JSON_OUTPUT, QUIET } from "../cli/options.js";
|
|
10
|
+
import { print, warn, warning } from "../util/output.js";
|
|
11
|
+
import { SpinnerWheel } from "../util/spinner.js";
|
|
12
|
+
import { buildTool } from "../action/build/tool.js";
|
|
13
|
+
// [use]
|
|
14
|
+
const relative = path.relative;
|
|
15
|
+
const resolve = path.resolve;
|
|
16
|
+
// [export]
|
|
17
|
+
export default defineCommand({
|
|
18
|
+
name: "build",
|
|
19
|
+
options: { json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
|
|
20
|
+
async run(argv, aborting) {
|
|
21
|
+
const json = argv.json;
|
|
22
|
+
const quiet = argv.quiet;
|
|
23
|
+
const root = resolve(process.cwd(), argv.cwd);
|
|
24
|
+
// what --json lists under `warnings`.
|
|
25
|
+
let warnings = [];
|
|
26
|
+
aborting.data = { warnings };
|
|
27
|
+
let sw = new SpinnerWheel("Validating… %s");
|
|
28
|
+
aborting.sw = sw;
|
|
29
|
+
sw.start(json || quiet);
|
|
30
|
+
// the project, parsed once for both steps.
|
|
31
|
+
const parsed = await checked(root, (found) => {
|
|
32
|
+
warnings = found;
|
|
33
|
+
aborting.data = { warnings };
|
|
34
|
+
});
|
|
35
|
+
sw.stop(true);
|
|
36
|
+
warn(warnings, { json, quiet });
|
|
37
|
+
sw = new SpinnerWheel("Building… %s");
|
|
38
|
+
aborting.sw = sw;
|
|
39
|
+
sw.start(json || quiet);
|
|
40
|
+
const artifact = await buildTool({ project: parsed, root });
|
|
41
|
+
if (json) {
|
|
42
|
+
const missing = artifact?.missing
|
|
43
|
+
? [
|
|
44
|
+
warning(WARNING.DEPLOY_DIR_NOT_BUILT, buildOutputMissing(relative(root, artifact.missing)), "workflow.deploy_dir"),
|
|
45
|
+
]
|
|
46
|
+
: [];
|
|
47
|
+
print({ artifact, warnings: [...warnings, ...missing] });
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (!quiet) {
|
|
51
|
+
sw.stop(true);
|
|
52
|
+
// the heading says what happened: built, built without deploy_dir
|
|
53
|
+
// (a caveat, so yellow), or no build to run.
|
|
54
|
+
if (artifact?.path || (artifact?.function && !artifact.missing)) {
|
|
55
|
+
hs(buildSucceeded());
|
|
56
|
+
print(artifact, { nl: true, toml: true });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (artifact?.missing) {
|
|
60
|
+
result(buildSucceeded(), [], { color: "yellow" });
|
|
61
|
+
nlpw(buildOutputMissing(relative(root, artifact.missing)));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
hs(nothingToDo());
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
summary: "Run the project's build",
|
|
68
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// arc delete: deletes the project's game on Arcadible, for its owner. It
|
|
2
|
+
// can't be undone, so it asks first (src/cli/confirm.ts), naming the game.
|
|
3
|
+
// The project's files are left as they are.
|
|
4
|
+
// [import]
|
|
5
|
+
import { resolve } from "node:path";
|
|
6
|
+
// [import]
|
|
7
|
+
import { ended } from "../account.js";
|
|
8
|
+
import { defineCommand } from "../cli/command.js";
|
|
9
|
+
import { askable, sure } from "../cli/confirm.js";
|
|
10
|
+
import { headersOf } from "../action/game.js";
|
|
11
|
+
import { confirmDeclined, gameDeleted, gameDeletedProject, gameDeleteQuestion, } from "../phrase/index.js";
|
|
12
|
+
import { p, result } from "../util/log.js";
|
|
13
|
+
import { CWD, JSON_OUTPUT, QUIET, YES } from "../cli/options.js";
|
|
14
|
+
import { print } from "../util/output.js";
|
|
15
|
+
import { SpinnerWheel } from "../util/spinner.js";
|
|
16
|
+
import { deleteTool, named } from "../action/delete/tool.js";
|
|
17
|
+
import { whoami } from "../action/whoami/tool.js";
|
|
18
|
+
// [declare]
|
|
19
|
+
const COMMAND = "delete";
|
|
20
|
+
// the command as it's typed, shown with `--yes` when there's no one to ask.
|
|
21
|
+
const USAGE = "arc delete";
|
|
22
|
+
// [export]
|
|
23
|
+
export default defineCommand({
|
|
24
|
+
name: COMMAND,
|
|
25
|
+
options: { json: JSON_OUTPUT, quiet: QUIET, cwd: CWD, yes: YES },
|
|
26
|
+
async run(argv, aborting) {
|
|
27
|
+
const json = argv.json;
|
|
28
|
+
const quiet = argv.quiet;
|
|
29
|
+
// the arguments first, then the project, then the login, as the other
|
|
30
|
+
// commands check them: with no one to ask and no --yes, it's refused
|
|
31
|
+
// before anything is read.
|
|
32
|
+
askable(argv, USAGE);
|
|
33
|
+
const game = await named({ root: resolve(process.cwd(), argv.cwd) });
|
|
34
|
+
const sw = new SpinnerWheel("Checking… %s");
|
|
35
|
+
aborting.sw = sw;
|
|
36
|
+
const current = await whoami({}, {
|
|
37
|
+
onAccountRefresh(refresh) {
|
|
38
|
+
sw.start(json || quiet);
|
|
39
|
+
return refresh();
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
sw.stop(true);
|
|
43
|
+
// no account, said before the question is asked.
|
|
44
|
+
headersOf(current);
|
|
45
|
+
const question = gameDeleteQuestion(game.title);
|
|
46
|
+
if (!(await sure(argv, { question, usage: USAGE }))) {
|
|
47
|
+
// a no at the prompt changes nothing, and isn't a failure
|
|
48
|
+
if (!quiet) {
|
|
49
|
+
p(confirmDeclined());
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const deleting = new SpinnerWheel("Deleting… %s");
|
|
54
|
+
aborting.sw = deleting;
|
|
55
|
+
deleting.start(json || quiet);
|
|
56
|
+
const gone = await deleteTool(current, game).catch(ended(current));
|
|
57
|
+
deleting.stop(true);
|
|
58
|
+
if (json) {
|
|
59
|
+
print(gone);
|
|
60
|
+
}
|
|
61
|
+
else if (!quiet) {
|
|
62
|
+
result(gameDeleted(game.title), [gameDeletedProject()]);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
summary: "Delete the game",
|
|
66
|
+
});
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { ended } from "../account.js";
|
|
4
|
+
import { checked } from "../action/validate/checked.js";
|
|
5
|
+
import { INTERNAL, NOT_LOGGED_IN, WAIT_TIMED_OUT } from "../config/code.js";
|
|
6
|
+
import { defineCommand } from "../cli/command.js";
|
|
7
|
+
import { ArcError } from "../util/error.js";
|
|
8
|
+
import { buildPublishing, buildPublishingGit, buildSubmitted, notLoggedIn, playLabel, releaseFailed, releaseFailedHeading, releasePublished, releaseTimedOut, releaseWaiting, storeLabel, tagPushed, waitTimedOut, } from "../phrase/index.js";
|
|
9
|
+
import { pw, result as logResult } from "../util/log.js";
|
|
10
|
+
import { CWD, JSON_OUTPUT, QUIET } from "../cli/options.js";
|
|
11
|
+
import { abort, print, warn, warning } from "../util/output.js";
|
|
12
|
+
import { FORMAT, ProgressBar } from "../util/progress.js";
|
|
13
|
+
import { rebuilt } from "../action/deploy/rebuilt.js";
|
|
14
|
+
import { releaseJson, resultOf } from "../action/deploy/result.js";
|
|
15
|
+
import { SpinnerWheel } from "../util/spinner.js";
|
|
16
|
+
import { checkTimeout, TIMEOUT } from "../action/deploy/timeout.js";
|
|
17
|
+
import { buildTool } from "../action/build/tool.js";
|
|
18
|
+
import { deployTool, } from "../action/deploy/tool.js";
|
|
19
|
+
import { packTool } from "../action/pack/tool.js";
|
|
20
|
+
import { predeployTool } from "../action/predeploy/tool.js";
|
|
21
|
+
import { whoami } from "../action/whoami/tool.js";
|
|
22
|
+
import { deployToolGit } from "../action/deploy/tool-git.js";
|
|
23
|
+
import { predeployToolGit, } from "../action/predeploy/tool-git.js";
|
|
24
|
+
import { wait } from "../action/deploy/wait.js";
|
|
25
|
+
// [use]
|
|
26
|
+
const resolve = path.resolve;
|
|
27
|
+
// [declare]
|
|
28
|
+
const COMMAND = "deploy";
|
|
29
|
+
const SUBMITTING = `Submitting ${FORMAT}`;
|
|
30
|
+
// [function]
|
|
31
|
+
// `warnings` collects what --json lists, such as a version that couldn't be
|
|
32
|
+
// checked.
|
|
33
|
+
function handler({ json, pb, quiet, sw, warnings, }) {
|
|
34
|
+
return {
|
|
35
|
+
onAccountRefresh(refresh) {
|
|
36
|
+
sw.start(json || quiet);
|
|
37
|
+
return refresh();
|
|
38
|
+
},
|
|
39
|
+
onDeployBegin() {
|
|
40
|
+
if (!json && !quiet && pb) {
|
|
41
|
+
pb.start(0);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
onPredeployBegin() {
|
|
45
|
+
sw.start(json || quiet);
|
|
46
|
+
},
|
|
47
|
+
onUploadProgress(step) {
|
|
48
|
+
if (!json && !quiet) {
|
|
49
|
+
if (pb) {
|
|
50
|
+
pb.increment(step);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
onWarning({ code, message }) {
|
|
55
|
+
warnings.push(warning(code, message));
|
|
56
|
+
if (!json && !quiet) {
|
|
57
|
+
sw.stop(true);
|
|
58
|
+
if (pb) {
|
|
59
|
+
pb.stop();
|
|
60
|
+
}
|
|
61
|
+
pw(message);
|
|
62
|
+
sw.start(false);
|
|
63
|
+
if (pb) {
|
|
64
|
+
pb.start(0);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// [function]
|
|
71
|
+
// the checks a deploy makes before it builds, by its method. A session the
|
|
72
|
+
// API refuses is ended (`ended`).
|
|
73
|
+
function predeploy({ current, git, handler: handlers, ...conf }) {
|
|
74
|
+
return (git
|
|
75
|
+
? predeployToolGit(conf, handlers)
|
|
76
|
+
: predeployTool(current, conf, handlers)).catch(ended(current));
|
|
77
|
+
}
|
|
78
|
+
// [function]
|
|
79
|
+
// the deploy itself, by its method: a direct deploy is the one with a
|
|
80
|
+
// package to send. A session the API refuses is ended (`ended`).
|
|
81
|
+
function deploy({ artifact, current, handler: handlers, ...conf }) {
|
|
82
|
+
return (artifact
|
|
83
|
+
? deployTool(current, artifact, conf, handlers)
|
|
84
|
+
: deployToolGit(conf, handlers)).catch(ended(current));
|
|
85
|
+
}
|
|
86
|
+
// [function]
|
|
87
|
+
// what was deployed, whether workflow.build ran, where it will be once it's
|
|
88
|
+
// published (the store only shows production), and what happens next. Once
|
|
89
|
+
// waited on, it's published, so it says so.
|
|
90
|
+
function report({ built, channel, store, tag, url, version }, { git, published }) {
|
|
91
|
+
let heading = git
|
|
92
|
+
? tagPushed(String(tag))
|
|
93
|
+
: buildSubmitted(version.to, channel, built);
|
|
94
|
+
let next = git
|
|
95
|
+
? buildPublishingGit(channel)
|
|
96
|
+
: buildPublishing();
|
|
97
|
+
if (published) {
|
|
98
|
+
heading = releasePublished(version.to, channel, built);
|
|
99
|
+
next = null;
|
|
100
|
+
}
|
|
101
|
+
logResult(heading, [
|
|
102
|
+
store ? [storeLabel(), store] : null,
|
|
103
|
+
[playLabel(), url],
|
|
104
|
+
next,
|
|
105
|
+
]);
|
|
106
|
+
}
|
|
107
|
+
// [function]
|
|
108
|
+
// waits on the release, then reports it: published, or failed or timed out,
|
|
109
|
+
// which exit 1. `result` is what the deploy prints.
|
|
110
|
+
async function waitAndReport(current, deployed, result, { git, json, quiet, root, since, timeout, }) {
|
|
111
|
+
let sw = new SpinnerWheel(releaseWaiting(git));
|
|
112
|
+
sw.start(json || quiet);
|
|
113
|
+
let building = git;
|
|
114
|
+
let waited;
|
|
115
|
+
try {
|
|
116
|
+
waited = await wait(current, deployed, { git, root, since, timeout }, {
|
|
117
|
+
onRelease() {
|
|
118
|
+
// found: GitHub Actions is done, and Arcadible publishes it now.
|
|
119
|
+
if (building) {
|
|
120
|
+
building = false;
|
|
121
|
+
sw.stop(true);
|
|
122
|
+
sw = new SpinnerWheel(releaseWaiting(false));
|
|
123
|
+
sw.start(json || quiet);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
catch (ex) {
|
|
129
|
+
sw.stop(true);
|
|
130
|
+
throw ex;
|
|
131
|
+
}
|
|
132
|
+
const { actions, studio } = waited;
|
|
133
|
+
const data = { ...result, release: releaseJson(waited.release) };
|
|
134
|
+
if (waited.timedOut) {
|
|
135
|
+
const found = Boolean(waited.release);
|
|
136
|
+
const reason = releaseTimedOut(result.version.to, timeout, {
|
|
137
|
+
actions,
|
|
138
|
+
found,
|
|
139
|
+
git,
|
|
140
|
+
studio,
|
|
141
|
+
});
|
|
142
|
+
await abort(waitTimedOut(), new ArcError(WAIT_TIMED_OUT, reason), {
|
|
143
|
+
data,
|
|
144
|
+
json,
|
|
145
|
+
sw,
|
|
146
|
+
});
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const release = waited.release;
|
|
150
|
+
if (release.status === "failed") {
|
|
151
|
+
const reason = releaseFailed(release, studio);
|
|
152
|
+
await abort(releaseFailedHeading(), new Error(reason), {
|
|
153
|
+
code: release.reason ?? INTERNAL,
|
|
154
|
+
data,
|
|
155
|
+
json,
|
|
156
|
+
sw,
|
|
157
|
+
});
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
sw.stop(true);
|
|
161
|
+
if (json) {
|
|
162
|
+
print(data);
|
|
163
|
+
}
|
|
164
|
+
else if (!quiet) {
|
|
165
|
+
report(result, { git, published: true });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// [function]
|
|
169
|
+
// a new spinner, which the error path clears from here on.
|
|
170
|
+
function spinner(aborting, text) {
|
|
171
|
+
const sw = new SpinnerWheel(text);
|
|
172
|
+
aborting.sw = sw;
|
|
173
|
+
return sw;
|
|
174
|
+
}
|
|
175
|
+
// [export]
|
|
176
|
+
export default defineCommand({
|
|
177
|
+
name: COMMAND,
|
|
178
|
+
options: {
|
|
179
|
+
json: JSON_OUTPUT,
|
|
180
|
+
quiet: QUIET,
|
|
181
|
+
wait: {
|
|
182
|
+
alias: "w",
|
|
183
|
+
default: true,
|
|
184
|
+
describe: "Wait until it's published or fails",
|
|
185
|
+
rc: true,
|
|
186
|
+
type: "boolean",
|
|
187
|
+
},
|
|
188
|
+
timeout: {
|
|
189
|
+
defaultDescription: "300, or 900 for git",
|
|
190
|
+
describe: "Seconds to wait",
|
|
191
|
+
rc: true,
|
|
192
|
+
type: "number",
|
|
193
|
+
},
|
|
194
|
+
cwd: CWD,
|
|
195
|
+
},
|
|
196
|
+
positionals: {
|
|
197
|
+
method: {
|
|
198
|
+
choices: ["direct", "git"],
|
|
199
|
+
default: "direct",
|
|
200
|
+
describe: "Deploy method",
|
|
201
|
+
rc: true,
|
|
202
|
+
type: "string",
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
async run(argv, aborting) {
|
|
206
|
+
const git = argv.method === "git";
|
|
207
|
+
const json = argv.json;
|
|
208
|
+
const quiet = argv.quiet;
|
|
209
|
+
// `.arcrc` values are strings, and a flag that isn't a number is NaN.
|
|
210
|
+
const timeout = Number(argv.timeout ?? TIMEOUT[git ? "git" : "direct"]);
|
|
211
|
+
const root = resolve(process.cwd(), argv.cwd);
|
|
212
|
+
let pb = null;
|
|
213
|
+
// what --json lists under `warnings`: arc validate's, then the deploy's.
|
|
214
|
+
const warnings = [];
|
|
215
|
+
aborting.data = { warnings };
|
|
216
|
+
let sw = spinner(aborting, "Validating… %s");
|
|
217
|
+
sw.start(json || quiet);
|
|
218
|
+
await checkTimeout(timeout);
|
|
219
|
+
// the project, parsed once and given to each step. A build can write files
|
|
220
|
+
// the manifest reads, such as art, so it's parsed again after one runs.
|
|
221
|
+
let parsed = await checked(root, (found) => {
|
|
222
|
+
warnings.push(...found);
|
|
223
|
+
});
|
|
224
|
+
sw.stop(true);
|
|
225
|
+
warn(warnings, { json, quiet });
|
|
226
|
+
sw = spinner(aborting, "Checking… %s");
|
|
227
|
+
// git deploys need no login, and never use one: anyone who can push to
|
|
228
|
+
// the repository can release, and the Arcadible GitHub App publishes
|
|
229
|
+
// the release. Every call is public, so it's the same for whoever runs
|
|
230
|
+
// it, and the saved session isn't read, or refreshed.
|
|
231
|
+
const current = git
|
|
232
|
+
? null
|
|
233
|
+
: await whoami({}, handler({ json, pb, quiet, sw, warnings }));
|
|
234
|
+
if (!current && !git) {
|
|
235
|
+
throw new ArcError(NOT_LOGGED_IN, notLoggedIn());
|
|
236
|
+
}
|
|
237
|
+
sw.stop(true);
|
|
238
|
+
sw = spinner(aborting, "Preparing… %s");
|
|
239
|
+
const predeployed = await predeploy({
|
|
240
|
+
current,
|
|
241
|
+
git,
|
|
242
|
+
handler: handler({ json, pb, quiet, sw, warnings }),
|
|
243
|
+
project: parsed,
|
|
244
|
+
root,
|
|
245
|
+
});
|
|
246
|
+
sw.stop(true);
|
|
247
|
+
// whether the handle rules held the handle back from this release, so the
|
|
248
|
+
// game's links are by id.
|
|
249
|
+
const held = predeployed.held ?? false;
|
|
250
|
+
sw = spinner(aborting, "Building… %s");
|
|
251
|
+
sw.start(git || json || quiet);
|
|
252
|
+
const output = git ? null : await buildTool({ project: parsed, root });
|
|
253
|
+
if (output) {
|
|
254
|
+
parsed = await rebuilt(root);
|
|
255
|
+
}
|
|
256
|
+
sw.stop(true);
|
|
257
|
+
sw = spinner(aborting, "Packing… %s");
|
|
258
|
+
sw.start(git || json || quiet);
|
|
259
|
+
const artifact = git
|
|
260
|
+
? null
|
|
261
|
+
: await packTool({
|
|
262
|
+
input: output?.path,
|
|
263
|
+
onWarning: handler({ json, pb, quiet, sw, warnings }).onWarning,
|
|
264
|
+
project: parsed,
|
|
265
|
+
root,
|
|
266
|
+
});
|
|
267
|
+
// build: whether workflow.build ran
|
|
268
|
+
const built = Boolean(output);
|
|
269
|
+
sw.stop(true);
|
|
270
|
+
if (!json && !quiet && artifact) {
|
|
271
|
+
pb = new ProgressBar(artifact.size, SUBMITTING);
|
|
272
|
+
aborting.pb = pb;
|
|
273
|
+
}
|
|
274
|
+
const deploying = deploy({
|
|
275
|
+
artifact,
|
|
276
|
+
current,
|
|
277
|
+
handler: handler({ json, pb, quiet, sw, warnings }),
|
|
278
|
+
project: parsed,
|
|
279
|
+
root,
|
|
280
|
+
});
|
|
281
|
+
// when the release started, to find a git one by
|
|
282
|
+
const since = Date.now();
|
|
283
|
+
const deployed = await deploying;
|
|
284
|
+
if (pb) {
|
|
285
|
+
pb.stop();
|
|
286
|
+
}
|
|
287
|
+
const result = resultOf(deployed, { built, git, held, warnings });
|
|
288
|
+
sw.stop(true);
|
|
289
|
+
if (argv.wait) {
|
|
290
|
+
await waitAndReport(current, deployed, result, {
|
|
291
|
+
git,
|
|
292
|
+
json,
|
|
293
|
+
quiet,
|
|
294
|
+
root,
|
|
295
|
+
since,
|
|
296
|
+
timeout,
|
|
297
|
+
});
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (json) {
|
|
301
|
+
print(result);
|
|
302
|
+
}
|
|
303
|
+
else if (!quiet) {
|
|
304
|
+
report(result, { git });
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
summary: "Deploy the game",
|
|
308
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// arc function: a game's function, the server code Arcadible runs for it:
|
|
2
|
+
// paused and resumed on a channel by the game's owner, with no release, and
|
|
3
|
+
// its secrets (./secret/index.ts). All of it is left out of `arc --help`
|
|
4
|
+
// until functions ship, with the docs.
|
|
5
|
+
// [import]
|
|
6
|
+
import { defineCommand } from "../../cli/command.js";
|
|
7
|
+
import secret from "./secret/index.js";
|
|
8
|
+
import pause from "./pause.js";
|
|
9
|
+
import resume from "./resume.js";
|
|
10
|
+
import status from "./status.js";
|
|
11
|
+
// [export]
|
|
12
|
+
export default defineCommand({
|
|
13
|
+
commands: [pause, resume, status, secret],
|
|
14
|
+
hidden: true,
|
|
15
|
+
name: "function",
|
|
16
|
+
summary: "Pause, resume, and show the game's function, and its secrets",
|
|
17
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { defineCommand } from "../../cli/command.js";
|
|
3
|
+
import { functionPaused } from "../../phrase/index.js";
|
|
4
|
+
import { p } from "../../util/log.js";
|
|
5
|
+
import { CHANNEL, CWD, JSON_OUTPUT, QUIET } from "../../cli/options.js";
|
|
6
|
+
import { run } from "./run.js";
|
|
7
|
+
import { pause } from "../../action/function/tool.js";
|
|
8
|
+
// [export]
|
|
9
|
+
export default defineCommand({
|
|
10
|
+
name: "pause",
|
|
11
|
+
options: { ...CHANNEL, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
|
|
12
|
+
run(argv, aborting) {
|
|
13
|
+
return run(argv, aborting, pause, (paused) => {
|
|
14
|
+
p(functionPaused(paused));
|
|
15
|
+
}, "arc function pause");
|
|
16
|
+
},
|
|
17
|
+
summary: "Pause the game's function on a channel",
|
|
18
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// [import]
|
|
2
|
+
import { defineCommand } from "../../cli/command.js";
|
|
3
|
+
import { functionResumed } from "../../phrase/index.js";
|
|
4
|
+
import { p } from "../../util/log.js";
|
|
5
|
+
import { CHANNEL, CWD, JSON_OUTPUT, QUIET } from "../../cli/options.js";
|
|
6
|
+
import { run } from "./run.js";
|
|
7
|
+
import { resume } from "../../action/function/tool.js";
|
|
8
|
+
// [export]
|
|
9
|
+
export default defineCommand({
|
|
10
|
+
name: "resume",
|
|
11
|
+
options: { ...CHANNEL, json: JSON_OUTPUT, quiet: QUIET, cwd: CWD },
|
|
12
|
+
run(argv, aborting) {
|
|
13
|
+
return run(argv, aborting, resume, (resumed) => {
|
|
14
|
+
p(functionResumed(resumed));
|
|
15
|
+
}, "arc function resume");
|
|
16
|
+
},
|
|
17
|
+
summary: "Resume the game's function on a channel",
|
|
18
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// what `arc function`'s own commands share: running one as the logged-in
|
|
2
|
+
// account.
|
|
3
|
+
// [import]
|
|
4
|
+
import { resolve as resolvePath } from "node:path";
|
|
5
|
+
// [import]
|
|
6
|
+
import { ended } from "../../account.js";
|
|
7
|
+
import { of } from "../../cli/channel.js";
|
|
8
|
+
import { print } from "../../util/output.js";
|
|
9
|
+
import { SpinnerWheel } from "../../util/spinner.js";
|
|
10
|
+
import { whoami } from "../../action/whoami/tool.js";
|
|
11
|
+
// [function]
|
|
12
|
+
// runs one command as the logged-in account, and prints what `shown` makes
|
|
13
|
+
// of its result. `usage` is the command as it's typed, for one that changes
|
|
14
|
+
// something, which then needs a channel. A session that was refused is
|
|
15
|
+
// refreshed, so the failure says to log in again.
|
|
16
|
+
export async function run(argv, aborting, command, shown, usage = null) {
|
|
17
|
+
const json = argv.json;
|
|
18
|
+
const quiet = argv.quiet;
|
|
19
|
+
const sw = new SpinnerWheel("Checking… %s");
|
|
20
|
+
aborting.sw = sw;
|
|
21
|
+
const handler = {
|
|
22
|
+
onAccountRefresh(refresh) {
|
|
23
|
+
sw.start(json || quiet);
|
|
24
|
+
return refresh();
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
// the channel first, so a command given none says so before anything else
|
|
28
|
+
const where = of(argv, usage);
|
|
29
|
+
const current = await whoami({}, handler);
|
|
30
|
+
sw.stop(true);
|
|
31
|
+
const result = await command(current, {
|
|
32
|
+
channel: where,
|
|
33
|
+
root: resolvePath(process.cwd(), argv.cwd),
|
|
34
|
+
}).catch(ended(current));
|
|
35
|
+
if (json) {
|
|
36
|
+
print(result);
|
|
37
|
+
}
|
|
38
|
+
else if (!quiet) {
|
|
39
|
+
shown(result);
|
|
40
|
+
}
|
|
41
|
+
}
|