@memberjunction/codegen-lib 2.43.0 → 2.44.0

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.
Files changed (3) hide show
  1. package/README.md +239 -0
  2. package/package.json +12 -12
  3. package/readme.md +0 -3
package/README.md ADDED
@@ -0,0 +1,239 @@
1
+ # @memberjunction/codegen-lib
2
+
3
+ A comprehensive code generation library for the MemberJunction platform that provides reusable object models and utilities for generating TypeScript entity classes, GraphQL schemas, SQL scripts, Angular components, and more.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @memberjunction/codegen-lib
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ The CodeGen Library is the core engine behind MemberJunction's code generation capabilities. It provides a programmatic API that can be integrated into any server-side application to generate various types of code based on your MemberJunction metadata.
14
+
15
+ ## Key Features
16
+
17
+ - **Entity Subclass Generation** - Generate TypeScript classes for all entities in your metadata
18
+ - **Action Subclass Generation** - Generate TypeScript classes for custom actions
19
+ - **GraphQL Schema Generation** - Create GraphQL schemas and resolvers
20
+ - **SQL Script Generation** - Generate database scripts and stored procedures
21
+ - **Angular Component Generation** - Create Angular components for entity management
22
+ - **Configuration Management** - Flexible configuration system with cosmiconfig support
23
+ - **Database Schema Introspection** - Analyze and work with database schemas
24
+ - **Status Logging** - Built-in logging and progress tracking
25
+
26
+ ## Usage
27
+
28
+ ### Basic Setup
29
+
30
+ ```typescript
31
+ import { initializeConfig, runCodeGen } from '@memberjunction/codegen-lib';
32
+
33
+ // Initialize configuration
34
+ await initializeConfig();
35
+
36
+ // Run code generation
37
+ await runCodeGen();
38
+ ```
39
+
40
+ ### Configuration
41
+
42
+ The library uses cosmiconfig to load configuration. Create a `.memberjunctionrc` file or add a `memberjunction` section to your `package.json`:
43
+
44
+ ```json
45
+ {
46
+ "memberjunction": {
47
+ "database": {
48
+ "server": "localhost",
49
+ "database": "YourDatabase",
50
+ "trustedConnection": true
51
+ },
52
+ "directories": {
53
+ "output": "./generated",
54
+ "entities": "./generated/entities",
55
+ "actions": "./generated/actions"
56
+ }
57
+ }
58
+ }
59
+ ```
60
+
61
+ ### Entity Subclass Generation
62
+
63
+ ```typescript
64
+ import { generateEntitySubClasses } from '@memberjunction/codegen-lib';
65
+
66
+ // Generate entity classes
67
+ const result = await generateEntitySubClasses({
68
+ outputDirectory: './generated/entities',
69
+ generateLoader: true,
70
+ generateCustomEntityClasses: true
71
+ });
72
+ ```
73
+
74
+ ### Action Subclass Generation
75
+
76
+ ```typescript
77
+ import { generateActionSubClasses } from '@memberjunction/codegen-lib';
78
+
79
+ // Generate action classes
80
+ const result = await generateActionSubClasses({
81
+ outputDirectory: './generated/actions',
82
+ generateLoader: true
83
+ });
84
+ ```
85
+
86
+ ### GraphQL Server Generation
87
+
88
+ ```typescript
89
+ import { generateGraphQLServerCode } from '@memberjunction/codegen-lib';
90
+
91
+ // Generate GraphQL schema and resolvers
92
+ await generateGraphQLServerCode({
93
+ outputDirectory: './generated/graphql',
94
+ entities: entityMetadata
95
+ });
96
+ ```
97
+
98
+ ### SQL Code Generation
99
+
100
+ ```typescript
101
+ import { generateSQLScripts } from '@memberjunction/codegen-lib';
102
+
103
+ // Generate SQL scripts
104
+ await generateSQLScripts({
105
+ outputDirectory: './generated/sql',
106
+ includeStoredProcedures: true,
107
+ includeViews: true
108
+ });
109
+ ```
110
+
111
+ ### Angular Component Generation
112
+
113
+ ```typescript
114
+ import { generateAllAngularEntityCode } from '@memberjunction/codegen-lib';
115
+
116
+ // Generate Angular components
117
+ await generateAllAngularEntityCode({
118
+ outputDirectory: './generated/angular',
119
+ entities: entityMetadata
120
+ });
121
+ ```
122
+
123
+ ## API Reference
124
+
125
+ ### Core Functions
126
+
127
+ - `initializeConfig()` - Initialize the configuration system
128
+ - `runCodeGen()` - Execute all configured code generation tasks
129
+ - `generateEntitySubClasses()` - Generate TypeScript entity classes
130
+ - `generateActionSubClasses()` - Generate TypeScript action classes
131
+ - `generateGraphQLServerCode()` - Generate GraphQL schemas and resolvers
132
+ - `generateSQLScripts()` - Generate SQL database scripts
133
+ - `generateAllAngularEntityCode()` - Generate Angular components
134
+
135
+ ### Configuration Types
136
+
137
+ - `Config` - Main configuration interface
138
+ - `DatabaseConfig` - Database connection settings
139
+ - `DirectoryConfig` - Output directory settings
140
+
141
+ ### Database Schema Types
142
+
143
+ - `SchemaInfo` - Database schema information
144
+ - `TableInfo` - Table metadata
145
+ - `ColumnInfo` - Column metadata
146
+
147
+ ### Utility Functions
148
+
149
+ - `runCommand()` - Execute shell commands
150
+ - `logStatus()` - Log generation progress
151
+ - `manageMetadata()` - Metadata management utilities
152
+
153
+ ## Integration with AI
154
+
155
+ The library includes integration with MemberJunction's AI framework for intelligent code generation:
156
+
157
+ - Automatic code documentation
158
+ - Smart naming conventions
159
+ - Code pattern recognition
160
+ - Integration with multiple AI providers (OpenAI, Anthropic, Groq, Mistral)
161
+
162
+ ## Working with Related Packages
163
+
164
+ This library works closely with:
165
+
166
+ - `@memberjunction/core` - Core MemberJunction functionality
167
+ - `@memberjunction/core-entities` - Entity definitions
168
+ - `@memberjunction/actions` - Action framework
169
+ - `@memberjunction/sqlserver-dataprovider` - Database connectivity
170
+ - `@memberjunction/ai` - AI integration framework
171
+
172
+ ## Advanced Features
173
+
174
+ ### Custom Templates
175
+
176
+ You can provide custom templates for code generation:
177
+
178
+ ```typescript
179
+ import { setCustomTemplate } from '@memberjunction/codegen-lib';
180
+
181
+ setCustomTemplate('entity', myCustomEntityTemplate);
182
+ ```
183
+
184
+ ### Schema Analysis
185
+
186
+ ```typescript
187
+ import { analyzeSchema } from '@memberjunction/codegen-lib';
188
+
189
+ const schemaInfo = await analyzeSchema(databaseConnection);
190
+ // Work with schema information
191
+ ```
192
+
193
+ ### Progress Tracking
194
+
195
+ ```typescript
196
+ import { onProgress } from '@memberjunction/codegen-lib';
197
+
198
+ onProgress((status) => {
199
+ console.log(`Progress: ${status.message} (${status.percentage}%)`);
200
+ });
201
+ ```
202
+
203
+ ## Error Handling
204
+
205
+ The library provides comprehensive error handling:
206
+
207
+ ```typescript
208
+ try {
209
+ await runCodeGen();
210
+ } catch (error) {
211
+ if (error.code === 'CONFIG_NOT_FOUND') {
212
+ // Handle missing configuration
213
+ } else if (error.code === 'DB_CONNECTION_FAILED') {
214
+ // Handle database connection errors
215
+ }
216
+ }
217
+ ```
218
+
219
+ ## Best Practices
220
+
221
+ 1. **Configuration Management** - Use environment-specific configuration files
222
+ 2. **Output Organization** - Keep generated code in separate directories
223
+ 3. **Version Control** - Consider excluding generated files from version control
224
+ 4. **Regular Updates** - Regenerate code when metadata changes
225
+ 5. **Custom Extensions** - Extend generated classes rather than modifying them
226
+
227
+ ## Contributing
228
+
229
+ When contributing to this package:
230
+
231
+ 1. Maintain backward compatibility
232
+ 2. Add tests for new generation features
233
+ 3. Update documentation for API changes
234
+ 4. Follow the existing code patterns
235
+ 5. Ensure generated code follows TypeScript best practices
236
+
237
+ ## License
238
+
239
+ This package is part of the MemberJunction ecosystem and follows the same licensing terms.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/codegen-lib",
3
- "version": "2.43.0",
3
+ "version": "2.44.0",
4
4
  "description": "Library used by the CodeGen executable to generate code for the MemberJunction platform. Contains a reusable object model that can be called by any other server-side application/library.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,17 +19,17 @@
