@tamyla/clodo-framework 3.1.21 → 3.1.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.
Files changed (169) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +53 -0
  3. package/dist/bin/clodo-service.js +47 -15
  4. package/dist/bin/commands/deploy.js +115 -83
  5. package/dist/bin/commands/helpers/deployment-ui.js +138 -0
  6. package/dist/bin/commands/helpers/deployment-verification.js +251 -0
  7. package/dist/bin/commands/helpers/error-recovery.js +80 -0
  8. package/dist/bin/commands/helpers/resource-detection.js +113 -0
  9. package/dist/bin/commands/validate.js +1 -1
  10. package/dist/bin/security/security-cli.js +1 -1
  11. package/dist/bin/shared/cache/configuration-cache.js +82 -0
  12. package/dist/bin/shared/cloudflare/domain-manager.js +1 -1
  13. package/dist/bin/shared/cloudflare/index.js +1 -1
  14. package/dist/bin/shared/cloudflare/ops.js +6 -4
  15. package/dist/bin/shared/config/ConfigurationManager.js +23 -1
  16. package/dist/bin/shared/config/command-config-manager.js +19 -3
  17. package/dist/bin/shared/config/index.js +1 -1
  18. package/dist/bin/shared/deployment/credential-collector.js +30 -7
  19. package/dist/bin/shared/deployment/index.js +2 -2
  20. package/dist/bin/shared/deployment/rollback-manager.js +4 -520
  21. package/dist/bin/shared/deployment/utilities/d1-error-recovery.js +177 -0
  22. package/dist/bin/shared/deployment/validator.js +40 -10
  23. package/dist/bin/shared/deployment/workflows/deployment-summary.js +214 -0
  24. package/dist/bin/shared/deployment/workflows/interactive-confirmation.js +188 -0
  25. package/dist/bin/shared/deployment/workflows/interactive-database-workflow.js +234 -0
  26. package/dist/bin/shared/deployment/workflows/interactive-domain-info-gatherer.js +240 -0
  27. package/dist/bin/shared/deployment/workflows/interactive-secret-workflow.js +228 -0
  28. package/dist/bin/shared/deployment/workflows/interactive-testing-workflow.js +235 -0
  29. package/dist/bin/shared/deployment/workflows/interactive-validation.js +218 -0
  30. package/dist/bin/shared/error-handling/error-classifier.js +46 -0
  31. package/dist/bin/shared/monitoring/health-checker.js +129 -1
  32. package/dist/bin/shared/monitoring/memory-manager.js +17 -6
  33. package/dist/bin/shared/routing/domain-router.js +1 -1
  34. package/dist/bin/shared/utils/deployment-validator.js +97 -0
  35. package/dist/bin/shared/utils/formatters.js +10 -0
  36. package/dist/bin/shared/utils/index.js +13 -1
  37. package/dist/bin/shared/utils/interactive-prompts.js +34 -18
  38. package/dist/bin/shared/utils/progress-manager.js +2 -2
  39. package/dist/bin/shared/utils/progress-spinner.js +53 -0
  40. package/dist/bin/shared/utils/sensitive-redactor.js +91 -0
  41. package/dist/bin/shared/validation/ValidationRegistry.js +1 -1
  42. package/dist/security/index.js +1 -1
  43. package/dist/security/patterns/insecure-patterns.js +1 -1
  44. package/dist/utils/constants.js +102 -0
  45. package/dist/utils/deployment/wrangler-config-manager.js +215 -48
  46. package/dist/utils/framework-config.js +2 -2
  47. package/dist/utils/interactive-prompts.js +10 -59
  48. package/package.json +16 -8
  49. package/dist/bin/clodo-service-old.js +0 -868
  50. package/dist/bin/clodo-service-test.js +0 -10
  51. package/dist/bin/commands/assess.js +0 -91
  52. package/dist/bin/commands/create.js +0 -77
  53. package/dist/bin/commands/diagnose.js +0 -83
  54. package/dist/bin/commands/helpers.js +0 -138
  55. package/dist/bin/commands/update.js +0 -75
  56. package/dist/bin/database/deployment-db-manager.js +0 -423
  57. package/dist/bin/database/enterprise-db-manager.js +0 -457
  58. package/dist/bin/database/wrangler-d1-manager.js +0 -685
  59. package/dist/bin/deployment/enterprise-deploy.js +0 -877
  60. package/dist/bin/deployment/master-deploy.js +0 -1376
  61. package/dist/bin/deployment/modular-enterprise-deploy.js +0 -466
  62. package/dist/bin/deployment/modules/DeploymentConfiguration.js +0 -395
  63. package/dist/bin/deployment/modules/DeploymentOrchestrator.js +0 -492
  64. package/dist/bin/deployment/modules/EnvironmentManager.js +0 -517
  65. package/dist/bin/deployment/modules/MonitoringIntegration.js +0 -560
  66. package/dist/bin/deployment/modules/ValidationManager.js +0 -342
  67. package/dist/bin/deployment/orchestration/BaseDeploymentOrchestrator.js +0 -426
  68. package/dist/bin/deployment/orchestration/EnterpriseOrchestrator.js +0 -401
  69. package/dist/bin/deployment/orchestration/PortfolioOrchestrator.js +0 -273
  70. package/dist/bin/deployment/orchestration/SingleServiceOrchestrator.js +0 -231
  71. package/dist/bin/deployment/orchestration/UnifiedDeploymentOrchestrator.js +0 -662
  72. package/dist/bin/deployment/test-interactive-utils.js +0 -66
  73. package/dist/bin/portfolio/portfolio-manager.js +0 -487
  74. package/dist/bin/service-management/create-service.js +0 -122
  75. package/dist/bin/service-management/init-service.js +0 -79
  76. package/dist/config/customers.js +0 -623
  77. package/dist/config/domains.js +0 -186
  78. package/dist/config/index.js +0 -6
  79. package/dist/database/database-orchestrator.js +0 -795
  80. package/dist/database/index.js +0 -4
  81. package/dist/deployment/index.js +0 -11
  82. package/dist/deployment/orchestration/BaseDeploymentOrchestrator.js +0 -426
  83. package/dist/deployment/orchestration/EnterpriseOrchestrator.js +0 -401
  84. package/dist/deployment/orchestration/PortfolioOrchestrator.js +0 -273
  85. package/dist/deployment/orchestration/SingleServiceOrchestrator.js +0 -231
  86. package/dist/deployment/orchestration/UnifiedDeploymentOrchestrator.js +0 -662
  87. package/dist/deployment/orchestration/index.js +0 -17
  88. package/dist/deployment/rollback-manager.js +0 -36
  89. package/dist/deployment/wrangler-deployer.js +0 -640
  90. package/dist/handlers/GenericRouteHandler.js +0 -532
  91. package/dist/migration/MigrationAdapters.js +0 -562
  92. package/dist/modules/ModuleManager.js +0 -668
  93. package/dist/modules/security.js +0 -96
  94. package/dist/orchestration/cross-domain-coordinator.js +0 -1083
  95. package/dist/orchestration/index.js +0 -5
  96. package/dist/orchestration/modules/DeploymentCoordinator.js +0 -368
  97. package/dist/orchestration/modules/DomainResolver.js +0 -198
  98. package/dist/orchestration/modules/StateManager.js +0 -332
  99. package/dist/orchestration/multi-domain-orchestrator.js +0 -724
  100. package/dist/routing/EnhancedRouter.js +0 -158
  101. package/dist/schema/SchemaManager.js +0 -778
  102. package/dist/service-management/ConfirmationEngine.js +0 -412
  103. package/dist/service-management/ErrorTracker.js +0 -299
  104. package/dist/service-management/GenerationEngine.js +0 -447
  105. package/dist/service-management/InputCollector.js +0 -619
  106. package/dist/service-management/ServiceCreator.js +0 -265
  107. package/dist/service-management/ServiceInitializer.js +0 -453
  108. package/dist/service-management/ServiceOrchestrator.js +0 -633
  109. package/dist/service-management/generators/BaseGenerator.js +0 -233
  110. package/dist/service-management/generators/GeneratorRegistry.js +0 -254
  111. package/dist/service-management/generators/cicd/CiWorkflowGenerator.js +0 -87
  112. package/dist/service-management/generators/cicd/DeployWorkflowGenerator.js +0 -106
  113. package/dist/service-management/generators/code/ServiceHandlersGenerator.js +0 -235
  114. package/dist/service-management/generators/code/ServiceMiddlewareGenerator.js +0 -116
  115. package/dist/service-management/generators/code/ServiceUtilsGenerator.js +0 -246
  116. package/dist/service-management/generators/code/WorkerIndexGenerator.js +0 -143
  117. package/dist/service-management/generators/config/DevelopmentEnvGenerator.js +0 -101
  118. package/dist/service-management/generators/config/DomainsConfigGenerator.js +0 -175
  119. package/dist/service-management/generators/config/EnvExampleGenerator.js +0 -178
  120. package/dist/service-management/generators/config/ProductionEnvGenerator.js +0 -97
  121. package/dist/service-management/generators/config/StagingEnvGenerator.js +0 -97
  122. package/dist/service-management/generators/config/WranglerTomlGenerator.js +0 -238
  123. package/dist/service-management/generators/core/PackageJsonGenerator.js +0 -243
  124. package/dist/service-management/generators/core/SiteConfigGenerator.js +0 -115
  125. package/dist/service-management/generators/documentation/ApiDocsGenerator.js +0 -331
  126. package/dist/service-management/generators/documentation/ConfigurationDocsGenerator.js +0 -294
  127. package/dist/service-management/generators/documentation/DeploymentDocsGenerator.js +0 -244
  128. package/dist/service-management/generators/documentation/ReadmeGenerator.js +0 -196
  129. package/dist/service-management/generators/schemas/ServiceSchemaGenerator.js +0 -190
  130. package/dist/service-management/generators/scripts/DeployScriptGenerator.js +0 -123
  131. package/dist/service-management/generators/scripts/HealthCheckScriptGenerator.js +0 -101
  132. package/dist/service-management/generators/scripts/SetupScriptGenerator.js +0 -88
  133. package/dist/service-management/generators/service-types/StaticSiteGenerator.js +0 -342
  134. package/dist/service-management/generators/testing/EslintConfigGenerator.js +0 -85
  135. package/dist/service-management/generators/testing/IntegrationTestsGenerator.js +0 -237
  136. package/dist/service-management/generators/testing/JestConfigGenerator.js +0 -72
  137. package/dist/service-management/generators/testing/UnitTestsGenerator.js +0 -277
  138. package/dist/service-management/generators/tooling/DockerComposeGenerator.js +0 -71
  139. package/dist/service-management/generators/tooling/GitignoreGenerator.js +0 -143
  140. package/dist/service-management/generators/utils/FileWriter.js +0 -179
  141. package/dist/service-management/generators/utils/PathResolver.js +0 -157
  142. package/dist/service-management/generators/utils/ServiceManifestGenerator.js +0 -111
  143. package/dist/service-management/generators/utils/TemplateEngine.js +0 -185
  144. package/dist/service-management/generators/utils/index.js +0 -18
  145. package/dist/service-management/handlers/ConfirmationHandler.js +0 -71
  146. package/dist/service-management/handlers/GenerationHandler.js +0 -80
  147. package/dist/service-management/handlers/InputHandler.js +0 -59
  148. package/dist/service-management/handlers/ValidationHandler.js +0 -203
  149. package/dist/service-management/index.js +0 -14
  150. package/dist/service-management/routing/DomainRouteMapper.js +0 -311
  151. package/dist/service-management/routing/RouteGenerator.js +0 -266
  152. package/dist/service-management/routing/WranglerRoutesBuilder.js +0 -273
  153. package/dist/service-management/routing/index.js +0 -14
  154. package/dist/service-management/services/DirectoryStructureService.js +0 -56
  155. package/dist/service-management/services/GenerationCoordinator.js +0 -208
  156. package/dist/service-management/services/GeneratorRegistry.js +0 -174
  157. package/dist/services/GenericDataService.js +0 -501
  158. package/dist/ui-structures/concepts/second-order-acquisition-strategy.md +0 -286
  159. package/dist/ui-structures/concepts/service-lifecycle-management.md +0 -150
  160. package/dist/ui-structures/concepts/service-manifest-guide.md +0 -309
  161. package/dist/ui-structures/concepts/three-tier-categorization-strategy.md +0 -231
  162. package/dist/ui-structures/creation/automated-generation-ui.json +0 -246
  163. package/dist/ui-structures/creation/core-inputs-ui.json +0 -217
  164. package/dist/ui-structures/creation/smart-confirmable-ui.json +0 -451
  165. package/dist/ui-structures/reference/absolutely-required-inputs.json +0 -315
  166. package/dist/ui-structures/reference/service-manifest-template.json +0 -342
  167. package/dist/version/VersionDetector.js +0 -723
  168. package/dist/worker/index.js +0 -4
  169. package/dist/worker/integration.js +0 -351
