arcadible 0.1.7 → 0.1.9

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/bin/arc-init.js CHANGED
@@ -7,6 +7,7 @@ const path = require("node:path");
7
7
 
8
8
  // [import]
9
9
 
10
+ const fs = require("fs-extra");
10
11
  const hideBin = require("yargs/helpers").hideBin;
11
12
  const prompts = require("@inquirer/prompts");
12
13
  const yargs = require("yargs/yargs");
@@ -18,14 +19,14 @@ const init = require("../src/cli/init");
18
19
  const log = require("../src/util/log");
19
20
  const output = require("../src/util/output");
20
21
  const pkg = require("../package.json");
21
- const project = require("../src/prompt/project");
22
22
  const rc = require("../src/util/rc");
23
23
  const template = require("../src/prompt/template");
24
24
 
25
25
  // [use]
26
26
 
27
27
  const findRc = rc.findRc;
28
- const input = prompts.input;
28
+ const join = path.join;
29
+ const pathExists = fs.pathExists;
29
30
  const print = output.print;
30
31
  const relative = path.relative;
31
32
  const resolve = path.resolve;
@@ -39,8 +40,8 @@ const SUBCMD = "init";
39
40
  // [define]
40
41
 
41
42
  const conf = {
42
- force: false,
43
43
  json: false,
44
+ project: ".",
44
45
  quiet: false,
45
46
  yes: false,
46
47
  ...findRc(CMD, SUBCMD, process.argv, ["--cwd", "-C"]),
@@ -66,8 +67,9 @@ const start = function (argv) {
66
67
  const quiet = argv.quiet;
67
68
  const root = resolve(process.cwd(), argv.cwd);
68
69
  return init({
69
- force: argv.force,
70
+ force: false,
70
71
  handler: handler({ json, quiet }),
72
+ patch: argv.patch,
71
73
  project: argv.project,
72
74
  root,
73
75
  template: argv.template,
@@ -106,17 +108,20 @@ const start = function (argv) {
106
108
 
107
109
  // [function]
108
110
 
111
+ const patch = function (cwd, project) {
112
+ return pathExists(join(resolve(process.cwd(), cwd), project));
113
+ };
114
+
115
+ // [function]
116
+
109
117
  const prompt = async function ({ yes, ...argv }) {
110
118
  const opts = { ...argv };
111
- if (yes) {
112
- opts.project ??= project.input.default;
119
+ opts.patch = await patch(opts.cwd, opts.project);
120
+ if (opts.patch || yes) {
113
121
  opts.template ??= template.select.default;
114
122
  return opts;
115
123
  }
116
- if (!argv.project) {
117
- opts.project = await input(project.input);
118
- }
119
- if (!argv.template) {
124
+ if (!opts.template) {
120
125
  opts.template = await select(template.select);
121
126
  }
122
127
  return opts;
@@ -128,9 +133,10 @@ const main = function (argv) {
128
133
  return prompt(
129
134
  yargs(hideBin(argv))
130
135
  .scriptName(`${CMD} ${SUBCMD}`)
131
- .usage("$0 <project> [options]")
132
- .command("$0 <project>", false, (cli) =>
136
+ .usage("$0 [project] [options]")
137
+ .command("$0 [project]", false, (cli) =>
133
138
  cli.positional("project", {
139
+ default: conf.project,
134
140
  describe: "Project directory",
135
141
  type: "string",
136
142
  }),
@@ -146,12 +152,6 @@ const main = function (argv) {
146
152
  describe: "Answer prompts using default values",
147
153
  type: "boolean",
148
154
  })
149
- .option("force", {
150
- alias: "f",
151
- default: conf.force,
152
- describe: "Overwrite an existing directory",
153
- type: "boolean",
154
- })
155
155
  .option("json", {
156
156
  alias: "j",
157
157
  default: conf.json,
package/bin/arc-pack.js CHANGED
@@ -34,7 +34,7 @@ const SUBCMD = "pack";
34
34
 
35
35
  const conf = {
36
36
  json: false,
37
- output: "project.zip",
37
+ output: null,
38
38
  quiet: false,
39
39
  ...findRc(CMD, SUBCMD, process.argv, ["--cwd", "-C"]),
40
40
  };
package/package.json CHANGED
@@ -51,5 +51,5 @@
51
51
  "license": "Apache-2.0",
52
52
  "main": "./src/cli/index.js",
53
53
  "name": "arcadible",
54
- "version": "0.1.7"
54
+ "version": "0.1.9"
55
55
  }
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ // [import]
4
+
5
+ const crypto = require("node:crypto");
6
+ const path = require("node:path");
7
+
8
+ // [import]
9
+
10
+ const fs = require("fs-extra");
11
+ const TOML = require("@iarna/toml");
12
+
13
+ // [use]
14
+
15
+ const join = path.join;
16
+ const pathExists = fs.pathExists;
17
+ const randomUUID = crypto.randomUUID;
18
+ const readFile = fs.promises.readFile;
19
+ const writeFile = fs.promises.writeFile;
20
+
21
+ // [declare]
22
+
23
+ const MANIFEST = "arcadible.toml";
24
+
25
+ // [function]
26
+
27
+ const parseToml = function (buf) {
28
+ try {
29
+ return TOML.parse(buf);
30
+ } catch (ex) {
31
+ throw new Error(`Unable to parse ${MANIFEST}: ${ex.message}`, {
32
+ cause: ex,
33
+ });
34
+ }
35
+ };
36
+
37
+ // [function]
38
+
39
+ const pickVersion = function (version, envVersion) {
40
+ switch (true) {
41
+ case Boolean(version):
42
+ return { version };
43
+ case Boolean(envVersion):
44
+ return {};
45
+ default:
46
+ return { version: "0.1.0" };
47
+ }
48
+ };
49
+
50
+ // [function]
51
+
52
+ const readManifest = function (file) {
53
+ return pathExists(file)
54
+ .then((exists) => (exists ? readFile(file, "utf8") : null))
55
+ .then((buf) => (buf === null ? {} : parseToml(buf)));
56
+ };
57
+
58
+ // [function]
59
+
60
+ const prepareGame = function (envVersion, game = {}) {
61
+ const { id, version, ...rest } = game;
62
+ return {
63
+ id: id ?? randomUUID(),
64
+ ...pickVersion(version, envVersion),
65
+ ...rest,
66
+ };
67
+ };
68
+
69
+ // [function]
70
+
71
+ const shouldWrite = function (manifest, next) {
72
+ return (
73
+ manifest.game?.id !== next.game?.id ||
74
+ manifest.game?.version !== next.game?.version
75
+ );
76
+ };
77
+
78
+ // [function]
79
+
80
+ const prepare = function (dest, envVersion) {
81
+ const file = join(dest, MANIFEST);
82
+ return readManifest(file).then((manifest) => {
83
+ const { game, ...rest } = manifest;
84
+ const next = { game: prepareGame(envVersion, game), ...rest };
85
+ if (shouldWrite(manifest, next)) {
86
+ return writeFile(file, TOML.stringify(next), "utf8");
87
+ }
88
+ return null;
89
+ });
90
+ };
91
+
92
+ // [export]
93
+
94
+ module.exports = { prepare };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ // [import]
4
+
5
+ const path = require("node:path");
6
+
7
+ // [import]
8
+
9
+ const env = require("../../parser/env");
10
+ const manifest = require("./manifest");
11
+
12
+ // [use]
13
+
14
+ const prepare = manifest.prepare;
15
+ const resolve = path.resolve;
16
+
17
+ // [function]
18
+
19
+ const inferVersion = function (root) {
20
+ return env(root).then(({ game }) => game?.version ?? null);
21
+ };
22
+
23
+ // [function]
24
+
25
+ const init = function () {
26
+ return Promise.resolve();
27
+ };
28
+
29
+ // [function]
30
+
31
+ const main = function ({ project, root }) {
32
+ const dest = resolve(root, project);
33
+ return init()
34
+ .then(() => inferVersion(dest))
35
+ .then((version) => prepare(dest, version))
36
+ .then(() => ({ path: dest }));
37
+ };
38
+
39
+ // [export]
40
+
41
+ module.exports = main;
@@ -9,20 +9,42 @@ const path = require("node:path");
9
9
  const degit = require("degit");
10
10
  const fs = require("fs-extra");
11
11
 
12
+ // [import]
13
+
14
+ const env = require("../../parser/env");
15
+ const manifest = require("./manifest");
16
+
12
17
  // [use]
13
18
 
19
+ const join = path.join;
14
20
  const pathExists = fs.pathExists;
21
+ const prepare = manifest.prepare;
15
22
  const remove = fs.remove;
16
23
  const resolve = path.resolve;
17
24
 
25
+ // [declare]
26
+
27
+ const LICENSE = "LICENSE";
28
+
29
+ // [function]
30
+
31
+ const removeLicense = function (dest) {
32
+ return remove(join(dest, LICENSE));
33
+ };
34
+
35
+ // [function]
36
+
37
+ const inferVersion = function (root) {
38
+ return env(root).then(({ game }) => game?.version ?? null);
39
+ };
40
+
18
41
  // [function]
19
42
 
20
43
  const init = function (src, dest, { onBegin, onInfo }) {
21
44
  onBegin({ dest, src });
22
45
  return degit(src, { cache: false, force: true, verbose: false })
23
46
  .on("info", onInfo)
24
- .clone(dest)
25
- .then(() => remove(resolve(dest, "LICENSE")));
47
+ .clone(dest);
26
48
  };
27
49
 
28
50
  // [function]
@@ -38,6 +60,9 @@ const main = function ({ force, project, root, template }, handler) {
38
60
  }
39
61
  return init(template, dest, handler);
40
62
  })
63
+ .then(() => removeLicense(dest))
64
+ .then(() => inferVersion(dest))
65
+ .then((version) => prepare(dest, version))
41
66
  .then(() => ({ path: dest }));
42
67
  };
43
68
 
@@ -8,10 +8,12 @@ const crypto = require("node:crypto");
8
8
 
9
9
  const api = require("../../api");
10
10
  const cfgurl = require("../../config/url");
11
+ const delay = require("../../util/delay");
11
12
  const time = require("../../util/time");
12
13
 
13
14
  // [use]
14
15
 
16
+ const poll = delay.poll;
15
17
  const randomUUID = crypto.randomUUID;
16
18
 
17
19
  // [function]
@@ -75,7 +77,7 @@ const main = function ({ onCreated, onPoll }) {
75
77
  onCreated,
76
78
  ).then(({ id }) => {
77
79
  const timeout = Math.max(0, expiresAt.getTime() - Date.now() - time.s(15));
78
- return time.poll(
80
+ return poll(
79
81
  (flow) => pollFlow(flow, onPoll),
80
82
  { id, token },
81
83
  {
@@ -11,6 +11,7 @@ const fs = require("fs-extra");
11
11
  // [import]
12
12
 
13
13
  const project = require("../../parser/project");
14
+ const size = require("../../util/size");
14
15
  const Zip = require("../../util/zip");
15
16
 
16
17
  // [use]
@@ -21,38 +22,78 @@ const resolve = path.resolve;
21
22
 
22
23
  // [declare]
23
24
 
25
+ const MAIN = "index.html";
24
26
  const MANIFEST = "arcadible.json";
25
27
  const MEDIA = ".arcadible";
28
+ const OUTPUT = ".arc/package";
29
+
30
+ // [declare]
31
+
32
+ const SIZE_PARTIAL = size.mb(64);
33
+ const SIZE_TOTAL = size.mb(256);
34
+
35
+ // [function]
36
+
37
+ const verifyPartial = function (zip) {
38
+ if (!zip.has(MAIN)) {
39
+ throw new Error(`Package is missing "${MAIN}".`);
40
+ }
41
+ if (zip.stat().size > SIZE_PARTIAL) {
42
+ const max = SIZE_PARTIAL / 1024 / 1024;
43
+ throw new Error(`Package size (excluding store assets) exceeds ${max} MB.`);
44
+ }
45
+ return zip;
46
+ };
47
+
48
+ // [function]
49
+
50
+ const verifyTotal = function (zip) {
51
+ if (zip.stat().size > SIZE_TOTAL) {
52
+ const max = SIZE_TOTAL / 1024 / 1024;
53
+ throw new Error(`Package size (including store assets) exceeds ${max} MB.`);
54
+ }
55
+ return zip;
56
+ };
26
57
 
27
58
  // [function]
28
59
 
29
60
  const pack = function (name, game, { deployPath, mediaPath, zipPath }) {
30
61
  const zip = new Zip(name);
31
- return Promise.all([pathExists(deployPath), pathExists(mediaPath)])
32
- .then(([existsDeploy, existsMedia]) => {
62
+ return pathExists(deployPath)
63
+ .then((existsDeploy) => {
33
64
  if (existsDeploy) {
34
65
  zip.addDir(deployPath);
35
66
  }
67
+ return zip;
68
+ })
69
+ .then(verifyPartial)
70
+ .then(() => pathExists(mediaPath))
71
+ .then((existsMedia) => {
36
72
  if (existsMedia) {
37
73
  zip.addDir(mediaPath, MEDIA);
38
74
  }
39
75
  zip.addJson(MANIFEST, { game });
40
- zip.write(zipPath);
41
- return zip.stat();
76
+ return zip;
42
77
  })
43
- .then((stat) => ({ path: zipPath, ...stat }));
78
+ .then(verifyTotal)
79
+ .then((file) => {
80
+ file.write(zipPath);
81
+ return { path: zipPath, ...file.stat() };
82
+ });
44
83
  };
45
84
 
46
85
  // [function]
47
86
 
48
87
  const main = function ({ output, root }) {
49
- return project(root).then(({ game, workflow }) =>
50
- pack(parse(output).name, game, {
88
+ return project(root).then(({ game, workflow }) => {
89
+ const name = game.handle || game.id;
90
+ const file = output || `${OUTPUT}/${name}-v${game.version}.zip`;
91
+ return pack(parse(file).name, game, {
51
92
  deployPath: resolve(root, workflow.deploy_dir),
52
93
  mediaPath: resolve(root, MEDIA),
53
- zipPath: resolve(root, output),
54
- }),
55
- );
94
+ zipPath: resolve(root, file),
95
+ });
96
+ });
56
97
  };
57
98
 
58
99
  // [export]
package/src/cli/deploy.js CHANGED
@@ -2,13 +2,13 @@
2
2
 
3
3
  // [import]
4
4
 
5
- const deployGitTool = require("../action/deploy-git/tool");
6
5
  const deployTool = require("../action/deploy/tool");
6
+ const deployToolGit = require("../action/deploy/tool-git");
7
7
 
8
8
  // [function]
9
9
 
10
10
  const main = function ({ git, handler, ...conf }) {
11
- const tool = git ? deployGitTool : deployTool;
11
+ const tool = git ? deployToolGit : deployTool;
12
12
  return tool(conf, handler);
13
13
  };
14
14
 
package/src/cli/init.js CHANGED
@@ -3,11 +3,13 @@
3
3
  // [import]
4
4
 
5
5
  const initTool = require("../action/init/tool");
6
+ const initToolPatch = require("../action/init/tool-patch");
6
7
 
7
8
  // [function]
8
9
 
9
- const main = function ({ handler, ...conf }) {
10
- return initTool(conf, handler);
10
+ const main = function ({ handler, patch, ...conf }) {
11
+ const tool = patch ? initToolPatch : initTool;
12
+ return tool(conf, handler);
11
13
  };
12
14
 
13
15
  // [export]
@@ -4,31 +4,31 @@
4
4
 
5
5
  const cfggame = require("../config/game");
6
6
  const cfgworkflow = require("../config/workflow");
7
+ const env = require("./env");
7
8
  const manifest = require("./manifest");
8
9
  const media = require("./media");
9
- const pkg = require("./pkg");
10
10
  const promise = require("../util/promise");
11
11
  const readme = require("./readme");
12
12
 
13
13
  // [function]
14
14
 
15
- const configGame = function (readmeGame, mediaGame, pkgGame, manifestGame) {
15
+ const configGame = function (readmeGame, mediaGame, envGame, manifestGame) {
16
16
  return {
17
17
  ...cfggame,
18
- ...(readmeGame || {}),
19
- ...(mediaGame || {}),
20
- ...(pkgGame || {}),
21
- ...(manifestGame || {}),
18
+ ...(readmeGame ?? {}),
19
+ ...(mediaGame ?? {}),
20
+ ...(envGame ?? {}),
21
+ ...(manifestGame ?? {}),
22
22
  };
23
23
  };
24
24
 
25
25
  // [function]
26
26
 
27
- const configWorkflow = function (pkgWorkflow, manifestWorkflow) {
27
+ const configWorkflow = function (envWorkflow, manifestWorkflow) {
28
28
  return {
29
29
  ...cfgworkflow,
30
- ...(pkgWorkflow || {}),
31
- ...(manifestWorkflow || {}),
30
+ ...(envWorkflow ?? {}),
31
+ ...(manifestWorkflow ?? {}),
32
32
  };
33
33
  };
34
34
 
@@ -36,23 +36,22 @@ const configWorkflow = function (pkgWorkflow, manifestWorkflow) {
36
36
 
37
37
  const main = function (root) {
38
38
  const parsers = [
39
- () => manifest(root),
40
- () => media(root),
41
- () => pkg(root),
42
39
  () => readme(root),
40
+ () => media(root),
41
+ () => env(root),
42
+ () => manifest(root),
43
43
  ];
44
44
  return promise
45
45
  .serial(parsers)
46
- .then(([manifestData, mediaData, pkgData, readmeData]) => {
47
- const game = configGame(
46
+ .then(([readmeData, mediaData, envData, manifestData]) => ({
47
+ game: configGame(
48
48
  readmeData.game,
49
49
  mediaData.game,
50
- pkgData.game,
50
+ envData.game,
51
51
  manifestData.game,
52
- );
53
- const workflow = configWorkflow(pkgData.workflow, manifestData.workflow);
54
- return { game, workflow };
55
- });
52
+ ),
53
+ workflow: configWorkflow(envData.workflow, manifestData.workflow),
54
+ }));
56
55
  };
57
56
 
58
57
  // [export]
@@ -17,6 +17,7 @@ const cfgurl = require("../config/url");
17
17
  const cfgvisibility = require("../config/visibility");
18
18
  const check = require("./check/game");
19
19
  const dom = require("../util/dom");
20
+ const size = require("../util/size");
20
21
  const strs = require("../util/strs");
21
22
 
22
23
  // [use]
@@ -152,7 +153,7 @@ const zBanner = function (root) {
152
153
  return z.optional(
153
154
  zPng(field, root, {
154
155
  aspect: "2:1",
155
- maxSize: 2 * 1024 * 1024,
156
+ maxSize: size.mb(2),
156
157
  minHeight: 512,
157
158
  minWidth: 1024,
158
159
  }),
@@ -166,7 +167,7 @@ const zBannerVideo = function (root) {
166
167
  return z.optional(
167
168
  zMp4(field, root, {
168
169
  aspect: "2:1",
169
- maxSize: 5 * 1024 * 1024,
170
+ maxSize: size.mb(5),
170
171
  minHeight: 512,
171
172
  minWidth: 1024,
172
173
  }),
@@ -187,7 +188,7 @@ const zCover = function (root) {
187
188
  return z.optional(
188
189
  zPng(field, root, {
189
190
  aspect: "3:2",
190
- maxSize: 2 * 1024 * 1024,
191
+ maxSize: size.mb(2),
191
192
  minHeight: 512,
192
193
  minWidth: 768,
193
194
  }),
@@ -201,7 +202,7 @@ const zCoverVideo = function (root) {
201
202
  return z.optional(
202
203
  zMp4(field, root, {
203
204
  aspect: "3:2",
204
- maxSize: 5 * 1024 * 1024,
205
+ maxSize: size.mb(5),
205
206
  minHeight: 512,
206
207
  minWidth: 768,
207
208
  }),
@@ -237,8 +238,8 @@ const zGallery = function (root) {
237
238
  z
238
239
  .array(
239
240
  z.union([
240
- zPng(field, root, { maxSize: 2 * 1024 * 1024 }),
241
- zMp4(field, root, { maxSize: 5 * 1024 * 1024 }),
241
+ zPng(field, root, { maxSize: size.mb(2) }),
242
+ zMp4(field, root, { maxSize: size.mb(5) }),
242
243
  ]),
243
244
  )
244
245
  .min(1)
@@ -274,7 +275,7 @@ const zIcon = function (root) {
274
275
  return z.optional(
275
276
  zPng(field, root, {
276
277
  aspect: "1:1",
277
- maxSize: 2 * 1024 * 1024,
278
+ maxSize: size.mb(2),
278
279
  minHeight: 512,
279
280
  minWidth: 512,
280
281
  }),
@@ -288,7 +289,7 @@ const zIconVideo = function (root) {
288
289
  return z.optional(
289
290
  zMp4(field, root, {
290
291
  aspect: "1:1",
291
- maxSize: 5 * 1024 * 1024,
292
+ maxSize: size.mb(5),
292
293
  minHeight: 512,
293
294
  minWidth: 512,
294
295
  }),
@@ -329,7 +330,7 @@ const zPoster = function (root) {
329
330
  return z.optional(
330
331
  zPng(field, root, {
331
332
  aspect: "2:3",
332
- maxSize: 2 * 1024 * 1024,
333
+ maxSize: size.mb(2),
333
334
  minHeight: 768,
334
335
  minWidth: 512,
335
336
  }),
@@ -343,7 +344,7 @@ const zPosterVideo = function (root) {
343
344
  return z.optional(
344
345
  zMp4(field, root, {
345
346
  aspect: "2:3",
346
- maxSize: 5 * 1024 * 1024,
347
+ maxSize: size.mb(5),
347
348
  minHeight: 768,
348
349
  minWidth: 512,
349
350
  }),
@@ -419,7 +420,7 @@ const zWordmark = function (root) {
419
420
  return z.optional(
420
421
  zSvg(field, root, {
421
422
  aspect: "1:1",
422
- maxSize: 512 * 1024,
423
+ maxSize: size.kb(512),
423
424
  }),
424
425
  );
425
426
  };
@@ -431,7 +432,7 @@ const zWordmarkAnimated = function (root) {
431
432
  return z.optional(
432
433
  zSvg(field, root, {
433
434
  aspect: "1:1",
434
- maxSize: 1024 * 1024,
435
+ maxSize: size.mb(1),
435
436
  }),
436
437
  );
437
438
  };
@@ -45,7 +45,7 @@ const message = function (field, lines) {
45
45
 
46
46
  const zBuild = function () {
47
47
  // const field = "build";
48
- return z.string();
48
+ return z.union([z.string(), z.array(z.string())]);
49
49
  };
50
50
 
51
51
  // [function]
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ // [import]
4
+
5
+ const time = require("./time");
6
+
7
+ // [function]
8
+
9
+ const backoff = function (elapsed, delay, factor, interval, maxDelay) {
10
+ const step = Math.floor(elapsed / interval);
11
+ return Math.min(delay * factor ** step, maxDelay);
12
+ };
13
+
14
+ // [function]
15
+
16
+ const sleep = function (delay) {
17
+ return new Promise((resolve) => {
18
+ setTimeout(resolve, delay);
19
+ });
20
+ };
21
+
22
+ // [function]
23
+
24
+ const wait = function (delay, next) {
25
+ return sleep(delay).then(next);
26
+ };
27
+
28
+ // [function]
29
+
30
+ const poll = function (
31
+ fn,
32
+ value,
33
+ {
34
+ delay = time.s(1),
35
+ factor = 1,
36
+ interval = time.m(1),
37
+ maxDelay = delay,
38
+ timeout = Infinity,
39
+ } = {},
40
+ ) {
41
+ const started = Date.now();
42
+ const next = function () {
43
+ return fn(value).then((result) => {
44
+ if (result !== null) {
45
+ return result;
46
+ }
47
+ const elapsed = Date.now() - started;
48
+ if (elapsed >= timeout) {
49
+ throw new Error("Timed out.");
50
+ }
51
+ return wait(backoff(elapsed, delay, factor, interval, maxDelay), next);
52
+ });
53
+ };
54
+ return next();
55
+ };
56
+
57
+ // [export]
58
+
59
+ module.exports = { poll };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ // [function]
4
+
5
+ const b = function (value) {
6
+ return value;
7
+ };
8
+
9
+ // [function]
10
+
11
+ const kb = function (value) {
12
+ return b(value * 1024);
13
+ };
14
+
15
+ // [function]
16
+
17
+ const mb = function (value) {
18
+ return kb(value * 1024);
19
+ };
20
+
21
+ // [function]
22
+
23
+ const gb = function (value) {
24
+ return mb(value * 1024);
25
+ };
26
+
27
+ // [export]
28
+
29
+ module.exports = { b, gb, kb, mb };
package/src/util/time.js CHANGED
@@ -24,56 +24,6 @@ const h = function (value) {
24
24
  return m(value * 60);
25
25
  };
26
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
27
  // [export]
78
28
 
79
- module.exports = { h, m, ms, poll, s };
29
+ module.exports = { h, m, ms, s };
package/src/util/zip.js CHANGED
@@ -49,6 +49,12 @@ const Main = class {
49
49
 
50
50
  // [method]
51
51
 
52
+ has(name) {
53
+ return this.zip.getEntry(join(this.prefix, name)) !== null;
54
+ }
55
+
56
+ // [method]
57
+
52
58
  stat() {
53
59
  const buffer = this.zip.toBuffer();
54
60
  const hash = createHash("sha256").update(buffer).digest("hex");
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- // [export]
4
-
5
- module.exports = {
6
- input: {
7
- default: ".",
8
- message: "Project",
9
- },
10
- };
File without changes
File without changes