@roarkanalytics/cli 0.51.1 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/npm-shrinkwrap.json +15 -5
- package/package.json +2 -1
- package/runtime/commands/config-as-code.d.ts +5 -3
- package/runtime/commands/config-as-code.js +59 -24
- package/runtime/config-module.d.ts +26 -0
- package/runtime/config-module.js +68 -0
- package/runtime/program.d.ts +19 -0
- package/runtime/program.js +42 -2
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.52.0](https://github.com/roarkhq/cli-roark-analytics/compare/v0.51.2...v0.52.0) (2026-10-25)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **config:** evaluate a TypeScript config file, not just a YAML directory ([#135](https://github.com/roarkhq/cli-roark-analytics/issues/135)) ([85779d1](https://github.com/roarkhq/cli-roark-analytics/commit/85779d1f8b0b3d8660e08a463159fe57458b16ea))
|
|
9
|
+
|
|
10
|
+
## [0.51.2](https://github.com/roarkhq/cli-roark-analytics/compare/v0.51.1...v0.51.2) (2026-10-23)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **confirm:** name the calls a batch delete will remove, not the command typed ([#133](https://github.com/roarkhq/cli-roark-analytics/issues/133)) ([e9a7d2f](https://github.com/roarkhq/cli-roark-analytics/commit/e9a7d2fab4fd074ce7be34e01f69c80e98aa09c2))
|
|
16
|
+
|
|
3
17
|
## [0.51.1](https://github.com/roarkhq/cli-roark-analytics/compare/v0.51.0...v0.51.1) (2026-10-22)
|
|
4
18
|
|
|
5
19
|
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roarkanalytics/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@roarkanalytics/cli",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.52.0",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@roarkanalytics/sdk": "^5.12.0",
|
|
13
13
|
"commander": "^14.0.3",
|
|
14
|
+
"jiti": "^2.4.2",
|
|
14
15
|
"yaml": "^2.9.0"
|
|
15
16
|
},
|
|
16
17
|
"bin": {
|
|
@@ -21,9 +22,9 @@
|
|
|
21
22
|
}
|
|
22
23
|
},
|
|
23
24
|
"node_modules/@roarkanalytics/sdk": {
|
|
24
|
-
"version": "5.
|
|
25
|
-
"resolved": "https://registry.npmjs.org/@roarkanalytics/sdk/-/sdk-5.
|
|
26
|
-
"integrity": "sha512-
|
|
25
|
+
"version": "5.14.0",
|
|
26
|
+
"resolved": "https://registry.npmjs.org/@roarkanalytics/sdk/-/sdk-5.14.0.tgz",
|
|
27
|
+
"integrity": "sha512-DOQBoDCs4C2cDISP6LHR/DZ6uIaD05zfT+BjwH3H0ftnIpXKh5Cxnv+ibC49McGK0t4WeRmC96u4SBWDR/iXNw==",
|
|
27
28
|
"license": "Apache-2.0"
|
|
28
29
|
},
|
|
29
30
|
"node_modules/commander": {
|
|
@@ -35,6 +36,15 @@
|
|
|
35
36
|
"node": ">=20"
|
|
36
37
|
}
|
|
37
38
|
},
|
|
39
|
+
"node_modules/jiti": {
|
|
40
|
+
"version": "2.7.0",
|
|
41
|
+
"resolved": "https://registry.npmjs.org/jiti/-/jiti-2.7.0.tgz",
|
|
42
|
+
"integrity": "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ==",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"bin": {
|
|
45
|
+
"jiti": "lib/jiti-cli.mjs"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
38
48
|
"node_modules/yaml": {
|
|
39
49
|
"version": "2.9.1",
|
|
40
50
|
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roarkanalytics/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.0",
|
|
4
4
|
"description": "The official command line interface for the Roark API",
|
|
5
5
|
"author": "Roark <james@roark.ai>",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@roarkanalytics/sdk": "^5.12.0",
|
|
33
33
|
"commander": "^14.0.3",
|
|
34
|
+
"jiti": "^2.4.2",
|
|
34
35
|
"yaml": "^2.9.0"
|
|
35
36
|
},
|
|
36
37
|
"man": [
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* `roark config diff [dir]` and `roark config apply [dir]` - config as code.
|
|
3
3
|
*
|
|
4
4
|
* These wrap the generated `config.diff` / `config.apply` SDK methods with the one client-side
|
|
5
|
-
* step they need to be useful: building the
|
|
6
|
-
*
|
|
7
|
-
* `
|
|
5
|
+
* step they need to be useful: building the `{ resources, prune }` bundle. Point either at a
|
|
6
|
+
* directory of YAML (`*.yaml`, with `file://` references inlined) or at a TypeScript config file
|
|
7
|
+
* (`roark.config.ts`, whose `defineConfig(...)` default export is evaluated with jiti); with no
|
|
8
|
+
* argument it auto-detects `roark.config.ts` in the cwd. `--data`/stdin still take a pre-built
|
|
9
|
+
* bundle for scripting.
|
|
8
10
|
*
|
|
9
11
|
* `apply` previews the diff and asks to confirm before writing (config-managed resources absent
|
|
10
12
|
* from the bundle are deleted unless `--no-prune`), so a destructive apply is never a surprise.
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
* `roark config diff [dir]` and `roark config apply [dir]` - config as code.
|
|
4
4
|
*
|
|
5
5
|
* These wrap the generated `config.diff` / `config.apply` SDK methods with the one client-side
|
|
6
|
-
* step they need to be useful: building the
|
|
7
|
-
*
|
|
8
|
-
* `
|
|
6
|
+
* step they need to be useful: building the `{ resources, prune }` bundle. Point either at a
|
|
7
|
+
* directory of YAML (`*.yaml`, with `file://` references inlined) or at a TypeScript config file
|
|
8
|
+
* (`roark.config.ts`, whose `defineConfig(...)` default export is evaluated with jiti); with no
|
|
9
|
+
* argument it auto-detects `roark.config.ts` in the cwd. `--data`/stdin still take a pre-built
|
|
10
|
+
* bundle for scripting.
|
|
9
11
|
*
|
|
10
12
|
* `apply` previews the diff and asks to confirm before writing (config-managed resources absent
|
|
11
13
|
* from the bundle are deleted unless `--no-prune`), so a destructive apply is never a surprise.
|
|
@@ -14,12 +16,14 @@
|
|
|
14
16
|
*/
|
|
15
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
18
|
exports.registerConfigAsCodeCommands = void 0;
|
|
19
|
+
const promises_1 = require("node:fs/promises");
|
|
17
20
|
const commander_1 = require("commander");
|
|
18
21
|
const confirm_1 = require("../confirm");
|
|
19
22
|
const errors_1 = require("../errors");
|
|
20
23
|
const input_1 = require("../input");
|
|
21
24
|
const output_1 = require("../output");
|
|
22
25
|
const config_bundle_1 = require("../config-bundle");
|
|
26
|
+
const config_module_1 = require("../config-module");
|
|
23
27
|
const OP_MARK = { create: '+', update: '~', delete: '-', noop: ' ' };
|
|
24
28
|
/** One-line-per-change summary for a terminal; `apply` results also carry a status. */
|
|
25
29
|
const formatChanges = (data) => {
|
|
@@ -39,11 +43,25 @@ const formatChanges = (data) => {
|
|
|
39
43
|
return [...lines, '', tally].join('\n');
|
|
40
44
|
};
|
|
41
45
|
const changeCount = (summary) => (summary['create'] ?? 0) + (summary['update'] ?? 0) + (summary['delete'] ?? 0);
|
|
42
|
-
/**
|
|
43
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Resolve the bundle from a `path`, `--data`/stdin, or an auto-detected config file:
|
|
48
|
+
* - a directory → build it from YAML
|
|
49
|
+
* - a `.ts`/`.js` file → evaluate it (the `defineConfig(...)` default export)
|
|
50
|
+
* - `--data`/piped stdin → a pre-built JSON bundle
|
|
51
|
+
* - nothing → auto-detect `roark.config.ts` in the cwd (like `sst.config.ts`)
|
|
52
|
+
*/
|
|
53
|
+
const resolveBundle = async (path, options) => {
|
|
44
54
|
const prune = options['prune'] === false ? false : undefined;
|
|
45
|
-
|
|
46
|
-
|
|
55
|
+
const pruneOpt = prune === undefined ? {} : { prune };
|
|
56
|
+
if (path !== undefined) {
|
|
57
|
+
const info = await (0, promises_1.stat)(path).catch(() => null);
|
|
58
|
+
if (info?.isDirectory())
|
|
59
|
+
return (0, config_bundle_1.buildBundle)(path, pruneOpt);
|
|
60
|
+
if (info?.isFile() && (0, config_module_1.isConfigModulePath)(path))
|
|
61
|
+
return (0, config_module_1.loadConfigModule)(path, pruneOpt);
|
|
62
|
+
if (!info)
|
|
63
|
+
throw new errors_1.UsageError(`path not found: ${path}`);
|
|
64
|
+
throw new errors_1.UsageError(`${path} is not a config directory or a .ts/.js config file`);
|
|
47
65
|
}
|
|
48
66
|
const explicit = options['data'] === undefined ? undefined : (0, input_1.readData)(options['data']);
|
|
49
67
|
const piped = explicit === undefined && (0, input_1.stdinIsPiped)() ?
|
|
@@ -53,11 +71,17 @@ const resolveBundle = async (dir, options) => {
|
|
|
53
71
|
})()
|
|
54
72
|
: undefined;
|
|
55
73
|
const body = explicit ?? piped;
|
|
56
|
-
if (body
|
|
57
|
-
|
|
74
|
+
if (body !== undefined) {
|
|
75
|
+
if (typeof body !== 'object')
|
|
76
|
+
throw new errors_1.UsageError('--data / stdin must be a JSON bundle object');
|
|
77
|
+
const bundle = body;
|
|
78
|
+
return prune === undefined ? bundle : { ...bundle, prune };
|
|
58
79
|
}
|
|
59
|
-
|
|
60
|
-
|
|
80
|
+
// Nothing given: fall back to a config file in the working directory.
|
|
81
|
+
const auto = (0, config_module_1.findDefaultConfigModule)(process.cwd());
|
|
82
|
+
if (auto)
|
|
83
|
+
return (0, config_module_1.loadConfigModule)(auto, pruneOpt);
|
|
84
|
+
throw new errors_1.UsageError('provide a config directory (e.g. `./roark`), a .ts config file, or a bundle via --data / stdin');
|
|
61
85
|
};
|
|
62
86
|
const configGroup = (root) => {
|
|
63
87
|
const existing = root.commands.find((child) => child.name() === 'config');
|
|
@@ -81,11 +105,16 @@ const withCommonOptions = (command) => command
|
|
|
81
105
|
.showHelpAfterError();
|
|
82
106
|
const registerConfigAsCodeCommands = (root, binaryName, clientFor, resolveOutput) => {
|
|
83
107
|
const config = configGroup(root);
|
|
84
|
-
withCommonOptions(config.command('diff [
|
|
85
|
-
.description('Preview the changes a config directory
|
|
86
|
-
.addHelpText('after', [
|
|
87
|
-
|
|
88
|
-
|
|
108
|
+
withCommonOptions(config.command('diff [path]'))
|
|
109
|
+
.description('Preview the changes a config directory, .ts config file, or bundle would make. No writes.')
|
|
110
|
+
.addHelpText('after', [
|
|
111
|
+
'',
|
|
112
|
+
'Examples:',
|
|
113
|
+
` ${binaryName} config diff ./roark`,
|
|
114
|
+
` ${binaryName} config diff roark.config.ts`,
|
|
115
|
+
].join('\n'))
|
|
116
|
+
.action(async (path, options) => {
|
|
117
|
+
const bundle = await resolveBundle(path, options);
|
|
89
118
|
const client = clientFor(options);
|
|
90
119
|
const result = await client.config.diff(bundle);
|
|
91
120
|
const output = resolveOutput(options);
|
|
@@ -93,13 +122,18 @@ const registerConfigAsCodeCommands = (root, binaryName, clientFor, resolveOutput
|
|
|
93
122
|
(0, output_1.render)(result.data, output)
|
|
94
123
|
: formatChanges(result.data));
|
|
95
124
|
});
|
|
96
|
-
withCommonOptions(config.command('apply [
|
|
97
|
-
.description('Reconcile the project to a config directory
|
|
125
|
+
withCommonOptions(config.command('apply [path]'))
|
|
126
|
+
.description('Reconcile the project to a config directory, .ts config file, or bundle. Previews and confirms first.')
|
|
98
127
|
.option('-y, --yes', 'skip the confirmation prompt')
|
|
99
128
|
.option('--no-input', 'never prompt; fail instead')
|
|
100
|
-
.addHelpText('after', [
|
|
101
|
-
|
|
102
|
-
|
|
129
|
+
.addHelpText('after', [
|
|
130
|
+
'',
|
|
131
|
+
'Examples:',
|
|
132
|
+
` ${binaryName} config apply ./roark`,
|
|
133
|
+
` ${binaryName} config apply roark.config.ts`,
|
|
134
|
+
].join('\n'))
|
|
135
|
+
.action(async (path, options) => {
|
|
136
|
+
const bundle = await resolveBundle(path, options);
|
|
103
137
|
const client = clientFor(options);
|
|
104
138
|
const output = resolveOutput(options);
|
|
105
139
|
const json = output.format === 'json' || options['json'] === true;
|
|
@@ -123,9 +157,10 @@ const registerConfigAsCodeCommands = (root, binaryName, clientFor, resolveOutput
|
|
|
123
157
|
});
|
|
124
158
|
config.addHelpText('after', [
|
|
125
159
|
'',
|
|
126
|
-
'Config as code: keep your Roark resources
|
|
127
|
-
` ${binaryName} config
|
|
128
|
-
` ${binaryName} config apply
|
|
160
|
+
'Config as code: keep your Roark resources in git (YAML or TypeScript) and sync them.',
|
|
161
|
+
` ${binaryName} config apply ./roark # a directory of YAML`,
|
|
162
|
+
` ${binaryName} config apply roark.config.ts # a TypeScript config (defineConfig)`,
|
|
163
|
+
` ${binaryName} config apply # auto-detects roark.config.ts in the cwd`,
|
|
129
164
|
].join('\n'));
|
|
130
165
|
};
|
|
131
166
|
exports.registerConfigAsCodeCommands = registerConfigAsCodeCommands;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Load a config-as-code bundle from a TypeScript (or JS) config file.
|
|
3
|
+
*
|
|
4
|
+
* The code-first counterpart to `config-bundle.ts` (which walks a YAML directory). Point the CLI
|
|
5
|
+
* at a `roark.config.ts` and it evaluates the module with jiti — the same zero-build TS loader
|
|
6
|
+
* tools like SST and Vitest use for their `*.config.ts` — and reads its default export: the
|
|
7
|
+
* `{ resources, prune }` bundle a `defineConfig(...)` returns (or a bare array of resources, or a
|
|
8
|
+
* function returning either). The result is the exact same bundle the YAML path produces, so it
|
|
9
|
+
* flows through the identical `config diff` / `config apply` without any new API surface.
|
|
10
|
+
*
|
|
11
|
+
* jiti resolves the config file's own imports (e.g. `@roarkanalytics/sdk/lib/config`) relative to
|
|
12
|
+
* the file, so they come from the user's project, not the CLI's bundled dependencies.
|
|
13
|
+
*/
|
|
14
|
+
import type { ConfigBundle } from './config-bundle';
|
|
15
|
+
/** Whether a path looks like a TypeScript/JS config entrypoint (vs. a YAML directory). */
|
|
16
|
+
export declare const isConfigModulePath: (path: string) => boolean;
|
|
17
|
+
/** The first `roark.config.*` present in `cwd`, or undefined — like `sst` finding `sst.config.ts`. */
|
|
18
|
+
export declare const findDefaultConfigModule: (cwd: string) => string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Evaluate a config module and normalize its export to a bundle. A `--no-prune` flag
|
|
21
|
+
* (`options.prune === false`) overrides whatever the module set; otherwise the module's own
|
|
22
|
+
* `prune` (from `defineConfig`) is kept.
|
|
23
|
+
*/
|
|
24
|
+
export declare const loadConfigModule: (file: string, options?: {
|
|
25
|
+
prune?: boolean;
|
|
26
|
+
}) => Promise<ConfigBundle>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Load a config-as-code bundle from a TypeScript (or JS) config file.
|
|
4
|
+
*
|
|
5
|
+
* The code-first counterpart to `config-bundle.ts` (which walks a YAML directory). Point the CLI
|
|
6
|
+
* at a `roark.config.ts` and it evaluates the module with jiti — the same zero-build TS loader
|
|
7
|
+
* tools like SST and Vitest use for their `*.config.ts` — and reads its default export: the
|
|
8
|
+
* `{ resources, prune }` bundle a `defineConfig(...)` returns (or a bare array of resources, or a
|
|
9
|
+
* function returning either). The result is the exact same bundle the YAML path produces, so it
|
|
10
|
+
* flows through the identical `config diff` / `config apply` without any new API surface.
|
|
11
|
+
*
|
|
12
|
+
* jiti resolves the config file's own imports (e.g. `@roarkanalytics/sdk/lib/config`) relative to
|
|
13
|
+
* the file, so they come from the user's project, not the CLI's bundled dependencies.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.loadConfigModule = exports.findDefaultConfigModule = exports.isConfigModulePath = void 0;
|
|
17
|
+
const node_fs_1 = require("node:fs");
|
|
18
|
+
const node_path_1 = require("node:path");
|
|
19
|
+
const node_url_1 = require("node:url");
|
|
20
|
+
const jiti_1 = require("jiti");
|
|
21
|
+
const errors_1 = require("./errors");
|
|
22
|
+
const MODULE_EXTENSIONS = ['.ts', '.mts', '.cts', '.js', '.mjs', '.cjs'];
|
|
23
|
+
/** Whether a path looks like a TypeScript/JS config entrypoint (vs. a YAML directory). */
|
|
24
|
+
const isConfigModulePath = (path) => MODULE_EXTENSIONS.some((ext) => path.endsWith(ext));
|
|
25
|
+
exports.isConfigModulePath = isConfigModulePath;
|
|
26
|
+
/** The default config entrypoints to auto-detect in the working directory, in order. */
|
|
27
|
+
const DEFAULT_CONFIG_FILES = ['roark.config.ts', 'roark.config.mts', 'roark.config.js', 'roark.config.mjs'];
|
|
28
|
+
/** The first `roark.config.*` present in `cwd`, or undefined — like `sst` finding `sst.config.ts`. */
|
|
29
|
+
const findDefaultConfigModule = (cwd) => {
|
|
30
|
+
for (const name of DEFAULT_CONFIG_FILES) {
|
|
31
|
+
const candidate = (0, node_path_1.resolve)(cwd, name);
|
|
32
|
+
if ((0, node_fs_1.existsSync)(candidate))
|
|
33
|
+
return candidate;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
};
|
|
37
|
+
exports.findDefaultConfigModule = findDefaultConfigModule;
|
|
38
|
+
/**
|
|
39
|
+
* Evaluate a config module and normalize its export to a bundle. A `--no-prune` flag
|
|
40
|
+
* (`options.prune === false`) overrides whatever the module set; otherwise the module's own
|
|
41
|
+
* `prune` (from `defineConfig`) is kept.
|
|
42
|
+
*/
|
|
43
|
+
const loadConfigModule = async (file, options = {}) => {
|
|
44
|
+
const abs = (0, node_path_1.resolve)(file);
|
|
45
|
+
const jiti = (0, jiti_1.createJiti)((0, node_url_1.pathToFileURL)(abs).href);
|
|
46
|
+
let mod;
|
|
47
|
+
try {
|
|
48
|
+
mod = await jiti.import(abs);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
throw new errors_1.UsageError(`failed to load config file ${file}: ${error.message}`);
|
|
52
|
+
}
|
|
53
|
+
// Prefer the default export; accept a bundle object, a bare resources array, or a
|
|
54
|
+
// (possibly async) function returning either.
|
|
55
|
+
const record = mod && typeof mod === 'object' ? mod : {};
|
|
56
|
+
let exported = 'default' in record ? record['default'] : mod;
|
|
57
|
+
if (typeof exported === 'function')
|
|
58
|
+
exported = await exported();
|
|
59
|
+
exported = await exported;
|
|
60
|
+
const bundle = Array.isArray(exported) ? { resources: exported } : exported;
|
|
61
|
+
if (!bundle || typeof bundle !== 'object' || !Array.isArray(bundle.resources)) {
|
|
62
|
+
throw new errors_1.UsageError(`config file ${file} must export (as default) a bundle from defineConfig(...), or an array of resources`);
|
|
63
|
+
}
|
|
64
|
+
const typed = bundle;
|
|
65
|
+
const prune = options.prune === false ? false : typed.prune;
|
|
66
|
+
return { resources: typed.resources, ...(prune === undefined ? {} : { prune }) };
|
|
67
|
+
};
|
|
68
|
+
exports.loadConfigModule = loadConfigModule;
|
package/runtime/program.d.ts
CHANGED
|
@@ -17,6 +17,25 @@ export interface ProgramOptions {
|
|
|
17
17
|
groups: Readonly<Record<string, string>>;
|
|
18
18
|
completions: Readonly<Record<string, string>>;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* What the confirmation prompt names as the thing being deleted.
|
|
22
|
+
*
|
|
23
|
+
* A path parameter IS that thing, so a command with one reads it back:
|
|
24
|
+
* `call delete abc123` asks about `abc123`.
|
|
25
|
+
*
|
|
26
|
+
* A batch delete has no path parameter - its targets arrive in a required flag -
|
|
27
|
+
* and the fallback named the command instead, so `call batch delete` asked
|
|
28
|
+
* "Permanently delete call batch delete?". That sentence cannot help the one
|
|
29
|
+
* person the prompt exists for: someone who typed the wrong `--call-ids` and has
|
|
30
|
+
* a last chance to notice. It is also the only destructive command without a
|
|
31
|
+
* positional, and the only one that deletes in bulk, so the single worst place
|
|
32
|
+
* to say nothing useful.
|
|
33
|
+
*
|
|
34
|
+
* So the targets come from the required flags, which are what identifies them.
|
|
35
|
+
* The command path stays as the last resort, for a destructive command that one
|
|
36
|
+
* day identifies its target some other way - wrong, but never silent.
|
|
37
|
+
*/
|
|
38
|
+
export declare const deletionTarget: (command: CliCommand, positionals: string[], options: Record<string, unknown>) => string;
|
|
20
39
|
interface GlobalOptions {
|
|
21
40
|
baseUrl?: string;
|
|
22
41
|
project?: string;
|
package/runtime/program.js
CHANGED
|
@@ -9,7 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.run = exports.createProgram = exports.resolveOutput = exports.assertBaseUrlIsTrusted = void 0;
|
|
12
|
+
exports.run = exports.createProgram = exports.resolveOutput = exports.assertBaseUrlIsTrusted = exports.deletionTarget = void 0;
|
|
13
13
|
const commander_1 = require("commander");
|
|
14
14
|
const sdk_1 = __importDefault(require("@roarkanalytics/sdk"));
|
|
15
15
|
const api_1 = require("./commands/api");
|
|
@@ -25,6 +25,46 @@ const output_1 = require("./output");
|
|
|
25
25
|
/** Verbs whose effect a user cannot undo, so they get a confirmation prompt. */
|
|
26
26
|
const DESTRUCTIVE_VERBS = new Set(['delete']);
|
|
27
27
|
const isDestructive = (command) => DESTRUCTIVE_VERBS.has(command.commandPath.at(-1) ?? '');
|
|
28
|
+
/** Values beyond this are counted rather than listed; a prompt nobody reads is not a prompt. */
|
|
29
|
+
const MAX_LISTED_TARGETS = 5;
|
|
30
|
+
/**
|
|
31
|
+
* What the confirmation prompt names as the thing being deleted.
|
|
32
|
+
*
|
|
33
|
+
* A path parameter IS that thing, so a command with one reads it back:
|
|
34
|
+
* `call delete abc123` asks about `abc123`.
|
|
35
|
+
*
|
|
36
|
+
* A batch delete has no path parameter - its targets arrive in a required flag -
|
|
37
|
+
* and the fallback named the command instead, so `call batch delete` asked
|
|
38
|
+
* "Permanently delete call batch delete?". That sentence cannot help the one
|
|
39
|
+
* person the prompt exists for: someone who typed the wrong `--call-ids` and has
|
|
40
|
+
* a last chance to notice. It is also the only destructive command without a
|
|
41
|
+
* positional, and the only one that deletes in bulk, so the single worst place
|
|
42
|
+
* to say nothing useful.
|
|
43
|
+
*
|
|
44
|
+
* So the targets come from the required flags, which are what identifies them.
|
|
45
|
+
* The command path stays as the last resort, for a destructive command that one
|
|
46
|
+
* day identifies its target some other way - wrong, but never silent.
|
|
47
|
+
*/
|
|
48
|
+
const deletionTarget = (command, positionals, options) => {
|
|
49
|
+
if (positionals.length > 0)
|
|
50
|
+
return positionals.join(' ');
|
|
51
|
+
const targets = command.flags
|
|
52
|
+
.filter((flag) => flag.required)
|
|
53
|
+
.flatMap((flag) => {
|
|
54
|
+
const raw = options[(0, input_1.optionKey)(flag.name)];
|
|
55
|
+
if (raw === undefined)
|
|
56
|
+
return [];
|
|
57
|
+
return (Array.isArray(raw) ? raw : [raw]).map((value) => String(value));
|
|
58
|
+
});
|
|
59
|
+
if (targets.length === 0)
|
|
60
|
+
return command.commandPath.join(' ');
|
|
61
|
+
// `call batch delete` -> `call`, so the count reads as the thing it counts.
|
|
62
|
+
const noun = command.commandPath[0] ?? 'record';
|
|
63
|
+
const listed = targets.slice(0, MAX_LISTED_TARGETS).join(', ');
|
|
64
|
+
const rest = targets.length - MAX_LISTED_TARGETS;
|
|
65
|
+
return `${targets.length} ${noun}${targets.length === 1 ? '' : 's'}: ${listed}${rest > 0 ? ` and ${rest} more` : ''}`;
|
|
66
|
+
};
|
|
67
|
+
exports.deletionTarget = deletionTarget;
|
|
28
68
|
/**
|
|
29
69
|
* Global flags are declared on every leaf as well as the root so they can be
|
|
30
70
|
* written on either side of the verb. Commander does not inherit options down
|
|
@@ -212,7 +252,7 @@ const addApiCommand = (root, options, definition) => {
|
|
|
212
252
|
const runApiCommand = async (definition, positionals, options, program) => {
|
|
213
253
|
const output = (0, exports.resolveOutput)(options);
|
|
214
254
|
if (isDestructive(definition)) {
|
|
215
|
-
await (0, confirm_1.confirm)(`Permanently delete ${
|
|
255
|
+
await (0, confirm_1.confirm)(`Permanently delete ${(0, exports.deletionTarget)(definition, positionals, options)}?`, {
|
|
216
256
|
assumeYes: options.yes === true,
|
|
217
257
|
noInput: options.input === false,
|
|
218
258
|
});
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.
|
|
1
|
+
export declare const version = "0.52.0";
|
package/version.js
CHANGED