@stacksjs/ts-cloud 0.1.1

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 (117) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +321 -0
  3. package/bin/cli.ts +133 -0
  4. package/bin/commands/analytics.ts +328 -0
  5. package/bin/commands/api.ts +379 -0
  6. package/bin/commands/assets.ts +221 -0
  7. package/bin/commands/audit.ts +501 -0
  8. package/bin/commands/backup.ts +682 -0
  9. package/bin/commands/cache.ts +294 -0
  10. package/bin/commands/cdn.ts +281 -0
  11. package/bin/commands/config.ts +202 -0
  12. package/bin/commands/container.ts +105 -0
  13. package/bin/commands/cost.ts +208 -0
  14. package/bin/commands/database.ts +401 -0
  15. package/bin/commands/deploy.ts +674 -0
  16. package/bin/commands/domain.ts +397 -0
  17. package/bin/commands/email.ts +423 -0
  18. package/bin/commands/environment.ts +285 -0
  19. package/bin/commands/events.ts +424 -0
  20. package/bin/commands/firewall.ts +145 -0
  21. package/bin/commands/function.ts +116 -0
  22. package/bin/commands/generate.ts +280 -0
  23. package/bin/commands/git.ts +139 -0
  24. package/bin/commands/iam.ts +464 -0
  25. package/bin/commands/index.ts +48 -0
  26. package/bin/commands/init.ts +120 -0
  27. package/bin/commands/logs.ts +148 -0
  28. package/bin/commands/network.ts +579 -0
  29. package/bin/commands/notify.ts +489 -0
  30. package/bin/commands/queue.ts +407 -0
  31. package/bin/commands/scheduler.ts +370 -0
  32. package/bin/commands/secrets.ts +54 -0
  33. package/bin/commands/server.ts +629 -0
  34. package/bin/commands/shared.ts +97 -0
  35. package/bin/commands/ssl.ts +138 -0
  36. package/bin/commands/stack.ts +325 -0
  37. package/bin/commands/status.ts +385 -0
  38. package/bin/commands/storage.ts +450 -0
  39. package/bin/commands/team.ts +96 -0
  40. package/bin/commands/tunnel.ts +489 -0
  41. package/bin/commands/utils.ts +202 -0
  42. package/build.ts +15 -0
  43. package/cloud +2 -0
  44. package/package.json +99 -0
  45. package/src/aws/acm.ts +768 -0
  46. package/src/aws/application-autoscaling.ts +845 -0
  47. package/src/aws/bedrock.ts +4074 -0
  48. package/src/aws/client.ts +878 -0
  49. package/src/aws/cloudformation.ts +896 -0
  50. package/src/aws/cloudfront.ts +1531 -0
  51. package/src/aws/cloudwatch-logs.ts +154 -0
  52. package/src/aws/comprehend.ts +839 -0
  53. package/src/aws/connect.ts +1056 -0
  54. package/src/aws/deploy-imap.ts +384 -0
  55. package/src/aws/dynamodb.ts +340 -0
  56. package/src/aws/ec2.ts +1385 -0
  57. package/src/aws/ecr.ts +621 -0
  58. package/src/aws/ecs.ts +615 -0
  59. package/src/aws/elasticache.ts +301 -0
  60. package/src/aws/elbv2.ts +942 -0
  61. package/src/aws/email.ts +928 -0
  62. package/src/aws/eventbridge.ts +248 -0
  63. package/src/aws/iam.ts +1689 -0
  64. package/src/aws/imap-server.ts +2100 -0
  65. package/src/aws/index.ts +213 -0
  66. package/src/aws/kendra.ts +1097 -0
  67. package/src/aws/lambda.ts +786 -0
  68. package/src/aws/opensearch.ts +158 -0
  69. package/src/aws/personalize.ts +977 -0
  70. package/src/aws/polly.ts +559 -0
  71. package/src/aws/rds.ts +888 -0
  72. package/src/aws/rekognition.ts +846 -0
  73. package/src/aws/route53-domains.ts +359 -0
  74. package/src/aws/route53.ts +1046 -0
  75. package/src/aws/s3.ts +2318 -0
  76. package/src/aws/scheduler.ts +571 -0
  77. package/src/aws/secrets-manager.ts +769 -0
  78. package/src/aws/ses.ts +1081 -0
  79. package/src/aws/setup-phone.ts +104 -0
  80. package/src/aws/setup-sms.ts +580 -0
  81. package/src/aws/sms.ts +1735 -0
  82. package/src/aws/smtp-server.ts +531 -0
  83. package/src/aws/sns.ts +758 -0
  84. package/src/aws/sqs.ts +382 -0
  85. package/src/aws/ssm.ts +807 -0
  86. package/src/aws/sts.ts +92 -0
  87. package/src/aws/support.ts +391 -0
  88. package/src/aws/test-imap.ts +86 -0
  89. package/src/aws/textract.ts +780 -0
  90. package/src/aws/transcribe.ts +108 -0
  91. package/src/aws/translate.ts +641 -0
  92. package/src/aws/voice.ts +1379 -0
  93. package/src/config.ts +35 -0
  94. package/src/deploy/index.ts +7 -0
  95. package/src/deploy/static-site-external-dns.ts +906 -0
  96. package/src/deploy/static-site.ts +1125 -0
  97. package/src/dns/godaddy.ts +412 -0
  98. package/src/dns/index.ts +183 -0
  99. package/src/dns/porkbun.ts +362 -0
  100. package/src/dns/route53-adapter.ts +414 -0
  101. package/src/dns/types.ts +114 -0
  102. package/src/dns/validator.ts +369 -0
  103. package/src/generators/index.ts +5 -0
  104. package/src/generators/infrastructure.ts +1660 -0
  105. package/src/index.ts +163 -0
  106. package/src/push/apns.ts +452 -0
  107. package/src/push/fcm.ts +506 -0
  108. package/src/push/index.ts +58 -0
  109. package/src/ssl/acme-client.ts +478 -0
  110. package/src/ssl/index.ts +7 -0
  111. package/src/ssl/letsencrypt.ts +747 -0
  112. package/src/types.ts +2 -0
  113. package/src/utils/cli.ts +398 -0
  114. package/src/validation/index.ts +5 -0
  115. package/src/validation/template.ts +405 -0
  116. package/test/index.test.ts +128 -0
  117. package/tsconfig.json +18 -0
