Skip to content

Commit d27a9d0

Browse files
committed
feat: update DashboardWidget schema to include new chart types and enhance CLI functionality
- Updated DashboardWidget.mdx to include 'donut' and 'gauge' types in the visualization options. - Modified package.json files for CRM and Todo examples to use the new CLI command for building. - Updated ChartType.json and Dashboard.json schemas to reflect new chart types. - Removed deprecated compile.ts script and replaced it with a new CLI implementation. - Added new CLI package with commands for compiling ObjectStack configurations. - Implemented TypeScript configuration and build setup for the CLI package.
1 parent 9beb5a8 commit d27a9d0

File tree

16 files changed

+426
-73
lines changed

16 files changed

+426
-73
lines changed

content/docs/references/ui/dashboard/ChartType.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ description: ChartType Schema Reference
99
* `bar`
1010
* `line`
1111
* `pie`
12+
* `donut`
13+
* `gauge`
1214
* `funnel`
1315
* `radar`
1416
* `scatter`

content/docs/references/ui/dashboard/DashboardWidget.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: DashboardWidget Schema Reference
88
| Property | Type | Required | Description |
99
| :--- | :--- | :--- | :--- |
1010
| **title** | `string` | optional | Widget title |
11-
| **type** | `Enum<'metric' \| 'bar' \| 'line' \| 'pie' \| 'funnel' \| 'radar' \| 'scatter' \| 'heatmap' \| 'pivot' \| 'table' \| 'list' \| 'text' \| 'image' \| 'frame'>` | optional | Visualization type |
11+
| **type** | `Enum<'metric' \| 'bar' \| 'line' \| 'pie' \| 'donut' \| 'gauge' \| 'funnel' \| 'radar' \| 'scatter' \| 'heatmap' \| 'pivot' \| 'table' \| 'list' \| 'text' \| 'image' \| 'frame'>` | optional | Visualization type |
1212
| **object** | `string` | optional | Data source object name |
1313
| **filter** | `any` | optional | Data filter criteria |
1414
| **categoryField** | `string` | optional | Field for grouping (X-Axis) |

examples/crm/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
"description": "Example CRM implementation using ObjectStack Protocol",
55
"private": true,
66
"scripts": {
7-
"build": "npx tsx ../../packages/spec/src/cli/compile.ts objectstack.config.ts dist/objectstack.json",
7+
"build": "objectstack compile objectstack.config.ts dist/crm.json",
88
"test": "echo \"Error: no test specified\" && exit 1"
99
},
1010
"dependencies": {
1111
"@objectstack/spec": "workspace:*"
1212
},
1313
"devDependencies": {
14-
"typescript": "^5.0.0"
14+
"typescript": "^5.0.0",
15+
"@objectstack/cli": "workspace:*"
1516
}
1617
}

examples/todo/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
"description": "Example Todo App using ObjectStack Protocol",
55
"private": true,
66
"scripts": {
7-
"build": "npx tsx ../../packages/spec/src/cli/compile.ts objectstack.config.ts dist/objectstack.json"
7+
"build": "objectstack compile objectstack.config.ts dist/objectstack.json"
88
},
99
"dependencies": {
1010
"@objectstack/spec": "workspace:*",
1111
"@objectstack/client": "workspace:*"
1212
},
1313
"devDependencies": {
14-
"typescript": "^5.0.0"
14+
"typescript": "^5.0.0",
15+
"@objectstack/cli": "workspace:*"
1516
}
1617
}

packages/cli/bin/objectstack.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
import '../dist/bin.js';

packages/cli/package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "@objectstack/cli",
3+
"version": "0.1.0",
4+
"description": "Command Line Interface for ObjectStack Protocol",
5+
"main": "dist/index.js",
6+
"bin": {
7+
"objectstack": "./bin/objectstack.js",
8+
"os": "./bin/objectstack.js"
9+
},
10+
"scripts": {
11+
"build": "tsup",
12+
"dev": "tsup --watch",
13+
"lint": "eslint src"
14+
},
15+
"keywords": [
16+
"objectstack",
17+
"cli",
18+
"compiler",
19+
"scaffold"
20+
],
21+
"type": "module",
22+
"author": "Steedos",
23+
"license": "MIT",
24+
"dependencies": {
25+
"@objectstack/spec": "workspace:*",
26+
"bundle-require": "^5.1.0",
27+
"chalk": "^5.3.0",
28+
"commander": "^11.1.0",
29+
"tsx": "^4.7.1",
30+
"zod": "^3.22.4"
31+
},
32+
"devDependencies": {
33+
"@types/node": "^20.11.19",
34+
"tsup": "^8.0.2",
35+
"typescript": "^5.3.3"
36+
}
37+
}

