mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-10-30 09:16:55 +00:00
fix(cli): a file given as the project folder names the folder to pass (#6476)
This commit is contained in:
@@ -23,6 +23,25 @@ describe("resolveProjectOrThrow", () => {
|
||||
expect(() => resolveProjectOrThrow(missing)).toThrowError(/Not a directory/);
|
||||
});
|
||||
|
||||
it("names the project folder when given a file inside it", () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "hf-file-arg-project-"));
|
||||
try {
|
||||
mkdirSync(join(dir, "assets"));
|
||||
writeFileSync(join(dir, "index.html"), "<html></html>");
|
||||
writeFileSync(join(dir, "assets", "music.mp3"), "x");
|
||||
const file = join(dir, "assets", "music.mp3");
|
||||
expect(() => resolveProjectOrThrow(file)).toThrowError(
|
||||
expect.objectContaining({
|
||||
title: "Not a directory: " + file,
|
||||
hint: "music.mp3 is a file; this command takes the project folder.",
|
||||
suggestion: "Pass the folder that holds index.html: " + dir,
|
||||
}),
|
||||
);
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("rejects a directory without index.html", () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "hf-empty-project-"));
|
||||
try {
|
||||
|
||||
@@ -45,7 +45,14 @@ export function resolveProjectOrThrow(
|
||||
const name = basename(dir);
|
||||
const indexPath = resolve(dir, "index.html");
|
||||
|
||||
if (!existsSync(dir) || !statSync(dir).isDirectory()) {
|
||||
if (existsSync(dir) && !statSync(dir).isDirectory()) {
|
||||
throw new InvalidProjectError(
|
||||
"Not a directory: " + dir,
|
||||
basename(dir) + " is a file; this command takes the project folder.",
|
||||
"Pass the folder that holds index.html: " + projectHolding(dir),
|
||||
);
|
||||
}
|
||||
if (!existsSync(dir)) {
|
||||
throw new InvalidProjectError("Not a directory: " + dir);
|
||||
}
|
||||
if (options.requireIndex !== false && !existsSync(indexPath)) {
|
||||
|
||||
Reference in New Issue
Block a user