diff --git a/index.ts b/index.ts index 1498de7..e20de3b 100644 --- a/index.ts +++ b/index.ts @@ -6,6 +6,9 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { exists } from './paths' +import { join } from 'path' +import { pathToFileURL } from 'url' import { launch } from './run.js' import type { LocalSearch } from './run.js' import { populate } from './data.js' @@ -39,6 +42,25 @@ function getConfig(arc: { else return {} } +const openSearchApiFile = 'openSearchApi.js' + +async function executeSearchRequests(cwd: string) { + //Load api call file and run all api calls to cluster + const apiPath = join(cwd, openSearchApiFile) + let result + if (await exists(apiPath)) { + console.log(`Found ${openSearchApiFile} file, running api calls...`) + result = (await import(pathToFileURL(apiPath).toString())).default + + // result should be a function that returns a promise + if (typeof result === 'function') { + result = result() + } + + await result + } +} + export const deploy = { // @ts-expect-error: The Architect plugins API has no type definitions. start({ cloudformation, inventory, arc, stage }) { @@ -64,6 +86,10 @@ export const deploy = { return serverlessServices } }, + // @ts-expect-error: The Architect plugins API has no type definitions. + async end({ inventory }) { + executeSearchRequests(inventory.inv._project.cwd) + }, } let local: LocalSearch @@ -86,8 +112,10 @@ export const sandbox = { }) { const engine = getEngine(getConfig(arc).sandboxEngine) local = await launch({ engine }) + await executeSearchRequests(cwd) await populate(cwd, { node: local.url }) }, + async end() { await local.stop() },