Skip to content
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

add config schema option #803

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cli/commands/init/init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const defautResolvedPrompts = {
appDevserverUrl: "http://localhost:3000",
apiDevserverUrl: "http://localhost:4040",
confirmOverwrite: true,
schemaUrl: "https://json.schemastore.org/staticwebapp.config.json",
};

describe("swa init", () => {
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/start/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default function registerCommand(program: Command) {
)
.option("-o, --open", "open the browser to the dev server", DEFAULT_CONFIG.open)
.option("-f, --func-args <funcArgs>", "pass additional arguments to the func start command")
.option("-sc, --schema <schemaUrl>", "URL to the custom schema for staticwebapp.config.json", DEFAULT_CONFIG.schemaUrl)
.action(async (positionalArg: string | undefined, _options: SWACLIConfig, command: Command) => {
positionalArg = positionalArg?.trim();
const options = await configureOptions(positionalArg, command.optsWithGlobals(), command, "start");
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const {
SWA_CLI_DATA_API_FOLDER,
SWA_CLI_API_LANGUAGE,
SWA_CLI_API_VERSION,
SWA_CLI_CONFIG_SCHEMA_LOCATION,
} = swaCLIEnv();

export const DEFAULT_CONFIG: SWACLIConfig = {
Expand All @@ -59,6 +60,7 @@ export const DEFAULT_CONFIG: SWACLIConfig = {
verbose: SWA_CLI_DEBUG || "log",
devserverTimeout: parseInt(SWA_CLI_SERVER_TIMEOUT || "60", 10),
open: useEnvVarOrUseDefault(SWA_CLI_OPEN_BROWSER, false),
schemaUrl: SWA_CLI_CONFIG_SCHEMA_LOCATION || undefined,
githubActionWorkflowLocation: SWA_RUNTIME_WORKFLOW_LOCATION ? SWA_RUNTIME_WORKFLOW_LOCATION : undefined,
appDevserverUrl: SWA_CLI_APP_DEVSERVER_URL || undefined,
apiDevserverUrl: SWA_CLI_API_DEVSERVER_URL || undefined,
Expand Down
3 changes: 2 additions & 1 deletion src/core/utils/user-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import path from "path";
import { SWA_CONFIG_FILENAME, SWA_CONFIG_FILENAME_LEGACY, SWA_RUNTIME_CONFIG_MAX_SIZE_IN_KB } from "../constants";
import { logger } from "./logger";
import { isHttpUrl } from "./net";
import { DEFAULT_CONFIG } from "../../config";
const { readdir, readFile, stat } = fs.promises;

/**
Expand Down Expand Up @@ -165,7 +166,7 @@ function findLineAndColumnByPosition(content: string, position: number | undefin
}

async function loadSWAConfigSchema(): Promise<JSONSchemaType<SWACLIConfigFile> | null> {
const schemaUrl = "https://json.schemastore.org/staticwebapp.config.json";
const schemaUrl = DEFAULT_CONFIG.schemaUrl || "https://json.schemastore.org/staticwebapp.config.json";
try {
const res = await fetch(schemaUrl, { timeout: 10 * 1000 } as RequestInit);
if (res.status === 200) {
Expand Down
2 changes: 2 additions & 0 deletions src/swa.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ declare interface SWACLIEnv extends StaticSiteClientEnv {
SWA_CLI_APP_DEVSERVER_URL?: string;
SWA_CLI_API_DEVSERVER_URL?: string;
SWA_CLI_DATA_API_DEVSERVER_URL?: string;
SWA_CLI_CONFIG_SCHEMA_LOCATION?: string;

// swa deploy
SWA_CLI_DEPLOY_DRY_RUN?: string;
Expand Down Expand Up @@ -152,6 +153,7 @@ declare type SWACLIStartOptions = {
run?: string;
devserverTimeout?: number;
open?: boolean;
schemaUrl?: string;
funcArgs?: string;
githubActionWorkflowLocation?: string;
swaConfigLocation?: string;
Expand Down
Loading