π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat: cli
Nevo David0c0255406447
diff --git a/apps/cli/HOW_TO_RUN.md b/apps/cli/HOW_TO_RUN.mdnew file mode 100644index 000000000..ef003c3b5--- /dev/null+++ b/apps/cli/HOW_TO_RUN.md@@ -0,0 +1,300 @@+# How to Run the Postiz CLI++There are several ways to run the CLI, depending on your needs.++## Option 1: Direct Execution (Quick Test) β‘++The built file at `apps/cli/dist/index.js` is already executable!++```bash+# From the monorepo root+node apps/cli/dist/index.js --help++# Or run it directly (it has a shebang)+./apps/cli/dist/index.js --help++# Example command+export POSTIZ_API_KEY=your_key+node apps/cli/dist/index.js posts:list+```++## Option 2: Link Globally (Recommended for Development) π++This creates a global `postiz` command you can use anywhere:++```bash+# From the monorepo root+cd apps/cli+pnpm link --global++# Now you can use it anywhere!+postiz --help+postiz posts:list+postiz posts:create -c "Hello!" -i "twitter-123"++# To unlink later+pnpm unlink --global+```++**After linking, you can use `postiz` from any directory!**++## Option 3: Use pnpm Filter (From Root) π¦++```bash+# From the monorepo root+pnpm --filter postiz start -- --help+pnpm --filter postiz start -- posts:list+pnpm --filter postiz start -- posts:create -c "Hello" -i "twitter-123"+```++## Option 4: Use npm/npx (After Publishing) π++Once published to npm:++```bash+# Install globally+npm install -g postiz++# Or use with npx (no install)+npx postiz --help+npx postiz posts:list+```++## Quick Setup Guide++### Step 1: Build the CLI++```bash+# From monorepo root+pnpm run build:cli+```++### Step 2: Set Your API Key++```bash+export POSTIZ_API_KEY=your_api_key_here++# To make it permanent, add to your shell profile:+echo 'export POSTIZ_API_KEY=your_api_key' >> ~/.bashrc+# or ~/.zshrc if you use zsh+```++### Step 3: Choose Your Method++**For quick testing:**+```bash+node apps/cli/dist/index.js --help+```++**For regular use (recommended):**+```bash+cd apps/cli+pnpm link --global+postiz --help+```++## Troubleshooting++### "Command not found: postiz"++If you linked globally but still get this error:++```bash+# Check if it's linked+which postiz++# If not found, try linking again+cd apps/cli+pnpm link --global++# Or check your PATH+echo $PATH+```++### "POSTIZ_API_KEY is not set"++```bash+export POSTIZ_API_KEY=your_key++# Verify it's set+echo $POSTIZ_API_KEY+```++### Permission Denied++If you get permission errors:++```bash+# Make the file executable+chmod +x apps/cli/dist/index.js++# Then try again+./apps/cli/dist/index.js --help+```++### Rebuild After Changes++After making code changes, rebuild:++```bash+pnpm run build:cli+```++If you linked globally, the changes will be reflected immediately (no need to re-link).++## Testing the CLI++### Test Help Command++```bash+postiz --help+postiz posts:create --help+```++### Test with Sample Command (requires API key)++```bash+export POSTIZ_API_KEY=your_key++# List integrations+postiz integrations:list++# Create a test post+postiz posts:create \+ -c "Test post from CLI" \+ -i "your-integration-id"+```++## Development Workflow++### 1. Make Changes++Edit files in `apps/cli/src/`++### 2. Rebuild++```bash+pnpm run build:cli+```++### 3. Test++```bash+# If linked globally+postiz --help++# Or direct execution+node apps/cli/dist/index.js --help+```++### 4. Watch Mode (Auto-rebuild)++```bash+# From apps/cli directory+pnpm run dev++# In another terminal, test your changes+postiz --help+```++## Environment Variables++### Required++- `POSTIZ_API_KEY` - Your Postiz API key (required for all operations)++### Optional++- `POSTIZ_API_URL` - Custom API endpoint (default: `https://api.postiz.com`)++### Setting Environment Variables++**Temporary (current session):**+```bash+export POSTIZ_API_KEY=your_key+export POSTIZ_API_URL=https://custom-api.com+```++**Permanent (add to shell profile):**+```bash+# For bash+echo 'export POSTIZ_API_KEY=your_key' >> ~/.bashrc+source ~/.bashrc++# For zsh+echo 'export POSTIZ_API_KEY=your_key' >> ~/.zshrc+source ~/.zshrc+```++## Using Aliases++Create a convenient alias:++```bash+# Add to ~/.bashrc or ~/.zshrc+alias pz='postiz'++# Now you can use+pz posts:list+pz posts:create -c "Quick post" -i "twitter-123"+```++## Production Deployment++### Publish to npm++```bash+# From monorepo root+pnpm run publish-cli++# Or from apps/cli+cd apps/cli+pnpm run publish+```++### Install from npm++```bash+# Global install+npm install -g postiz++# Project-specific+npm install postiz+npx postiz --help+```++## Summary of Methods++| Method | Command | Use Case |+|--------|---------|----------|+| **Direct Node** | `node apps/cli/dist/index.js` | Quick testing, no installation |+| **Direct Execution** | `./apps/cli/dist/index.js` | Same as above, slightly shorter |+| **Global Link** | `postiz` (after `pnpm link --global`) | **Recommended** for development |+| **pnpm Filter** | `pnpm --filter postiz start --` | From monorepo root |+| **npm Global** | `postiz` (after `npm i -g postiz`) | After publishing to npm |+| **npx** | `npx postiz` | One-off usage without installing |++## Recommended Setup++For the best development experience:++```bash+# 1. Build+pnpm run build:cli++# 2. Link globally+cd apps/cli+pnpm link --global++# 3. Set API key+export POSTIZ_API_KEY=your_key++# 4. Test+postiz --help+postiz integrations:list++# 5. Start using!+postiz posts:create -c "My first post" -i "twitter-123"+```++Now you can use `postiz` from anywhere! πdiff --git a/apps/cli/PUBLISHING.md b/apps/cli/PUBLISHING.mdnew file mode 100644index 000000000..5c4d5d348--- /dev/null+++ b/apps/cli/PUBLISHING.md@@ -0,0 +1,377 @@+# Publishing the Postiz CLI to npm++## Quick Publish (Current Name: "postiz")++```bash+# From apps/cli directory+pnpm run build+pnpm publish --access public+```++Then users can install:+```bash+npm install -g postiz+# or+pnpm install -g postiz++# And use:+postiz --help+```++## Publishing with a Different Package Name++If you want to publish as a different npm package name (e.g., "agent-postiz"):++### 1. Change Package Name++Edit `apps/cli/package.json`:++```json+{+ "name": "agent-postiz", // β Changed package name+ "version": "1.0.0",+ "bin": {+ "postiz": "./dist/index.js" // β Keep command name!+ }+}+```++**Important:** The `bin` field determines the command name, NOT the package name!++### 2. Publish++```bash+cd apps/cli+pnpm run build+pnpm publish --access public+```++### 3. Users Install++```bash+npm install -g agent-postiz+# or+pnpm install -g agent-postiz+```++### 4. Users Use++Even though the package is called "agent-postiz", the command is still:++```bash+postiz --help # β Command name from "bin" field+postiz posts:create -c "Hello!" -i "twitter-123"+```++## Package Name vs Command Name++| Field | Purpose | Example |+|-------|---------|---------|+| `"name"` | npm package name (what you install) | `"agent-postiz"` |+| `"bin"` | Command name (what you type) | `"postiz"` |++**Examples:**++1. **Same name:**+ ```json+ "name": "postiz",+ "bin": { "postiz": "./dist/index.js" }+ ```+ Install: `npm i -g postiz`+ Use: `postiz`++2. **Different names:**+ ```json+ "name": "agent-postiz",+ "bin": { "postiz": "./dist/index.js" }+ ```+ Install: `npm i -g agent-postiz`+ Use: `postiz`++3. **Multiple commands:**+ ```json+ "name": "agent-postiz",+ "bin": {+ "postiz": "./dist/index.js",+ "pz": "./dist/index.js"+ }+ ```+ Install: `npm i -g agent-postiz`+ Use: `postiz` or `pz`++## Publishing Checklist++### Before First Publish++- [ ] Verify package name is available on npm+ ```bash+ npm view postiz+ # If error "404 Not Found" - name is available!+ ```++- [ ] Update version if needed+ ```json+ "version": "1.0.0"+ ```++- [ ] Review files to include+ ```json+ "files": [+ "dist",+ "README.md",+ "SKILL.md"+ ]+ ```++- [ ] Build the package+ ```bash+ pnpm run build+ ```++- [ ] Test locally+ ```bash+ pnpm link --global+ postiz --help+ ```++### Publish to npm++```bash+# Login to npm (first time only)+npm login++# From apps/cli+pnpm run build+pnpm publish --access public++# Or use the root script+cd /path/to/monorepo/root+pnpm run publish-cli+```++### After Publishing++Verify it's published:+```bash+npm view postiz+# Should show your package info+```++Test installation:+```bash+npm install -g postiz+postiz --version+```++## Using from Monorepo Root++The root `package.json` already has:++```json+{+ "scripts": {+ "publish-cli": "pnpm run --filter ./apps/cli publish"+ }+}+```++So you can publish from the root:++```bash+# From monorepo root+pnpm run publish-cli+```++## Version Updates++### Patch Release (1.0.0 β 1.0.1)++```bash+cd apps/cli+npm version patch+pnpm publish --access public+```++### Minor Release (1.0.0 β 1.1.0)++```bash+cd apps/cli+npm version minor+pnpm publish --access public+```++### Major Release (1.0.0 β 2.0.0)++```bash+cd apps/cli+npm version major+pnpm publish --access public+```++## Scoped Packages++If you want to publish under an organization scope:++```json+{+ "name": "@yourorg/postiz",+ "bin": {+ "postiz": "./dist/index.js"+ }+}+```++Install:+```bash+npm install -g @yourorg/postiz+```++Use:+```bash+postiz --help+```++## Testing Before Publishing++### Test the Build++```bash+pnpm run build+node dist/index.js --help+```++### Test Linking++```bash+pnpm link --global+postiz --help+pnpm unlink --global+```++### Test Publishing (Dry Run)++```bash+npm publish --dry-run+# Shows what would be published+```++### Test with `npm pack`++```bash+npm pack+# Creates a .tgz file++# Test installing the tarball+npm install -g ./postiz-1.0.0.tgz+postiz --help+npm uninstall -g postiz+```++## Continuous Publishing++### Using GitHub Actions++Create `.github/workflows/publish-cli.yml`:++```yaml+name: Publish CLI to npm++on:+ push:+ tags:+ - 'cli-v*'++jobs:+ publish:+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v3+ - uses: pnpm/action-setup@v2+ - uses: actions/setup-node@v3+ with:+ node-version: '20'+ registry-url: 'https://registry.npmjs.org'++ - run: pnpm install+ - run: pnpm run build:cli++ - name: Publish to npm+ run: pnpm --filter ./apps/cli publish --access public+ env:+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}+```++Then publish with:+```bash+git tag cli-v1.0.0+git push origin cli-v1.0.0+```++## Common Issues++### "You do not have permission to publish"++- Make sure you're logged in: `npm login`+- Check package name isn't taken: `npm view postiz`+- If scoped, ensure org access: `npm org ls yourorg`++### "Package name too similar to existing package"++- Choose a more unique name+- Or use a scoped package: `@yourorg/postiz`++### "Missing required files"++- Check `"files"` field in package.json+- Run `npm pack` to see what would be included+- Make sure `dist/` exists and is built++### Command not found after install++- Check `"bin"` field is correct+- Ensure `dist/index.js` has shebang: `#!/usr/bin/env node`+- Try reinstalling: `npm uninstall -g postiz && npm install -g postiz`++## Recommended Names++If "postiz" is taken, consider:++- `@postiz/cli`+- `postiz-cli`+- `postiz-agent`+- `agent-postiz`+- `@yourorg/postiz`++Remember: The package name is just for installation. The command can still be `postiz`!++## Summary++β Current setup works perfectly!+β `bin` field defines the command name+β `name` field defines the npm package name+β They can be different!++**To publish now:**++```bash+cd apps/cli+pnpm run build+pnpm publish --access public+```++**Users install:**++```bash+npm install -g postiz+# or+pnpm install -g postiz+```++**Users use:**++```bash+postiz --help+postiz posts:create -c "Hello!" -i "twitter-123"+```++π **Ready to publish!**