chore: UPdate the shell

This commit is contained in:
BluJ
2023-04-07 15:06:55 -06:00
parent 90aa314633
commit 4efa94ec10
6 changed files with 17 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
import { Effects } from "../../types";
import { parseCommand } from "../../util/parseCommand";
import { CheckResult } from "./CheckResult";
export function containsAddress(x: string, port: number) {
const readPorts = x
@@ -25,8 +26,14 @@ export async function checkPortListening(
} = {}
): Promise<CheckResult> {
const hasAddress =
containsAddress(await effects.shell("cat /proc/net/tcp"), port) ||
containsAddress(await effects.shell("cat /proc/net/udp"), port);
containsAddress(
await effects.runCommand(parseCommand("cat /proc/net/tcp")),
port
) ||
containsAddress(
await effects.runCommand(parseCommand("cat /proc/net/udp")),
port
);
if (hasAddress) {
return { status: "passing", message };
}

View File

@@ -129,10 +129,6 @@ export type Effects = {
path: string;
}): Promise<Record<string, unknown>>;
shell(
command: string,
options?: { timeoutMillis?: number | null }
): Promise<string>;
runCommand(input: {
command: string;
args?: string[];

View File

@@ -3,7 +3,7 @@ import * as T from "../types";
export { guardAll, typeFromProps } from "./propertiesMatcher";
export { default as nullIfEmpty } from "./nullIfEmpty";
export { FileHelper } from "./fileHelper";
export { sh } from "./shell";
export { parseCommand as sh } from "./parseCommand";
/** Used to check if the file exists before hand */
export const exists = (

View File

@@ -46,7 +46,10 @@ const quoteSeperated = (s: string, quote: typeof quotes) => {
return values;
};
export function sh(shellCommand: string) {
type ValidIfNoStupidEscape<A> = A extends `${string}'"'"'${string}` ? never : A;
export function parseCommand<T extends string>(
shellCommand: ValidIfNoStupidEscape<T>
) {
const [command, ...args] = quoteSeperated(shellCommand, quotes).filter(
Boolean
);

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "start-sdk",
"version": "0.4.0-lib0.charlie8",
"version": "0.4.0-lib0.charlie9",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "start-sdk",
"version": "0.4.0-lib0.charlie8",
"version": "0.4.0-lib0.charlie9",
"license": "MIT",
"dependencies": {
"@iarna/toml": "^2.2.5",

View File

@@ -1,6 +1,6 @@
{
"name": "start-sdk",
"version": "0.4.0-lib0.charlie8",
"version": "0.4.0-lib0.charlie9",
"description": "For making the patterns that are wanted in making services for the startOS.",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",