packages/cli/src/bin.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Command } from 'commander';
2+
import { compileCommand } from './commands/compile.js';
3+
4+
const program = new Command();
5+
6+
program
7+
.name('objectstack')
8+
.description('CLI for ObjectStack Protocol')
9+
.version('0.1.0');
10+
11+
program.addCommand(compileCommand);
12+
13+
program.parse(process.argv);
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { Command } from 'commander';
2+
import path from 'path';
3+
import fs from 'fs';
4+
import { pathToFileURL } from 'url';
5+
import chalk from 'chalk';
6+
import { bundleRequire } from 'bundle-require';
7+
import { ObjectStackDefinitionSchema } from '@objectstack/spec';
8+
9+
export const compileCommand = new Command('compile')
10+
.description('Compile ObjectStack configuration to JSON definition')
11+
.argument('[source]', 'Source configuration file', 'objectstack.config.ts')
12+
.argument('[output]', 'Output JSON file', 'dist/objectstack.json')
13+
.action(async (source, output) => {
14+
const start = Date.now();
15+
console.log(chalk.bold(`\n🔹 ObjectStack Compiler v0.1`));
16+
console.log(chalk.dim(`------------------------------`));
17+
console.log(`📂 Source: ${chalk.blue(source)}`);
18+
19+
const absolutePath = path.resolve(process.cwd(), source);
20+
if (!fs.existsSync(absolutePath)) {
21+
console.error(chalk.red(`\n❌ Config file not found: ${absolutePath}`));
22+
process.exit(1);
23+
}
24+
25+
try {
26+
// 1. Load Configuration
27+
console.log(chalk.yellow(`📦 Bundling Configuration...`));
28+
const { mod } = await bundleRequire({
29+
filepath: absolutePath,
30+
});
31+
32+
const config = mod.default || mod;
33+
34+
if (!config) {
35+
throw new Error(`Default export not found in ${source}`);
36+
}
37+
38+
// 2. Validate against Protocol
39+
console.log(chalk.yellow(`🔍 Validating Protocol Compliance...`));
40+
const result = ObjectStackDefinitionSchema.safeParse(config);
41+
42+
if (!result.success) {
43+
console.error(chalk.red(`\n❌ Validation Failed!`));
44+
45+
result.error.errors.forEach(e => {
46+
console.error(chalk.red(` - [${e.path.join('.')}] ${e.message}`));
47+
});
48+
49+
process.exit(1);
50+
}
51+
52+
// 3. Generate Artifact
53+
const artifactPath = path.resolve(process.cwd(), output);
54+
const artifactDir = path.dirname(artifactPath);
55+
56+
if (!fs.existsSync(artifactDir)) {
57+
fs.mkdirSync(artifactDir, { recursive: true });
58+
}
59+
60+
const jsonContent = JSON.stringify(result.data, null, 2);
61+
fs.writeFileSync(artifactPath, jsonContent);
62+
63+
const size = (jsonContent.length / 1024).toFixed(2);
64+
console.log(chalk.green(`\n✅ Build Success (${Date.now() - start}ms)`));
65+
console.log(`📦 Artifact: ${chalk.blue(output)} (${size} KB)`);
66+
console.log(chalk.magenta(`✨ Ready for Deployment`));
67+
68+
} catch (error: any) {
69+
console.error(chalk.red(`\n❌ Compilation Error:`));
70+
console.error(error.message || error);
71+
process.exit(1);
72+
}
73+
});

packages/cli/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './commands/compile.js';

packages/cli/tsconfig.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "NodeNext",
5+
"moduleResolution": "NodeNext",
6+
"lib": ["ES2022"],
7+
"strict": true,
8+
"esModuleInterop": true,
9+
"skipLibCheck": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"outDir": "dist",
12+
"rootDir": "src"
13+
},
14+
"include": ["src"]
15+
}

0 commit comments

Comments
 (0)