Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create-plugin: Check if inside a plugin directory #706

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/create-plugin/src/commands/update.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions packages/create-plugin/src/utils/utils.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Loading