# Publish Workflow

## Goal

Publish a prepared npm package directory to:

```text
http://ires.58corp.com/repository/npm/
```

## Recommended Scripts

Environment check:

```bash
node scripts/check-58npm-env.mjs
```

High-level publish orchestrator:

```bash
node scripts/publish-58npm-package.mjs --package-dir <dir> --dry-run
node scripts/publish-58npm-package.mjs --package-dir <dir>
```

Low-level publish script:

```bash
node scripts/publish-58npm-package-core.mjs --package-dir <dir> --dry-run
node scripts/publish-58npm-package-core.mjs --package-dir <dir>
```

## Examples

Publish a bundle:

```bash
node scripts/publish-58npm-package.mjs \
  --package-dir dist/my-bundle \
  --prepare-cmd "npm run build:bundle" \
  --dry-run

node scripts/publish-58npm-package.mjs \
  --package-dir dist/my-bundle \
  --prepare-cmd "npm run build:bundle"
```

If the package is already prepared, skip the prepare step:

```bash
node scripts/publish-58npm-package.mjs --package-dir dist/my-bundle --dry-run
node scripts/publish-58npm-package.mjs --package-dir dist/my-bundle
```

## Script Responsibilities

`check-58npm-env.mjs`:

1. Check `NPM_58_*` environment variables
2. Report missing auth inputs
3. Optionally run `npm whoami`

`publish-58npm-package.mjs`:

1. Optionally run the bundle or build command
2. Check whether the git worktree is clean
3. Create a temporary `.npmrc`
4. Run `npm whoami` as an auth preflight
5. Call the core publish script

`publish-58npm-package-core.mjs`:

1. Read `package.json` from the target directory
2. Validate `name`, `version`, and `private`
3. Run `npm pack --dry-run`
4. Run `npm publish`
5. Run `npm view <pkg> version` after a real publish
6. Clean up temporary auth files
