arcadible 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/bin/arc-default.js +33 -32
  2. package/bin/arc-deploy.js +73 -42
  3. package/bin/arc-init.js +196 -0
  4. package/bin/arc-inspect.js +65 -44
  5. package/bin/arc-login.js +127 -0
  6. package/bin/arc-logout.js +58 -0
  7. package/bin/arc-pack.js +82 -49
  8. package/bin/arc-validate.js +114 -0
  9. package/bin/arc-whoami.js +111 -0
  10. package/bin/arc.js +20 -15
  11. package/package.json +20 -9
  12. package/src/action/deploy/tool.js +11 -0
  13. package/src/{util/arc.js → action/deploy-git/release.js} +3 -3
  14. package/src/action/deploy-git/tool.js +11 -0
  15. package/src/action/init/tool.js +44 -0
  16. package/src/action/inspect/tool.js +25 -0
  17. package/src/action/login/flow.js +94 -0
  18. package/src/action/login/tool.js +16 -0
  19. package/src/action/logout/tool.js +15 -0
  20. package/src/action/pack/tool.js +60 -0
  21. package/src/action/validate/tool.js +39 -0
  22. package/src/action/whoami/tool.js +15 -0
  23. package/src/api.js +39 -0
  24. package/src/cli/deploy.js +17 -0
  25. package/src/cli/index.js +25 -0
  26. package/src/cli/init.js +15 -0
  27. package/src/cli/inspect.js +15 -0
  28. package/src/cli/login.js +15 -0
  29. package/src/cli/logout.js +15 -0
  30. package/src/cli/pack.js +15 -0
  31. package/src/cli/validate.js +15 -0
  32. package/src/cli/whoami.js +15 -0
  33. package/src/config/html.js +27 -0
  34. package/src/config/uri.js +14 -0
  35. package/src/config/url.js +17 -0
  36. package/src/{media.js → parser/media.js} +1 -1
  37. package/src/parser/project.js +55 -0
  38. package/src/{readme.js → parser/readme.js} +4 -4
  39. package/src/prompt/project.js +10 -0
  40. package/src/prompt/template.js +37 -0
  41. package/src/schema/game.js +20 -15
  42. package/src/schema/workflow.js +7 -5
  43. package/src/user.js +91 -0
  44. package/src/util/dom.js +10 -36
  45. package/src/util/log.js +2 -2
  46. package/src/util/md.js +2 -2
  47. package/src/util/objs.js +3 -1
  48. package/src/util/os.js +24 -0
  49. package/src/util/output.js +46 -0
  50. package/src/util/request.js +62 -0
  51. package/src/util/schema.js +25 -0
  52. package/src/util/time.js +79 -0
  53. package/bin/arc-check.js +0 -74
  54. package/npm-shrinkwrap.json +0 -988
  55. package/src/cmd/check.js +0 -26
  56. package/src/cmd/deploy.js +0 -22
  57. package/src/cmd/index.js +0 -12
  58. package/src/cmd/inspect.js +0 -26
  59. package/src/cmd/pack.js +0 -24
  60. package/src/cmd-check/index.js +0 -57
  61. package/src/cmd-deploy/index.js +0 -43
  62. package/src/cmd-inspect/index.js +0 -53
  63. package/src/cmd-pack/index.js +0 -83
  64. package/src/project.js +0 -62
  65. /package/src/{util → action/deploy-git}/git.js +0 -0
  66. /package/src/{manifest.js → parser/manifest.js} +0 -0
@@ -7,19 +7,19 @@ const z = require("zod");
7
7
 
8
8
  // [import]
9
9
 
10
- const audience = require("../config/audience");
10
+ const cfgaudience = require("../config/audience");
11
+ const cfggenre = require("../config/genre");
12
+ const cfghtml = require("../config/html");
13
+ const cfginput = require("../config/input");
14
+ const cfgorientation = require("../config/orientation");
15
+ const cfgurl = require("../config/url");
16
+ const cfgvisibility = require("../config/visibility");
11
17
  const dom = require("../util/dom");
12
- const genre = require("../config/genre");
13
- const input = require("../config/input");
14
- const orientation = require("../config/orientation");
15
- const visibility = require("../config/visibility");
16
18
 
17
19
  // [function]
18
20
 
19
21
  const reference = function (field) {
20
- return chalk.cyan.underline(
21
- `https://developer.arcadible.com/references/arcadible-manifest#${field}`,
22
- );
22
+ return chalk.cyan.underline(`${cfgurl.MANIFEST}#${field}`);
23
23
  };
