feat(medusa,medusa-cli): add an exec command (#7376)
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import loaders from "../loaders"
|
||||
import express from "express"
|
||||
import path from "path"
|
||||
import logger from "../loaders/logger"
|
||||
import { ExecArgs } from "@medusajs/types"
|
||||
|
||||
type Options = {
|
||||
file: string
|
||||
args: string[]
|
||||
}
|
||||
|
||||
export default async function script({ file, args }: Options) {
|
||||
logger.info(`Executing script at ${file}...`)
|
||||
const app = express()
|
||||
const directory = process.cwd()
|
||||
|
||||
try {
|
||||
// set worker mode
|
||||
process.env.MEDUSA_WORKER_MODE = "worker"
|
||||
|
||||
const { container } = await loaders({
|
||||
directory,
|
||||
expressApp: app,
|
||||
})
|
||||
|
||||
const scriptFile = (await import(path.resolve(directory, file))).default
|
||||
|
||||
const scriptParams: ExecArgs = {
|
||||
container,
|
||||
args,
|
||||
}
|
||||
|
||||
await scriptFile(scriptParams)
|
||||
|
||||
logger.info(`Finished executing script.`)
|
||||
|
||||
process.exit()
|
||||
} catch (err) {
|
||||
logger.error("Error running script", err)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@ import { SubscriberLoader } from "./helpers/subscribers"
|
||||
type Options = {
|
||||
directory: string
|
||||
expressApp: Express
|
||||
isTest: boolean
|
||||
}
|
||||
|
||||
const isWorkerMode = (configModule) => {
|
||||
|
||||
Reference in New Issue
Block a user