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

Add global installation option (e.g. pnpm add -g) for HomePage.InstallPackage #184

Open
guidanoli opened this issue Jul 12, 2024 · 1 comment

Comments

@guidanoli
Copy link
Contributor

I'm developing a CLI, and would like for people to install it with pnpm add -g (and equivalents for other package managers). However, the HomePage.InstallPackage component only allows two types: init and add.

@spmoe
Copy link

spmoe commented Jul 29, 2024

To add a global installation option to your HomePage.InstallPackage component, you can modify the component to handle a new type, such as global, and then render the appropriate command based on this type. Here's an example of how you could update the component:

  1. Update the Component to Handle a New Type:
// HomePage/InstallPackage.tsx

import React from 'react';

interface InstallPackageProps {
  type: 'init' | 'add' | 'global';
  packageName: string;
}

const InstallPackage: React.FC<InstallPackageProps> = ({ type, packageName }) => {
  let command = '';

  switch (type) {
    case 'init':
      command = `pnpm init ${packageName}`;
      break;
    case 'add':
      command = `pnpm add ${packageName}`;
      break;
    case 'global':
      command = `pnpm add -g ${packageName}`;
      break;
    default:
      command = '';
  }

  return (
    <div>
      <code>{command}</code>
    </div>
  );
};

export default InstallPackage;
  1. Use the Updated Component with the New Type:
// Usage example
import React from 'react';
import InstallPackage from './HomePage/InstallPackage';

const MyComponent: React.FC = () => {
  return (
    <div>
      <h1>Install My CLI</h1>
      <InstallPackage type="global" packageName="my-cli-package" />
    </div>
  );
};

export default MyComponent;

This modification introduces a global type to the InstallPackage component, allowing it to generate the global installation command for your CLI. You can extend this further for other package managers like npm or yarn by adding additional cases in the switch statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants