arcadible 0.1.28 → 0.1.31
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 +66 -2
- package/bin/arc-build.js +18 -25
- package/bin/arc-default.js +3 -2
- package/bin/arc-deploy.js +198 -58
- package/bin/arc-init.js +32 -51
- package/bin/arc-inspect.js +7 -37
- package/bin/arc-login.js +6 -7
- package/bin/arc-logout.js +7 -8
- package/bin/arc-open.js +21 -21
- package/bin/arc-pack.js +11 -27
- package/bin/arc-play.js +28 -20
- package/bin/arc-validate.js +8 -20
- package/bin/arc-whoami.js +16 -10
- package/bin/arc.js +2 -2
- package/package.json +20 -6
- package/src/account.js +60 -7
- package/src/action/build/tool.js +12 -3
- package/src/action/deploy/tool-git.js +61 -11
- package/src/action/deploy/tool.js +47 -29
- package/src/action/deploy/wait.js +145 -0
- package/src/action/init/tool-patch.js +5 -28
- package/src/action/init/tool.js +8 -21
- package/src/action/inspect/tool.js +3 -38
- package/src/action/login/flow.js +1 -1
- package/src/action/open/tool.js +15 -3
- package/src/action/pack/limits.js +43 -0
- package/src/action/pack/tool.js +3 -7
- package/src/action/play/tool.js +74 -13
- package/src/action/predeploy/ac.js +14 -43
- package/src/action/predeploy/git.js +40 -61
- package/src/action/predeploy/published.js +69 -0
- package/src/action/predeploy/tool-git.js +58 -15
- package/src/action/predeploy/tool.js +5 -11
- package/src/action/validate/tool.js +28 -7
- package/src/api.js +56 -19
- package/src/cli/inspect.js +2 -2
- package/src/config/html.js +2 -1
- package/src/config/image.js +0 -1
- package/src/config/uri.js +1 -0
- package/src/parser/env.js +8 -3
- package/src/parser/manifest.js +16 -3
- package/src/parser/media.js +16 -11
- package/src/parser/project.js +38 -16
- package/src/parser/readme-file.js +69 -0
- package/src/parser/readme.js +37 -109
- package/src/parser/sections.js +107 -0
- package/src/phrase.js +382 -53
- package/src/schema/check/workflow.js +42 -5
- package/src/schema/game.js +164 -99
- package/src/schema/message.js +46 -0
- package/src/schema/readme.js +38 -0
- package/src/schema/workflow.js +27 -26
- package/src/util/argv.js +49 -0
- package/src/util/chars.js +30 -0
- package/src/util/delay.js +1 -1
- package/src/util/doc.js +50 -29
- package/src/util/http.js +5 -3
- package/src/util/image.js +46 -23
- package/src/util/links.js +63 -0
- package/src/util/log.js +36 -51
- package/src/util/md.js +39 -2
- package/src/util/output.js +34 -9
- package/src/util/paths.js +3 -1
- package/src/util/progress.js +19 -5
- package/src/util/rc.js +67 -11
- package/src/util/request.js +36 -32
- package/src/util/schema.js +12 -4
- package/src/util/shell.js +39 -7
- package/src/util/spinner.js +14 -3
- package/src/util/term.js +28 -0
- package/src/util/uris.js +8 -1
- package/src/util/video.js +49 -17
- package/src/util/zip.js +15 -0
- package/.eslintrc +0 -6
- package/src/action/inspect/media.js +0 -34
- package/src/config/game.js +0 -5
- package/src/util/dom.js +0 -46
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// [import]
|
|
4
|
+
|
|
5
|
+
const api = require("../../api");
|
|
6
|
+
const cfguri = require("../../config/uri");
|
|
7
|
+
const delay = require("../../util/delay");
|
|
8
|
+
const repo = require("../predeploy/git");
|
|
9
|
+
const time = require("../../util/time");
|
|
10
|
+
|
|
11
|
+
// [use]
|
|
12
|
+
|
|
13
|
+
const git = repo.git;
|
|
14
|
+
const sleep = delay.sleep;
|
|
15
|
+
|
|
16
|
+
// [declare]
|
|
17
|
+
|
|
18
|
+
// how often a release is checked.
|
|
19
|
+
const INTERVAL = time.s(2);
|
|
20
|
+
const FINAL = new Set(["failed", "published"]);
|
|
21
|
+
const SELECT =
|
|
22
|
+
"id,status,reason,message,build,source,version,channel,created_at";
|
|
23
|
+
// a git release is found by version among the newest few; one from before
|
|
24
|
+
// this deploy (a tag deleted and pushed again) is left out, allowing for
|
|
25
|
+
// the machine's clock being off.
|
|
26
|
+
const SKEW = time.m(10);
|
|
27
|
+
|
|
28
|
+
// [function]
|
|
29
|
+
|
|
30
|
+
// a failure worth retrying: the network, or the API having a moment.
|
|
31
|
+
const transient = function (err) {
|
|
32
|
+
return !err.status || err.status >= 500;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// [function]
|
|
36
|
+
|
|
37
|
+
// where a developer sees the release in Studio.
|
|
38
|
+
const studioUrl = function (game) {
|
|
39
|
+
return `${cfguri.HOST_HTTP_STUDIO}/games/${game}/builds`;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// [function]
|
|
43
|
+
|
|
44
|
+
// the repository's GitHub Actions page, from origin's URL, or null when
|
|
45
|
+
// origin isn't on GitHub.
|
|
46
|
+
const actionsUrl = function (root) {
|
|
47
|
+
return new Promise((resolve) => {
|
|
48
|
+
git(root, ["remote", "get-url", "origin"], (err, stdout) => {
|
|
49
|
+
const match = err
|
|
50
|
+
? null
|
|
51
|
+
: /github\.com[:/]([^/\s]+)\/([^/\s]+?)(?:\.git)?\s*$/u.exec(stdout);
|
|
52
|
+
resolve(
|
|
53
|
+
match ? `https://github.com/${match[1]}/${match[2]}/actions` : null,
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// [function]
|
|
60
|
+
|
|
61
|
+
// a direct deploy's release, by its upload's id.
|
|
62
|
+
const findDirect = function (id, headers) {
|
|
63
|
+
return () => api.release(id, { select: SELECT }, headers);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// [function]
|
|
67
|
+
|
|
68
|
+
// a git deploy's release: GitHub's, for this version, made since the tag was
|
|
69
|
+
// pushed. Null until GitHub Actions has built it.
|
|
70
|
+
const findGit = function (game, version, since, headers) {
|
|
71
|
+
return () =>
|
|
72
|
+
api
|
|
73
|
+
.gameReleases(game, { limit: 10, select: SELECT, version }, headers)
|
|
74
|
+
.then(
|
|
75
|
+
(rows) =>
|
|
76
|
+
(rows ?? []).find(
|
|
77
|
+
(r) =>
|
|
78
|
+
r.source === "github" && Date.parse(r.created_at) >= since - SKEW,
|
|
79
|
+
) ?? null,
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// [function]
|
|
84
|
+
|
|
85
|
+
// checks the release until it's published or failed, or `timeout` seconds
|
|
86
|
+
// pass. Resolves { release, timedOut }; `release` is null when it was never
|
|
87
|
+
// found. `onRelease` hears each release it finds.
|
|
88
|
+
const poll = function (find, timeout, onRelease) {
|
|
89
|
+
const deadline = Date.now() + timeout * 1000;
|
|
90
|
+
// one check, then the next, each after the last: `last` is the newest
|
|
91
|
+
// release found, kept through a check that fails for a moment.
|
|
92
|
+
const tick = async function (last) {
|
|
93
|
+
let release = last;
|
|
94
|
+
try {
|
|
95
|
+
release = (await find()) ?? last;
|
|
96
|
+
} catch (err) {
|
|
97
|
+
if (!transient(err)) {
|
|
98
|
+
throw err;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (release && onRelease) {
|
|
102
|
+
onRelease(release);
|
|
103
|
+
}
|
|
104
|
+
if (release && FINAL.has(release.status)) {
|
|
105
|
+
return { release, timedOut: false };
|
|
106
|
+
}
|
|
107
|
+
const left = deadline - Date.now();
|
|
108
|
+
if (left <= 0) {
|
|
109
|
+
return { release, timedOut: true };
|
|
110
|
+
}
|
|
111
|
+
await sleep(Math.min(INTERVAL, left));
|
|
112
|
+
return tick(release);
|
|
113
|
+
};
|
|
114
|
+
return tick(null);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// [function]
|
|
118
|
+
|
|
119
|
+
// waits on a deploy's release. `deployed` is what the deploy resolved: a
|
|
120
|
+
// direct deploy's has the release's id, and a git deploy's its game.
|
|
121
|
+
const main = function (
|
|
122
|
+
current,
|
|
123
|
+
deployed,
|
|
124
|
+
{ git: isGit, root, since, timeout },
|
|
125
|
+
{ onRelease } = {},
|
|
126
|
+
) {
|
|
127
|
+
const headers = api.auth(current?.session?.access_token);
|
|
128
|
+
const game = deployed.game;
|
|
129
|
+
const find = isGit
|
|
130
|
+
? findGit(game, deployed.version.to, since, headers)
|
|
131
|
+
: findDirect(deployed.release, headers);
|
|
132
|
+
return Promise.all([
|
|
133
|
+
poll(find, timeout, onRelease),
|
|
134
|
+
isGit ? actionsUrl(root) : null,
|
|
135
|
+
]).then(([{ release, timedOut }, actions]) => ({
|
|
136
|
+
actions,
|
|
137
|
+
release,
|
|
138
|
+
studio: studioUrl(game),
|
|
139
|
+
timedOut,
|
|
140
|
+
}));
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// [export]
|
|
144
|
+
|
|
145
|
+
module.exports = main;
|
|
@@ -6,17 +6,11 @@ const path = require("node:path");
|
|
|
6
6
|
|
|
7
7
|
// [import]
|
|
8
8
|
|
|
9
|
-
const fs = require("fs-extra");
|
|
10
|
-
|
|
11
|
-
// [import]
|
|
12
|
-
|
|
13
9
|
const env = require("../../parser/env");
|
|
14
10
|
const manifest = require("./manifest");
|
|
15
|
-
const phrase = require("../../phrase");
|
|
16
11
|
|
|
17
12
|
// [use]
|
|
18
13
|
|
|
19
|
-
const pathExists = fs.pathExists;
|
|
20
14
|
const prepare = manifest.prepare;
|
|
21
15
|
const resolve = path.resolve;
|
|
22
16
|
|
|
@@ -28,30 +22,13 @@ const detectVersion = function (dest) {
|
|
|
28
22
|
|
|
29
23
|
// [function]
|
|
30
24
|
|
|
31
|
-
|
|
25
|
+
// an existing project: add a manifest, and copy nothing from the template.
|
|
26
|
+
const main = function ({ project, root }, { onInitBegin }) {
|
|
27
|
+
const dest = resolve(root, project);
|
|
32
28
|
if (onInitBegin) {
|
|
33
|
-
onInitBegin({ dest
|
|
29
|
+
onInitBegin({ dest });
|
|
34
30
|
}
|
|
35
|
-
return
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// [function]
|
|
39
|
-
|
|
40
|
-
const init = function (dest, { force, template }, handler) {
|
|
41
|
-
return pathExists(dest).then((exists) => {
|
|
42
|
-
if (exists && !force) {
|
|
43
|
-
throw new Error(phrase.overwriteWithForce());
|
|
44
|
-
}
|
|
45
|
-
return scaffold(template, dest, handler);
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// [function]
|
|
50
|
-
|
|
51
|
-
const main = function ({ force, project, root, template }, handler) {
|
|
52
|
-
const dest = resolve(root, project);
|
|
53
|
-
return init(dest, { force, template }, handler)
|
|
54
|
-
.then(() => detectVersion(dest))
|
|
31
|
+
return detectVersion(dest)
|
|
55
32
|
.then((version) => prepare(dest, version))
|
|
56
33
|
.then(() => ({ path: dest }));
|
|
57
34
|
};
|
package/src/action/init/tool.js
CHANGED
|
@@ -18,7 +18,6 @@ const phrase = require("../../phrase");
|
|
|
18
18
|
// [use]
|
|
19
19
|
|
|
20
20
|
const join = path.join;
|
|
21
|
-
const pathExists = fs.pathExists;
|
|
22
21
|
const prepare = manifest.prepare;
|
|
23
22
|
const remove = fs.remove;
|
|
24
23
|
const resolve = path.resolve;
|
|
@@ -41,35 +40,23 @@ const detectVersion = function (dest) {
|
|
|
41
40
|
|
|
42
41
|
// [function]
|
|
43
42
|
|
|
44
|
-
const scaffold = function (src, dest, { onInitBegin
|
|
43
|
+
const scaffold = function (src, dest, { onInitBegin }) {
|
|
45
44
|
if (onInitBegin) {
|
|
46
45
|
onInitBegin({ dest, src });
|
|
47
46
|
}
|
|
48
47
|
return degit(src, { cache: false, force: true, verbose: false })
|
|
49
|
-
.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
})
|
|
54
|
-
.clone(dest);
|
|
48
|
+
.clone(dest)
|
|
49
|
+
.catch((ex) => {
|
|
50
|
+
throw new Error(phrase.templateUnavailable(src), { cause: ex });
|
|
51
|
+
});
|
|
55
52
|
};
|
|
56
53
|
|
|
57
54
|
// [function]
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (exists && !force) {
|
|
62
|
-
throw new Error(phrase.overwriteWithForce());
|
|
63
|
-
}
|
|
64
|
-
return scaffold(template, dest, handler);
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// [function]
|
|
69
|
-
|
|
70
|
-
const main = function ({ force, project, root, template }, handler) {
|
|
56
|
+
// a new project: `arc init` runs tool-patch.js when the directory exists.
|
|
57
|
+
const main = function ({ project, root, template }, handler) {
|
|
71
58
|
const dest = resolve(root, project);
|
|
72
|
-
return
|
|
59
|
+
return scaffold(template, dest, handler)
|
|
73
60
|
.then(() => removeLicense(dest))
|
|
74
61
|
.then(() => detectVersion(dest))
|
|
75
62
|
.then((version) => prepare(dest, version))
|
|
@@ -6,9 +6,6 @@ const dotProp = require("dot-prop");
|
|
|
6
6
|
|
|
7
7
|
// [import]
|
|
8
8
|
|
|
9
|
-
const api = require("../../api");
|
|
10
|
-
const media = require("./media");
|
|
11
|
-
const phrase = require("../../phrase");
|
|
12
9
|
const project = require("../../parser/project");
|
|
13
10
|
|
|
14
11
|
// [function]
|
|
@@ -19,41 +16,9 @@ const select = function (proj, key) {
|
|
|
19
16
|
|
|
20
17
|
// [function]
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
channel: "production",
|
|
26
|
-
select: "manifest",
|
|
27
|
-
})
|
|
28
|
-
.then((builds) => {
|
|
29
|
-
if (!builds.length) {
|
|
30
|
-
throw new Error(phrase.noProductionBuild(id));
|
|
31
|
-
}
|
|
32
|
-
const manifest = builds[0]?.manifest ?? {};
|
|
33
|
-
if (manifest.game) {
|
|
34
|
-
media.dehydrate(manifest.game);
|
|
35
|
-
}
|
|
36
|
-
return manifest;
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// [function]
|
|
41
|
-
|
|
42
|
-
const main = function ({ game: id, root, selector }, { onInspectFetch }) {
|
|
43
|
-
const local = !id;
|
|
44
|
-
if (onInspectFetch && !local) {
|
|
45
|
-
onInspectFetch({ game: id });
|
|
46
|
-
}
|
|
47
|
-
if (local) {
|
|
48
|
-
return project(root).then((data) => select(data, selector));
|
|
49
|
-
}
|
|
50
|
-
if (id === "self") {
|
|
51
|
-
return project(root)
|
|
52
|
-
.then(({ game }) => game?.handle ?? game?.id)
|
|
53
|
-
.then(inspect)
|
|
54
|
-
.then((data) => select(data, selector));
|
|
55
|
-
}
|
|
56
|
-
return inspect(id).then((data) => select(data, selector));
|
|
19
|
+
// the project's resolved manifest, or the value at `selector` in it.
|
|
20
|
+
const main = function ({ root, selector }) {
|
|
21
|
+
return project(root).then((data) => select(data, selector));
|
|
57
22
|
};
|
|
58
23
|
|
|
59
24
|
// [export]
|
package/src/action/login/flow.js
CHANGED
package/src/action/open/tool.js
CHANGED
|
@@ -6,17 +6,29 @@ const project = require("../../parser/project");
|
|
|
6
6
|
|
|
7
7
|
// [function]
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const openUrl = function (id) {
|
|
10
10
|
return id ? { page: `/play/${id}` } : null;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
// [function]
|
|
14
14
|
|
|
15
|
+
const open = function (id) {
|
|
16
|
+
return Promise.resolve(openUrl(id));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// [function]
|
|
20
|
+
|
|
21
|
+
const openSelf = function (root) {
|
|
22
|
+
return project(root).then(({ game }) => openUrl(game?.handle ?? game?.id));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// [function]
|
|
26
|
+
|
|
15
27
|
const main = function ({ game: id, root }) {
|
|
16
28
|
if (id === "self") {
|
|
17
|
-
return
|
|
29
|
+
return openSelf(root);
|
|
18
30
|
}
|
|
19
|
-
return
|
|
31
|
+
return open(id);
|
|
20
32
|
};
|
|
21
33
|
|
|
22
34
|
// [export]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// [import]
|
|
4
|
+
|
|
5
|
+
const phrase = require("../../phrase");
|
|
6
|
+
const size = require("../../util/size");
|
|
7
|
+
|
|
8
|
+
// [use]
|
|
9
|
+
|
|
10
|
+
const toMb = size.toMb;
|
|
11
|
+
|
|
12
|
+
// [declare]
|
|
13
|
+
|
|
14
|
+
// the limits on a packed game, uncompressed, as Arcadible enforces them when
|
|
15
|
+
// it publishes a release. They're checked here so a build that would fail
|
|
16
|
+
// there fails before it's uploaded.
|
|
17
|
+
const MAX_FILES = 10000;
|
|
18
|
+
const MAX_FILE_SIZE = size.mb(64);
|
|
19
|
+
const MAX_TOTAL_SIZE = size.mb(256);
|
|
20
|
+
|
|
21
|
+
// [function]
|
|
22
|
+
|
|
23
|
+
// checks a zip's files against the limits, and throws for the first one it
|
|
24
|
+
// breaks: a file over 64 MB, more than 10,000 files, or over 256 MB in all.
|
|
25
|
+
const check = function (entries) {
|
|
26
|
+
const large = entries.find((entry) => entry.size > MAX_FILE_SIZE);
|
|
27
|
+
if (large) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
phrase.packageFileTooLarge(large.name, toMb(MAX_FILE_SIZE)),
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
if (entries.length > MAX_FILES) {
|
|
33
|
+
throw new Error(phrase.packageTooManyFiles(MAX_FILES));
|
|
34
|
+
}
|
|
35
|
+
const total = entries.reduce((sum, entry) => sum + entry.size, 0);
|
|
36
|
+
if (total > MAX_TOTAL_SIZE) {
|
|
37
|
+
throw new Error(phrase.packageUncompressedTooLarge(toMb(MAX_TOTAL_SIZE)));
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// [export]
|
|
42
|
+
|
|
43
|
+
module.exports = { MAX_FILES, MAX_FILE_SIZE, MAX_TOTAL_SIZE, check };
|
package/src/action/pack/tool.js
CHANGED
|
@@ -11,6 +11,7 @@ const fs = require("fs-extra");
|
|
|
11
11
|
// [import]
|
|
12
12
|
|
|
13
13
|
const cfgproduct = require("../../config/product");
|
|
14
|
+
const limits = require("./limits");
|
|
14
15
|
const phrase = require("../../phrase");
|
|
15
16
|
const project = require("../../parser/project");
|
|
16
17
|
const size = require("../../util/size");
|
|
@@ -37,7 +38,6 @@ const OUTPUT = `.${TOOL}/package`;
|
|
|
37
38
|
// [declare]
|
|
38
39
|
|
|
39
40
|
const SIZE_PARTIAL = size.mb(64);
|
|
40
|
-
const SIZE_TOTAL = size.mb(256);
|
|
41
41
|
|
|
42
42
|
// [function]
|
|
43
43
|
|
|
@@ -46,8 +46,7 @@ const verifyPartial = function (zip) {
|
|
|
46
46
|
throw new Error(phrase.packageFileMissing(MAIN));
|
|
47
47
|
}
|
|
48
48
|
if (zip.stat().size > SIZE_PARTIAL) {
|
|
49
|
-
|
|
50
|
-
throw new Error(phrase.packageTooLarge(max, false));
|
|
49
|
+
throw new Error(phrase.packageTooLarge(size.toMb(SIZE_PARTIAL)));
|
|
51
50
|
}
|
|
52
51
|
return zip;
|
|
53
52
|
};
|
|
@@ -55,10 +54,7 @@ const verifyPartial = function (zip) {
|
|
|
55
54
|
// [function]
|
|
56
55
|
|
|
57
56
|
const verifyTotal = function (zip) {
|
|
58
|
-
|
|
59
|
-
const max = SIZE_TOTAL / 1024 / 1024;
|
|
60
|
-
throw new Error(phrase.packageTooLarge(max, true));
|
|
61
|
-
}
|
|
57
|
+
limits.check(zip.entries());
|
|
62
58
|
return zip;
|
|
63
59
|
};
|
|
64
60
|
|
package/src/action/play/tool.js
CHANGED
|
@@ -3,24 +3,87 @@
|
|
|
3
3
|
// [import]
|
|
4
4
|
|
|
5
5
|
const api = require("../../api");
|
|
6
|
-
const
|
|
6
|
+
const links = require("../../util/links");
|
|
7
|
+
const phrase = require("../../phrase");
|
|
7
8
|
const project = require("../../parser/project");
|
|
8
9
|
|
|
9
10
|
// [function]
|
|
10
11
|
|
|
12
|
+
// the game, `select`ed, or null when the API can't be reached. It rejects
|
|
13
|
+
// when the game isn't on Arcadible: its builds can't say, since a game that
|
|
14
|
+
// doesn't exist has none.
|
|
15
|
+
const lookup = function (id, select) {
|
|
16
|
+
return api.discoverGame(id, { select }).catch((err) => {
|
|
17
|
+
if (err?.status === 404) {
|
|
18
|
+
throw new Error(phrase.gameNotFound(id));
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// [function]
|
|
25
|
+
|
|
26
|
+
const fallbackIf = function (fallback) {
|
|
27
|
+
return { fallback, release: fallback ? links.STAGING : links.PRODUCTION };
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// [function]
|
|
31
|
+
|
|
32
|
+
// the release to play. A chosen one is used as is. Without one, it's
|
|
33
|
+
// production, or staging when the game has no production release yet. When
|
|
34
|
+
// the API can't be reached, it's production.
|
|
35
|
+
const resolveRelease = function (id, release) {
|
|
36
|
+
if (release) {
|
|
37
|
+
return Promise.resolve({ fallback: false, release });
|
|
38
|
+
}
|
|
39
|
+
return api
|
|
40
|
+
.discoverGameBuilds(id, { channel: links.PRODUCTION, select: "version" })
|
|
41
|
+
.then(
|
|
42
|
+
(builds) => fallbackIf(!builds?.length),
|
|
43
|
+
() => fallbackIf(false),
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// [function]
|
|
48
|
+
|
|
49
|
+
const target = function (id, orientation, release) {
|
|
50
|
+
return resolveRelease(id, release).then(({ fallback, release: chosen }) => ({
|
|
51
|
+
fallback,
|
|
52
|
+
orientation: orientation ?? "natural",
|
|
53
|
+
url: links.playUrl(id, chosen),
|
|
54
|
+
}));
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// [function]
|
|
58
|
+
|
|
59
|
+
// another game: its orientation comes from the API, or natural when the API
|
|
60
|
+
// can't be reached.
|
|
11
61
|
const play = function (id, release) {
|
|
12
62
|
if (!id) {
|
|
13
63
|
return Promise.resolve(null);
|
|
14
64
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
65
|
+
return lookup(id, "orientation").then((game) =>
|
|
66
|
+
target(id, game?.orientation, release),
|
|
67
|
+
);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// [function]
|
|
71
|
+
|
|
72
|
+
// this project's game: its orientation comes from the manifest. With a
|
|
73
|
+
// chosen release, it makes no API call.
|
|
74
|
+
const playSelf = function (root, release) {
|
|
75
|
+
return project(root)
|
|
76
|
+
.then(({ game }) => {
|
|
77
|
+
const id = game?.handle ?? game?.id;
|
|
78
|
+
if (!id) {
|
|
79
|
+
return [null, null];
|
|
80
|
+
}
|
|
81
|
+
return Promise.all([
|
|
82
|
+
release ? null : lookup(id, "id"),
|
|
83
|
+
target(id, game.orientation, release),
|
|
84
|
+
]);
|
|
85
|
+
})
|
|
86
|
+
.then(([, found]) => found);
|
|
24
87
|
};
|
|
25
88
|
|
|
26
89
|
// [function]
|
|
@@ -30,9 +93,7 @@ const main = function ({ game: id, release, root }, { onPlayFetch }) {
|
|
|
30
93
|
onPlayFetch({ game: id });
|
|
31
94
|
}
|
|
32
95
|
if (id === "self") {
|
|
33
|
-
return
|
|
34
|
-
play(game?.handle ?? game?.id, release),
|
|
35
|
-
);
|
|
96
|
+
return playSelf(root, release);
|
|
36
97
|
}
|
|
37
98
|
return play(id, release);
|
|
38
99
|
};
|
|
@@ -4,36 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
const api = require("../../api");
|
|
6
6
|
const phrase = require("../../phrase");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
// [function]
|
|
10
|
-
|
|
11
|
-
const uploadBuild = function (
|
|
12
|
-
current,
|
|
13
|
-
artifact,
|
|
14
|
-
{ id, version },
|
|
15
|
-
onUploadProgress,
|
|
16
|
-
cb,
|
|
17
|
-
) {
|
|
18
|
-
const form = new FormData();
|
|
19
|
-
form.append("artifact", id);
|
|
20
|
-
form.append("version", version);
|
|
21
|
-
form.append("sha256", artifact.sha256);
|
|
22
|
-
form.append("size", artifact.size);
|
|
23
|
-
// api
|
|
24
|
-
return api
|
|
25
|
-
.postUpload(form, { token: current?.session?.access_token })
|
|
26
|
-
.then((upload) => {
|
|
27
|
-
s3.upload(upload.upload_url, artifact, onUploadProgress, cb);
|
|
28
|
-
}, cb);
|
|
29
|
-
};
|
|
7
|
+
const published = require("./published");
|
|
30
8
|
|
|
31
9
|
// [function]
|
|
32
10
|
|
|
33
11
|
const ensureGame = function (current, idOrHandle, id, cb) {
|
|
34
12
|
return api.discoverGame(idOrHandle).then(
|
|
35
13
|
(game) => {
|
|
36
|
-
|
|
14
|
+
// a token's account isn't known yet, so only the id is compared; the
|
|
15
|
+
// server checks ownership when it authorizes the upload.
|
|
16
|
+
const owned = current?.token || game.account === current?.user?.id;
|
|
17
|
+
if (owned && game.id === id) {
|
|
37
18
|
cb(null);
|
|
38
19
|
return;
|
|
39
20
|
}
|
|
@@ -53,7 +34,7 @@ const ensureGame = function (current, idOrHandle, id, cb) {
|
|
|
53
34
|
|
|
54
35
|
const ensureId = function (current, { handle, id }, cb) {
|
|
55
36
|
return ensureGame(current, id, id, (err) => {
|
|
56
|
-
if (err || handle === null) {
|
|
37
|
+
if (err || (handle ?? null) === null) {
|
|
57
38
|
cb(err);
|
|
58
39
|
return;
|
|
59
40
|
}
|
|
@@ -63,27 +44,17 @@ const ensureId = function (current, { handle, id }, cb) {
|
|
|
63
44
|
|
|
64
45
|
// [function]
|
|
65
46
|
|
|
66
|
-
|
|
47
|
+
// fails when the version is already published.
|
|
48
|
+
const ensureUnpublished = function (current, { id, version }, cb) {
|
|
67
49
|
return api
|
|
68
|
-
.gameBuild(id, version,
|
|
50
|
+
.gameBuild(id, version, null, api.auth(current?.session?.access_token))
|
|
69
51
|
.then(
|
|
70
|
-
() =>
|
|
71
|
-
(err) =>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
cb(err);
|
|
77
|
-
},
|
|
78
|
-
);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// [function]
|
|
82
|
-
|
|
83
|
-
const release = function (current, artifact, game, onUploadProgress, cb) {
|
|
84
|
-
uploadBuild(current, artifact, game, onUploadProgress, cb);
|
|
52
|
+
() => published.versionPublished(id, version),
|
|
53
|
+
(err) => (err.status === 404 ? null : err),
|
|
54
|
+
)
|
|
55
|
+
.then(cb);
|
|
85
56
|
};
|
|
86
57
|
|
|
87
58
|
// [export]
|
|
88
59
|
|
|
89
|
-
module.exports = { ensureId,
|
|
60
|
+
module.exports = { ensureId, ensureUnpublished };
|