Skip to content

Commit 08d1abe

Browse files
authored
fix(init): allow to override apiDevserverUrl (#634)
1 parent 8110283 commit 08d1abe

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

src/cli/commands/init/init.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const defautResolvedPrompts = {
2121
apiBuildCommand: "npm run build:api",
2222
appDevserverCommand: "npm run dev",
2323
appDevserverUrl: "http://localhost:3000",
24+
apiDevserverUrl: "http://localhost:4040",
2425
confirmOverwrite: true,
2526
};
2627

@@ -154,4 +155,34 @@ describe("swa init", () => {
154155
}"
155156
`);
156157
});
158+
159+
it("should detect frameworks and let user override config options", async () => {
160+
mockFs({ src: mockFs.load("e2e/fixtures/static-node-ts") });
161+
const promptsMock = jest.requireMock("prompts");
162+
promptsMock.mockResolvedValue({
163+
...defautResolvedPrompts,
164+
confirmSettings: false,
165+
});
166+
167+
await init({ ...defaultCliConfig, configName: "test" });
168+
const configFile = convertToUnixPaths(fs.readFileSync(defaultCliConfig.config, "utf-8"));
169+
170+
expect(configFile).toMatchInlineSnapshot(`
171+
"{
172+
\\"$schema\\": \\"https://aka.ms/azure/static-web-apps-cli/schema\\",
173+
\\"configurations\\": {
174+
\\"test\\": {
175+
\\"appLocation\\": \\"./app\\",
176+
\\"apiLocation\\": \\"./api\\",
177+
\\"outputLocation\\": \\"./dist\\",
178+
\\"appBuildCommand\\": \\"npm run build\\",
179+
\\"apiBuildCommand\\": \\"npm run build:api\\",
180+
\\"run\\": \\"npm run dev\\",
181+
\\"appDevserverUrl\\": \\"http://localhost:3000\\",
182+
\\"apiDevserverUrl\\": \\"http://localhost:4040\\"
183+
}
184+
}
185+
}"
186+
`);
187+
});
157188
});

src/cli/commands/init/init.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ function convertToCliConfig(config: FrameworkConfig): SWACLIConfig {
141141
apiBuildCommand: config.apiBuildCommand,
142142
run: config.appDevserverCommand,
143143
appDevserverUrl: config.appDevserverUrl,
144+
apiDevserverUrl: config.apiDevserverUrl,
144145
};
145146
}
146147

@@ -198,10 +199,17 @@ async function promptConfigSettings(disablePrompts: boolean, detectedConfig: Fra
198199
{
199200
type: "text",
200201
name: "appDevserverUrl",
201-
message: "What is your development server url (optional)",
202+
message: "What's your app development server URL (optional)",
202203
initial: detectedConfig.appDevserverUrl,
203204
format: trimValue,
204205
},
206+
{
207+
type: "text",
208+
name: "apiDevserverUrl",
209+
message: "What's your API development server URL (optional)",
210+
initial: detectedConfig.apiDevserverUrl,
211+
format: trimValue,
212+
},
205213
]);
206214
return response;
207215
}
@@ -216,9 +224,5 @@ function printFrameworkConfig(config: FrameworkConfig) {
216224
logger.log(`- API build command: ${chalk.green(config.apiBuildCommand ?? "")}`);
217225
logger.log(`- App dev server command: ${chalk.green(config.appDevserverCommand ?? "")}`);
218226
logger.log(`- App dev server URL: ${chalk.green(config.appDevserverUrl ?? "")}\n`);
227+
logger.log(`- API dev server URL: ${chalk.green(config.apiDevserverUrl ?? "")}\n`);
219228
}
220-
221-
// function isEmptyFolder(path: string) {
222-
// const files = fs.readdirSync(path);
223-
// return files.length === 0;
224-
// }

src/swa.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ declare type FrameworkConfig = GithubActionWorkflow & {
276276
apiBuildCommand?: string;
277277
appDevserverCommand?: string;
278278
appDevserverUrl?: string;
279+
apiDevserverUrl?: string;
279280
};
280281

281282
declare interface CoreToolsRelease {

0 commit comments

Comments
 (0)