@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,123 +0,0 @@
1
- import { BaseGenerator } from '../BaseGenerator.js';
2
- import { join } from 'path';
3
-
4
- /**
5
- * DeployScriptGenerator
6
- *
7
- * Generates scripts/deploy.ps1 PowerShell deployment script.
8
- */
9
- export class DeployScriptGenerator extends BaseGenerator {
10
- constructor(options = {}) {
11
- super({
12
- name: 'DeployScriptGenerator',
13
- description: 'Generates PowerShell deployment script',
14
- outputPath: 'scripts/deploy.ps1',
15
- ...options
16
- });
17
- }
18
- shouldGenerate(context) {
19
- return true;
20
- }
21
- async generate(context) {
22
- const coreInputs = context.coreInputs || context;
23
- const confirmedValues = context.confirmedValues || context;
24
- const servicePath = context.servicePath || context.outputDir;
25
- this.setContext({
26
- coreInputs,
27
- confirmedValues,
28
- servicePath
29
- });
30
- const content = `#!/usr/bin/env pwsh
31
-
32
- <#
33
- .SYNOPSIS
34
- Deploy ${confirmedValues.displayName} to Cloudflare
35
-
36
- .DESCRIPTION
37
- Automated deployment script for ${confirmedValues.displayName}
38
- Handles database setup, worker deployment, and environment configuration
39
-
40
- .PARAMETER Environment
41
- Target environment (development, staging, production)
42
-
43
- .PARAMETER SkipTests
44
- Skip running tests before deployment
45
-
46
- .EXAMPLE
47
- .\\scripts\\deploy.ps1 -Environment production
48
-
49
- .EXAMPLE
50
- .\\scripts\\deploy.ps1 -Environment staging -SkipTests
51
- #>
52
-
53
- param(
54
- [Parameter(Mandatory = $false)]
55
- [ValidateSet('development', 'staging', 'production')]
56
- [string]$Environment = 'development',
57
-
58
- [Parameter(Mandatory = $false)]
59
- [switch]$SkipTests
60
- )
61
-
62
- Write-Host "🚀 Deploying ${confirmedValues.displayName} to $Environment" -ForegroundColor Cyan
63
-
64
- # Load environment variables
65
- if (Test-Path ".env") {
66
- Write-Host "📄 Loading environment variables from .env" -ForegroundColor Gray
67
- Get-Content ".env" | ForEach-Object {
68
- if ($_ -match '^([^=]+)=(.*)$') {
69
- $key = $matches[1]
70
- $value = $matches[2]
71
- [Environment]::SetEnvironmentVariable($key, $value)
72
- }
73
- }
74
- }
75
-
76
- try {
77
- # Run tests unless skipped
78
- if (-not $SkipTests) {
79
- Write-Host "🧪 Running tests..." -ForegroundColor Yellow
80
- npm test
81
- if ($LASTEXITCODE -ne 0) {
82
- throw "Tests failed. Aborting deployment."
83
- }
84
- }
85
-
86
- # Lint code
87
- Write-Host "🔍 Running linter..." -ForegroundColor Yellow
88
- npm run lint
89
- if ($LASTEXITCODE -ne 0) {
90
- throw "Linting failed. Aborting deployment."
91
- }
92
-
93
- # Deploy to Cloudflare
94
- Write-Host "☁️ Deploying to Cloudflare Workers..." -ForegroundColor Yellow
95
- npx wrangler deploy --env $Environment
96
-
97
- if ($LASTEXITCODE -ne 0) {
98
- throw "Cloudflare deployment failed."
99
- }
100
-
101
- # Run health check
102
- Write-Host "🏥 Running health check..." -ForegroundColor Yellow
103
- .\\scripts\\health-check.ps1 -Environment $Environment
104
-
105
- Write-Host "✅ Deployment completed successfully!" -ForegroundColor Green
106
- Write-Host "🌐 Service URL: ${confirmedValues.productionUrl}" -ForegroundColor Cyan
107
-
108
- } catch {
109
- Write-Host "❌ Deployment failed: $_" -ForegroundColor Red
110
- exit 1
111
- }
112
- `;
113
- await this.writeFile(join('scripts', 'deploy.ps1'), content);
114
- return join(servicePath, 'scripts', 'deploy.ps1');
115
- }
116
- validateContext(context) {
117
- const confirmedValues = context.confirmedValues || context;
118
- if (!confirmedValues.displayName || !confirmedValues.productionUrl) {
119
- throw new Error('DeployScriptGenerator: Missing required fields');
120
- }
121
- return true;
122
- }
123
- }
@@ -1,101 +0,0 @@
1
- import { BaseGenerator } from '../BaseGenerator.js';
2
- import { join } from 'path';
3
- export class HealthCheckScriptGenerator extends BaseGenerator {
4
- constructor(options = {}) {
5
- super({
6
- name: 'HealthCheckScriptGenerator',
7
- description: 'Generates PowerShell health check script',
8
- outputPath: 'scripts/health-check.ps1',
9
- ...options
10
- });
11
- }
12
- shouldGenerate(context) {
13
- return true;
14
- }
15
- async generate(context) {
16
- const coreInputs = context.coreInputs || context;
17
- const confirmedValues = context.confirmedValues || context;
18
- const servicePath = context.servicePath || context.outputDir;
19
- this.setContext({
20
- coreInputs,
21
- confirmedValues,
22
- servicePath
23
- });
24
- const content = `#!/usr/bin/env pwsh
25
-
26
- <#
27
- .SYNOPSIS
28
- Health check for ${confirmedValues.displayName}
29
-
30
- .DESCRIPTION
31
- Performs health checks on ${confirmedValues.displayName} service
32
- Tests endpoints, database connectivity, and overall service health
33
-
34
- .PARAMETER Environment
35
- Target environment to check (development, staging, production)
36
-
37
- .EXAMPLE
38
- .\\scripts\\health-check.ps1 -Environment production
39
- #>
40
-
41
- param(
42
- [Parameter(Mandatory = $false)]
43
- [ValidateSet('development', 'staging', 'production')]
44
- [string]$Environment = 'development'
45
- )
46
-
47
- Write-Host "🏥 Running health checks for ${confirmedValues.displayName} ($Environment)" -ForegroundColor Cyan
48
-
49
- # Determine service URL based on environment
50
- $serviceUrl = switch ($Environment) {
51
- 'production' { "${confirmedValues.productionUrl}" }
52
- 'staging' { "${confirmedValues.stagingUrl}" }
53
- 'development' { "${confirmedValues.developmentUrl}" }
54
- }
55
-
56
- Write-Host "🌐 Checking service at: $serviceUrl" -ForegroundColor Gray
57
-
58
- try {
59
- # Health check endpoint
60
- $healthUrl = "$serviceUrl${confirmedValues.healthCheckPath}"
61
- Write-Host "🔍 Testing health endpoint: $healthUrl" -ForegroundColor Yellow
62
-
63
- $response = Invoke-RestMethod -Uri $healthUrl -Method GET -TimeoutSec 30
64
- if ($response.status -eq 'healthy') {
65
- Write-Host "✅ Health check passed" -ForegroundColor Green
66
- } else {
67
- Write-Host "❌ Health check failed: $($response | ConvertTo-Json)" -ForegroundColor Red
68
- exit 1
69
- }
70
-
71
- # API endpoint check
72
- $apiUrl = "$serviceUrl${confirmedValues.apiBasePath}"
73
- Write-Host "🔍 Testing API endpoint: $apiUrl" -ForegroundColor Yellow
74
-
75
- try {
76
- $apiResponse = Invoke-WebRequest -Uri $apiUrl -Method GET -TimeoutSec 30
77
- Write-Host "✅ API endpoint accessible (Status: $($apiResponse.StatusCode))" -ForegroundColor Green
78
- } catch {
79
- Write-Host "⚠️ API endpoint returned error (may be expected): $($_.Exception.Message)" -ForegroundColor Yellow
80
- }
81
-
82
- Write-Host "✅ All health checks completed successfully!" -ForegroundColor Green
83
-
84
- } catch {
85
- Write-Host "❌ Health check failed: $_" -ForegroundColor Red
86
- exit 1
87
- }
88
- `;
89
- await this.writeFile(join('scripts', 'health-check.ps1'), content);
90
- return join(servicePath, 'scripts', 'health-check.ps1');
91
- }
92
- validateContext(context) {
93
- const confirmedValues = context.confirmedValues || context;
94
- const required = ['displayName', 'productionUrl', 'stagingUrl', 'developmentUrl', 'healthCheckPath', 'apiBasePath'];
95
- const missing = required.filter(field => !confirmedValues[field]);
96
- if (missing.length > 0) {
97
- throw new Error(`HealthCheckScriptGenerator: Missing fields: ${missing.join(', ')}`);
98
- }
99
- return true;
100
- }
101
- }
@@ -1,88 +0,0 @@
1
- import { BaseGenerator } from '../BaseGenerator.js';
2
- import { join } from 'path';
3
- export class SetupScriptGenerator extends BaseGenerator {
4
- constructor(options = {}) {
5
- super({
6
- name: 'SetupScriptGenerator',
7
- description: 'Generates PowerShell setup script',
8
- outputPath: 'scripts/setup.ps1',
9
- ...options
10
- });
11
- }
12
- shouldGenerate(context) {
13
- return true;
14
- }
15
- async generate(context) {
16
- const coreInputs = context.coreInputs || context;
17
- const confirmedValues = context.confirmedValues || context;
18
- const servicePath = context.servicePath || context.outputDir;
19
- this.setContext({
20
- coreInputs,
21
- confirmedValues,
22
- servicePath
23
- });
24
- const databaseSetup = confirmedValues.features && confirmedValues.features.database ? `
25
- Write-Host "🗄️ Setting up database..." -ForegroundColor Yellow
26
- # Database setup would go here
27
- Write-Host "⚠️ Database setup requires manual configuration" -ForegroundColor Yellow
28
- ` : `
29
- Write-Host "ℹ️ Database not required for this service type" -ForegroundColor Gray
30
- `;
31
- const content = `#!/usr/bin/env pwsh
32
-
33
- <#
34
- .SYNOPSIS
35
- Setup ${confirmedValues.displayName} environment
36
-
37
- .DESCRIPTION
38
- Initializes the development environment for ${confirmedValues.displayName}
39
- Sets up database, configures environment variables, and prepares for development
40
-
41
- .EXAMPLE
42
- .\\scripts\\setup.ps1
43
- #>
44
-
45
- Write-Host "🔧 Setting up ${confirmedValues.displayName} development environment" -ForegroundColor Cyan
46
-
47
- try {
48
- # Check if .env exists
49
- if (-not (Test-Path ".env")) {
50
- Write-Host "📄 Creating .env file from template..." -ForegroundColor Yellow
51
- Copy-Item ".env.example" ".env" -Force
52
- Write-Host "⚠️ Please edit .env file with your actual values" -ForegroundColor Yellow
53
- }
54
-
55
- # Install dependencies
56
- Write-Host "📦 Installing dependencies..." -ForegroundColor Yellow
57
- npm install
58
-
59
- # Create database (if configured)
60
- ${databaseSetup}
61
-
62
- # Run initial build
63
- Write-Host "🔨 Running initial build..." -ForegroundColor Yellow
64
- npm run build
65
-
66
- # Run tests
67
- Write-Host "🧪 Running tests..." -ForegroundColor Yellow
68
- npm test
69
-
70
- Write-Host "✅ Setup completed successfully!" -ForegroundColor Green
71
- Write-Host "🚀 You can now run 'npm run dev' to start development" -ForegroundColor Cyan
72
-
73
- } catch {
74
- Write-Host "❌ Setup failed: $_" -ForegroundColor Red
75
- exit 1
76
- }
77
- `;
78
- await this.writeFile(join('scripts', 'setup.ps1'), content);
79
- return join(servicePath, 'scripts', 'setup.ps1');
80
- }
81
- validateContext(context) {
82
- const confirmedValues = context.confirmedValues || context;
83
- if (!confirmedValues.displayName) {
84
- throw new Error('SetupScriptGenerator: Missing displayName');
85
- }
86
- return true;
87
- }
88
- }
@@ -1,342 +0,0 @@
1
- /**
2
- * StaticSiteGenerator - Service-type generator for static-site services
3
- *
4
- * Generates static-site specific files and configurations:
5
- * - Static file serving handlers
6
- * - Site configuration schemas
7
- * - Asset optimization middleware
8
- * - SPA fallback routing
9
- *
10
- * Extends BaseServiceTypeGenerator to provide static-site specific generation logic.
11
- */
12
- import { BaseGenerator } from '../BaseGenerator.js';
13
- export class StaticSiteGenerator extends BaseGenerator {
14
- /**
15
- * Create a new StaticSiteGenerator instance
16
- * @param {Object} options - Generator options
17
- */
18
- constructor(options = {}) {
19
- super({
20
- name: 'StaticSiteGenerator',
21
- ...options
22
- });
23
- this.serviceType = 'static-site';
24
- }
25
-
26
- /**
27
- * Main generation method for static-site services
28
- * Generates all static-site specific files and configurations
29
- *
30
- * @param {Object} context - Generation context
31
- * @param {Object} context.coreInputs - Core service inputs
32
- * @param {Object} context.confirmedValues - Confirmed configuration values
33
- * @param {string} context.servicePath - Path to generate service in
34
- * @returns {Promise<void>}
35
- */
36
- async generate(context) {
37
- this.setContext(context);
38
- const {
39
- coreInputs,
40
- confirmedValues,
41
- servicePath
42
- } = this.extractContext(context);
43
-
44
- // Validate service type
45
- if (coreInputs.serviceType !== 'static-site') {
46
- this.log('Skipping static-site generation - service type is not static-site');
47
- return;
48
- }
49
- this.log('Generating static-site service files...');
50
-
51
- // Generate static-site specific handlers
52
- await this.generateHandlers(context);
53
-
54
- // Generate configuration schemas
55
- await this.generateSchemas(context);
56
-
57
- // Generate middleware
58
- await this.generateMiddleware(context);
59
-
60
- // Generate documentation
61
- await this.generateDocs(context);
62
- this.log('Static-site service generation complete');
63
- }
64
-
65
- /**
66
- * Generate static-site specific request handlers
67
- * Creates handlers for static file serving, SPA routing, and health checks
68
- *
69
- * @param {Object} context - Generation context
70
- * @returns {Promise<void>}
71
- */
72
- async generateHandlers(context) {
73
- const {
74
- coreInputs,
75
- confirmedValues
76
- } = this.extractContext(context);
77
-
78
- // Load the base worker template
79
- const workerTemplate = await this.loadTemplate('src/worker/index.js');
80
-
81
- // Prepare template variables
82
- const templateVars = {
83
- SERVICE_NAME: coreInputs.serviceName || 'static-site',
84
- SERVICE_DISPLAY_NAME: confirmedValues.displayName || coreInputs.serviceName || 'Static Site',
85
- SERVICE_TYPE: 'static-site',
86
- DOMAIN_NAME: coreInputs.domainName || 'example.com',
87
- CURRENT_DATE: new Date().toISOString().split('T')[0],
88
- ENVIRONMENT: context.environment || 'development'
89
- };
90
-
91
- // Render the worker
92
- const workerContent = this.renderTemplate(workerTemplate, templateVars);
93
- await this.writeFile('src/worker/index.js', workerContent);
94
-
95
- // Generate domain configuration
96
- const domainTemplate = await this.loadTemplate('src/config/domains.js');
97
- const domainContent = this.renderTemplate(domainTemplate, templateVars);
98
- await this.writeFile('src/config/domains.js', domainContent);
99
- this.log('Generated static-site handlers and configuration');
100
- }
101
-
102
- /**
103
- * Generate static-site specific configuration schemas
104
- * Creates validation schemas for static-site configuration
105
- *
106
- * @param {Object} context - Generation context
107
- * @returns {Promise<void>}
108
- */
109
- async generateSchemas(context) {
110
- const {
111
- coreInputs
112
- } = this.extractContext(context);
113
-
114
- // Create a basic schema for static-site configuration validation
115
- const schemaContent = {
116
- $schema: "https://json-schema.org/draft/2020-12/schema",
117
- title: "Static Site Configuration Schema",
118
- description: "Configuration schema for static-site services",
119
- type: "object",
120
- properties: {
121
- serviceType: {
122
- type: "string",
123
- enum: ["static-site"],
124
- description: "Must be 'static-site' for this schema"
125
- },
126
- publicDir: {
127
- type: "string",
128
- default: "public",
129
- description: "Directory containing static files"
130
- },
131
- indexFile: {
132
- type: "string",
133
- default: "index.html",
134
- description: "Default index file for directory requests"
135
- },
136
- errorFile: {
137
- type: "string",
138
- default: "404.html",
139
- description: "Error page for 404 responses"
140
- },
141
- spaFallback: {
142
- type: "boolean",
143
- default: true,
144
- description: "Enable SPA fallback to index.html for client-side routing"
145
- },
146
- cleanUrls: {
147
- type: "boolean",
148
- default: true,
149
- description: "Serve .html files without extension"
150
- },
151
- compressText: {
152
- type: "boolean",
153
- default: true,
154
- description: "Enable gzip compression for text files"
155
- },
156
- corsEnabled: {
157
- type: "boolean",
158
- default: true,
159
- description: "Enable CORS headers"
160
- }
161
- },
162
- required: ["serviceType"]
163
- };
164
- await this.writeFile('static-site-schema.json', JSON.stringify(schemaContent, null, 2));
165
- this.log('Generated static-site configuration schema');
166
- }
167
-
168
- /**
169
- * Generate static-site specific middleware
170
- * Creates middleware for asset optimization, caching, and security
171
- *
172
- * @param {Object} context - Generation context
173
- * @returns {Promise<void>}
174
- */
175
- async generateMiddleware(context) {
176
- const middlewareContent = `/**
177
- * Static Site Middleware
178
- * Generated by Clodo Framework for ${context.coreInputs?.serviceName || 'static-site'}
179
- *
180
- * Provides middleware for:
181
- * - Asset optimization
182
- * - Cache headers
183
- * - Security headers
184
- * - Compression
185
- */
186
-
187
- export class StaticSiteMiddleware {
188
- constructor(options = {}) {
189
- this.options = {
190
- cacheControl: options.cacheControl || 'public, max-age=31536000, immutable',
191
- compressText: options.compressText !== false,
192
- corsEnabled: options.corsEnabled !== false,
193
- ...options
194
- };
195
- }
196
-
197
- /**
198
- * Apply static site middleware to a response
199
- * @param {Response} response - The response to modify
200
- * @param {Request} request - The original request
201
- * @returns {Response} - Modified response
202
- */
203
- apply(response, request) {
204
- const newResponse = new Response(response.body, response);
205
-
206
- // Add cache control for static assets
207
- if (this.isStaticAsset(request.url)) {
208
- newResponse.headers.set('Cache-Control', this.options.cacheControl);
209
- }
210
-
211
- // Add CORS headers if enabled
212
- if (this.options.corsEnabled) {
213
- newResponse.headers.set('Access-Control-Allow-Origin', '*');
214
- newResponse.headers.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
215
- newResponse.headers.set('Access-Control-Allow-Headers', 'Content-Type, Authorization');
216
- }
217
-
218
- // Add compression if enabled and response is text-based
219
- if (this.options.compressText && this.shouldCompress(newResponse)) {
220
- newResponse.headers.set('Content-Encoding', 'gzip');
221
- }
222
-
223
- // Add security headers
224
- newResponse.headers.set('X-Content-Type-Options', 'nosniff');
225
- newResponse.headers.set('X-Frame-Options', 'DENY');
226
- newResponse.headers.set('Referrer-Policy', 'strict-origin-when-cross-origin');
227
-
228
- return newResponse;
229
- }
230
-
231
- /**
232
- * Check if URL is a static asset
233
- * @param {string} url - Request URL
234
- * @returns {boolean} - True if static asset
235
- */
236
- isStaticAsset(url) {
237
- const pathname = new URL(url).pathname;
238
- const staticExtensions = ['.css', '.js', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.woff', '.woff2', '.webp'];
239
-
240
- return staticExtensions.some(ext => pathname.endsWith(ext));
241
- }
242
-
243
- /**
244
- * Check if response should be compressed
245
- * @param {Response} response - Response to check
246
- * @returns {boolean} - True if should compress
247
- */
248
- shouldCompress(response) {
249
- const contentType = response.headers.get('Content-Type') || '';
250
- return contentType.includes('text/') ||
251
- contentType.includes('application/json') ||
252
- contentType.includes('application/javascript') ||
253
- contentType.includes('application/xml');
254
- }
255
- }
256
-
257
- export default StaticSiteMiddleware;`;
258
- await this.writeFile('src/middleware/StaticSiteMiddleware.js', middlewareContent);
259
- this.log('Generated static-site middleware');
260
- }
261
-
262
- /**
263
- * Generate static-site specific documentation
264
- * Creates README and configuration guides
265
- *
266
- * @param {Object} context - Generation context
267
- * @returns {Promise<void>}
268
- */
269
- async generateDocs(context) {
270
- const {
271
- coreInputs,
272
- confirmedValues
273
- } = this.extractContext(context);
274
-
275
- // Load the README template
276
- const readmeTemplate = await this.loadTemplate('README.md');
277
-
278
- // Prepare template variables
279
- const templateVars = {
280
- SERVICE_NAME: coreInputs.serviceName || 'static-site',
281
- SERVICE_DISPLAY_NAME: confirmedValues.displayName || coreInputs.serviceName || 'Static Site',
282
- SERVICE_TYPE: 'static-site',
283
- DOMAIN_NAME: coreInputs.domainName || 'example.com',
284
- CURRENT_DATE: new Date().toISOString().split('T')[0],
285
- CURRENT_YEAR: new Date().getFullYear(),
286
- FRAMEWORK_VERSION: '1.0.0',
287
- ENVIRONMENT: context.environment || 'development'
288
- };
289
-
290
- // Render and write README
291
- const readmeContent = this.renderTemplate(readmeTemplate, templateVars);
292
- await this.writeFile('README.md', readmeContent);
293
- this.log('Generated static-site documentation');
294
- }
295
-
296
- /**
297
- * Determine if this generator should run
298
- * Only runs for static-site service type
299
- *
300
- * @param {Object} context - Generation context
301
- * @returns {boolean} - True if service type is static-site
302
- */
303
- shouldGenerate(context) {
304
- const serviceType = context?.coreInputs?.serviceType || context?.serviceType;
305
- return serviceType === 'static-site';
306
- }
307
-
308
- /**
309
- * Validate static-site specific configuration
310
- * @param {Object} config - Configuration to validate
311
- * @returns {Object} - Validation result { valid: boolean, errors: string[] }
312
- */
313
- validateConfig(config) {
314
- const errors = [];
315
- if (config.serviceType !== 'static-site') {
316
- errors.push('Service type must be "static-site"');
317
- }
318
- if (config.publicDir && typeof config.publicDir !== 'string') {
319
- errors.push('publicDir must be a string path');
320
- }
321
- if (config.indexFile && typeof config.indexFile !== 'string') {
322
- errors.push('indexFile must be a string filename');
323
- }
324
- if (config.spaFallback !== undefined && typeof config.spaFallback !== 'boolean') {
325
- errors.push('spaFallback must be a boolean');
326
- }
327
- if (config.buildCommand !== undefined && (typeof config.buildCommand !== 'string' || !config.buildCommand.trim())) {
328
- errors.push('buildCommand must be a non-empty string');
329
- }
330
- if (config.buildOutputDir !== undefined && (typeof config.buildOutputDir !== 'string' || !config.buildOutputDir.trim())) {
331
- errors.push('buildOutputDir must be a non-empty string');
332
- }
333
- if (errors.length > 0) {
334
- throw new Error(`Invalid static-site configuration: ${errors.join(', ')}`);
335
- }
336
- return {
337
- valid: true,
338
- errors: []
339
- };
340
- }
341
- }
342
- export default StaticSiteGenerator;