Skip to content

Commit 0957e2f

Browse files
authored
Merge pull request #8 from anthonychu/fix-windows
Fix Windows sometimes not finding func command
2 parents a6d9de7 + cbe4d19 commit 0957e2f

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

denofunc.ts

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,42 @@ async function generateFunctions() {
121121
}
122122

123123
async function runFunc(...args: string[]) {
124-
const cmd = ["func", ...args];
125-
console.info(`Starting Azure Functions Core Tools: ${cmd.join(" ")}`);
126-
const proc = Deno.run({ cmd });
127-
await proc.status();
124+
let cmd = ["func", ...args];
125+
const env = {
126+
"logging__logLevel__Microsoft": "warning",
127+
"logging__logLevel__Worker": "warning"
128+
};
129+
try {
130+
console.info(`Running Azure Functions Core Tools: ${cmd.join(" ")}`);
131+
const proc = Deno.run({ cmd, env });
132+
await proc.status();
133+
} catch (ex) {
134+
if (Deno.build.os === "windows") {
135+
console.info("Could not start func from path, searching for executable...")
136+
cmd = ["where.exe", "func"];
137+
const proc = Deno.run({
138+
cmd,
139+
stdout: "piped"
140+
});
141+
await proc.status();
142+
const rawOutput = await proc.output();
143+
const funcPath = new TextDecoder().decode(rawOutput).split(/\r?\n/).find(p => p.endsWith("func.cmd"));
144+
if (funcPath) {
145+
cmd = [funcPath, ...args];
146+
console.info(`Running Azure Functions Core Tools: ${cmd.join(" ")}`);
147+
const proc = Deno.run({ cmd, env });
148+
await proc.status();
149+
} else {
150+
throw "Could not located func. Please ensure it is installed and in the path.";
151+
}
152+
} else {
153+
throw ex;
154+
}
155+
}
128156
}
129157

130158
async function publishApp(appName: string) {
131-
const cmd = ["func", "azure", "functionapp", "publish", appName, "--no-build", "-b", "local", "--force"];
132-
console.info(`Publishing app: ${cmd.join(" ")}`);
133-
const proc = Deno.run({ cmd });
134-
await proc.status();
159+
await runFunc("azure", "functionapp", "publish", appName, "--no-build", "-b", "local", "--force");
135160
}
136161

137162
function printLogo() {

0 commit comments

Comments
 (0)