@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,633 +0,0 @@
1
- /**
2
- * ServiceOrchestrator - Unified Three-Tier Service Management
3
- *
4
- * Coordinates the three-tier service creation process:
5
- * 1. Core Input Collection (6 required inputs)
6
- * 2. Smart Confirmations (15 derived values)
7
- * 3. Automated Generation (67 configurations + service manifest)
8
- */
9
-
10
- // Modular handler imports
11
- import { InputHandler } from './handlers/InputHandler.js';
12
- import { ConfirmationHandler } from './handlers/ConfirmationHandler.js';
13
- import { GenerationHandler } from './handlers/GenerationHandler.js';
14
- import { WranglerConfigManager } from '../utils/deployment/wrangler-config-manager.js';
15
- import { ValidationHandler } from './handlers/ValidationHandler.js';
16
-
17
- // Legacy imports for backward compatibility
18
- import { ServiceCreator } from './ServiceCreator.js';
19
- import { ErrorTracker } from './ErrorTracker.js';
20
- import chalk from 'chalk';
21
- import fs from 'fs/promises';
22
- import path from 'path';
23
- export class ServiceOrchestrator {
24
- constructor(options = {}) {
25
- this.interactive = options.interactive !== false;
26
- this.outputPath = options.outputPath || '.';
27
- this.templatePath = options.templatePath || './templates';
28
-
29
- // Initialize modular handler components
30
- this.inputHandler = new InputHandler({
31
- interactive: this.interactive
32
- });
33
- this.confirmationHandler = new ConfirmationHandler({
34
- interactive: this.interactive
35
- });
36
- this.generationHandler = new GenerationHandler({
37
- outputPath: this.outputPath,
38
- templatePath: this.templatePath
39
- });
40
- this.wranglerConfigManager = null; // Initialized when needed with specific config path
41
- this.validationHandler = new ValidationHandler();
42
-
43
- // Initialize legacy components for backward compatibility
44
- this.serviceCreator = new ServiceCreator();
45
- this.errorTracker = new ErrorTracker();
46
- }
47
-
48
- /**
49
- * Run the complete three-tier service creation process interactively
50
- */
51
- async runInteractive() {
52
- console.log(chalk.cyan('🚀 Clodo Framework - Interactive Service Creator'));
53
- console.log(chalk.white('Welcome to the unified service creation wizard!\n'));
54
- try {
55
- // Tier 1: Collect 6 core inputs
56
- console.log(chalk.yellow('📝 Tier 1: Core Input Collection'));
57
- console.log(chalk.white('Collecting 6 required inputs for your service...\n'));
58
- const coreInputs = await this.inputHandler.collectCoreInputs();
59
-
60
- // Tier 2: Smart confirmations for 15 derived values
61
- const confirmedValues = await this.confirmationHandler.generateAndConfirm(coreInputs);
62
-
63
- // Tier 3: Automated generation of 67 components
64
- console.log(chalk.yellow('⚙️ Tier 3: Automated Generation'));
65
- console.log(chalk.white('Generating 67 configuration files and service components...\n'));
66
- const generationResult = await this.generationHandler.generateService(coreInputs, confirmedValues, {
67
- outputPath: this.outputPath
68
- });
69
-
70
- // Display results
71
- this.displayResults(generationResult);
72
- } catch (error) {
73
- throw new Error(`Service creation failed: ${error.message}`);
74
- }
75
- }
76
-
77
- /**
78
- * Run service creation in non-interactive mode with provided inputs
79
- */
80
- async runNonInteractive(coreInputs) {
81
- console.log(chalk.cyan('🚀 Clodo Framework - Non-Interactive Service Creator'));
82
- try {
83
- // Validate inputs
84
- await this.inputHandler.validateCoreInputs(coreInputs);
85
-
86
- // Generate derived values automatically
87
- const confirmedValues = await this.confirmationHandler.generateAndConfirm(coreInputs);
88
-
89
- // Generate service using GenerationHandler
90
- const generationResult = await this.generationHandler.generateService(coreInputs, confirmedValues, {
91
- outputPath: this.outputPath
92
- });
93
- console.log(chalk.green(`✓ Service "${coreInputs.serviceName}" created successfully`));
94
- } catch (error) {
95
- throw new Error(`Non-interactive service creation failed: ${error.message}`);
96
- }
97
- }
98
-
99
- /**
100
- * Validate an existing service configuration
101
- */
102
- async validateService(servicePath) {
103
- return await this.validationHandler.validateService(servicePath);
104
- }
105
-
106
- /**
107
- * Run comprehensive service diagnostics (delegated to ValidationHandler)
108
- */
109
- async diagnoseServiceBasic(servicePath, options = {}) {
110
- return await this.validationHandler.diagnoseService(servicePath);
111
- }
112
-
113
- /**
114
- * Legacy validateService implementation for compatibility
115
- */
116
- async _legacyValidateService(servicePath) {
117
- try {
118
- const issues = [];
119
-
120
- // Check for required files
121
- const requiredFiles = ['package.json', 'src/config/domains.js', 'src/worker/index.js', 'wrangler.toml'];
122
- for (const file of requiredFiles) {
123
- const filePath = path.join(servicePath, file);
124
- try {
125
- await fs.access(filePath);
126
- } catch {
127
- issues.push(`Missing required file: ${file}`);
128
- }
129
- }
130
-
131
- // Validate package.json
132
- try {
133
- const packageJson = JSON.parse(await fs.readFile(path.join(servicePath, 'package.json'), 'utf8'));
134
- if (!packageJson.name || !packageJson.version) {
135
- issues.push('Invalid package.json: missing name or version');
136
- }
137
- } catch {
138
- issues.push('Invalid package.json format');
139
- }
140
-
141
- // Validate domain configuration
142
- try {
143
- const domainConfig = await fs.readFile(path.join(servicePath, 'src/config/domains.js'), 'utf8');
144
- if (!domainConfig.includes('createDomainConfigSchema')) {
145
- issues.push('Domain configuration missing Clodo Framework integration');
146
- }
147
- } catch {
148
- issues.push('Cannot read domain configuration');
149
- }
150
- return {
151
- valid: issues.length === 0,
152
- issues
153
- };
154
- } catch (error) {
155
- throw new Error(`Service validation failed: ${error.message}`);
156
- }
157
- }
158
-
159
- /**
160
- * Display generation results to user
161
- */
162
- displayResults(generationResult) {
163
- console.log(chalk.green('\n✅ Service Generation Complete!'));
164
- if (generationResult.serviceManifest) {
165
- // New GenerationEngine format
166
- console.log(chalk.white(`Service: ${generationResult.serviceName}`));
167
- console.log(chalk.white(`Path: ${generationResult.servicePath}`));
168
- console.log(chalk.white(`Files Generated: ${generationResult.fileCount}`));
169
- console.log(chalk.cyan('\n📁 Generated Files:'));
170
- generationResult.generatedFiles.forEach(file => {
171
- console.log(chalk.white(` ✓ ${path.relative(process.cwd(), file)}`));
172
- });
173
- console.log(chalk.cyan('\n📋 Service Manifest:'));
174
- console.log(chalk.white(` Location: clodo-service-manifest.json`));
175
- } else {
176
- // Legacy format (for backward compatibility)
177
- console.log(chalk.white(`Service: ${generationResult.serviceName}`));
178
- console.log(chalk.white(`Type: ${generationResult.serviceType}`));
179
- console.log(chalk.white(`Domain: ${generationResult.domainName}`));
180
- console.log(chalk.white(`Environment: ${generationResult.environment}`));
181
- console.log(chalk.cyan('\n📁 Generated Files:'));
182
- generationResult.generatedFiles.forEach(file => {
183
- console.log(chalk.white(` ✓ ${file}`));
184
- });
185
- console.log(chalk.cyan('\n🔧 Configured Features:'));
186
- generationResult.features.forEach(feature => {
187
- console.log(chalk.white(` ✓ ${feature}`));
188
- });
189
- if (generationResult.serviceManifest) {
190
- console.log(chalk.cyan('\n📋 Service Manifest:'));
191
- console.log(chalk.white(` Location: ${generationResult.serviceManifest}`));
192
- }
193
- }
194
- }
195
-
196
- /**
197
- * Auto-detect service path from current working directory
198
- */
199
- async detectServicePath() {
200
- try {
201
- // Check if current directory is a service
202
- const currentDir = process.cwd();
203
- if (await this.isServiceDirectory(currentDir)) {
204
- return currentDir;
205
- }
206
-
207
- // Check parent directories
208
- let checkDir = path.dirname(currentDir);
209
- while (checkDir !== path.dirname(checkDir)) {
210
- // Stop at root
211
- if (await this.isServiceDirectory(checkDir)) {
212
- return checkDir;
213
- }
214
- checkDir = path.dirname(checkDir);
215
- }
216
- return null;
217
- } catch (error) {
218
- return null;
219
- }
220
- }
221
-
222
- /**
223
- * Check if a directory is a Clodo service
224
- */
225
- async isServiceDirectory(dirPath) {
226
- try {
227
- const requiredFiles = ['package.json', 'src/config/domains.js', 'wrangler.toml'];
228
- for (const file of requiredFiles) {
229
- await fs.access(path.join(dirPath, file));
230
- }
231
- return true;
232
- } catch {
233
- return false;
234
- }
235
- }
236
-
237
- /**
238
- * Run interactive service update
239
- */
240
- async runInteractiveUpdate(servicePath) {
241
- console.log(chalk.cyan('🔄 Interactive Service Update'));
242
- console.log(chalk.white(`Updating service at: ${servicePath}\n`));
243
-
244
- // Load current service configuration
245
- const currentConfig = await this.loadServiceConfiguration(servicePath);
246
- console.log(chalk.cyan('Current Configuration:'));
247
- console.log(chalk.white(` Service: ${currentConfig.serviceName}`));
248
- console.log(chalk.white(` Type: ${currentConfig.serviceType}`));
249
- console.log(chalk.white(` Domain: ${currentConfig.domainName}`));
250
- console.log(chalk.white(` Environment: ${currentConfig.environment}\n`));
251
-
252
- // Interactive update menu
253
- const updateOptions = {
254
- 1: {
255
- name: 'Domain Configuration',
256
- action: () => this.updateDomainConfig(servicePath, currentConfig)
257
- },
258
- 2: {
259
- name: 'Cloudflare Settings',
260
- action: () => this.updateCloudflareConfig(servicePath, currentConfig)
261
- },
262
- 3: {
263
- name: 'Environment Settings',
264
- action: () => this.updateEnvironmentConfig(servicePath, currentConfig)
265
- },
266
- 4: {
267
- name: 'Feature Flags',
268
- action: () => this.updateFeatureFlags(servicePath, currentConfig)
269
- },
270
- 5: {
271
- name: 'Regenerate All Configs',
272
- action: () => this.regenerateAllConfigs(servicePath, currentConfig)
273
- },
274
- 6: {
275
- name: 'Fix Configuration Errors',
276
- action: () => this.fixConfigurationErrors(servicePath)
277
- }
278
- };
279
- for (;;) {
280
- console.log(chalk.cyan('What would you like to update?'));
281
- Object.entries(updateOptions).forEach(([key, option]) => {
282
- console.log(chalk.white(` ${key}. ${option.name}`));
283
- });
284
- console.log(chalk.white(' 0. Exit update mode\n'));
285
- const choice = await this.promptUser('Enter your choice (0-6): ');
286
- if (choice === '0') {
287
- break;
288
- }
289
- const option = updateOptions[choice];
290
- if (option) {
291
- try {
292
- await option.action();
293
- console.log(chalk.green(`✓ ${option.name} updated successfully`));
294
- } catch (error) {
295
- this.errorTracker.captureError(error, {
296
- action: option.name,
297
- servicePath
298
- });
299
- console.log(chalk.red(`✗ Failed to update ${option.name}: ${error.message}`));
300
- }
301
- } else {
302
- console.log(chalk.red('Invalid choice. Please select 0-6.'));
303
- }
304
- }
305
- }
306
-
307
- /**
308
- * Run non-interactive service update
309
- */
310
- async runNonInteractiveUpdate(servicePath, options) {
311
- console.log(chalk.cyan('🔄 Non-Interactive Service Update'));
312
- const currentConfig = await this.loadServiceConfiguration(servicePath);
313
- let hasChanges = false;
314
- try {
315
- // Update domain if specified
316
- if (options.domainName) {
317
- await this.updateDomainConfig(servicePath, currentConfig, {
318
- domainName: options.domainName
319
- });
320
- hasChanges = true;
321
- }
322
-
323
- // Update Cloudflare settings
324
- if (options.cloudflareToken || options.cloudflareAccountId || options.cloudflareZoneId) {
325
- const cfUpdates = {};
326
- if (options.cloudflareToken) cfUpdates.token = options.cloudflareToken;
327
- if (options.cloudflareAccountId) cfUpdates.accountId = options.cloudflareAccountId;
328
- if (options.cloudflareZoneId) cfUpdates.zoneId = options.cloudflareZoneId;
329
- await this.updateCloudflareConfig(servicePath, currentConfig, cfUpdates);
330
- hasChanges = true;
331
- }
332
-
333
- // Update environment
334
- if (options.environment) {
335
- await this.updateEnvironmentConfig(servicePath, currentConfig, {
336
- environment: options.environment
337
- });
338
- hasChanges = true;
339
- }
340
-
341
- // Update features
342
- if (options.addFeature || options.removeFeature) {
343
- const featureUpdates = {};
344
- if (options.addFeature) featureUpdates.add = options.addFeature;
345
- if (options.removeFeature) featureUpdates.remove = options.removeFeature;
346
- await this.updateFeatureFlags(servicePath, currentConfig, featureUpdates);
347
- hasChanges = true;
348
- }
349
-
350
- // Regenerate configs if requested
351
- if (options.regenerateConfigs) {
352
- await this.regenerateAllConfigs(servicePath, currentConfig);
353
- hasChanges = true;
354
- }
355
-
356
- // Fix errors if requested
357
- if (options.fixErrors) {
358
- await this.fixConfigurationErrors(servicePath);
359
- hasChanges = true;
360
- }
361
- if (!hasChanges) {
362
- console.log(chalk.yellow('No update options specified. Use --help to see available options.'));
363
- }
364
- } catch (error) {
365
- this.errorTracker.captureError(error, {
366
- options,
367
- servicePath
368
- });
369
- throw error;
370
- }
371
- }
372
-
373
- /**
374
- * Load current service configuration
375
- */
376
- async loadServiceConfiguration(servicePath) {
377
- try {
378
- // Load package.json
379
- const packageJson = JSON.parse(await fs.readFile(path.join(servicePath, 'package.json'), 'utf8'));
380
-
381
- // Load domain configuration
382
- const domainConfig = await fs.readFile(path.join(servicePath, 'src/config/domains.js'), 'utf8');
383
-
384
- // Extract configuration from domain config (simplified parsing)
385
- const config = {
386
- serviceName: packageJson.name,
387
- serviceType: this.extractServiceTypeFromConfig(domainConfig),
388
- domainName: this.extractDomainFromConfig(domainConfig),
389
- environment: this.extractEnvironmentFromConfig(domainConfig),
390
- cloudflareAccountId: this.extractCloudflareAccountId(domainConfig),
391
- cloudflareZoneId: this.extractCloudflareZoneId(domainConfig),
392
- features: this.extractFeaturesFromConfig(domainConfig)
393
- };
394
- return config;
395
- } catch (error) {
396
- throw new Error(`Failed to load service configuration: ${error.message}`);
397
- }
398
- }
399
-
400
- /**
401
- * Update domain configuration
402
- * @deprecated Use WranglerConfigManager directly for wrangler.toml updates
403
- */
404
- async updateDomainConfig(servicePath, currentConfig, updates = null) {
405
- console.log(chalk.yellow('⚠️ updateDomainConfig is deprecated. Use WranglerConfigManager for wrangler.toml updates.'));
406
- throw new Error('updateDomainConfig is deprecated. Please use WranglerConfigManager directly.');
407
- }
408
-
409
- /**
410
- * Update Cloudflare configuration
411
- * @deprecated Use WranglerConfigManager directly for wrangler.toml updates
412
- */
413
- async updateCloudflareConfig(servicePath, currentConfig, updates = null) {
414
- console.log(chalk.yellow('⚠️ updateCloudflareConfig is deprecated. Use WranglerConfigManager for wrangler.toml updates.'));
415
- throw new Error('updateCloudflareConfig is deprecated. Please use WranglerConfigManager directly.');
416
- }
417
-
418
- /**
419
- * Update environment configuration
420
- * @deprecated Use WranglerConfigManager directly for wrangler.toml updates
421
- */
422
- async updateEnvironmentConfig(servicePath, currentConfig, updates = null) {
423
- console.log(chalk.yellow('⚠️ updateEnvironmentConfig is deprecated. Use WranglerConfigManager for wrangler.toml updates.'));
424
- throw new Error('updateEnvironmentConfig is deprecated. Please use WranglerConfigManager directly.');
425
- }
426
-
427
- /**
428
- * Update feature flags using ConfigMutator
429
- */
430
- async updateFeatureFlags(servicePath, currentConfig, updates = null) {
431
- return await this.configMutator.updateFeatureConfig(servicePath, currentConfig, updates);
432
- }
433
-
434
- /**
435
- * Regenerate all configuration files
436
- */
437
- async regenerateAllConfigs(servicePath, currentConfig) {
438
- console.log(chalk.cyan('Regenerating all configuration files...'));
439
-
440
- // This would call the generation engine to recreate all configs
441
- // For now, just mark as needing implementation
442
- console.log(chalk.yellow('⚠️ Config regeneration not yet implemented'));
443
- }
444
-
445
- /**
446
- * Fix common configuration errors
447
- */
448
- async fixConfigurationErrors(servicePath) {
449
- console.log(chalk.cyan('Attempting to fix configuration errors...'));
450
- const issues = await this.validateService(servicePath);
451
- if (issues.valid) {
452
- console.log(chalk.green('No issues found to fix'));
453
- return;
454
- }
455
-
456
- // Attempt to fix common issues
457
- for (const issue of issues.issues) {
458
- try {
459
- if (issue.includes('Missing required file')) {
460
- console.log(chalk.yellow(`Cannot auto-fix missing file: ${issue}`));
461
- } else if (issue.includes('Invalid package.json')) {
462
- console.log(chalk.yellow(`Cannot auto-fix package.json: ${issue}`));
463
- } else {
464
- console.log(chalk.yellow(`Unknown issue, cannot auto-fix: ${issue}`));
465
- }
466
- } catch (error) {
467
- console.log(chalk.red(`Failed to fix issue: ${error.message}`));
468
- }
469
- }
470
- }
471
-
472
- /**
473
- * Diagnose service issues
474
- */
475
- async diagnoseService(servicePath, options = {}) {
476
- console.log(chalk.cyan('🔍 Running comprehensive service diagnosis...'));
477
- const diagnosis = {
478
- serviceName: null,
479
- errors: [],
480
- warnings: [],
481
- recommendations: []
482
- };
483
- try {
484
- // Load basic configuration
485
- const config = await this.loadServiceConfiguration(servicePath);
486
- diagnosis.serviceName = config.serviceName;
487
-
488
- // Check file structure
489
- const requiredFiles = ['package.json', 'src/config/domains.js', 'src/worker/index.js', 'wrangler.toml'];
490
- for (const file of requiredFiles) {
491
- try {
492
- await fs.access(path.join(servicePath, file));
493
- } catch {
494
- diagnosis.errors.push({
495
- message: `Missing required file: ${file}`,
496
- location: servicePath,
497
- suggestion: `Run 'clodo-service update --regenerate-configs' to recreate missing files`
498
- });
499
- }
500
- }
501
-
502
- // Validate package.json
503
- try {
504
- const packageJson = JSON.parse(await fs.readFile(path.join(servicePath, 'package.json'), 'utf8'));
505
- if (!packageJson.name) {
506
- diagnosis.errors.push({
507
- message: 'package.json missing name field',
508
- location: 'package.json',
509
- suggestion: 'Add a name field to package.json'
510
- });
511
- }
512
- } catch (error) {
513
- diagnosis.errors.push({
514
- message: `Invalid package.json: ${error.message}`,
515
- location: 'package.json',
516
- suggestion: 'Fix JSON syntax in package.json'
517
- });
518
- }
519
-
520
- // Check domain configuration
521
- try {
522
- const domainConfig = await fs.readFile(path.join(servicePath, 'src/config/domains.js'), 'utf8');
523
- if (!domainConfig.includes('createDomainConfigSchema')) {
524
- diagnosis.warnings.push({
525
- message: 'Domain configuration may not be using Clodo Framework schema',
526
- location: 'src/config/domains.js',
527
- suggestion: 'Ensure domain config uses createDomainConfigSchema from @tamyla/clodo-framework'
528
- });
529
- }
530
- } catch (error) {
531
- diagnosis.errors.push({
532
- message: 'Cannot read domain configuration',
533
- location: 'src/config/domains.js',
534
- suggestion: 'Check file permissions and syntax'
535
- });
536
- }
537
-
538
- // Deep scan if requested
539
- if (options.deepScan) {
540
- // Check for common issues
541
- diagnosis.recommendations.push('Consider running tests to validate service functionality');
542
- diagnosis.recommendations.push('Check Cloudflare authentication if deployment fails');
543
- diagnosis.recommendations.push('Verify all dependencies are installed with npm install');
544
- }
545
- } catch (error) {
546
- diagnosis.errors.push({
547
- message: `Diagnosis failed: ${error.message}`,
548
- location: 'general',
549
- suggestion: 'Check service directory structure and permissions'
550
- });
551
- }
552
- return diagnosis;
553
- }
554
-
555
- /**
556
- * Export diagnostic report
557
- */
558
- async exportDiagnosticReport(diagnosis, filePath) {
559
- const report = {
560
- timestamp: new Date().toISOString(),
561
- serviceName: diagnosis.serviceName,
562
- summary: {
563
- errors: diagnosis.errors.length,
564
- warnings: diagnosis.warnings.length,
565
- recommendations: diagnosis.recommendations.length
566
- },
567
- errors: diagnosis.errors,
568
- warnings: diagnosis.warnings,
569
- recommendations: diagnosis.recommendations
570
- };
571
- await fs.writeFile(filePath, JSON.stringify(report, null, 2), 'utf8');
572
- }
573
-
574
- /**
575
- * Generate service using legacy ServiceCreator (placeholder for GenerationEngine)
576
- */
577
- async generateWithLegacyCreator({
578
- coreInputs,
579
- confirmedValues,
580
- outputPath,
581
- templatePath
582
- }) {
583
- console.log(chalk.gray('Using legacy ServiceCreator for generation...\n'));
584
-
585
- // This would normally use the GenerationEngine, but for now we'll create a basic result
586
- return {
587
- serviceName: coreInputs.serviceName,
588
- serviceType: coreInputs.serviceType,
589
- domainName: coreInputs.domainName,
590
- environment: coreInputs.environment,
591
- generatedFiles: ['package.json', 'src/config/domains.js', 'src/worker/index.js', 'wrangler.toml', 'README.md'],
592
- features: Object.keys(confirmedValues.features || {}),
593
- serviceManifest: null // TODO: Generate service manifest
594
- };
595
- }
596
-
597
- /**
598
- * Prompt user for input using shared PromptHandler
599
- */
600
- async promptUser(question) {
601
- if (!this.interactive) {
602
- return '';
603
- }
604
- return await this.confirmationHandler.promptHandler.prompt(question);
605
- }
606
-
607
- // Helper methods for extracting config values (simplified implementations)
608
- extractServiceTypeFromConfig(config) {
609
- return 'generic';
610
- }
611
- extractDomainFromConfig(config) {
612
- return 'unknown';
613
- }
614
- extractEnvironmentFromConfig(config) {
615
- return 'development';
616
- }
617
- extractCloudflareAccountId(config) {
618
- return null;
619
- }
620
- extractCloudflareZoneId(config) {
621
- return null;
622
- }
623
- extractFeaturesFromConfig(config) {
624
- return [];
625
- }
626
-
627
- /**
628
- * Escape special regex characters for safe replacement
629
- */
630
- escapeRegExp(string) {
631
- return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
632
- }
633
- }