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
5 changes: 1 addition & 4 deletions .github/workflows/cli-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ jobs:
zip_name: macos-arm64.zip
smoke_command: ./out/macos-arm64/anywaydata --help
bun_build_flags: --compile
defaults:
run:
working-directory: ./cli
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
Expand All @@ -56,7 +53,7 @@ jobs:
- name: build binary
shell: bash
run: |
bun build ./index.ts ${{ matrix.bun_build_flags }} --target=${{ matrix.bun_target }} --outfile "${{ github.workspace }}/${{ matrix.bin_relpath }}"
bun build ./apps/cli/src/bun-entry.js ${{ matrix.bun_build_flags }} --target=${{ matrix.bun_target }} --outfile "${{ github.workspace }}/${{ matrix.bin_relpath }}"
- name: smoke test binary
run: ${{ matrix.smoke_command }}
- name: package zip (windows)
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/codex-pr-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Codex PR Review

on:
workflow_dispatch:

permissions:
contents: read
pull-requests: write
issues: write

concurrency:
group: codex-pr-review-${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true

jobs:
codex-review:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Verify OpenAI key is configured
shell: bash
run: |
if [ -z "${{ secrets.OPENAI_API_KEY }}" ]; then
echo "OPENAI_API_KEY is not configured for this run."
exit 1
fi

- name: Run Codex PR review
uses: openai/codex-action@v1
with:
Comment thread
eviltester marked this conversation as resolved.
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
prompt: |
Review this pull request for:
- bugs and behavioral regressions
- security or reliability risks
- missing or weak tests
Keep feedback concise and actionable with file/line references.
22 changes: 22 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,31 @@ jobs:
- name: Install dependencies
run: npm ci

- name: CLI pack smoke test
shell: bash
run: |
set -euo pipefail
rm -rf .tmp-pack
mkdir -p .tmp-pack
CORE_TARBALL="$(npm pack --workspace packages/core --pack-destination ./.tmp-pack | tail -n 1)"
CLI_TARBALL="$(npm pack --workspace apps/cli --pack-destination ./.tmp-pack | tail -n 1)"
npm exec --yes \
--package "./.tmp-pack/${CORE_TARBALL}" \
--package "./.tmp-pack/${CLI_TARBALL}" \
anywaydata -- --help >/dev/null
echo "CLI npm pack smoke test passed with local core+cli tarballs: ${CORE_TARBALL}, ${CLI_TARBALL}"

- name: Build
run: npm run build --if-present

- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.2.10

- name: Bun CLI entry smoke test
run: bun run apps/cli/src/bun-entry.js --help

- name: Install Playwright browser
run: npx playwright install --with-deps chromium

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ coverage.txt
test_output.txt
playwright-report
test-results
.tmp
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ This repository now uses npm workspaces:

- `packages/core` -> shared generation engine (`@anywaydata/core`)
- `packages/core-ui` -> browser UI modules (`@anywaydata/core-ui`)
- `packages/cli` -> CLI wrapper (`@anywaydata/cli`)
- `apps/cli` -> npm CLI package (`@anywaydata/cli`)
- `apps/api` -> REST API (`@anywaydata/api`)
- `apps/mcp` -> MCP server (`@anywaydata/mcp`)

Expand All @@ -201,7 +201,7 @@ Run an individual workspace command:

## npm CLI Usage (`@anywaydata/cli`)

The npm CLI package is the workspace package `@anywaydata/cli` (separate from the Bun CLI in `cli/`).
The npm CLI package is the workspace app `apps/cli` (`@anywaydata/cli`), and Bun executable builds also use `apps/cli` as the source.

Install globally from npm:

Expand Down
162 changes: 162 additions & 0 deletions apps/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# AnyWayData CLI (`apps/cli`)

Unified CLI implementation for Node and Bun, backed by `@anywaydata/core`.

This workspace is the source of truth for:

- npm/npx CLI usage (`anywaydata`)
- Node runtime entrypoint (`src/node-entry.js`)
- Bun runtime entrypoint (`src/bun-entry.js`)
- Bun executable builds

## Quick Start

Install globally:

```bash
npm install -g @anywaydata/cli
```

Run with npx:

```bash
npx @anywaydata/cli --help
```

Run from repo with Node:

```bash
node apps/cli/src/node-entry.js --help
```

Run from repo with Bun:

```bash
bun run apps/cli/src/bun-entry.js --help
```

## Example Usage

Generate 3 rows from a spec file:

```bash
anywaydata generate -i exampleTestDataSpec.txt -n 3
```

Write to an output file:

```bash
anywaydata generate -i exampleTestDataSpec.txt -n 3 -o output.csv
```

Redirect stdout:

```bash
anywaydata generate -i exampleTestDataSpec.txt -n 3 > output.csv
```

Use included examples in this workspace:

```bash
anywaydata generate -i ./apps/cli/examples/company-literal.txt -n 3 -f csv
anywaydata generate -i ./apps/cli/examples/company.txt -n 3 -f csv
anywaydata generate -i ./apps/cli/examples/regex-field.txt -n 3 -f csv
```

## CLI Options

- `-i, --inputfile` input text spec path (required)
- `-n, --numberOfLines` row count (required, overridden to `1` by `--testMode`)
- `-f, --format` output format (e.g. `csv`, `json`, `jsonl`, `xml`, `sql`)
- `-o, --outputfile` optional output file path
- `-t, --testMode` generate one row and print diagnostics/example output
- `--show-progress` force progress logs on/off
- `--stream` enable stream mode when supported
- `--stream-threshold` auto-enable stream mode when rows >= threshold and output file is set (default `5000`)
- `--unsafe-faker-expressions` allow expression-style faker args (unsafe for untrusted input)

## Streaming Behavior

Streaming is currently supported for:

- `csv`
- `jsonl`

Other formats use buffered generation.

Examples:

```bash
anywaydata generate -i ./apps/cli/examples/company-literal.txt -n 100000 -f jsonl -o output.jsonl --stream
anywaydata generate -i ./apps/cli/examples/company-literal.txt -n 100000 -f csv -o output.csv --stream-threshold 1000
```

## Spec File Format

The test data spec format is two lines per field:

1. Column name
2. Rule/spec for that column

Example:

```text
Column Name 1
Data Value Spec for Column Name 1
Column Name 2
Data Value Spec for Column Name 2
```

### Literal Value Example

```text
Company
AnyWayData
```

### Faker Value Example

```text
Company
company.name
```

Faker API docs:

- https://fakerjs.dev/api/

### Regex Value Example

```text
Regex Generated Field
[A-Z]{3,6}[0-9]{0,6}
```

## Safe vs Unsafe Faker Expressions

CLI is safe-by-default. For untrusted specs, keep default behavior.

To allow expression-style faker arguments, opt in explicitly:

```bash
anywaydata generate -i input.txt -n 10 -f csv --unsafe-faker-expressions
```

## Build Bun Executables

Build a Bun executable from the shared entrypoint:

```bash
bun build ./apps/cli/src/bun-entry.js --compile --target=bun-linux-x64 --outfile ./out/linux-x64/anywaydata
```

Cross-platform targets follow the same pattern:

- `bun-windows-x64`
- `bun-linux-x64`
- `bun-linux-arm64`
- `bun-darwin-arm64`

See Bun executable docs:

- https://bun.sh/docs/bundler/executables
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions apps/cli/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
verbose: true,
testEnvironment: 'node',
transform: {
'^.+\\.js$': 'babel-jest',
},
testMatch: ['<rootDir>/src/tests/**/*.test.js'],
};
8 changes: 4 additions & 4 deletions packages/cli/package.json → apps/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@anywaydata/cli",
"version": "2.1.0",
"version": "0.1.0",
"type": "module",
"private": false,
"bin": {
"anywaydata": "src/index.js"
"anywaydata": "./src/node-entry.js"
},
"main": "./src/index.js",
"exports": {
Expand All @@ -17,8 +17,8 @@
"access": "public"
},
"scripts": {
"build": "node -e \"console.log('cli: no build step')\"",
"test": "node ./src/index.js --help"
"build": "node -e \"console.log('cli-next: no build step')\"",
"test": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js --config ./jest.config.cjs"
},
"dependencies": {
"@anywaydata/core": "^1.1.0",
Expand Down
7 changes: 7 additions & 0 deletions apps/cli/src/bun-entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bun
import { createBunPlatform, runCli } from './index.js';

const code = await runCli(process.argv, createBunPlatform());
if (code !== 0) {
process.exit(code);
}
70 changes: 70 additions & 0 deletions apps/cli/src/cli-options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { SUPPORTED_FORMATS } from '@anywaydata/core';

export function parseCliOptions(argvInput = process.argv) {
const parsed = yargs(hideBin(argvInput))
.usage('Usage: anywaydata generate -i input.txt -n 10 -f csv [-o output.txt]')
.command('generate', 'Generate test data from an input spec')
.option('i', { alias: 'inputfile', type: 'string', demandOption: true, describe: 'Text file with a data spec' })
.option('n', {
alias: 'numberOfLines',
type: 'number',
demandOption: true,
default: 1,
describe: 'Number of lines to generate',
})
.option('f', {
alias: 'format',
type: 'string',
default: 'csv',
describe: `Output format e.g. ${SUPPORTED_FORMATS.join(',')}`,
})
.option('o', { alias: 'outputfile', type: 'string', describe: 'Output file' })
.option('t', {
alias: 'testMode',
type: 'boolean',
default: false,
describe: 'Generate one line, report diagnostics and include example output',
})
.option('show-progress', {
type: 'boolean',
default: undefined,
describe: 'Show progress logs even when writing to file',
})
.option('stream', {
type: 'boolean',
default: false,
describe: 'Use streaming generation path when available (exporting CSV or JSONL)',
})
.option('stream-threshold', {
type: 'number',
default: 5000,
describe: 'Auto-enable stream mode when rows >= threshold and output file is provided',
})
.option('unsafe-faker-expressions', {
type: 'boolean',
default: false,
describe: 'Allow expression-style faker arguments (unsafe for untrusted input)',
})
.help('h')
.alias('h', 'help')
.parseSync();

const rowCount = parsed.testMode ? 1 : parsed.numberOfLines;
const streamThreshold = Number.isFinite(parsed.streamThreshold) ? Math.max(0, parsed.streamThreshold) : 5000;
const shouldStream = parsed.stream === true || (!!parsed.outputfile && rowCount >= streamThreshold);
const showProgress =
parsed.showProgress !== undefined ? parsed.showProgress === true : parsed.testMode || !parsed.outputfile;

return {
inputFile: parsed.inputfile,
outputFile: parsed.outputfile,
format: String(parsed.format || 'csv').toLowerCase(),
rowCount,
testMode: parsed.testMode === true,
showProgress,
shouldStream,
unsafeFakerExpressions: parsed['unsafe-faker-expressions'] === true,
};
}
Loading
Loading