Skip to content

Commit 7982355

Browse files
committed
feat: add idp flag; remove copyAwsProfile; add check for existing .codegenie directory
1 parent 3c161fe commit 7982355

File tree

3 files changed

+28
-49
lines changed

3 files changed

+28
-49
lines changed

src/aws-creds.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import fs from 'node:fs'
2+
import path from 'node:path'
3+
import os from 'node:os'
4+
5+
const awsCredentialsFilePath = path.resolve(os.homedir(), '.aws/credentials')
6+
7+
export function awsCredentialsFileExists() {
8+
return fs.existsSync(awsCredentialsFilePath)
9+
}

src/commands/generate.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { cosmiconfig } from 'cosmiconfig'
77
import createDebug from 'debug'
88
import _s from 'underscore.string'
99
// import codeGenieSampleOpenAiOutputJson from '../sample-api-output.js'
10-
import copyAwsProfile, { awsCredentialsFileExists } from '../copyAwsProfile.js'
10+
import { awsCredentialsFileExists } from '../aws-creds.js'
1111
import sleep from '../sleep.js'
1212
import { execSync } from 'node:child_process'
1313
import { Readable } from 'node:stream'
@@ -73,12 +73,6 @@ generating app...
7373
"The AWS Profile to copy in the ~/.aws/credentials file and used to deploy the application. Defaults to the 'default' profile. Specify --noCopyAwsProfile to skip this step",
7474
default: 'default',
7575
}),
76-
noCopyAwsProfile: Flags.boolean({
77-
description:
78-
'Skips copying an AWS profile in the ~/.aws/credentials file. You must specify a your-app-name_dev (as well as _staging and _prod) profile before you can deploy the app.',
79-
required: false,
80-
default: false,
81-
}),
8276
replaceAppDefinition: Flags.boolean({
8377
char: 'r',
8478
description: 'Replaces the current .codegenie directory.',
@@ -90,11 +84,16 @@ generating app...
9084
required: false,
9185
default: false,
9286
}),
87+
idp: Flags.string({
88+
description: 'Supported identity providers. Valid values include "Google" and "SAML". Can be specified multiple times to enable multiple IDPs.',
89+
required: false,
90+
multiple: true,
91+
}),
9392
}
9493

9594
async run(): Promise<{ description?: string; deploy: boolean; awsProfileToCopy: string; appDir: string }> {
9695
const { flags } = await this.parse(Generate)
97-
const { name, description, deploy, awsProfileToCopy, noCopyAwsProfile, generateAppDefinitionOnly } = flags
96+
const { name, description, deploy, awsProfileToCopy, generateAppDefinitionOnly } = flags
9897

9998
if (description && description.length > 500) {
10099
this.error('description must be less than 500 characters.', {
@@ -128,6 +127,7 @@ generating app...
128127
if (!hasExistingAppDefinition) {
129128
appDir = getAppOutputDir({ appName: generateAppDefinitionResult.appName })
130129
}
130+
131131
if (generateAppDefinitionOnly) {
132132
const appDirRelative = getAppOutputDir({ appName, absolute: false })
133133
this.log(`The app definition has successfully been generated and downloaded to \`./${appDirRelative}\`.`)
@@ -138,6 +138,14 @@ generating app...
138138
appDir,
139139
}
140140
}
141+
} else if (!existsSync(path.join(cwd(), '.codegenie'))) {
142+
this.error("No .codegenie directory found. Make sure you're running this command inside a directory that has a child .codegenie directory.", {
143+
code: 'APP_DEFINITION_DIR_NOT_FOUND',
144+
suggestions: [
145+
'Run the generate command within a directory that has a .codegenie directory inside it.',
146+
'Run the generate command with a `--description "detailed description of app"` to generate a starter point for your app definition.',
147+
],
148+
})
141149
}
142150

143151
const { headOutputPresignedUrl, getOutputPresignedUrl } = await this.uploadAppDefinition({ appDir })
@@ -166,10 +174,6 @@ For now you can open \`./${appDirRelative}\` in your favorite IDE like VS Code.
166174
}
167175
}
168176

169-
if (!noCopyAwsProfile) {
170-
copyAwsProfile({ appName })
171-
}
172-
173177
if (deploy) {
174178
await this.runInitDev({ appDir, appName })
175179
} else {
@@ -237,12 +241,14 @@ For now you can open \`./${appDirRelative}\` in your favorite IDE like VS Code.
237241
*/
238242
async generateAppDefinition({ appName, appDir }: { appName: string; appDir: string }): Promise<{ appName: string; appDescription: string }> {
239243
const { flags } = await this.parse(Generate)
240-
const { description } = flags
244+
const { description, idp } = flags
241245
ux.action.start('🧞 Generating App Definition. This may take a minute')
246+
242247
try {
243248
const output = await axios.post('/app-definition-generator', {
244249
name: appName,
245250
description,
251+
idps: idp,
246252
})
247253
const { headAppDefinitionPresignedUrl, getAppDefinitionPresignedUrl } = output.data.data
248254
await sleep(30_000) // It takes at least 30s to generate a definition; chill before polling

src/copyAwsProfile.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)