# How To Package And Run Locally

This guide describes how to test `wikied` as an installable CLI package without publishing it to npm.

## Prerequisites

* Node.js.
* npm.
* Project dependencies installed with `npm install`.

## Clean Build And Pack

The repository includes a PowerShell helper:

```powershell
powershell -ExecutionPolicy Bypass -File scripts/package-local.ps1
```

The script:

* Deletes `dist`.
* Deletes old `wikied-*.tgz` tarballs.
* Runs `npm run build`.
* Runs `npm pack`.
* Prints the exact `npx --package` command for the new tarball.

## Clean Build, Pack, And Launch

```powershell
powershell -ExecutionPolicy Bypass -File scripts/package-local.ps1 -Run
```

Open a specific directory after packing:

```powershell
powershell -ExecutionPolicy Bypass -File scripts/package-local.ps1 -Run -OpenPath docs
```

## Manual Build And Pack

```powershell
Remove-Item -Recurse -Force dist -ErrorAction SilentlyContinue
Remove-Item -Force wikied-*.tgz -ErrorAction SilentlyContinue
npm run build
npm pack
```

This creates a package file such as:

```text
wikied-0.8.7.tgz
```

## Run The Tarball With Npx On Windows

From any directory you want to edit:

```powershell
npx --yes --package "C:\Projects\learning\site-editor\wikied-0.8.7.tgz" wikied
```

To open a specific directory:

```powershell
npx --yes --package "C:\Projects\learning\site-editor\wikied-0.8.7.tgz" wikied docs
```

Use the actual tarball path and version produced by `npm pack`.

The explicit `--package` form is the safest Windows command because it tells npm which package to install and which binary, `wikied`, to execute.

Do not use this shorthand on Windows:

```powershell
npx C:\Projects\learning\site-editor\wikied-0.8.7.tgz
```

That form can resolve the tarball without launching the `wikied` binary.

## Test From A Temporary Directory

Create a small fixture outside the repository:

```powershell
mkdir C:\tmp\wikied-smoke
cd C:\tmp\wikied-smoke
Set-Content -Path README.md -Value "# Local Smoke"
npx --yes --package "C:\Projects\learning\site-editor\wikied-0.8.7.tgz" wikied
```

Verify that:

* The CLI prints a localhost URL.
* The browser loads the editor.
* `README.md` appears in the file tree.
* Editing and saving `README.md` updates the file on disk.

## Alternative: Use Npm Link

For repeated local testing while developing:

```powershell
npm link
```

Then run from another directory:

```powershell
wikied
```

When finished, remove the link:

```powershell
npm unlink -g wikied
```

Use `npm pack` for final pre-publish checks because it validates the actual files included in the package.