24
24
 
25
25
  // [function]
@@ -93,7 +93,7 @@ const zYouTube = function () {
93
93
 
94
94
  const zAudience = function () {
95
95
  // const field = "game.audience";
96
- return z.optional(z.enum(audience));
96
+ return z.optional(z.enum(cfgaudience));
97
97
  };
98
98
 
99
99
  // [function]
@@ -141,7 +141,12 @@ const zDescription = function () {
141
141
  .min(1)
142
142
  .max(4000)
143
143
  .refine(
144
- (html) => html === dom.sanitizeAfm(html),
144
+ (str) =>
145
+ str ===
146
+ dom.sanitize(str, {
147
+ ALLOWED_ATTR: cfghtml.ALLOWED_ATTR,
148
+ ALLOWED_TAGS: cfghtml.ALLOWED_TAGS,
149
+ }),
145
150
  message(field, "Contains invalid elements."),
146
151
  ),
147
152
  );
@@ -158,7 +163,7 @@ const zGallery = function () {
158
163
 
159
164
  const zGenres = function () {
160
165
  // const field = "game.genres";
161
- return z.optional(z.array(z.enum(genre)).max(3));
166
+ return z.optional(z.array(z.enum(cfggenre)).max(3));
162
167
  };
163
168
 
164
169
  // [function]
@@ -193,14 +198,14 @@ const zIconVideo = function () {
193
198
 
194
199
  const zInputs = function () {
195
200
  // const field = "game.inputs";
196
- return z.optional(z.array(z.enum(input)).max(3));
201
+ return z.optional(z.array(z.enum(cfginput)).max(3));
197
202
  };
198
203
 
199
204
  // [function]
200
205
 
201
206
  const zOrientation = function () {
202
207
  // const field = "game.orientation";
203
- return z.optional(z.enum(orientation));
208
+ return z.optional(z.enum(cfgorientation));
204
209
  };
205
210
 
206
211
  // [function]
@@ -264,7 +269,7 @@ const zTrailer = function () {
264
269
 
265
270
  const zVisibility = function () {
266
271
  // const field = "game.visibility";
267
- return z.optional(z.enum(visibility));
272
+ return z.optional(z.enum(cfgvisibility));
268
273
  };
269
274
 
270
275
  // [function]
@@ -283,7 +288,7 @@ const zWordmarkAnimated = function () {
283
288
 
284
289
  // [function]
285
290
 
286
- const main = function (root) {
291
+ const main = function (value, { root }) {
287
292
  /* eslint-disable camelcase */
288
293
  return z.object({
289
294
  audience: zAudience(),
@@ -10,6 +10,10 @@ const chalk = require("chalk");
10
10
  const fs = require("fs-extra");
11
11
  const z = require("zod");
12
12
 
13
+ // [import]
14
+
15
+ const cfgurl = require("../config/url");
16
+
13
17
  // [use]
14
18
 
15
19
  const isAbsolute = path.isAbsolute;
@@ -24,9 +28,7 @@ const MEDIA = ".arcadible";
24
28
  // [function]
25
29
 
26
30
  const reference = function (field) {
27
- return chalk.cyan.underline(
28
- `https://developer.arcadible.com/references/arcadible-manifest#${field}`,
29
- );
31
+ return chalk.cyan.underline(`${cfgurl.MANIFEST}#${field}`);
30
32
  };
31
33
 
32
34
  // [function]
@@ -103,10 +105,10 @@ const zSkipBuild = function () {
103
105
 
104
106
  // [function]
105
107
 
106
- const main = function (root, workflow) {
108
+ const main = function (value, { root }) {
107
109
  /* eslint-disable camelcase */
108
110
  return z.object({
109
- deploy_dir: zDeployDir(root, workflow),
111
+ deploy_dir: zDeployDir(root, value),
110
112
  skip_build: zSkipBuild(),
111
113
  });
112
114
  /* eslint-enable camelcase */
package/src/user.js ADDED
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ // [import]
4
+
5
+ const path = require("node:path");
6
+
7
+ // [import]
8
+
9
+ const fs = require("fs-extra");
10
+
11
+ // [import]
12
+
13
+ const api = require("./api");
14
+ const os = require("./util/os");
15
+
16
+ // [use]
17
+
18
+ const configDir = os.configDir;
19
+ const join = path.join;
20
+ const mkdir = fs.promises.mkdir;
21
+ const readFile = fs.promises.readFile;
22
+ const unlink = fs.promises.unlink;
23
+ const writeFile = fs.promises.writeFile;
24
+
25
+ // [declare]
26
+
27
+ const CMD = "arc";
28
+ const FILE = "user.json";
29
+
30
+ // [define]
31
+
32
+ const dir = join(configDir(), CMD);
33
+ const file = join(dir, FILE);
34
+
35
+ // [function]
36
+
37
+ const expired = function (session) {
38
+ return session.expires_at <= Math.floor(Date.now() / 1000) + 60;
39
+ };
40
+
41
+ // [function]
42
+
43
+ const save = function (user) {
44
+ return mkdir(dir, { recursive: true })
45
+ .then(() => writeFile(file, JSON.stringify(user, null, 2), "utf8"))
46
+ .then(() => user);
47
+ };
48
+
49
+ // [function]
50
+
51
+ const refresh = function ({ session, ...user }) {
52
+ const form = new FormData();
53
+ form.append("refresh_token", session.refresh_token);
54
+ return api.authRefresh(form).then((data) => save({ ...user, session: data }));
55
+ };
56
+
57
+ // [function]
58
+
59
+ const get = function ({ onRefresh }) {
60
+ return readFile(file, "utf8")
61
+ .then(JSON.parse)
62
+ .catch((ex) => {
63
+ if (ex.code === "ENOENT") {
64
+ return null;
65
+ }
66
+ throw ex;
67
+ })
68
+ .then((user) => {
69
+ if (!user || !user.session) {
70
+ return null;
71
+ }
72
+ return expired(user.session)
73
+ ? onRefresh((renew) => (renew ? refresh(user) : null))
74
+ : user;
75
+ });
76
+ };
77
+
78
+ // [function]
79
+
80
+ const remove = function () {
81
+ return unlink(file).catch((ex) => {
82
+ if (ex.code === "ENOENT") {
83
+ return;
84
+ }
85
+ throw ex;
86
+ });
87
+ };
88
+
89
+ // [export]
90
+
91
+ module.exports = { get, remove, save };
package/src/util/dom.js CHANGED
@@ -9,45 +9,19 @@ const jsdom = require("jsdom");
9
9
 
10
10
  const DOM = jsdom.JSDOM;
11
11
 
12
- // [declare]
13
-
14
- const AFM_ATTR_WHITELIST = ["href", "target", "rel", "src", "alt", "title"];
15
- const AFM_TAG_WHITELIST = [
16
- "h3",
17
- "h4",
18
- "h5",
19
- "h6",
20
- "hr",
21
- "p",
22
- "ul",
23
- "ol",
24
- "li",
25
- "pre",
26
- "img",
27
- "a",
28
- "code",
29
- "strong",
30
- "b",
31
- "em",
32
- "i",
33
- "br",
34
- ];
35
-
36
- // [function]
37
-
38
- const sanitize = function (html) {
39
- return dompurify(new DOM().window).sanitize(html);
40
- };
41
-
42
12
  // [function]
43
13
 
44
- const sanitizeAfm = function (html) {
45
- return dompurify(new DOM().window).sanitize(html, {
46
- ALLOWED_ATTR: AFM_ATTR_WHITELIST,
47
- ALLOWED_TAGS: AFM_TAG_WHITELIST,
48
- });
14
+ const sanitize = function (str, cfg) {
15
+ const dom = dompurify(new DOM().window);
16
+ if (cfg) {
17
+ return dom.sanitize(str, {
18
+ ALLOWED_ATTR: cfg.ALLOWED_ATTR,
19
+ ALLOWED_TAGS: cfg.ALLOWED_TAGS,
20
+ });
21
+ }
22
+ return dom.sanitize(str);
49
23
  };
50
24
 
51
25
  // [export]
52
26
 
53
- module.exports = { DOM, sanitize, sanitizeAfm };
27
+ module.exports = { DOM, sanitize };
package/src/util/log.js CHANGED
@@ -61,13 +61,13 @@ const hdnl = function (message) {
61
61
  // [function]
62
62
 
63
63
  const pd = function (message) {
64
- log(console.error, message, { color: "white" });
64
+ log(console.error, message, { color: "red" });
65
65
  };
66
66
 
67
67
  // [function]
68
68
 
69
69
  const pdnl = function (message) {
70
- log(console.error, message, { color: "white", nl: true });
70
+ log(console.error, message, { color: "red", nl: true });
71
71
  };
72
72
 
73
73
  // [function]
package/src/util/md.js CHANGED
@@ -15,8 +15,8 @@ const stripLeadingInvisible = strs.stripLeadingInvisible;
15
15
 
16
16
  // [function]
17
17
 
18
- const parse = function (buf) {
19
- return dom.sanitize(marked.parse(stripLeadingInvisible(buf)));
18
+ const parse = function (str) {
19
+ return dom.sanitize(marked.parse(stripLeadingInvisible(str)));
20
20
  };
21
21
 
22
22
  // [export]
package/src/util/objs.js CHANGED
@@ -22,5 +22,7 @@ const pruneEmpty = function (value) {
22
22
  return value;
23
23
  /* eslint-enable no-undefined */
24
24
  };
25
- // [export];
25
+
26
+ // [export]
27
+
26
28
  module.exports = { pruneEmpty };
package/src/util/os.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ // [import]
4
+
5
+ const os = require("node:os");
6
+ const path = require("node:path");
7
+
8
+ // [use]
9
+
10
+ const homedir = os.homedir;
11
+ const join = path.join;
12
+
13
+ // [function]
14
+
15
+ const configDir = function () {
16
+ if (process.platform === "win32") {
17
+ return process.env.APPDATA;
18
+ }
19
+ return join(homedir(), ".config");
20
+ };
21
+
22
+ // [export]
23
+
24
+ module.exports = { configDir };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ // [import]
4
+
5
+ const TOML = require("@iarna/toml");
6
+
7
+ // [function]
8
+
9
+ const write = function (data) {
10
+ process.stdout.write(data.trim().concat("\n"));
11
+ };
12
+
13
+ // [function]
14
+
15
+ const printJson = function (data) {
16
+ write(JSON.stringify(data, null, 2));
17
+ };
18
+
19
+ // [function]
20
+
21
+ const printToml = function (data, key = "value") {
22
+ const field = key.split(".").at(-1);
23
+ if (data === null) {
24
+ write(`# ${field} = null`);
25
+ return;
26
+ }
27
+ try {
28
+ write(TOML.stringify(data));
29
+ } catch (ex) {
30
+ write(TOML.stringify({ [field]: data }));
31
+ }
32
+ };
33
+
34
+ // [function]
35
+
36
+ const print = function (data, { key, toml } = {}) {
37
+ if (toml) {
38
+ printToml(data, key);
39
+ } else {
40
+ printJson(data);
41
+ }
42
+ };
43
+
44
+ // [export]
45
+
46
+ module.exports = { print, printJson, printToml };
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ // [import]
4
+
5
+ const pkg = require("../../package.json");
6
+
7
+ // [declare]
8
+
9
+ const CLIENT_ID = "cli";
10
+ const CLIENT_VERSION = pkg.version;
11
+
12
+ // [function]
13
+
14
+ const parse = function (resp) {
15
+ return resp.json().then((json) => {
16
+ if (!resp.ok) {
17
+ throw new Error(json.data.message);
18
+ }
19
+ return json.data;
20
+ });
21
+ };
22
+
23
+ // [function]
24
+
25
+ const send = function (method, url, body, { token } = {}) {
26
+ const headers = {
27
+ "X-Arc-Id": CLIENT_ID,
28
+ "X-Arc-Version": CLIENT_VERSION,
29
+ };
30
+ if (token) {
31
+ headers.authorization = `Bearer ${token}`;
32
+ }
33
+ return fetch(url, { body, headers, method }).then(parse);
34
+ };
35
+
36
+ // [function]
37
+
38
+ const get = function (url, options) {
39
+ return send("GET", url, null, options);
40
+ };
41
+
42
+ // [function]
43
+
44
+ const post = function (url, body, options) {
45
+ return send("POST", url, body, options);
46
+ };
47
+
48
+ // [function]
49
+
50
+ const patch = function (url, body, options) {
51
+ return send("PATCH", url, body, options);
52
+ };
53
+
54
+ // [function]
55
+
56
+ const del = function (url, options) {
57
+ return send("DELETE", url, null, options);
58
+ };
59
+
60
+ // [export]
61
+
62
+ module.exports = { del, get, patch, post };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ // [function]
4
+
5
+ const format = function (name, error) {
6
+ return error.issues.map(
7
+ (issue) => `${name}.${issue.path.join(".") || "value"}: ${issue.message}`,
8
+ );
9
+ };
10
+
11
+ // [function]
12
+
13
+ const validator = function (name, schema) {
14
+ return function (value, conf) {
15
+ const result = schema(value, conf).safeParse(value);
16
+ if (!result.success) {
17
+ return { issues: format(name, result.error) };
18
+ }
19
+ return { issues: [] };
20
+ };
21
+ };
22
+
23
+ // [export]
24
+
25
+ module.exports = { validator };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ // [function]
4
+
5
+ const ms = function (value) {
6
+ return value;
7
+ };
8
+
9
+ // [function]
10
+
11
+ const s = function (value) {
12
+ return value * 1000;
13
+ };
14
+
15
+ // [function]
16
+
17
+ const m = function (value) {
18
+ return s(value * 60);
19
+ };
20
+
21
+ // [function]
22
+
23
+ const h = function (value) {
24
+ return m(value * 60);
25
+ };
26
+
27
+ // [function]
28
+
29
+ const backoff = function (elapsed, delay, factor, interval, maxDelay) {
30
+ const step = Math.floor(elapsed / interval);
31
+ return Math.min(delay * factor ** step, maxDelay);
32
+ };
33
+
34
+ // [function]
35
+
36
+ const sleep = function (delay) {
37
+ return new Promise((resolve) => {
38
+ setTimeout(resolve, delay);
39
+ });
40
+ };
41
+
42
+ // [function]
43
+
44
+ const wait = function (delay, next) {
45
+ return sleep(delay).then(next);
46
+ };
47
+
48
+ // [function]
49
+
50
+ const poll = function (
51
+ fn,
52
+ value,
53
+ {
54
+ delay = s(1),
55
+ factor = 1,
56
+ interval = m(1),
57
+ maxDelay = delay,
58
+ timeout = Infinity,
59
+ } = {},
60
+ ) {
61
+ const started = Date.now();
62
+ const next = function () {
63
+ return fn(value).then((result) => {
64
+ if (result !== null) {
65
+ return result;
66
+ }
67
+ const elapsed = Date.now() - started;
68
+ if (elapsed >= timeout) {
69
+ throw new Error("Timed out.");
70
+ }
71
+ return wait(backoff(elapsed, delay, factor, interval, maxDelay), next);
72
+ });
73
+ };
74
+ return next();
75
+ };
76
+
77
+ // [export]
78
+
79
+ module.exports = { h, m, ms, poll, s };
package/bin/arc-check.js DELETED
@@ -1,74 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- // [import]
5
-
6
- const path = require("node:path");
7
-
8
- // [import]
9
-
10
- const hideBin = require("yargs/helpers").hideBin;
11
- const yargs = require("yargs/yargs");
12
-
13
- // [import]
14
-
15
- const check = require("../src/cmd/check");
16
- const pkg = require("../package.json");
17
- const rc = require("../src/util/rc");
18
-
19
- // [use]
20
-
21
- const dirname = path.dirname;
22
- const findRc = rc.findRc;
23
- const join = path.join;
24
- const resolve = path.resolve;
25
-
26
- // [declare]
27
-
28
- const CMD = "arc";
29
- const SUBCMD = "check";
30
-
31
- // [define]
32
-
33
- const conf = {
34
- quiet: false,
35
- ...findRc(CMD, SUBCMD, process.argv, ["--cwd", "-C"]),
36
- };
37
-
38
- // [function]
39
-
40
- const fixBin = function (argv) {
41
- argv[1] = join(dirname(argv[1]), CMD);
42
- return hideBin(argv);
43
- };
44
-
45
- // [function]
46
-
47
- const start = function (cli) {
48
- const argv = cli.parse();
49
- check({ quiet: argv.quiet, root: resolve(process.cwd(), argv.cwd) });
50
- };
51
-
52
- // [start]
53
-
54
- start(
55
- yargs(fixBin(process.argv))
56
- .usage(`${CMD} ${SUBCMD} [options]`)
57
- .option("quiet", {
58
- alias: "q",
59
- default: conf.quiet,
60
- describe: "Suppress standard output and show only errors.",
61
- type: "boolean",
62
- })
63
- .option("cwd", {
64
- alias: "C",
65
- default: ".",
66
- describe: "Run in the specified path.",
67
- type: "string",
68
- })
69
- .help("help")
70
- .alias("help", "h")
71
- .version(pkg.version)
72
- .alias("version", "v")
73
- .strict(),
74
- );