@famgia/omnify-laravel 0.0.45 → 0.0.46

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.
@@ -0,0 +1,222 @@
1
+ # Omnify Laravel Generator Guide
2
+
3
+ This guide covers Laravel-specific features and generated code patterns for Omnify.
4
+
5
+ ## Generated Files
6
+
7
+ When you run `npx omnify generate`, the following Laravel files are generated:
8
+
9
+ ### Migrations
10
+ - `database/migrations/omnify/*.php` - Laravel migrations for each schema
11
+
12
+ ### Models
13
+ - `app/Models/OmnifyBase/{ModelName}BaseModel.php` - Generated base models (DO NOT EDIT)
14
+ - `app/Models/{ModelName}.php` - Extendable model classes (safe to customize)
15
+
16
+ ### Traits
17
+ - `app/Models/OmnifyBase/Traits/HasLocalizedDisplayName.php` - Localization trait
18
+
19
+ ### Locales
20
+ - `app/Models/OmnifyBase/Locales/{ModelName}Locales.php` - i18n display names
21
+
22
+ ## Model Structure
23
+
24
+ ```php
25
+ // app/Models/User.php (YOUR customizations go here)
26
+ <?php
27
+ namespace App\Models;
28
+
29
+ use App\Models\OmnifyBase\UserBaseModel;
30
+
31
+ class User extends UserBaseModel
32
+ {
33
+ // Add your custom methods, scopes, accessors, etc.
34
+ }
35
+ ```
36
+
37
+ ```php
38
+ // app/Models/OmnifyBase/UserBaseModel.php (DO NOT EDIT - auto-generated)
39
+ <?php
40
+ namespace App\Models\OmnifyBase;
41
+
42
+ use App\Models\OmnifyBase\Traits\HasLocalizedDisplayName;
43
+ use App\Models\OmnifyBase\Locales\UserLocales;
44
+
45
+ class UserBaseModel extends Model
46
+ {
47
+ use HasLocalizedDisplayName;
48
+
49
+ protected static array $localizedDisplayNames = UserLocales::DISPLAY_NAMES;
50
+ protected static array $localizedPropertyDisplayNames = UserLocales::PROPERTY_DISPLAY_NAMES;
51
+
52
+ protected $fillable = ['name', 'email', 'password'];
53
+ protected $casts = [...];
54
+
55
+ // Relations defined here
56
+ }
57
+ ```
58
+
59
+ ## Localization (i18n)
60
+
61
+ ### Display Names
62
+ ```php
63
+ // Get localized model name
64
+ User::getLocalizedDisplayName(); // Returns based on app()->getLocale()
65
+
66
+ // Get localized property name
67
+ User::getLocalizedPropertyDisplayName('email');
68
+ ```
69
+
70
+ ### Schema Definition
71
+ ```yaml
72
+ # yaml-language-server: $schema=./node_modules/.omnify/combined-schema.json
73
+ name: User
74
+ displayName:
75
+ ja: ユーザー
76
+ en: User
77
+ properties:
78
+ email:
79
+ type: String
80
+ displayName:
81
+ ja: メールアドレス
82
+ en: Email Address
83
+ ```
84
+
85
+ ## Relationships
86
+
87
+ ### ManyToOne
88
+ ```yaml
89
+ # In Post schema
90
+ author:
91
+ type: Association
92
+ relation: ManyToOne
93
+ target: User
94
+ onDelete: CASCADE
95
+ ```
96
+
97
+ Generated:
98
+ ```php
99
+ // PostBaseModel.php
100
+ public function author(): BelongsTo
101
+ {
102
+ return $this->belongsTo(User::class);
103
+ }
104
+ ```
105
+
106
+ ### OneToMany
107
+ ```yaml
108
+ # In User schema
109
+ posts:
110
+ type: Association
111
+ relation: OneToMany
112
+ target: Post
113
+ mappedBy: author
114
+ ```
115
+
116
+ Generated:
117
+ ```php
118
+ // UserBaseModel.php
119
+ public function posts(): HasMany
120
+ {
121
+ return $this->hasMany(Post::class, 'author_id');
122
+ }
123
+ ```
124
+
125
+ ### ManyToMany
126
+ ```yaml
127
+ # In Post schema
128
+ tags:
129
+ type: Association
130
+ relation: ManyToMany
131
+ target: Tag
132
+ pivotTable: post_tags
133
+ pivotFields:
134
+ - name: order
135
+ type: Int
136
+ default: 0
137
+ ```
138
+
139
+ Generated:
140
+ ```php
141
+ // PostBaseModel.php
142
+ public function tags(): BelongsToMany
143
+ {
144
+ return $this->belongsToMany(Tag::class, 'post_tags')
145
+ ->withPivot(['order']);
146
+ }
147
+ ```
148
+
149
+ ## Migration Options
150
+
151
+ ### Soft Delete
152
+ ```yaml
153
+ options:
154
+ softDelete: true # Adds deleted_at column and SoftDeletes trait
155
+ ```
156
+
157
+ ### Timestamps
158
+ ```yaml
159
+ options:
160
+ timestamps: true # Adds created_at, updated_at columns
161
+ ```
162
+
163
+ ### Custom Table Name
164
+ ```yaml
165
+ options:
166
+ table: custom_table_name
167
+ ```
168
+
169
+ ## Enum Support
170
+
171
+ ```yaml
172
+ # schemas/PostStatus.yaml
173
+ name: PostStatus
174
+ kind: enum
175
+ values:
176
+ draft: 下書き
177
+ published: 公開済み
178
+ archived: アーカイブ
179
+ ```
180
+
181
+ Usage in schema:
182
+ ```yaml
183
+ status:
184
+ type: EnumRef
185
+ enum: PostStatus
186
+ default: draft
187
+ ```
188
+
189
+ Generated migration:
190
+ ```php
191
+ $table->enum('status', ['draft', 'published', 'archived'])->default('draft');
192
+ ```
193
+
194
+ ## Commands
195
+
196
+ ```bash
197
+ # Generate Laravel migrations and models
198
+ npx omnify generate
199
+
200
+ # Force regenerate all files
201
+ npx omnify generate --force
202
+
203
+ # Validate schemas
204
+ npx omnify validate
205
+ ```
206
+
207
+ ## Configuration
208
+
209
+ ```typescript
210
+ // omnify.config.ts
211
+ import { defineConfig } from '@famgia/omnify';
212
+
213
+ export default defineConfig({
214
+ schemasDir: './schemas',
215
+ output: {
216
+ laravel: {
217
+ migrationsPath: './database/migrations/omnify',
218
+ modelsPath: './app/Models',
219
+ },
220
+ },
221
+ });
222
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@famgia/omnify-laravel",
3
- "version": "0.0.45",
3
+ "version": "0.0.46",
4
4
  "description": "Laravel migration and TypeScript type generator for omnify-schema",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,12 +21,13 @@
21
21
  "files": [
22
22
  "dist",
23
23
  "scripts",
24
+ "ai-guides",
24
25
  "README.md"
25
26
  ],
26
27
  "dependencies": {
27
- "@famgia/omnify-types": "0.0.36",
28
- "@famgia/omnify-core": "0.0.39",
29
- "@famgia/omnify-atlas": "0.0.35"
28
+ "@famgia/omnify-types": "0.0.37",
29
+ "@famgia/omnify-core": "0.0.40",
30
+ "@famgia/omnify-atlas": "0.0.36"
30
31
  },
31
32
  "scripts": {
32
33
  "build": "tsup",
@@ -2,232 +2,12 @@
2
2
 
3
3
  import fs from 'fs';
4
4
  import path from 'path';
5
+ import { fileURLToPath } from 'url';
5
6
 
6
- const LARAVEL_GUIDE_CONTENT = `# Omnify Laravel Generator Guide
7
-
8
- This guide covers Laravel-specific features and generated code patterns for Omnify.
9
-
10
- ## Generated Files
11
-
12
- When you run \`npx omnify generate\`, the following Laravel files are generated:
13
-
14
- ### Migrations
15
- - \`database/migrations/omnify/*.php\` - Laravel migrations for each schema
16
-
17
- ### Models
18
- - \`app/Models/OmnifyBase/{ModelName}BaseModel.php\` - Generated base models (DO NOT EDIT)
19
- - \`app/Models/{ModelName}.php\` - Extendable model classes (safe to customize)
20
-
21
- ### Traits
22
- - \`app/Models/OmnifyBase/Traits/HasLocalizedDisplayName.php\` - Localization trait
23
-
24
- ### Locales
25
- - \`app/Models/OmnifyBase/Locales/{ModelName}Locales.php\` - i18n display names
26
-
27
- ## Model Structure
28
-
29
- \`\`\`php
30
- // app/Models/User.php (YOUR customizations go here)
31
- <?php
32
- namespace App\\Models;
33
-
34
- use App\\Models\\OmnifyBase\\UserBaseModel;
35
-
36
- class User extends UserBaseModel
37
- {
38
- // Add your custom methods, scopes, accessors, etc.
39
- }
40
- \`\`\`
41
-
42
- \`\`\`php
43
- // app/Models/OmnifyBase/UserBaseModel.php (DO NOT EDIT - auto-generated)
44
- <?php
45
- namespace App\\Models\\OmnifyBase;
46
-
47
- use App\\Models\\OmnifyBase\\Traits\\HasLocalizedDisplayName;
48
- use App\\Models\\OmnifyBase\\Locales\\UserLocales;
49
-
50
- class UserBaseModel extends Model
51
- {
52
- use HasLocalizedDisplayName;
53
-
54
- protected static array $localizedDisplayNames = UserLocales::DISPLAY_NAMES;
55
- protected static array $localizedPropertyDisplayNames = UserLocales::PROPERTY_DISPLAY_NAMES;
56
-
57
- protected $fillable = ['name', 'email', 'password'];
58
- protected $casts = [...];
59
-
60
- // Relations defined here
61
- }
62
- \`\`\`
63
-
64
- ## Localization (i18n)
65
-
66
- ### Display Names
67
- \`\`\`php
68
- // Get localized model name
69
- User::getLocalizedDisplayName(); // Returns based on app()->getLocale()
70
-
71
- // Get localized property name
72
- User::getLocalizedPropertyDisplayName('email');
73
- \`\`\`
74
-
75
- ### Schema Definition
76
- \`\`\`yaml
77
- # yaml-language-server: $schema=./node_modules/.omnify/combined-schema.json
78
- name: User
79
- displayName:
80
- ja: ユーザー
81
- en: User
82
- properties:
83
- email:
84
- type: String
85
- displayName:
86
- ja: メールアドレス
87
- en: Email Address
88
- \`\`\`
89
-
90
- ## Relationships
91
-
92
- ### ManyToOne
93
- \`\`\`yaml
94
- # In Post schema
95
- author:
96
- type: Association
97
- relation: ManyToOne
98
- target: User
99
- onDelete: CASCADE
100
- \`\`\`
101
-
102
- Generated:
103
- \`\`\`php
104
- // PostBaseModel.php
105
- public function author(): BelongsTo
106
- {
107
- return $this->belongsTo(User::class);
108
- }
109
- \`\`\`
110
-
111
- ### OneToMany
112
- \`\`\`yaml
113
- # In User schema
114
- posts:
115
- type: Association
116
- relation: OneToMany
117
- target: Post
118
- mappedBy: author
119
- \`\`\`
120
-
121
- Generated:
122
- \`\`\`php
123
- // UserBaseModel.php
124
- public function posts(): HasMany
125
- {
126
- return $this->hasMany(Post::class, 'author_id');
127
- }
128
- \`\`\`
129
-
130
- ### ManyToMany
131
- \`\`\`yaml
132
- # In Post schema
133
- tags:
134
- type: Association
135
- relation: ManyToMany
136
- target: Tag
137
- pivotTable: post_tags
138
- pivotFields:
139
- - name: order
140
- type: Int
141
- default: 0
142
- \`\`\`
143
-
144
- Generated:
145
- \`\`\`php
146
- // PostBaseModel.php
147
- public function tags(): BelongsToMany
148
- {
149
- return $this->belongsToMany(Tag::class, 'post_tags')
150
- ->withPivot(['order']);
151
- }
152
- \`\`\`
153
-
154
- ## Migration Options
155
-
156
- ### Soft Delete
157
- \`\`\`yaml
158
- options:
159
- softDelete: true # Adds deleted_at column and SoftDeletes trait
160
- \`\`\`
161
-
162
- ### Timestamps
163
- \`\`\`yaml
164
- options:
165
- timestamps: true # Adds created_at, updated_at columns
166
- \`\`\`
167
-
168
- ### Custom Table Name
169
- \`\`\`yaml
170
- options:
171
- table: custom_table_name
172
- \`\`\`
173
-
174
- ## Enum Support
175
-
176
- \`\`\`yaml
177
- # schemas/PostStatus.yaml
178
- name: PostStatus
179
- kind: enum
180
- values:
181
- draft: 下書き
182
- published: 公開済み
183
- archived: アーカイブ
184
- \`\`\`
185
-
186
- Usage in schema:
187
- \`\`\`yaml
188
- status:
189
- type: EnumRef
190
- enum: PostStatus
191
- default: draft
192
- \`\`\`
193
-
194
- Generated migration:
195
- \`\`\`php
196
- $table->enum('status', ['draft', 'published', 'archived'])->default('draft');
197
- \`\`\`
198
-
199
- ## Commands
200
-
201
- \`\`\`bash
202
- # Generate Laravel migrations and models
203
- npx omnify generate --laravel
204
-
205
- # Validate schemas
206
- npx omnify validate
207
-
208
- # Watch for changes
209
- npx omnify watch --laravel
210
- \`\`\`
211
-
212
- ## Configuration
213
-
214
- \`\`\`javascript
215
- // omnify.config.js
216
- export default {
217
- schemasDir: './schemas',
218
- outputDir: './',
219
- laravel: {
220
- migrationsDir: 'database/migrations/omnify',
221
- modelsDir: 'app/Models',
222
- baseModelsDir: 'app/Models/OmnifyBase',
223
- namespace: 'App\\\\Models'
224
- }
225
- };
226
- \`\`\`
227
- `;
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
228
9
 
