@famgia/omnify-react 0.0.1 โ†’ 0.0.2

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,95 @@
1
+ #!/usr/bin/env tsx
2
+ /**
3
+ * Build script to generate TypeScript types from SSO schemas
4
+ *
5
+ * This script:
6
+ * 1. Copies SSO schemas from omnify-client-laravel-sso
7
+ * 2. Generates TypeScript types using omnify-typescript
8
+ * 3. Outputs to src/schemas/ for bundling
9
+ */
10
+
11
+ import { cpSync, existsSync, mkdirSync, rmSync } from 'fs';
12
+ import { resolve, dirname } from 'path';
13
+ import { fileURLToPath } from 'url';
14
+
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = dirname(__filename);
17
+ const packageRoot = resolve(__dirname, '..');
18
+
19
+ // Paths
20
+ const ssoSchemasSource = resolve(packageRoot, '../omnify-client-laravel-sso/database/schemas/Sso');
21
+ const schemasTarget = resolve(packageRoot, 'schemas');
22
+ const typesOutput = resolve(packageRoot, 'src/schemas');
23
+
24
+ async function main() {
25
+ console.log('๐Ÿ”ง Building SSO schema types...');
26
+
27
+ // 1. Clean previous builds
28
+ if (existsSync(schemasTarget)) {
29
+ rmSync(schemasTarget, { recursive: true });
30
+ }
31
+ if (existsSync(typesOutput)) {
32
+ rmSync(typesOutput, { recursive: true });
33
+ }
34
+
35
+ // 2. Copy SSO schemas
36
+ if (!existsSync(ssoSchemasSource)) {
37
+ console.error('โŒ SSO schemas not found at:', ssoSchemasSource);
38
+ process.exit(1);
39
+ }
40
+
41
+ mkdirSync(schemasTarget, { recursive: true });
42
+ cpSync(ssoSchemasSource, schemasTarget, { recursive: true });
43
+ console.log('โœ… Copied SSO schemas');
44
+
45
+ // 3. Generate TypeScript types
46
+ const { loadSchemas } = await import('@famgia/omnify-core');
47
+ const { generateTypeScript } = await import('@famgia/omnify-typescript');
48
+
49
+ const schemas = await loadSchemas(schemasTarget);
50
+ console.log(`๐Ÿ“ฆ Loaded ${Object.keys(schemas).length} schemas`);
51
+
52
+ const files = generateTypeScript(schemas, {
53
+ generateZodSchemas: true,
54
+ multiLocale: true,
55
+ });
56
+
57
+ // 4. Write output files
58
+ mkdirSync(typesOutput, { recursive: true });
59
+ mkdirSync(resolve(typesOutput, 'base'), { recursive: true });
60
+
61
+ const { writeFileSync } = await import('fs');
62
+
63
+ for (const file of files) {
64
+ let outputPath: string;
65
+
66
+ if (file.category === 'enum') {
67
+ // Enums go to schemas/enum/
68
+ outputPath = resolve(typesOutput, 'enum', file.filePath);
69
+ } else if (file.filePath.startsWith('base/')) {
70
+ // Base files stay in base/
71
+ outputPath = resolve(typesOutput, file.filePath);
72
+ } else {
73
+ // Model files go to root
74
+ outputPath = resolve(typesOutput, file.filePath);
75
+ }
76
+
77
+ const dir = dirname(outputPath);
78
+ if (!existsSync(dir)) {
79
+ mkdirSync(dir, { recursive: true });
80
+ }
81
+
82
+ writeFileSync(outputPath, file.content);
83
+ console.log(` ๐Ÿ“„ ${file.filePath}`);
84
+ }
85
+
86
+ console.log(`โœ… Generated ${files.length} TypeScript files`);
87
+
88
+ // 5. Clean up copied schemas (not needed in published package)
89
+ rmSync(schemasTarget, { recursive: true });
90
+ console.log('๐Ÿงน Cleaned up temporary schemas');
91
+
92
+ console.log('โœจ Done!');
93
+ }
94
+
95
+ main().catch(console.error);