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
59 changes: 47 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ npm install -g @burgan-tech/vnext-workflow-cli
npm install @burgan-tech/vnext-workflow-cli
```

After installation, you can use the CLI with:
After installation, you can use the CLI with any of these aliases:
```bash
wf --version
wf check
wf --version # short alias
vnext --version # alternative alias (recommended for Windows)
workflow --version # full name
```

### Install from Source
Expand Down Expand Up @@ -118,6 +119,8 @@ wf check

**Note:** The CLI automatically uses the current working directory as the project root. Just `cd` into your project folder before running commands.

> **Tip:** All examples use `wf` but you can also use `vnext` or `workflow` interchangeably. The `vnext` alias is recommended on Windows where `wf` may conflict with existing system commands.

### Basic Usage

```bash
Expand Down Expand Up @@ -420,18 +423,20 @@ wf csx

### 6. Multidomain Workflow
```bash
# Add domains
# Add domains (one-time setup)
wf domain add domain-a --API_BASE_URL http://localhost:4201 --DB_NAME vNext_DomainA
wf domain add domain-b --API_BASE_URL http://localhost:4221 --DB_NAME vNext_DomainB

# Work on Domain A
wf domain use domain-a
wf check
wf update
# Option A: Auto-switch via vnext.config.json (recommended)
# Just cd into the project - domain profile switches automatically
cd ~/projects/domain-a-app # vnext.config.json has "domain": "domain-a"
wf update # auto-switches to domain-a profile

# Switch to Domain B - config is applied automatically
wf domain use domain-b
wf check
cd ~/projects/domain-b-app # vnext.config.json has "domain": "domain-b"
wf update # auto-switches to domain-b profile

# Option B: Manual switch (still works)
wf domain use domain-a
wf update

# See all domains
Expand All @@ -457,6 +462,35 @@ wf domain list

The CLI supports managing multiple domain configurations. Each domain has its own `API_BASE_URL`, `DB_NAME`, and other settings. Switch between domains with a single command.

### Auto Domain Resolution

When you run any command inside a vNext workspace that contains a `vnext.config.json`, the CLI **automatically** switches to the matching domain profile based on the `domain` field in the config file. This eliminates the need to manually run `wf domain use <name>` every time you switch between projects.

**How it works:**
1. Before each command (except `wf domain`), the CLI checks if `vnext.config.json` exists in the current directory.
2. If found, it reads the `domain` field and looks for a matching CLI domain profile (`DOMAINS[].DOMAIN_NAME`).
3. If a match is found and it differs from the current active domain, it silently switches and shows a dim log message:
```
[auto] Domain switched to "onboarding" (from vnext.config.json)
```
4. If no `vnext.config.json` is found or no matching profile exists, the current active domain is kept (no error).

**Example:** You have two projects and two domain profiles:
```bash
# Add domain profiles once
wf domain add core --DB_NAME vNext_Core
wf domain add onboarding --DB_NAME vNext_Onboarding

# Now just cd into the project and run commands - domain switches automatically
cd ~/projects/core-app # has vnext.config.json with "domain": "core"
wf update # auto-switches to "core" profile