@@ -0,0 +1,464 @@
1
+ import type { CLI } from '@stacksjs/clapp'
2
+ import * as cli from '../../src/utils/cli'
3
+ import { IAMClient } from '../../src/aws/iam'
4
+ import { loadValidatedConfig } from './shared'
5
+
6
+ export function registerIamCommands(app: CLI): void {
7
+ app
8
+ .command('iam:roles', 'List IAM roles')
9
+ .option('--prefix <prefix>', 'Filter by role name prefix')
10
+ .option('--path <path>', 'Filter by path prefix', { default: '/' })
11
+ .action(async (options: { prefix?: string; path: string }) => {
12
+ cli.header('IAM Roles')
13
+
14
+ try {
15
+ const iam = new IAMClient()
16
+
17
+ const spinner = new cli.Spinner('Fetching roles...')
18
+ spinner.start()
19
+
20
+ const result = await iam.listRoles({ PathPrefix: options.path })
21
+ let roles = result.Roles || []
22
+
23
+ if (options.prefix) {
24
+ roles = roles.filter(r => r.RoleName?.startsWith(options.prefix!))
25
+ }
26
+
27
+ spinner.succeed(`Found ${roles.length} role(s)`)
28
+
29
+ if (roles.length === 0) {
30
+ cli.info('No IAM roles found')
31
+ return
32
+ }
33
+
34
+ cli.table(
35
+ ['Role Name', 'Path', 'Created', 'Description'],
36
+ roles.map(role => [
37
+ role.RoleName || 'N/A',
38
+ role.Path || '/',
39
+ role.CreateDate ? new Date(role.CreateDate).toLocaleDateString() : 'N/A',
40
+ (role.Description || '').substring(0, 40),
41
+ ]),
42
+ )
43
+ }
44
+ catch (error: any) {
45
+ cli.error(`Failed to list roles: ${error.message}`)
46
+ process.exit(1)
47
+ }
48
+ })
49
+
50
+ app
51
+ .command('iam:role <roleName>', 'Show IAM role details')
52
+ .action(async (roleName: string) => {
53
+ cli.header(`IAM Role: ${roleName}`)
54
+
55
+ try {
56
+ const iam = new IAMClient()
57
+
58
+ const spinner = new cli.Spinner('Fetching role details...')
59
+ spinner.start()
60
+
61
+ const role = await iam.getRole({ RoleName: roleName })
62
+
63
+ // Get attached policies
64
+ const attachedPolicies = await iam.listAttachedRolePolicies({ RoleName: roleName })
65
+ const inlinePolicies = await iam.listRolePolicies({ RoleName: roleName })
66
+
67
+ spinner.succeed('Role details loaded')
68
+
69
+ cli.info('\nRole Information:')
70
+ cli.info(` Name: ${role.RoleName}`)
71
+ cli.info(` ARN: ${role.Arn}`)
72
+ cli.info(` Path: ${role.Path}`)
73
+ cli.info(` Created: ${role.CreateDate ? new Date(role.CreateDate).toLocaleString() : 'N/A'}`)
74
+
75
+ if (role.Description) {
76
+ cli.info(` Description: ${role.Description}`)
77
+ }
78
+
79
+ if (role.MaxSessionDuration) {
80
+ cli.info(` Max Session: ${role.MaxSessionDuration / 3600} hours`)
81
+ }
82
+
83
+ if (role.AssumeRolePolicyDocument) {
84
+ cli.info('\nTrust Policy:')
85
+ const trustPolicy = JSON.parse(decodeURIComponent(role.AssumeRolePolicyDocument))
86
+ console.log(JSON.stringify(trustPolicy, null, 2))
87
+ }
88
+
89
+ if (attachedPolicies.AttachedPolicies && attachedPolicies.AttachedPolicies.length > 0) {
90
+ cli.info('\nAttached Managed Policies:')
91
+ for (const policy of attachedPolicies.AttachedPolicies) {
92
+ cli.info(` - ${policy.PolicyName}`)
93
+ }
94
+ }
95
+
96
+ if (inlinePolicies.PolicyNames && inlinePolicies.PolicyNames.length > 0) {
97
+ cli.info('\nInline Policies:')
98
+ for (const policyName of inlinePolicies.PolicyNames) {
99
+ cli.info(` - ${policyName}`)
100
+ }
101
+ }
102
+
103
+ if (role.Tags && role.Tags.length > 0) {
104
+ cli.info('\nTags:')
105
+ for (const tag of role.Tags) {
106
+ cli.info(` ${tag.Key}: ${tag.Value}`)
107
+ }
108
+ }
109
+ }
110
+ catch (error: any) {
111
+ cli.error(`Failed to get role: ${error.message}`)
112
+ process.exit(1)
113
+ }
114
+ })
115
+
116
+ app
117
+ .command('iam:policies', 'List IAM policies')
118
+ .option('--scope <scope>', 'Filter by scope (All, AWS, Local)', { default: 'Local' })
119
+ .option('--prefix <prefix>', 'Filter by policy name prefix')
120
+ .option('--path <path>', 'Filter by path prefix', { default: '/' })
121
+ .action(async (options: { scope: 'All' | 'AWS' | 'Local'; prefix?: string; path: string }) => {
122
+ cli.header('IAM Policies')
123
+
124
+ try {
125
+ const iam = new IAMClient()
126
+
127
+ const spinner = new cli.Spinner('Fetching policies...')
128
+ spinner.start()
129
+
130
+ const result = await iam.listPolicies({
131
+ Scope: options.scope,
132
+ PathPrefix: options.path,
133
+ OnlyAttached: false,
134
+ })
135
+
136
+ let policies = result.Policies || []
137
+
138
+ if (options.prefix) {
139
+ policies = policies.filter(p => p.PolicyName?.startsWith(options.prefix!))
140
+ }
141
+
142
+ spinner.succeed(`Found ${policies.length} policy(s)`)
143
+
144
+ if (policies.length === 0) {
145
+ cli.info('No IAM policies found')
146
+ return
147
+ }
148
+
149
+ cli.table(
150
+ ['Policy Name', 'ARN', 'Attachments', 'Created'],
151
+ policies.slice(0, 50).map(policy => [
152
+ policy.PolicyName || 'N/A',
153
+ (policy.Arn || 'N/A').substring(0, 50),
154
+ (policy.AttachmentCount || 0).toString(),
155
+ policy.CreateDate ? new Date(policy.CreateDate).toLocaleDateString() : 'N/A',
156
+ ]),
157
+ )
158
+
159
+ if (policies.length > 50) {
160
+ cli.info(`\n... and ${policies.length - 50} more policies`)
161
+ }
162
+ }
163
+ catch (error: any) {
164
+ cli.error(`Failed to list policies: ${error.message}`)
165
+ process.exit(1)
166
+ }
167
+ })
168
+
169
+ app
170
+ .command('iam:policy <policyArn>', 'Show IAM policy details')
171
+ .option('--version <version>', 'Policy version ID')
172
+ .action(async (policyArn: string, options: { version?: string }) => {
173
+ cli.header('IAM Policy Details')
174
+
175
+ try {
176
+ const iam = new IAMClient()
177
+
178
+ const spinner = new cli.Spinner('Fetching policy...')
179
+ spinner.start()
180
+
181
+ const policy = await iam.getPolicy({ PolicyArn: policyArn })
182
+
183
+ // Get the policy document
184
+ const versionId = options.version || policy.DefaultVersionId || 'v1'
185
+ const versionResult = await iam.getPolicyVersion({
186
+ PolicyArn: policyArn,
187
+ VersionId: versionId,
188
+ })
189
+
190
+ spinner.succeed('Policy loaded')
191
+
192
+ cli.info('\nPolicy Information:')
193
+ cli.info(` Name: ${policy.PolicyName}`)
194
+ cli.info(` ARN: ${policy.Arn}`)
195
+ cli.info(` Path: ${policy.Path}`)
196
+ cli.info(` Created: ${policy.CreateDate ? new Date(policy.CreateDate).toLocaleString() : 'N/A'}`)
197
+ cli.info(` Updated: ${policy.UpdateDate ? new Date(policy.UpdateDate).toLocaleString() : 'N/A'}`)
198
+ cli.info(` Attachment Count: ${policy.AttachmentCount || 0}`)
199
+ cli.info(` Version: ${versionId}`)
200
+
201
+ if (policy.Description) {
202
+ cli.info(` Description: ${policy.Description}`)
203
+ }
204
+
205
+ if (versionResult.Document) {
206
+ cli.info('\nPolicy Document:')
207
+ const document = JSON.parse(decodeURIComponent(versionResult.Document))
208
+ console.log(JSON.stringify(document, null, 2))
209
+ }
210
+ }
211
+ catch (error: any) {
212
+ cli.error(`Failed to get policy: ${error.message}`)
213
+ process.exit(1)
214
+ }
215
+ })
216
+
217
+ app
218
+ .command('iam:users', 'List IAM users')
219
+ .option('--path <path>', 'Filter by path prefix', { default: '/' })
220
+ .action(async (options: { path: string }) => {
221
+ cli.header('IAM Users')
222
+
223
+ try {
224
+ const iam = new IAMClient()
225
+
226
+ const spinner = new cli.Spinner('Fetching users...')
227
+ spinner.start()
228
+
229
+ const result = await iam.listUsers({ PathPrefix: options.path })
230
+ const users = result.Users || []
231
+
232
+ spinner.succeed(`Found ${users.length} user(s)`)
233
+
234
+ if (users.length === 0) {
235
+ cli.info('No IAM users found')
236
+ return
237
+ }
238
+
239
+ cli.table(
240
+ ['User Name', 'User ID', 'Path', 'Created', 'Password Last Used'],
241
+ users.map(user => [
242
+ user.UserName || 'N/A',
243
+ user.UserId || 'N/A',
244
+ user.Path || '/',
245
+ user.CreateDate ? new Date(user.CreateDate).toLocaleDateString() : 'N/A',
246
+ user.PasswordLastUsed ? new Date(user.PasswordLastUsed).toLocaleDateString() : 'Never',
247
+ ]),
248
+ )
249
+ }
250
+ catch (error: any) {
251
+ cli.error(`Failed to list users: ${error.message}`)
252
+ process.exit(1)
253
+ }
254
+ })
255
+
256
+ app
257
+ .command('iam:user <userName>', 'Show IAM user details')
258
+ .action(async (userName: string) => {
259
+ cli.header(`IAM User: ${userName}`)
260
+
261
+ try {
262
+ const iam = new IAMClient()
263
+
264
+ const spinner = new cli.Spinner('Fetching user details...')
265
+ spinner.start()
266
+
267
+ const user = await iam.getUser({ UserName: userName })
268
+
269
+ // Get additional info
270
+ const [groups, policies, accessKeys] = await Promise.all([
271
+ iam.listGroupsForUser({ UserName: userName }),
272
+ iam.listAttachedUserPolicies({ UserName: userName }),
273
+ iam.listAccessKeys({ UserName: userName }),
274
+ ])
275
+
276
+ spinner.succeed('User details loaded')
277
+
278
+ cli.info('\nUser Information:')
279
+ cli.info(` Name: ${user.UserName}`)
280
+ cli.info(` ARN: ${user.Arn}`)
281
+ cli.info(` User ID: ${user.UserId}`)
282
+ cli.info(` Path: ${user.Path}`)
283
+ cli.info(` Created: ${user.CreateDate ? new Date(user.CreateDate).toLocaleString() : 'N/A'}`)
284
+
285
+ if (user.PasswordLastUsed) {
286
+ cli.info(` Password Last Used: ${new Date(user.PasswordLastUsed).toLocaleString()}`)
287
+ }
288
+
289
+ if (groups.Groups && groups.Groups.length > 0) {
290
+ cli.info('\nGroups:')
291
+ for (const group of groups.Groups) {
292
+ cli.info(` - ${group.GroupName}`)
293
+ }
294
+ }
295
+
296
+ if (policies.AttachedPolicies && policies.AttachedPolicies.length > 0) {
297
+ cli.info('\nAttached Policies:')
298
+ for (const policy of policies.AttachedPolicies) {
299
+ cli.info(` - ${policy.PolicyName}`)
300
+ }
301
+ }
302
+
303
+ if (accessKeys.AccessKeyMetadata && accessKeys.AccessKeyMetadata.length > 0) {
304
+ cli.info('\nAccess Keys:')
305
+ for (const key of accessKeys.AccessKeyMetadata) {
306
+ cli.info(` - ${key.AccessKeyId}: ${key.Status}`)
307
+ if (key.CreateDate) {
308
+ cli.info(` Created: ${new Date(key.CreateDate).toLocaleString()}`)
309
+ }
310
+ }
311
+ }
312
+
313
+ if (user.Tags && user.Tags.length > 0) {
314
+ cli.info('\nTags:')
315
+ for (const tag of user.Tags) {
316
+ cli.info(` ${tag.Key}: ${tag.Value}`)
317
+ }
318
+ }
319
+ }
320
+ catch (error: any) {
321
+ cli.error(`Failed to get user: ${error.message}`)
322
+ process.exit(1)
323
+ }
324
+ })
325
+
326
+ app
327
+ .command('iam:groups', 'List IAM groups')
328
+ .option('--path <path>', 'Filter by path prefix', { default: '/' })
329
+ .action(async (options: { path: string }) => {
330
+ cli.header('IAM Groups')
331
+
332
+ try {
333
+ const iam = new IAMClient()
334
+
335
+ const spinner = new cli.Spinner('Fetching groups...')
336
+ spinner.start()
337
+
338
+ const result = await iam.listGroups({ PathPrefix: options.path })
339
+ const groups = result.Groups || []
340
+
341
+ spinner.succeed(`Found ${groups.length} group(s)`)
342
+
343
+ if (groups.length === 0) {
344
+ cli.info('No IAM groups found')
345
+ return
346
+ }
347
+
348
+ cli.table(
349
+ ['Group Name', 'Group ID', 'Path', 'Created'],
350
+ groups.map(group => [
351
+ group.GroupName || 'N/A',
352
+ group.GroupId || 'N/A',
353
+ group.Path || '/',
354
+ group.CreateDate ? new Date(group.CreateDate).toLocaleDateString() : 'N/A',
355
+ ]),
356
+ )
357
+ }
358
+ catch (error: any) {
359
+ cli.error(`Failed to list groups: ${error.message}`)
360
+ process.exit(1)
361
+ }
362
+ })
363
+
364
+ app
365
+ .command('iam:simulate <policyArn>', 'Simulate IAM policy')
366
+ .option('--action <action>', 'Action to simulate (e.g., s3:GetObject)')
367
+ .option('--resource <arn>', 'Resource ARN to test against')
368
+ .action(async (policyArn: string, options: { action?: string; resource?: string }) => {
369
+ cli.header('Simulate IAM Policy')
370
+
371
+ try {
372
+ const iam = new IAMClient()
373
+
374
+ const action = options.action || await cli.prompt('Action to simulate', 's3:GetObject')
375
+ const resource = options.resource || await cli.prompt('Resource ARN', '*')
376
+
377
+ cli.info(`\nPolicy: ${policyArn}`)
378
+ cli.info(`Action: ${action}`)
379
+ cli.info(`Resource: ${resource}`)
380
+
381
+ const spinner = new cli.Spinner('Running simulation...')
382
+ spinner.start()
383
+
384
+ const result = await iam.simulatePrincipalPolicy({
385
+ PolicySourceArn: policyArn,
386
+ ActionNames: [action],
387
+ ResourceArns: [resource],
388
+ })
389
+
390
+ spinner.succeed('Simulation complete')
391
+
392
+ if (result.EvaluationResults && result.EvaluationResults.length > 0) {
393
+ for (const evalResult of result.EvaluationResults) {
394
+ const decision = evalResult.EvalDecision
395
+
396
+ cli.info(`\nResult for ${evalResult.EvalActionName}:`)
397
+
398
+ if (decision === 'allowed') {
399
+ cli.success(` Decision: ALLOWED`)
400
+ }
401
+ else if (decision === 'implicitDeny') {
402
+ cli.warn(` Decision: IMPLICIT DENY (no matching allow statement)`)
403
+ }
404
+ else {
405
+ cli.error(` Decision: EXPLICIT DENY`)
406
+ }
407
+
408
+ if (evalResult.MatchedStatements && evalResult.MatchedStatements.length > 0) {
409
+ cli.info(' Matched Statements:')
410
+ for (const statement of evalResult.MatchedStatements) {
411
+ cli.info(` - ${statement.SourcePolicyId}: ${statement.SourcePolicyType}`)
412
+ }
413
+ }
414
+ }
415
+ }
416
+ }
417
+ catch (error: any) {
418
+ cli.error(`Failed to simulate policy: ${error.message}`)
419
+ process.exit(1)
420
+ }
421
+ })
422
+
423
+ app
424
+ .command('iam:whoami', 'Show current IAM identity')
425
+ .action(async () => {
426
+ cli.header('Current IAM Identity')
427
+
428
+ try {
429
+ const iam = new IAMClient()
430
+
431
+ const spinner = new cli.Spinner('Fetching identity...')
432
+ spinner.start()
433
+
434
+ // Use STS to get caller identity
435
+ const { STSClient } = await import('../../src/aws/sts')
436
+ const sts = new STSClient('us-east-1')
437
+ const identity = await sts.getCallerIdentity()
438
+
439
+ spinner.succeed('Identity loaded')
440
+
441
+ cli.info('\nCaller Identity:')
442
+ cli.info(` Account: ${identity.Account}`)
443
+ cli.info(` ARN: ${identity.Arn}`)
444
+ cli.info(` User ID: ${identity.UserId}`)
445
+
446
+ // Determine identity type
447
+ const arn = identity.Arn || ''
448
+ if (arn.includes(':user/')) {
449
+ cli.info(` Type: IAM User`)
450
+ }
451
+ else if (arn.includes(':assumed-role/')) {
452
+ cli.info(` Type: Assumed Role`)
453
+ }
454
+ else if (arn.includes(':root')) {
455
+ cli.warn(` Type: Root Account`)
456
+ cli.warn('\n Warning: Using root credentials is not recommended!')
457
+ }
458
+ }
459
+ catch (error: any) {
460
+ cli.error(`Failed to get identity: ${error.message}`)
461
+ process.exit(1)
462
+ }
463
+ })
464
+ }
@@ -0,0 +1,48 @@
1
+ export { registerInitCommands } from './init'
2
+ export { registerConfigCommands } from './config'
3
+ export { registerGenerateCommands } from './generate'
4
+ export { registerServerCommands } from './server'
5
+ export { registerFunctionCommands } from './function'
6
+ export { registerContainerCommands } from './container'
7
+ export { registerDomainCommands } from './domain'
8
+ export { registerDatabaseCommands } from './database'
9
+ export { registerLogsCommands } from './logs'
10
+ export { registerSecretsCommands } from './secrets'
11
+ export { registerFirewallCommands } from './firewall'
12
+ export { registerSslCommands } from './ssl'
13
+ export { registerCostCommands } from './cost'
14
+ export { registerGitCommands } from './git'
15
+ export { registerEnvironmentCommands } from './environment'
16
+ export { registerAssetsCommands } from './assets'
17
+ export { registerTeamCommands } from './team'
18
+ export { registerDeployCommands } from './deploy'
19
+ export { registerStackCommands } from './stack'
20
+ export { registerUtilsCommands } from './utils'
21
+ export { registerAnalyticsCommands } from './analytics'
22
+
23
+ // New infrastructure commands
24
+ export { registerCdnCommands } from './cdn'
25
+ export { registerStorageCommands } from './storage'
26
+ export { registerCacheCommands } from './cache'
27
+ export { registerQueueCommands } from './queue'
28
+ export { registerNetworkCommands } from './network'
29
+
30
+ // Scheduling & Events
31
+ export { registerSchedulerCommands } from './scheduler'
32
+ export { registerEventsCommands } from './events'
33
+
34
+ // Communication
35
+ export { registerEmailCommands } from './email'
36
+ export { registerNotifyCommands } from './notify'
37
+
38
+ // Security & Access
39
+ export { registerIamCommands } from './iam'
40
+ export { registerAuditCommands } from './audit'
41
+
42
+ // Operations
43
+ export { registerStatusCommands } from './status'
44
+ export { registerBackupCommands } from './backup'
45
+ export { registerApiCommands } from './api'
46
+ export { registerTunnelCommands } from './tunnel'
47
+
48
+ export { loadValidatedConfig, resolveDnsProviderConfig, getDnsProvider } from './shared'
@@ -0,0 +1,120 @@
1
+ import type { CLI } from '@stacksjs/clapp'
2
+ import { existsSync } from 'node:fs'
3
+ import { mkdir, writeFile } from 'node:fs/promises'
4
+ import * as cli from '../../src/utils/cli'
5
+
6
+ export function registerInitCommands(app: CLI): void {
7
+ app
8
+ .command('init', 'Initialize a new ts-cloud project')
9
+ .option('--mode <mode>', 'Deployment mode: server, serverless, or hybrid')
10
+ .option('--name <name>', 'Project name')
11
+ .option('--region <region>', 'AWS Region')
12
+ .action(async (options?: { mode?: string, name?: string, region?: string }) => {
13
+ cli.header('Initializing ts-cloud Project')
14
+
15
+ // Check if already initialized
16
+ if (existsSync('cloud.config.ts')) {
17
+ const overwrite = await cli.confirm('cloud.config.ts already exists. Overwrite?', false)
18
+ if (!overwrite) {
19
+ cli.info('Initialization cancelled')
20
+ return
21
+ }
22
+ }
23
+
24
+ // Get project name
25
+ const projectName = options?.name || await cli.prompt('Project name', 'my-app')
26
+
27
+ // Get deployment mode
28
+ const mode = options?.mode || await cli.select(
29
+ 'Select deployment mode',
30
+ ['serverless', 'server', 'hybrid'],
31
+ )
32
+
33
+ // Get AWS region
34
+ const region = options?.region || await cli.select(
35
+ 'Select AWS region',
36
+ ['us-east-1', 'us-west-2', 'eu-west-1', 'eu-central-1', 'ap-southeast-1'],
37
+ )
38
+
39
+ // Create cloud.config.ts
40
+ const spinner = new cli.Spinner('Creating configuration file...')
41
+ spinner.start()
42
+
43
+ const configContent = `import { defineConfig } from '@stacksjs/ts-cloud-types'
44
+
45
+ export default defineConfig({
46
+ project: {
47
+ name: '${projectName}',
48
+ slug: '${projectName.toLowerCase().replace(/[^a-z0-9-]/g, '-')}',
49
+ region: '${region}',
50
+ },
51
+ mode: '${mode}',
52
+ environments: {
53
+ production: {
54
+ enabled: true,
55
+ },
56
+ staging: {
57
+ enabled: true,
58
+ },
59
+ development: {
60
+ enabled: true,
61
+ },
62
+ },
63
+ infrastructure: {
64
+ // Add your infrastructure configuration here
65
+ },
66
+ })
67
+ `
68
+
69
+ await writeFile('cloud.config.ts', configContent)
70
+ spinner.succeed('Created cloud.config.ts')
71
+
72
+ // Create .gitignore
73
+ if (!existsSync('.gitignore')) {
74
+ await writeFile('.gitignore', `.env
75
+ .env.*
76
+ node_modules/
77
+ dist/
78
+ cloudformation/
79
+ *.log
80
+ .DS_Store
81
+ `)
82
+ cli.success('Created .gitignore')
83
+ }
84
+
85
+ // Create cloudformation directory
86
+ if (!existsSync('cloudformation')) {
87
+ await mkdir('cloudformation', { recursive: true })
88
+ cli.success('Created cloudformation/ directory')
89
+ }
90
+
91
+ cli.box(`ts-cloud project initialized!
92
+
93
+ Next steps:
94
+ 1. Edit cloud.config.ts to configure your infrastructure
95
+ 2. Run 'cloud generate' to create CloudFormation templates
96
+ 3. Run 'cloud deploy' to deploy your infrastructure`, 'green')
97
+ })
98
+
99
+ app
100
+ .command('init:server', 'Initialize server-based (EC2) project')
101
+ .action(async () => {
102
+ cli.header('Initializing Server-Based Project')
103
+ // Delegate to init with mode
104
+ await app.parse(['init', '--mode', 'server'])
105
+ })
106
+
107
+ app
108
+ .command('init:serverless', 'Initialize serverless (Fargate/Lambda) project')
109
+ .action(async () => {
110
+ cli.header('Initializing Serverless Project')
111
+ await app.parse(['init', '--mode', 'serverless'])
112
+ })
113
+
114
+ app
115
+ .command('init:hybrid', 'Initialize hybrid project')
116
+ .action(async () => {
117
+ cli.header('Initializing Hybrid Project')
118
+ await app.parse(['init', '--mode', 'hybrid'])
119
+ })
120
+ }