mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Merge branch 'main' into non-interactive-terminal-support
This commit is contained in:
commit
b2ce8a2abb
8 changed files with 207 additions and 22 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { spawnSync } from "child_process";
|
||||
import * as os from "os";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
export const knownAikidoTools = [
|
||||
{ tool: "npm", aikidoCommand: "aikido-npm" },
|
||||
|
|
@ -81,13 +82,24 @@ function shouldRemoveLine(line, pattern) {
|
|||
}
|
||||
|
||||
export function addLineToFile(filePath, line, eol) {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
fs.writeFileSync(filePath, "", "utf-8");
|
||||
}
|
||||
createFileIfNotExists(filePath);
|
||||
|
||||
eol = eol || os.EOL;
|
||||
|
||||
const fileContent = fs.readFileSync(filePath, "utf-8");
|
||||
const updatedContent = fileContent + eol + line;
|
||||
const updatedContent = fileContent + eol + line + eol;
|
||||
fs.writeFileSync(filePath, updatedContent, "utf-8");
|
||||
}
|
||||
|
||||
function createFileIfNotExists(filePath) {
|
||||
if (fs.existsSync(filePath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const dir = path.dirname(filePath);
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
|
||||
fs.writeFileSync(filePath, "", "utf-8");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,11 +56,13 @@ export async function setup() {
|
|||
*/
|
||||
function setupShell(shell) {
|
||||
let success = false;
|
||||
let error;
|
||||
try {
|
||||
shell.teardown(knownAikidoTools); // First, tear down to prevent duplicate aliases
|
||||
success = shell.setup(knownAikidoTools);
|
||||
} catch {
|
||||
} catch (err) {
|
||||
success = false;
|
||||
error = err;
|
||||
}
|
||||
|
||||
if (success) {
|
||||
|
|
@ -75,6 +77,13 @@ function setupShell(shell) {
|
|||
"Setup failed"
|
||||
)}. Please check your ${shell.name} configuration.`
|
||||
);
|
||||
if (error) {
|
||||
let message = ` Error: ${error.message}`;
|
||||
if (error.code) {
|
||||
message += ` (code: ${error.code})`;
|
||||
}
|
||||
ui.writeError(message);
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue