Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# wp-deployer Changelog

## 2.1.0 - 2026-08-05
- Added: standalone `wp-deployer.json` config file support
- Added: `--config <path>` flag to use a custom config file

## 2.0.1 - 2026-07-09
- Fixed: clean SVN checkout directory before each run

Expand Down
11 changes: 6 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ Every task must end with:

### Pipeline flow

1. `index.js` — Entry point. Parses CLI flags (`--assets`, `--dry-run`), reads `package.json` from CWD, calls `resolveSettings()`, then `runPreflightSync()`, then runs steps in sequence. Errors from any step abort the pipeline.
2. `lib/config.js` — Resolves the `wpDeployer` key from the project's `package.json`, applies defaults, normalises paths, derives the SVN URL, and validates via `lib/config-schema.js`. Returns `{ settings, error, errorMessage }` — never throws.
3. `lib/config-schema.js` — Validates merged settings against `lib/schemas/config.schema.json` using Ajv. Maps AJV errors to stable error codes consumed by `index.js`.
4. `lib/preflight.js` — Synchronous environment checks: `svn` and `awk` on PATH, build/assets dirs exist and are non-empty. Throws `DeployError` on failure.
5. `lib/steps.js` — Step factories. `createPluginSteps()` and `createThemeSteps()` each return an array of `async (settings) => settings` functions. Steps are composed, not inherited. Each step receives the live settings object and returns it (possibly mutated). `dryRun` skips commit steps.
1. `index.js` — Entry point. Parses CLI flags (`--assets`, `--dry-run`, `--config`), reads `package.json` from CWD, calls `loadConfigSource()` then `resolveSettings()`, then `runPreflightSync()`, then runs steps in sequence. Errors from any step abort the pipeline.
2. `lib/config-source.js` — Locates the wpDeployer settings object: `package.json#wpDeployer`, a standalone `wp-deployer.json` in CWD, or an explicit `--config` path. The first two are mutually exclusive — if both exist, returns an error instead of picking one. `--config` bypasses both. Returns `{ wpDeployerConfig, error, errorMessage }` — never throws.
3. `lib/config.js` — `resolveSettings(pkg, wpDeployerOverride?)` merges the wpDeployer config (from `pkg.wpDeployer` by default, or the override from `loadConfigSource()`) with defaults, normalises paths, derives the SVN URL, and validates via `lib/config-schema.js`. Returns `{ settings, error, errorMessage }` — never throws.
4. `lib/config-schema.js` — Validates merged settings against `lib/schemas/config.schema.json` using Ajv. Maps AJV errors to stable error codes consumed by `index.js`.
5. `lib/preflight.js` — Synchronous environment checks: `svn` and `awk` on PATH, build/assets dirs exist and are non-empty. Throws `DeployError` on failure.
6. `lib/steps.js` — Step factories. `createPluginSteps()` and `createThemeSteps()` each return an array of `async (settings) => settings` functions. Steps are composed, not inherited. Each step receives the live settings object and returns it (possibly mutated). `dryRun` skips commit steps.

### Plugin vs theme deploy

Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ npm install --save-dev wp-deployer

## Usage

Run from your project root (the directory that contains `package.json` with your `wpDeployer` config):
Run from your project root (the directory that contains your config — see [Config file](#config-file)):

```sh
npx wp-deployer
Expand All @@ -25,6 +25,7 @@ npx wp-deployer --help
npx wp-deployer --version
npx wp-deployer --assets
npx wp-deployer --dry-run
npx wp-deployer --config path/to/config.json
```

Use `--assets` when you only want to push the assets directory (e.g. screenshots, banner) to WordPress.org and skip trunk and tag deployment.
Expand All @@ -37,6 +38,16 @@ Or add a script to `package.json` and run it:
npm run wpdeploy
```

## Config file

Settings can come from one of three places:

* **`wpDeployer`** key in `package.json`.
* **`wp-deployer.json`** in the project root — same shape as the `wpDeployer` object, as a standalone file.
* **`--config <path>`** — an explicit path to a config file, same shape.

`package.json#wpDeployer` and `wp-deployer.json` are **mutually exclusive**. If both exist, wp-deployer exits with an error rather than guessing which one to use — remove one. `--config` bypasses both and is used as-is.

## SVN authentication

wp-deployer is intended for **deploying from your own computer** to WordPress.org SVN. It does **not** store or read an SVN password.
Expand Down
19 changes: 16 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* wp-deployer
*
* Deploys a WordPress plugin or theme to the WordPress.org SVN repo.
* Config is read from package.json under the "wpDeployer" key.
* Config is read from package.json under the "wpDeployer" key, a standalone
* wp-deployer.json (mutually exclusive with the package.json key), or an
* explicit --config path.
* Run from the project root (where package.json and wpDeployer config live).
*
* Exit codes: 0 success, 1 config/validation/preflight, 2 deploy failure, 130 SIGINT.
Expand All @@ -18,6 +20,7 @@ import minimist from 'minimist'
import { exec as execCb } from 'child_process'
import { promisify } from 'util'
import { resolveSettings } from './lib/config.js'
import { loadConfigSource } from './lib/config-source.js'
import { createPluginSteps, createThemeSteps } from './lib/steps.js'
import { runPreflightSync } from './lib/preflight.js'
import { DeployError } from './lib/deploy-error.js'
Expand All @@ -29,19 +32,22 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))

