@objectstack/cli 1.0.11 → 1.0.12
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/.turbo/turbo-build.log +14 -9
- package/CHANGELOG.md +13 -0
- package/README.md +132 -13
- package/dist/bin.js +1488 -178
- package/dist/index.d.ts +97 -1
- package/dist/index.js +1938 -5
- package/package.json +9 -9
- package/src/bin.ts +53 -6
- package/src/commands/compile.ts +66 -39
- package/src/commands/create.ts +15 -11
- package/src/commands/dev.ts +12 -16
- package/src/commands/doctor.ts +13 -9
- package/src/commands/generate.ts +297 -0
- package/src/commands/info.ts +111 -0
- package/src/commands/init.ts +313 -0
- package/src/commands/serve.ts +134 -48
- package/src/commands/studio.ts +40 -0
- package/src/commands/test.ts +2 -2
- package/src/commands/validate.ts +130 -0
- package/src/index.ts +9 -0
- package/src/utils/config.ts +78 -0
- package/src/utils/console.ts +319 -0
- package/src/utils/format.ts +261 -0
- package/test/commands.test.ts +26 -1
- package/tsup.config.ts +18 -9
- package/dist/bin.d.ts +0 -2
- package/dist/chunk-2YXVEYO7.js +0 -64
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { printHeader, printSuccess, printError, printInfo } from '../utils/format.js';
|
|
6
|
+
|
|
7
|
+
// ─── Metadata Type Templates ────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
const GENERATORS: Record<string, {
|
|
10
|
+
description: string;
|
|
11
|
+
defaultDir: string;
|
|
12
|
+
generate: (name: string) => string;
|
|
13
|
+
}> = {
|
|
14
|
+
object: {
|
|
15
|
+
description: 'Business data object',
|
|
16
|
+
defaultDir: 'src/objects',
|
|
17
|
+
generate: (name: string) => `import { Data } from '@objectstack/spec';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* ${toTitleCase(name)} Object
|
|
21
|
+
*/
|
|
22
|
+
const ${toCamelCase(name)}: Data.Object = {
|
|
23
|
+
name: '${toSnakeCase(name)}',
|
|
24
|
+
label: '${toTitleCase(name)}',
|
|
25
|
+
pluralLabel: '${toTitleCase(name)}s',
|
|
26
|
+
ownership: 'own',
|
|
27
|
+
fields: {
|
|
28
|
+
name: {
|
|
29
|
+
type: 'text',
|
|
30
|
+
label: 'Name',
|
|
31
|
+
required: true,
|
|
32
|
+
maxLength: 255,
|
|
33
|
+
},
|
|
34
|
+
description: {
|
|
35
|
+
type: 'textarea',
|
|
36
|
+
label: 'Description',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default ${toCamelCase(name)};
|
|
42
|
+
`,
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
view: {
|
|
46
|
+
description: 'List or form view',
|
|
47
|
+
defaultDir: 'src/views',
|
|
48
|
+
generate: (name: string) => `import { UI } from '@objectstack/spec';
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* ${toTitleCase(name)} List View
|
|
52
|
+
*/
|
|
53
|
+
const ${toCamelCase(name)}ListView: UI.View = {
|
|
54
|
+
name: '${toSnakeCase(name)}_list',
|
|
55
|
+
label: '${toTitleCase(name)} List',
|
|
56
|
+
type: 'list',
|
|
57
|
+
objectName: '${toSnakeCase(name)}',
|
|
58
|
+
list: {
|
|
59
|
+
type: 'grid',
|
|
60
|
+
columns: [
|
|
61
|
+
{ field: 'name', width: 200 },
|
|
62
|
+
],
|
|
63
|
+
defaultSort: { field: 'name', direction: 'asc' },
|
|
64
|
+
pageSize: 25,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export default ${toCamelCase(name)}ListView;
|
|
69
|
+
`,
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
action: {
|
|
73
|
+
description: 'Button or batch action',
|
|
74
|
+
defaultDir: 'src/actions',
|
|
75
|
+
generate: (name: string) => `import { UI } from '@objectstack/spec';
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* ${toTitleCase(name)} Action
|
|
79
|
+
*/
|
|
80
|
+
const ${toCamelCase(name)}Action: UI.Action = {
|
|
81
|
+
name: '${toSnakeCase(name)}',
|
|
82
|
+
label: '${toTitleCase(name)}',
|
|
83
|
+
type: 'custom',
|
|
84
|
+
objectName: '${toSnakeCase(name)}',
|
|
85
|
+
handler: {
|
|
86
|
+
type: 'flow',
|
|
87
|
+
target: '${toSnakeCase(name)}_flow',
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export default ${toCamelCase(name)}Action;
|
|
92
|
+
`,
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
flow: {
|
|
96
|
+
description: 'Automation flow',
|
|
97
|
+
defaultDir: 'src/flows',
|
|
98
|
+
generate: (name: string) => `import { Automation } from '@objectstack/spec';
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* ${toTitleCase(name)} Flow
|
|
102
|
+
*/
|
|
103
|
+
const ${toCamelCase(name)}Flow: Automation.Flow = {
|
|
104
|
+
name: '${toSnakeCase(name)}_flow',
|
|
105
|
+
label: '${toTitleCase(name)} Flow',
|
|
106
|
+
type: 'autolaunched',
|
|
107
|
+
status: 'draft',
|
|
108
|
+
trigger: {
|
|
109
|
+
type: 'record_change',
|
|
110
|
+
object: '${toSnakeCase(name)}',
|
|
111
|
+
events: ['after_insert', 'after_update'],
|
|
112
|
+
},
|
|
113
|
+
nodes: [
|
|
114
|
+
{
|
|
115
|
+
id: 'start',
|
|
116
|
+
type: 'start',
|
|
117
|
+
name: 'Start',
|
|
118
|
+
next: 'end',
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export default ${toCamelCase(name)}Flow;
|
|
124
|
+
`,
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
agent: {
|
|
128
|
+
description: 'AI agent',
|
|
129
|
+
defaultDir: 'src/agents',
|
|
130
|
+
generate: (name: string) => `import { AI } from '@objectstack/spec';
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* ${toTitleCase(name)} Agent
|
|
134
|
+
*/
|
|
135
|
+
const ${toCamelCase(name)}Agent: AI.Agent = {
|
|
136
|
+
name: '${toSnakeCase(name)}_agent',
|
|
137
|
+
label: '${toTitleCase(name)} Agent',
|
|
138
|
+
role: '${toTitleCase(name)} assistant',
|
|
139
|
+
instructions: 'You are a helpful ${toTitleCase(name).toLowerCase()} assistant.',
|
|
140
|
+
model: {
|
|
141
|
+
provider: 'openai',
|
|
142
|
+
model: 'gpt-4o',
|
|
143
|
+
},
|
|
144
|
+
tools: [],
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export default ${toCamelCase(name)}Agent;
|
|
148
|
+
`,
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
dashboard: {
|
|
152
|
+
description: 'Analytics dashboard',
|
|
153
|
+
defaultDir: 'src/dashboards',
|
|
154
|
+
generate: (name: string) => `import { UI } from '@objectstack/spec';
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* ${toTitleCase(name)} Dashboard
|
|
158
|
+
*/
|
|
159
|
+
const ${toCamelCase(name)}Dashboard: UI.Dashboard = {
|
|
160
|
+
name: '${toSnakeCase(name)}_dashboard',
|
|
161
|
+
label: '${toTitleCase(name)} Dashboard',
|
|
162
|
+
widgets: [],
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
export default ${toCamelCase(name)}Dashboard;
|
|
166
|
+
`,
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
app: {
|
|
170
|
+
description: 'Application navigation',
|
|
171
|
+
defaultDir: 'src/apps',
|
|
172
|
+
generate: (name: string) => `import { UI } from '@objectstack/spec';
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* ${toTitleCase(name)} App
|
|
176
|
+
*/
|
|
177
|
+
const ${toCamelCase(name)}App: UI.App = {
|
|
178
|
+
name: '${toSnakeCase(name)}_app',
|
|
179
|
+
label: '${toTitleCase(name)}',
|
|
180
|
+
navigation: {
|
|
181
|
+
type: 'sidebar',
|
|
182
|
+
items: [],
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export default ${toCamelCase(name)}App;
|
|
187
|
+
`,
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// ─── Helpers ────────────────────────────────────────────────────────
|
|
192
|
+
|
|
193
|
+
function toCamelCase(str: string): string {
|
|
194
|
+
return str.replace(/[-_]([a-z])/g, (_, c) => c.toUpperCase());
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function toTitleCase(str: string): string {
|
|
198
|
+
return str.replace(/[-_]/g, ' ').replace(/\b\w/g, c => c.toUpperCase());
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function toSnakeCase(str: string): string {
|
|
202
|
+
return str.replace(/[-]/g, '_').replace(/[A-Z]/g, c => `_${c.toLowerCase()}`).replace(/^_/, '');
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// ─── Command ────────────────────────────────────────────────────────
|
|
206
|
+
|
|
207
|
+
export const generateCommand = new Command('generate')
|
|
208
|
+
.alias('g')
|
|
209
|
+
.description('Generate metadata files (object, view, action, flow, agent, dashboard, app)')
|
|
210
|
+
.argument('<type>', 'Metadata type to generate')
|
|
211
|
+
.argument('<name>', 'Name for the metadata (use kebab-case)')
|
|
212
|
+
.option('-d, --dir <directory>', 'Target directory (overrides default)')
|
|
213
|
+
.option('--dry-run', 'Show what would be created without writing files')
|
|
214
|
+
.action(async (type: string, name: string, options) => {
|
|
215
|
+
printHeader('Generate');
|
|
216
|
+
|
|
217
|
+
const generator = GENERATORS[type];
|
|
218
|
+
if (!generator) {
|
|
219
|
+
printError(`Unknown type: ${type}`);
|
|
220
|
+
console.log('');
|
|
221
|
+
console.log(chalk.bold(' Available types:'));
|
|
222
|
+
for (const [key, gen] of Object.entries(GENERATORS)) {
|
|
223
|
+
console.log(` ${chalk.cyan(key.padEnd(12))} ${chalk.dim(gen.description)}`);
|
|
224
|
+
}
|
|
225
|
+
console.log('');
|
|
226
|
+
console.log(chalk.dim(' Usage: objectstack generate <type> <name>'));
|
|
227
|
+
console.log(chalk.dim(' Example: objectstack generate object project'));
|
|
228
|
+
console.log(chalk.dim(' Alias: os g object project'));
|
|
229
|
+
process.exit(1);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const dir = options.dir || generator.defaultDir;
|
|
233
|
+
const fileName = `${toSnakeCase(name)}.ts`;
|
|
234
|
+
const filePath = path.join(process.cwd(), dir, fileName);
|
|
235
|
+
|
|
236
|
+
console.log(` ${chalk.dim('Type:')} ${chalk.cyan(type)} — ${generator.description}`);
|
|
237
|
+
console.log(` ${chalk.dim('Name:')} ${chalk.white(name)}`);
|
|
238
|
+
console.log(` ${chalk.dim('File:')} ${chalk.white(path.join(dir, fileName))}`);
|
|
239
|
+
console.log('');
|
|
240
|
+
|
|
241
|
+
if (options.dryRun) {
|
|
242
|
+
printInfo('Dry run — no files written');
|
|
243
|
+
console.log('');
|
|
244
|
+
console.log(chalk.dim(' Content:'));
|
|
245
|
+
console.log(chalk.dim(' ' + '-'.repeat(38)));
|
|
246
|
+
const content = generator.generate(name);
|
|
247
|
+
for (const line of content.split('\n')) {
|
|
248
|
+
console.log(chalk.dim(` ${line}`));
|
|
249
|
+
}
|
|
250
|
+
console.log('');
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Check if file exists
|
|
255
|
+
if (fs.existsSync(filePath)) {
|
|
256
|
+
printError(`File already exists: ${filePath}`);
|
|
257
|
+
process.exit(1);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
try {
|
|
261
|
+
// Create directory
|
|
262
|
+
const fullDir = path.dirname(filePath);
|
|
263
|
+
if (!fs.existsSync(fullDir)) {
|
|
264
|
+
fs.mkdirSync(fullDir, { recursive: true });
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Write file
|
|
268
|
+
const content = generator.generate(name);
|
|
269
|
+
fs.writeFileSync(filePath, content);
|
|
270
|
+
printSuccess(`Created ${path.join(dir, fileName)}`);
|
|
271
|
+
|
|
272
|
+
// Check for barrel index
|
|
273
|
+
const indexPath = path.join(process.cwd(), dir, 'index.ts');
|
|
274
|
+
if (fs.existsSync(indexPath)) {
|
|
275
|
+
const indexContent = fs.readFileSync(indexPath, 'utf-8');
|
|
276
|
+
const exportLine = `export { default as ${toCamelCase(name)} } from './${toSnakeCase(name)}';`;
|
|
277
|
+
|
|
278
|
+
if (!indexContent.includes(toCamelCase(name))) {
|
|
279
|
+
fs.appendFileSync(indexPath, exportLine + '\n');
|
|
280
|
+
printSuccess(`Updated ${dir}/index.ts with export`);
|
|
281
|
+
}
|
|
282
|
+
} else {
|
|
283
|
+
// Create barrel index
|
|
284
|
+
const exportLine = `export { default as ${toCamelCase(name)} } from './${toSnakeCase(name)}';\n`;
|
|
285
|
+
fs.writeFileSync(indexPath, exportLine);
|
|
286
|
+
printSuccess(`Created ${dir}/index.ts`);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
console.log('');
|
|
290
|
+
console.log(chalk.dim(` Tip: Run \`objectstack validate\` to check your config`));
|
|
291
|
+
console.log('');
|
|
292
|
+
|
|
293
|
+
} catch (error: any) {
|
|
294
|
+
printError(error.message || String(error));
|
|
295
|
+
process.exit(1);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { loadConfig } from '../utils/config.js';
|
|
4
|
+
import {
|
|
5
|
+
printHeader,
|
|
6
|
+
printKV,
|
|
7
|
+
printSuccess,
|
|
8
|
+
printError,
|
|
9
|
+
printStep,
|
|
10
|
+
createTimer,
|
|
11
|
+
collectMetadataStats,
|
|
12
|
+
printMetadataStats,
|
|
13
|
+
} from '../utils/format.js';
|
|
14
|
+
|
|
15
|
+
export const infoCommand = new Command('info')
|
|
16
|
+
.description('Display metadata summary of an ObjectStack configuration')
|
|
17
|
+
.argument('[config]', 'Configuration file path')
|
|
18
|
+
.option('--json', 'Output as JSON')
|
|
19
|
+
.action(async (configPath, options) => {
|
|
20
|
+
const timer = createTimer();
|
|
21
|
+
|
|
22
|
+
if (!options.json) {
|
|
23
|
+
printHeader('Info');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const { config, absolutePath, duration } = await loadConfig(configPath);
|
|
28
|
+
const stats = collectMetadataStats(config);
|
|
29
|
+
|
|
30
|
+
if (options.json) {
|
|
31
|
+
console.log(JSON.stringify({
|
|
32
|
+
config: absolutePath,
|
|
33
|
+
manifest: config.manifest || null,
|
|
34
|
+
stats,
|
|
35
|
+
objects: (config.objects || []).map((o: any) => ({
|
|
36
|
+
name: o.name,
|
|
37
|
+
label: o.label,
|
|
38
|
+
fields: o.fields ? Object.keys(o.fields).length : 0,
|
|
39
|
+
})),
|
|
40
|
+
loadTime: duration,
|
|
41
|
+
}, null, 2));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Manifest
|
|
46
|
+
if (config.manifest) {
|
|
47
|
+
const m = config.manifest;
|
|
48
|
+
console.log('');
|
|
49
|
+
console.log(` ${chalk.bold(m.name || m.id || 'Unnamed')} ${chalk.dim(`v${m.version || '0.0.0'}`)}`);
|
|
50
|
+
if (m.id) console.log(chalk.dim(` ${m.id}`));
|
|
51
|
+
if (m.description) console.log(chalk.dim(` ${m.description}`));
|
|
52
|
+
if (m.namespace) printKV(' Namespace', m.namespace);
|
|
53
|
+
if (m.type) printKV(' Type', m.type);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
console.log('');
|
|
57
|
+
printMetadataStats(stats);
|
|
58
|
+
|
|
59
|
+
// Object details
|
|
60
|
+
if (config.objects && config.objects.length > 0) {
|
|
61
|
+
console.log('');
|
|
62
|
+
console.log(chalk.bold(' Objects:'));
|
|
63
|
+
for (const obj of config.objects) {
|
|
64
|
+
const fieldCount = obj.fields ? Object.keys(obj.fields).length : 0;
|
|
65
|
+
const ownership = obj.ownership || 'own';
|
|
66
|
+
console.log(
|
|
67
|
+
` ${chalk.cyan(obj.name || '?')}` +
|
|
68
|
+
chalk.dim(` (${fieldCount} fields, ${ownership})`) +
|
|
69
|
+
(obj.label ? chalk.dim(` — ${obj.label}`) : '')
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Agent details
|
|
75
|
+
if (config.agents && config.agents.length > 0) {
|
|
76
|
+
console.log('');
|
|
77
|
+
console.log(chalk.bold(' Agents:'));
|
|
78
|
+
for (const agent of config.agents) {
|
|
79
|
+
console.log(
|
|
80
|
+
` ${chalk.magenta(agent.name || '?')}` +
|
|
81
|
+
(agent.role ? chalk.dim(` — ${agent.role}`) : '')
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// App details
|
|
87
|
+
if (config.apps && config.apps.length > 0) {
|
|
88
|
+
console.log('');
|
|
89
|
+
console.log(chalk.bold(' Apps:'));
|
|
90
|
+
for (const app of config.apps) {
|
|
91
|
+
console.log(
|
|
92
|
+
` ${chalk.green(app.name || '?')}` +
|
|
93
|
+
(app.label ? chalk.dim(` — ${app.label}`) : '')
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
console.log('');
|
|
99
|
+
console.log(chalk.dim(` Loaded in ${duration}ms`));
|
|
100
|
+
console.log('');
|
|
101
|
+
|
|
102
|
+
} catch (error: any) {
|
|
103
|
+
if (options.json) {
|
|
104
|
+
console.log(JSON.stringify({ error: error.message }));
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
console.log('');
|
|
108
|
+
printError(error.message || String(error));
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}
|
|
111
|
+
});
|