@nuucognition/flint-cli 0.1.0-beta.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/README.md +344 -0
- package/bin/flint-prod.js +7 -0
- package/bin/flint.js +19 -0
- package/dist/chunk-BVYUS7NX.js +386 -0
- package/dist/chunk-EICASOEX.js +1524 -0
- package/dist/chunk-F5Q2BJFK.js +233 -0
- package/dist/exports-Y3NVZFFT.js +14 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11118 -0
- package/dist/mesh-config-O3UKKKAO.js +112 -0
- package/dist/registry-FUIZ2SKS.js +30 -0
- package/package.json +39 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// ../../packages/flint/src/registry.ts
|
|
2
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
3
|
+
import { homedir } from "os";
|
|
4
|
+
import { join, resolve } from "path";
|
|
5
|
+
var REGISTRY_VERSION = 1;
|
|
6
|
+
function getGlobalFlintDir() {
|
|
7
|
+
return join(homedir(), ".flint");
|
|
8
|
+
}
|
|
9
|
+
function getFlintRegistryPath() {
|
|
10
|
+
return join(getGlobalFlintDir(), "registry.json");
|
|
11
|
+
}
|
|
12
|
+
async function ensureRegistryDir() {
|
|
13
|
+
await mkdir(getGlobalFlintDir(), { recursive: true });
|
|
14
|
+
}
|
|
15
|
+
function createEmptyRegistry() {
|
|
16
|
+
return {
|
|
17
|
+
version: REGISTRY_VERSION,
|
|
18
|
+
flints: []
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async function getFlintRegistry() {
|
|
22
|
+
try {
|
|
23
|
+
const content = await readFile(getFlintRegistryPath(), "utf-8");
|
|
24
|
+
const registry = JSON.parse(content);
|
|
25
|
+
return registry.flints;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error.code === "ENOENT") {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function saveRegistry(registry) {
|
|
34
|
+
await ensureRegistryDir();
|
|
35
|
+
await writeFile(getFlintRegistryPath(), JSON.stringify(registry, null, 2));
|
|
36
|
+
}
|
|
37
|
+
async function registerFlint(entry) {
|
|
38
|
+
const normalizedEntry = { ...entry, path: resolve(entry.path) };
|
|
39
|
+
const flints = await getFlintRegistry();
|
|
40
|
+
const existing = flints.find((f) => f.path === normalizedEntry.path);
|
|
41
|
+
if (existing) {
|
|
42
|
+
throw new Error(`Flint already registered at path: ${entry.path}`);
|
|
43
|
+
}
|
|
44
|
+
flints.push(normalizedEntry);
|
|
45
|
+
await saveRegistry({ version: REGISTRY_VERSION, flints });
|
|
46
|
+
}
|
|
47
|
+
async function unregisterFlint(path) {
|
|
48
|
+
const resolvedPath = resolve(path);
|
|
49
|
+
const flints = await getFlintRegistry();
|
|
50
|
+
const filtered = flints.filter((f) => f.path !== resolvedPath);
|
|
51
|
+
if (filtered.length === flints.length) {
|
|
52
|
+
throw new Error(`Flint not found at path: ${path}`);
|
|
53
|
+
}
|
|
54
|
+
await saveRegistry({ version: REGISTRY_VERSION, flints: filtered });
|
|
55
|
+
}
|
|
56
|
+
async function findFlintByPath(path) {
|
|
57
|
+
const resolvedPath = resolve(path);
|
|
58
|
+
const flints = await getFlintRegistry();
|
|
59
|
+
return flints.find((f) => f.path === resolvedPath) ?? null;
|
|
60
|
+
}
|
|
61
|
+
async function findFlintById(_id) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
async function findFlintByName(name) {
|
|
65
|
+
const flints = await getFlintRegistry();
|
|
66
|
+
return flints.find((f) => f.name === name) ?? null;
|
|
67
|
+
}
|
|
68
|
+
async function upsertFlintEntry(entry) {
|
|
69
|
+
const normalizedEntry = { ...entry, path: resolve(entry.path) };
|
|
70
|
+
const flints = await getFlintRegistry();
|
|
71
|
+
const indexByPath = flints.findIndex((f) => f.path === normalizedEntry.path);
|
|
72
|
+
if (indexByPath !== -1) {
|
|
73
|
+
flints[indexByPath] = normalizedEntry;
|
|
74
|
+
} else {
|
|
75
|
+
flints.push(normalizedEntry);
|
|
76
|
+
}
|
|
77
|
+
await saveRegistry({ version: REGISTRY_VERSION, flints });
|
|
78
|
+
}
|
|
79
|
+
async function updateFlintEntry(path, updates) {
|
|
80
|
+
const resolvedPath = resolve(path);
|
|
81
|
+
const flints = await getFlintRegistry();
|
|
82
|
+
const entry = flints.find((f) => f.path === resolvedPath);
|
|
83
|
+
if (!entry) {
|
|
84
|
+
throw new Error(`Flint not found at path: ${path}`);
|
|
85
|
+
}
|
|
86
|
+
Object.assign(entry, updates);
|
|
87
|
+
await saveRegistry({ version: REGISTRY_VERSION, flints });
|
|
88
|
+
}
|
|
89
|
+
async function isPathRegistered(path) {
|
|
90
|
+
const resolvedPath = resolve(path);
|
|
91
|
+
const flints = await getFlintRegistry();
|
|
92
|
+
return flints.some((f) => f.path === resolvedPath);
|
|
93
|
+
}
|
|
94
|
+
async function cleanRegistryFile() {
|
|
95
|
+
const result = {
|
|
96
|
+
entriesCleaned: 0,
|
|
97
|
+
invalidEntriesRemoved: 0,
|
|
98
|
+
modified: false,
|
|
99
|
+
details: []
|
|
100
|
+
};
|
|
101
|
+
let rawContent;
|
|
102
|
+
try {
|
|
103
|
+
rawContent = await readFile(getFlintRegistryPath(), "utf-8");
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (error.code === "ENOENT") {
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
let registry;
|
|
111
|
+
try {
|
|
112
|
+
registry = JSON.parse(rawContent);
|
|
113
|
+
} catch {
|
|
114
|
+
result.details.push("Registry file was corrupted, creating fresh registry");
|
|
115
|
+
result.modified = true;
|
|
116
|
+
await saveRegistry(createEmptyRegistry());
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
if (!registry || typeof registry !== "object") {
|
|
120
|
+
result.details.push("Registry file had invalid structure, creating fresh registry");
|
|
121
|
+
result.modified = true;
|
|
122
|
+
await saveRegistry(createEmptyRegistry());
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
if (!Array.isArray(registry.flints)) {
|
|
126
|
+
registry.flints = [];
|
|
127
|
+
result.details.push("Registry was missing flints array");
|
|
128
|
+
result.modified = true;
|
|
129
|
+
}
|
|
130
|
+
const cleanedFlints = [];
|
|
131
|
+
const deprecatedFields = ["id", "created"];
|
|
132
|
+
for (const rawEntry of registry.flints) {
|
|
133
|
+
if (!rawEntry || typeof rawEntry !== "object") {
|
|
134
|
+
result.invalidEntriesRemoved++;
|
|
135
|
+
result.details.push("Removed invalid non-object entry");
|
|
136
|
+
result.modified = true;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const entry = rawEntry;
|
|
140
|
+
if (typeof entry.name !== "string" || typeof entry.path !== "string") {
|
|
141
|
+
result.invalidEntriesRemoved++;
|
|
142
|
+
result.details.push(`Removed invalid entry missing name or path`);
|
|
143
|
+
result.modified = true;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
let hadDeprecatedFields = false;
|
|
147
|
+
for (const field of deprecatedFields) {
|
|
148
|
+
if (field in entry) {
|
|
149
|
+
delete entry[field];
|
|
150
|
+
hadDeprecatedFields = true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (hadDeprecatedFields) {
|
|
154
|
+
result.entriesCleaned++;
|
|
155
|
+
result.modified = true;
|
|
156
|
+
}
|
|
157
|
+
const cleanEntry = {
|
|
158
|
+
name: entry.name,
|
|
159
|
+
path: entry.path
|
|
160
|
+
};
|
|
161
|
+
if (entry.type === "flint" || entry.type === "subflint") {
|
|
162
|
+
cleanEntry.type = entry.type;
|
|
163
|
+
}
|
|
164
|
+
if (entry.source === "local") {
|
|
165
|
+
cleanEntry.source = entry.source;
|
|
166
|
+
}
|
|
167
|
+
if (Array.isArray(entry.tags)) {
|
|
168
|
+
cleanEntry.tags = entry.tags.filter((t) => typeof t === "string");
|
|
169
|
+
}
|
|
170
|
+
if (typeof entry.description === "string") {
|
|
171
|
+
cleanEntry.description = entry.description;
|
|
172
|
+
}
|
|
173
|
+
if (Array.isArray(entry.exports)) {
|
|
174
|
+
cleanEntry.exports = entry.exports.filter((e) => typeof e === "string");
|
|
175
|
+
}
|
|
176
|
+
cleanedFlints.push(cleanEntry);
|
|
177
|
+
}
|
|
178
|
+
if (result.modified) {
|
|
179
|
+
await saveRegistry({ version: REGISTRY_VERSION, flints: cleanedFlints });
|
|
180
|
+
if (result.entriesCleaned > 0) {
|
|
181
|
+
result.details.push(`Removed deprecated fields from ${result.entriesCleaned} entries`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
async function registerFlintByPath(path, options) {
|
|
187
|
+
const { readFlintToml, hasFlintToml } = await import("./mesh-config-O3UKKKAO.js");
|
|
188
|
+
const isFlint = await hasFlintToml(path);
|
|
189
|
+
if (!isFlint) {
|
|
190
|
+
throw new Error(`Not a valid flint: ${path}
|
|
191
|
+
Missing flint.toml`);
|
|
192
|
+
}
|
|
193
|
+
const toml = await readFlintToml(path);
|
|
194
|
+
if (!toml || !toml.flint?.name) {
|
|
195
|
+
throw new Error(`Invalid flint.toml at ${path}: missing flint.name`);
|
|
196
|
+
}
|
|
197
|
+
const name = toml.flint.name;
|
|
198
|
+
const type = toml.flint.type ?? "flint";
|
|
199
|
+
const existing = await findFlintByPath(path);
|
|
200
|
+
if (existing && !options?.force) {
|
|
201
|
+
throw new Error(`Already registered: "${existing.name}" at ${path}`);
|
|
202
|
+
}
|
|
203
|
+
const entry = {
|
|
204
|
+
name,
|
|
205
|
+
path,
|
|
206
|
+
type,
|
|
207
|
+
source: "local"
|
|
208
|
+
};
|
|
209
|
+
if (toml.flint.tags && toml.flint.tags.length > 0) {
|
|
210
|
+
entry.tags = toml.flint.tags;
|
|
211
|
+
}
|
|
212
|
+
if (toml.flint.description) {
|
|
213
|
+
entry.description = toml.flint.description;
|
|
214
|
+
}
|
|
215
|
+
await upsertFlintEntry(entry);
|
|
216
|
+
return entry;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export {
|
|
220
|
+
getGlobalFlintDir,
|
|
221
|
+
getFlintRegistryPath,
|
|
222
|
+
getFlintRegistry,
|
|
223
|
+
registerFlint,
|
|
224
|
+
unregisterFlint,
|
|
225
|
+
findFlintByPath,
|
|
226
|
+
findFlintById,
|
|
227
|
+
findFlintByName,
|
|
228
|
+
upsertFlintEntry,
|
|
229
|
+
updateFlintEntry,
|
|
230
|
+
isPathRegistered,
|
|
231
|
+
cleanRegistryFile,
|
|
232
|
+
registerFlintByPath
|
|
233
|
+
};
|
package/dist/index.d.ts
ADDED