@friggframework/devtools 2.0.0-next.3 → 2.0.0-next.31

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 (199) hide show
  1. package/frigg-cli/.eslintrc.js +141 -0
  2. package/frigg-cli/__tests__/jest.config.js +102 -0
  3. package/frigg-cli/__tests__/unit/commands/build.test.js +483 -0
  4. package/frigg-cli/__tests__/unit/commands/install.test.js +418 -0
  5. package/frigg-cli/__tests__/unit/commands/ui.test.js +592 -0
  6. package/frigg-cli/__tests__/utils/command-tester.js +170 -0
  7. package/frigg-cli/__tests__/utils/mock-factory.js +270 -0
  8. package/frigg-cli/__tests__/utils/test-fixtures.js +463 -0
  9. package/frigg-cli/__tests__/utils/test-setup.js +286 -0
  10. package/frigg-cli/build-command/index.js +54 -0
  11. package/frigg-cli/deploy-command/index.js +36 -0
  12. package/frigg-cli/generate-command/__tests__/generate-command.test.js +312 -0
  13. package/frigg-cli/generate-command/azure-generator.js +43 -0
  14. package/frigg-cli/generate-command/gcp-generator.js +47 -0
  15. package/frigg-cli/generate-command/index.js +332 -0
  16. package/frigg-cli/generate-command/terraform-generator.js +555 -0
  17. package/frigg-cli/generate-iam-command.js +115 -0
  18. package/frigg-cli/index.js +47 -1
  19. package/frigg-cli/index.test.js +1 -4
  20. package/frigg-cli/init-command/backend-first-handler.js +756 -0
  21. package/frigg-cli/init-command/index.js +93 -0
  22. package/frigg-cli/init-command/template-handler.js +143 -0
  23. package/frigg-cli/install-command/index.js +1 -4
  24. package/frigg-cli/package.json +51 -0
  25. package/frigg-cli/start-command/index.js +24 -4
  26. package/frigg-cli/test/init-command.test.js +180 -0
  27. package/frigg-cli/test/npm-registry.test.js +319 -0
  28. package/frigg-cli/ui-command/index.js +154 -0
  29. package/frigg-cli/utils/app-resolver.js +319 -0
  30. package/frigg-cli/utils/backend-path.js +16 -17
  31. package/frigg-cli/utils/npm-registry.js +167 -0
  32. package/frigg-cli/utils/process-manager.js +199 -0
  33. package/frigg-cli/utils/repo-detection.js +405 -0
  34. package/infrastructure/AWS-DISCOVERY-TROUBLESHOOTING.md +245 -0
  35. package/infrastructure/AWS-IAM-CREDENTIAL-NEEDS.md +596 -0
  36. package/infrastructure/DEPLOYMENT-INSTRUCTIONS.md +268 -0
  37. package/infrastructure/GENERATE-IAM-DOCS.md +253 -0
  38. package/infrastructure/IAM-POLICY-TEMPLATES.md +176 -0
  39. package/infrastructure/README-TESTING.md +332 -0
  40. package/infrastructure/README.md +421 -0
  41. package/infrastructure/WEBSOCKET-CONFIGURATION.md +105 -0
  42. package/infrastructure/__tests__/fixtures/mock-aws-resources.js +391 -0
  43. package/infrastructure/__tests__/helpers/test-utils.js +277 -0
  44. package/infrastructure/aws-discovery.js +568 -0
  45. package/infrastructure/aws-discovery.test.js +373 -0
  46. package/infrastructure/build-time-discovery.js +206 -0
  47. package/infrastructure/build-time-discovery.test.js +375 -0
  48. package/infrastructure/create-frigg-infrastructure.js +3 -5
  49. package/infrastructure/frigg-deployment-iam-stack.yaml +379 -0
  50. package/infrastructure/iam-generator.js +687 -0
  51. package/infrastructure/iam-generator.test.js +169 -0
  52. package/infrastructure/iam-policy-basic.json +212 -0
  53. package/infrastructure/iam-policy-full.json +282 -0
  54. package/infrastructure/integration.test.js +383 -0
  55. package/infrastructure/run-discovery.js +110 -0
  56. package/infrastructure/serverless-template.js +923 -113
  57. package/infrastructure/serverless-template.test.js +541 -0
  58. package/management-ui/.eslintrc.js +22 -0
  59. package/management-ui/README.md +203 -0
  60. package/management-ui/components.json +21 -0
  61. package/management-ui/docs/phase2-integration-guide.md +320 -0
  62. package/management-ui/index.html +13 -0
  63. package/management-ui/package-lock.json +16517 -0
  64. package/management-ui/package.json +76 -0
  65. package/management-ui/packages/devtools/frigg-cli/ui-command/index.js +302 -0
  66. package/management-ui/postcss.config.js +6 -0
  67. package/management-ui/server/api/backend.js +256 -0
  68. package/management-ui/server/api/cli.js +315 -0
  69. package/management-ui/server/api/codegen.js +663 -0
  70. package/management-ui/server/api/connections.js +857 -0
  71. package/management-ui/server/api/discovery.js +185 -0
  72. package/management-ui/server/api/environment/index.js +1 -0
  73. package/management-ui/server/api/environment/router.js +378 -0
  74. package/management-ui/server/api/environment.js +328 -0
  75. package/management-ui/server/api/integrations.js +876 -0
  76. package/management-ui/server/api/logs.js +248 -0
  77. package/management-ui/server/api/monitoring.js +282 -0
  78. package/management-ui/server/api/open-ide.js +31 -0
  79. package/management-ui/server/api/project.js +1029 -0
  80. package/management-ui/server/api/users/sessions.js +371 -0
  81. package/management-ui/server/api/users/simulation.js +254 -0
  82. package/management-ui/server/api/users.js +362 -0
  83. package/management-ui/server/api-contract.md +275 -0
  84. package/management-ui/server/index.js +873 -0
  85. package/management-ui/server/middleware/errorHandler.js +93 -0
  86. package/management-ui/server/middleware/security.js +32 -0
  87. package/management-ui/server/processManager.js +296 -0
  88. package/management-ui/server/server.js +346 -0
  89. package/management-ui/server/services/aws-monitor.js +413 -0
  90. package/management-ui/server/services/npm-registry.js +347 -0
  91. package/management-ui/server/services/template-engine.js +538 -0
  92. package/management-ui/server/utils/cliIntegration.js +220 -0
  93. package/management-ui/server/utils/environment/auditLogger.js +471 -0
  94. package/management-ui/server/utils/environment/awsParameterStore.js +264 -0
  95. package/management-ui/server/utils/environment/encryption.js +278 -0
  96. package/management-ui/server/utils/environment/envFileManager.js +286 -0
  97. package/management-ui/server/utils/import-commonjs.js +28 -0
  98. package/management-ui/server/utils/response.js +83 -0
  99. package/management-ui/server/websocket/handler.js +325 -0
  100. package/management-ui/src/App.jsx +109 -0
  101. package/management-ui/src/assets/FriggLogo.svg +1 -0
  102. package/management-ui/src/components/AppRouter.jsx +65 -0
  103. package/management-ui/src/components/Button.jsx +70 -0
  104. package/management-ui/src/components/Card.jsx +97 -0
  105. package/management-ui/src/components/EnvironmentCompare.jsx +400 -0
  106. package/management-ui/src/components/EnvironmentEditor.jsx +372 -0
  107. package/management-ui/src/components/EnvironmentImportExport.jsx +469 -0
  108. package/management-ui/src/components/EnvironmentSchema.jsx +491 -0
  109. package/management-ui/src/components/EnvironmentSecurity.jsx +463 -0
  110. package/management-ui/src/components/ErrorBoundary.jsx +73 -0
  111. package/management-ui/src/components/IntegrationCard.jsx +481 -0
  112. package/management-ui/src/components/IntegrationCardEnhanced.jsx +770 -0
  113. package/management-ui/src/components/IntegrationExplorer.jsx +379 -0
  114. package/management-ui/src/components/IntegrationStatus.jsx +336 -0
  115. package/management-ui/src/components/Layout.jsx +716 -0
  116. package/management-ui/src/components/LoadingSpinner.jsx +113 -0
  117. package/management-ui/src/components/RepositoryPicker.jsx +248 -0
  118. package/management-ui/src/components/SessionMonitor.jsx +350 -0
  119. package/management-ui/src/components/StatusBadge.jsx +208 -0
  120. package/management-ui/src/components/UserContextSwitcher.jsx +212 -0
  121. package/management-ui/src/components/UserSimulation.jsx +327 -0
  122. package/management-ui/src/components/Welcome.jsx +434 -0
  123. package/management-ui/src/components/codegen/APIEndpointGenerator.jsx +637 -0
  124. package/management-ui/src/components/codegen/APIModuleSelector.jsx +227 -0
  125. package/management-ui/src/components/codegen/CodeGenerationWizard.jsx +247 -0
  126. package/management-ui/src/components/codegen/CodePreviewEditor.jsx +316 -0
  127. package/management-ui/src/components/codegen/DynamicModuleForm.jsx +271 -0
  128. package/management-ui/src/components/codegen/FormBuilder.jsx +737 -0
  129. package/management-ui/src/components/codegen/IntegrationGenerator.jsx +855 -0
  130. package/management-ui/src/components/codegen/ProjectScaffoldWizard.jsx +797 -0
  131. package/management-ui/src/components/codegen/SchemaBuilder.jsx +303 -0
  132. package/management-ui/src/components/codegen/TemplateSelector.jsx +586 -0
  133. package/management-ui/src/components/codegen/index.js +10 -0
  134. package/management-ui/src/components/connections/ConnectionConfigForm.jsx +362 -0
  135. package/management-ui/src/components/connections/ConnectionHealthMonitor.jsx +182 -0
  136. package/management-ui/src/components/connections/ConnectionTester.jsx +200 -0
  137. package/management-ui/src/components/connections/EntityRelationshipMapper.jsx +292 -0
  138. package/management-ui/src/components/connections/OAuthFlow.jsx +204 -0
  139. package/management-ui/src/components/connections/index.js +5 -0
  140. package/management-ui/src/components/index.js +21 -0
  141. package/management-ui/src/components/monitoring/APIGatewayMetrics.jsx +222 -0
  142. package/management-ui/src/components/monitoring/LambdaMetrics.jsx +169 -0
  143. package/management-ui/src/components/monitoring/MetricsChart.jsx +197 -0
  144. package/management-ui/src/components/monitoring/MonitoringDashboard.jsx +393 -0
  145. package/management-ui/src/components/monitoring/SQSMetrics.jsx +246 -0
  146. package/management-ui/src/components/monitoring/index.js +6 -0
  147. package/management-ui/src/components/monitoring/monitoring.css +218 -0
  148. package/management-ui/src/components/theme-provider.jsx +52 -0
  149. package/management-ui/src/components/theme-toggle.jsx +39 -0
  150. package/management-ui/src/components/ui/badge.tsx +36 -0
  151. package/management-ui/src/components/ui/button.test.jsx +56 -0
  152. package/management-ui/src/components/ui/button.tsx +57 -0
  153. package/management-ui/src/components/ui/card.tsx +76 -0
  154. package/management-ui/src/components/ui/dropdown-menu.tsx +199 -0
  155. package/management-ui/src/components/ui/select.tsx +157 -0
  156. package/management-ui/src/components/ui/skeleton.jsx +15 -0
  157. package/management-ui/src/hooks/useFrigg.jsx +601 -0
  158. package/management-ui/src/hooks/useSocket.jsx +58 -0
  159. package/management-ui/src/index.css +193 -0
  160. package/management-ui/src/lib/utils.ts +6 -0
  161. package/management-ui/src/main.jsx +10 -0
  162. package/management-ui/src/pages/CodeGeneration.jsx +14 -0
  163. package/management-ui/src/pages/Connections.jsx +252 -0
  164. package/management-ui/src/pages/ConnectionsEnhanced.jsx +633 -0
  165. package/management-ui/src/pages/Dashboard.jsx +311 -0
  166. package/management-ui/src/pages/Environment.jsx +314 -0
  167. package/management-ui/src/pages/IntegrationConfigure.jsx +669 -0
  168. package/management-ui/src/pages/IntegrationDiscovery.jsx +567 -0
  169. package/management-ui/src/pages/IntegrationTest.jsx +742 -0
  170. package/management-ui/src/pages/Integrations.jsx +253 -0
  171. package/management-ui/src/pages/Monitoring.jsx +17 -0
  172. package/management-ui/src/pages/Simulation.jsx +155 -0
  173. package/management-ui/src/pages/Users.jsx +492 -0
  174. package/management-ui/src/services/api.js +41 -0
  175. package/management-ui/src/services/apiModuleService.js +193 -0
  176. package/management-ui/src/services/websocket-handlers.js +120 -0
  177. package/management-ui/src/test/api/project.test.js +273 -0
  178. package/management-ui/src/test/components/Welcome.test.jsx +378 -0
  179. package/management-ui/src/test/mocks/server.js +178 -0
  180. package/management-ui/src/test/setup.js +61 -0
  181. package/management-ui/src/test/utils/test-utils.jsx +134 -0
  182. package/management-ui/src/utils/repository.js +98 -0
  183. package/management-ui/src/utils/repository.test.js +118 -0
  184. package/management-ui/src/workflows/phase2-integration-workflows.js +884 -0
  185. package/management-ui/tailwind.config.js +63 -0
  186. package/management-ui/tsconfig.json +37 -0
  187. package/management-ui/tsconfig.node.json +10 -0
  188. package/management-ui/vite.config.js +26 -0
  189. package/management-ui/vitest.config.js +38 -0
  190. package/package.json +17 -9
  191. package/infrastructure/app-handler-helpers.js +0 -57
  192. package/infrastructure/backend-utils.js +0 -90
  193. package/infrastructure/routers/auth.js +0 -26
  194. package/infrastructure/routers/integration-defined-routers.js +0 -37
  195. package/infrastructure/routers/middleware/loadUser.js +0 -15
  196. package/infrastructure/routers/middleware/requireLoggedInUser.js +0 -12
  197. package/infrastructure/routers/user.js +0 -41
  198. package/infrastructure/routers/websocket.js +0 -55
  199. package/infrastructure/workers/integration-defined-workers.js +0 -24
