in src/core/frameworks/detect.ts [13:76]
export async function generateConfiguration(app?: DetectedFolder, api?: DetectedFolder, dataApi?: DetectedDbConfigFolder): Promise<FrameworkConfig> {
let config: FrameworkConfig = {
appLocation: DEFAULT_CONFIG.appLocation!,
outputLocation: DEFAULT_CONFIG.outputLocation!,
};
if (!app && !api) {
logger.silly("No known frameworks detected");
return config;
}
let name = "";
if (app) {
name += `${app.frameworks.map((f) => f.name).join(", ")}`;
app.frameworks.forEach((f) => (config = { ...config, ...f.config }));
config.appLocation = await computePath(app.rootPath, config.appLocation);
config.appLocation = removeTrailingPathSep(config.appLocation);
config.outputLocation = await computePath(config.appLocation, config.outputLocation);
config.outputLocation = path.normalize(path.relative(config.appLocation!, config.outputLocation));
config.outputLocation = removeTrailingPathSep(config.outputLocation);
}
if (api) {
name += name ? ", with " : "No app frameworks detected, ";
name += `API: ${api.frameworks.map((f) => f.name).join(", ")}`;
api.frameworks.forEach((f) => (config = { ...config, ...f.config }));
const computedApiLocation = await computePath(api.rootPath, config.apiLocation);
if (computedApiLocation !== api.rootPath) {
// TODO: if someday SWA introduces an equivalent to outputLocation for the API
// we should handle this here
logger.silly(`Built API location "${computedApiLocation}" does not match root API location ${api.rootPath}, which is not supported yet`);
}
config.apiLocation = removeTrailingPathSep(api.rootPath);
}
if (dataApi) {
name += name ? ", " : "No app frameworks detected, ";
name += `data API: ${dataApi.databaseType}`;
config.dataApiLocation = dataApi.rootPath;
}
const appRootPath = app && removeTrailingPathSep(app.rootPath);
if (appRootPath && config.appBuildCommand && appRootPath !== config.appLocation) {
// If the final app location is not the same as the detected root path of the app,
// we need to adjust the build command to run in the correct path.
let commandPath = path.relative(config.appLocation!, appRootPath);
commandPath = hasSpaces(commandPath) ? `"${commandPath}"` : commandPath;
config.appBuildCommand = `cd ${commandPath} && ${config.appBuildCommand}`;
}
const apiRootPath = api && removeTrailingPathSep(api.rootPath);
if (apiRootPath && config.apiBuildCommand && apiRootPath !== config.apiLocation) {
// If the final api location is not the same as the detected root path of the api,
// we need to adjust the build command to run in the correct path.
let commandPath = path.relative(config.apiLocation!, apiRootPath);
commandPath = hasSpaces(commandPath) ? `"${commandPath}"` : commandPath;
config.apiBuildCommand = `cd ${commandPath} && ${config.apiBuildCommand}`;
}
config.name = name;
return config;
}