Skip to content

Commit

Permalink
[PM2] Add support for customizing PM2_HOME (#13473)
Browse files Browse the repository at this point in the history
* [PM2] Add support for customizing PM2_HOME

* Update changelog

* Update CHANGELOG.md

* Update CHANGELOG.md and optimise images

---------

Co-authored-by: Milena Araujo <mil3na@users.noreply.github.com>
Co-authored-by: raycastbot <bot@raycast.com>
  • Loading branch information
3 people committed Jul 16, 2024
1 parent b3f3fc4 commit 4b80c2e
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 56 deletions.
7 changes: 6 additions & 1 deletion extensions/pm2/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Raycast PM2

## [Bugfixes & Chore]
## [Enhancement] - 2024-07-16

- Bump dependencies
- Add support for customzing `PM2_HOME`

## [Bugfixes & Chore] - 2024-06-05

- Fix API command
- Add [`raycast-pm2`](https://github.com/LitoMore/raycast-pm2) example to readme
Expand Down
27 changes: 15 additions & 12 deletions extensions/pm2/assets/pm2-wrapper/package-lock.json

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

2 changes: 1 addition & 1 deletion extensions/pm2/assets/pm2-wrapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"dependencies": {
"lodash": "^4.17.21",
"meow": "^13.2.0",
"pm2": "^5.4.0"
"pm2": "^5.4.2"
}
}
63 changes: 33 additions & 30 deletions extensions/pm2/package-lock.json

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

17 changes: 13 additions & 4 deletions extensions/pm2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,32 @@
"value": "preferenceNodePath"
}
]
},
{
"type": "textfield",
"required": false,
"name": "pm2Home",
"title": "PM2 Home Directory",
"default": "",
"description": "The directory where PM2 stores its configuration files and logs",
"placeholder": "e.g. /Users/litomore/.pm3"
}
],
"dependencies": {
"@raycast/api": "^1.75.2",
"@raycast/utils": "^1.15.0",
"@raycast/api": "^1.78.1",
"@raycast/utils": "^1.16.2",
"@types/lodash": "^4.17.4",
"date-fns": "^3.6.0",
"execa": "^9.1.0",
"lodash": "^4.17.21",
"raycast-cross-extension": "^0.2.2"
"raycast-cross-extension": "^0.2.3"
},
"devDependencies": {
"@raycast/eslint-config": "^1.0.8",
"@types/node": "^20.12.5",
"@types/react": "^18.2.75",
"eslint": "^8.57.0",
"pm2": "^5.4.0",
"pm2": "^5.4.2",
"prettier": "^3.2.5",
"typescript": "^5.4.4"
}
Expand Down
6 changes: 3 additions & 3 deletions extensions/pm2/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { ProcessDescription } from "pm2";
import { MetaData, ProcessActions } from "./components.js";
import {
checkIfNeedSetup,
getNodeBinaryPath,
getProcessStatusColor,
getRaycastIcon,
isRaycastNodeProcess,
pm2WrapperExamplePath,
pm2WrapperIndexPath,
runPm2Command,
setupEnv,
} from "./utils.js";

export default function Main() {
Expand All @@ -22,8 +22,8 @@ export default function Main() {

const loadList = async () => {
await checkIfNeedSetup();
const nodeBinaryPath = getNodeBinaryPath();
const { stdout } = await $`${nodeBinaryPath} ${pm2WrapperIndexPath} list`;
setupEnv();
const { stdout } = await $`node ${pm2WrapperIndexPath} list`;
const parsedList = JSON.parse(stdout);
setList(parsedList);
setIsLoading(false);
Expand Down
20 changes: 15 additions & 5 deletions extensions/pm2/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,19 @@ export const base64Encode = (str: string) => Buffer.from(str).toString("base64")

export const encodeParameters = (parameters: StartOptions | Pm2Process) => base64Encode(JSON.stringify(parameters));

export const getNodeBinaryPath = (runtimeOptions?: RuntimeOptions) => {
const { defaultNodeExecutor, nodePath } = getPreferenceValues<Preferences>();
return runtimeOptions?.nodePath ?? (defaultNodeExecutor === "raycastNodePath" ? raycastNodePath : nodePath);
export const setupEnv = (options?: { runtimeOptions?: RuntimeOptions }) => {
const { defaultNodeExecutor, nodePath, pm2Home } = getPreferenceValues<Preferences>();
const nodeBinaryPath = path.dirname(
options?.runtimeOptions?.nodePath ?? (defaultNodeExecutor === "raycastNodePath" ? raycastNodePath : nodePath),
);

if (!process.env.PATH?.includes(nodeBinaryPath)) {
process.env.PATH = process.env.PATH ? `${process.env.PATH}:${nodeBinaryPath}` : nodeBinaryPath;
}

if (pm2Home) {
process.env.PM2_HOME = pm2Home;
}
};

export async function runPm2Command(
Expand All @@ -59,8 +69,8 @@ export async function runPm2Command(
console.error("No options provided for PM2 command");
return;
}
const nodeBinaryPath = getNodeBinaryPath(runtimeOptions);
const commandLine = `PATH="$PATH:${path.dirname(nodeBinaryPath)}" '${nodeBinaryPath}' '${pm2WrapperIndexPath}' ${command} --options=${encodeParameters(options)}`;
setupEnv({ runtimeOptions });
const commandLine = `node '${pm2WrapperIndexPath}' ${command} --options=${encodeParameters(options)}`;
const toast =
environment.commandMode === "view"
? await showToast({ title: "", message: `Running ${command} command...` })
Expand Down

0 comments on commit 4b80c2e

Please sign in to comment.