@@ -1,453 +0,0 @@
1
- /**
2
- * Clodo Framework - Service Initializer
3
- * Programmatic API for initializing services with configurations
4
- */
5
-
6
- import { readdirSync } from 'fs';
7
- import { join, dirname, resolve } from 'path';
8
- import { fileURLToPath } from 'url';
9
- import { FileManager } from "../../dist/bin/shared/utils/file-manager.js";
10
-
11
- // Get framework root - handle both ES module and CommonJS environments
12
- const getFrameworkRoot = () => {
13
- try {
14
- // Try ES module approach
15
- const filename = fileURLToPath(import.meta.url);
16
- const dirname_ = dirname(filename);
17
- return resolve(dirname_, '..', '..');
18
- } catch (error) {
19
- // Fallback for test environments - use current working directory
20
- return process.cwd();
21
- }
22
- };
23
- const FRAMEWORK_ROOT = getFrameworkRoot();
24
- const TEMPLATES_DIR = join(FRAMEWORK_ROOT, 'templates');
25
- const SERVICE_TYPES = ['generic', 'data-service', 'auth-service', 'content-service', 'api-gateway'];
26
- export class ServiceInitializer {
27
- constructor(options = {}) {
28
- this.fileManager = new FileManager({
29
- enableCache: true
30
- });
31
- this.frameworkRoot = options.frameworkRoot || FRAMEWORK_ROOT;
32
- this.templatesDir = options.templatesDir || TEMPLATES_DIR;
33
- this.serviceTypes = options.serviceTypes || SERVICE_TYPES;
34
- }
35
-
36
- /**
37
- * Validate service name according to framework conventions
38
- * @param {string} name - Service name to validate
39
- * @throws {Error} If validation fails
40
- */
41
- validateServiceName(name) {
42
- if (!/^[a-z0-9-]+$/.test(name)) {
43
- throw new Error('Service name must contain only lowercase letters, numbers, and hyphens');
44
- }
45
- if (name.length < 3 || name.length > 50) {
46
- throw new Error('Service name must be between 3 and 50 characters');
47
- }
48
- }
49
-
50
- /**
51
- * Validate service type
52
- * @param {string} type - Service type to validate
53
- * @throws {Error} If type is invalid
54
- */
55
- validateServiceType(type) {
56
- if (!this.serviceTypes.includes(type)) {
57
- throw new Error(`Invalid service type. Must be one of: ${this.serviceTypes.join(', ')}`);
58
- }
59
- }
60
-
61
- /**
62
- * Initialize a service with auto-generated configurations
63
- * @param {string} serviceName - Name of the service to initialize
64
- * @param {Object} options - Initialization options
65
- * @param {string} options.type - Service type (default: 'generic')
66
- * @param {string} options.domains - Comma-separated list of domains
67
- * @param {string} options.env - Target environment (default: 'development')
68
- * @param {string} options.apiToken - Cloudflare API token
69
- * @param {string} options.accountId - Cloudflare account ID
70
- * @param {string} options.zoneId - Cloudflare zone ID
71
- * @param {string} options.output - Output directory (default: current directory)
72
- * @param {boolean} options.force - Overwrite existing directory (default: false)
73
- * @param {boolean} options.dryRun - Show what would be created without creating files (default: false)
74
- * @returns {Object} Initialization result
75
- */
76
- async initializeService(serviceName, options = {}) {
77
- const config = {
78
- type: 'generic',
79
- domains: '',
80
- env: 'development',
81
- output: process.cwd(),
82
- force: false,
83
- dryRun: false,
84
- ...options
85
- };
86
- try {
87
- // Validate inputs
88
- this.validateServiceName(serviceName);
89
- this.validateServiceType(config.type);
90
-
91
- // Parse domain information
92
- const domainInfo = this.parseDomainInfo(config, serviceName);
93
-
94
- // Generate configurations
95
- const configs = this.generateConfigurations(serviceName, config, domainInfo);
96
- if (config.dryRun) {
97
- return {
98
- success: true,
99
- dryRun: true,
100
- serviceName,
101
- configs
102
- };
103
- }
104
-
105
- // Create service structure
106
- this.createServiceStructure(serviceName, config, configs);
107
- return {
108
- success: true,
109
- serviceName,
110
- serviceType: config.type,
111
- serviceDir: join(config.output, 'services', serviceName),
112
- configs: Object.keys(configs),
113
- domainInfo
114
- };
115
- } catch (error) {
116
- return {
117
- success: false,
118
- serviceName,
119
- error: error.message
120
- };
121
- }
122
- }
123
-
124
- /**
125
- * Parse domain information from options
126
- * @param {Object} config - Configuration options
127
- * @param {string} serviceName - Service name
128
- * @returns {Object} Domain information
129
- */
130
- parseDomainInfo(config, serviceName) {
131
- const domainInfo = {
132
- domains: [],
133
- defaultAccountId: config.accountId || process.env.CLOUDFLARE_ACCOUNT_ID,
134
- defaultZoneId: config.zoneId || process.env.CLOUDFLARE_ZONE_ID,
135
- apiToken: config.apiToken || process.env.CLOUDFLARE_API_TOKEN
136
- };
137
-
138
- // Parse domains from command line - support format: domain[:accountId[:zoneId]]
139
- if (config.domains) {
140
- const domainSpecs = config.domains.split(',').map(d => d.trim());
141
- domainInfo.domains = domainSpecs.map(spec => {
142
- const parts = spec.split(':');
143
- return {
144
- domain: parts[0],
145
- accountId: parts[1] || domainInfo.defaultAccountId,
146
- zoneId: parts[2] || domainInfo.defaultZoneId,
147
- name: `${serviceName}-${parts[0].replace(/[^a-zA-Z0-9]/g, '-')}`
148
- };
149
- });
150
- }
151
-
152
- // If no domains specified, create a default one
153
- if (domainInfo.domains.length === 0) {
154
- domainInfo.domains.push({
155
- domain: `${serviceName}.example.com`,
156
- accountId: domainInfo.defaultAccountId,
157
- zoneId: domainInfo.defaultZoneId,
158
- name: `${serviceName}-default`
159
- });
160
- }
161
- return domainInfo;
162
- }
163
-
164
- /**
165
- * Generate all configurations for the service
166
- * @param {string} serviceName - Service name
167
- * @param {Object} config - Configuration options
168
- * @param {Object} domainInfo - Domain information
169
- * @returns {Object} Generated configurations
170
- */
171
- generateConfigurations(serviceName, config, domainInfo) {
172
- const configs = {};
173
-
174
- // Generate wrangler.toml
175
- Object.assign(configs, this.generateWranglerConfig(serviceName, config, domainInfo));
176
-
177
- // Generate domains.js
178
- configs['src/config/domains.js'] = this.generateDomainsConfig(serviceName, config, domainInfo);
179
-
180
- // Generate package.json
181
- configs['package.json'] = this.generatePackageJson(serviceName, config);
182
-
183
- // Generate README.md
184
- configs['README.md'] = this.generateReadme(serviceName, config, domainInfo);
185
- return configs;
186
- }
187
-
188
- /**
189
- * Generate Wrangler configuration
190
- * @param {string} serviceName - Service name
191
- * @param {Object} config - Configuration options
192
- * @param {Object} domainInfo - Domain information
193
- * @returns {Object} Wrangler configurations
194
- */
195
- generateWranglerConfig(serviceName, config, domainInfo) {
196
- const env = config.env;
197
-
198
- // For multiple domains, generate separate wrangler files
199
- if (domainInfo.domains.length > 1) {
200
- const wranglerConfigs = {};
201
- domainInfo.domains.forEach(domainConfig => {
202
- const configName = `wrangler.${domainConfig.name}.toml`;
203
- wranglerConfigs[configName] = this.generateSingleWranglerConfig(domainConfig.name, env, config, domainConfig, serviceName);
204
- });
205
- return wranglerConfigs;
206
- }
207
-
208
- // For single domain, generate single wrangler.toml
209
- return {
210
- 'wrangler.toml': this.generateSingleWranglerConfig(`${serviceName}-${env}`, env, config, domainInfo.domains[0], serviceName)
211
- };
212
- }
213
-
214
- /**
215
- * Generate single Wrangler configuration
216
- * @param {string} name - Configuration name
217
- * @param {string} env - Environment
218
- * @param {Object} config - Configuration options
219
- * @param {Object} domainConfig - Domain configuration
220
- * @param {string} serviceName - Service name
221
- * @returns {string} Wrangler TOML content
222
- */
223
- generateSingleWranglerConfig(name, env, config, domainConfig, serviceName) {
224
- const isProduction = env === 'production';
225
- let wranglerConfig = `name = "${name}"
226
- main = "src/worker/index.js"
227
- compatibility_date = "${new Date().toISOString().split('T')[0]}"
228
-
229
- `;
230
- if (!isProduction) {
231
- wranglerConfig += `[env.${env}]
232
- name = "${name}"
233
-
234
- `;
235
- }
236
- wranglerConfig += `[env.production]
237
- name = "${name.replace(`-${env}`, '')}-production"
238
-
239
- `;
240
-
241
- // Add D1 databases for data services
242
- if (config.type === 'data-service') {
243
- wranglerConfig += `# Database bindings
244
- [[d1_databases]]
245
- binding = "${name.toUpperCase().replace(/[^A-Z0-9]/g, '_')}_DB"
246
- database_name = "${name}-db"
247
-
248
- `;
249
- }
250
-
251
- // Environment variables
252
- wranglerConfig += `# Environment variables
253
- [vars]
254
- DOMAIN_NAME = "${domainConfig.domain}"
255
- ENVIRONMENT = "${env}"
256
- SERVICE_NAME = "${serviceName}"
257
- SERVICE_TYPE = "${config.type}"
258
- DOMAIN_CONFIG = "${domainConfig.name}"
259
-
260
- `;
261
-
262
- // Add service-specific environment variables
263
- if (config.type === 'auth-service') {
264
- wranglerConfig += `JWT_SECRET = "change-in-production"
265
- AUTH_PROVIDERS = "google,github"
266
- `;
267
- } else if (config.type === 'api-gateway') {
268
- wranglerConfig += `RATE_LIMIT_REQUESTS = "100"
269
- RATE_LIMIT_WINDOW_MS = "60000"
270
- ENABLE_CORS = "true"
271
- `;
272
- }
273
- return wranglerConfig;
274
- }
275
-
276
- /**
277
- * Generate domains configuration
278
- * @param {string} serviceName - Service name
279
- * @param {Object} config - Configuration options
280
- * @param {Object} domainInfo - Domain information
281
- * @returns {string} Domains configuration content
282
- */
283
- generateDomainsConfig(serviceName, config, domainInfo) {
284
- let domainsConfig = `import { createDomainConfigSchema } from '@tamyla/clodo-framework';
285
-
286
- /**
287
- * Domain configurations for ${serviceName}
288
- *
289
- * Auto-generated by Clodo Framework Service Initializer
290
- * Generated on: ${new Date().toISOString()}
291
- *
292
- * This service supports multiple domains with domain-specific configurations
293
- */
294
-
295
- export const domains = [
296
- `;
297
- domainInfo.domains.forEach((domain, index) => {
298
- domainsConfig += ` {
299
- name: '${domain.name}',
300
- domain: '${domain.domain}',
301
- accountId: '${domain.accountId || 'your-account-id'}',
302
- zoneId: '${domain.zoneId || 'your-zone-id'}',
303
- environment: '${config.env}',
304
- ssl: true,
305
- cors: ${config.type === 'api-gateway' ? 'true' : 'false'}
306
- }`;
307
- if (index < domainInfo.domains.length - 1) {
308
- domainsConfig += ',';
309
- }
310
- domainsConfig += '\n';
311
- });
312
- domainsConfig += `];
313
-
314
- export const domainConfigSchema = createDomainConfigSchema();
315
- `;
316
- return domainsConfig;
317
- }
318
-
319
- /**
320
- * Generate package.json for the service
321
- * @param {string} serviceName - Service name
322
- * @param {Object} config - Configuration options
323
- * @returns {string} Package.json content
324
- */
325
- generatePackageJson(serviceName, config) {
326
- const packageJson = {
327
- name: serviceName,
328
- version: '1.0.0',
329
- description: `${config.type} service created with Clodo Framework`,
330
- type: 'module',
331
- main: 'dist/index.js',
332
- scripts: {
333
- build: 'babel src --out-dir dist --copy-files',
334
- dev: 'wrangler dev',
335
- deploy: 'wrangler deploy',
336
- test: 'jest',
337
- setup: 'node setup.js'
338
- },
339
- dependencies: {
340
- '@tamyla/clodo-framework': '^3.0.5'
341
- },
342
- devDependencies: {
343
- '@babel/cli': '^7.0.0',
344
- '@babel/core': '^7.0.0',
345
- '@babel/preset-env': '^7.0.0',
346
- 'jest': '^29.0.0',
347
- 'wrangler': '^3.0.0'
348
- },
349
- keywords: ['cloudflare', 'workers', 'clodo-framework', config.type],
350
- author: 'Generated by Clodo Framework',
351
- license: 'MIT'
352
- };
353
- return JSON.stringify(packageJson, null, 2);
354
- }
355
-
356
- /**
357
- * Generate README for the service
358
- * @param {string} serviceName - Service name
359
- * @param {Object} config - Configuration options
360
- * @param {Object} domainInfo - Domain information
361
- * @returns {string} README content
362
- */
363
- generateReadme(serviceName, config, domainInfo) {
364
- return `# ${serviceName}
365
-
366
- ${config.type} service created with Clodo Framework.
367
-
368
- ## Setup
369
-
370
- \`\`\`bash
371
- npm install
372
- npm run setup
373
- \`\`\`
374
-
375
- ## Development
376
-
377
- \`\`\`bash
378
- npm run dev
379
- \`\`\`
380
-
381
- ## Deployment
382
-
383
- \`\`\`bash
384
- npm run deploy
385
- \`\`\`
386
-
387
- ## Domains
388
-
389
- ${domainInfo.domains.map(d => `- ${d.domain}`).join('\n')}
390
-
391
- ## Environment
392
-
393
- - **Environment**: ${config.env}
394
- - **Type**: ${config.type}
395
- - **Generated**: ${new Date().toISOString()}
396
- `;
397
- }
398
-
399
- /**
400
- * Create the service directory structure and write configurations
401
- * @param {string} serviceName - Service name
402
- * @param {Object} config - Configuration options
403
- * @param {Object} configs - Generated configurations
404
- */
405
- createServiceStructure(serviceName, config, configs) {
406
- const servicesDir = join(config.output, 'services');
407
- const serviceDir = join(servicesDir, serviceName);
408
-
409
- // Create directories
410
- this.fileManager.ensureDir(servicesDir);
411
- this.fileManager.ensureDir(serviceDir);
412
- this.fileManager.ensureDir(join(serviceDir, 'src', 'config'));
413
- this.fileManager.ensureDir(join(serviceDir, 'src', 'worker'));
414
-
415
- // Write configuration files
416
- for (const [filePath, content] of Object.entries(configs)) {
417
- const fullPath = join(serviceDir, filePath);
418
- this.fileManager.ensureDir(dirname(fullPath));
419
- this.fileManager.writeFile(fullPath, content, 'utf8');
420
- }
421
-
422
- // Create basic worker file
423
- const workerContent = `import { ClodoWorker } from '@tamyla/clodo-framework/worker';
424
- import { domains } from './config/domains.js';
425
-
426
- export default {
427
- async fetch(request, env, ctx) {
428
- const worker = new ClodoWorker({
429
- domains,
430
- environment: env
431
- });
432
-
433
- return worker.handleRequest(request, env, ctx);
434
- }
435
- };
436
- `;
437
- this.fileManager.writeFile(join(serviceDir, 'src', 'worker', 'index.js'), workerContent, 'utf8');
438
- }
439
-
440
- /**
441
- * Get available service types
442
- * @returns {string[]} Array of available service types
443
- */
444
- getServiceTypes() {
445
- return [...this.serviceTypes];
446
- }
447
- }
448
-
449
- // Convenience function for quick service initialization
450
- export async function initializeService(serviceName, options = {}) {
451
- const initializer = new ServiceInitializer();
452
- return await initializer.initializeService(serviceName, options);
453
- }