19
19
  "typescript": "^5.4.5"
20
20
  },
21
21
  "dependencies": {
22
- "@memberjunction/core": "2.43.0",
23
- "@memberjunction/actions": "2.43.0",
24
- "@memberjunction/core-entities": "2.43.0",
25
- "@memberjunction/global": "2.43.0",
26
- "@memberjunction/sqlserver-dataprovider": "2.43.0",
27
- "@memberjunction/ai": "2.43.0",
28
- "@memberjunction/aiengine": "2.43.0",
29
- "@memberjunction/ai-openai": "2.43.0",
30
- "@memberjunction/ai-groq": "2.43.0",
31
- "@memberjunction/ai-mistral": "2.43.0",
32
- "@memberjunction/ai-anthropic": "2.43.0",
22
+ "@memberjunction/core": "2.44.0",
23
+ "@memberjunction/actions": "2.44.0",
24
+ "@memberjunction/core-entities": "2.44.0",
25
+ "@memberjunction/global": "2.44.0",
26
+ "@memberjunction/sqlserver-dataprovider": "2.44.0",
27
+ "@memberjunction/ai": "2.44.0",
28
+ "@memberjunction/aiengine": "2.44.0",
29
+ "@memberjunction/ai-openai": "2.44.0",
30
+ "@memberjunction/ai-groq": "2.44.0",
31
+ "@memberjunction/ai-mistral": "2.44.0",
32
+ "@memberjunction/ai-anthropic": "2.44.0",
33
33
  "cosmiconfig": "9.0.0",
34
34
  "uuid": "^10.0.0",
35
35
  "mssql": "^11.0.1",
package/readme.md DELETED
@@ -1,3 +0,0 @@
1
- # @memberjunction/codegen-lib
2
-
3
- The `@memberjunction/codegen-lib` library provides a set of helper functions that are used by the CodeGen executable to generate various types of code. They are encapsulated here to minimize the complexity of the CodeGen project codebase itself.