Skip to content

Commit

Permalink
Merge pull request #2 from vinugawade/1-unknown-command-drush-for-ddev
Browse files Browse the repository at this point in the history
Fix for issue #1
  • Loading branch information
vinugawade authored Sep 6, 2023
2 parents fd1b775 + e9c13d3 commit 4d35eee
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 92 deletions.
24 changes: 15 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
# Change Log

## 1.0.0 :-
## v1.0.0

- Enables **Clear Cache** command of **Drush** to used in **Drupal** projects, Only works on **Linux/Mac** OS.
- Added support for the **Clear Cache** command of **Drush** in **Drupal** projects. This feature is available only for **Linux/Mac** OS.

## 1.1.0 :-
## v1.1.0

- Enables **Clear Cache** command's support for **DDEV** drupal project environment.
- Added support for the **Clear Cache** command in **DDEV** Drupal project environment.
- Fixed minor issues and added comments.
- Removed extension from **Preview**.
- Removed extension from the **Preview**.
- Updated the **Readme** file.

## 1.2.0 :-
## v1.2.0

- Now displays more details about site in tooltip.
- Action button will be not visible if **Drush** not found.
- Updated output messages for end users.
- Enhanced tooltip to display more details about the site.
- Added logic to hide the action button if **Drush** is not found.
- Improved output messages for end users.
- Fixed minor issues and removed debugging code.
- Updated the **Readme** file.

## v1.3.0

