# create-three-blocks-starter

Private CLI to scaffold a new project from the Three Blocks starter.

## Usage

Authenticate to the private registry first (one time per project):

```bash
# Using pnpm (recommended - no warnings)
npx -y three-blocks-login@latest@latest --mode project --scope @three-blocks --channel stable

# Using npx (may show harmless npm config warnings)
npx -y three-blocks-login@latest --mode project --scope @three-blocks --channel stable
```

> **Note:** If you see npm warnings about unknown env configs, use `pnpm dlx` instead of `npx`, or see [three-blocks-login NPM warnings fix](https://www.npmjs.com/package/three-blocks-login).

Then scaffold a new app:

```bash
npm create @three-blocks/starter@latest my-app
# or
pnpm dlx create-three-blocks-starter my-app
```

Next steps:

```bash
cd my-app
pnpm i
pnpm dev
```

## CI/CD & Vercel Setup

The CLI now automatically generates the correct setup, but if you need to configure it manually:

### Quick Setup (3 steps)

1. **Commit `.npmrc`** to your repository (generated automatically by create-three-blocks-starter):
   ```
   @three-blocks:registry=https://three-blocks-196905988268.d.codeartifact.ap-northeast-1.amazonaws.com/npm/core/
   ```

2. **Preinstall script** (added automatically by create-three-blocks-starter):
   ```json
   {
     "scripts": {
       "preinstall": "npx -y three-blocks-login@latest"
     }
   }
   ```

3. **Set environment variable** in your CI/CD platform:
   - **Vercel**: Project Settings → Environment Variables → Add `THREE_BLOCKS_SECRET_KEY`
   - **GitHub Actions**: Repository Settings → Secrets → Add `THREE_BLOCKS_SECRET_KEY`
   - **Other CI**: Add `THREE_BLOCKS_SECRET_KEY` secret with your license key

### How It Works

- Committed `.npmrc` tells pnpm WHERE to find packages (no auth needed yet)
- Preinstall script fetches a short-lived token and adds it to `.npmrc`
- This solves pnpm's timing issue (it resolves packages before running preinstall)

## Development (monorepo)

- The CLI pulls the template from `packages/three-blocks-starter/` during `prepack`.
- To sync locally without publishing:

```bash
pnpm --filter create-three-blocks-starter run dev:sync
```

## Publish

```bash
npx -y three-blocks-login@latest --mode project --scope @three-blocks
pnpm --filter create-three-blocks-starter publish --access restricted
```
