Skip to content

Commit

Permalink
fix: generator when script is provided as array (#125)
Browse files Browse the repository at this point in the history
Signed-off-by: Chapman Pendery <[email protected]>
  • Loading branch information
cpendery authored Dec 14, 2023
1 parent 785ca0f commit dded563
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/runtime/generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import log from "../utils/log.js";
import { runTemplates } from "./template.js";
import { buildExecuteShellCommand } from "./utils.js";

Expand All @@ -23,7 +24,14 @@ export const runGenerator = async (generator: Fig.Generator, tokens: string[], c
const suggestions = [];
try {
if (script) {
const scriptOutput = typeof script === "function" ? script(tokens) : script != null ? await executeShellCommand(script) : "";
const scriptOutput =
typeof script === "function"
? script(tokens)
: typeof script === "string"
? await executeShellCommand(script)
: script != null
? await executeShellCommand((script as string[]).join(" "))
: "";
if (postProcess) {
suggestions.push(...postProcess(scriptOutput, tokens));
} else if (splitOn) {
Expand All @@ -40,7 +48,7 @@ export const runGenerator = async (generator: Fig.Generator, tokens: string[], c
}
return suggestions;
} catch (e) {
/* empty */
log.debug({ msg: "generator failed", e, script, splitOn, template });
}
return suggestions;
};
2 changes: 1 addition & 1 deletion src/runtime/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const buildExecuteShellCommand =
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- TODO: use cwd in the future
async (command: string, cwd?: string): Promise<string> => {
return new Promise((resolve) => {
exec(command, { timeout }, (_, stdout, stderr) => {
exec(command, { timeout, cwd }, (_, stdout, stderr) => {
resolve(stdout || stderr);
});
});
Expand Down

0 comments on commit dded563

Please sign in to comment.