-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add non-interactive init/pull in git-cloned project #11365
Changes from 6 commits
71211a2
8d9dcb2
3adf756
6cafabb
3793357
38e4313
9216556
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,6 +178,7 @@ | |
"uint", | ||
"unauth", | ||
"unlink", | ||
"unstaged", | ||
"updateamplify", | ||
"urls", | ||
"userpool", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Shape of awscloudformation object within `--profile` payload for init/pull | ||
*/ | ||
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have a similar type in prod code base? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't have an exact corollary but we have some types here that define the credential config (plus other values that it can have) |
||
export type AwsProviderConfig = { | ||
configLevel: string, | ||
useProfile: boolean, | ||
profileName: string, | ||
} | ||
|
||
/** | ||
* Shape of `--categories` payload for init/pull | ||
*/ | ||
export type CategoriesConfig = Record<string, unknown>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
/* eslint-disable import/no-cycle */ | ||
export * from './amplifyPull'; | ||
export * from './amplifyPush'; | ||
export * from './deleteProject'; | ||
export * from './initProjectHelper'; | ||
export * from './pull-headless'; | ||
export * from './adminUI'; | ||
export * from './overrideStack'; | ||
export * from './non-interactive-init'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import execa from 'execa'; | ||
// eslint-disable-next-line import/no-cycle | ||
import { getCLIPath, TEST_PROFILE_NAME } from '..'; | ||
import { CategoriesConfig, AwsProviderConfig } from './headless-types'; | ||
|
||
/** | ||
* Executes a non-interactive init to attach a local project to an existing cloud environment | ||
*/ | ||
export const nonInteractiveInitAttach = async ( | ||
projRoot: string, | ||
amplifyInitConfig: AmplifyInitConfig, | ||
categoriesConfig?: CategoriesConfig, | ||
awsProviderConfig = getAwsProviderConfig(), | ||
): Promise<void> => { | ||
const args = [ | ||
'init', | ||
'--yes', | ||
'--amplify', | ||
JSON.stringify(amplifyInitConfig), | ||
'--providers', | ||
JSON.stringify({ | ||
awscloudformation: awsProviderConfig, | ||
}), | ||
]; | ||
if (categoriesConfig) { | ||
args.push('--categories', JSON.stringify(categoriesConfig)); | ||
} | ||
await execa(getCLIPath(), args, { cwd: projRoot }); | ||
}; | ||
|
||
/** | ||
* Returns an AmplifyConfig object with a default editor | ||
*/ | ||
export const getAmplifyInitConfig = (projectName: string, envName: string): AmplifyInitConfig => ({ | ||
projectName, | ||
envName, | ||
defaultEditor: 'code', | ||
}); | ||
|
||
/** | ||
* Returns a default AwsProviderConfig | ||
*/ | ||
export const getAwsProviderConfig = (): AwsProviderConfig => ({ | ||
configLevel: 'project', | ||
useProfile: true, | ||
profileName: TEST_PROFILE_NAME, | ||
}); | ||
|
||
/** | ||
* Shape of `--amplify` payload for init/pull | ||
*/ | ||
export type AmplifyInitConfig = { | ||
projectName: string, | ||
envName: string, | ||
defaultEditor: string, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,36 @@ | ||
/* eslint-disable jsdoc/require-jsdoc */ | ||
// eslint-disable-next-line import/no-cycle | ||
import { nspawn as spawn, getCLIPath } from '..'; | ||
|
||
export function amplifyOverrideRoot(cwd: string, settings: { testingWithLatestCodebase?: boolean }) { | ||
return new Promise((resolve, reject) => { | ||
const args = ['override', 'project']; | ||
export const amplifyOverrideRoot = (cwd: string, settings: { testingWithLatestCodebase?: boolean }): Promise<void> => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this file is just lint fixes |
||
const args = ['override', 'project']; | ||
|
||
spawn(getCLIPath(settings.testingWithLatestCodebase), args, { cwd, stripColors: true }) | ||
.wait('Do you want to edit override.ts file now?') | ||
.sendNo() | ||
.sendEof() | ||
.run((err: Error) => { | ||
if (!err) { | ||
resolve({}); | ||
} else { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
} | ||
return spawn(getCLIPath(settings.testingWithLatestCodebase), args, { cwd, stripColors: true }) | ||
.wait('Do you want to edit override.ts file now?') | ||
.sendNo() | ||
.sendEof() | ||
.runAsync(); | ||
}; | ||
|
||
export function amplifyOverrideAuth(cwd: string, settings: {}) { | ||
return new Promise((resolve, reject) => { | ||
const args = ['override', 'auth']; | ||
export const amplifyOverrideAuth = (cwd: string): Promise<void> => { | ||
const args = ['override', 'auth']; | ||
|
||
spawn(getCLIPath(), args, { cwd, stripColors: true }) | ||
.wait('Do you want to edit override.ts file now?') | ||
.sendNo() | ||
.sendEof() | ||
.run((err: Error) => { | ||
if (!err) { | ||
resolve({}); | ||
} else { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
} | ||
return spawn(getCLIPath(), args, { cwd, stripColors: true }) | ||
.wait('Do you want to edit override.ts file now?') | ||
.sendNo() | ||
.sendEof() | ||
.runAsync(); | ||
}; | ||
|
||
export function amplifyOverrideApi(cwd: string, settings: any) { | ||
export const amplifyOverrideApi = (cwd: string): Promise<void> => { | ||
const args = ['override', 'api']; | ||
const chain = spawn(getCLIPath(), args, { cwd, stripColors: true }); | ||
chain.wait('Do you want to edit override.ts file now?').sendNo().sendEof(); | ||
return chain.runAsync(); | ||
} | ||
}; | ||
|
||
export function buildOverrides(cwd: string, settings: any) { | ||
export const buildOverrides = (cwd: string): Promise<void> => { | ||
const args = ['build']; | ||
const chain = spawn(getCLIPath(), args, { cwd, stripColors: true }); | ||
return chain.runAsync(); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file is minimal lint fixes after moving the
isCI
function to a different file