@@ -0,0 +1,43 @@
1
+ async function generateAzureARMTemplate(options) {
2
+ const { appName, features, userPrefix } = options;
3
+
4
+ // Placeholder for Azure ARM template generation
5
+ const template = {
6
+ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
7
+ "contentVersion": "1.0.0.0",
8
+ "metadata": {
9
+ "description": "Frigg deployment credentials for Azure - Coming Soon",
10
+ "author": "Frigg CLI"
11
+ },
12
+ "parameters": {},
13
+ "variables": {},
14
+ "resources": [],
15
+ "outputs": {
16
+ "message": {
17
+ "type": "string",
18
+ "value": "Azure ARM template generation is coming soon. Please use Terraform for now."
19
+ }
20
+ }
21
+ };
22
+
23
+ return JSON.stringify(template, null, 2);
24
+ }
25
+
26
+ async function generateAzureTerraformTemplate(options) {
27
+ // Placeholder for Azure Terraform template
28
+ return `# Frigg Deployment Configuration for Azure
29
+ # Coming Soon
30
+
31
+ # Azure support with Terraform is under development.
32
+ # Please check back in a future release.
33
+
34
+ output "message" {
35
+ value = "Azure Terraform support is coming soon"
36
+ }
37
+ `;
38
+ }
39
+
40
+ module.exports = {
41
+ generateAzureARMTemplate,
42
+ generateAzureTerraformTemplate
43
+ };
@@ -0,0 +1,47 @@
1
+ async function generateGCPDeploymentManagerTemplate(options) {
2
+ const { appName, features, userPrefix } = options;
3
+
4
+ // Placeholder for GCP Deployment Manager template
5
+ const template = `# Frigg Deployment Configuration for Google Cloud Platform
6
+ # Coming Soon
7
+
8
+ # GCP Deployment Manager support is under development.
9
+ # Please use Terraform for GCP deployments in the meantime.
10
+
11
+ resources: []
12
+
13
+ outputs:
14
+ - name: message
15
+ value: "GCP Deployment Manager support is coming soon"
16
+ `;
17
+
18
+ return template;
19
+ }
20
+
21
+ async function generateGCPTerraformTemplate(options) {
22
+ // Placeholder for GCP Terraform template
23
+ return `# Frigg Deployment Configuration for Google Cloud Platform
24
+ # Coming Soon
25
+
26
+ terraform {
27
+ required_providers {
28
+ google = {
29
+ source = "hashicorp/google"
30
+ version = "~> 5.0"
31
+ }
32
+ }
33
+ }
34
+
35
+ # GCP support with Terraform is under development.
36
+ # Please check back in a future release.
37
+
38
+ output "message" {
39
+ value = "GCP Terraform support is coming soon"
40
+ }
41
+ `;
42
+ }
43
+
44
+ module.exports = {
45
+ generateGCPDeploymentManagerTemplate,
46
+ generateGCPTerraformTemplate
47
+ };
@@ -0,0 +1,332 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+ const { findNearestBackendPackageJson } = require('../utils/backend-path');
4
+ const { select } = require('@inquirer/prompts');
5
+
6
+ // Import generators for different formats
7
+ const { generateCloudFormationTemplate } = require('../../infrastructure/iam-generator');
8
+ const { generateTerraformTemplate } = require('./terraform-generator');
9
+ const { generateAzureARMTemplate, generateAzureTerraformTemplate } = require('./azure-generator');
10
+ const { generateGCPDeploymentManagerTemplate, generateGCPTerraformTemplate } = require('./gcp-generator');
11
+
12
+ async function generateCommand(options = {}) {
13
+ // Set up graceful exit handler
14
+ process.on('SIGINT', () => {
15
+ console.log('\nāœ– Command cancelled by user');
16
+ process.exit(0);
17
+ });
18
+
19
+ try {
20
+ // Interactive mode: ask for cloud provider and format if not provided
21
+ if (!options.provider) {
22
+ try {
23
+ options.provider = await select({
24
+ message: 'Select cloud provider:',
25
+ choices: [
26
+ { name: 'AWS', value: 'aws' },
27
+ { name: 'Azure', value: 'azure' },
28
+ { name: 'Google Cloud Platform', value: 'gcp' }
29
+ ]
30
+ });
31
+ } catch (error) {
32
+ if (error.name === 'ExitPromptError') {
33
+ console.log('\nāœ– Command cancelled by user');
34
+ process.exit(0);
35
+ }
36
+ throw error;
37
+ }
38
+ }
39
+
40
+ if (!options.format) {
41
+ // Determine format choices based on provider
42
+ let formatChoices;
43
+ let defaultFormat;
44
+ if (options.provider === 'aws') {
45
+ formatChoices = [
46
+ { name: 'CloudFormation', value: 'cloudformation' },
47
+ { name: 'Terraform', value: 'terraform' },
48
+ { name: 'Pulumi', value: 'pulumi' }
49
+ ];
50
+ defaultFormat = 'cloudformation';
51
+ } else if (options.provider === 'azure') {
52
+ formatChoices = [
53
+ { name: 'ARM Template', value: 'arm' },
54
+ { name: 'Terraform', value: 'terraform' },
55
+ { name: 'Pulumi', value: 'pulumi' }
56
+ ];
57
+ defaultFormat = 'arm';
58
+ } else if (options.provider === 'gcp') {
59
+ formatChoices = [
60
+ { name: 'Deployment Manager', value: 'deployment-manager' },
61
+ { name: 'Terraform', value: 'terraform' },
62
+ { name: 'Pulumi', value: 'pulumi' }
63
+ ];
64
+ defaultFormat = 'deployment-manager';
65
+ }
66
+
67
+ try {
68
+ options.format = await select({
69
+ message: 'Select output format:',
70
+ choices: formatChoices
71
+ });
72
+ } catch (error) {
73
+ if (error.name === 'ExitPromptError') {
74
+ console.log('\nāœ– Command cancelled by user');
75
+ process.exit(0);
76
+ }
77
+ throw error;
78
+ }
79
+ }
80
+
81
+ // Find the Frigg application
82
+ const nearestBackendPackageJson = await findNearestBackendPackageJson();
83
+ if (!nearestBackendPackageJson) {
84
+ throw new Error('Could not find a Frigg application. Make sure you are in a Frigg project directory.');
85
+ }
86
+
87
+ const backendDir = path.dirname(nearestBackendPackageJson);
88
+ const backendPackageJsonFile = JSON.parse(fs.readFileSync(nearestBackendPackageJson, 'utf8'));
89
+ const appName = backendPackageJsonFile.name || 'frigg-app';
90
+
91
+ if (options.verbose) {
92
+ console.log('Current directory:', process.cwd());
93
+ console.log('Backend package.json found at:', nearestBackendPackageJson);
94
+ console.log('Backend directory:', backendDir);
95
+ }
96
+
97
+ // Load app definition
98
+ const appDefinitionPath = path.join(backendDir, 'index.js');
99
+ if (!fs.existsSync(appDefinitionPath)) {
100
+ throw new Error(`App definition not found at ${appDefinitionPath}`);
101
+ }
102
+
103
+ // Analyze the app definition
104
+ const appModule = require(appDefinitionPath);
105
+ const appDefinition = appModule.Definition || appModule;
106
+ const features = analyzeAppFeatures(appDefinition);
107
+
108
+ if (options.verbose) {
109
+ console.log('Detected features:', features);
110
+ }
111
+
112
+ // Generate based on provider and format
113
+ let template;
114
+ let fileExtension;
115
+ let deploymentInstructions;
116
+
117
+ if (options.provider === 'aws') {
118
+ if (options.format === 'cloudformation') {
119
+ template = await generateCloudFormationTemplate({
120
+ appName,
121
+ features,
122
+ userPrefix: options.user || 'frigg-deployment-user',
123
+ stackName: options.stackName || 'frigg-deployment-iam'
124
+ });
125
+ fileExtension = 'yaml';
126
+ deploymentInstructions = generateCloudFormationInstructions(options);
127
+ } else if (options.format === 'terraform') {
128
+ template = await generateTerraformTemplate({
129
+ appName,
130
+ features,
131
+ userPrefix: options.user || 'frigg-deployment-user'
132
+ });
133
+ fileExtension = 'tf';
134
+ deploymentInstructions = generateTerraformInstructions(options);
135
+ } else if (options.format === 'pulumi') {
136
+ throw new Error('Pulumi support is not yet implemented');
137
+ }
138
+ } else if (options.provider === 'azure') {
139
+ if (options.format === 'arm') {
140
+ template = await generateAzureARMTemplate({
141
+ appName,
142
+ features,
143
+ userPrefix: options.user || 'frigg-deployment-user'
144
+ });
145
+ fileExtension = 'json';
146
+ deploymentInstructions = generateAzureInstructions(options);
147
+ } else if (options.format === 'terraform') {
148
+ template = await generateAzureTerraformTemplate({
149
+ appName,
150
+ features,
151
+ userPrefix: options.user || 'frigg-deployment-user'
152
+ });
153
+ fileExtension = 'tf';
154
+ deploymentInstructions = generateTerraformInstructions(options);
155
+ } else if (options.format === 'pulumi') {
156
+ throw new Error('Pulumi support for Azure is not yet implemented');
157
+ }
158
+ } else if (options.provider === 'gcp') {
159
+ if (options.format === 'deployment-manager') {
160
+ template = await generateGCPDeploymentManagerTemplate({
161
+ appName,
162
+ features,
163
+ userPrefix: options.user || 'frigg-deployment-user'
164
+ });
165
+ fileExtension = 'yaml';
166
+ deploymentInstructions = generateGCPInstructions(options);
167
+ } else if (options.format === 'terraform') {
168
+ template = await generateGCPTerraformTemplate({
169
+ appName,
170
+ features,
171
+ userPrefix: options.user || 'frigg-deployment-user'
172
+ });
173
+ fileExtension = 'tf';
174
+ deploymentInstructions = generateTerraformInstructions(options);
175
+ } else if (options.format === 'pulumi') {
176
+ throw new Error('Pulumi support for GCP is not yet implemented');
177
+ }
178
+ } else {
179
+ throw new Error(`Provider ${options.provider} is not yet implemented`);
180
+ }
181
+
182
+ // Ensure output directory exists - smart path detection
183
+ let outputDir;
184
+ if (options.output) {
185
+ // If user specified output, use it as-is
186
+ outputDir = path.resolve(options.output);
187
+ } else {
188
+ // Smart default: put infrastructure in the backend directory we found
189
+ outputDir = path.join(backendDir, 'infrastructure');
190
+ }
191
+
192
+ if (options.verbose) {
193
+ console.log('Output directory will be:', outputDir);
194
+ }
195
+
196
+ if (!fs.existsSync(outputDir)) {
197
+ fs.mkdirSync(outputDir, { recursive: true });
198
+ }
199
+
200
+ // Write the template
201
+ const outputFileName = `frigg-deployment-${options.provider}-${options.format}.${fileExtension}`;
202
+ const outputPath = path.join(outputDir, outputFileName);
203
+ fs.writeFileSync(outputPath, template);
204
+
205
+ // Generate relative path for instructions
206
+ const relativeOutputDir = path.relative(process.cwd(), outputDir);
207
+ const relativeOutputPath = path.join(relativeOutputDir, outputFileName);
208
+
209
+ console.log(`\nāœ… Generated ${options.format} template for ${options.provider}`);
210
+ console.log(`šŸ“„ Template saved to: ${outputPath}`);
211
+ // Update deployment instructions with actual paths
212
+ if (deploymentInstructions) {
213
+ deploymentInstructions = deploymentInstructions
214
+ .replace(/backend\/infrastructure/g, relativeOutputDir)
215
+ .replace(/file:\/\/backend\/infrastructure/g, `file://${relativeOutputDir}`);
216
+ }
217
+ console.log('\n' + deploymentInstructions);
218
+
219
+ } catch (error) {
220
+ console.error('Error generating deployment credentials:', error.message);
221
+ if (options.verbose && error.stack) {
222
+ console.error(error.stack);
223
+ }
224
+ process.exit(1);
225
+ }
226
+ }
227
+
228
+ function analyzeAppFeatures(appDefinition) {
229
+ const features = {
230
+ vpc: appDefinition.vpc?.enable === true,
231
+ kms: appDefinition.encryption?.useDefaultKMSForFieldLevelEncryption === true,
232
+ ssm: appDefinition.ssm?.enable === true,
233
+ websockets: appDefinition.websockets?.enable === true,
234
+ // Add more feature detection as needed
235
+ };
236
+
237
+ return features;
238
+ }
239
+
240
+ function generateCloudFormationInstructions(options) {
241
+ const stackName = options.stackName || 'frigg-deployment-iam';
242
+ return `
243
+ šŸ“‹ Deployment Instructions (CloudFormation):
244
+
245
+ 1. Deploy the CloudFormation stack:
246
+ aws cloudformation create-stack \\
247
+ --stack-name ${stackName} \\
248
+ --template-body file://${options.output || 'backend/infrastructure'}/frigg-deployment-aws-cloudformation.yaml \\
249
+ --capabilities CAPABILITY_NAMED_IAM
250
+
251
+ 2. Wait for stack creation to complete:
252
+ aws cloudformation wait stack-create-complete --stack-name ${stackName}
253
+
254
+ 3. Retrieve the created user ARN:
255
+ aws cloudformation describe-stacks \\
256
+ --stack-name ${stackName} \\
257
+ --query 'Stacks[0].Outputs[?OutputKey==\`UserArn\`].OutputValue' \\
258
+ --output text
259
+
260
+ 4. Retrieve the access key ID:
261
+ aws cloudformation describe-stacks \\
262
+ --stack-name ${stackName} \\
263
+ --query 'Stacks[0].Outputs[?OutputKey==\`AccessKeyId\`].OutputValue' \\
264
+ --output text
265
+
266
+ 5. Retrieve the secret access key from Secrets Manager:
267
+ SECRET_NAME=$(aws cloudformation describe-stacks \\
268
+ --stack-name ${stackName} \\
269
+ --query 'Stacks[0].Outputs[?OutputKey==\`SecretName\`].OutputValue' \\
270
+ --output text)
271
+
272
+ aws secretsmanager get-secret-value \\
273
+ --secret-id $SECRET_NAME \\
274
+ --query 'SecretString' \\
275
+ --output text
276
+ `;
277
+ }
278
+
279
+ function generateTerraformInstructions(options) {
280
+ return `
281
+ šŸ“‹ Deployment Instructions (Terraform):
282
+
283
+ 1. Initialize Terraform:
284
+ cd ${options.output || 'backend/infrastructure'}
285
+ terraform init
286
+
287
+ 2. Review the plan:
288
+ terraform plan
289
+
290
+ 3. Apply the configuration:
291
+ terraform apply
292
+
293
+ 4. Retrieve the outputs:
294
+ terraform output -json
295
+
296
+ 5. The access key ID and secret will be displayed in the outputs.
297
+ Store them securely and use them for your CI/CD pipeline.
298
+
299
+ āš ļø Security Note: The secret access key is sensitive. Consider using:
300
+ - terraform output -raw secret_access_key | pbcopy # Copy to clipboard
301
+ - Store in your CI/CD secret management system
302
+ - Delete local state file if not using remote state
303
+ `;
304
+ }
305
+
306
+ function generateAzureInstructions(options) {
307
+ return `
308
+ šŸ“‹ Deployment Instructions (Azure ARM):
309
+
310
+ Azure ARM template support is coming soon.
311
+ For now, please use Terraform for Azure deployments.
312
+
313
+ To use Terraform with Azure:
314
+ 1. Run: frigg generate --provider azure --format terraform
315
+ 2. Follow the Terraform deployment instructions
316
+ `;
317
+ }
318
+
319
+ function generateGCPInstructions(options) {
320
+ return `
321
+ šŸ“‹ Deployment Instructions (GCP Deployment Manager):
322
+
323
+ GCP Deployment Manager support is coming soon.
324
+ For now, please use Terraform for GCP deployments.
325
+
326
+ To use Terraform with GCP:
327
+ 1. Run: frigg generate --provider gcp --format terraform
328
+ 2. Follow the Terraform deployment instructions
329
+ `;
330
+ }
331
+
332
+ module.exports = generateCommand;