@decantr/cli 1.0.0-beta.3 → 1.0.0-beta.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/dist/index.js +32 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -58,8 +58,20 @@ async function cmdGet(type, id) {
|
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
const resolver = getResolver();
|
|
61
|
-
|
|
61
|
+
let result = await resolver.resolve(type, id);
|
|
62
62
|
if (!result) {
|
|
63
|
+
const apiType = type === "blueprint" ? "blueprints" : `${type}s`;
|
|
64
|
+
try {
|
|
65
|
+
const res = await fetch(`https://decantr-registry.fly.dev/v1/${apiType}/${id}`);
|
|
66
|
+
if (res.ok) {
|
|
67
|
+
const item = await res.json();
|
|
68
|
+
if (!item.error) {
|
|
69
|
+
console.log(JSON.stringify(item, null, 2));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
63
75
|
console.error(error(`${type} "${id}" not found.`));
|
|
64
76
|
process.exitCode = 1;
|
|
65
77
|
return;
|
|
@@ -117,25 +129,33 @@ async function cmdList(type) {
|
|
|
117
129
|
}
|
|
118
130
|
const { readdirSync } = await import("fs");
|
|
119
131
|
const dir = join(getContentRoot(), type);
|
|
132
|
+
let found = false;
|
|
120
133
|
try {
|
|
121
134
|
const files = readdirSync(dir).filter((f) => f.endsWith(".json"));
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
135
|
+
if (files.length > 0) {
|
|
136
|
+
found = true;
|
|
137
|
+
console.log(heading(`${files.length} ${type}`));
|
|
138
|
+
for (const f of files) {
|
|
139
|
+
const data = JSON.parse(readFileSync(join(dir, f), "utf-8"));
|
|
140
|
+
console.log(` ${cyan(data.id || f.replace(".json", ""))} ${dim(data.description || data.name || "")}`);
|
|
141
|
+
}
|
|
126
142
|
}
|
|
127
143
|
} catch {
|
|
128
|
-
|
|
144
|
+
}
|
|
145
|
+
if (!found) {
|
|
129
146
|
try {
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
147
|
+
const res = await fetch(`https://decantr-registry.fly.dev/v1/${type}`);
|
|
148
|
+
if (res.ok) {
|
|
149
|
+
const data = await res.json();
|
|
150
|
+
console.log(heading(`${data.total} ${type}`));
|
|
151
|
+
for (const item of data.items) {
|
|
152
|
+
console.log(` ${cyan(item.id)} ${dim(item.description || item.name || "")}`);
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
135
155
|
}
|
|
136
156
|
} catch {
|
|
137
|
-
console.log(dim(`No ${type} found.`));
|
|
138
157
|
}
|
|
158
|
+
console.log(dim(`No ${type} found.`));
|
|
139
159
|
}
|
|
140
160
|
}
|
|
141
161
|
function cmdHelp() {
|
package/package.json
CHANGED