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

feat(connect): ph cli version in settings #1065

Merged
merged 4 commits into from
Feb 18, 2025
Merged
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
13 changes: 12 additions & 1 deletion apps/connect/src/components/modal/modals/settings/about.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { About as BaseAbout } from '@powerhousedao/design-system';
import { useConnectConfig } from 'src/hooks/useConnectConfig';
import packageJson from '../../../../../package.json';

export const About: React.FC = () => {
return <BaseAbout packageJson={packageJson} />;
const [connectConfig] = useConnectConfig();
return (
<BaseAbout
packageJson={packageJson}
phCliVersion={
typeof connectConfig.phCliVersion === 'string'
? connectConfig.phCliVersion
: undefined
}
/>
);
};
3 changes: 3 additions & 0 deletions apps/connect/src/connect.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const PH_CONNECT_SENTRY_TRACING_ENABLED =
import.meta.env.PH_CONNECT_SENTRY_TRACING_ENABLED || 'false';

const GA_TRACKING_ID = import.meta.env.PH_CONNECT_GA_TRACKING_ID;
const PH_CONNECT_CLI_VERSION =
import.meta.env.PH_CONNECT_CLI_VERSION || undefined;

export default {
appVersion: APP_VERSION,
Expand Down Expand Up @@ -76,4 +78,5 @@ export default {
},
},
gaTrackingId: GA_TRACKING_ID,
phCliVersion: PH_CONNECT_CLI_VERSION,
};
1 change: 1 addition & 0 deletions apps/connect/src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type ImportMetaEnv = {
LOCAL_DOCUMENT_MODELS: string
LOCAL_DOCUMENT_EDITORS: string
LOAD_EXTERNAL_PACKAGES: string
PH_CONNECT_CLI_VERSION: string
// @user-defined-start
/*
* You can use this section to explicitly extend the type definition of `import.meta.env`
Expand Down
5 changes: 5 additions & 0 deletions apps/connect/studio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type ConnectStudioOptions = {
localDocuments?: string;
open?: boolean;
packages?: { packageName: string }[];
phCliVersion?: string;
};

export function startConnectStudio(options: ConnectStudioOptions) {
Expand Down Expand Up @@ -99,6 +100,10 @@ export function startConnectStudio(options: ConnectStudioOptions) {
serverOptions.https = options.https;
}

if (options.phCliVersion) {
serverOptions.phCliVersion = options.phCliVersion;
}

return startServer(serverOptions).catch(error => {
throw error;
});
Expand Down
2 changes: 2 additions & 0 deletions apps/connect/studio/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type StartServerOptions = {
packages?: string[];
https?: boolean;
open?: boolean;
phCliVersion?: string;
};

const studioDirname = fileURLToPath(new URL('.', import.meta.url));
Expand Down Expand Up @@ -96,6 +97,7 @@ export async function startServer(options: StartServerOptions = {}) {
}

process.env.PH_CONNECT_STUDIO_MODE = 'true';
process.env.PH_CONNECT_CLI_VERSION = options.phCliVersion;

const config: InlineConfig = {
customLogger: logger,
Expand Down
8 changes: 4 additions & 4 deletions clis/ph-cli/src/commands/connect.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getConfig } from "@powerhousedao/config/powerhouse";
import {
startConnectStudio,
ConnectStudioOptions,
startConnectStudio,
} from "@powerhousedao/connect";
import { getConfig } from "@powerhousedao/config/powerhouse";
import { Command } from "commander";

import { version } from "../../package.json";
export type ConnectOptions = ConnectStudioOptions;

export async function startConnect(connectOptions: ConnectOptions) {
Expand Down Expand Up @@ -36,10 +36,10 @@ export function connectCommand(program: Command) {
.action(async (...args: [ConnectOptions]) => {
const connectOptions = args.at(0) || {};
const { documentModelsDir, editorsDir, packages, studio } = getConfig();

await startConnectStudio({
port: studio?.port?.toString() || undefined,
packages,
phCliVersion: typeof version === "string" ? version : undefined,
localDocuments: documentModelsDir || undefined,
localEditors: editorsDir || undefined,
open: studio?.openBrowser,
Expand Down
5 changes: 3 additions & 2 deletions clis/ph-cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "./dist",
"isolatedModules": true
"isolatedModules": true,
"resolveJsonModule": true,
},
"include": ["src/**/*", "*.config.ts"]
"include": ["src/**/*", "*.config.ts", "package.json"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ export const Default: Story = {
packageJson: mockPackageJson,
},
};

export const WithPhCliVersion: Story = {
args: {
packageJson: mockPackageJson,
phCliVersion: "1.0.0",
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { DependencyVersions } from "../settings-modal/dependency-versions/depend

type Props = {
packageJson: unknown;
phCliVersion?: string;
};
export function About(props: Props) {
const { packageJson } = props;
const { packageJson, phCliVersion } = props;
return (
<div className="bg-white p-3">
<h2 className="font-semibold">About</h2>
Expand All @@ -14,7 +15,10 @@ export function About(props: Props) {
Connect.
</p>
<div className="my-4">
<DependencyVersions packageJson={packageJson} />
<DependencyVersions
packageJson={packageJson}
phCliVersion={phCliVersion}
/>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,17 @@ export const Default: Story = {
packageJson: mockPackageJson,
},
};

export const WithPhCliVersion: Story = {
decorators: [
(Story) => (
<div className="w-[320px]">
<Story />
</div>
),
],
args: {
packageJson: mockPackageJson,
phCliVersion: "1.0.0",
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ export function verifyPackageJsonFields(

type Props = {
readonly packageJson: unknown;
readonly phCliVersion?: string;
};

export function DependencyVersions(props: Props) {
const [isOpen, setIsOpen] = useState(false);
const { packageJson } = props;
const { packageJson, phCliVersion } = props;

const validatedData = verifyPackageJsonFields(packageJson);
if (!validatedData) {
Expand All @@ -90,7 +91,7 @@ export function DependencyVersions(props: Props) {
title={`App version: ${validatedData.version}`}
toggleClassName="text-gray-900 text-sm"
>
<ul className="text-gray-600 text-sm">
<ul className="text-sm text-gray-600">
{REQUIRED_DEPENDENCIES.map((dep) => (
<li key={dep} className="my-1 flex justify-between pr-1">
<span>{dep.replace("@powerhousedao/", "")}:</span>
Expand All @@ -99,6 +100,12 @@ export function DependencyVersions(props: Props) {
</span>
</li>
))}
{phCliVersion && (
<li className="my-1 flex justify-between pr-1" key="ph-cli">
<span>@powerhousedao/ph-cli:</span>
<span className="font-normal">{phCliVersion}</span>
</li>
)}
</ul>
</Disclosure>
);
Expand Down