-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jikun/start or deploy from outside #740
Changes from 4 commits
0e594e5
c9bfcbd
610459f
735fc94
03d034a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,22 +48,37 @@ 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<SWACLIConfig> { | ||
logger.silly(`Getting config file options from ${configFilePath}...`); | ||
logger.silly(`Getting config file options from "${configFilePath}"...`); | ||
|
||
configFilePath = path.resolve(configFilePath); | ||
if (!swaCliConfigFileExists(configFilePath)) { | ||
logger.silly(`Config file does not exist at ${configFilePath}`); | ||
return {}; | ||
let resolvedConfigFilePath = path.resolve(configFilePath); | ||
if (!swaCliConfigFileExists(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)} <command> ${configName} [options]"?`, | ||
initial: true, | ||
}); | ||
if (!confirmConfigPath) { | ||
return {}; | ||
} | ||
resolvedConfigFilePath = path.resolve(configName, configFilePath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question: Why in some places |
||
} | ||
|
||
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 +92,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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: |
||
config, | ||
}; | ||
return { ...config }; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little strange that both
path.join
andpath.resolve
were used in the same part of code. I believe using only one of them is enough depending on the case.Nit: make it as a variable in the beginning.