forked from yuth/amplify-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor/packaging (aws-amplify#8547) * feat(amplify-provider-awscloudformation): refactor of the exporting resources * feat(amplify-provider-awscloudformation): refactored export to write files to external path * refactor: clean up * refactor: remove unused * fix: mispelled url * feat: fall back on push globing and template url * feat: export * feat: modify generation of lambda layer version content * fix(amplify-category-function): lambda layers filter stacks * feat: added command line for export * test(amplify-provider-awscloudformation): added tests for export resources * perf: removed unused * refactor: removed unused * fix: make the tags file pascal case * docs(amplify-provider-awscloudformation): added some documentation * feat(amplify-provider-awscloudformation): added warning and folder perms * fix: check in constants change * refactor: addressing PR feedback * refactor: es6 export * feat: minor changes for integration testing * refactor: pr comments * fix: cleared commented out code removed backup * ci: revert config file to main * Feat: export pull front end (aws-amplify#8488) * feat: export (aws-amplify#8486) * feat(amplify-provider-awscloudformation): refactor of the exporting resources * feat(amplify-provider-awscloudformation): refactored export to write files to external path * refactor: clean up * refactor: remove unused * fix: mispelled url * feat: fall back on push globing and template url * feat: export * feat: modify generation of lambda layer version content * fix(amplify-category-function): lambda layers filter stacks * feat: added command line for export * test(amplify-provider-awscloudformation): added tests for export resources * perf: removed unused * refactor: removed unused * fix: make the tags file pascal case * docs(amplify-provider-awscloudformation): added some documentation * feat(amplify-provider-awscloudformation): added warning and folder perms * fix: check in constants change * refactor: addressing PR feedback * refactor: es6 export * feat: minor changes for integration testing * refactor: pr comments * fix: cleared commented out code removed backup * ci: revert config file to main * feat: wip export pull * feat: amplify export pull to genereate front end config files * fix: merge fixes from export * refactor: removed unused * fix: some language fixes and bug fix with notification * test: e2e tests * test: codecov and test fix * Refactor/packaging (aws-amplify#8547) * feat(amplify-provider-awscloudformation): refactor of the exporting resources * feat(amplify-provider-awscloudformation): refactored export to write files to external path * refactor: clean up * refactor: remove unused * fix: mispelled url * feat: fall back on push globing and template url * feat: export * feat: modify generation of lambda layer version content * fix(amplify-category-function): lambda layers filter stacks * feat: added command line for export * test(amplify-provider-awscloudformation): added tests for export resources * perf: removed unused * refactor: removed unused * fix: make the tags file pascal case * docs(amplify-provider-awscloudformation): added some documentation * feat(amplify-provider-awscloudformation): added warning and folder perms * fix: check in constants change * refactor: addressing PR feedback * refactor: es6 export * feat: minor changes for integration testing * refactor: pr comments * fix: cleared commented out code removed backup * ci: revert config file to main * Feat: export pull front end (aws-amplify#8488) * feat: export (aws-amplify#8486) * feat(amplify-provider-awscloudformation): refactor of the exporting resources * feat(amplify-provider-awscloudformation): refactored export to write files to external path * refactor: clean up * refactor: remove unused * fix: mispelled url * feat: fall back on push globing and template url * feat: export * feat: modify generation of lambda layer version content * fix(amplify-category-function): lambda layers filter stacks * feat: added command line for export * test(amplify-provider-awscloudformation): added tests for export resources * perf: removed unused * refactor: removed unused * fix: make the tags file pascal case * docs(amplify-provider-awscloudformation): added some documentation * feat(amplify-provider-awscloudformation): added warning and folder perms * fix: check in constants change * refactor: addressing PR feedback * refactor: es6 export * feat: minor changes for integration testing * refactor: pr comments * fix: cleared commented out code removed backup * ci: revert config file to main * feat: wip export pull * feat: amplify export pull to genereate front end config files * fix: merge fixes from export * refactor: removed unused * fix: some language fixes and bug fix with notification * test: e2e tests * test: codecov and test fix * feat: export + override reconciled * test: fixed test because of bad merge * fix: added back conditional conditional rebuild * refactor(amplify-provider-awscloudformation): renamed the files to fit * test: fixed idp add storage test * test: fixes type import
- Loading branch information
1 parent
8240ed9
commit dff93a7
Showing
39 changed files
with
2,271 additions
and
124 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
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,22 @@ | ||
import * as fs from 'fs-extra'; | ||
import { ExportPathValidationError } from '../errors'; | ||
|
||
/** | ||
* Validates whether the path is a directory | ||
* @throws {ExportPathValidationError} if path not valid | ||
* @param directoryPath to validate | ||
*/ | ||
export function validateExportDirectoryPath(directoryPath: any) { | ||
if (typeof directoryPath !== 'string') { | ||
throw new ExportPathValidationError(`${directoryPath} is not a valid path specified by --out`); | ||
} | ||
|
||
if (!fs.existsSync(directoryPath)) { | ||
throw new ExportPathValidationError(`${directoryPath} does not exist`); | ||
} | ||
|
||
const stat = fs.lstatSync(directoryPath); | ||
if (!stat.isDirectory()) { | ||
throw new ExportPathValidationError(`${directoryPath} is not a valid directory`); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
"console", | ||
"delete", | ||
"env", | ||
"export", | ||
"help", | ||
"init", | ||
"logout", | ||
|
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,105 @@ | ||
import { $TSContext, IAmplifyResource, stateManager, UnrecognizedFrontendError, validateExportDirectoryPath } from 'amplify-cli-core'; | ||
import { printer } from 'amplify-prompts'; | ||
import chalk from 'chalk'; | ||
import { getResourceOutputs } from '../extensions/amplify-helpers/get-resource-outputs'; | ||
import Ora from 'ora'; | ||
import { getResources } from './build-override'; | ||
|
||
export const run = async (context: $TSContext) => { | ||
const options = context.input.options; | ||
const subCommands = context.input.subCommands; | ||
const showHelp = !options || options.help || !options.out; | ||
const isPull = !!(subCommands && subCommands.includes('pull')); | ||
const showPullHelp = (showHelp || !options.frontend || !options.rootStackName) && isPull; | ||
|
||
if (showHelp && !showPullHelp) { | ||
printer.blankLine(); | ||
printer.info("'amplify export', Allows you to integrate your backend into an external deployment tool"); | ||
printer.blankLine(); | ||
printer.info(`${chalk.yellow('--cdk')} Export all resources with cdk comatibility`); | ||
printer.info(`${chalk.yellow('--out')} Root directory of cdk project`); | ||
printer.blankLine(); | ||
printer.info(`Example: ${chalk.green('amplify export --cdk --out ~/myCDKApp')}`); | ||
printer.blankLine(); | ||
printer.info("'amplify export pull' To export front-end config files'"); | ||
printer.info("'amplify export pull --help' to learn"); | ||
printer.blankLine(); | ||
return; | ||
} | ||
|
||
if (showPullHelp) { | ||
const frontendPlugins = context.amplify.getFrontendPlugins(context); | ||
const frontends = Object.keys(frontendPlugins); | ||
printer.blankLine(); | ||
printer.info("'amplify export pull', Allows you to genreate frontend config files at a desired location"); | ||
printer.blankLine(); | ||
printer.info(`${chalk.yellow('--rooStackName')} Amplify CLI deployed Root Stack name`); | ||
printer.info(`${chalk.yellow('--frontend')} Front end type ex: ${frontends.join(', ')}`); | ||
printer.info(`${chalk.yellow('--out')} Directory to write the front-end config files`); | ||
printer.blankLine(); | ||
printer.info( | ||
`Example: ${chalk.green( | ||
'amplify export pull --rootStackName amplify-myapp-stack-123 --out ~/myCDKApp/src/config/ --frontend javascript', | ||
)}`, | ||
); | ||
printer.blankLine(); | ||
printer.blankLine(); | ||
return; | ||
} | ||
const exportPath = context.input.options['out']; | ||
if (isPull) { | ||
await createFrontEndConfigFile(context, exportPath); | ||
} else { | ||
await exportBackend(context, exportPath); | ||
} | ||
}; | ||
|
||
async function exportBackend(context: $TSContext, exportPath: string) { | ||
await buildAllResources(context); | ||
const resources = await context.amplify.getResourceStatus(); | ||
await context.amplify.showResourceTable(); | ||
const providerPlugin = context.amplify.getProviderPlugins(context); | ||
const providers = Object.keys(providerPlugin); | ||
for await (const provider of providers) { | ||
const plugin = await import(providerPlugin[provider]); | ||
await plugin.exportResources(context, resources, exportPath); | ||
} | ||
} | ||
|
||
async function buildAllResources(context: $TSContext) { | ||
const resourcesToBuild: IAmplifyResource[] = await getResources(context); | ||
await context.amplify.executeProviderUtils(context, 'awscloudformation', 'buildOverrides', { resourcesToBuild, forceCompile: true }); | ||
} | ||
|
||
async function createFrontEndConfigFile(context: $TSContext, exportPath: string) { | ||
const { rootStackName, frontend } = context.input.options; | ||
|
||
const frontendSet = new Set(Object.keys(context.amplify.getFrontendPlugins(context))); | ||
if (!frontendSet.has(frontend)) { | ||
throw new UnrecognizedFrontendError(`${frontend} is not a supported Amplify frontend`); | ||
} | ||
const spinner = Ora(`Extracting outputs from ${rootStackName}`); | ||
|
||
spinner.start(); | ||
const providerPlugin = context.amplify.getProviderPlugins(context); | ||
const providers = Object.keys(providerPlugin); | ||
try { | ||
for await (const provider of providers) { | ||
const plugin = await import(providerPlugin[provider]); | ||
await plugin.exportedStackResourcesUpdateMeta(context, rootStackName); | ||
} | ||
spinner.text = `Generating files at ${exportPath}`; | ||
const meta = stateManager.getMeta(); | ||
const cloudMeta = stateManager.getCurrentMeta(); | ||
const frontendPlugins = context.amplify.getFrontendPlugins(context); | ||
const frontendHandlerModule = require(frontendPlugins[frontend]); | ||
validateExportDirectoryPath(exportPath); | ||
await frontendHandlerModule.createFrontendConfigsAtPath(context, getResourceOutputs(meta), getResourceOutputs(cloudMeta), exportPath); | ||
spinner.succeed('Successfully generated frontend config files'); | ||
} catch (ex: any) { | ||
spinner.fail('Failed to generate frontend config files ' + ex.message); | ||
throw ex; | ||
} finally { | ||
spinner.stop(); | ||
} | ||
} |
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,36 @@ | ||
import { nspawn as spawn, getCLIPath } from '..'; | ||
|
||
export function exportBackend(cwd: string, settings: { exportPath: string }): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
spawn(getCLIPath(), ['export', '--out', settings.exportPath], { cwd, stripColors: true }) | ||
.wait('For more information: docs.amplify.aws/cli/export') | ||
.sendEof() | ||
.run((err: Error) => { | ||
if (!err) { | ||
resolve(); | ||
} else { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
export function exportPullBackend(cwd: string, settings: { exportPath: string; frontend: string; rootStackName: string }): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
spawn( | ||
getCLIPath(), | ||
['export', 'pull', '--out', settings.exportPath, '--frontend', settings.frontend, '--rootStackName', settings.rootStackName], | ||
{ cwd, stripColors: true }, | ||
) | ||
.wait('Successfully generated frontend config files') | ||
.sendEof() | ||
.run((err: Error) => { | ||
if (!err) { | ||
resolve(); | ||
} else { | ||
reject(err); | ||
} | ||
}); | ||
}); | ||
} | ||
|
Oops, something went wrong.