radashi-helper
Version:
Help with managing your own Radashi
68 lines (66 loc) • 1.8 kB
JavaScript
import {
queryFuncs
} from "./chunk-GDVGEOPF.js";
import {
openInEditor
} from "./chunk-CQEIEK2X.js";
import "./chunk-GGEXN2BI.js";
import {
findSources
} from "./chunk-652CQLOF.js";
import {
cwdRelative,
projectFolders
} from "./chunk-BKS73LZK.js";
import "./chunk-MJC327DM.js";
import {
getEnv
} from "./chunk-DSXY7YVB.js";
import {
log
} from "./chunk-JLKIE3A2.js";
import {
sift
} from "./chunk-VOEQFXI5.js";
// src/open.ts
import { existsSync } from "node:fs";
import { join, relative } from "node:path";
async function openFunction(query = "", options = {}) {
const env = options.env ?? getEnv();
const sources = await findSources(env, ["src", "overrides"]);
const { funcPath } = await queryFuncs(
query,
sift(
Object.entries(sources).flatMap(([type, paths]) => {
const root = join(env.root, type === "src" ? "" : type, "src");
return paths?.map((p) => relative(root, p).replace(/\.ts$/, ""));
})
)
);
const targetFolders = options.all ? projectFolders : projectFolders.filter((f) => {
return options.source && f.name === "src" || options.test && f.extension === ".test.ts" || options.typeTest && f.extension === ".test-d.ts" || options.benchmark && f.name === "benchmarks" || options.docs && f.name === "docs";
});
let openedCount = 0;
for (const folder of targetFolders) {
for (const overrideFolder of ["", "overrides"]) {
const file = join(
env.root,
overrideFolder,
folder.name,
funcPath + folder.extension
);
if (existsSync(file)) {
await openInEditor(file, env);
log(`
Opening ${cwdRelative(file)}`);
openedCount++;
}
}
}
if (openedCount === 0) {
log("\nNo files were found. Exiting.");
}
}
export {
openFunction
};