From 0e594e5f1a0c735440b0f62a8a9622124c120984 Mon Sep 17 00:00:00 2001 From: Jikun Date: Wed, 2 Aug 2023 17:22:07 +0800 Subject: [PATCH 1/4] fix: accept apiDevserverUrl with non-ok response --- src/msha/handlers/function.handler.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/msha/handlers/function.handler.ts b/src/msha/handlers/function.handler.ts index ac1257a3..b0c2129f 100644 --- a/src/msha/handlers/function.handler.ts +++ b/src/msha/handlers/function.handler.ts @@ -63,11 +63,10 @@ async function resolveLocalhostByFetching(url: string) { .then((response) => { if (response.ok || response.redirected) { logger.silly(`Fetch ${Url} successfully`); - return Url; } else { - logger.silly(`Fetch ${Url} failed with status ${response.status} ${response.statusText}`); - throw new Error(`Fetch ${Url} failed with status ${response.status} ${response.statusText}`); + logger.warn(`Fetch ${Url} with status ${response.status} ${response.statusText}`); } + return Url; }) .catch((err) => { logger.silly(`Could not fetch ${Url}`); From 610459f4a342e0f1a6cdf9c6ae34ec2e99e3a6a8 Mon Sep 17 00:00:00 2001 From: Jikun Date: Fri, 18 Aug 2023 15:04:09 +0800 Subject: [PATCH 2/4] feat: support start or deploy outside app folder --- src/core/utils/cli-config.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/core/utils/cli-config.ts b/src/core/utils/cli-config.ts index 0053d249..5524fae9 100644 --- a/src/core/utils/cli-config.ts +++ b/src/core/utils/cli-config.ts @@ -49,20 +49,27 @@ export function matchLoadedConfigName(name: string) { export async function getConfigFileOptions(configName: string | undefined, configFilePath: string): Promise { logger.silly(`Getting config file options from ${configFilePath}...`); - configFilePath = path.resolve(configFilePath); - if (!swaCliConfigFileExists(configFilePath)) { + let resolvedConfigFilePath = path.resolve(configFilePath); + if (!swaCliConfigFileExists(resolvedConfigFilePath)) { logger.silly(`Config file does not exist at ${configFilePath}`); - return {}; + if (configName) { + resolvedConfigFilePath = path.resolve(configName, configFilePath); + if (!swaCliConfigFileExists(resolvedConfigFilePath)) { + return {}; + } else { + logger.silly(`Found config file at ${resolvedConfigFilePath}`); + } + } } - const cliConfig = await tryParseSwaCliConfig(configFilePath); + const cliConfig = await tryParseSwaCliConfig(resolvedConfigFilePath); if (!cliConfig.configurations) { logger.warn(`${swaCliConfigFilename} is missing the "configurations" property. No options will be loaded.`); return {}; } // Use configuration root path as the outputLocation - const configDir = path.dirname(configFilePath); + const configDir = path.dirname(resolvedConfigFilePath); process.chdir(configDir); logger.silly(`Changed directory to ${configDir}`); @@ -76,10 +83,10 @@ export async function getConfigFileOptions(configName: string | undefined, confi } const [configName, config] = Object.entries(cliConfig.configurations)[0]; - printConfigMsg(configName, configFilePath); + printConfigMsg(configName, resolvedConfigFilePath); currentSwaCliConfigFromFile = { name: configName, - filePath: configFilePath, + filePath: resolvedConfigFilePath, config, }; return { ...config }; From 735fc94e1a30ff38df44de9ba2d96e97413a1889 Mon Sep 17 00:00:00 2001 From: Jikun Date: Mon, 21 Aug 2023 12:37:53 +0800 Subject: [PATCH 3/4] introducing prompts --- src/core/utils/cli-config.ts | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/core/utils/cli-config.ts b/src/core/utils/cli-config.ts index 5524fae9..816330aa 100644 --- a/src/core/utils/cli-config.ts +++ b/src/core/utils/cli-config.ts @@ -3,6 +3,7 @@ import { existsSync, promises as fsPromises } from "fs"; import * as path from "path"; import * as process from "process"; import { logger } from "./logger"; +import { promptOrUseDefault } from "../prompts"; const { readFile, writeFile } = fsPromises; export const swaCliConfigSchemaUrl = "https://aka.ms/azure/static-web-apps-cli/schema"; @@ -47,19 +48,27 @@ export function matchLoadedConfigName(name: string) { * @returns An object with the `{@link SWACLIOptions}` config or an empty object if the config file, or the config entry were not found. */ export async function getConfigFileOptions(configName: string | undefined, configFilePath: string): Promise { - logger.silly(`Getting config file options from ${configFilePath}...`); + logger.silly(`Getting config file options from "${configFilePath}"...`); let resolvedConfigFilePath = path.resolve(configFilePath); if (!swaCliConfigFileExists(resolvedConfigFilePath)) { - logger.silly(`Config file does not exist at ${configFilePath}`); - if (configName) { - resolvedConfigFilePath = path.resolve(configName, configFilePath); - if (!swaCliConfigFileExists(resolvedConfigFilePath)) { - return {}; - } else { - logger.silly(`Found config file at ${resolvedConfigFilePath}`); - } + logger.silly(`Config file does not exist at "${configFilePath}"`); + + // Handle the case when the user runs the command outside the project path + if (!configName || !swaCliConfigFileExists(path.resolve(configName, configFilePath))) { + return {}; + } + logger.warn(`WARNING: Config file does not exist at "${configFilePath}", but can be detected at "${path.join(configName, configFilePath)}".`); + const { confirmConfigPath } = await promptOrUseDefault(false, { + type: "confirm", + name: "confirmConfigPath", + message: `Do you mean "swa --config ${path.join(configName, configFilePath)} ${configName} [options]"?`, + initial: true, + }); + if (!confirmConfigPath) { + return {}; } + resolvedConfigFilePath = path.resolve(configName, configFilePath); } const cliConfig = await tryParseSwaCliConfig(resolvedConfigFilePath); From 03d034a1c6f2ec43a4f9309ac3d7ffd842473361 Mon Sep 17 00:00:00 2001 From: Jikun Date: Tue, 22 Aug 2023 19:19:00 +0800 Subject: [PATCH 4/4] remove prompts --- src/core/utils/cli-config.ts | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/core/utils/cli-config.ts b/src/core/utils/cli-config.ts index 816330aa..3029d618 100644 --- a/src/core/utils/cli-config.ts +++ b/src/core/utils/cli-config.ts @@ -3,7 +3,6 @@ import { existsSync, promises as fsPromises } from "fs"; import * as path from "path"; import * as process from "process"; import { logger } from "./logger"; -import { promptOrUseDefault } from "../prompts"; const { readFile, writeFile } = fsPromises; export const swaCliConfigSchemaUrl = "https://aka.ms/azure/static-web-apps-cli/schema"; @@ -50,35 +49,31 @@ export function matchLoadedConfigName(name: string) { export async function getConfigFileOptions(configName: string | undefined, configFilePath: string): Promise { logger.silly(`Getting config file options from "${configFilePath}"...`); - let resolvedConfigFilePath = path.resolve(configFilePath); - if (!swaCliConfigFileExists(resolvedConfigFilePath)) { + let configFilePathResolved = path.resolve(configFilePath); + if (!swaCliConfigFileExists(configFilePathResolved)) { logger.silly(`Config file does not exist at "${configFilePath}"`); // Handle the case when the user runs the command outside the project path - if (!configName || !swaCliConfigFileExists(path.resolve(configName, configFilePath))) { + if (!configName || !swaCliConfigFileExists(path.resolve(configName, swaCliConfigFilename))) { return {}; } - logger.warn(`WARNING: Config file does not exist at "${configFilePath}", but can be detected at "${path.join(configName, configFilePath)}".`); - const { confirmConfigPath } = await promptOrUseDefault(false, { - type: "confirm", - name: "confirmConfigPath", - message: `Do you mean "swa --config ${path.join(configName, configFilePath)} ${configName} [options]"?`, - initial: true, - }); - if (!confirmConfigPath) { - return {}; - } - resolvedConfigFilePath = path.resolve(configName, configFilePath); + logger.warn( + `WARNING: Config file does not exist at "${configFilePath}", but can be detected at "${path.join( + configName, + swaCliConfigFilename + )}". Do you mean "swa --config ${path.join(configName, swaCliConfigFilename)} ${configName} [options]"?` + ); + configFilePathResolved = path.resolve(configName, swaCliConfigFilename); } - const cliConfig = await tryParseSwaCliConfig(resolvedConfigFilePath); + const cliConfig = await tryParseSwaCliConfig(configFilePathResolved); if (!cliConfig.configurations) { logger.warn(`${swaCliConfigFilename} is missing the "configurations" property. No options will be loaded.`); return {}; } // Use configuration root path as the outputLocation - const configDir = path.dirname(resolvedConfigFilePath); + const configDir = path.dirname(configFilePathResolved); process.chdir(configDir); logger.silly(`Changed directory to ${configDir}`); @@ -92,10 +87,10 @@ export async function getConfigFileOptions(configName: string | undefined, confi } const [configName, config] = Object.entries(cliConfig.configurations)[0]; - printConfigMsg(configName, resolvedConfigFilePath); + printConfigMsg(configName, configFilePathResolved); currentSwaCliConfigFromFile = { name: configName, - filePath: resolvedConfigFilePath, + filePath: configFilePathResolved, config, }; return { ...config };