- Adds support for **drush v12**.
- Fixes the issues reported in [#1](https://github.com/vinugawade/ur-cache-cleaner/issues/1) by [@elgandoz](https://github.com/elgandoz).
- Refactors the code for better maintainability and readability.
63 changes: 41 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,42 @@

## Features ✨

**UR Cache Cleaner** is a VS Code extension which helps you to **Clear Cache** of your **Drupal** project with single click of a **Button** without switching to **Admin Panel** or **Terminal**. Only build for **Linux/Mac** OS.
**UR Cache Cleaner** is a powerful VS Code extension designed specifically for drupal projects. It offers the following features:

### Shortcut keys
- **Cache Clearing:** With just a single click of a button, you can easily clear the cache of your drupal project without the need to switch to the admin panel or terminal.

- Mac :- **⇧+⌘+C ⇧+⌘+R**
- Linux :- **Ctrl+Shift+C Ctrl+Shift+R**
- **Efficiency:** UR Cache Cleaner streamlines the cache clearing process, saving you time and effort by eliminating the need to navigate through different panels or tools.

For example if you open **Drupal project**, Then you can see the **Clear Cache** button at the left side of **Status Bar** :
- **User-Friendly Interface:** The extension provides a clean and intuitive interface, making it easy for users to navigate and utilize its features.

- **Linux/Mac OS Support:** UR Cache Cleaner is specially built to cater to Linux and Mac OS users, ensuring optimal performance on these platforms.

Experience the convenience and efficiency of **UR Cache Cleaner** in managing cache clearing for your drupal projects. Upgrade your workflow and enhance productivity with this powerful VS Code extension.

---

### Shortcut keys ✨

- Mac: **⇧+⌘+C ⇧+⌘+R**
- Linux: **Ctrl+Shift+C Ctrl+Shift+R**

When you open a Drupal project, you will find the "Clear Cache" button located on the left side of the Status Bar.

![Clear Your Cache](assets/images/feature.gif)

---

## Requirements ✨

- Install [Drush Launcher](https://github.com/drush-ops/drush-launcher) on your system.
To utilize UR Cache Cleaner, please ensure you have installed [Drush Launcher](https://github.com/drush-ops/drush-launcher) on your system.

---

## Known Issues ✨

- Not build for windows OS.
Please note that UR Cache Cleaner is not currently compatible with Windows OS. We apologize for any inconvenience this may cause.

Feel free to add any issues under our [repository](https://github.com/vinugawade/ur-cache-cleaner/issues).
We encourage you to report any issues you encounter on our [repository](https://github.com/vinugawade/ur-cache-cleaner/issues). Your feedback and contributions are highly appreciated.

---

Expand All @@ -43,31 +55,39 @@ See [CHANGELOG.md](CHANGELOG.md).

## Release Notes ✨

### 1.0.0
### v1.0.0

- Introduces the **Clear Cache** command of **Drush** for use in Drupal projects. This feature is currently supported only on **Linux/Mac OS**.

- Enables **Clear Cache** command of **Drush** to used in **Drupal** projects, Only works on **Linux/Mac** OS.
### v1.1.0

### 1.1.0
- Adds support for the **Clear Cache** command in **DDEV** Drupal project environments.
- Fixes minor issues and adds comments for improved clarity.

- Enables **Clear Cache** command's support for **DDEV** drupal project environment.
- Fixed minor issues and added comments.
### v1.2.0

### 1.2.0
- Enhances the tooltip to display additional site details.
- Addresses minor issues for improved performance.

- Now displays more details about site in tooltip.
- Fixed minor issues.
### v1.3.0

- Adds support for **drush v12**.
- Fixes the issues reported in [#1](https://github.com/vinugawade/ur-cache-cleaner/issues/1) by [@elgandoz](https://github.com/elgandoz).
- Refactors the code for better maintainability and readability.

---

## Contributors ✨

Feel free to contribute in our [repository](https://github.com/vinugawade/ur-cache-cleaner).
We welcome contributions to our [repository](https://github.com/vinugawade/ur-cache-cleaner). Feel free to contribute and help make **UR Cache Cleaner** even better.

---

## Maintainer ✨

Built with 💛 by [Vinay Gawade](https://github.com/vinugawade).
**UR Cache Cleaner** is built with 💛 by [Vinay Gawade](https://github.com/vinugawade).

Your support and feedback are valuable in maintaining and improving the extension.

<a href="https://www.linkedin.com/in/vinu-gawade" target="_blank"><img src="assets/images/media/LinkedIn.png" alt="logo" width="150"></a>
<a href="https://www.buymeacoffee.com/vinaygawade" target="_blank"><img src="assets/images/media/Bmc.png" alt="logo" width="150"></a>
Expand All @@ -79,13 +99,12 @@ Built with 💛 by [Vinay Gawade](https://github.com/vinugawade).

## Credits ✨

- Logo generated by [DesignEvo](https://www.designevo.com) free logo designer.
- Icons added by [glyphter](https://glyphter.com/) free icon font pack.
The logo for **UR Cache Cleaner** was generated using the free logo designer [DesignEvo](https://www.designevo.com), while the icons were provided by [glyphter](https://glyphter.com/), a free icon font pack.

---

## License
## License

Check [here](LICENSE).
Please refer to the [LICENSE](LICENSE) file for details on the licensing of **UR Cache Cleaner**.

![LICENSE](https://img.shields.io/github/license/vinugawade/ur-cache-cleaner?style=flat-square)
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"url": "https://github.com/vinugawade/ur-cache-cleaner.git"
},
"license": "GNU General Public License",
"version": "1.2.0",
"version": "1.3.0",
"engines": {
"vscode": "^1.72.0"
},
Expand Down Expand Up @@ -83,11 +83,11 @@
}
],
"keybindings": [
{
"command": "ur-cache-cleaner.drushClearCache",
"key": "ctrl+shift+c ctrl+shift+r",
"mac": "cmd+shift+c cmd+shift+r"
}
{
"command": "ur-cache-cleaner.drushClearCache",
"key": "ctrl+shift+c ctrl+shift+r",
"mac": "cmd+shift+c cmd+shift+r"
}
]
},
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions src/commands/check_cmd.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const commandExists = require('command-exists').sync;

/**
* @param {object} cmd
* Checks if a command exists.
* @param {object} cmd - The command object.
* @returns {boolean|string} - Returns true if the command exists, or an error message if it doesn't.
*/
exports.command = (cmd) => {
var result;
if (commandExists(cmd.name)) {
result = true;
return true;
} else {
result = `${cmd.title} launcher is not installed, Please install it globally on your system.`;
return "Drush launcher is not installed. Please install it globally on your system.";
}
return result;
}
};
59 changes: 23 additions & 36 deletions src/commands/drush/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,55 @@ const fs = require('fs');
const title = "Drush";
const name = "drush";
const root = vscode.workspace.rootPath;
const status = name + ' status --root=' + root;
const successMsg = "Cache rebuild completed.";
var cacheRebuild = "drush > /dev/null";

let cacheRebuild = checkDdevEnv() ? 'ddev drush cr' : `${root}/vendor/bin/${name} cr`;
let status = checkDdevEnv() ? 'ddev drush status' : `${root}/vendor/bin/${name} status`;

/**
* @param {object} extStatusBarItem
* @param {string} drupalVersion
* @param {string} drushVersion
* Clears the cache and updates the status bar item.
* @param {object} extStatusBarItem - The extension status bar item.
* @param {string} drupalVersion - The Drupal version.
* @param {string} drushVersion - The Drush version.
*/
function clearCache(extStatusBarItem, drupalVersion, drushVersion) {

// Modify command if it's running in ddev environment.
cacheRebuild = checkDdevEnv(cacheRebuild);

cmdRunner.exec(cacheRebuild, (exps, stdout, stderr) => {
if (stderr) {
// Show success output & update values of status bar button.
let output = stderr.trim();
if (output.includes('[success]')) {
vscode.window.showInformationMessage(successMsg);
} else {
vscode.window.showErrorMessage(`${title} error: ` + stderr);
vscode.window.showErrorMessage(`${title} error: ${stderr}`);
}
extStatusBarItem.text = `$(clear-cache) Clear Cache`;
extStatusBarItem.tooltip = `Drupal ${drupalVersion} (${title} ${drushVersion})`;
}

if (exps) {
// Show exception & update values of status bar button.
vscode.window.showErrorMessage('Exception: ' + exps);
extStatusBarItem.text = `$(clear-cache) Clear Cache`;
extStatusBarItem.tooltip = `Drupal ${drupalVersion} (${title} ${drushVersion})`;
}

if (stdout) {
// Show output & update values of status bar button.
vscode.window.showInformationMessage('stdout: ' + stdout);
extStatusBarItem.text = `$(clear-cache) Clear Cache`;
extStatusBarItem.tooltip = `Drupal ${drupalVersion} (${title} ${drushVersion})`;
}

// Update the status bar item with cache clear information.
extStatusBarItem.text = `$(clear-cache) Clear Cache`;
extStatusBarItem.tooltip = `Drupal ${drupalVersion} (${title} ${drushVersion})`;
});
}

/**
* @param {string} cacheRebuildCmd
* Checks if the workspace is running in ddev environment.
* @returns {boolean} - Returns true if ddev environment is detected, false otherwise.
*/
function checkDdevEnv(cacheRebuildCmd) {
// Check .ddev directory exist or not in workspace.
var ddev_config = root + '/.ddev'
if (fs.existsSync(ddev_config)) {
cacheRebuildCmd = `ddev ` + name + ` cr`;
} else {
cacheRebuildCmd = name + ' cr --root=' + root;
}
return cacheRebuildCmd;
function checkDdevEnv() {
return fs.existsSync(`${root}/.ddev`);
}

module.exports = {
title,
name,
root,
status,
clearCache,
checkDdevEnv
}
title, // Drupal site title
name, // Drush command name
root, // Workspace root path
status, // Drush command status
clearCache, // Function to clear the cache
checkDdevEnv // Function to check if ddev environment is detected
};
26 changes: 15 additions & 11 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const check = require('./commands/check_cmd');
var drupalVersion, drushVersion;

/**
* @param {vscode.ExtensionContext} context
* Activate the extension when the VS Code instance starts.
* @param {vscode.ExtensionContext} context - The extension context.
*/
function activate(context) {

// Create a new status bar item that we can now manage.
const extStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
const result = check.command(drush);
Expand All @@ -18,34 +18,37 @@ function activate(context) {
// Assign values of status bar button.
const extDrushButtonId = 'ur-cache-cleaner.drushClearCache';
extStatusBarItem.command = extDrushButtonId;
extStatusBarItem.name = `drush-clear-cache`;
extStatusBarItem.name = 'drush-clear-cache';

cmdRunner.exec(drush.status, (exps, stdout, stderr) => {

if (stderr) {
// Show command error.
vscode.window.showErrorMessage(`${drush.title} error: ` + stderr);
vscode.window.showErrorMessage(`${drush.title} error: ${stderr}`);
}

if (exps) {
// Show command exception.
vscode.window.showErrorMessage(`${drush.title} ` + exps);
vscode.window.showErrorMessage(`${drush.title} ${exps}`);
}

if (stdout && !exps && !stderr) {
// Extract the version of Drupal and Drush from the output of the status command.
const drupal_expression = /Drupal version\s+:\s(([0-9]\.*){1,})/g;
const drush_expression = /Drush version\s+:\s(([0-9]\.*){1,})/g;
drupalVersion = drupal_expression.exec(stdout)[1];
drushVersion = drush_expression.exec(stdout)[1];

extStatusBarItem.text = `$(clear-cache) Clear Cache`;
extStatusBarItem.text = '$(clear-cache) Clear Cache';
extStatusBarItem.tooltip = `Drupal ${drupalVersion} (${drush.title} ${drushVersion})`;
extStatusBarItem.show();
}
});

const disposable = vscode.commands.registerCommand(extDrushButtonId, function () {
// Change text while clearing cache.
extStatusBarItem.text = `$(sync~spin) Clearing Cache`;
extStatusBarItem.tooltip = `Working on...`;
extStatusBarItem.text = '$(sync~spin) Clearing Cache';
extStatusBarItem.tooltip = 'Working on...';
// Execute clear cache command.
drush.clearCache(extStatusBarItem, drupalVersion, drushVersion);
});
Expand All @@ -56,13 +59,14 @@ function activate(context) {
// Show command not found error message.
vscode.window.showErrorMessage(result);
}

}

// This method is called when your extension is deactivated
/**
* Deactivates the extension.
*/
function deactivate() { }

module.exports = {
activate,
deactivate
}
};

0 comments on commit 4d35eee

Please sign in to comment.