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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ Requests managed by this plugin are tagged with `_pman.routeId`. On each sync, s

See [`CONTRIBUTING.md`](CONTRIBUTING.md).

## CLI

The package ships a small `pman` CLI:

```bash
pman help
pman clear
pman support
```

`pman support` prints the Discord invite: `https://discord.gg/4FBYAMxwdk`.

## License

MIT
11 changes: 11 additions & 0 deletions bin/pman.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env node
import { unlink } from 'node:fs/promises';

const SUPPORT_DISCORD_URL = 'https://discord.gg/4FBYAMxwdk';

const cmd = process.argv[2];
const statePath = process.argv.includes('--state')
? process.argv[process.argv.indexOf('--state') + 1]
Expand All @@ -11,6 +13,10 @@ if (!cmd || cmd === 'help' || cmd === '--help' || cmd === '-h') {

Commands:
pman clear [--state <path>] Deletes the local sync state file (default .postman-sync.json)
pman support Prints the Discord support invite

Support:
${SUPPORT_DISCORD_URL}
`);
process.exit(0);
}
Expand All @@ -32,6 +38,11 @@ if (cmd === 'clear') {
process.exit(0);
}

if (cmd === 'support') {
process.stdout.write(`${SUPPORT_DISCORD_URL}\n`);
process.exit(0);
}

process.stderr.write(`Unknown command: ${cmd}\n`);
process.exit(1);

2 changes: 1 addition & 1 deletion 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": "@st3ix/pman",
"version": "1.0.1",
"version": "1.0.2",
"description": "Sync Fastify route schemas to Postman via OpenAPI and the Postman API.",
"type": "module",
"main": "./dist/index.js",
Expand Down
36 changes: 36 additions & 0 deletions test/pman-cli.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { spawn } from 'node:child_process';
import { once } from 'node:events';
import { text } from 'node:stream/consumers';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';

const root = join(dirname(fileURLToPath(import.meta.url)), '..');
const bin = join(root, 'bin', 'pman.js');

async function runPman(args) {
const child = spawn(process.execPath, [bin, ...args], {
stdio: ['ignore', 'pipe', 'pipe'],
});
const outP = text(child.stdout);
const errP = text(child.stderr);
const [code] = await once(child, 'exit');
const out = await outP;
const err = await errP;
return { code, out, err };
}

test('pman help includes Discord support link', async () => {
const { code, out, err } = await runPman(['help']);
assert.equal(code, 0);
assert.equal(err, '');
assert.match(out, /https:\/\/discord\.gg\/4FBYAMxwdk/);
});

test('pman support prints Discord invite', async () => {
const { code, out, err } = await runPman(['support']);
assert.equal(code, 0);
assert.equal(err, '');
assert.equal(out.trim(), 'https://discord.gg/4FBYAMxwdk');
});
Loading