arcadible 0.1.2 → 0.1.4

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-deploy.js CHANGED
@@ -33,8 +33,8 @@ const SUBCMD = "deploy";
33
33
  // [define]
34
34
 
35
35
  const conf = {
36
+ git: false,
36
37
  json: false,
37
- production: false,
38
38
  quiet: false,
39
39
  ...findRc(CMD, SUBCMD, process.argv, ["--cwd", "-C"]),
40
40
  };
@@ -67,7 +67,6 @@ const handler = function ({ json, quiet }) {
67
67
 
68
68
  const start = function (argv) {
69
69
  const json = argv.json;
70
- const pre = !argv.production;
71
70
  const quiet = argv.quiet;
72
71
  const root = resolve(process.cwd(), argv.cwd);
73
72
  return validate({ root })
@@ -77,10 +76,8 @@ const start = function (argv) {
77
76
  throw new Error("Validate failed. Run `arc validate` for details.");
78
77
  }
79
78
  return deploy({
80
- direct: false,
79
+ git: argv.git,
81
80
  handler: handler({ json, quiet }),
82
- pre,
83
- preId: "rc",
84
81
  root,
85
82
  });
86
83
  })
@@ -90,7 +87,7 @@ const start = function (argv) {
90
87
  return;
91
88
  }
92
89
  if (!quiet) {
93
- log.p(`✓ ${pre ? "Prerelease" : "Release"} v${data.to} submitted.`);
90
+ log.p(`✓ Build v${data.to} submitted for release.`);
94
91
  log.hs("Deployed.");
95
92
  }
96
93
  })
