🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@cyberalien/deploy-utils

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cyberalien/deploy-utils - npm Package Compare versions

Comparing version
0.0.11
to
0.0.12
+8
lib/npm/update.d.ts
import { Client } from "ssh2";
/**
* Update Node version
*
* After running this function, run startPM2Process() to restart all apps
*/
declare function updateNode(client: Client, nodeVersion?: number | string): Promise<void>;
export { updateNode };
import { execSFTPCommandWithShell } from "../ssh/shell.js";
import "../commands/config.js";
/**
* Update Node version
*
* After running this function, run startPM2Process() to restart all apps
*/
async function updateNode(client, nodeVersion = 24) {
await execSFTPCommandWithShell(client, `nvm install ${nodeVersion} && nvm use ${nodeVersion} && nvm alias default ${nodeVersion}`);
await execSFTPCommandWithShell(client, "npm install -g corepack@latest pm2@latest && corepack enable && pm2 update");
}
export { updateNode };
+3
-2

@@ -16,4 +16,5 @@ import { cloneGitRepository } from "./git/clone.js";

import { startPM2Process } from "./npm/pm2.js";
import { getPM2Status } from "./npm/pm2-status.js";
import { PM2StatusItem, getPM2Status } from "./npm/pm2-status.js";
import { updateNode } from "./npm/update.js";
import { initTokens } from "./misc/tokens.js";
export { SSHExecResult, checkIfRemoteFileExists, cloneGitRepository, connectToSSH, connectToSSHWithKeys, execSFTPCommand, execSFTPCommandWithShell, getPM2Status, getSFTPFile, initTokens, installNodeServer, installNpmPackages, putSFTPFile, putSFTPFiles, readSFTPDir, scanLocalGitRepository, startPM2Process, startSFTPSession, uploadLocalGitRepository, uploadSFTPFile, uploadSFTPFiles };
export { PM2StatusItem, SSHExecResult, checkIfRemoteFileExists, cloneGitRepository, connectToSSH, connectToSSHWithKeys, execSFTPCommand, execSFTPCommandWithShell, getPM2Status, getSFTPFile, initTokens, installNodeServer, installNpmPackages, putSFTPFile, putSFTPFiles, readSFTPDir, scanLocalGitRepository, startPM2Process, startSFTPSession, updateNode, uploadLocalGitRepository, uploadSFTPFile, uploadSFTPFiles };
+2
-1

@@ -17,3 +17,4 @@ import { connectToSSH, connectToSSHWithKeys } from "./ssh/connect.js";

import { startPM2Process } from "./npm/pm2.js";
import { updateNode } from "./npm/update.js";
import { initTokens } from "./misc/tokens.js";
export { checkIfRemoteFileExists, cloneGitRepository, connectToSSH, connectToSSHWithKeys, execSFTPCommand, execSFTPCommandWithShell, getPM2Status, getSFTPFile, initTokens, installNodeServer, installNpmPackages, putSFTPFile, putSFTPFiles, readSFTPDir, scanLocalGitRepository, startPM2Process, startSFTPSession, uploadLocalGitRepository, uploadSFTPFile, uploadSFTPFiles };
export { checkIfRemoteFileExists, cloneGitRepository, connectToSSH, connectToSSHWithKeys, execSFTPCommand, execSFTPCommandWithShell, getPM2Status, getSFTPFile, initTokens, installNodeServer, installNpmPackages, putSFTPFile, putSFTPFiles, readSFTPDir, scanLocalGitRepository, startPM2Process, startSFTPSession, updateNode, uploadLocalGitRepository, uploadSFTPFile, uploadSFTPFiles };
import { Client } from "ssh2";
interface ResultItem {
interface PM2StatusItem {
id: string;

@@ -17,3 +17,3 @@ name: string;

*/
declare function getPM2Status(client: Client): Promise<false | ResultItem[]>;
export { getPM2Status };
declare function getPM2Status(client: Client): Promise<false | PM2StatusItem[]>;
export { PM2StatusItem, getPM2Status };

@@ -8,2 +8,17 @@ import { execSFTPCommandWithShell } from "../ssh/shell.js";

async function startPM2Process(client, data) {
function findItem(status) {
return status ? data.name && !data.oneProcess ? status.find((item) => item.name === data.name) : status[0] : void 0;
}
async function verifyRestart() {
const status = await getPM2Status(client);
if (!status) {
console.error("Failed to get status after starting app");
return false;
}
if (!findItem(status)) {
console.error("Failed to start app");
return false;
}
return true;
}
let status = await getPM2Status(client);

@@ -13,5 +28,8 @@ if (!status) {

status = await getPM2Status(client);
if (!status) return false;
if (!status) {
console.error("Failed to execute pm2");
return false;
}
}
const item = data.name && !data.oneProcess ? status.find((item) => item.name === data.name) : status[0];
const item = findItem(status);
if (item) {

@@ -23,14 +41,6 @@ if (!item.id) {

await execSFTPCommandWithShell(client, `cd "${data.cwd}" && pm2 restart ${item.id}`);
return true;
return await verifyRestart();
}
await execSFTPCommandWithShell(client, `cd "${data.cwd}" && pm2 start "${data.cmd}" --time${data.name ? ` --name "${data.name}"` : ""}`);
status = await getPM2Status(client);
if (!status) {
console.error("Failed to get status after starting app");
return false;
}
if (!(data.name && !data.oneProcess ? status.find((item) => item.name === data.name) : status[0])) {
console.error("Failed to start app");
return false;
}
if (!await verifyRestart()) return false;
await execSFTPCommandWithShell(client, "pm2 startup systemd && chmod -x /etc/systemd/system/pm2-root.service && systemctl daemon-reload && pm2 save");

@@ -37,0 +47,0 @@ return true;

@@ -6,3 +6,3 @@ {

"author": "Vjacheslav Trushkin",
"version": "0.0.11",
"version": "0.0.12",
"license": "UNLICENSED",

@@ -27,3 +27,3 @@ "homepage": "https://cyberalien.dev/",

"dependencies": {
"@cyberalien/git-utils": "^0.0.11",
"@cyberalien/git-utils": "^0.0.12",
"ssh2": "^1.17.0"

@@ -30,0 +30,0 @@ },