Skip to content

Commit 7910e1c

Browse files
committed
refactor: update app config type to be defined via confg.d.ts file
1 parent 9da52e6 commit 7910e1c

File tree

4 files changed

+74
-23
lines changed

4 files changed

+74
-23
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
export interface Config {
2+
/**
3+
* Properties that concern your Coder deployment.
4+
* @visibility frontend
5+
*/
6+
deployment: Readonly<{
7+
/**
8+
* The URL where your Coder deployment can be found.
9+
* @visibility frontend
10+
*/
11+
accessUrl: string;
12+
}>;
13+
14+
/**
15+
* Properties that concern the creation and manipulation of individual
16+
* workspaces from within your Coder deployment.
17+
*
18+
* @visibility frontend
19+
*/
20+
workspaces: Readonly<{
21+
/**
22+
* The default workspace creation mode to use when making a new workspace
23+
* from Backstage to Coder.
24+
*
25+
* This value can be overwritten with the `mode` property from a repo's
26+
* app-config.yaml file.
27+
* @visibility frontend
28+
*/
29+
defaultMode?: import('./src/hooks/useCoderWorkspacesConfig').WorkspaceCreationMode;
30+
31+
/**
32+
* The name of the template that will be used by default when creating a new
33+
* workspace.
34+
*
35+
* This value can be overwritten with the `templateName` property from a
36+
* repo's app-config-yaml file.
37+
* @visibility frontend
38+
*/
39+
defaultTemplateName?: string;
40+
41+
/**
42+
* The set of workspace parameters to pass to the Coder deployment when
43+
* making a new workspace.
44+
*
45+
* If a `config` property is defined in app-config.yaml, the keys from the
46+
* base Backstage config and the keys from the repo's app-config file will
47+
* be merged, with the repo params always winning any key conflicts.
48+
* @visibility frontend
49+
*/
50+
params?: Record<string, string | undefined>;
51+
52+
/**
53+
* The key that defines where the URL to a repo can be found from a
54+
* template.
55+
*
56+
* Multiple keys can be defined. In the event that there are multiple keys
57+
* that provide repo information, the first key in the array will always be
58+
* chosen.
59+
* @visibility frontend
60+
*/
61+
repoUrlParamKeys: readonly string[];
62+
}>;
63+
}

plugins/backstage-plugin-coder/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
"msw": "^1.0.0"
6464
},
6565
"files": [
66-
"dist"
66+
"dist",
67+
"config.d.ts"
6768
],
6869
"keywords": [
6970
"backstage",
@@ -73,5 +74,6 @@
7374
"ide",
7475
"vscode",
7576
"jetbrains"
76-
]
77+
],
78+
"configSchema": "config.d.ts"
7779
}

plugins/backstage-plugin-coder/src/components/CoderProvider/CoderAppConfigProvider.tsx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,9 @@ import React, {
33
createContext,
44
useContext,
55
} from 'react';
6-
import type { WorkspaceCreationMode } from '../../hooks/useCoderWorkspacesConfig';
6+
import type { Config as CoderAppConfig } from '../../../config.d.ts';
77

8-
export type CoderAppConfig = Readonly<{
9-
deployment: Readonly<{
10-
accessUrl: string;
11-
}>;
12-
13-
// Type is meant to be used with YamlConfig from useCoderWorkspacesConfig;
14-
// not using a mapped type because there's just enough differences that
15-
// maintaining a relationship that way would be a nightmare of ternaries
16-
workspaces: Readonly<{
17-
defaultMode?: WorkspaceCreationMode;
18-
defaultTemplateName?: string;
19-
params?: Record<string, string | undefined>;
20-
21-
// Defined like this to ensure array always has at least one element
22-
repoUrlParamKeys: readonly [string, ...string[]];
23-
}>;
24-
}>;
8+
export type { Config as CoderAppConfig } from '../../../config.d.ts';
259

2610
const AppConfigContext = createContext<CoderAppConfig | null>(null);
2711

plugins/backstage-plugin-coder/src/hooks/useCoderWorkspacesConfig.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useMemo, useState } from 'react';
22

33
import {
4-
type Output,
4+
type InferOutput,
55
literal,
66
object,
77
optional,
@@ -30,7 +30,9 @@ const workspaceCreationModeSchema = optional(
3030
),
3131
);
3232

33-
export type WorkspaceCreationMode = Output<typeof workspaceCreationModeSchema>;
33+
export type WorkspaceCreationMode = InferOutput<
34+
typeof workspaceCreationModeSchema
35+
>;
3436

3537
// Very loose parsing requirements to make interfacing with various kinds of
3638
// YAML files as easy as possible
@@ -57,7 +59,7 @@ const yamlConfigSchema = union([
5759
* repo's catalog-info.yaml file. The entire value will be undefined if a repo
5860
* does not have the file
5961
*/
60-
export type YamlConfig = Output<typeof yamlConfigSchema>;
62+
export type YamlConfig = InferOutput<typeof yamlConfigSchema>;
6163

6264
/**
6365
* Provides a cleaned and pre-processed version of all repo data that can be

0 commit comments

Comments
 (0)