npm package: @caresync/plugin-cli
Description: CLI tool for creating and managing CareSync plugins
Author: CareSync
Latest version: 1.0.13

# CareSync Plugin CLI

Command-line tool for creating and managing CareSync plugins.

## Installation

```bash
npm install -g @caresync/plugin-cli
```

Or use locally:

```bash
npm install @caresync/plugin-cli
npx caresync-plugin create my-plugin
```

## Usage

### Create a New Plugin

```bash
caresync-plugin create my-plugin
```

Interactive prompts will ask for:
- Plugin description
- Author name
- Plugin type (Backend Only / Frontend Only / Full Stack)

**Options:**
- `-t, --template <template>` - Skip prompts and use template (basic, backend-only, frontend-only, full-stack)
- `-y, --yes` - Use defaults for all prompts

**Examples:**
```bash
# Interactive creation
caresync-plugin create patient-reminder

# Quick creation with template
caresync-plugin create patient-reminder -t full-stack

# Skip all prompts
caresync-plugin create patient-reminder -y
```

### Build Plugin Package

```bash
caresync-plugin build
```

Creates a ZIP file ready for deployment.

**Options:**
- `-o, --output <path>` - Output directory (default: `./dist`)

**Example:**
```bash
caresync-plugin build -o ./packages
```

### Development Server (Coming Soon)

```bash
caresync-plugin dev
```

Starts a development server with hot reload.

## Generated Structure

### Backend Only Plugin

```
my-plugin/
├── manifest.json
├── README.md
├── .gitignore
├── backend/
│   ├── index.js
│   ├── routes.js
│   ├── package.json
│   └── hooks/
│       └── onPatientCreated.js
└── assets/
```

### Frontend Only Plugin

```
my-plugin/
├── manifest.json
├── README.md
├── .gitignore
├── frontend/
│   ├── index.js
│   ├── package.json
│   ├── components/
│   └── pages/
│       └── myPluginPage.tsx
└── assets/
```

### Full Stack Plugin

```
my-plugin/
├── manifest.json
├── README.md
├── .gitignore
├── backend/
│   ├── index.js
│   ├── routes.js
│   ├── package.json
│   └── hooks/
├── frontend/
│   ├── index.js
│   ├── package.json
│   ├── components/
│   │   └── myPluginWidget.tsx
│   └── pages/
│       └── myPluginPage.tsx
└── assets/
```

## What Gets Generated

### Backend Files

- **index.js**: Main plugin class with SDK integration
- **routes.js**: API endpoint definitions
- **hooks/onPatientCreated.js**: Example event hook
- **package.json**: Backend dependencies

### Frontend Files

- **index.js**: Component exports
- **components/**: React components (TypeScript)
- **pages/**: Full page components
- **package.json**: Frontend dependencies

### Configuration Files

- **manifest.json**: Plugin manifest with all required fields
- **README.md**: Documentation template
- **.gitignore**: Git ignore rules

## Examples

### Create a Backend-Only Plugin

```bash
caresync-plugin create api-integration -t backend-only
cd api-integration
# Edit backend/index.js and backend/routes.js
caresync-plugin build
```

### Create a Full-Stack Plugin

```bash
caresync-plugin create patient-dashboard -t full-stack
cd patient-dashboard
# Edit backend and frontend files
caresync-plugin build
```

## Next Steps

After creating your plugin:

1. **Install dependencies:**
   ```bash
   cd backend && npm install
   cd ../frontend && npm install
   ```

2. **Edit your code:**
   - Backend: Edit `backend/index.js` and `backend/routes.js`
   - Frontend: Edit `frontend/components/` and `frontend/pages/`

3. **Build package:**
   ```bash
   caresync-plugin build
   ```

4. **Upload to CareSync:**
   - Upload the generated ZIP file through the developer portal
   - Install and activate for your tenant

## Troubleshooting

### "command not found: caresync-plugin"

Make sure you installed it globally:
```bash
npm install -g @caresync/plugin-cli
```

Or use npx:
```bash
npx caresync-plugin create my-plugin
```

### Build fails with "zip command not found"

Install zip utility:
- **macOS**: `brew install zip`
- **Linux**: `sudo apt-get install zip` or `sudo yum install zip`
- **Windows**: Use 7-Zip or WinRAR, or manually create ZIP from the temp directory

## Contributing

This is a development tool. To contribute:

1. Make changes to the CLI code
2. Test locally: `node bin/caresync-plugin.js create test-plugin`
3. Submit improvements

## License

MIT