cd ~/projects/onboarding-app # has vnext.config.json with "domain": "onboarding"
wf update # auto-switches to "onboarding" profile
```

> **Note:** The `wf domain` command is excluded from auto-resolution so that manual domain management is never interfered with.

### Backward Compatibility

- Existing single-domain configurations are automatically migrated to the new format.
Expand Down Expand Up @@ -583,8 +617,9 @@ wf config get DOCKER_POSTGRES_CONTAINER

### "npm link not working"
```bash
# Use alias
# Use alias (wf or vnext)
echo 'alias wf="node $(pwd)/bin/workflow.js"' >> ~/.bashrc
echo 'alias vnext="node $(pwd)/bin/workflow.js"' >> ~/.bashrc
source ~/.bashrc
```

Expand Down
16 changes: 16 additions & 0 deletions bin/workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const { program, Argument } = require('commander');
const chalk = require('chalk');
const pkg = require('../package.json');

// Config
const config = require('../src/lib/config');
const { printActiveDomainBanner } = require('../src/lib/ui');

// Commands
const checkCommand = require('../src/commands/check');
const csxCommand = require('../src/commands/csx');
Expand All @@ -18,6 +22,18 @@ program
.description('vNext Workflow Manager CLI')
.version(pkg.version);

// Auto-resolve domain and show banner before each command
program.hook('preAction', (thisCommand, actionCommand) => {
if (actionCommand.name() === 'domain') return;

const result = config.resolveWorkspaceDomain(process.cwd());
if (result.resolved && result.switched) {
console.log(chalk.dim(` [auto] Domain switched to "${result.domain}" (from vnext.config.json)`));
}

printActiveDomainBanner();
});

// Check command
program
.command('check')
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "dist/index.js",
"bin": {
"workflow": "./bin/workflow.js",
"wf": "./bin/workflow.js"
"wf": "./bin/workflow.js",
"vnext": "./bin/workflow.js"
},
"scripts": {
"dev": "node bin/workflow.js",
Expand Down
17 changes: 1 addition & 16 deletions src/commands/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,7 @@ const { discoverComponents, listDiscovered } = require('../lib/discover');
const { getDomain, getComponentTypes, getComponentsRoot } = require('../lib/vnextConfig');
const { testApiConnection } = require('../lib/api');
const { testDbConnection } = require('../lib/db');

// Logging helpers
const LOG = {
separator: () => console.log(chalk.cyan('═'.repeat(60))),
subSeparator: () => console.log(chalk.cyan('─'.repeat(60))),
header: (text) => {
console.log();
LOG.separator();
console.log(chalk.cyan.bold(` ${text}`));
LOG.separator();
},
success: (text) => console.log(chalk.green(` ✓ ${text}`)),
error: (text) => console.log(chalk.red(` ✗ ${text}`)),
warning: (text) => console.log(chalk.yellow(` ⚠ ${text}`)),
info: (text) => console.log(chalk.dim(` ○ ${text}`))
};
const { LOG } = require('../lib/ui');

async function checkCommand() {
LOG.header('SYSTEM CHECK');
Expand Down
33 changes: 2 additions & 31 deletions src/commands/csx.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,7 @@ const path = require('path');
const config = require('../lib/config');
const { getDomain } = require('../lib/vnextConfig');
const { processCsxFile, getGitChangedCsx, findAllCsx } = require('../lib/csx');

// Logging helpers
const LOG = {
separator: () => console.log(chalk.cyan('═'.repeat(60))),
subSeparator: () => console.log(chalk.cyan('─'.repeat(60))),
header: (text) => {
console.log();
LOG.separator();
console.log(chalk.cyan.bold(` ${text}`));
LOG.separator();
},
success: (text) => console.log(chalk.green(` ✓ ${text}`)),
error: (text) => console.log(chalk.red(` ✗ ${text}`)),
warning: (text) => console.log(chalk.yellow(` ⚠ ${text}`)),
info: (text) => console.log(chalk.dim(` ○ ${text}`)),
component: (type, name, status, detail = '') => {
const typeLabel = chalk.cyan(`[${type}]`);
const nameLabel = chalk.white(name);
if (status === 'success') {
console.log(` ${typeLabel} ${chalk.green('✓')} ${nameLabel} ${chalk.dim(detail)}`);
} else if (status === 'error') {
console.log(` ${typeLabel} ${chalk.red('✗')} ${nameLabel}`);
if (detail) console.log(chalk.red(` └─ ${detail}`));
} else if (status === 'skip') {
console.log(` ${typeLabel} ${chalk.dim('○')} ${nameLabel} ${chalk.dim(detail)}`);
}
}
};
const { LOG } = require('../lib/ui');

async function csxCommand(options) {
LOG.header('CSX UPDATE');
Expand All @@ -40,9 +13,7 @@ async function csxCommand(options) {

// Check domain
try {
const domain = getDomain(projectRoot);
console.log(chalk.dim(` Domain: ${domain}`));
console.log();
getDomain(projectRoot);
} catch (error) {
LOG.error(`Failed to read vnext.config.json: ${error.message}`);
return;
Expand Down
44 changes: 4 additions & 40 deletions src/commands/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,7 @@ const { getDomain, getComponentTypes } = require('../lib/vnextConfig');
const { getJsonMetadata, findAllJson, detectComponentType } = require('../lib/workflow');
const { publishComponent, reinitializeSystem } = require('../lib/api');
const { getInstanceId, deleteWorkflow } = require('../lib/db');

// Logging helpers
const LOG = {
separator: () => console.log(chalk.cyan('═'.repeat(60))),
subSeparator: () => console.log(chalk.cyan('─'.repeat(60))),
header: (text) => {
console.log();
LOG.separator();
console.log(chalk.cyan.bold(` ${text}`));
LOG.separator();
},
success: (text) => console.log(chalk.green(` ✓ ${text}`)),
error: (text) => console.log(chalk.red(` ✗ ${text}`)),
warning: (text) => console.log(chalk.yellow(` ⚠ ${text}`)),
info: (text) => console.log(chalk.dim(` ○ ${text}`)),
component: (type, name, status, detail = '') => {
const typeLabel = chalk.cyan(`[${type}]`);
const nameLabel = chalk.white(name);
if (status === 'success') {
console.log(` ${typeLabel} ${chalk.green('✓')} ${nameLabel} ${chalk.dim(detail)}`);
} else if (status === 'error') {
console.log(` ${typeLabel} ${chalk.red('✗')} ${nameLabel}`);
if (detail) console.log(chalk.red(` └─ ${detail}`));
} else if (status === 'skip') {
console.log(` ${typeLabel} ${chalk.dim('○')} ${nameLabel} ${chalk.dim(detail)}`);
}
}
};
const { LOG, printApiError, printErrorSummaryTable } = require('../lib/ui');

async function resetCommand(options) {
LOG.header('COMPONENT RESET (Force Update)');
Expand Down Expand Up @@ -72,10 +45,6 @@ async function resetCommand(options) {
domain: domain
};

console.log(chalk.dim(` Domain: ${domain}`));
console.log(chalk.dim(` API: ${apiConfig.baseUrl}`));
console.log();

// Discover folders
const spinner = ora(' Scanning folders...').start();
let discovered;
Expand Down Expand Up @@ -210,9 +179,9 @@ async function resetCommand(options) {
LOG.component(type, fileName, 'success', `→ ${action}`);
componentStats[type].success++;
} else {
LOG.component(type, fileName, 'error', result.error);
printApiError(result, type, fileName);
componentStats[type].failed++;
errors.push({ type, file: fileName, error: result.error });
errors.push({ type, file: fileName, error: result.error, statusCode: result.statusCode, apiError: result.apiError });
}
} catch (error) {
const errorMsg = error.message || 'Unknown error';
Expand Down Expand Up @@ -257,12 +226,7 @@ async function resetCommand(options) {
if (errors.length > 0) {
console.log();
LOG.subSeparator();
console.log(chalk.red.bold('\n ERRORS:\n'));

for (const err of errors) {
console.log(chalk.red(` [${err.type}] ${err.file}`));
console.log(chalk.dim(` └─ ${err.error}`));
}
printErrorSummaryTable(errors);
}

LOG.separator();
Expand Down
55 changes: 9 additions & 46 deletions src/commands/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,7 @@ const { publishComponent, reinitializeSystem } = require('../lib/api');
const { getInstanceId, deleteWorkflow } = require('../lib/db');
const { getJsonMetadata, detectComponentType } = require('../lib/workflow');
const { processCsxFile, findAllCsx } = require('../lib/csx');

// Logging helpers
const LOG = {
separator: () => console.log(chalk.cyan('═'.repeat(60))),
subSeparator: () => console.log(chalk.cyan('─'.repeat(60))),
header: (text) => {
console.log();
LOG.separator();
console.log(chalk.cyan.bold(` ${text}`));
LOG.separator();
},
success: (text) => console.log(chalk.green(` ✓ ${text}`)),
error: (text) => console.log(chalk.red(` ✗ ${text}`)),
warning: (text) => console.log(chalk.yellow(` ⚠ ${text}`)),
info: (text) => console.log(chalk.dim(` ○ ${text}`)),
component: (type, name, status, detail = '') => {
const typeLabel = chalk.cyan(`[${type}]`);
const nameLabel = chalk.white(name);
if (status === 'success') {
console.log(` ${typeLabel} ${chalk.green('✓')} ${nameLabel} ${chalk.dim(detail)}`);
} else if (status === 'error') {
console.log(` ${typeLabel} ${chalk.red('✗')} ${nameLabel}`);
if (detail) console.log(chalk.red(` └─ ${detail}`));
} else if (status === 'skip') {
console.log(` ${typeLabel} ${chalk.dim('○')} ${nameLabel} ${chalk.dim(detail)}`);
}
}
};
const { LOG, printApiError, printErrorSummaryTable } = require('../lib/ui');

async function syncCommand() {
LOG.header('SYSTEM SYNC - Add Missing Components');
Expand Down Expand Up @@ -77,10 +50,6 @@ async function syncCommand() {
domain: domain
};

console.log(chalk.dim(` Domain: ${domain}`));
console.log(chalk.dim(` API: ${apiConfig.baseUrl}`));
console.log();

// Discover folders
const discoverSpinner = ora('Scanning folders...').start();
let discovered;
Expand Down Expand Up @@ -183,9 +152,9 @@ async function syncCommand() {
LOG.component(type, fileName, 'success', '→ published');
componentStats[type].success++;
} else {
LOG.component(type, fileName, 'error', result.error);
printApiError(result, type, fileName);
componentStats[type].failed++;
errors.push({ type, file: fileName, error: result.error });
errors.push({ type, file: fileName, error: result.error, statusCode: result.statusCode, apiError: result.apiError });
}
} catch (error) {
const errorMsg = error.message || 'Unknown error';
Expand Down Expand Up @@ -239,20 +208,14 @@ async function syncCommand() {
}

// Errors
if (errors.length > 0 || csxResults.errors.length > 0) {
const allErrors = [
...errors,
...csxResults.errors.map(e => ({ type: 'CSX', file: e.file, error: e.error }))
];
if (allErrors.length > 0) {
console.log();
LOG.subSeparator();
console.log(chalk.red.bold('\n ERRORS:\n'));

for (const err of errors) {
console.log(chalk.red(` [${err.type}] ${err.file}`));
console.log(chalk.dim(` └─ ${err.error}`));
}

for (const err of csxResults.errors) {
console.log(chalk.red(` [CSX] ${err.file}`));
console.log(chalk.dim(` └─ ${err.error}`));
}
printErrorSummaryTable(allErrors);
}

LOG.separator();
Expand Down
Loading
Loading