@famgia/omnify-laravel 0.0.19 → 0.0.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@famgia/omnify-laravel",
3
- "version": "0.0.19",
3
+ "version": "0.0.22",
4
4
  "description": "Laravel migration and TypeScript type generator for omnify-schema",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -20,12 +20,13 @@
20
20
  },
21
21
  "files": [
22
22
  "dist",
23
+ "scripts",
23
24
  "README.md"
24
25
  ],
25
26
  "dependencies": {
26
- "@famgia/omnify-types": "0.0.9",
27
- "@famgia/omnify-core": "0.0.14",
28
- "@famgia/omnify-atlas": "0.0.10"
27
+ "@famgia/omnify-types": "0.0.12",
28
+ "@famgia/omnify-core": "0.0.16",
29
+ "@famgia/omnify-atlas": "0.0.12"
29
30
  },
30
31
  "scripts": {
31
32
  "build": "tsup",
@@ -33,6 +34,7 @@
33
34
  "test": "vitest run --passWithNoTests",
34
35
  "test:watch": "vitest",
35
36
  "lint": "eslint src",
36
- "typecheck": "tsc --noEmit"
37
+ "typecheck": "tsc --noEmit",
38
+ "postinstall": "node scripts/postinstall.js"
37
39
  }
38
40
  }
@@ -0,0 +1,276 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+
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
+ name: User
78
+ displayName:
79
+ ja: ユーザー
80
+ en: User
81
+ properties:
82
+ email:
83
+ type: String
84
+ displayName:
85
+ ja: メールアドレス
86
+ en: Email Address
87
+ \`\`\`
88
+
89
+ ## Relationships
90
+
91
+ ### ManyToOne
92
+ \`\`\`yaml
93
+ # In Post schema
94
+ author:
95
+ type: Association
96
+ relation: ManyToOne
97
+ target: User
98
+ onDelete: CASCADE
99
+ \`\`\`
100
+
101
+ Generated:
102
+ \`\`\`php
103
+ // PostBaseModel.php
104
+ public function author(): BelongsTo
105
+ {
106
+ return $this->belongsTo(User::class);
107
+ }
108
+ \`\`\`
109
+
110
+ ### OneToMany
111
+ \`\`\`yaml
112
+ # In User schema
113
+ posts:
114
+ type: Association
115
+ relation: OneToMany
116
+ target: Post
117
+ mappedBy: author
118
+ \`\`\`
119
+
120
+ Generated:
121
+ \`\`\`php
122
+ // UserBaseModel.php
123
+ public function posts(): HasMany
124
+ {
125
+ return $this->hasMany(Post::class, 'author_id');
126
+ }
127
+ \`\`\`
128
+
129
+ ### ManyToMany
130
+ \`\`\`yaml
131
+ # In Post schema
132
+ tags:
133
+ type: Association
134
+ relation: ManyToMany
135
+ target: Tag
136
+ pivotTable: post_tags
137
+ pivotFields:
138
+ - name: order
139
+ type: Int
140
+ default: 0
141
+ \`\`\`
142
+
143
+ Generated:
144
+ \`\`\`php
145
+ // PostBaseModel.php
146
+ public function tags(): BelongsToMany
147
+ {
148
+ return $this->belongsToMany(Tag::class, 'post_tags')
149
+ ->withPivot(['order']);
150
+ }
151
+ \`\`\`
152
+
153
+ ## Migration Options
154
+
155
+ ### Soft Delete
156
+ \`\`\`yaml
157
+ options:
158
+ softDelete: true # Adds deleted_at column and SoftDeletes trait
159
+ \`\`\`
160
+
161
+ ### Timestamps
162
+ \`\`\`yaml
163
+ options:
164
+ timestamps: true # Adds created_at, updated_at columns
165
+ \`\`\`
166
+
167
+ ### Custom Table Name
168
+ \`\`\`yaml
169
+ options:
170
+ table: custom_table_name
171
+ \`\`\`
172
+
173
+ ## Enum Support
174
+
175
+ \`\`\`yaml
176
+ # schemas/PostStatus.yaml
177
+ name: PostStatus
178
+ kind: enum
179
+ values:
180
+ draft: 下書き
181
+ published: 公開済み
182
+ archived: アーカイブ
183
+ \`\`\`
184
+
185
+ Usage in schema:
186
+ \`\`\`yaml
187
+ status:
188
+ type: EnumRef
189
+ enum: PostStatus
190
+ default: draft
191
+ \`\`\`
192
+
193
+ Generated migration:
194
+ \`\`\`php
195
+ $table->enum('status', ['draft', 'published', 'archived'])->default('draft');
196
+ \`\`\`
197
+
198
+ ## Commands
199
+
200
+ \`\`\`bash
201
+ # Generate Laravel migrations and models
202
+ npx omnify generate --laravel
203
+
204
+ # Validate schemas
205
+ npx omnify validate
206
+
207
+ # Watch for changes
208
+ npx omnify watch --laravel
209
+ \`\`\`
210
+
211
+ ## Configuration
212
+
213
+ \`\`\`javascript
214
+ // omnify.config.js
215
+ export default {
216
+ schemasDir: './schemas',
217
+ outputDir: './',
218
+ laravel: {
219
+ migrationsDir: 'database/migrations/omnify',
220
+ modelsDir: 'app/Models',
221
+ baseModelsDir: 'app/Models/OmnifyBase',
222
+ namespace: 'App\\\\Models'
223
+ }
224
+ };
225
+ \`\`\`
226
+ `;
227
+
228
+ function findProjectRoot() {
229
+ // npm/pnpm set INIT_CWD to the directory where the install was run
230
+ let dir = process.env.INIT_CWD || process.cwd();
231
+ const nodeModulesIndex = dir.indexOf('node_modules');
232
+ if (nodeModulesIndex !== -1) {
233
+ dir = dir.substring(0, nodeModulesIndex - 1);
234
+ }
235
+ const packageJsonPath = path.join(dir, 'package.json');
236
+ if (fs.existsSync(packageJsonPath)) {
237
+ return dir;
238
+ }
239
+ return null;
240
+ }
241
+
242
+ function createLaravelSkillFile(projectRoot) {
243
+ const omnifyDir = path.join(projectRoot, '.claude', 'omnify');
244
+
245
+ try {
246
+ if (!fs.existsSync(omnifyDir)) {
247
+ fs.mkdirSync(omnifyDir, { recursive: true });
248
+ }
249
+
250
+ const guidePath = path.join(omnifyDir, 'laravel-guide.md');
251
+ fs.writeFileSync(guidePath, LARAVEL_GUIDE_CONTENT, 'utf-8');
252
+ console.log(' Created .claude/omnify/laravel-guide.md');
253
+ return true;
254
+ } catch {
255
+ return false;
256
+ }
257
+ }
258
+
259
+ function main() {
260
+ if (process.env.CI || process.env.CONTINUOUS_INTEGRATION) {
261
+ return;
262
+ }
263
+
264
+ // Skip if in omnify-ts monorepo (source code), but allow examples/
265
+ const projectDir = process.env.INIT_CWD || process.cwd();
266
+ if (projectDir.includes('omnify-ts') && !projectDir.includes('omnify-ts/examples')) {
267
+ return;
268
+ }
269
+
270
+ const projectRoot = findProjectRoot();
271
+ if (projectRoot) {
272
+ createLaravelSkillFile(projectRoot);
273
+ }
274
+ }
275
+
276
+ main();