229
10
  function findProjectRoot() {
230
- // npm/pnpm set INIT_CWD to the directory where the install was run
231
11
  let dir = process.env.INIT_CWD || process.cwd();
232
12
  const nodeModulesIndex = dir.indexOf('node_modules');
233
13
  if (nodeModulesIndex !== -1) {
@@ -240,17 +20,28 @@ function findProjectRoot() {
240
20
  return null;
241
21
  }
242
22
 
243
- function createLaravelSkillFile(projectRoot) {
23
+ function copyAiGuidesToProject(projectRoot) {
244
24
  const omnifyDir = path.join(projectRoot, '.claude', 'omnify');
25
+ const aiGuidesDir = path.join(__dirname, '..', 'ai-guides');
245
26
 
246
27
  try {
247
28
  if (!fs.existsSync(omnifyDir)) {
248
29
  fs.mkdirSync(omnifyDir, { recursive: true });
249
30
  }
250
31
 
251
- const guidePath = path.join(omnifyDir, 'laravel-guide.md');
252
- fs.writeFileSync(guidePath, LARAVEL_GUIDE_CONTENT, 'utf-8');
253
- console.log(' Created .claude/omnify/laravel-guide.md');
32
+ if (fs.existsSync(aiGuidesDir)) {
33
+ const files = fs.readdirSync(aiGuidesDir);
34
+ for (const file of files) {
35
+ const srcPath = path.join(aiGuidesDir, file);
36
+ const destPath = path.join(omnifyDir, file);
37
+
38
+ if (fs.statSync(srcPath).isFile()) {
39
+ fs.copyFileSync(srcPath, destPath);
40
+ console.log(` Created .claude/omnify/${file}`);
41
+ }
42
+ }
43
+ }
44
+
254
45
  return true;
255
46
  } catch {
256
47
  return false;
@@ -262,7 +53,6 @@ function main() {
262
53
  return;
263
54
  }
264
55
 
265
- // Skip if in omnify-ts monorepo (source code), but allow examples/
266
56
  const projectDir = process.env.INIT_CWD || process.cwd();
267
57
  if (projectDir.includes('omnify-ts') && !projectDir.includes('omnify-ts/examples')) {
268
58
  return;
@@ -270,7 +60,7 @@ function main() {
270
60
 
271
61
  const projectRoot = findProjectRoot();
272
62
  if (projectRoot) {
273
- createLaravelSkillFile(projectRoot);
63
+ copyAiGuidesToProject(projectRoot);
274
64
  }
275
65
  }
276
66