repo-util 1.23.0 → 1.24.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repo-util",
3
- "version": "1.23.0",
3
+ "version": "1.24.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -24,7 +24,7 @@
24
24
  "aggregation-repository-provider": "^5.2.36",
25
25
  "bitbucket-repository-provider": "^4.2.10",
26
26
  "commander": "^9.3.0",
27
- "etag-cache-leveldb": "^1.2.0",
27
+ "etag-cache-leveldb": "^1.2.1",
28
28
  "gitea-repository-provider": "^2.2.11",
29
29
  "github-repository-provider": "^7.30.12",
30
30
  "leveldown": "^6.1.1",
@@ -38,7 +38,7 @@
38
38
  "semantic-release": "^19.0.3"
39
39
  },
40
40
  "engines": {
41
- "node": ">=16.15.1"
41
+ "node": ">=18.3.0"
42
42
  },
43
43
  "repository": {
44
44
  "type": "git",
@@ -1,10 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { readFileSync } from "node:fs";
4
3
  import { mkdir } from "node:fs/promises";
5
4
  import { join } from "node:path";
6
5
  import { homedir } from "node:os";
7
- import { fileURLToPath } from "node:url";
8
6
  import { program } from "commander";
9
7
  import levelup from "levelup";
10
8
  import leveldown from "leveldown";
@@ -22,21 +20,16 @@ import {
22
20
  } from "repository-provider";
23
21
  import AggregationProvider from "aggregation-repository-provider";
24
22
  import { ETagCacheLevelDB } from "etag-cache-leveldb";
23
+ import pkg from "../package.json" assert { type: "json" };
25
24
 
26
25
  process.on("uncaughtException", console.error);
27
26
  process.on("unhandledRejection", console.error);
28
27
 
29
- const { version, description } = JSON.parse(
30
- readFileSync(fileURLToPath(new URL("../package.json", import.meta.url)), {
31
- encoding: "utf8"
32
- })
33
- );
34
-
35
28
  const properties = {};
36
29
 
37
30
  program
38
- .description(description)
39
- .version(version)
31
+ .description(pkg.description)
32
+ .version(pkg.version)
40
33
  .option("-D --define <a=b>", "define property", str =>
41
34
  Object.assign(properties, Object.fromEntries([str.split(/=/)]))
42
35
  );
@@ -91,7 +84,8 @@ for (const o of [
91
84
  .option("--no-cache", "cache requests")
92
85
  .option("--statistics", "cache statistics")
93
86
  .option("--json", "output as json")
94
- .option("--no-identifier", "do not output identifier, show attributes only")
87
+ .option("--no-identifier", "do not output identifier, show attribute values only")
88
+ .option("--no-undefined", "do not output undefined attribute values")
95
89
  .option("-a, --attribute <attributes>", "list attribute", a =>
96
90
  a.split(",")
97
91
  );
@@ -136,6 +130,37 @@ function normalize(names) {
136
130
  return names.length === 0 ? ["*"] : names;
137
131
  }
138
132
 
133
+ function listAttributes(object, attributes, options) {
134
+ const values = {};
135
+ let maxKeyLength = 0;
136
+
137
+ for (const a of attributes) {
138
+ let value = object[a];
139
+ if (Array.isArray(value)) {
140
+ value = value.join(" ");
141
+ } else if (value instanceof Set) {
142
+ value = [...value].join(" ");
143
+ } else if (value === undefined) {
144
+ if(options["undefined"])
145
+ value = "";
146
+ }
147
+
148
+ if (a.length > maxKeyLength) {
149
+ maxKeyLength = a.length;
150
+ }
151
+
152
+ values[a] = value;
153
+ }
154
+
155
+ for (const [k, v] of Object.entries(values)) {
156
+ if (options.identifier) {
157
+ console.log(" ".repeat(maxKeyLength - k.length + 2) + k + `: ${v}`);
158
+ } else {
159
+ console.log(v);
160
+ }
161
+ }
162
+ }
163
+
139
164
  async function list(provider, names, options, slot, attributes, actions) {
140
165
  const json = [];
141
166
 
@@ -151,27 +176,10 @@ async function list(provider, names, options, slot, attributes, actions) {
151
176
  if (options.json) {
152
177
  json.push(object);
153
178
  } else {
154
- for (const a of attributes) {
155
- let value = object[a];
156
- if (Array.isArray(value)) {
157
- value = value.join(" ");
158
- } else if (value instanceof Set) {
159
- value = [...value].join(" ");
160
- } else if (value === undefined) {
161
- value = "";
162
- }
163
-
164
- if (options.identifier === false) {
165
- console.log(value);
166
- } else {
167
- console.log(
168
- attributes.indexOf(a) === 0
169
- ? object.fullName + ":"
170
- : " ".substring(a.length) + a + ":",
171
- value
172
- );
173
- }
179
+ if (options.identifier) {
180
+ console.log(`${object.fullName}:`);
174
181
  }
182
+ listAttributes(object, attributes, options);
175
183
  }
176
184
  }
177
185