@nuucognition/flint-cli 0.2.0-beta.1 → 0.3.0-alpha.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 +0 -1
- package/bin/flint-prod.js +2 -0
- package/dist/chunk-2Q7QG2UK.js +374 -0
- package/dist/{chunk-5YLBX2W6.js → chunk-KLFK7CPM.js} +104 -146
- package/dist/chunk-KVE7WLA2.js +297 -0
- package/dist/{chunk-VO4ZYDCW.js → chunk-ODSWKVNZ.js} +16 -48
- package/dist/{chunk-UNMULXL5.js → chunk-OIXBMYAA.js} +7 -11
- package/dist/chunk-T7VT4BN3.js +303 -0
- package/dist/chunk-V7YA5RXL.js +43 -0
- package/dist/connections-AXGFYQOK-A6BXCAC7.js +43 -0
- package/dist/{exports-CA5QHVI7-6IDFKMCF.js → exports-B5CYVV5M-KF36KYYW.js} +1 -1
- package/dist/index.js +4729 -6571
- package/dist/{mesh-config-VGFSHC2G-YCC4ZIAT.js → mesh-config-7GOTOVCM-TZEJ43E5.js} +15 -21
- package/dist/presets/blank/preset.toml +1 -1
- package/dist/presets/default/preset.toml +1 -7
- package/dist/{registry-5QFQ3XPR-G7IB3KWS.js → registry-QJIY5NBV-UDZW4AUU.js} +3 -3
- package/dist/utils-BBA2XQZO-YU5SL3JY.js +8 -0
- package/dist/workspace-local-LKB4MTN2-OY5UVN3K.js +70 -0
- package/package.json +6 -5
package/README.md
CHANGED
package/bin/flint-prod.js
CHANGED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateReferenceMetadata,
|
|
3
|
+
getFlintConfigDir,
|
|
4
|
+
getReferenceMetadataPath,
|
|
5
|
+
getReferencesMetadataDir
|
|
6
|
+
} from "./chunk-KVE7WLA2.js";
|
|
7
|
+
import {
|
|
8
|
+
getWorkspaceReferences,
|
|
9
|
+
getWorkspaceRepositories,
|
|
10
|
+
getWorkspaceSourceRepositories,
|
|
11
|
+
parse
|
|
12
|
+
} from "./chunk-KLFK7CPM.js";
|
|
13
|
+
|
|
14
|
+
// ../../packages/flint/dist/chunk-K24H5FBA.js
|
|
15
|
+
import { readFile, writeFile, mkdir, stat, unlink, access } from "fs/promises";
|
|
16
|
+
import { join } from "path";
|
|
17
|
+
import { exec } from "child_process";
|
|
18
|
+
import { promisify } from "util";
|
|
19
|
+
import { rm } from "fs/promises";
|
|
20
|
+
var execAsync = promisify(exec);
|
|
21
|
+
var LEGACY_WORKSPACE_CONFIG_FILENAME = "workspace.toml";
|
|
22
|
+
function getWorkspaceReferencesDir(flintPath) {
|
|
23
|
+
return getReferencesMetadataDir(flintPath);
|
|
24
|
+
}
|
|
25
|
+
function toKebabCase(name) {
|
|
26
|
+
return name.toLowerCase().replace(/\s+/g, "-");
|
|
27
|
+
}
|
|
28
|
+
function getWorkspaceReferenceFilePath(flintPath, name) {
|
|
29
|
+
return getReferenceMetadataPath(flintPath, name);
|
|
30
|
+
}
|
|
31
|
+
function getLegacyWorkspaceConfigPath(flintPath) {
|
|
32
|
+
return join(getFlintConfigDir(flintPath), LEGACY_WORKSPACE_CONFIG_FILENAME);
|
|
33
|
+
}
|
|
34
|
+
function getLegacyWorkspaceDir(flintPath) {
|
|
35
|
+
return join(flintPath, "Workspace");
|
|
36
|
+
}
|
|
37
|
+
function getReferencesStatePath(flintPath) {
|
|
38
|
+
return join(getFlintConfigDir(flintPath), "references.json");
|
|
39
|
+
}
|
|
40
|
+
async function readReferencesState(flintPath) {
|
|
41
|
+
try {
|
|
42
|
+
const content = await readFile(getReferencesStatePath(flintPath), "utf-8");
|
|
43
|
+
return JSON.parse(content);
|
|
44
|
+
} catch {
|
|
45
|
+
return { version: 1, references: [] };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function writeReferencesState(flintPath, state) {
|
|
49
|
+
const statePath = getReferencesStatePath(flintPath);
|
|
50
|
+
await mkdir(getFlintConfigDir(flintPath), { recursive: true });
|
|
51
|
+
await writeFile(statePath, JSON.stringify(state, null, 2));
|
|
52
|
+
}
|
|
53
|
+
async function updateReferenceState(flintPath, name, type, path) {
|
|
54
|
+
const state = await readReferencesState(flintPath);
|
|
55
|
+
const fulfillment = {
|
|
56
|
+
name,
|
|
57
|
+
type,
|
|
58
|
+
path,
|
|
59
|
+
fulfilled: (/* @__PURE__ */ new Date()).toISOString()
|
|
60
|
+
};
|
|
61
|
+
const existingIndex = state.references.findIndex(
|
|
62
|
+
(r) => r.name.toLowerCase() === name.toLowerCase()
|
|
63
|
+
);
|
|
64
|
+
if (existingIndex >= 0) {
|
|
65
|
+
state.references[existingIndex] = fulfillment;
|
|
66
|
+
} else {
|
|
67
|
+
state.references.push(fulfillment);
|
|
68
|
+
}
|
|
69
|
+
await writeReferencesState(flintPath, state);
|
|
70
|
+
}
|
|
71
|
+
async function removeReferenceState(flintPath, name) {
|
|
72
|
+
const state = await readReferencesState(flintPath);
|
|
73
|
+
const normalizedName = name.toLowerCase();
|
|
74
|
+
const index = state.references.findIndex(
|
|
75
|
+
(r) => r.name.toLowerCase() === normalizedName
|
|
76
|
+
);
|
|
77
|
+
if (index >= 0) {
|
|
78
|
+
state.references.splice(index, 1);
|
|
79
|
+
await writeReferencesState(flintPath, state);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
async function pathExists(path) {
|
|
85
|
+
try {
|
|
86
|
+
await stat(path);
|
|
87
|
+
return true;
|
|
88
|
+
} catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function readReferencePath(flintPath, name) {
|
|
93
|
+
const state = await readReferencesState(flintPath);
|
|
94
|
+
const normalizedName = name.toLowerCase();
|
|
95
|
+
const fulfillment = state.references.find(
|
|
96
|
+
(r) => r.name.toLowerCase() === normalizedName
|
|
97
|
+
);
|
|
98
|
+
return fulfillment?.path || null;
|
|
99
|
+
}
|
|
100
|
+
async function writeReferenceFile(flintPath, name, targetPath, type = "codebase") {
|
|
101
|
+
await generateReferenceMetadata(flintPath, { name, type });
|
|
102
|
+
await updateReferenceState(flintPath, name, type, targetPath);
|
|
103
|
+
return getWorkspaceReferenceFilePath(flintPath, name);
|
|
104
|
+
}
|
|
105
|
+
async function deleteReferenceFile(flintPath, name) {
|
|
106
|
+
const filePath = getWorkspaceReferenceFilePath(flintPath, name);
|
|
107
|
+
try {
|
|
108
|
+
await unlink(filePath);
|
|
109
|
+
return true;
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (error.code === "ENOENT") {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function getWorkspaceStatus(flintPath) {
|
|
118
|
+
const declarations = await getWorkspaceReferences(flintPath);
|
|
119
|
+
const statuses = [];
|
|
120
|
+
for (const ref of declarations) {
|
|
121
|
+
const referencePath = await readReferencePath(flintPath, ref.name);
|
|
122
|
+
if (!referencePath) {
|
|
123
|
+
statuses.push({
|
|
124
|
+
name: ref.name,
|
|
125
|
+
type: ref.type,
|
|
126
|
+
status: "unfulfilled"
|
|
127
|
+
});
|
|
128
|
+
} else if (await pathExists(referencePath)) {
|
|
129
|
+
statuses.push({
|
|
130
|
+
name: ref.name,
|
|
131
|
+
type: ref.type,
|
|
132
|
+
status: "fulfilled",
|
|
133
|
+
path: referencePath
|
|
134
|
+
});
|
|
135
|
+
} else {
|
|
136
|
+
statuses.push({
|
|
137
|
+
name: ref.name,
|
|
138
|
+
type: ref.type,
|
|
139
|
+
status: "missing",
|
|
140
|
+
path: referencePath
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return statuses;
|
|
145
|
+
}
|
|
146
|
+
async function getUnfulfilledWorkspaces(flintPath) {
|
|
147
|
+
const statuses = await getWorkspaceStatus(flintPath);
|
|
148
|
+
return statuses.filter((s) => s.status === "unfulfilled").map((s) => s.name);
|
|
149
|
+
}
|
|
150
|
+
async function setWorkspacePath(flintPath, name, path) {
|
|
151
|
+
const declarations = await getWorkspaceReferences(flintPath);
|
|
152
|
+
const ref = declarations.find((r) => r.name.toLowerCase() === name.toLowerCase());
|
|
153
|
+
const type = ref?.type || "codebase";
|
|
154
|
+
await writeReferenceFile(flintPath, name, path, type);
|
|
155
|
+
}
|
|
156
|
+
async function removeWorkspacePath(flintPath, name) {
|
|
157
|
+
await removeReferenceState(flintPath, name);
|
|
158
|
+
return deleteReferenceFile(flintPath, name);
|
|
159
|
+
}
|
|
160
|
+
async function getWorkspacePath(flintPath, name) {
|
|
161
|
+
return readReferencePath(flintPath, name);
|
|
162
|
+
}
|
|
163
|
+
function getWorkspaceRepositoriesDir(flintPath) {
|
|
164
|
+
return join(flintPath, "Workspace", "Repositories");
|
|
165
|
+
}
|
|
166
|
+
function getRepositoryPath(flintPath, name) {
|
|
167
|
+
const kebabName = toKebabCase(name);
|
|
168
|
+
return join(getWorkspaceRepositoriesDir(flintPath), kebabName);
|
|
169
|
+
}
|
|
170
|
+
async function createRepository(flintPath, name, url) {
|
|
171
|
+
const repositoriesDir = getWorkspaceRepositoriesDir(flintPath);
|
|
172
|
+
await mkdir(repositoriesDir, { recursive: true });
|
|
173
|
+
const repoPath = getRepositoryPath(flintPath, name);
|
|
174
|
+
if (await pathExists(repoPath)) {
|
|
175
|
+
throw new Error(`Repository folder already exists: ${repoPath}`);
|
|
176
|
+
}
|
|
177
|
+
await mkdir(repoPath, { recursive: true });
|
|
178
|
+
try {
|
|
179
|
+
await execAsync("git init", { cwd: repoPath });
|
|
180
|
+
await execAsync(`git remote add origin "${url}"`, { cwd: repoPath });
|
|
181
|
+
} catch (error) {
|
|
182
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
183
|
+
await rm(repoPath, { recursive: true, force: true });
|
|
184
|
+
throw new Error(`Failed to initialize repository: ${message}`);
|
|
185
|
+
}
|
|
186
|
+
return repoPath;
|
|
187
|
+
}
|
|
188
|
+
async function cloneRepository(flintPath, name, url) {
|
|
189
|
+
const repositoriesDir = getWorkspaceRepositoriesDir(flintPath);
|
|
190
|
+
await mkdir(repositoriesDir, { recursive: true });
|
|
191
|
+
const repoPath = getRepositoryPath(flintPath, name);
|
|
192
|
+
if (await pathExists(repoPath)) {
|
|
193
|
+
throw new Error(`Repository folder already exists: ${repoPath}`);
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
await execAsync(`git clone "${url}" "${repoPath}"`);
|
|
197
|
+
} catch (error) {
|
|
198
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
199
|
+
throw new Error(`Failed to clone repository: ${message}`);
|
|
200
|
+
}
|
|
201
|
+
return repoPath;
|
|
202
|
+
}
|
|
203
|
+
async function removeRepositoryFolder(flintPath, name) {
|
|
204
|
+
const repoPath = getRepositoryPath(flintPath, name);
|
|
205
|
+
if (!await pathExists(repoPath)) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
await rm(repoPath, { recursive: true, force: true });
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
async function updateRepository(flintPath, name, url) {
|
|
212
|
+
const repoPath = getRepositoryPath(flintPath, name);
|
|
213
|
+
if (await pathExists(repoPath)) {
|
|
214
|
+
await execAsync("git pull", { cwd: repoPath });
|
|
215
|
+
return repoPath;
|
|
216
|
+
}
|
|
217
|
+
return cloneRepository(flintPath, name, url);
|
|
218
|
+
}
|
|
219
|
+
async function freshCloneRepository(flintPath, name, url) {
|
|
220
|
+
await removeRepositoryFolder(flintPath, name);
|
|
221
|
+
return cloneRepository(flintPath, name, url);
|
|
222
|
+
}
|
|
223
|
+
async function getRepositoryStatus(flintPath) {
|
|
224
|
+
const declarations = await getWorkspaceRepositories(flintPath);
|
|
225
|
+
const statuses = [];
|
|
226
|
+
for (const repo of declarations) {
|
|
227
|
+
const repoPath = getRepositoryPath(flintPath, repo.name);
|
|
228
|
+
const exists = await pathExists(repoPath);
|
|
229
|
+
statuses.push({
|
|
230
|
+
name: repo.name,
|
|
231
|
+
url: repo.url,
|
|
232
|
+
status: exists ? "cloned" : "missing",
|
|
233
|
+
path: repoPath
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
return statuses;
|
|
237
|
+
}
|
|
238
|
+
function getWorkspaceSourceRepositoriesDir(flintPath) {
|
|
239
|
+
return join(flintPath, "Sources", "Repos");
|
|
240
|
+
}
|
|
241
|
+
function getSourceRepositoryPath(flintPath, name) {
|
|
242
|
+
const kebabName = toKebabCase(name);
|
|
243
|
+
return join(getWorkspaceSourceRepositoriesDir(flintPath), kebabName);
|
|
244
|
+
}
|
|
245
|
+
async function cloneSourceRepository(flintPath, name, url) {
|
|
246
|
+
const repositoriesDir = getWorkspaceSourceRepositoriesDir(flintPath);
|
|
247
|
+
await mkdir(repositoriesDir, { recursive: true });
|
|
248
|
+
const repoPath = getSourceRepositoryPath(flintPath, name);
|
|
249
|
+
if (await pathExists(repoPath)) {
|
|
250
|
+
throw new Error(`Source repository folder already exists: ${repoPath}`);
|
|
251
|
+
}
|
|
252
|
+
try {
|
|
253
|
+
await execAsync(`git clone --depth 1 "${url}" "${repoPath}"`);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
256
|
+
throw new Error(`Failed to clone source repository: ${message}`);
|
|
257
|
+
}
|
|
258
|
+
const gitDir = join(repoPath, ".git");
|
|
259
|
+
try {
|
|
260
|
+
await rm(gitDir, { recursive: true, force: true });
|
|
261
|
+
} catch {
|
|
262
|
+
}
|
|
263
|
+
return repoPath;
|
|
264
|
+
}
|
|
265
|
+
async function removeSourceRepositoryFolder(flintPath, name) {
|
|
266
|
+
const repoPath = getSourceRepositoryPath(flintPath, name);
|
|
267
|
+
if (!await pathExists(repoPath)) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
await rm(repoPath, { recursive: true, force: true });
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
async function updateSourceRepository(flintPath, name, url) {
|
|
274
|
+
await removeSourceRepositoryFolder(flintPath, name);
|
|
275
|
+
return cloneSourceRepository(flintPath, name, url);
|
|
276
|
+
}
|
|
277
|
+
async function getSourceRepositoryStatus(flintPath) {
|
|
278
|
+
const declarations = await getWorkspaceSourceRepositories(flintPath);
|
|
279
|
+
const statuses = [];
|
|
280
|
+
for (const repo of declarations) {
|
|
281
|
+
const repoPath = getSourceRepositoryPath(flintPath, repo.name);
|
|
282
|
+
const exists = await pathExists(repoPath);
|
|
283
|
+
statuses.push({
|
|
284
|
+
name: repo.name,
|
|
285
|
+
url: repo.url,
|
|
286
|
+
status: exists ? "cloned" : "missing",
|
|
287
|
+
path: repoPath
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
return statuses;
|
|
291
|
+
}
|
|
292
|
+
async function readLegacyWorkspaceConfig(flintPath) {
|
|
293
|
+
const configPath = getLegacyWorkspaceConfigPath(flintPath);
|
|
294
|
+
try {
|
|
295
|
+
const content = await readFile(configPath, "utf-8");
|
|
296
|
+
return parse(content);
|
|
297
|
+
} catch (error) {
|
|
298
|
+
if (error.code === "ENOENT") {
|
|
299
|
+
return {};
|
|
300
|
+
}
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
async function legacyWorkspaceConfigExists(flintPath) {
|
|
305
|
+
try {
|
|
306
|
+
await access(getLegacyWorkspaceConfigPath(flintPath));
|
|
307
|
+
return true;
|
|
308
|
+
} catch {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
async function migrateWorkspaceConfig(flintPath) {
|
|
313
|
+
const result = { migrated: [], removed: false };
|
|
314
|
+
if (!await legacyWorkspaceConfigExists(flintPath)) {
|
|
315
|
+
return result;
|
|
316
|
+
}
|
|
317
|
+
const legacyConfig = await readLegacyWorkspaceConfig(flintPath);
|
|
318
|
+
if (Object.keys(legacyConfig).length === 0) {
|
|
319
|
+
try {
|
|
320
|
+
await unlink(getLegacyWorkspaceConfigPath(flintPath));
|
|
321
|
+
result.removed = true;
|
|
322
|
+
} catch {
|
|
323
|
+
}
|
|
324
|
+
return result;
|
|
325
|
+
}
|
|
326
|
+
for (const [name, entry] of Object.entries(legacyConfig)) {
|
|
327
|
+
if (entry && typeof entry === "object" && "path" in entry) {
|
|
328
|
+
await generateReferenceMetadata(flintPath, { name, type: "codebase" });
|
|
329
|
+
await updateReferenceState(flintPath, name, "codebase", entry.path);
|
|
330
|
+
result.migrated.push(name);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
try {
|
|
334
|
+
await unlink(getLegacyWorkspaceConfigPath(flintPath));
|
|
335
|
+
result.removed = true;
|
|
336
|
+
} catch {
|
|
337
|
+
}
|
|
338
|
+
return result;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export {
|
|
342
|
+
getWorkspaceReferencesDir,
|
|
343
|
+
getWorkspaceReferenceFilePath,
|
|
344
|
+
getLegacyWorkspaceConfigPath,
|
|
345
|
+
getLegacyWorkspaceDir,
|
|
346
|
+
getReferencesStatePath,
|
|
347
|
+
readReferencesState,
|
|
348
|
+
writeReferencesState,
|
|
349
|
+
updateReferenceState,
|
|
350
|
+
removeReferenceState,
|
|
351
|
+
readReferencePath,
|
|
352
|
+
writeReferenceFile,
|
|
353
|
+
deleteReferenceFile,
|
|
354
|
+
getWorkspaceStatus,
|
|
355
|
+
getUnfulfilledWorkspaces,
|
|
356
|
+
setWorkspacePath,
|
|
357
|
+
removeWorkspacePath,
|
|
358
|
+
getWorkspacePath,
|
|
359
|
+
getWorkspaceRepositoriesDir,
|
|
360
|
+
getRepositoryPath,
|
|
361
|
+
createRepository,
|
|
362
|
+
cloneRepository,
|
|
363
|
+
removeRepositoryFolder,
|
|
364
|
+
updateRepository,
|
|
365
|
+
freshCloneRepository,
|
|
366
|
+
getRepositoryStatus,
|
|
367
|
+
getWorkspaceSourceRepositoriesDir,
|
|
368
|
+
getSourceRepositoryPath,
|
|
369
|
+
cloneSourceRepository,
|
|
370
|
+
removeSourceRepositoryFolder,
|
|
371
|
+
updateSourceRepository,
|
|
372
|
+
getSourceRepositoryStatus,
|
|
373
|
+
migrateWorkspaceConfig
|
|
374
|
+
};
|