@@ -113,10 +110,10 @@ const main = function (argv) {
113
110
  yargs(hideBin(argv))
114
111
  .scriptName(`${CMD} ${SUBCMD}`)
115
112
  .usage("$0 [options]")
116
- .option("production", {
117
- alias: "p",
118
- default: conf.production,
119
- describe: "Deploy to production.",
113
+ .option("git", {
114
+ alias: "g",
115
+ default: conf.git,
116
+ describe: "Deploy through Git.",
120
117
  type: "boolean",
121
118
  })
122
119
  .option("json", {
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.2"
54
+ "version": "0.1.4"
55
55
  }
@@ -8,15 +8,9 @@ const execFile = require("node:child_process").execFile;
8
8
 
9
9
  const semver = require("semver");
10
10
 
11
- // [import]
12
-
13
- const strs = require("../../util/strs");
14
-
15
11
  // [use]
16
12
 
17
- const compareSemver = semver.compare;
18
- const trimWhitespace = strs.trimWhitespace;
19
- const validSemver = semver.valid;
13
+ const prereleaseSemver = semver.prerelease;
20
14
 
21
15
  // [declare]
22
16
 
@@ -32,8 +26,8 @@ const git = function (root, args, cb) {
32
26
 
33
27
  const ensureRepo = function (root, cb) {
34
28
  const message = [
35
- "Unable to find Git repository.",
36
- "Run this command from a Git repository.",
29
+ "Unable to find a Git repository.",
30
+ "Navigate to a Git repository and try again.",
37
31
  ];
38
32
  git(root, ["rev-parse", "--is-inside-work-tree"], (err) => {
39
33
  if (err) {
@@ -65,7 +59,7 @@ const ensureRemote = function (root, cb) {
65
59
  const ensureClean = function (root, cb) {
66
60
  const message = [
67
61
  "Unable to continue with unstaged changes.",
68
- "Stage, commit, or discard local changes before deploying.",
62
+ "Stage, commit, or discard your local changes before deploying.",
69
63
  ];
70
64
  git(root, ["diff", "--quiet"], (err) => {
71
65
  if (err) {
@@ -92,50 +86,7 @@ const ensureClean = function (root, cb) {
92
86
 
93
87
  // [function]
94
88
 
95
- const fetchTags = function (root, cb) {
96
- const message = [
97
- "Unable to synchronize Git release tags.",
98
- "Run `arc deploy` again to retry with the latest release tags.",
99
- ];
100
- git(
101
- root,
102
- ["fetch", "origin", `refs/tags/${PREFIX}*:refs/tags/${PREFIX}*`],
103
- (err) => {
104
- if (err) {
105
- cb(new Error(message.join("\n"), { cause: err }));
106
- return;
107
- }
108
- cb();
109
- },
110
- );
111
- };
112
-
113
- // [function]
114
-
115
- const listTags = function (root, cb) {
116
- fetchTags(root, (err) => {
117
- if (err) {
118
- cb(err);
119
- return;
120
- }
121
- git(root, ["tag", "--list", `${PREFIX}*`], (err, stdOut) => {
122
- if (err) {
123
- cb(err);
124
- return;
125
- }
126
- const versions = trimWhitespace(stdOut)
127
- .split("\n")
128
- .map((tag) => tag.slice(PREFIX.length))
129
- .filter(validSemver)
130
- .sort(compareSemver);
131
- cb(null, versions.at(-1) || "0.0.0");
132
- });
133
- });
134
- };
135
-
136
- // [function]
137
-
138
- const createTag = function (root, version, pre, cb) {
89
+ const createTag = function (root, version, cb) {
139
90
  const message = [
140
91
  "Unable to create Git tag.",
141
92
  "Verify the release tag does not already exist locally.",
@@ -147,7 +98,9 @@ const createTag = function (root, version, pre, cb) {
147
98
  "-a",
148
99
  `${PREFIX}${version}`,
149
100
  "-m",
150
- pre ? `Prerelease v${version}` : `Release v${version}`,
101
+ prereleaseSemver(version) === null
102
+ ? `Release v${version}`
103
+ : `Prerelease v${version}`,
151
104
  ],
152
105
  (err) => {
153
106
  if (err) {
@@ -164,7 +117,7 @@ const createTag = function (root, version, pre, cb) {
164
117
  const pushTag = function (root, version, cb) {
165
118
  const message = [
166
119
  "Unable to push Git tag.",
167
- "Run `arc deploy` again to retry with the latest release version.",
120
+ "Verify the release tag does not already exist on remote 'origin'.",
168
121
  ];
169
122
  git(root, ["push", "origin", `${PREFIX}${version}`], (err) => {
170
123
  if (err) {
@@ -177,8 +130,8 @@ const pushTag = function (root, version, cb) {
177
130
 
178
131
  // [function]
179
132
 
180
- const release = function (root, version, pre, cb) {
181
- createTag(root, version, pre, (err) => {
133
+ const release = function (root, version, cb) {
134
+ createTag(root, version, (err) => {
182
135
  if (err) {
183
136
  cb(err);
184
137
  return;
@@ -189,4 +142,4 @@ const release = function (root, version, pre, cb) {
189
142
 
190
143
  // [export]
191
144
 
192
- module.exports = { ensureClean, ensureRemote, ensureRepo, listTags, release };
145
+ module.exports = { ensureClean, ensureRemote, ensureRepo, release };
@@ -2,43 +2,31 @@
2
2
 
3
3
  // [import]
4
4
 
5
- const semver = require("semver");
6
-
7
- // [import]
8
-
9
5
  const git = require("./git");
6
+ const project = require("../../parser/project");
10
7
 
11
8
  // [use]
12
9
 
13
10
  const ensureClean = git.ensureClean;
14
11
  const ensureRemote = git.ensureRemote;
15
12
  const ensureRepo = git.ensureRepo;
16
- const incSemver = semver.inc;
17
- const listTags = git.listTags;
18
13
  const release = git.release;
19
14
 
20
15
  // [function]
21
16
 
22
- const deployGit = function ({ pre, preId, root }, handler, cb) {
23
- listTags(root, (err, from) => {
17
+ const deployRelease = function (version, { root }, handler, cb) {
18
+ release(root, version, (err) => {
24
19
  if (err) {
25
20
  cb(err);
26
21
  return;
27
22
  }
28
- const to = incSemver(from, pre ? "prerelease" : "patch", preId);
29
- release(root, to, pre, (err) => {
30
- if (err) {
31
- cb(err);
32
- return;
33
- }
34
- cb(null, { from, to });
35
- });
23
+ cb(null, { to: version });
36
24
  });
37
25
  };
38
26
 
39
27
  // [function]
40
28
 
41
- const deploy = function ({ pre, preId, root }, { onInfo }, cb) {
29
+ const deployEnsure = function ({ root }, { onInfo }, cb) {
42
30
  ensureRepo(root, (err) => {
43
31
  if (err) {
44
32
  cb(err);
@@ -55,32 +43,41 @@ const deploy = function ({ pre, preId, root }, { onInfo }, cb) {
55
43
  message: "Staged but uncommitted changes will not be deployed.",
56
44
  });
57
45
  }
58
- ensureRemote(root, (err) => {
59
- if (err) {
60
- cb(err);
61
- return;
62
- }
63
- deployGit({ pre, preId, root }, { onInfo }, cb);
64
- });
46
+ ensureRemote(root, cb);
65
47
  });
66
48
  });
67
49
  };
68
50
 
69
51
  // [function]
70
52
 
71
- const main = function ({ pre, preId, root }, { onBegin, ...handler }) {
72
- onBegin({ root });
73
- return new Promise((resolve, reject) => {
74
- deploy({ pre, preId, root }, handler, (err, data) => {
75
- if (err) {
76
- reject(err);
77
- return;
78
- }
79
- resolve(data);
80
- });
53
+ const deploy = function (version, { root }, handler, cb) {
54
+ deployEnsure({ root }, handler, (err) => {
55
+ if (err) {
56
+ cb(err);
57
+ return;
58
+ }
59
+ deployRelease(version, { root }, handler, cb);
81
60
  });
82
61
  };
83
62
 
63
+ // [function]
64
+
65
+ const main = function ({ root }, { onBegin, ...handler }) {
66
+ onBegin({ root });
67
+ return project.parse(root).then(
68
+ ({ game }) =>
69
+ new Promise((resolve, reject) => {
70
+ deploy(game.version, { root }, handler, (err, data) => {
71
+ if (err) {
72
+ reject(err);
73
+ return;
74
+ }
75
+ resolve(data);
76
+ });
77
+ }),
78
+ );
79
+ };
80
+
84
81
  // [export]
85
82
 
86
83
  module.exports = main;
package/src/cli/deploy.js CHANGED
@@ -7,8 +7,8 @@ const deployTool = require("../action/deploy/tool");
7
7
 
8
8
  // [function]
9
9
 
10
- const main = function ({ direct, handler, ...conf }) {
11
- const tool = direct ? deployTool : deployGitTool;
10
+ const main = function ({ git, handler, ...conf }) {
11
+ const tool = git ? deployGitTool : deployTool;
12
12
  return tool(conf, handler);
13
13
  };
14
14
 
@@ -14,11 +14,11 @@ const objs = require("../util/objs");
14
14
 
15
15
  // [use]
16
16
 
17
+ const compactObjs = objs.compact;
17
18
  const extname = path.extname;
18
19
  const join = path.join;
19
20
  const pathExists = fs.pathExists;
20
21
  const pathParse = path.parse;
21
- const pruneEmpty = objs.pruneEmpty;
22
22
  const readdir = fs.promises.readdir;
23
23
 
24
24
  // [declare]
@@ -84,7 +84,7 @@ const parse = function (root) {
84
84
  Promise.resolve({})
85
85
  .then(art(root))
86
86
  .then(gallery(root))
87
- .then(pruneEmpty)
87
+ .then(compactObjs)
88
88
  .then((game) => ({ game }))
89
89
  .then(resolve)
90
90
  .catch(reject);
@@ -17,9 +17,9 @@ const strs = require("../util/strs");
17
17
 
18
18
  // [use]
19
19
 
20
+ const compactObjs = objs.compact;
20
21
  const join = path.join;
21
22
  const pathExists = fs.pathExists;
22
- const pruneEmpty = objs.pruneEmpty;
23
23
  const readFile = fs.readFile;
24
24
  const trimWhitespace = strs.trimWhitespace;
25
25
 
@@ -145,7 +145,7 @@ const parse = function (root) {
145
145
  return findReadme(root)
146
146
  .then((file) => (file ? readFile(join(root, file), "utf8") : null))
147
147
  .then((buf) => (buf === null ? null : parseReadme(buf)))
148
- .then(pruneEmpty)
148
+ .then(compactObjs)
149
149
  .then((game) => ({ game: game || null }));
150
150
  };
151
151
 
package/src/user.js CHANGED
@@ -11,6 +11,7 @@ const fs = require("fs-extra");
11
11
  // [import]
12
12
 
13
13
  const api = require("./api");
14
+ const objs = require("./util/objs");
14
15
  const os = require("./util/os");
15
16
 
16
17
  // [use]
@@ -19,6 +20,7 @@ const configDir = os.configDir;
19
20
  const join = path.join;
20
21
  const mkdir = fs.promises.mkdir;
21
22
  const readFile = fs.promises.readFile;
23
+ const sortObjs = objs.sort;
22
24
  const unlink = fs.promises.unlink;
23
25
  const writeFile = fs.promises.writeFile;
24
26
 
@@ -42,7 +44,9 @@ const expired = function (session) {
42
44
 
43
45
  const save = function (user) {
44
46
  return mkdir(dir, { recursive: true })
45
- .then(() => writeFile(file, JSON.stringify(user, null, 2), "utf8"))
47
+ .then(() =>
48
+ writeFile(file, JSON.stringify(sortObjs(user), null, 2), "utf8"),
49
+ )
46
50
  .then(() => user);
47
51
  };
48
52
 
package/src/util/objs.js CHANGED
@@ -6,19 +6,19 @@ const stringify = require("fast-json-stable-stringify");
6
6
 
7
7
  // [function]
8
8
 
9
- const pruneEmpty = function (value) {
9
+ const compact = function (value) {
10
10
  /* eslint-disable no-undefined */
11
11
  if (value === null || value === undefined) {
12
12
  return undefined;
13
13
  }
14
14
  if (Array.isArray(value)) {
15
- const cleaned = value.map(pruneEmpty).filter((v) => v !== undefined);
15
+ const cleaned = value.map(compact).filter((v) => v !== undefined);
16
16
  return cleaned.length ? cleaned : undefined;
17
17
  }
18
18
  if (typeof value === "object") {
19
19
  const cleaned = Object.fromEntries(
20
20
  Object.entries(value)
21
- .map(([k, v]) => [k, pruneEmpty(v)])
21
+ .map(([k, v]) => [k, compact(v)])
22
22
  .filter(([, v]) => v !== undefined),
23
23
  );
24
24
  return Object.keys(cleaned).length ? cleaned : undefined;
@@ -35,4 +35,4 @@ const sort = function (value) {
35
35
 
36
36
  // [export]
37
37
 
38
- module.exports = { pruneEmpty, sort };
38
+ module.exports = { compact, sort };
@@ -10,7 +10,7 @@ const objs = require("./objs");
10
10
 
11
11
  // [use]
12
12
 
13
- const sort = objs.sort;
13
+ const sortObjs = objs.sort;
14
14
 
15
15
  // [function]
16
16
 
@@ -21,7 +21,7 @@ const write = function (data) {
21
21
  // [function]
22
22
 
23
23
  const printJson = function (data) {
24
- write(JSON.stringify(sort(data), null, 2));
24
+ write(JSON.stringify(sortObjs(data), null, 2));
25
25
  };
26
26
 
27
27
  // [function]
@@ -33,7 +33,7 @@ const printToml = function (data, key = "value") {
33
33
  return;
34
34
  }
35
35
  try {
36
- write(TOML.stringify(sort(data)));
36
+ write(TOML.stringify(sortObjs(data)));
37
37
  } catch (ex) {
38
38
  write(TOML.stringify({ [field]: data }));
39
39
  }
@@ -11,7 +11,7 @@ const format = function (name, error) {
11
11
  // [function]
12
12
 
13
13
  const validator = function (name, schema) {
14
- return function (value, conf) {
14
+ return (value, conf) => {
15
15
  const result = schema(value, conf).safeParse(value);
16
16
  if (!result.success) {
17
17
  return { issues: format(name, result.error) };
package/src/util/zip.js CHANGED
@@ -9,10 +9,15 @@ const path = require("node:path");
9
9
 
10
10
  const AdmZip = require("adm-zip");
11
11
 
12
+ // [import]
13
+
14
+ const objs = require("./objs");
15
+
12
16
  // [use]
13
17
 
14
18
  const createHash = crypto.createHash;
15
19
  const join = path.join;
20
+ const sortObjs = objs.sort;
16
21
 
17
22
  // [class]
18
23
 
@@ -35,7 +40,10 @@ const Main = class {
35
40
 
36
41
  addJson(name, value) {
37
42
  const entry = join(this.prefix, name);
38
- const content = Buffer.from(JSON.stringify(value, null, 2), "utf8");
43
+ const content = Buffer.from(
44
+ JSON.stringify(sortObjs(value), null, 2),
45
+ "utf8",
46
+ );
39
47
  this.zip.addFile(entry, content);
40
48
  }
41
49