@xrystal/core 3.55.8 → 3.55.10
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 +1 -1
- package/x/bin/commands/project-info.mjs +13 -0
- package/x/bin/commands/projects.mjs +56 -11
- package/x/bin/commands/sync.mjs +21 -7
- package/x/bin/commands/watch.mjs +2 -2
- package/x/bin/helpers/.generated/.generated-from +1 -1
- package/x/bin/helpers/.generated/tmp-schema.mjs +42 -9
- package/x/bin/helpers/.generated/{xrystal-home-registry.mjs → user-home-registry.mjs} +150 -43
- package/x/bin/helpers/.generated/workspace.mjs +338 -50
- package/x/bin/helpers/cli-enums.mjs +1 -0
- package/x/bin/helpers/cli-i18n.mjs +14 -0
- package/x/bin/helpers/create-target.mjs +5 -1
- package/x/bin/helpers/project-artifacts.mjs +2 -2
- package/x/bin/helpers/project-context.mjs +16 -4
- package/x/bin/helpers/registry-display.mjs +30 -0
- package/x/bin/helpers/workspace-heal.mjs +21 -5
- package/x/bin/helpers/workspace-resolve.mjs +8 -0
- package/x/bin/helpers/workspace-tmp.mjs +17 -7
- package/x/bin/helpers/xrystal-config.mjs +4 -4
- package/x/bin/helpers/xrystal-registry.mjs +4 -4
- package/x/bin/helpers/xrystal-watch-daemon.mjs +3 -3
- package/x/bin/helpers/xrystal-watch-service.mjs +2 -2
- package/x/bin/helpers/xrystal-watch-spawn.mjs +3 -3
- package/x/dist/utils/helpers/tmp/index.d.ts +1 -1
- package/x/dist/utils/helpers/tmp/index.js +1 -1
- package/x/dist/utils/helpers/tmp/loader-boot-plan.js +7 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +2 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +43 -9
- package/x/dist/utils/helpers/{xrystal-home → user-home}/registry.d.ts +11 -10
- package/x/dist/utils/helpers/{xrystal-home → user-home}/registry.js +11 -10
- package/x/dist/utils/helpers/workspace/index.d.ts +48 -2
- package/x/dist/utils/helpers/workspace/index.js +365 -48
- package/x/dist/utils/models/enums/index.d.ts +4 -2
- package/x/dist/utils/models/enums/index.js +3 -1
- package/x/tmp.yml +2 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import yaml from 'yaml';
|
|
3
4
|
import { GlobalTypeEnum, WorkspaceSlotEnum } from '../../../utils/models/enums/index.js';
|
|
4
5
|
import { packageDefaults } from '../../../utils/constants/index.js';
|
|
5
6
|
import { normalizeGlobalType } from '../../../utils/helpers/tmp/tmp-schema.js';
|
|
@@ -43,9 +44,12 @@ export function readTmpFile(filePath) {
|
|
|
43
44
|
return out;
|
|
44
45
|
}
|
|
45
46
|
export function parseFolderStructure(text) {
|
|
46
|
-
|
|
47
|
+
// Canonical key: configs.slots — legacy alias: configs.folder-structure
|
|
48
|
+
const fsBlock = text.match(/(?:^|\n)[ \t]*slots:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1]
|
|
49
|
+
?? text.match(/(?:^|\n)[ \t]*folder-structure:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1]
|
|
50
|
+
?? '';
|
|
47
51
|
if (/^[ \t]+admin:/m.test(fsBlock)) {
|
|
48
|
-
throw new Error('configs.
|
|
52
|
+
throw new Error('configs.slots.admin removed — put admin panels under web/ (e.g. web/admin-ui)');
|
|
49
53
|
}
|
|
50
54
|
const readSlot = (key) => {
|
|
51
55
|
const scalar = fsBlock.match(new RegExp(`^[ \\t]+${key}:\\s*(.+?)(?:\\s+#.*)?$`, 'm'));
|
|
@@ -59,13 +63,38 @@ export function parseFolderStructure(text) {
|
|
|
59
63
|
[WorkspaceSlotEnum.MOBILE]: readSlot(WorkspaceSlotEnum.MOBILE),
|
|
60
64
|
};
|
|
61
65
|
}
|
|
66
|
+
export function allowedGlobalTypesForSlot(slot) {
|
|
67
|
+
if (slot === WorkspaceSlotEnum.API)
|
|
68
|
+
return [GlobalTypeEnum.API_SERVICE];
|
|
69
|
+
if (slot === WorkspaceSlotEnum.WEB || slot === WorkspaceSlotEnum.MOBILE) {
|
|
70
|
+
return [GlobalTypeEnum.FRONTEND];
|
|
71
|
+
}
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
62
74
|
export function workspaceDiscoverySlots(fsMap) {
|
|
63
75
|
return [
|
|
64
|
-
{
|
|
65
|
-
|
|
66
|
-
|
|
76
|
+
{
|
|
77
|
+
slot: WorkspaceSlotEnum.API,
|
|
78
|
+
folder: fsMap[WorkspaceSlotEnum.API],
|
|
79
|
+
allowedTypes: allowedGlobalTypesForSlot(WorkspaceSlotEnum.API),
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
slot: WorkspaceSlotEnum.WEB,
|
|
83
|
+
folder: fsMap[WorkspaceSlotEnum.WEB],
|
|
84
|
+
allowedTypes: allowedGlobalTypesForSlot(WorkspaceSlotEnum.WEB),
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
slot: WorkspaceSlotEnum.MOBILE,
|
|
88
|
+
folder: fsMap[WorkspaceSlotEnum.MOBILE],
|
|
89
|
+
allowedTypes: allowedGlobalTypesForSlot(WorkspaceSlotEnum.MOBILE),
|
|
90
|
+
},
|
|
67
91
|
];
|
|
68
92
|
}
|
|
93
|
+
export function formatSlotMismatch(mismatch) {
|
|
94
|
+
const expected = mismatch.expectedTypes.join(' | ');
|
|
95
|
+
const got = mismatch.globalType?.trim() || '(missing global.type)';
|
|
96
|
+
return `${mismatch.projectName}: ${got} in ${mismatch.slot}/ slot — expected ${expected}`;
|
|
97
|
+
}
|
|
69
98
|
export { normalizeGlobalType } from '../../../utils/helpers/tmp/tmp-schema.js';
|
|
70
99
|
export function entryName(meta) {
|
|
71
100
|
const project = (meta.projectName ?? '').trim();
|
|
@@ -86,13 +115,48 @@ export function entryType(meta, slot) {
|
|
|
86
115
|
return null;
|
|
87
116
|
}
|
|
88
117
|
export function findWorkspaceRoot(startDir = process.cwd()) {
|
|
89
|
-
|
|
118
|
+
return findWorkspaceAnchor(startDir)?.root ?? null;
|
|
119
|
+
}
|
|
120
|
+
/** Outer workspace tmp path for a known workspace root (honours configs.global.paths). */
|
|
121
|
+
export function resolveWorkspaceOuterTmp(workspaceRoot) {
|
|
122
|
+
const root = path.resolve(workspaceRoot);
|
|
123
|
+
const anchor = findWorkspaceAnchor(root);
|
|
124
|
+
if (!anchor)
|
|
125
|
+
return null;
|
|
126
|
+
if (path.resolve(anchor.root) !== root)
|
|
127
|
+
return null;
|
|
128
|
+
return anchor.tmpPath;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Walk up from cwd; at each level look for workspace tmp at `./tmp.yml` or
|
|
132
|
+
* `./<paths.root>/tmp.yml` (any one-level folder). Project/workspace root is
|
|
133
|
+
* always derived from that file's configs.global.paths — never hardcoded.
|
|
134
|
+
*/
|
|
135
|
+
export function findWorkspaceAnchor(startDir = process.cwd()) {
|
|
136
|
+
const start = path.resolve(startDir);
|
|
137
|
+
let cur = start;
|
|
90
138
|
for (;;) {
|
|
91
|
-
const candidate
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
139
|
+
for (const candidate of listShallowTmpCandidates(cur)) {
|
|
140
|
+
let meta;
|
|
141
|
+
try {
|
|
142
|
+
meta = readTmpFile(candidate);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
meta = readBrokenWorkspaceTmpMeta(candidate);
|
|
146
|
+
}
|
|
147
|
+
if (!meta)
|
|
148
|
+
continue;
|
|
149
|
+
if (meta.globalType !== GlobalTypeEnum.WORKSPACE)
|
|
150
|
+
continue;
|
|
151
|
+
try {
|
|
152
|
+
const root = path.resolve(resolveRepoRootFromTmpMeta(candidate, meta));
|
|
153
|
+
if (start === root || start.startsWith(`${root}${path.sep}`)) {
|
|
154
|
+
return { root, tmpPath: path.resolve(candidate), meta };
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
96
160
|
}
|
|
97
161
|
const parent = path.dirname(cur);
|
|
98
162
|
if (parent === cur)
|
|
@@ -101,6 +165,82 @@ export function findWorkspaceRoot(startDir = process.cwd()) {
|
|
|
101
165
|
}
|
|
102
166
|
return null;
|
|
103
167
|
}
|
|
168
|
+
/** Best-effort workspace meta when folder-structure is broken (e.g. legacy admin slot). */
|
|
169
|
+
export function readBrokenWorkspaceTmpMeta(filePath) {
|
|
170
|
+
if (!fs.existsSync(filePath))
|
|
171
|
+
return null;
|
|
172
|
+
let text;
|
|
173
|
+
try {
|
|
174
|
+
text = fs.readFileSync(filePath, 'utf8');
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
const typeMatch = text.match(/global:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+type:\s*(.+?)\s*(?:#.*)?$/m);
|
|
180
|
+
if (!typeMatch || parseScalar(typeMatch[1]) !== GlobalTypeEnum.WORKSPACE)
|
|
181
|
+
return null;
|
|
182
|
+
const out = {
|
|
183
|
+
path: filePath,
|
|
184
|
+
globalType: GlobalTypeEnum.WORKSPACE,
|
|
185
|
+
folderStructure: { ...DEFAULT_FOLDER_STRUCTURE },
|
|
186
|
+
};
|
|
187
|
+
const projectMatch = text.match(/^project:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+name:\s*(.+?)\s*(?:#.*)?$/m)
|
|
188
|
+
?? text.match(/^project:\s*\n[ \t]+name:\s*(.+?)\s*(?:#.*)?$/m);
|
|
189
|
+
if (projectMatch)
|
|
190
|
+
out.projectName = parseScalar(projectMatch[1]);
|
|
191
|
+
const rootBlock = text.match(/paths:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+root:\s*(.+?)\s*(?:#.*)?$/m);
|
|
192
|
+
if (rootBlock)
|
|
193
|
+
out.pathsRoot = parseScalar(rootBlock[1]);
|
|
194
|
+
const tmpBlock = text.match(/paths:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+tmp:\s*(.+?)\s*(?:#.*)?$/m);
|
|
195
|
+
if (tmpBlock)
|
|
196
|
+
out.pathsTmp = parseScalar(tmpBlock[1]);
|
|
197
|
+
// Preserve known good slot folder names even when admin is present.
|
|
198
|
+
const fsBlock = text.match(/(?:^|\n)[ \t]*slots:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1]
|
|
199
|
+
?? text.match(/(?:^|\n)[ \t]*folder-structure:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1]
|
|
200
|
+
?? '';
|
|
201
|
+
for (const slot of [WorkspaceSlotEnum.API, WorkspaceSlotEnum.WEB, WorkspaceSlotEnum.MOBILE]) {
|
|
202
|
+
const scalar = fsBlock.match(new RegExp(`^[ \\t]+${slot}:\\s*(.+?)(?:\\s+#.*)?$`, 'm'));
|
|
203
|
+
if (scalar)
|
|
204
|
+
out.folderStructure[slot] = parseScalar(scalar[1]);
|
|
205
|
+
}
|
|
206
|
+
return out;
|
|
207
|
+
}
|
|
208
|
+
export function readWorkspaceTmpMeta(filePath) {
|
|
209
|
+
try {
|
|
210
|
+
return readTmpFile(filePath);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
const broken = readBrokenWorkspaceTmpMeta(filePath);
|
|
214
|
+
if (broken)
|
|
215
|
+
return broken;
|
|
216
|
+
throw new Error(`Unable to read workspace tmp: ${filePath}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/** tmp.yml directly under dir, or one level down (paths.root folder). */
|
|
220
|
+
function listShallowTmpCandidates(dir) {
|
|
221
|
+
const out = [];
|
|
222
|
+
const direct = path.join(dir, TMP_FILE);
|
|
223
|
+
if (fs.existsSync(direct))
|
|
224
|
+
out.push(direct);
|
|
225
|
+
let entries;
|
|
226
|
+
try {
|
|
227
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
return out;
|
|
231
|
+
}
|
|
232
|
+
for (const entry of entries) {
|
|
233
|
+
const full = path.join(dir, entry.name);
|
|
234
|
+
if (!isTraversableDir(entry, full))
|
|
235
|
+
continue;
|
|
236
|
+
if (SKIP_DIRS.has(entry.name) || entry.name.startsWith('.'))
|
|
237
|
+
continue;
|
|
238
|
+
const nested = path.join(full, TMP_FILE);
|
|
239
|
+
if (fs.existsSync(nested))
|
|
240
|
+
out.push(nested);
|
|
241
|
+
}
|
|
242
|
+
return out;
|
|
243
|
+
}
|
|
104
244
|
function isTraversableDir(entry, fullPath) {
|
|
105
245
|
if (entry.isDirectory())
|
|
106
246
|
return true;
|
|
@@ -143,39 +283,75 @@ function walkTmpUnder(rootDir) {
|
|
|
143
283
|
return found;
|
|
144
284
|
}
|
|
145
285
|
function stripDotSlash(value) {
|
|
146
|
-
return value.replace(/^\.\//, '');
|
|
286
|
+
return value.replace(/^\.\//, '').replace(/\/$/, '');
|
|
287
|
+
}
|
|
288
|
+
/** Relative tmp path from project root, driven only by configs.global.paths. */
|
|
289
|
+
export function buildRepoTmpRelPath(meta) {
|
|
290
|
+
const isWorkspace = meta.globalType === GlobalTypeEnum.WORKSPACE;
|
|
291
|
+
const rootFolder = stripDotSlash(meta.pathsRoot?.trim() || (isWorkspace ? '.' : packageDefaults.packageRootFolder));
|
|
292
|
+
const tmpName = stripDotSlash(meta.pathsTmp?.trim() || TMP_FILE) || TMP_FILE;
|
|
293
|
+
if (!rootFolder || rootFolder === '.')
|
|
294
|
+
return tmpName;
|
|
295
|
+
return `${rootFolder}/${tmpName}`.replace(/\/+/g, '/');
|
|
147
296
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return
|
|
297
|
+
/** Project/workspace root = tmp file location minus paths.root/paths.tmp. */
|
|
298
|
+
export function resolveRepoRootFromTmpMeta(tmpPath, meta) {
|
|
299
|
+
const abs = path.resolve(tmpPath).replace(/\\/g, '/');
|
|
300
|
+
const rel = buildRepoTmpRelPath(meta);
|
|
301
|
+
if (abs === rel || abs.endsWith(`/${rel}`)) {
|
|
302
|
+
const root = abs === rel ? '' : abs.slice(0, -(rel.length + 1));
|
|
303
|
+
return root || path.dirname(abs);
|
|
155
304
|
}
|
|
156
305
|
throw new Error(`tmp path mismatch: expected */${rel}, got ${abs}`);
|
|
157
306
|
}
|
|
158
|
-
export function
|
|
159
|
-
const
|
|
307
|
+
export function scanWorkspaceProjects(workspaceRoot) {
|
|
308
|
+
const outerTmp = resolveWorkspaceOuterTmp(workspaceRoot);
|
|
309
|
+
const wsMeta = readWorkspaceTmpMeta(outerTmp ?? path.join(workspaceRoot, TMP_FILE));
|
|
160
310
|
const fsMap = wsMeta.folderStructure;
|
|
161
311
|
const entries = [];
|
|
312
|
+
const mismatches = [];
|
|
162
313
|
const seen = new Set();
|
|
163
|
-
|
|
314
|
+
const seenMismatch = new Set();
|
|
315
|
+
const outerResolved = outerTmp ? path.resolve(outerTmp) : null;
|
|
316
|
+
for (const { slot, folder: folderRel, allowedTypes } of workspaceDiscoverySlots(fsMap)) {
|
|
164
317
|
const folder = path.join(workspaceRoot, folderRel);
|
|
165
318
|
for (const tmpPath of walkTmpUnder(folder)) {
|
|
166
|
-
if (path.resolve(tmpPath) ===
|
|
319
|
+
if (outerResolved && path.resolve(tmpPath) === outerResolved)
|
|
167
320
|
continue;
|
|
168
321
|
const meta = readTmpFile(tmpPath);
|
|
169
322
|
const kind = entryType(meta, slot);
|
|
170
323
|
if (kind === GlobalTypeEnum.WORKSPACE)
|
|
171
324
|
continue;
|
|
172
|
-
if (frontendOnly && kind !== GlobalTypeEnum.FRONTEND)
|
|
173
|
-
continue;
|
|
174
|
-
if (kind !== GlobalTypeEnum.API_SERVICE && kind !== GlobalTypeEnum.FRONTEND)
|
|
175
|
-
continue;
|
|
176
325
|
const name = entryName(meta);
|
|
326
|
+
const explicitType = (meta.globalType ?? '').trim() || null;
|
|
327
|
+
const projectPath = (() => {
|
|
328
|
+
try {
|
|
329
|
+
return resolveRepoRootFromTmpMeta(tmpPath, meta);
|
|
330
|
+
}
|
|
331
|
+
catch {
|
|
332
|
+
return path.dirname(tmpPath);
|
|
333
|
+
}
|
|
334
|
+
})();
|
|
177
335
|
if (!name)
|
|
178
336
|
continue;
|
|
337
|
+
if (kind == null || !allowedTypes.includes(kind)) {
|
|
338
|
+
const mismatchKey = `${slot}:${tmpPath}`;
|
|
339
|
+
if (!seenMismatch.has(mismatchKey)) {
|
|
340
|
+
seenMismatch.add(mismatchKey);
|
|
341
|
+
mismatches.push({
|
|
342
|
+
slot,
|
|
343
|
+
slotFolder: folderRel,
|
|
344
|
+
projectName: name,
|
|
345
|
+
globalType: explicitType,
|
|
346
|
+
expectedTypes: allowedTypes,
|
|
347
|
+
tmp: tmpPath,
|
|
348
|
+
projectPath,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (kind !== GlobalTypeEnum.API_SERVICE && kind !== GlobalTypeEnum.FRONTEND)
|
|
354
|
+
continue;
|
|
179
355
|
const key = `${kind}:${name}`;
|
|
180
356
|
if (seen.has(key))
|
|
181
357
|
continue;
|
|
@@ -183,14 +359,24 @@ export function findEntries(workspaceRoot) {
|
|
|
183
359
|
entries.push({
|
|
184
360
|
name,
|
|
185
361
|
type: kind,
|
|
186
|
-
path:
|
|
362
|
+
path: projectPath,
|
|
187
363
|
tmp: tmpPath,
|
|
188
364
|
slot,
|
|
189
365
|
cluster: meta.clusterDeployment ?? meta.projectName,
|
|
190
366
|
});
|
|
191
367
|
}
|
|
192
368
|
}
|
|
193
|
-
|
|
369
|
+
const sortEntries = (a, b) => (a.type === b.type ? a.name.localeCompare(b.name) : a.type.localeCompare(b.type));
|
|
370
|
+
mismatches.sort((a, b) => (a.slot.localeCompare(b.slot)
|
|
371
|
+
|| a.projectName.localeCompare(b.projectName)
|
|
372
|
+
|| a.tmp.localeCompare(b.tmp)));
|
|
373
|
+
return {
|
|
374
|
+
entries: entries.sort(sortEntries),
|
|
375
|
+
mismatches,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
export function findEntries(workspaceRoot) {
|
|
379
|
+
return scanWorkspaceProjects(workspaceRoot).entries;
|
|
194
380
|
}
|
|
195
381
|
export function findApiServices(workspaceRoot) {
|
|
196
382
|
return findEntries(workspaceRoot).filter((e) => e.type === GlobalTypeEnum.API_SERVICE);
|
|
@@ -200,19 +386,25 @@ export function resolveEntryPath(workspaceRoot, name) {
|
|
|
200
386
|
return hit?.path ?? null;
|
|
201
387
|
}
|
|
202
388
|
export function workspaceProjectName(workspaceRoot) {
|
|
203
|
-
const
|
|
389
|
+
const tmpPath = resolveWorkspaceOuterTmp(workspaceRoot);
|
|
390
|
+
if (!tmpPath)
|
|
391
|
+
return path.basename(workspaceRoot);
|
|
392
|
+
const meta = readTmpFile(tmpPath);
|
|
204
393
|
return meta.projectName?.trim() || path.basename(workspaceRoot);
|
|
205
394
|
}
|
|
206
395
|
export function readWorkspaceGlobalTmp(workspaceRoot) {
|
|
207
|
-
const
|
|
396
|
+
const tmpPath = resolveWorkspaceOuterTmp(workspaceRoot);
|
|
397
|
+
if (!tmpPath)
|
|
398
|
+
return {};
|
|
399
|
+
const text = fs.readFileSync(tmpPath, 'utf8');
|
|
208
400
|
const match = text.match(/options:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+fileWatchIntervalMs:\s*(\d+)/m)
|
|
209
401
|
?? text.match(/fileWatchIntervalMs:\s*(\d+)/);
|
|
210
402
|
return match ? { fileWatchIntervalMs: Number(match[1]) } : {};
|
|
211
403
|
}
|
|
212
404
|
/** Ensure api/web/mobile (or custom folder-structure paths) exist on disk. */
|
|
213
405
|
export function ensureWorkspaceSlotDirs(workspaceRoot) {
|
|
214
|
-
const tmpPath =
|
|
215
|
-
if (!
|
|
406
|
+
const tmpPath = resolveWorkspaceOuterTmp(workspaceRoot);
|
|
407
|
+
if (!tmpPath)
|
|
216
408
|
return [];
|
|
217
409
|
const meta = readTmpFile(tmpPath);
|
|
218
410
|
const created = [];
|
|
@@ -225,21 +417,143 @@ export function ensureWorkspaceSlotDirs(workspaceRoot) {
|
|
|
225
417
|
}
|
|
226
418
|
return created;
|
|
227
419
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
420
|
+
function isPlainObject(value) {
|
|
421
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Heal outer workspace tmp structure on sync/project:
|
|
425
|
+
* slots (api/web/mobile), global.paths, options.fileWatchIntervalMs, end.version.
|
|
426
|
+
* Migrates legacy configs.folder-structure → configs.slots.
|
|
427
|
+
* Does not overwrite existing custom slot folder names.
|
|
428
|
+
*/
|
|
429
|
+
export function healWorkspaceOuterTmpStructure(workspaceRoot) {
|
|
430
|
+
const resolvedRoot = path.resolve(workspaceRoot);
|
|
431
|
+
const tmpPath = resolveWorkspaceOuterTmp(resolvedRoot)
|
|
432
|
+
?? (fs.existsSync(path.join(resolvedRoot, TMP_FILE)) ? path.join(resolvedRoot, TMP_FILE) : null);
|
|
433
|
+
if (!tmpPath || !fs.existsSync(tmpPath))
|
|
434
|
+
return { changed: false, notes: [] };
|
|
435
|
+
const raw = fs.readFileSync(tmpPath, 'utf8');
|
|
436
|
+
let doc;
|
|
437
|
+
try {
|
|
438
|
+
const parsed = yaml.parse(raw);
|
|
439
|
+
doc = isPlainObject(parsed) ? parsed : {};
|
|
440
|
+
}
|
|
441
|
+
catch {
|
|
442
|
+
return { changed: false, notes: [] };
|
|
443
|
+
}
|
|
444
|
+
const notes = [];
|
|
236
445
|
const defaultMs = packageDefaults.tmpWatchDefaults.intervalMs;
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
446
|
+
const schemaVersion = packageDefaults.tmpSchemaVersion ?? 1;
|
|
447
|
+
if (!isPlainObject(doc.project)) {
|
|
448
|
+
doc.project = { name: path.basename(workspaceRoot) };
|
|
449
|
+
notes.push('project');
|
|
450
|
+
}
|
|
451
|
+
else if (typeof doc.project.name !== 'string' || !doc.project.name.trim()) {
|
|
452
|
+
doc.project.name = path.basename(workspaceRoot);
|
|
453
|
+
notes.push('project.name');
|
|
454
|
+
}
|
|
455
|
+
if (!isPlainObject(doc.configs)) {
|
|
456
|
+
doc.configs = {};
|
|
457
|
+
notes.push('configs');
|
|
458
|
+
}
|
|
459
|
+
const configs = doc.configs;
|
|
460
|
+
if (!isPlainObject(configs.global)) {
|
|
461
|
+
configs.global = {};
|
|
462
|
+
notes.push('configs.global');
|
|
463
|
+
}
|
|
464
|
+
const global = configs.global;
|
|
465
|
+
if (global.type !== GlobalTypeEnum.WORKSPACE) {
|
|
466
|
+
global.type = GlobalTypeEnum.WORKSPACE;
|
|
467
|
+
notes.push('global.type');
|
|
468
|
+
}
|
|
469
|
+
if (!isPlainObject(global.paths)) {
|
|
470
|
+
global.paths = { root: '.', tmp: 'tmp.yml' };
|
|
471
|
+
notes.push('global.paths');
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
const paths = global.paths;
|
|
475
|
+
if (typeof paths.root !== 'string' || !paths.root.trim()) {
|
|
476
|
+
paths.root = '.';
|
|
477
|
+
notes.push('global.paths.root');
|
|
478
|
+
}
|
|
479
|
+
if (typeof paths.tmp !== 'string' || !paths.tmp.trim()) {
|
|
480
|
+
paths.tmp = 'tmp.yml';
|
|
481
|
+
notes.push('global.paths.tmp');
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (!isPlainObject(global.options)) {
|
|
485
|
+
global.options = { fileWatchIntervalMs: defaultMs };
|
|
486
|
+
notes.push('global.options');
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
const options = global.options;
|
|
490
|
+
if (options.fileWatchIntervalMs == null || options.fileWatchIntervalMs === '') {
|
|
491
|
+
options.fileWatchIntervalMs = defaultMs;
|
|
492
|
+
notes.push('global.options.fileWatchIntervalMs');
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
const slotsKey = 'slots';
|
|
496
|
+
const legacyKey = 'folder-structure';
|
|
497
|
+
let slotsMap;
|
|
498
|
+
if (isPlainObject(configs[slotsKey])) {
|
|
499
|
+
slotsMap = configs[slotsKey];
|
|
500
|
+
}
|
|
501
|
+
else if (isPlainObject(configs[legacyKey])) {
|
|
502
|
+
slotsMap = { ...configs[legacyKey] };
|
|
503
|
+
configs[slotsKey] = slotsMap;
|
|
504
|
+
delete configs[legacyKey];
|
|
505
|
+
notes.push('folder-structure → slots');
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
slotsMap = { ...DEFAULT_FOLDER_STRUCTURE };
|
|
509
|
+
configs[slotsKey] = slotsMap;
|
|
510
|
+
notes.push('slots');
|
|
511
|
+
}
|
|
512
|
+
if ('admin' in slotsMap) {
|
|
513
|
+
delete slotsMap.admin;
|
|
514
|
+
notes.push('slots.admin removed');
|
|
515
|
+
}
|
|
516
|
+
for (const slot of [
|
|
517
|
+
WorkspaceSlotEnum.API,
|
|
518
|
+
WorkspaceSlotEnum.WEB,
|
|
519
|
+
WorkspaceSlotEnum.MOBILE,
|
|
520
|
+
]) {
|
|
521
|
+
const value = slotsMap[slot];
|
|
522
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
523
|
+
slotsMap[slot] = DEFAULT_FOLDER_STRUCTURE[slot];
|
|
524
|
+
notes.push(`slots.${slot}`);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
// Drop leftover legacy key if both somehow exist
|
|
528
|
+
if (legacyKey in configs && slotsKey in configs) {
|
|
529
|
+
delete configs[legacyKey];
|
|
530
|
+
if (!notes.includes('folder-structure → slots')) {
|
|
531
|
+
notes.push('folder-structure removed');
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (!isPlainObject(doc.end)) {
|
|
535
|
+
doc.end = { version: schemaVersion };
|
|
536
|
+
notes.push('end');
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
const end = doc.end;
|
|
540
|
+
if (end.version == null || end.version === '') {
|
|
541
|
+
end.version = schemaVersion;
|
|
542
|
+
notes.push('end.version');
|
|
543
|
+
}
|
|
544
|
+
else if (typeof end.version === 'string' && /^\d+$/.test(end.version.trim())) {
|
|
545
|
+
end.version = Number(end.version);
|
|
546
|
+
notes.push('end.version type');
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
if (notes.length === 0)
|
|
550
|
+
return { changed: false, notes: [] };
|
|
551
|
+
fs.writeFileSync(tmpPath, `${yaml.stringify(doc).trimEnd()}\n`);
|
|
552
|
+
return { changed: true, notes };
|
|
553
|
+
}
|
|
554
|
+
/** @deprecated use healWorkspaceOuterTmpStructure */
|
|
555
|
+
export function healWorkspaceOuterTmpOptions(workspaceRoot) {
|
|
556
|
+
return healWorkspaceOuterTmpStructure(workspaceRoot).changed;
|
|
243
557
|
}
|
|
244
558
|
/** @deprecated */ export const readWorkspaceCoreTmp = readWorkspaceGlobalTmp;
|
|
245
559
|
export function workspaceTmpTemplate(projectName) {
|
|
@@ -249,9 +563,12 @@ export function workspaceTmpTemplate(projectName) {
|
|
|
249
563
|
configs:
|
|
250
564
|
global:
|
|
251
565
|
type: workspace
|
|
566
|
+
paths:
|
|
567
|
+
root: .
|
|
568
|
+
tmp: tmp.yml
|
|
252
569
|
options:
|
|
253
570
|
fileWatchIntervalMs: 500
|
|
254
|
-
|
|
571
|
+
slots:
|
|
255
572
|
api: api
|
|
256
573
|
web: web
|
|
257
574
|
mobile: mobile
|
|
@@ -24,7 +24,9 @@ export declare enum FrameworkEnum {
|
|
|
24
24
|
export declare enum GlobalTypeEnum {
|
|
25
25
|
WORKSPACE = "workspace",
|
|
26
26
|
API_SERVICE = "api-service",
|
|
27
|
-
FRONTEND = "frontend"
|
|
27
|
+
FRONTEND = "frontend",
|
|
28
|
+
/** @xrystal/core package source — layout/build only, not a runnable service or workspace. */
|
|
29
|
+
CORE_LIBRARY = "core-library"
|
|
28
30
|
}
|
|
29
31
|
/** Runtime loader boot profile derived from tmp global.type (+ minimal fallback). */
|
|
30
32
|
export declare enum LoaderBootProfileEnum {
|
|
@@ -46,7 +48,7 @@ export declare enum ProjectScopeKindEnum {
|
|
|
46
48
|
WORKSPACE_SERVICE = "workspace-service",
|
|
47
49
|
STANDALONE_SERVICE = "standalone-service"
|
|
48
50
|
}
|
|
49
|
-
/** Workspace
|
|
51
|
+
/** Workspace slots (outer tmp.yml configs.slots — legacy: folder-structure). */
|
|
50
52
|
export declare enum WorkspaceSlotEnum {
|
|
51
53
|
API = "api",
|
|
52
54
|
WEB = "web",
|
|
@@ -29,6 +29,8 @@ export var GlobalTypeEnum;
|
|
|
29
29
|
GlobalTypeEnum["WORKSPACE"] = "workspace";
|
|
30
30
|
GlobalTypeEnum["API_SERVICE"] = "api-service";
|
|
31
31
|
GlobalTypeEnum["FRONTEND"] = "frontend";
|
|
32
|
+
/** @xrystal/core package source — layout/build only, not a runnable service or workspace. */
|
|
33
|
+
GlobalTypeEnum["CORE_LIBRARY"] = "core-library";
|
|
32
34
|
})(GlobalTypeEnum || (GlobalTypeEnum = {}));
|
|
33
35
|
/** Runtime loader boot profile derived from tmp global.type (+ minimal fallback). */
|
|
34
36
|
export var LoaderBootProfileEnum;
|
|
@@ -53,7 +55,7 @@ export var ProjectScopeKindEnum;
|
|
|
53
55
|
ProjectScopeKindEnum["WORKSPACE_SERVICE"] = "workspace-service";
|
|
54
56
|
ProjectScopeKindEnum["STANDALONE_SERVICE"] = "standalone-service";
|
|
55
57
|
})(ProjectScopeKindEnum || (ProjectScopeKindEnum = {}));
|
|
56
|
-
/** Workspace
|
|
58
|
+
/** Workspace slots (outer tmp.yml configs.slots — legacy: folder-structure). */
|
|
57
59
|
export var WorkspaceSlotEnum;
|
|
58
60
|
(function (WorkspaceSlotEnum) {
|
|
59
61
|
WorkspaceSlotEnum["API"] = "api";
|