-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(amplify-category-analytics): delete pinpoint project in delete (#…
…3165) * fix(amplify-category-analytics): delete pinpoint project in delete fix #2974 * test(amplify-e2e-tests): add e2e test for pinpoint project delete * update for changed analytics prompt * typo correction Co-authored-by: Zhou <zhoweimi@186590ce137f.ant.amazon.com>
- Loading branch information
1 parent
051b2fb
commit acc0240
Showing
10 changed files
with
240 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import { nspawn as spawn } from '../utils/nexpect'; | ||
import { getCLIPath, isCI } from '../utils'; | ||
import { Pinpoint } from 'aws-sdk'; | ||
|
||
const settings = { | ||
name: '\r', | ||
envName: 'test', | ||
editor: '\r', | ||
appType: '\r', | ||
framework: '\r', | ||
srcDir: '\r', | ||
distDir: '\r', | ||
buildCmd: '\r', | ||
startCmd: '\r', | ||
accessKeyId: process.env.AWS_ACCESS_KEY_ID, | ||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, | ||
region: process.env.CLI_REGION, | ||
pinpointResourceName: 'testpinpoint', | ||
}; | ||
|
||
export async function pinpointAppExist(pinpointProjectId: string): Promise<boolean> { | ||
let result = false; | ||
|
||
const pinpointClient = new Pinpoint({ | ||
accessKeyId: settings.accessKeyId, | ||
secretAccessKey: settings.secretAccessKey, | ||
region: settings.region, | ||
}); | ||
|
||
try { | ||
const response = await pinpointClient | ||
.getApp({ | ||
ApplicationId: pinpointProjectId, | ||
}) | ||
.promise(); | ||
if (response.ApplicationResponse.Id === pinpointProjectId) { | ||
result = true; | ||
} | ||
} catch (err) { | ||
if (err.code === 'NotFoundException') { | ||
result = false; | ||
} else { | ||
throw err; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
export function initProject(cwd: string, verbose: boolean = !isCI()) { | ||
return new Promise((resolve, reject) => { | ||
spawn(getCLIPath(), ['init'], { cwd, stripColors: true, verbose }) | ||
.wait('Enter a name for the project') | ||
.sendLine(settings.name) | ||
.wait('Enter a name for the environment') | ||
.sendLine(settings.envName) | ||
.wait('Choose your default editor:') | ||
.sendLine(settings.editor) | ||
.wait("Choose the type of app that you're building") | ||
.sendLine(settings.appType) | ||
.wait('What javascript framework are you using') | ||
.sendLine(settings.framework) | ||
.wait('Source Directory Path:') | ||
.sendLine(settings.srcDir) | ||
.wait('Distribution Directory Path:') | ||
.sendLine(settings.distDir) | ||
.wait('Build Command:') | ||
.sendLine(settings.buildCmd) | ||
.wait('Start Command:') | ||
.sendLine(settings.startCmd) | ||
.wait('Using default provider awscloudformation') | ||
.wait('Do you want to use an AWS profile?') | ||
.sendLine('n') | ||
.pauseRecording() | ||
.wait('accessKeyId') | ||
.sendLine(settings.accessKeyId) | ||
.wait('secretAccessKey') | ||
.sendLine(settings.secretAccessKey) | ||
.resumeRecording() | ||
.wait('region') | ||
.sendLine(settings.region) | ||
.wait('Try "amplify add api" to create a backend API and then "amplify publish" to deploy everything') | ||
.run((err: Error) => { | ||
if (!err) { | ||
resolve(); | ||
} else { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
export function addPinpointAnalytics(cwd: string, verbose: boolean = !isCI()): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
spawn(getCLIPath(), ['add', 'analytics'], { cwd, stripColors: true, verbose }) | ||
.wait('Please select from one of the below mentioned services') | ||
.sendCarriageReturn() | ||
.wait('Provide your pinpoint resource name:') | ||
.sendLine(settings.pinpointResourceName) | ||
.wait('Apps need authorization to send analytics events. Do you want to allow guests') | ||
.sendLine('n') | ||
.wait(`Successfully added resource ${settings.pinpointResourceName} locally`) | ||
.sendEof() | ||
.run((err: Error) => { | ||
if (!err) { | ||
resolve(settings.pinpointResourceName); | ||
} else { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
export function pushToCloud(cwd: string, verbose: boolean = !isCI()) { | ||
return new Promise((resolve, reject) => { | ||
spawn(getCLIPath(), ['push'], { cwd, stripColors: true, verbose }) | ||
.wait('Are you sure you want to continue') | ||
.sendCarriageReturn() | ||
.wait('All resources are updated in the cloud') | ||
.wait('Pinpoint URL to track events') | ||
.run((err: Error) => { | ||
if (!err) { | ||
resolve(); | ||
} else { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
export function amplifyDelete(cwd: string, verbose: boolean = !isCI()) { | ||
return new Promise((resolve, reject) => { | ||
spawn(getCLIPath(), ['delete'], { cwd, stripColors: true, verbose }) | ||
.wait('Are you sure you want to continue?') | ||
.sendLine('Y') | ||
.wait('Project deleted in the cloud') | ||
.wait('Project deleted locally.') | ||
.run((err: Error) => { | ||
if (!err) { | ||
resolve(); | ||
} else { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters