-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinfo.ts
More file actions
125 lines (110 loc) · 3.77 KB
/
Copy pathinfo.ts
File metadata and controls
125 lines (110 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { Args, Command, Flags } from '@oclif/core';
import chalk from 'chalk';
import { normalizeStackInput } from '@objectstack/spec';
import { loadConfig } from '../utils/config.js';
import {
printHeader,
printKV,
printSuccess,
printError,
printStep,
createTimer,
collectMetadataStats,
printMetadataStats,
} from '../utils/format.js';
export default class Info extends Command {
static override description = 'Display metadata summary of an ObjectStack configuration';
static override args = {
config: Args.string({ description: 'Configuration file path', required: false }),
};
static override flags = {
json: Flags.boolean({ description: 'Output as JSON' }),
};
async run(): Promise<void> {
const { args, flags } = await this.parse(Info);
const timer = createTimer();
if (!flags.json) {
printHeader('Info');
}
try {
const { config: rawConfig, absolutePath, duration } = await loadConfig(args.config);
const config: any = normalizeStackInput(rawConfig as Record<string, unknown>);
const stats = collectMetadataStats(config);
if (flags.json) {
console.log(JSON.stringify({
config: absolutePath,
manifest: config.manifest || null,
stats,
objects: (config.objects || []).map((o: any) => ({
name: o.name,
label: o.label,
fields: o.fields ? Object.keys(o.fields).length : 0,
})),
loadTime: duration,
}, null, 2));
return;
}
// Manifest
if (config.manifest) {
const m = config.manifest;
console.log('');
console.log(` ${chalk.bold(m.name || m.id || 'Unnamed')} ${chalk.dim(`v${m.version || '0.0.0'}`)}`);
if (m.id) console.log(chalk.dim(` ${m.id}`));
if (m.description) console.log(chalk.dim(` ${m.description}`));
if (m.namespace) printKV(' Namespace', m.namespace);
if (m.type) printKV(' Type', m.type);
}
console.log('');
printMetadataStats(stats);
// Object details
if (config.objects && config.objects.length > 0) {
console.log('');
console.log(chalk.bold(' Objects:'));
for (const obj of config.objects) {
const fieldCount = obj.fields ? Object.keys(obj.fields).length : 0;
// Record-ownership model (#3175); defaults to user-owned when unset.
const ownership = obj.ownership || 'user';
console.log(
` ${chalk.cyan(obj.name || '?')}` +
chalk.dim(` (${fieldCount} fields, ${ownership})`) +
(obj.label ? chalk.dim(` — ${obj.label}`) : '')
);
}
}
// Agent details
if (config.agents && config.agents.length > 0) {
console.log('');
console.log(chalk.bold(' Agents:'));
for (const agent of config.agents) {
console.log(
` ${chalk.magenta(agent.name || '?')}` +
(agent.role ? chalk.dim(` — ${agent.role}`) : '')
);
}
}
// App details
if (config.apps && config.apps.length > 0) {
console.log('');
console.log(chalk.bold(' Apps:'));
for (const app of config.apps) {
console.log(
` ${chalk.green(app.name || '?')}` +
(app.label ? chalk.dim(` — ${app.label}`) : '')
);
}
}
console.log('');
console.log(chalk.dim(` Loaded in ${duration}ms`));
console.log('');
} catch (error: any) {
if (flags.json) {
console.log(JSON.stringify({ error: error.message }));
process.exit(1);
}
console.log('');
printError(error.message || String(error));
process.exit(1);
}
}
}