@friggframework/devtools 2.0.0-next.47 → 2.0.0-next.48

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 (69) hide show
  1. package/frigg-cli/README.md +1290 -0
  2. package/frigg-cli/__tests__/unit/commands/build.test.js +279 -0
  3. package/frigg-cli/__tests__/unit/commands/db-setup.test.js +548 -0
  4. package/frigg-cli/__tests__/unit/commands/deploy.test.js +320 -0
  5. package/frigg-cli/__tests__/unit/commands/doctor.test.js +309 -0
  6. package/frigg-cli/__tests__/unit/commands/install.test.js +400 -0
  7. package/frigg-cli/__tests__/unit/commands/ui.test.js +346 -0
  8. package/frigg-cli/__tests__/unit/dependencies.test.js +74 -0
  9. package/frigg-cli/__tests__/unit/utils/database-validator.test.js +366 -0
  10. package/frigg-cli/__tests__/unit/utils/error-messages.test.js +304 -0
  11. package/frigg-cli/__tests__/unit/version-detection.test.js +171 -0
  12. package/frigg-cli/__tests__/utils/mock-factory.js +270 -0
  13. package/frigg-cli/__tests__/utils/prisma-mock.js +194 -0
  14. package/frigg-cli/__tests__/utils/test-fixtures.js +463 -0
  15. package/frigg-cli/__tests__/utils/test-setup.js +287 -0
  16. package/frigg-cli/build-command/index.js +66 -0
  17. package/frigg-cli/db-setup-command/index.js +193 -0
  18. package/frigg-cli/deploy-command/SPEC-DEPLOY-DRY-RUN.md +981 -0
  19. package/frigg-cli/deploy-command/index.js +302 -0
  20. package/frigg-cli/doctor-command/index.js +335 -0
  21. package/frigg-cli/generate-command/__tests__/generate-command.test.js +301 -0
  22. package/frigg-cli/generate-command/azure-generator.js +43 -0
  23. package/frigg-cli/generate-command/gcp-generator.js +47 -0
  24. package/frigg-cli/generate-command/index.js +332 -0
  25. package/frigg-cli/generate-command/terraform-generator.js +555 -0
  26. package/frigg-cli/generate-iam-command.js +118 -0
  27. package/frigg-cli/index.js +173 -0
  28. package/frigg-cli/index.test.js +158 -0
  29. package/frigg-cli/init-command/backend-first-handler.js +756 -0
  30. package/frigg-cli/init-command/index.js +93 -0
  31. package/frigg-cli/init-command/template-handler.js +143 -0
  32. package/frigg-cli/install-command/backend-js.js +33 -0
  33. package/frigg-cli/install-command/commit-changes.js +16 -0
  34. package/frigg-cli/install-command/environment-variables.js +127 -0
  35. package/frigg-cli/install-command/environment-variables.test.js +136 -0
  36. package/frigg-cli/install-command/index.js +54 -0
  37. package/frigg-cli/install-command/install-package.js +13 -0
  38. package/frigg-cli/install-command/integration-file.js +30 -0
  39. package/frigg-cli/install-command/logger.js +12 -0
  40. package/frigg-cli/install-command/template.js +90 -0
  41. package/frigg-cli/install-command/validate-package.js +75 -0
  42. package/frigg-cli/jest.config.js +124 -0
  43. package/frigg-cli/package.json +63 -0
  44. package/frigg-cli/repair-command/index.js +564 -0
  45. package/frigg-cli/start-command/index.js +149 -0
  46. package/frigg-cli/start-command/start-command.test.js +297 -0
  47. package/frigg-cli/test/init-command.test.js +180 -0
  48. package/frigg-cli/test/npm-registry.test.js +319 -0
  49. package/frigg-cli/ui-command/index.js +154 -0
  50. package/frigg-cli/utils/app-resolver.js +319 -0
  51. package/frigg-cli/utils/backend-path.js +25 -0
  52. package/frigg-cli/utils/database-validator.js +154 -0
  53. package/frigg-cli/utils/error-messages.js +257 -0
  54. package/frigg-cli/utils/npm-registry.js +167 -0
  55. package/frigg-cli/utils/process-manager.js +199 -0
  56. package/frigg-cli/utils/repo-detection.js +405 -0
  57. package/infrastructure/create-frigg-infrastructure.js +125 -12
  58. package/infrastructure/docs/PRE-DEPLOYMENT-HEALTH-CHECK-SPEC.md +1317 -0
  59. package/infrastructure/domains/shared/resource-discovery.enhanced.test.js +306 -0
  60. package/infrastructure/domains/shared/resource-discovery.js +31 -2
  61. package/infrastructure/domains/shared/utilities/base-definition-factory.js +1 -1
  62. package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +109 -5
  63. package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +310 -4
  64. package/infrastructure/domains/shared/validation/plugin-validator.js +187 -0
  65. package/infrastructure/domains/shared/validation/plugin-validator.test.js +323 -0
  66. package/infrastructure/infrastructure-composer.js +22 -0
  67. package/layers/prisma/.build-complete +3 -0
  68. package/package.json +18 -7
  69. package/management-ui/package-lock.json +0 -16517
@@ -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/domains/security/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?.fieldLevelEncryptionMethod === 'kms',
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;