mirror of
https://github.com/AikidoSec/safe-chain.git
synced 2026-05-26 12:10:49 +00:00
Merge remote-tracking branch 'origin/main' into feature/pypi
This commit is contained in:
commit
548d416996
64 changed files with 1689 additions and 381 deletions
|
|
@ -3,6 +3,15 @@ import * as os from "os";
|
|||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
/**
|
||||
* @typedef {Object} AikidoTool
|
||||
* @property {string} tool
|
||||
* @property {string} aikidoCommand
|
||||
*/
|
||||
|
||||
/**
|
||||
* @type {AikidoTool[]}
|
||||
*/
|
||||
export const knownAikidoTools = [
|
||||
{ tool: "npm", aikidoCommand: "aikido-npm" },
|
||||
{ tool: "npx", aikidoCommand: "aikido-npx" },
|
||||
|
|
@ -32,6 +41,11 @@ export function getPackageManagerList() {
|
|||
return `${tools.join(", ")}, and ${lastTool} commands`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} executableName
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function doesExecutableExistOnSystem(executableName) {
|
||||
if (os.platform() === "win32") {
|
||||
const result = spawnSync("where", [executableName], { stdio: "ignore" });
|
||||
|
|
@ -42,6 +56,13 @@ export function doesExecutableExistOnSystem(executableName) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} filePath
|
||||
* @param {RegExp} pattern
|
||||
* @param {string} [eol]
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
export function removeLinesMatchingPattern(filePath, pattern, eol) {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return;
|
||||
|
|
@ -56,6 +77,12 @@ export function removeLinesMatchingPattern(filePath, pattern, eol) {
|
|||
}
|
||||
|
||||
const maxLineLength = 100;
|
||||
|
||||
/**
|
||||
* @param {string} line
|
||||
* @param {RegExp} pattern
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function shouldRemoveLine(line, pattern) {
|
||||
const isPatternMatch = pattern.test(line);
|
||||
|
||||
|
|
@ -84,6 +111,13 @@ function shouldRemoveLine(line, pattern) {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} filePath
|
||||
* @param {string} line
|
||||
* @param {string} [eol]
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
export function addLineToFile(filePath, line, eol) {
|
||||
createFileIfNotExists(filePath);
|
||||
|
||||
|
|
@ -94,6 +128,11 @@ export function addLineToFile(filePath, line, eol) {
|
|||
fs.writeFileSync(filePath, updatedContent, "utf-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} filePath
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
function createFileIfNotExists(filePath) {
|
||||
if (fs.existsSync(filePath)) {
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue