@compilr-dev/factory 0.1.4 → 0.1.6
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/LICENSE +108 -0
- package/README.md +124 -45
- package/dist/toolkits/react-node/api.js +6 -3
- package/dist/toolkits/react-node/config.d.ts +4 -0
- package/dist/toolkits/react-node/config.js +90 -3
- package/dist/toolkits/react-node/entity.js +8 -0
- package/dist/toolkits/react-node/seed.js +7 -0
- package/dist/toolkits/react-node/types-gen.js +3 -0
- package/package.json +2 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
Functional Source License, Version 1.1, MIT Future License
|
|
2
|
+
|
|
3
|
+
Abbreviation: FSL-1.1-MIT
|
|
4
|
+
|
|
5
|
+
Notice
|
|
6
|
+
|
|
7
|
+
Copyright 2026 Carmelo Scozzola
|
|
8
|
+
|
|
9
|
+
Terms and Conditions
|
|
10
|
+
|
|
11
|
+
Licensor ("We")
|
|
12
|
+
|
|
13
|
+
The party offering the Software under these Terms and Conditions.
|
|
14
|
+
|
|
15
|
+
The Software
|
|
16
|
+
|
|
17
|
+
The "Software" is each version of the software that we make available under
|
|
18
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
19
|
+
Conditions with the Software.
|
|
20
|
+
|
|
21
|
+
License Grant
|
|
22
|
+
|
|
23
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
24
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
25
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
26
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
27
|
+
|
|
28
|
+
Permitted Purpose
|
|
29
|
+
|
|
30
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
31
|
+
means making the Software available to others in a commercial product or
|
|
32
|
+
service that:
|
|
33
|
+
|
|
34
|
+
1. substitutes for the Software;
|
|
35
|
+
|
|
36
|
+
2. substitutes for any other product or service we offer using the Software
|
|
37
|
+
that exists as of the date we make the Software available; or
|
|
38
|
+
|
|
39
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
40
|
+
|
|
41
|
+
Permitted Purposes specifically include using the Software:
|
|
42
|
+
|
|
43
|
+
1. for your internal use and access;
|
|
44
|
+
|
|
45
|
+
2. for non-commercial education;
|
|
46
|
+
|
|
47
|
+
3. for non-commercial research; and
|
|
48
|
+
|
|
49
|
+
4. in connection with professional services that you provide to a licensee
|
|
50
|
+
using the Software in accordance with these Terms and Conditions.
|
|
51
|
+
|
|
52
|
+
Patents
|
|
53
|
+
|
|
54
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
55
|
+
patents, the license grant above includes a license under our patents. If you
|
|
56
|
+
make a claim against any party that the Software infringes or contributes to
|
|
57
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
58
|
+
immediately.
|
|
59
|
+
|
|
60
|
+
Redistribution
|
|
61
|
+
|
|
62
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
63
|
+
the Software.
|
|
64
|
+
|
|
65
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
66
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
67
|
+
remove any copyright notices provided in or with the Software.
|
|
68
|
+
|
|
69
|
+
Disclaimer
|
|
70
|
+
|
|
71
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
72
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
73
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
74
|
+
|
|
75
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
76
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
77
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
78
|
+
|
|
79
|
+
Trademarks
|
|
80
|
+
|
|
81
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
82
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
83
|
+
trademarks, trade names, service marks or product names.
|
|
84
|
+
|
|
85
|
+
Grant of Future License
|
|
86
|
+
|
|
87
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
88
|
+
the MIT license that is effective on the second anniversary of the date we make
|
|
89
|
+
the Software available. On or after that date, you may use the Software under
|
|
90
|
+
the MIT license, in which case the following will apply:
|
|
91
|
+
|
|
92
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
93
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
94
|
+
the Software without restriction, including without limitation the rights to
|
|
95
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
96
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
97
|
+
so, subject to the following conditions:
|
|
98
|
+
|
|
99
|
+
The above copyright notice and this permission notice shall be included in all
|
|
100
|
+
copies or substantial portions of the Software.
|
|
101
|
+
|
|
102
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
103
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
104
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
105
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
106
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
107
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
108
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,23 +1,40 @@
|
|
|
1
1
|
# @compilr-dev/factory
|
|
2
2
|
|
|
3
|
-
AI-driven application scaffolder for the compilr-dev ecosystem. Generates working full-stack MVPs from an Application Model — a declarative description of what an app is (entities, fields, relationships, layout, features).
|
|
4
|
-
|
|
5
|
-
## Architecture
|
|
6
|
-
|
|
7
3
|
```
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
\|/
|
|
5
|
+
╭══════════╮ ___ ___ _ __ ___ _ __ (_) |_ __
|
|
6
|
+
║' ▐▌ ▐▌ │ / __|/ _ \| '_ ` _ \| '_ \| | | '__|
|
|
7
|
+
║ │ | (__| (_) | | | | | | |_) | | | |
|
|
8
|
+
╰─═──────═─╯ \___|\___/|_| |_| |_| .__/|_|_|_|
|
|
9
|
+
\________\ | | .dev
|
|
10
|
+
|_| factory
|
|
10
11
|
```
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
> AI-driven application scaffolder — from declarative model to working full-stack MVP
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
[](https://www.npmjs.com/package/@compilr-dev/factory)
|
|
16
|
+
[](https://fsl.software/)
|
|
17
|
+
|
|
18
|
+
> [!WARNING]
|
|
19
|
+
> This package is in beta. APIs may change between minor versions.
|
|
20
|
+
|
|
21
|
+
## Overview
|
|
22
|
+
|
|
23
|
+
The factory takes an **Application Model** — a declarative description of what an app is (entities, fields, relationships, layout, features, theme) — and generates a complete, working full-stack project. It provides tools and skills that let AI agents design and scaffold applications through conversation.
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
- **Application Model** — declarative schema for entities, fields, relationships, layout, theme
|
|
28
|
+
- **Semantic Operations** — type-safe mutations (addEntity, updateField, addRelationship, etc.)
|
|
29
|
+
- **Optimistic Locking** — revision counter prevents lost updates
|
|
30
|
+
- **Auto-Inverse Relationships** — adding `belongsTo` auto-creates `hasMany` on target
|
|
31
|
+
- **Cascading Operations** — renaming an entity updates all relationship targets
|
|
32
|
+
- **Validation** — comprehensive model health checks with actionable error messages
|
|
33
|
+
- **Toolkit Registry** — extensible generator system (React+Node built-in)
|
|
34
|
+
- **5 Agent Tools** — model CRUD, validation, scaffolding, toolkit listing
|
|
35
|
+
- **1 Skill** — guided scaffolding workflow for AI agents
|
|
36
|
+
- **Full Color Palette** — auto-generates 50–950 Tailwind shades from single hex
|
|
37
|
+
- **Implicit Timestamps** — `createdAt`/`updatedAt` on all entity records
|
|
21
38
|
|
|
22
39
|
## Installation
|
|
23
40
|
|
|
@@ -25,31 +42,28 @@ The factory provides **5 tools** (via MetaToolsRegistry) and **1 skill**:
|
|
|
25
42
|
npm install @compilr-dev/factory
|
|
26
43
|
```
|
|
27
44
|
|
|
28
|
-
Peer dependency:
|
|
45
|
+
Peer dependency:
|
|
29
46
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
import { createModelTools } from '@compilr-dev/factory';
|
|
34
|
-
import type { PlatformContext } from '@compilr-dev/sdk';
|
|
47
|
+
```bash
|
|
48
|
+
npm install @compilr-dev/sdk
|
|
49
|
+
```
|
|
35
50
|
|
|
36
|
-
|
|
37
|
-
const tools = createModelTools({
|
|
38
|
-
context: platformContext, // PlatformContext with documents repo
|
|
39
|
-
});
|
|
51
|
+
## Quick Start
|
|
40
52
|
|
|
41
|
-
|
|
53
|
+
```typescript
|
|
42
54
|
import {
|
|
43
55
|
createDefaultModel,
|
|
44
|
-
createDefaultEntity,
|
|
45
56
|
applyOperation,
|
|
46
57
|
validateModel,
|
|
47
58
|
} from '@compilr-dev/factory';
|
|
48
59
|
|
|
60
|
+
// Define your application
|
|
49
61
|
const model = createDefaultModel({
|
|
50
62
|
identity: { name: 'Restaurant Manager', description: 'Manage reservations', version: '1.0.0' },
|
|
63
|
+
theme: { primaryColor: '#E65100' },
|
|
51
64
|
});
|
|
52
65
|
|
|
66
|
+
// Add entities through semantic operations
|
|
53
67
|
const updated = applyOperation(model, {
|
|
54
68
|
op: 'addEntity',
|
|
55
69
|
entity: {
|
|
@@ -66,10 +80,34 @@ const updated = applyOperation(model, {
|
|
|
66
80
|
},
|
|
67
81
|
});
|
|
68
82
|
|
|
83
|
+
// Validate
|
|
69
84
|
const result = validateModel(updated);
|
|
70
85
|
// { valid: true, errors: [] }
|
|
71
86
|
```
|
|
72
87
|
|
|
88
|
+
### Agent Tools
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { createModelTools, createFactoryTools } from '@compilr-dev/factory';
|
|
92
|
+
import type { PlatformContext } from '@compilr-dev/sdk';
|
|
93
|
+
|
|
94
|
+
// 3 model tools (get, update, validate)
|
|
95
|
+
const modelTools = createModelTools({ context: platformContext });
|
|
96
|
+
|
|
97
|
+
// 2 factory tools (scaffold, list-toolkits)
|
|
98
|
+
const factoryTools = createFactoryTools({ context: platformContext });
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Agent Tools Reference
|
|
102
|
+
|
|
103
|
+
| Tool | Purpose |
|
|
104
|
+
|------|---------|
|
|
105
|
+
| `app_model_get` | Scoped reads of the Application Model (summary, entities, identity, etc.) |
|
|
106
|
+
| `app_model_update` | Semantic operations with optimistic locking |
|
|
107
|
+
| `app_model_validate` | Check model health and get actionable errors |
|
|
108
|
+
| `factory_scaffold` | Generate files from model + toolkit |
|
|
109
|
+
| `factory_list_toolkits` | List available toolkits with descriptions |
|
|
110
|
+
|
|
73
111
|
## Application Model
|
|
74
112
|
|
|
75
113
|
The model describes **what** an application is, independently of how it's built:
|
|
@@ -87,45 +125,86 @@ ApplicationModel
|
|
|
87
125
|
|
|
88
126
|
### Semantic Operations
|
|
89
127
|
|
|
90
|
-
|
|
128
|
+
All model changes go through typed operations — never raw JSON editing:
|
|
91
129
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
**
|
|
95
|
-
**
|
|
130
|
+
| Category | Operations |
|
|
131
|
+
|----------|------------|
|
|
132
|
+
| **Entity** | addEntity, updateEntity, removeEntity, renameEntity, reorderEntities |
|
|
133
|
+
| **Field** | addField, updateField, removeField, renameField |
|
|
134
|
+
| **Relationship** | addRelationship, removeRelationship (with auto-inverse) |
|
|
135
|
+
| **Section** | updateIdentity, updateLayout, updateFeatures, updateTheme, updateTechStack |
|
|
96
136
|
|
|
97
137
|
Every operation follows: **READ → CHECK → APPLY → VALIDATE → WRITE**.
|
|
98
138
|
|
|
99
|
-
### Key
|
|
139
|
+
### Key Design Choices
|
|
100
140
|
|
|
101
141
|
- **Name-based addressing** — `entity: "Reservation"`, not `entities[2]`
|
|
102
142
|
- **Optimistic locking** — revision counter prevents lost updates
|
|
103
143
|
- **Auto-inverse relationships** — adding `belongsTo` auto-adds `hasMany` on target
|
|
104
|
-
- **Cascading
|
|
144
|
+
- **Cascading renames** — renaming an entity updates all FK references
|
|
105
145
|
- **Scoped reads** — `app_model_get({ scope: "summary" })` for lightweight overview
|
|
106
146
|
|
|
147
|
+
## Toolkits
|
|
148
|
+
|
|
149
|
+
### React + Node (`react-node`)
|
|
150
|
+
|
|
151
|
+
Generates a complete full-stack application:
|
|
152
|
+
|
|
153
|
+
| Category | Generated Files |
|
|
154
|
+
|----------|----------------|
|
|
155
|
+
| **Config** | package.json, vite.config.ts, tailwind.config.js, tsconfig.json, postcss.config.js |
|
|
156
|
+
| **Server** | Express API with CRUD routes, in-memory data stores, seed data |
|
|
157
|
+
| **Pages** | List (card + table views), Detail, Dashboard |
|
|
158
|
+
| **Components** | Cards, Forms, SearchBar, ViewToggle, FilterBar, DarkModeToggle |
|
|
159
|
+
| **Routing** | React Router with nested layouts |
|
|
160
|
+
| **Shell** | Sidebar + header layout, responsive navigation |
|
|
161
|
+
| **Static** | index.html, global CSS, favicon |
|
|
162
|
+
|
|
163
|
+
**Highlights:**
|
|
164
|
+
- `@tailwindcss/forms` plugin included
|
|
165
|
+
- Full primary color palette (50–950 shades) auto-generated from theme
|
|
166
|
+
- Implicit `createdAt`/`updatedAt` timestamps on all entities
|
|
167
|
+
- Enum fields get filter bars on list pages
|
|
168
|
+
- `belongsTo` relationships get populated API responses and form dropdowns
|
|
169
|
+
- `hasMany` relationships shown as linked lists on detail pages
|
|
170
|
+
- Deterministic seed data (8 items per entity with realistic values)
|
|
171
|
+
|
|
107
172
|
## Development
|
|
108
173
|
|
|
109
174
|
```bash
|
|
110
175
|
npm run build # Compile TypeScript
|
|
111
176
|
npm run lint # ESLint (strict, 0 errors required)
|
|
112
177
|
npm run format:check # Prettier check
|
|
113
|
-
npm test -- --run # Run
|
|
178
|
+
npm test -- --run # Run 290 tests
|
|
114
179
|
npm run typecheck # Type-check without emitting
|
|
115
180
|
```
|
|
116
181
|
|
|
117
|
-
##
|
|
182
|
+
## Requirements
|
|
183
|
+
|
|
184
|
+
- **Node.js** 18 or higher
|
|
185
|
+
- **@compilr-dev/sdk** ^0.1.12 (peer dependency)
|
|
118
186
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
|
122
|
-
|
|
123
|
-
|
|
|
124
|
-
|
|
|
125
|
-
|
|
|
126
|
-
|
|
|
127
|
-
|
|
187
|
+
## Related Packages
|
|
188
|
+
|
|
189
|
+
| Package | Description |
|
|
190
|
+
|---------|-------------|
|
|
191
|
+
| [@compilr-dev/sdk](https://www.npmjs.com/package/@compilr-dev/sdk) | Universal agent runtime |
|
|
192
|
+
| [@compilr-dev/agents](https://www.npmjs.com/package/@compilr-dev/agents) | Multi-LLM agent library |
|
|
193
|
+
| [@compilr-dev/agents-coding](https://www.npmjs.com/package/@compilr-dev/agents-coding) | Coding-specific tools and language analysis |
|
|
194
|
+
| [@compilr-dev/cli](https://www.npmjs.com/package/@compilr-dev/cli) | AI-powered coding assistant for your terminal |
|
|
195
|
+
|
|
196
|
+
## Links
|
|
197
|
+
|
|
198
|
+
- [Website](https://compilr.dev)
|
|
199
|
+
- [npm Package](https://www.npmjs.com/package/@compilr-dev/factory)
|
|
200
|
+
- [Report Issues](https://github.com/compilr-dev/factory/issues)
|
|
128
201
|
|
|
129
202
|
## License
|
|
130
203
|
|
|
131
|
-
MIT
|
|
204
|
+
[FSL-1.1-MIT](https://fsl.software/) - See [LICENSE](LICENSE) for details. Converts to MIT after 2 years per version.
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
<p align="center">
|
|
209
|
+
<strong>Built with care by <a href="https://compilr.dev">compilr.dev</a></strong>
|
|
210
|
+
</p>
|
|
@@ -69,6 +69,8 @@ function generateDataStore(model, entity) {
|
|
|
69
69
|
for (const rel of belongsToRels(entity)) {
|
|
70
70
|
typeFields.push(` ${fkFieldName(rel)}: number;`);
|
|
71
71
|
}
|
|
72
|
+
typeFields.push(' createdAt: string;');
|
|
73
|
+
typeFields.push(' updatedAt: string;');
|
|
72
74
|
const seedData = generateSeedData(model, entity);
|
|
73
75
|
return {
|
|
74
76
|
path: `server/data/${fileName}.ts`,
|
|
@@ -91,8 +93,9 @@ export function getById(id: number): ${typeName}Record | undefined {
|
|
|
91
93
|
return items.find((item) => item.id === id);
|
|
92
94
|
}
|
|
93
95
|
|
|
94
|
-
export function create(data: Omit<${typeName}Record, 'id'>): ${typeName}Record {
|
|
95
|
-
const
|
|
96
|
+
export function create(data: Omit<${typeName}Record, 'id' | 'createdAt' | 'updatedAt'>): ${typeName}Record {
|
|
97
|
+
const now = new Date().toISOString();
|
|
98
|
+
const item = { ...data, id: nextId++, createdAt: now, updatedAt: now };
|
|
96
99
|
items.push(item);
|
|
97
100
|
return item;
|
|
98
101
|
}
|
|
@@ -100,7 +103,7 @@ export function create(data: Omit<${typeName}Record, 'id'>): ${typeName}Record {
|
|
|
100
103
|
export function update(id: number, data: Partial<${typeName}Record>): ${typeName}Record | undefined {
|
|
101
104
|
const index = items.findIndex((item) => item.id === id);
|
|
102
105
|
if (index === -1) return undefined;
|
|
103
|
-
items[index] = { ...items[index], ...data, id };
|
|
106
|
+
items[index] = { ...items[index], ...data, id, updatedAt: new Date().toISOString() };
|
|
104
107
|
return items[index];
|
|
105
108
|
}
|
|
106
109
|
|
|
@@ -7,3 +7,7 @@
|
|
|
7
7
|
import type { ApplicationModel } from '../../model/types.js';
|
|
8
8
|
import type { FactoryFile } from '../types.js';
|
|
9
9
|
export declare function generateConfigFiles(model: ApplicationModel): FactoryFile[];
|
|
10
|
+
declare function hexToHsl(hex: string): [number, number, number];
|
|
11
|
+
declare function hslToHex(h: number, s: number, l: number): string;
|
|
12
|
+
declare function generateColorShades(hex: string): string;
|
|
13
|
+
export { hexToHsl, hslToHex, generateColorShades };
|
|
@@ -43,6 +43,7 @@ function generatePackageJson(appSlug) {
|
|
|
43
43
|
cors: '^2.8.5',
|
|
44
44
|
express: '^4.21.1',
|
|
45
45
|
postcss: '^8.4.49',
|
|
46
|
+
'@tailwindcss/forms': '^0.5.9',
|
|
46
47
|
tailwindcss: '^3.4.15',
|
|
47
48
|
tsx: '^4.19.2',
|
|
48
49
|
typescript: '^5.6.3',
|
|
@@ -71,18 +72,20 @@ export default defineConfig({
|
|
|
71
72
|
function generateTailwindConfig(model) {
|
|
72
73
|
return {
|
|
73
74
|
path: 'tailwind.config.js',
|
|
74
|
-
content:
|
|
75
|
+
content: `import forms from '@tailwindcss/forms';
|
|
76
|
+
|
|
77
|
+
/** @type {import('tailwindcss').Config} */
|
|
75
78
|
export default {
|
|
76
79
|
content: ['./index.html', './src/**/*.{ts,tsx}'],
|
|
77
80
|
darkMode: 'class',
|
|
78
81
|
theme: {
|
|
79
82
|
extend: {
|
|
80
83
|
colors: {
|
|
81
|
-
primary:
|
|
84
|
+
primary: ${generateColorShades(model.theme.primaryColor)},
|
|
82
85
|
},
|
|
83
86
|
},
|
|
84
87
|
},
|
|
85
|
-
plugins: [],
|
|
88
|
+
plugins: [forms],
|
|
86
89
|
};
|
|
87
90
|
`,
|
|
88
91
|
};
|
|
@@ -106,6 +109,90 @@ function generateTsConfig() {
|
|
|
106
109
|
};
|
|
107
110
|
return { path: 'tsconfig.json', content: JSON.stringify(config, null, 2) + '\n' };
|
|
108
111
|
}
|
|
112
|
+
// =============================================================================
|
|
113
|
+
// Color Shade Utilities
|
|
114
|
+
// =============================================================================
|
|
115
|
+
const SHADE_LIGHTNESS = {
|
|
116
|
+
'50': 97,
|
|
117
|
+
'100': 94,
|
|
118
|
+
'200': 86,
|
|
119
|
+
'300': 77,
|
|
120
|
+
'400': 66,
|
|
121
|
+
'500': 55,
|
|
122
|
+
'600': 44,
|
|
123
|
+
'700': 36,
|
|
124
|
+
'800': 27,
|
|
125
|
+
'900': 20,
|
|
126
|
+
'950': 14,
|
|
127
|
+
};
|
|
128
|
+
function hexToHsl(hex) {
|
|
129
|
+
const raw = hex.replace('#', '');
|
|
130
|
+
const r = parseInt(raw.substring(0, 2), 16) / 255;
|
|
131
|
+
const g = parseInt(raw.substring(2, 4), 16) / 255;
|
|
132
|
+
const b = parseInt(raw.substring(4, 6), 16) / 255;
|
|
133
|
+
const max = Math.max(r, g, b);
|
|
134
|
+
const min = Math.min(r, g, b);
|
|
135
|
+
const l = (max + min) / 2;
|
|
136
|
+
if (max === min)
|
|
137
|
+
return [0, 0, Math.round(l * 100)];
|
|
138
|
+
const d = max - min;
|
|
139
|
+
const s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
140
|
+
let h = 0;
|
|
141
|
+
if (max === r)
|
|
142
|
+
h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
|
|
143
|
+
else if (max === g)
|
|
144
|
+
h = ((b - r) / d + 2) / 6;
|
|
145
|
+
else
|
|
146
|
+
h = ((r - g) / d + 4) / 6;
|
|
147
|
+
return [Math.round(h * 360), Math.round(s * 100), Math.round(l * 100)];
|
|
148
|
+
}
|
|
149
|
+
function hslToHex(h, s, l) {
|
|
150
|
+
const sN = s / 100;
|
|
151
|
+
const lN = l / 100;
|
|
152
|
+
const c = (1 - Math.abs(2 * lN - 1)) * sN;
|
|
153
|
+
const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
|
|
154
|
+
const m = lN - c / 2;
|
|
155
|
+
let r = 0, g = 0, b = 0;
|
|
156
|
+
if (h < 60)
|
|
157
|
+
[r, g, b] = [c, x, 0];
|
|
158
|
+
else if (h < 120)
|
|
159
|
+
[r, g, b] = [x, c, 0];
|
|
160
|
+
else if (h < 180)
|
|
161
|
+
[r, g, b] = [0, c, x];
|
|
162
|
+
else if (h < 240)
|
|
163
|
+
[r, g, b] = [0, x, c];
|
|
164
|
+
else if (h < 300)
|
|
165
|
+
[r, g, b] = [x, 0, c];
|
|
166
|
+
else
|
|
167
|
+
[r, g, b] = [c, 0, x];
|
|
168
|
+
const toHex = (v) => Math.round((v + m) * 255)
|
|
169
|
+
.toString(16)
|
|
170
|
+
.padStart(2, '0');
|
|
171
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
172
|
+
}
|
|
173
|
+
function generateColorShades(hex) {
|
|
174
|
+
const [h, s] = hexToHsl(hex);
|
|
175
|
+
const entries = [];
|
|
176
|
+
for (const [shade, lightness] of Object.entries(SHADE_LIGHTNESS)) {
|
|
177
|
+
entries.push(` ${shade}: '${hslToHex(h, s, lightness)}',`);
|
|
178
|
+
}
|
|
179
|
+
// Find the shade closest to the original for DEFAULT
|
|
180
|
+
const [, , originalL] = hexToHsl(hex);
|
|
181
|
+
let closestShade = '500';
|
|
182
|
+
let closestDiff = Infinity;
|
|
183
|
+
for (const [shade, lightness] of Object.entries(SHADE_LIGHTNESS)) {
|
|
184
|
+
const diff = Math.abs(lightness - originalL);
|
|
185
|
+
if (diff < closestDiff) {
|
|
186
|
+
closestDiff = diff;
|
|
187
|
+
closestShade = shade;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const defaultHex = hslToHex(h, s, SHADE_LIGHTNESS[closestShade]);
|
|
191
|
+
entries.push(` DEFAULT: '${defaultHex}',`);
|
|
192
|
+
return `{\n${entries.join('\n')}\n }`;
|
|
193
|
+
}
|
|
194
|
+
// Export for testing
|
|
195
|
+
export { hexToHsl, hslToHex, generateColorShades };
|
|
109
196
|
function generatePostCssConfig() {
|
|
110
197
|
return {
|
|
111
198
|
path: 'postcss.config.js',
|
|
@@ -253,6 +253,14 @@ export default function ${entity.name}Detail() {
|
|
|
253
253
|
|
|
254
254
|
<dl className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
|
255
255
|
${fieldRows}
|
|
256
|
+
<div>
|
|
257
|
+
<dt className="text-sm font-medium text-gray-500 dark:text-gray-400">Created</dt>
|
|
258
|
+
<dd className="mt-1 text-gray-900 dark:text-white">{new Date(item.createdAt).toLocaleString()}</dd>
|
|
259
|
+
</div>
|
|
260
|
+
<div>
|
|
261
|
+
<dt className="text-sm font-medium text-gray-500 dark:text-gray-400">Last Updated</dt>
|
|
262
|
+
<dd className="mt-1 text-gray-900 dark:text-white">{new Date(item.updatedAt).toLocaleString()}</dd>
|
|
263
|
+
</div>
|
|
256
264
|
${relLinks}
|
|
257
265
|
</dl>${hasManyRender}
|
|
258
266
|
</div>
|
|
@@ -136,6 +136,13 @@ export function generateSeedData(model, entity) {
|
|
|
136
136
|
const targetCount = targetEntity ? SEED_COUNT : SEED_COUNT;
|
|
137
137
|
lines.push(` ${fk}: ${String((i % targetCount) + 1)},`);
|
|
138
138
|
}
|
|
139
|
+
// Implicit timestamps (deterministic)
|
|
140
|
+
const createdDate = new Date('2025-06-01T10:00:00Z');
|
|
141
|
+
createdDate.setDate(createdDate.getDate() + i * 2);
|
|
142
|
+
const updatedDate = new Date(createdDate);
|
|
143
|
+
updatedDate.setDate(updatedDate.getDate() + i);
|
|
144
|
+
lines.push(` createdAt: '${createdDate.toISOString()}',`);
|
|
145
|
+
lines.push(` updatedAt: '${updatedDate.toISOString()}',`);
|
|
139
146
|
lines.push(' },');
|
|
140
147
|
}
|
|
141
148
|
lines.push('];');
|
|
@@ -26,6 +26,9 @@ function generateInterface(entity) {
|
|
|
26
26
|
lines.push(` ${fk}: number;`);
|
|
27
27
|
lines.push(` ${rel.target.charAt(0).toLowerCase() + rel.target.slice(1)}?: ${rel.target};`);
|
|
28
28
|
}
|
|
29
|
+
// Implicit timestamps
|
|
30
|
+
lines.push(' createdAt: string;');
|
|
31
|
+
lines.push(' updatedAt: string;');
|
|
29
32
|
lines.push('}');
|
|
30
33
|
return lines.join('\n');
|
|
31
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compilr-dev/factory",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "AI-driven application scaffolder for the compilr-dev ecosystem",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"typescript-eslint": "^8.18.1",
|
|
38
38
|
"vitest": "^2.1.8"
|
|
39
39
|
},
|
|
40
|
-
"license": "MIT",
|
|
40
|
+
"license": "FSL-1.1-MIT",
|
|
41
41
|
"repository": {
|
|
42
42
|
"type": "git",
|
|
43
43
|
"url": "https://github.com/scozzola/compilr-dev-factory"
|