From b7a37598249a60c91ce70c999ff8b0dfa6246e49 Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Mon, 13 Jan 2025 15:24:49 +0100 Subject: [PATCH] feat(cli): Add plugin:publish and plugin:add commands support (#10938) RESOLVES FRMW-2864 RESOLVES FRMW-2868 **What** Add support for the following cli commands: - `plugin:publish` - `plugin:add` --- .changeset/grumpy-papayas-call.md | 6 ++++ packages/cli/medusa-cli/src/create-cli.ts | 29 +++++++++++++++++++ packages/medusa/src/commands/plugin/add.ts | 17 +++++++++++ .../medusa/src/commands/plugin/publish.ts | 17 +++++++++++ 4 files changed, 69 insertions(+) create mode 100644 .changeset/grumpy-papayas-call.md create mode 100644 packages/medusa/src/commands/plugin/add.ts create mode 100644 packages/medusa/src/commands/plugin/publish.ts diff --git a/.changeset/grumpy-papayas-call.md b/.changeset/grumpy-papayas-call.md new file mode 100644 index 0000000000..006bf5df67 --- /dev/null +++ b/.changeset/grumpy-papayas-call.md @@ -0,0 +1,6 @@ +--- +"@medusajs/medusa": patch +"@medusajs/cli": patch +--- + +feat(cli): Add plugin:publish and plugin:add commands support diff --git a/packages/cli/medusa-cli/src/create-cli.ts b/packages/cli/medusa-cli/src/create-cli.ts index 5329a1d561..2f3a1b42e2 100644 --- a/packages/cli/medusa-cli/src/create-cli.ts +++ b/packages/cli/medusa-cli/src/create-cli.ts @@ -276,6 +276,35 @@ function buildLocalCommands(cli, isLocalProject) { }) ), }) + .command({ + command: "plugin:publish", + desc: "Publish the plugin to the local packages registry", + handler: handlerP( + getCommandHandler("plugin/publish", (args, cmd) => { + process.env.NODE_ENV = process.env.NODE_ENV || `development` + cmd(args) + return new Promise(() => {}) + }) + ), + }) + .command({ + command: "plugin:add [plugin_names...]", + desc: "Add the specified plugin to the project from the local packages registry", + builder: { + plugin_names: { + type: "array", + description: "The name of the plugins to add", + demand: true, + }, + }, + handler: handlerP( + getCommandHandler("plugin/add", (args, cmd) => { + process.env.NODE_ENV = process.env.NODE_ENV || `development` + cmd(args) + return new Promise(() => {}) + }) + ), + }) .command({ command: `telemetry`, describe: `Enable or disable collection of anonymous usage data.`, diff --git a/packages/medusa/src/commands/plugin/add.ts b/packages/medusa/src/commands/plugin/add.ts new file mode 100644 index 0000000000..a391f2dfdd --- /dev/null +++ b/packages/medusa/src/commands/plugin/add.ts @@ -0,0 +1,17 @@ +import * as yalc from "yalc" + +/** + * Add the specified plugins to the project from the local packages registry + */ +export default async function localAddPlugin({ + directory, + plugin_names, +}: { + directory: string + plugin_names: string[] +}) { + await yalc.addPackages(plugin_names, { + workingDir: directory, + replace: true, + }) +} diff --git a/packages/medusa/src/commands/plugin/publish.ts b/packages/medusa/src/commands/plugin/publish.ts new file mode 100644 index 0000000000..598297ab76 --- /dev/null +++ b/packages/medusa/src/commands/plugin/publish.ts @@ -0,0 +1,17 @@ +import * as yalc from "yalc" + +/** + * Publish the plugin to the local packages registry + */ +export default async function localPublishPlugin({ + directory, +}: { + directory: string +}) { + await yalc.publishPackage({ + push: true, + workingDir: directory, + changed: true, + replace: true, + }) +}