From 8d661c11b523949b0aebd52b7fd27c3090f349f0 Mon Sep 17 00:00:00 2001 From: Levente Balogh Date: Tue, 30 Jan 2024 10:33:00 +0100 Subject: [PATCH] feat: add an error message if the user is not in a plugin directory --- .../create-plugin/src/commands/update.command.ts | 13 +++++++++++++ packages/create-plugin/src/utils/utils.plugin.ts | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/create-plugin/src/commands/update.command.ts b/packages/create-plugin/src/commands/update.command.ts index 1e6db2554..ceda3e3a7 100644 --- a/packages/create-plugin/src/commands/update.command.ts +++ b/packages/create-plugin/src/commands/update.command.ts @@ -12,6 +12,7 @@ import { } from '../utils/utils.npm.js'; import { getPackageManagerWithFallback } from '../utils/utils.packageManager.js'; import { isGitDirectory, isGitDirectoryClean } from '../utils/utils.git.js'; +import { isPluginDirectory } from '../utils/utils.plugin.js'; export const update = async (argv: minimist.ParsedArgs) => { try { @@ -37,6 +38,18 @@ In case you want to proceed as is please use the ${chalk.bold('--force')} flag.) process.exit(1); } + if (!isPluginDirectory() && !argv.force) { + printRedBox({ + title: 'Are you inside a plugin directory?', + subtitle: 'We couldn\'t find a "src/plugin.json" file under your current directory.', + content: `(Please make sure to run this command from the root of your plugin folder. In case you want to proceed as is please use the ${chalk.bold( + '--force' + )} flag.)`, + }); + + process.exit(1); + } + // 0. Warning // ---------- printMessage(TEXT.updateCommandWarning); diff --git a/packages/create-plugin/src/utils/utils.plugin.ts b/packages/create-plugin/src/utils/utils.plugin.ts index cc6906b0b..14be11e60 100644 --- a/packages/create-plugin/src/utils/utils.plugin.ts +++ b/packages/create-plugin/src/utils/utils.plugin.ts @@ -6,3 +6,13 @@ export function getPluginJson(srcDir?: string) { const pluginJsonPath = path.join(srcPath, 'plugin.json'); return readJsonFile(pluginJsonPath); } + +// Checks if CWD is a valid root directory of a plugin +export function isPluginDirectory() { + try { + getPluginJson(); + return true; + } catch (e) { + return false; + } +}