@knocklabs/cli 0.1.0 → 0.1.4
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/README.md +142 -61
- package/dist/commands/commit/index.js +6 -3
- package/dist/commands/commit/promote.js +5 -2
- package/dist/commands/knock.js +102 -0
- package/dist/commands/ping.js +0 -4
- package/dist/commands/translation/get.js +13 -9
- package/dist/commands/translation/list.js +7 -3
- package/dist/commands/translation/pull.js +18 -9
- package/dist/commands/translation/push.js +10 -6
- package/dist/commands/translation/validate.js +11 -7
- package/dist/commands/whoami.js +3 -0
- package/dist/commands/workflow/activate.js +19 -8
- package/dist/commands/workflow/get.js +14 -10
- package/dist/commands/workflow/list.js +7 -3
- package/dist/commands/workflow/new.js +4 -5
- package/dist/commands/workflow/pull.js +17 -9
- package/dist/commands/workflow/push.js +9 -6
- package/dist/commands/workflow/run.js +56 -0
- package/dist/commands/workflow/validate.js +9 -6
- package/dist/lib/api-v1.js +14 -0
- package/dist/lib/base-command.js +8 -4
- package/dist/lib/helpers/flag.js +30 -1
- package/dist/lib/helpers/json.js +9 -0
- package/dist/lib/helpers/page.js +7 -2
- package/dist/lib/helpers/request.js +1 -1
- package/dist/lib/helpers/ux.js +2 -2
- package/dist/lib/marshal/translation/helpers.js +11 -5
- package/dist/lib/marshal/translation/reader.js +1 -1
- package/dist/lib/marshal/workflow/generator.js +1 -0
- package/dist/lib/marshal/workflow/helpers.js +19 -6
- package/dist/lib/marshal/workflow/reader.js +1 -1
- package/dist/lib/marshal/workflow/types.js +1 -0
- package/dist/lib/run-context/helpers.js +2 -2
- package/oclif.manifest.json +169 -25
- package/package.json +23 -17
|
@@ -104,6 +104,7 @@ class TranslationPush extends _baseCommand.default {
|
|
|
104
104
|
this.log(`‣ Successfully ${actioned} ${translations.length} translation(s):\n` + (0, _string.indentString)(handledRefs.join("\n"), 4));
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
+
TranslationPush.summary = "Push one or more translations from a local file system to Knock.";
|
|
107
108
|
TranslationPush.flags = {
|
|
108
109
|
environment: _core.Flags.string({
|
|
109
110
|
summary: "Pushing a translation is only allowed in the development environment",
|
|
@@ -112,8 +113,11 @@ TranslationPush.flags = {
|
|
|
112
113
|
_const.KnockEnv.Development
|
|
113
114
|
]
|
|
114
115
|
}),
|
|
115
|
-
all: _core.Flags.boolean(
|
|
116
|
+
all: _core.Flags.boolean({
|
|
117
|
+
summary: "Whether to push all translations from the target directory."
|
|
118
|
+
}),
|
|
116
119
|
"translations-dir": _flag.dirPath({
|
|
120
|
+
summary: "The target directory path to find all translations to push.",
|
|
117
121
|
dependsOn: [
|
|
118
122
|
"all"
|
|
119
123
|
]
|
|
@@ -129,9 +133,9 @@ TranslationPush.flags = {
|
|
|
129
133
|
]
|
|
130
134
|
})
|
|
131
135
|
};
|
|
132
|
-
TranslationPush.args =
|
|
133
|
-
{
|
|
134
|
-
|
|
136
|
+
TranslationPush.args = {
|
|
137
|
+
translationRef: _core.Args.string({
|
|
138
|
+
description: _translation.translationRefDescription,
|
|
135
139
|
required: false
|
|
136
|
-
}
|
|
137
|
-
|
|
140
|
+
})
|
|
141
|
+
};
|
|
@@ -99,24 +99,28 @@ class TranslationValidate extends _baseCommand.default {
|
|
|
99
99
|
return errors;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
+
TranslationValidate.summary = "Validate one or more translations from a local file system.";
|
|
102
103
|
TranslationValidate.flags = {
|
|
103
104
|
environment: _core.Flags.string({
|
|
104
|
-
summary: "Validating a
|
|
105
|
+
summary: "Validating a translation is only done in the development environment",
|
|
105
106
|
default: _const.KnockEnv.Development,
|
|
106
107
|
options: [
|
|
107
108
|
_const.KnockEnv.Development
|
|
108
109
|
]
|
|
109
110
|
}),
|
|
110
|
-
all: _core.Flags.boolean(
|
|
111
|
+
all: _core.Flags.boolean({
|
|
112
|
+
summary: "Whether to validate all translations from the target directory."
|
|
113
|
+
}),
|
|
111
114
|
"translations-dir": _flag.dirPath({
|
|
115
|
+
summary: "The target directory path to find all translations to validate.",
|
|
112
116
|
dependsOn: [
|
|
113
117
|
"all"
|
|
114
118
|
]
|
|
115
119
|
})
|
|
116
120
|
};
|
|
117
|
-
TranslationValidate.args =
|
|
118
|
-
{
|
|
119
|
-
|
|
121
|
+
TranslationValidate.args = {
|
|
122
|
+
translationRef: _core.Args.string({
|
|
123
|
+
description: _translation.translationRefDescription,
|
|
120
124
|
required: false
|
|
121
|
-
}
|
|
122
|
-
|
|
125
|
+
})
|
|
126
|
+
};
|
package/dist/commands/whoami.js
CHANGED
|
@@ -17,6 +17,8 @@ function _interopRequireDefault(obj) {
|
|
|
17
17
|
class Whoami extends _baseCommand.default {
|
|
18
18
|
async run() {
|
|
19
19
|
const resp = await (0, _request.withSpinner)(()=>this.apiV1.whoami());
|
|
20
|
+
const { flags } = this.props;
|
|
21
|
+
if (flags.json) return resp.data;
|
|
20
22
|
this.log(`‣ Successfully verified the provided service token:`);
|
|
21
23
|
const info = [
|
|
22
24
|
`Account name: ${resp.data.account_name}`,
|
|
@@ -25,4 +27,5 @@ class Whoami extends _baseCommand.default {
|
|
|
25
27
|
this.log((0, _string.indentString)(info.join("\n"), 4));
|
|
26
28
|
}
|
|
27
29
|
}
|
|
30
|
+
Whoami.summary = "Verify the provided service token.";
|
|
28
31
|
Whoami.enableJsonFlag = true;
|
|
@@ -35,20 +35,31 @@ class WorkflowActivate extends _baseCommand.default {
|
|
|
35
35
|
this.log(`‣ Successfully ${actioned} \`${args.workflowKey}\` workflow in \`${flags.environment}\` environment`);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
WorkflowActivate.summary = "Activate or deactivate a workflow in a given environment.";
|
|
39
|
+
WorkflowActivate.description = `
|
|
40
|
+
This immediately enables or disables a workflow in a given environment without
|
|
41
|
+
needing to go through environment promotion.
|
|
42
|
+
|
|
43
|
+
By default, this command activates a given workflow. Pass in the --status flag
|
|
44
|
+
with \`false\` in order to deactivate it.
|
|
45
|
+
`.trim();
|
|
38
46
|
WorkflowActivate.flags = {
|
|
39
47
|
// Do not default to any env for this command, since this action runs
|
|
40
48
|
// directly in each environment outside the commit and promote flow.
|
|
41
49
|
environment: _core.Flags.string({
|
|
42
|
-
required: true
|
|
50
|
+
required: true,
|
|
51
|
+
summary: "The environment to use."
|
|
43
52
|
}),
|
|
44
53
|
status: (0, _flag.booleanStr)({
|
|
45
|
-
default: true
|
|
54
|
+
default: true,
|
|
55
|
+
summary: "The workflow active status to set."
|
|
46
56
|
}),
|
|
47
|
-
force: _core.Flags.boolean(
|
|
57
|
+
force: _core.Flags.boolean({
|
|
58
|
+
summary: "Remove the confirmation prompt."
|
|
59
|
+
})
|
|
48
60
|
};
|
|
49
|
-
WorkflowActivate.args =
|
|
50
|
-
{
|
|
51
|
-
name: "workflowKey",
|
|
61
|
+
WorkflowActivate.args = {
|
|
62
|
+
workflowKey: _core.Args.string({
|
|
52
63
|
required: true
|
|
53
|
-
}
|
|
54
|
-
|
|
64
|
+
})
|
|
65
|
+
};
|
|
@@ -102,7 +102,7 @@ class WorkflowGet extends _baseCommand.default {
|
|
|
102
102
|
value: (0, _date.formatDateTime)(workflow.updated_at)
|
|
103
103
|
}
|
|
104
104
|
];
|
|
105
|
-
_core.
|
|
105
|
+
_core.ux.table(rows, {
|
|
106
106
|
key: {
|
|
107
107
|
header: "Workflow",
|
|
108
108
|
minWidth: 24
|
|
@@ -113,8 +113,9 @@ class WorkflowGet extends _baseCommand.default {
|
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
115
|
this.log("");
|
|
116
|
+
// Leading space is there intentionally to align the left padding.
|
|
116
117
|
if (workflow.steps.length === 0) {
|
|
117
|
-
return _core.
|
|
118
|
+
return _core.ux.log(" This workflow has no steps to display.");
|
|
118
119
|
}
|
|
119
120
|
/*
|
|
120
121
|
* Workflow steps table
|
|
@@ -122,7 +123,7 @@ class WorkflowGet extends _baseCommand.default {
|
|
|
122
123
|
...step,
|
|
123
124
|
index
|
|
124
125
|
}));
|
|
125
|
-
_core.
|
|
126
|
+
_core.ux.table(steps, {
|
|
126
127
|
index: {
|
|
127
128
|
header: "Steps",
|
|
128
129
|
get: (step)=>step.index + 1
|
|
@@ -146,16 +147,19 @@ class WorkflowGet extends _baseCommand.default {
|
|
|
146
147
|
});
|
|
147
148
|
}
|
|
148
149
|
}
|
|
150
|
+
WorkflowGet.summary = "Display a single workflow from an environment.";
|
|
149
151
|
WorkflowGet.flags = {
|
|
150
152
|
environment: _core.Flags.string({
|
|
151
|
-
default: "development"
|
|
153
|
+
default: "development",
|
|
154
|
+
summary: "The environment to use."
|
|
152
155
|
}),
|
|
153
|
-
"hide-uncommitted-changes": _core.Flags.boolean(
|
|
156
|
+
"hide-uncommitted-changes": _core.Flags.boolean({
|
|
157
|
+
summary: "Hide any uncommitted changes."
|
|
158
|
+
})
|
|
154
159
|
};
|
|
155
|
-
WorkflowGet.args =
|
|
156
|
-
{
|
|
157
|
-
name: "workflowKey",
|
|
160
|
+
WorkflowGet.args = {
|
|
161
|
+
workflowKey: _core.Args.string({
|
|
158
162
|
required: true
|
|
159
|
-
}
|
|
160
|
-
|
|
163
|
+
})
|
|
164
|
+
};
|
|
161
165
|
WorkflowGet.enableJsonFlag = true;
|
|
@@ -79,7 +79,7 @@ class WorkflowList extends _baseCommand.default {
|
|
|
79
79
|
this.log(`‣ Showing ${entries.length} workflows in \`${env}\` environment ${qualifier}\n`);
|
|
80
80
|
/*
|
|
81
81
|
* Workflows list table
|
|
82
|
-
*/ _core.
|
|
82
|
+
*/ _core.ux.table(entries, {
|
|
83
83
|
key: {
|
|
84
84
|
header: "Key"
|
|
85
85
|
},
|
|
@@ -118,11 +118,15 @@ class WorkflowList extends _baseCommand.default {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
+
WorkflowList.summary = "Display all workflows for an environment.";
|
|
121
122
|
WorkflowList.flags = {
|
|
122
123
|
environment: _core.Flags.string({
|
|
123
|
-
default: "development"
|
|
124
|
+
default: "development",
|
|
125
|
+
summary: "The environment to use."
|
|
126
|
+
}),
|
|
127
|
+
"hide-uncommitted-changes": _core.Flags.boolean({
|
|
128
|
+
summary: "Hide any uncommitted changes."
|
|
124
129
|
}),
|
|
125
|
-
"hide-uncommitted-changes": _core.Flags.boolean(),
|
|
126
130
|
..._page.pageFlags
|
|
127
131
|
};
|
|
128
132
|
WorkflowList.enableJsonFlag = true;
|
|
@@ -125,11 +125,10 @@ WorkflowNew.flags = {
|
|
|
125
125
|
}),
|
|
126
126
|
force: _core.Flags.boolean()
|
|
127
127
|
};
|
|
128
|
-
WorkflowNew.args =
|
|
129
|
-
{
|
|
130
|
-
name: "workflowKey",
|
|
128
|
+
WorkflowNew.args = {
|
|
129
|
+
workflowKey: _core.Args.string({
|
|
131
130
|
required: true
|
|
132
|
-
}
|
|
133
|
-
|
|
131
|
+
})
|
|
132
|
+
};
|
|
134
133
|
// TODO(KNO-3072): Unhide after we move the generator logic to the backend.
|
|
135
134
|
WorkflowNew.hidden = true;
|
|
@@ -171,22 +171,30 @@ class WorkflowPull extends _baseCommand.default {
|
|
|
171
171
|
}, workflows) : workflows;
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
+
WorkflowPull.summary = "Pull one or more workflows from an environment into a local file system.";
|
|
174
175
|
WorkflowPull.flags = {
|
|
175
176
|
environment: _core.Flags.string({
|
|
176
|
-
default: "development"
|
|
177
|
+
default: "development",
|
|
178
|
+
summary: "The environment to use."
|
|
179
|
+
}),
|
|
180
|
+
all: _core.Flags.boolean({
|
|
181
|
+
summary: "Whether to pull all workflows from the specified environment."
|
|
177
182
|
}),
|
|
178
|
-
all: _core.Flags.boolean(),
|
|
179
183
|
"workflows-dir": _flag.dirPath({
|
|
184
|
+
summary: "The target directory path to pull all workflows into.",
|
|
180
185
|
dependsOn: [
|
|
181
186
|
"all"
|
|
182
187
|
]
|
|
183
188
|
}),
|
|
184
|
-
"hide-uncommitted-changes": _core.Flags.boolean(
|
|
185
|
-
|
|
189
|
+
"hide-uncommitted-changes": _core.Flags.boolean({
|
|
190
|
+
summary: "Hide any uncommitted changes."
|
|
191
|
+
}),
|
|
192
|
+
force: _core.Flags.boolean({
|
|
193
|
+
summary: "Remove the confirmation prompt."
|
|
194
|
+
})
|
|
186
195
|
};
|
|
187
|
-
WorkflowPull.args =
|
|
188
|
-
{
|
|
189
|
-
name: "workflowKey",
|
|
196
|
+
WorkflowPull.args = {
|
|
197
|
+
workflowKey: _core.Args.string({
|
|
190
198
|
required: false
|
|
191
|
-
}
|
|
192
|
-
|
|
199
|
+
})
|
|
200
|
+
};
|
|
@@ -116,6 +116,7 @@ class WorkflowPush extends _baseCommand.default {
|
|
|
116
116
|
this.log(`‣ Successfully ${actioned} ${workflows.length} workflow(s):\n` + (0, _string.indentString)(workflowKeys.join("\n"), 4));
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
+
WorkflowPush.summary = "Push one or more workflows from a local file system to Knock.";
|
|
119
120
|
WorkflowPush.flags = {
|
|
120
121
|
environment: _core.Flags.string({
|
|
121
122
|
summary: "Pushing a workflow is only allowed in the development environment",
|
|
@@ -124,8 +125,11 @@ WorkflowPush.flags = {
|
|
|
124
125
|
_const.KnockEnv.Development
|
|
125
126
|
]
|
|
126
127
|
}),
|
|
127
|
-
all: _core.Flags.boolean(
|
|
128
|
+
all: _core.Flags.boolean({
|
|
129
|
+
summary: "Whether to push all workflows from the target directory."
|
|
130
|
+
}),
|
|
128
131
|
"workflows-dir": _flag.dirPath({
|
|
132
|
+
summary: "The target directory path to find all workflows to push.",
|
|
129
133
|
dependsOn: [
|
|
130
134
|
"all"
|
|
131
135
|
]
|
|
@@ -141,9 +145,8 @@ WorkflowPush.flags = {
|
|
|
141
145
|
]
|
|
142
146
|
})
|
|
143
147
|
};
|
|
144
|
-
WorkflowPush.args =
|
|
145
|
-
{
|
|
146
|
-
name: "workflowKey",
|
|
148
|
+
WorkflowPush.args = {
|
|
149
|
+
workflowKey: _core.Args.string({
|
|
147
150
|
required: false
|
|
148
|
-
}
|
|
149
|
-
|
|
151
|
+
})
|
|
152
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>WorkflowRun
|
|
8
|
+
});
|
|
9
|
+
const _core = require("@oclif/core");
|
|
10
|
+
const _baseCommand = /*#__PURE__*/ _interopRequireDefault(require("../../lib/base-command"));
|
|
11
|
+
const _flag = require("../../lib/helpers/flag");
|
|
12
|
+
const _request = require("../../lib/helpers/request");
|
|
13
|
+
const _string = require("../../lib/helpers/string");
|
|
14
|
+
function _interopRequireDefault(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
class WorkflowRun extends _baseCommand.default {
|
|
20
|
+
async run() {
|
|
21
|
+
const { args , flags } = this.props;
|
|
22
|
+
const resp = await (0, _request.withSpinner)(()=>this.apiV1.runWorkflow(this.props), {
|
|
23
|
+
action: "‣ Running"
|
|
24
|
+
});
|
|
25
|
+
this.log(`‣ Successfully ran \`${args.workflowKey}\` workflow in \`${flags.environment}\` environment`);
|
|
26
|
+
this.log((0, _string.indentString)(`Workflow run id: ${resp.data.workflow_run_id}`, 4));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
WorkflowRun.summary = "Test run a workflow using the latest version from Knock.";
|
|
30
|
+
WorkflowRun.flags = {
|
|
31
|
+
environment: _core.Flags.string({
|
|
32
|
+
default: "development",
|
|
33
|
+
summary: "The environment in which to run the workflow"
|
|
34
|
+
}),
|
|
35
|
+
recipients: (0, _flag.maybeJsonStrAsList)({
|
|
36
|
+
required: true,
|
|
37
|
+
aliases: [
|
|
38
|
+
"recipient"
|
|
39
|
+
],
|
|
40
|
+
summary: "One or more recipient user ids separated by comma, or a JSON string containing one or more recipient object references for this workflow run."
|
|
41
|
+
}),
|
|
42
|
+
actor: (0, _flag.maybeJsonStr)({
|
|
43
|
+
summary: "An actor id, or a JSON string of an actor object reference for the workflow run."
|
|
44
|
+
}),
|
|
45
|
+
tenant: _core.Flags.string({
|
|
46
|
+
summary: "A tenant id for the workflow run."
|
|
47
|
+
}),
|
|
48
|
+
data: (0, _flag.jsonStr)({
|
|
49
|
+
summary: "A JSON string of the data for this workflow"
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
WorkflowRun.args = {
|
|
53
|
+
workflowKey: _core.Args.string({
|
|
54
|
+
required: true
|
|
55
|
+
})
|
|
56
|
+
};
|
|
@@ -103,6 +103,7 @@ class WorkflowValidate extends _baseCommand.default {
|
|
|
103
103
|
return errors;
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
+
WorkflowValidate.summary = "Validate one or more workflows from a local file system.";
|
|
106
107
|
WorkflowValidate.flags = {
|
|
107
108
|
environment: _core.Flags.string({
|
|
108
109
|
summary: "Validating a workflow is only done in the development environment",
|
|
@@ -111,16 +112,18 @@ WorkflowValidate.flags = {
|
|
|
111
112
|
_const.KnockEnv.Development
|
|
112
113
|
]
|
|
113
114
|
}),
|
|
114
|
-
all: _core.Flags.boolean(
|
|
115
|
+
all: _core.Flags.boolean({
|
|
116
|
+
summary: "Whether to validate all workflows from the target directory."
|
|
117
|
+
}),
|
|
115
118
|
"workflows-dir": _flag.dirPath({
|
|
119
|
+
summary: "The target directory path to find all workflows to validate.",
|
|
116
120
|
dependsOn: [
|
|
117
121
|
"all"
|
|
118
122
|
]
|
|
119
123
|
})
|
|
120
124
|
};
|
|
121
|
-
WorkflowValidate.args =
|
|
122
|
-
{
|
|
123
|
-
name: "workflowKey",
|
|
125
|
+
WorkflowValidate.args = {
|
|
126
|
+
workflowKey: _core.Args.string({
|
|
124
127
|
required: false
|
|
125
|
-
}
|
|
126
|
-
|
|
128
|
+
})
|
|
129
|
+
};
|
package/dist/lib/api-v1.js
CHANGED
|
@@ -79,6 +79,20 @@ class ApiV1 {
|
|
|
79
79
|
params
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
+
async runWorkflow({ args , flags }) {
|
|
83
|
+
const params = (0, _object.prune)({
|
|
84
|
+
environment: flags.environment
|
|
85
|
+
});
|
|
86
|
+
const data = (0, _object.prune)({
|
|
87
|
+
recipients: flags.recipients,
|
|
88
|
+
tenant: flags.tenant,
|
|
89
|
+
data: flags.data,
|
|
90
|
+
actor: flags.actor
|
|
91
|
+
});
|
|
92
|
+
return this.put(`/workflows/${args.workflowKey}/run`, data, {
|
|
93
|
+
params
|
|
94
|
+
});
|
|
95
|
+
}
|
|
82
96
|
// By resources: Commits
|
|
83
97
|
async commitAllChanges({ flags }) {
|
|
84
98
|
const params = (0, _object.prune)({
|
package/dist/lib/base-command.js
CHANGED
|
@@ -60,21 +60,25 @@ class BaseCommand extends _core.Command {
|
|
|
60
60
|
// 1. Load user's config from the config dir, as available.
|
|
61
61
|
await _userConfig.default.load(this.config.configDir);
|
|
62
62
|
// 2. Parse flags and args, must come after the user config load.
|
|
63
|
-
|
|
63
|
+
const { args , flags } = await this.parse(this.ctor);
|
|
64
|
+
this.props = {
|
|
65
|
+
args: args,
|
|
66
|
+
flags: flags
|
|
67
|
+
};
|
|
64
68
|
// 3. Instantiate a knock api client.
|
|
65
69
|
this.apiV1 = new _apiV1.default(this.props.flags, this.config);
|
|
66
70
|
// 4. Load the run context of the invoked command.
|
|
67
71
|
this.runContext = await _runContext.load(this.id);
|
|
68
72
|
}
|
|
69
73
|
}
|
|
70
|
-
//
|
|
71
|
-
BaseCommand.
|
|
74
|
+
// Base flags are inherited by any command that extends BaseCommand.
|
|
75
|
+
BaseCommand.baseFlags = {
|
|
72
76
|
// Evaluated in the following precedence:
|
|
73
77
|
// - service token flag passed into the command
|
|
74
78
|
// - if not provided, fall back to env variable
|
|
75
79
|
// - if not available, fall back to user config
|
|
76
80
|
"service-token": _core.Flags.string({
|
|
77
|
-
summary: "The service token to authenticate with",
|
|
81
|
+
summary: "The service token to authenticate with.",
|
|
78
82
|
required: true,
|
|
79
83
|
multiple: false,
|
|
80
84
|
env: "KNOCK_SERVICE_TOKEN",
|
package/dist/lib/helpers/flag.js
CHANGED
|
@@ -10,11 +10,15 @@ function _export(target, all) {
|
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
12
|
booleanStr: ()=>booleanStr,
|
|
13
|
-
dirPath: ()=>dirPath
|
|
13
|
+
dirPath: ()=>dirPath,
|
|
14
|
+
jsonStr: ()=>jsonStr,
|
|
15
|
+
maybeJsonStr: ()=>maybeJsonStr,
|
|
16
|
+
maybeJsonStrAsList: ()=>maybeJsonStrAsList
|
|
14
17
|
});
|
|
15
18
|
const _nodePath = /*#__PURE__*/ _interopRequireWildcard(require("node:path"));
|
|
16
19
|
const _core = require("@oclif/core");
|
|
17
20
|
const _fsExtra = /*#__PURE__*/ _interopRequireWildcard(require("fs-extra"));
|
|
21
|
+
const _json = require("./json");
|
|
18
22
|
function _getRequireWildcardCache(nodeInterop) {
|
|
19
23
|
if (typeof WeakMap !== "function") return null;
|
|
20
24
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -74,3 +78,28 @@ const dirPath = _core.Flags.custom({
|
|
|
74
78
|
};
|
|
75
79
|
}
|
|
76
80
|
});
|
|
81
|
+
const jsonStr = _core.Flags.custom({
|
|
82
|
+
parse: async (input)=>{
|
|
83
|
+
try {
|
|
84
|
+
const data = JSON.parse(input);
|
|
85
|
+
return data;
|
|
86
|
+
} catch {
|
|
87
|
+
throw new Error(`${input} is not a valid JSON string.`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
const maybeJsonStr = _core.Flags.custom({
|
|
92
|
+
parse: async (input)=>{
|
|
93
|
+
return (0, _json.tryJsonParse)(input);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
const maybeJsonStrAsList = _core.Flags.custom({
|
|
97
|
+
parse: async (input)=>{
|
|
98
|
+
const data = (0, _json.tryJsonParse)(input);
|
|
99
|
+
if (typeof data === "string") return data.split(",");
|
|
100
|
+
if (Array.isArray(data)) return data;
|
|
101
|
+
return [
|
|
102
|
+
data
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
});
|
package/dist/lib/helpers/json.js
CHANGED
|
@@ -11,6 +11,7 @@ function _export(target, all) {
|
|
|
11
11
|
_export(exports, {
|
|
12
12
|
DOUBLE_SPACES: ()=>DOUBLE_SPACES,
|
|
13
13
|
parseJson: ()=>parseJson,
|
|
14
|
+
tryJsonParse: ()=>tryJsonParse,
|
|
14
15
|
readJson: ()=>readJson
|
|
15
16
|
});
|
|
16
17
|
const _jsonlint = /*#__PURE__*/ _interopRequireWildcard(require("@prantlf/jsonlint"));
|
|
@@ -71,6 +72,14 @@ const parseJson = (json)=>{
|
|
|
71
72
|
errors
|
|
72
73
|
];
|
|
73
74
|
};
|
|
75
|
+
const tryJsonParse = (maybeJson)=>{
|
|
76
|
+
try {
|
|
77
|
+
const data = JSON.parse(maybeJson);
|
|
78
|
+
return data;
|
|
79
|
+
} catch {
|
|
80
|
+
return maybeJson;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
74
83
|
const readJson = async (filePath)=>{
|
|
75
84
|
const json = await _fsExtra.readFile(filePath, "utf8");
|
|
76
85
|
return parseJson(json);
|
package/dist/lib/helpers/page.js
CHANGED
|
@@ -28,9 +28,14 @@ function _interopRequireDefault(obj) {
|
|
|
28
28
|
}
|
|
29
29
|
const MAX_PAGINATION_LIMIT = 100;
|
|
30
30
|
const pageFlags = {
|
|
31
|
-
after: _core.Flags.string(
|
|
32
|
-
|
|
31
|
+
after: _core.Flags.string({
|
|
32
|
+
summary: "The cursor after which to fetch the next page."
|
|
33
|
+
}),
|
|
34
|
+
before: _core.Flags.string({
|
|
35
|
+
summary: "The cursor before which to fetch the previous page."
|
|
36
|
+
}),
|
|
33
37
|
limit: _core.Flags.integer({
|
|
38
|
+
summary: "The total number of entries to fetch per page.",
|
|
34
39
|
max: MAX_PAGINATION_LIMIT
|
|
35
40
|
})
|
|
36
41
|
};
|
|
@@ -38,7 +38,7 @@ const withSpinner = async (requestFn, opts = {})=>{
|
|
|
38
38
|
// Error out before the action stop so the spinner can update accordingly.
|
|
39
39
|
if (ensureSuccess && !isSuccessResp(resp)) {
|
|
40
40
|
const message = formatErrorRespMessage(resp);
|
|
41
|
-
_core.
|
|
41
|
+
_core.ux.error(new _error.ApiError(message));
|
|
42
42
|
}
|
|
43
43
|
_ux.spinner.stop();
|
|
44
44
|
return resp;
|
package/dist/lib/helpers/ux.js
CHANGED
|
@@ -34,9 +34,9 @@ const promptToConfirm = async (message)=>{
|
|
|
34
34
|
};
|
|
35
35
|
const spinner = {
|
|
36
36
|
start (action) {
|
|
37
|
-
if (!_const.isTestEnv) _core.
|
|
37
|
+
if (!_const.isTestEnv) _core.ux.action.start(action);
|
|
38
38
|
},
|
|
39
39
|
stop () {
|
|
40
|
-
_core.
|
|
40
|
+
_core.ux.action.stop();
|
|
41
41
|
}
|
|
42
42
|
};
|
|
@@ -9,6 +9,7 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
+
translationRefDescription: ()=>translationRefDescription,
|
|
12
13
|
formatLanguage: ()=>formatLanguage,
|
|
13
14
|
formatRef: ()=>formatRef,
|
|
14
15
|
isValidLocale: ()=>isValidLocale,
|
|
@@ -67,6 +68,11 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
67
68
|
}
|
|
68
69
|
return newObj;
|
|
69
70
|
}
|
|
71
|
+
const translationRefDescription = `
|
|
72
|
+
Translation ref is a identifier string that refers to a unique translation.
|
|
73
|
+
If a translation has no namespace, it is the same as the locale, e.g. \`en\`.
|
|
74
|
+
If namespaced, it is formatted as namespace.locale, e.g. \`admin.en\`.
|
|
75
|
+
`.trim();
|
|
70
76
|
const formatLanguage = (translation)=>{
|
|
71
77
|
const lang = _localeCodes.default.getByTag(translation.locale_code);
|
|
72
78
|
return lang.location ? `${lang.name}, ${lang.location}` : lang.name;
|
|
@@ -113,11 +119,11 @@ const ensureValidCommandTarget = async (props, runContext)=>{
|
|
|
113
119
|
const { commandId , resourceDir: resourceDirCtx , cwd: runCwd } = runContext;
|
|
114
120
|
// Error, trying to run the command not in a translation directory.
|
|
115
121
|
if (resourceDirCtx && resourceDirCtx.type !== "translation") {
|
|
116
|
-
return _core.
|
|
122
|
+
return _core.ux.error(`Cannot run ${commandId} inside a ${resourceDirCtx.type} directory`);
|
|
117
123
|
}
|
|
118
124
|
// Error, got neither the translationRef arg nor the --all flag.
|
|
119
125
|
if (!args.translationRef && !flags.all) {
|
|
120
|
-
_core.
|
|
126
|
+
_core.ux.error("At least one of translation ref arg or --all flag must be given");
|
|
121
127
|
}
|
|
122
128
|
// No translationRef arg, which means --all flag is used.
|
|
123
129
|
if (!args.translationRef) {
|
|
@@ -143,12 +149,12 @@ const ensureValidCommandTarget = async (props, runContext)=>{
|
|
|
143
149
|
// From this point on, we have translationRef so parse and validate the format.
|
|
144
150
|
const parsedRef = parseTranslationRef(args.translationRef);
|
|
145
151
|
if (!parsedRef) {
|
|
146
|
-
return _core.
|
|
152
|
+
return _core.ux.error(`Invalid translation ref \`${args.translationRef}\`, use valid <locale> or <namespace>.<locale> for namespaced translations`);
|
|
147
153
|
}
|
|
148
154
|
const { localeCode , namespace } = parsedRef;
|
|
149
155
|
// If we are in the translation dir, make sure the locale matches.
|
|
150
156
|
if (resourceDirCtx && resourceDirCtx.key !== localeCode) {
|
|
151
|
-
return _core.
|
|
157
|
+
return _core.ux.error(`Cannot run ${commandId} with \`${args.translationRef}\` inside a ${resourceDirCtx.key} directory`);
|
|
152
158
|
}
|
|
153
159
|
const targetDirPath = resourceDirCtx ? resourceDirCtx.abspath : _nodePath.resolve(runCwd, localeCode);
|
|
154
160
|
// Got translationRef arg but no --all flag, which means target only a single
|
|
@@ -163,7 +169,7 @@ const ensureValidCommandTarget = async (props, runContext)=>{
|
|
|
163
169
|
// From this point on, we have both translationRef and --all flag used
|
|
164
170
|
// together, so make sure we are targeting a non-namespaced top-level locale.
|
|
165
171
|
if (namespace) {
|
|
166
|
-
return _core.
|
|
172
|
+
return _core.ux.error(`Cannot use --all with a namespaced translation \`${args.translationRef}\``);
|
|
167
173
|
}
|
|
168
174
|
const translationDirCtx = {
|
|
169
175
|
type: "translation",
|
|
@@ -92,7 +92,7 @@ const readAllForCommandTarget = async (target)=>{
|
|
|
92
92
|
const { type: targetType , context: targetCtx } = target;
|
|
93
93
|
if (!targetCtx.exists) {
|
|
94
94
|
const subject = targetType === "translationFile" ? "a translation file at" : "translation files in";
|
|
95
|
-
return _core.
|
|
95
|
+
return _core.ux.error(`Cannot locate ${subject} \`${targetCtx.abspath}\``);
|
|
96
96
|
}
|
|
97
97
|
switch(targetType){
|
|
98
98
|
case "translationFile":
|