Skip to content

Commit 04161d0

Browse files
authored
Update title via postDeployUploaded instead of postUpdateProject (#1715)
1 parent a920deb commit 04161d0

File tree

6 files changed

+21
-57
lines changed

6 files changed

+21
-57
lines changed

src/build.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ export async function build(
321321

322322
// Render pages!
323323
const buildManifest: BuildManifest = {pages: []};
324+
if (config.title) buildManifest.title = config.title;
324325
for (const [path, output] of outputs) {
325326
effects.output.write(`${faint("render")} ${path} ${faint("→")} `);
326327
if (output.type === "page") {
@@ -487,5 +488,6 @@ export class FileBuildEffects implements BuildEffects {
487488
}
488489

489490
export interface BuildManifest {
491+
title?: string;
490492
pages: {path: string; title: string | null}[];
491493
}

src/deploy.ts

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import type {
2121
GetCurrentUserResponse,
2222
GetDeployResponse,
2323
GetProjectResponse,
24-
PostEditProjectRequest,
2524
WorkspaceResponse
2625
} from "./observableApiClient.js";
2726
import type {ConfigEffects, DeployConfig} from "./observableApiConfig.js";
@@ -193,18 +192,13 @@ class Deployer {
193192

194193
private async startNewDeploy(): Promise<GetDeployResponse> {
195194
const deployConfig = await this.getUpdatedDeployConfig();
196-
const {deployTarget, projectUpdates} = await this.getDeployTarget(deployConfig);
197-
195+
const deployTarget = await this.getDeployTarget(deployConfig);
198196
const buildFilePaths = await this.getBuildFilePaths();
199-
200197
const deployId = await this.createNewDeploy(deployTarget);
201198

202199
await this.uploadFiles(deployId, buildFilePaths);
203200
await this.markDeployUploaded(deployId);
204-
const deployInfo = await this.pollForProcessingCompletion(deployId);
205-
await this.maybeUpdateProject(deployTarget, projectUpdates);
206-
207-
return deployInfo;
201+
return await this.pollForProcessingCompletion(deployId);
208202
}
209203

210204
// Make sure deploy exists and has an expected status.
@@ -280,19 +274,15 @@ class Deployer {
280274
}
281275

282276
// Get the deploy target, prompting the user as needed.
283-
private async getDeployTarget(
284-
deployConfig: DeployConfig
285-
): Promise<{deployTarget: DeployTargetInfo; projectUpdates: PostEditProjectRequest}> {
277+
private async getDeployTarget(deployConfig: DeployConfig): Promise<DeployTargetInfo> {
286278
let deployTarget: DeployTargetInfo;
287-
const projectUpdates: PostEditProjectRequest = {};
288279
if (deployConfig.workspaceLogin && deployConfig.projectSlug) {
289280
try {
290281
const project = await this.apiClient.getProject({
291282
workspaceLogin: deployConfig.workspaceLogin,
292283
projectSlug: deployConfig.projectSlug
293284
});
294285
deployTarget = {create: false, workspace: project.owner, project};
295-
if (this.deployOptions.config.title !== project.title) projectUpdates.title = this.deployOptions.config.title;
296286
} catch (error) {
297287
if (!isHttpError(error) || error.statusCode !== 404) {
298288
throw error;
@@ -360,10 +350,6 @@ class Deployer {
360350
throw new CliError("Running non-interactively, cancelling due to conflict.");
361351
}
362352
}
363-
364-
if (deployTarget.project.title !== this.deployOptions.config.title) {
365-
projectUpdates.title = this.deployOptions.config.title;
366-
}
367353
}
368354

369355
if (deployTarget.create) {
@@ -409,7 +395,7 @@ class Deployer {
409395
this.effects
410396
);
411397

412-
return {deployTarget, projectUpdates};
398+
return deployTarget;
413399
}
414400

415401
// Create the new deploy on the server.
@@ -704,12 +690,6 @@ class Deployer {
704690
if (!deployInfo) throw new CliError("Deploy failed to process on server");
705691
return deployInfo;
706692
}
707-
708-
private async maybeUpdateProject(deployTarget: DeployTargetInfo, projectUpdates: PostEditProjectRequest) {
709-
if (!deployTarget.create && typeof projectUpdates?.title === "string") {
710-
await this.apiClient.postEditProject(deployTarget.project.id, projectUpdates);
711-
}
712-
}
713693
}
714694

715695
// export for testing

src/observableApiClient.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,6 @@ export class ObservableApiClient {
144144
});
145145
}
146146

147-
async postEditProject(projectId: string, updates: PostEditProjectRequest): Promise<PostEditProjectResponse> {
148-
return await this._fetch<PostEditProjectResponse>(new URL(`/cli/project/${projectId}/edit`, this._apiOrigin), {
149-
method: "POST",
150-
headers: {"content-type": "application/json"},
151-
body: JSON.stringify({...updates})
152-
});
153-
}
154-
155147
async getWorkspaceProjects(workspaceLogin: string): Promise<GetProjectResponse[]> {
156148
const pages = await this._fetch<PaginatedList<GetProjectResponse>>(
157149
new URL(`/cli/workspace/@${workspaceLogin}/projects`, this._apiOrigin),
@@ -229,10 +221,6 @@ export class ObservableApiClient {
229221
}
230222
}
231223

232-
export interface PostEditProjectRequest {
233-
title?: string;
234-
}
235-
236224
export interface PostEditProjectResponse {
237225
id: string;
238226
slug: string;

test/build-test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,21 @@ describe("build", () => {
148148

149149
await Promise.all([inputDir, cacheDir, outputDir].map((dir) => rm(dir, {recursive: true}))).catch(() => {});
150150
});
151+
152+
it("should include the title in the build manifest", async () => {
153+
const tmpPrefix = join(os.tmpdir(), "framework-test-");
154+
const inputDir = await mkdtemp(tmpPrefix + "input-");
155+
await writeFile(join(inputDir, "index.md"), "# Hello, world!");
156+
157+
const outputDir = await mkdtemp(tmpPrefix + "output-");
158+
const cacheDir = await mkdtemp(tmpPrefix + "output-");
159+
const effects = new LoggingBuildEffects(outputDir, cacheDir);
160+
const config = normalizeConfig({root: inputDir, output: outputDir, title: "Project Title"}, inputDir);
161+
await build({config}, effects);
162+
163+
assert.deepEqual(effects.buildManifest?.title, "Project Title");
164+
await Promise.all([inputDir, cacheDir, outputDir].map((dir) => rm(dir, {recursive: true}))).catch(() => {});
165+
});
151166
});
152167

153168
function* findFiles(root: string): Iterable<string> {

test/deploy-test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ describe("deploy", () => {
293293
getCurrentObservableApi()
294294
.handleGetCurrentUser()
295295
.handleGetProject({...DEPLOY_CONFIG, title: oldTitle})
296-
.handleUpdateProject({projectId: DEPLOY_CONFIG.projectId, title: TEST_CONFIG.title!})
297296
.handlePostDeploy({projectId: DEPLOY_CONFIG.projectId, deployId})
298297
.expectStandardFiles({deployId})
299298
.handlePostDeployUploaded({deployId})
@@ -324,7 +323,6 @@ describe("deploy", () => {
324323
.expectStandardFiles({deployId})
325324
.handlePostDeployUploaded({deployId})
326325
.handleGetDeploy({deployId})
327-
.handleUpdateProject({projectId: DEPLOY_CONFIG.projectId, title: TEST_CONFIG.title!})
328326
.start();
329327

330328
const effects = new MockDeployEffects({

test/mocks/observableApi.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -215,25 +215,6 @@ class ObservableApiMock {
215215
return this;
216216
}
217217

218-
handleUpdateProject({
219-
projectId = "project123",
220-
title,
221-
status = 200
222-
}: {
223-
projectId?: string;
224-
title?: string;
225-
status?: number;
226-
} = {}): ObservableApiMock {
227-
const response = status == 200 ? JSON.stringify({title, slug: "bi"}) : emptyErrorBody;
228-
const headers = authorizationHeader(status !== 403);
229-
this.addHandler((pool) =>
230-
pool
231-
.intercept({path: `/cli/project/${projectId}/edit`, method: "POST", headers: headersMatcher(headers)})
232-
.reply(status, response, {headers: {"content-type": "application/json"}})
233-
);
234-
return this;
235-
}
236-
237218
handleGetWorkspaceProjects({
238219
workspaceLogin,
239220
projects,

0 commit comments

Comments
 (0)