const argv = minimist(process.argv.slice(2), {
boolean: ['help', 'version', 'assets', 'dry-run'],
string: ['config'],
alias: { h: 'help', v: 'version' }
})

function printHelp () {
console.log(`Usage: wp-deployer [options]

Deploy a WordPress plugin or theme to WordPress.org SVN using wpDeployer in package.json.
Deploy a WordPress plugin or theme to WordPress.org SVN using wpDeployer config
from package.json, wp-deployer.json, or --config.

Options:
--help, -h Show this message
--version, -v Print wp-deployer version
--assets Deploy only the assets directory (plugin only; skips trunk and tag)
--dry-run Prepare working copy and local SVN changes only; no commit or remote tag copy
--config <path> Use this config file instead of package.json / wp-deployer.json
`)
}

Expand Down Expand Up @@ -78,7 +84,14 @@ const wpDeployer = async () => {
}
console.log(chalk.cyan('Processing...'))

let { settings, error, errorMessage } = resolveSettings(pkg)
const configPath = argv.config
const sourceResult = loadConfigSource(pkg, { fs, cwd: process.cwd(), configPath })
if (sourceResult.error) {
console.error(chalk.red(sourceResult.errorMessage))
return EXIT_CONFIG
}

let { settings, error, errorMessage } = resolveSettings(pkg, sourceResult.wpDeployerConfig)
if (error === 'invalid_slug') {
console.error(chalk.red(`Invalid slug: ${errorMessage}`))
return EXIT_CONFIG
Expand Down
60 changes: 60 additions & 0 deletions lib/config-source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Locates the wpDeployer settings object: package.json#wpDeployer,
* a standalone wp-deployer.json, or an explicit --config path.
* package.json#wpDeployer and wp-deployer.json are mutually exclusive.
*/

import path from 'node:path'

export const CONFIG_FILE_NAME = 'wp-deployer.json'

/**
* @param {object} pkg - Parsed package.json
* @param {{ fs: import('fs-extra').default, cwd: string, configPath?: string }} io
* @returns {{ wpDeployerConfig: object, error: null } | { wpDeployerConfig: null, error: 'duplicate_config' | 'config_file_not_found' | 'invalid_config_json', errorMessage: string }}
*/
export function loadConfigSource (pkg, { fs, cwd, configPath }) {
if (configPath) {
return readConfigFile(fs, path.resolve(cwd, configPath))
}

const pkgHasWpDeployer = Object.prototype.hasOwnProperty.call(pkg, 'wpDeployer')
const defaultConfigFile = path.join(cwd, CONFIG_FILE_NAME)
const defaultConfigExists = fs.existsSync(defaultConfigFile)

if (defaultConfigExists && pkgHasWpDeployer) {
return {
wpDeployerConfig: null,
error: 'duplicate_config',
errorMessage: `Config found in both package.json#wpDeployer and ${CONFIG_FILE_NAME}. Remove one — refusing to guess which is authoritative.`
}
}

if (defaultConfigExists) {
return readConfigFile(fs, defaultConfigFile)
}

return { wpDeployerConfig: pkgHasWpDeployer ? pkg.wpDeployer : {}, error: null }
}

function readConfigFile (fs, filePath) {
if (!fs.existsSync(filePath)) {
return {
wpDeployerConfig: null,
error: 'config_file_not_found',
errorMessage: `Config file not found: ${filePath}`
}
}

const raw = fs.readFileSync(filePath, 'utf8')

try {
return { wpDeployerConfig: JSON.parse(raw), error: null }
} catch (e) {
return {
wpDeployerConfig: null,
error: 'invalid_config_json',
errorMessage: `Invalid JSON in config file ${filePath}: ${e.message}`
}
}
}
11 changes: 8 additions & 3 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ export function getDefaults (pkg) {
}

/**
* Resolve settings from package.json. Does not exit; returns an error key if validation fails.
* Resolve settings from package.json (or an explicit wpDeployer config, e.g. from
* a standalone wp-deployer.json / --config file). Does not exit; returns an error
* key if validation fails.
* @param {object} pkg - Parsed package.json (must have name, version)
* @param {object} [wpDeployerOverride] - wpDeployer settings to use instead of pkg.wpDeployer
* @returns {{ settings: object, error: null | 'invalid_slug' | 'username_required' | 'invalid_username' | 'theme_earlier_version_required' | 'invalid_config' | 'invalid_svn_url' | 'invalid_new_version' | 'invalid_earlier_version', errorMessage?: string }}
*/
export function resolveSettings (pkg) {
export function resolveSettings (pkg, wpDeployerOverride) {
const defaults = getDefaults(pkg)
const wpDeployer = Object.prototype.hasOwnProperty.call(pkg, 'wpDeployer') ? pkg.wpDeployer : {}
const wpDeployer = wpDeployerOverride !== undefined
? wpDeployerOverride
: (Object.prototype.hasOwnProperty.call(pkg, 'wpDeployer') ? pkg.wpDeployer : {})
let settings = { ...defaults, ...wpDeployer }

if (Object.prototype.hasOwnProperty.call(wpDeployer, 'url')) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-deployer",
"version": "2.0.1",
"version": "2.1.0",
"description": "Deploy WordPress plugin and theme to the WordPress.org repo.",
"keywords": [
"WordPress",
Expand Down
6 changes: 6 additions & 0 deletions test/cli-flags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ describe('CLI flags', () => {
assert.strictEqual(r.status, 0, r.stderr)
assert.match(r.stdout, /--dry-run\b/)
})

it('--help documents --config', () => {
const r = spawnSync(process.execPath, [indexJs, '--help'], { encoding: 'utf8' })
assert.strictEqual(r.status, 0, r.stderr)
assert.match(r.stdout, /--config\b/)
})
})
78 changes: 78 additions & 0 deletions test/config-cli.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* End-to-end CLI tests for config source resolution (package.json#wpDeployer,
* wp-deployer.json, --config). Exits before any svn/preflight work runs.
*/

import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { mkdtempSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { spawnSync } from 'node:child_process'
import { describe, it } from 'node:test'
import assert from 'node:assert'

const __dirname = path.dirname(fileURLToPath(import.meta.url))
const indexJs = path.join(__dirname, '..', 'index.js')

function makeProjectDir () {
return mkdtempSync(path.join(tmpdir(), 'wpdep-config-cli-'))
}

function writePkg (dir, pkg) {
writeFileSync(path.join(dir, 'package.json'), JSON.stringify(pkg))
}

function run (args, cwd) {
return spawnSync(process.execPath, [indexJs, ...args], { encoding: 'utf8', cwd })
}

describe('config source CLI resolution', () => {
it('fails loudly when both package.json#wpDeployer and wp-deployer.json exist', () => {
const dir = makeProjectDir()
writePkg(dir, { name: 'dup-pkg', version: '1.0.0', wpDeployer: { username: 'jane' } })
writeFileSync(path.join(dir, 'wp-deployer.json'), JSON.stringify({ username: 'bob' }))

const r = run([], dir)
assert.strictEqual(r.status, 1, r.stderr)
assert.match(r.stderr, /both package\.json#wpDeployer and wp-deployer\.json/)
})

it('reads settings from wp-deployer.json when package.json has no wpDeployer key', () => {
const dir = makeProjectDir()
writePkg(dir, { name: 'standalone-pkg', version: '1.0.0' })
writeFileSync(path.join(dir, 'wp-deployer.json'), JSON.stringify({}))

const r = run([], dir)
assert.strictEqual(r.status, 1, r.stderr)
assert.match(r.stderr, /Username is required/)
})

it('--config points at a custom file and is used over package.json/wp-deployer.json', () => {
const dir = makeProjectDir()
writePkg(dir, { name: 'custom-pkg', version: '1.0.0', wpDeployer: { username: 'ignored' } })
writeFileSync(path.join(dir, 'my-config.json'), JSON.stringify({}))

const r = run(['--config', 'my-config.json'], dir)
assert.strictEqual(r.status, 1, r.stderr)
assert.match(r.stderr, /Username is required/)
})

it('--config with a missing file fails loudly', () => {
const dir = makeProjectDir()
writePkg(dir, { name: 'missing-config-pkg', version: '1.0.0' })

const r = run(['--config', 'nope.json'], dir)
assert.strictEqual(r.status, 1, r.stderr)
assert.match(r.stderr, /Config file not found/)
})

it('--config with malformed JSON fails loudly', () => {
const dir = makeProjectDir()
writePkg(dir, { name: 'bad-json-pkg', version: '1.0.0' })
writeFileSync(path.join(dir, 'bad.json'), '{ not valid')

const r = run(['--config', 'bad.json'], dir)
assert.strictEqual(r.status, 1, r.stderr)
assert.match(r.stderr, /Invalid JSON/)
})
})
Loading