diff --git a/plugins/backstage-plugin-coder/config.d.ts b/plugins/backstage-plugin-coder/config.d.ts new file mode 100644 index 0000000..6262c53 --- /dev/null +++ b/plugins/backstage-plugin-coder/config.d.ts @@ -0,0 +1,63 @@ +export interface Config { + /** + * Properties that concern your Coder deployment. + * @visibility frontend + */ + deployment: Readonly<{ + /** + * The URL where your Coder deployment can be found. + * @visibility frontend + */ + accessUrl: string; + }>; + + /** + * Properties that concern the creation and manipulation of individual + * workspaces from within your Coder deployment. + * + * @visibility frontend + */ + workspaces: Readonly<{ + /** + * The default workspace creation mode to use when making a new workspace + * from Backstage to Coder. + * + * This value can be overwritten with the `mode` property from a repo's + * app-config.yaml file. + * @visibility frontend + */ + defaultMode?: import('./src/hooks/useCoderWorkspacesConfig').WorkspaceCreationMode; + + /** + * The name of the template that will be used by default when creating a new + * workspace. + * + * This value can be overwritten with the `templateName` property from a + * repo's app-config-yaml file. + * @visibility frontend + */ + defaultTemplateName?: string; + + /** + * The set of workspace parameters to pass to the Coder deployment when + * making a new workspace. + * + * If a `config` property is defined in app-config.yaml, the keys from the + * base Backstage config and the keys from the repo's app-config file will + * be merged, with the repo params always winning any key conflicts. + * @visibility frontend + */ + params?: Record; + + /** + * The key that defines where the URL to a repo can be found from a + * template. + * + * Multiple keys can be defined. In the event that there are multiple keys + * that provide repo information, the first key in the array will always be + * chosen. + * @visibility frontend + */ + repoUrlParamKeys: readonly string[]; + }>; +} diff --git a/plugins/backstage-plugin-coder/package.json b/plugins/backstage-plugin-coder/package.json index 1d21b96..9dc60de 100644 --- a/plugins/backstage-plugin-coder/package.json +++ b/plugins/backstage-plugin-coder/package.json @@ -63,7 +63,8 @@ "msw": "^1.0.0" }, "files": [ - "dist" + "dist", + "config.d.ts" ], "keywords": [ "backstage", @@ -73,5 +74,6 @@ "ide", "vscode", "jetbrains" - ] + ], + "configSchema": "config.d.ts" } diff --git a/plugins/backstage-plugin-coder/src/components/CoderProvider/CoderAppConfigProvider.tsx b/plugins/backstage-plugin-coder/src/components/CoderProvider/CoderAppConfigProvider.tsx index e342229..a8443f1 100644 --- a/plugins/backstage-plugin-coder/src/components/CoderProvider/CoderAppConfigProvider.tsx +++ b/plugins/backstage-plugin-coder/src/components/CoderProvider/CoderAppConfigProvider.tsx @@ -3,25 +3,9 @@ import React, { createContext, useContext, } from 'react'; -import type { WorkspaceCreationMode } from '../../hooks/useCoderWorkspacesConfig'; +import type { Config as CoderAppConfig } from '../../../config.d.ts'; -export type CoderAppConfig = Readonly<{ - deployment: Readonly<{ - accessUrl: string; - }>; - - // Type is meant to be used with YamlConfig from useCoderWorkspacesConfig; - // not using a mapped type because there's just enough differences that - // maintaining a relationship that way would be a nightmare of ternaries - workspaces: Readonly<{ - defaultMode?: WorkspaceCreationMode; - defaultTemplateName?: string; - params?: Record; - - // Defined like this to ensure array always has at least one element - repoUrlParamKeys: readonly [string, ...string[]]; - }>; -}>; +export type { Config as CoderAppConfig } from '../../../config.d.ts'; const AppConfigContext = createContext(null); diff --git a/plugins/backstage-plugin-coder/src/hooks/useCoderWorkspacesConfig.ts b/plugins/backstage-plugin-coder/src/hooks/useCoderWorkspacesConfig.ts index 67bbb55..a9ac2ac 100644 --- a/plugins/backstage-plugin-coder/src/hooks/useCoderWorkspacesConfig.ts +++ b/plugins/backstage-plugin-coder/src/hooks/useCoderWorkspacesConfig.ts @@ -1,7 +1,7 @@ import { useMemo, useState } from 'react'; import { - type Output, + type InferOutput, literal, object, optional, @@ -30,7 +30,9 @@ const workspaceCreationModeSchema = optional( ), ); -export type WorkspaceCreationMode = Output; +export type WorkspaceCreationMode = InferOutput< + typeof workspaceCreationModeSchema +>; // Very loose parsing requirements to make interfacing with various kinds of // YAML files as easy as possible @@ -57,7 +59,7 @@ const yamlConfigSchema = union([ * repo's catalog-info.yaml file. The entire value will be undefined if a repo * does not have the file */ -export type YamlConfig = Output; +export type YamlConfig = InferOutput; /** * Provides a cleaned and pre-processed version of all repo data that can be