@knocklabs/cli 0.1.0-rc.4 → 0.1.3
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 +172 -77
- 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 +2 -4
- package/dist/commands/translation/get.js +128 -0
- package/dist/commands/translation/list.js +57 -9
- package/dist/commands/translation/pull.js +72 -21
- package/dist/commands/translation/push.js +23 -12
- package/dist/commands/translation/validate.js +12 -8
- package/dist/commands/whoami.js +31 -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 +18 -10
- package/dist/commands/workflow/push.js +60 -47
- package/dist/commands/workflow/run.js +58 -0
- package/dist/commands/workflow/validate.js +52 -48
- package/dist/lib/api-v1.js +32 -5
- package/dist/lib/base-command.js +8 -4
- package/dist/lib/helpers/flag.js +12 -1
- 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 +21 -7
- package/dist/lib/marshal/translation/reader.js +17 -14
- package/dist/lib/marshal/translation/types.js +1 -0
- package/dist/lib/marshal/translation/writer.js +26 -16
- package/dist/lib/marshal/workflow/helpers.js +64 -2
- package/dist/lib/marshal/workflow/reader.js +62 -0
- package/dist/lib/run-context/helpers.js +2 -2
- package/oclif.manifest.json +281 -24
- package/package.json +25 -19
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>TranslationGet
|
|
8
|
+
});
|
|
9
|
+
const _core = require("@oclif/core");
|
|
10
|
+
const _baseCommand = /*#__PURE__*/ _interopRequireDefault(require("../../lib/base-command"));
|
|
11
|
+
const _date = require("../../lib/helpers/date");
|
|
12
|
+
const _request = require("../../lib/helpers/request");
|
|
13
|
+
const _translation = /*#__PURE__*/ _interopRequireWildcard(require("../../lib/marshal/translation"));
|
|
14
|
+
function _interopRequireDefault(obj) {
|
|
15
|
+
return obj && obj.__esModule ? obj : {
|
|
16
|
+
default: obj
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
20
|
+
if (typeof WeakMap !== "function") return null;
|
|
21
|
+
var cacheBabelInterop = new WeakMap();
|
|
22
|
+
var cacheNodeInterop = new WeakMap();
|
|
23
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
24
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
25
|
+
})(nodeInterop);
|
|
26
|
+
}
|
|
27
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
28
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
31
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
32
|
+
return {
|
|
33
|
+
default: obj
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
37
|
+
if (cache && cache.has(obj)) {
|
|
38
|
+
return cache.get(obj);
|
|
39
|
+
}
|
|
40
|
+
var newObj = {};
|
|
41
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
42
|
+
for(var key in obj){
|
|
43
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
44
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
45
|
+
if (desc && (desc.get || desc.set)) {
|
|
46
|
+
Object.defineProperty(newObj, key, desc);
|
|
47
|
+
} else {
|
|
48
|
+
newObj[key] = obj[key];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
newObj.default = obj;
|
|
53
|
+
if (cache) {
|
|
54
|
+
cache.set(obj, newObj);
|
|
55
|
+
}
|
|
56
|
+
return newObj;
|
|
57
|
+
}
|
|
58
|
+
class TranslationGet extends _baseCommand.default {
|
|
59
|
+
async run() {
|
|
60
|
+
const { args , flags } = this.props;
|
|
61
|
+
const parsedRef = _translation.parseTranslationRef(args.translationRef);
|
|
62
|
+
if (!parsedRef) {
|
|
63
|
+
return this.error(`Invalid translation ref \`${args.translationRef}\`, use valid <locale> or <namespace>.<locale> for namespaced translations`);
|
|
64
|
+
}
|
|
65
|
+
const resp = await (0, _request.withSpinner)(()=>this.apiV1.getTranslation(this.props, parsedRef));
|
|
66
|
+
if (flags.json) return resp.data;
|
|
67
|
+
this.render(resp.data);
|
|
68
|
+
}
|
|
69
|
+
render(translation) {
|
|
70
|
+
const { translationRef } = this.props.args;
|
|
71
|
+
const { environment: env , "hide-uncommitted-changes": commitedOnly } = this.props.flags;
|
|
72
|
+
const qualifier = env === "development" && !commitedOnly ? "(including uncommitted)" : "";
|
|
73
|
+
this.log(`‣ Showing translation \`${translationRef}\` in \`${env}\` environment ${qualifier}\n`);
|
|
74
|
+
/*
|
|
75
|
+
* Translation table
|
|
76
|
+
*/ const rows = [
|
|
77
|
+
{
|
|
78
|
+
key: "Language",
|
|
79
|
+
value: _translation.formatLanguage(translation)
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
key: "Locale",
|
|
83
|
+
value: translation.locale_code
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
key: "Namespace",
|
|
87
|
+
value: translation.namespace || "-"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
key: "Updated at",
|
|
91
|
+
value: (0, _date.formatDate)(translation.updated_at)
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
key: "Created at",
|
|
95
|
+
value: (0, _date.formatDate)(translation.created_at)
|
|
96
|
+
}
|
|
97
|
+
];
|
|
98
|
+
_core.ux.table(rows, {
|
|
99
|
+
key: {
|
|
100
|
+
header: "Translation",
|
|
101
|
+
minWidth: 24
|
|
102
|
+
},
|
|
103
|
+
value: {
|
|
104
|
+
header: "",
|
|
105
|
+
minWidth: 16
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
this.log("");
|
|
109
|
+
_core.ux.styledJSON(JSON.parse(translation.content));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
TranslationGet.summary = "Display a single translation from an environment.";
|
|
113
|
+
TranslationGet.flags = {
|
|
114
|
+
environment: _core.Flags.string({
|
|
115
|
+
default: "development",
|
|
116
|
+
summary: "The environment to use."
|
|
117
|
+
}),
|
|
118
|
+
"hide-uncommitted-changes": _core.Flags.boolean({
|
|
119
|
+
summary: "Hide any uncommitted changes."
|
|
120
|
+
})
|
|
121
|
+
};
|
|
122
|
+
TranslationGet.args = {
|
|
123
|
+
translationRef: _core.Args.string({
|
|
124
|
+
description: _translation.translationRefDescription,
|
|
125
|
+
required: true
|
|
126
|
+
})
|
|
127
|
+
};
|
|
128
|
+
TranslationGet.enableJsonFlag = true;
|
|
@@ -7,17 +7,56 @@ Object.defineProperty(exports, "default", {
|
|
|
7
7
|
get: ()=>TranslationList
|
|
8
8
|
});
|
|
9
9
|
const _core = require("@oclif/core");
|
|
10
|
-
const _localeCodes = /*#__PURE__*/ _interopRequireDefault(require("locale-codes"));
|
|
11
10
|
const _baseCommand = /*#__PURE__*/ _interopRequireDefault(require("../../lib/base-command"));
|
|
12
11
|
const _date = require("../../lib/helpers/date");
|
|
13
12
|
const _object = require("../../lib/helpers/object");
|
|
14
13
|
const _page = require("../../lib/helpers/page");
|
|
15
14
|
const _request = require("../../lib/helpers/request");
|
|
15
|
+
const _translation = /*#__PURE__*/ _interopRequireWildcard(require("../../lib/marshal/translation"));
|
|
16
16
|
function _interopRequireDefault(obj) {
|
|
17
17
|
return obj && obj.__esModule ? obj : {
|
|
18
18
|
default: obj
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
22
|
+
if (typeof WeakMap !== "function") return null;
|
|
23
|
+
var cacheBabelInterop = new WeakMap();
|
|
24
|
+
var cacheNodeInterop = new WeakMap();
|
|
25
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
26
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
27
|
+
})(nodeInterop);
|
|
28
|
+
}
|
|
29
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
30
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
34
|
+
return {
|
|
35
|
+
default: obj
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
39
|
+
if (cache && cache.has(obj)) {
|
|
40
|
+
return cache.get(obj);
|
|
41
|
+
}
|
|
42
|
+
var newObj = {};
|
|
43
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
44
|
+
for(var key in obj){
|
|
45
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
46
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
47
|
+
if (desc && (desc.get || desc.set)) {
|
|
48
|
+
Object.defineProperty(newObj, key, desc);
|
|
49
|
+
} else {
|
|
50
|
+
newObj[key] = obj[key];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
newObj.default = obj;
|
|
55
|
+
if (cache) {
|
|
56
|
+
cache.set(obj, newObj);
|
|
57
|
+
}
|
|
58
|
+
return newObj;
|
|
59
|
+
}
|
|
21
60
|
class TranslationList extends _baseCommand.default {
|
|
22
61
|
async run() {
|
|
23
62
|
const resp = await this.request();
|
|
@@ -40,16 +79,17 @@ class TranslationList extends _baseCommand.default {
|
|
|
40
79
|
this.log(`‣ Showing ${entries.length} translations in \`${env}\` environment ${qualifier}\n`);
|
|
41
80
|
/*
|
|
42
81
|
* Translations list table
|
|
43
|
-
*/ _core.
|
|
82
|
+
*/ _core.ux.table(entries, {
|
|
83
|
+
ref: {
|
|
84
|
+
header: "Ref",
|
|
85
|
+
get: (entry)=>_translation.formatRef(entry)
|
|
86
|
+
},
|
|
44
87
|
language_name: {
|
|
45
88
|
header: "Language",
|
|
46
|
-
get: (entry)=>
|
|
47
|
-
const language = _localeCodes.default.getByTag(entry.locale_code);
|
|
48
|
-
return language.location ? `${language.name}, ${language.location}` : language.name;
|
|
49
|
-
}
|
|
89
|
+
get: (entry)=>_translation.formatLanguage(entry)
|
|
50
90
|
},
|
|
51
91
|
locale_code: {
|
|
52
|
-
header: "Locale
|
|
92
|
+
header: "Locale"
|
|
53
93
|
},
|
|
54
94
|
namespace: {
|
|
55
95
|
header: "Namespace"
|
|
@@ -57,6 +97,10 @@ class TranslationList extends _baseCommand.default {
|
|
|
57
97
|
updated_at: {
|
|
58
98
|
header: "Updated at",
|
|
59
99
|
get: (entry)=>(0, _date.formatDate)(entry.updated_at)
|
|
100
|
+
},
|
|
101
|
+
created_at: {
|
|
102
|
+
header: "Created at",
|
|
103
|
+
get: (entry)=>(0, _date.formatDate)(entry.created_at)
|
|
60
104
|
}
|
|
61
105
|
});
|
|
62
106
|
return this.prompt(data);
|
|
@@ -72,11 +116,15 @@ class TranslationList extends _baseCommand.default {
|
|
|
72
116
|
}
|
|
73
117
|
}
|
|
74
118
|
}
|
|
119
|
+
TranslationList.summary = "Display all translations for an environment.";
|
|
75
120
|
TranslationList.flags = {
|
|
76
121
|
environment: _core.Flags.string({
|
|
77
|
-
default: "development"
|
|
122
|
+
default: "development",
|
|
123
|
+
summary: "The environment to use."
|
|
124
|
+
}),
|
|
125
|
+
"hide-uncommitted-changes": _core.Flags.boolean({
|
|
126
|
+
summary: "Hide any uncommitted changes."
|
|
78
127
|
}),
|
|
79
|
-
"hide-uncommitted-changes": _core.Flags.boolean(),
|
|
80
128
|
..._page.pageFlags
|
|
81
129
|
};
|
|
82
130
|
TranslationList.enableJsonFlag = true;
|
|
@@ -61,40 +61,76 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
61
61
|
}
|
|
62
62
|
class TranslationPull extends _baseCommand.default {
|
|
63
63
|
async run() {
|
|
64
|
+
const target = await _translation.ensureValidCommandTarget(this.props, this.runContext);
|
|
65
|
+
switch(target.type){
|
|
66
|
+
case "translationFile":
|
|
67
|
+
return this.pullOneTranslation(target.context);
|
|
68
|
+
case "translationDir":
|
|
69
|
+
return this.pullAllTranslationsForLocale(target.context);
|
|
70
|
+
case "translationsIndexDir":
|
|
71
|
+
return this.pullAllTranslations(target.context);
|
|
72
|
+
default:
|
|
73
|
+
throw new Error(`Invalid translation command target: ${target}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/*
|
|
77
|
+
* Pull a single translation (using TranslationFileContext)
|
|
78
|
+
*/ async pullOneTranslation(targetCtx) {
|
|
64
79
|
const { flags } = this.props;
|
|
65
|
-
|
|
66
|
-
|
|
80
|
+
if (targetCtx.exists) {
|
|
81
|
+
this.log(`‣ Found \`${targetCtx.ref}\` at ${targetCtx.abspath}`);
|
|
82
|
+
} else {
|
|
83
|
+
const prompt = `Create a new translation file \`${targetCtx.ref}\` at ${targetCtx.abspath}?`;
|
|
84
|
+
const input = flags.force || await (0, _ux.promptToConfirm)(prompt);
|
|
85
|
+
if (!input) return;
|
|
86
|
+
}
|
|
87
|
+
const resp = await (0, _request.withSpinner)(()=>this.apiV1.getTranslation(this.props, targetCtx));
|
|
88
|
+
await _translation.writeTranslationFile(targetCtx, resp.data);
|
|
89
|
+
const actioned = targetCtx.exists ? "updated" : "created";
|
|
90
|
+
this.log(`‣ Successfully ${actioned} \`${targetCtx.ref}\` at ${targetCtx.abspath}`);
|
|
67
91
|
}
|
|
68
92
|
/*
|
|
69
|
-
* Pull all translations
|
|
70
|
-
*/ async
|
|
93
|
+
* Pull all translations for a locale (using TranslationDirContext)
|
|
94
|
+
*/ async pullAllTranslationsForLocale(targetCtx) {
|
|
71
95
|
const { flags } = this.props;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
96
|
+
const prompt = targetCtx.exists ? `Pull latest \`${targetCtx.key}\` translations into ${targetCtx.abspath}?\n This will overwrite the contents of this directory.` : `Create a new \`${targetCtx.key}\` translations directory at ${targetCtx.abspath}?`;
|
|
97
|
+
const input = flags.force || await (0, _ux.promptToConfirm)(prompt);
|
|
98
|
+
if (!input) return;
|
|
99
|
+
// Fetch all translations for a given locale then write them to the local
|
|
100
|
+
// file system.
|
|
101
|
+
_ux.spinner.start(`‣ Loading`);
|
|
102
|
+
const filters = {
|
|
103
|
+
localeCode: targetCtx.key
|
|
77
104
|
};
|
|
78
|
-
const
|
|
79
|
-
|
|
105
|
+
const translations = await this.listAllTranslations(filters);
|
|
106
|
+
await _translation.writeTranslationFiles(targetCtx, translations);
|
|
107
|
+
_ux.spinner.stop();
|
|
108
|
+
const actioned = targetCtx.exists ? "updated" : "created";
|
|
109
|
+
this.log(`‣ Successfully ${actioned} the \`${targetCtx.key}\` translations directory at ${targetCtx.abspath}`);
|
|
110
|
+
}
|
|
111
|
+
/*
|
|
112
|
+
* Pull all translations (using DirContext)
|
|
113
|
+
*/ async pullAllTranslations(targetCtx) {
|
|
114
|
+
const { flags } = this.props;
|
|
115
|
+
const prompt = targetCtx.exists ? `Pull latest translations into ${targetCtx.abspath}?\n This will overwrite the contents of this directory.` : `Create a new translations directory at ${targetCtx.abspath}?`;
|
|
80
116
|
const input = flags.force || await (0, _ux.promptToConfirm)(prompt);
|
|
81
117
|
if (!input) return;
|
|
82
118
|
// Fetch all translations then write them to the local file system.
|
|
83
119
|
_ux.spinner.start(`‣ Loading`);
|
|
84
120
|
const translations = await this.listAllTranslations();
|
|
85
|
-
await _translation.
|
|
121
|
+
await _translation.writeTranslationFiles(targetCtx, translations);
|
|
86
122
|
_ux.spinner.stop();
|
|
87
|
-
const action =
|
|
88
|
-
this.log(`‣ Successfully ${action} the translations directory at ${
|
|
123
|
+
const action = targetCtx.exists ? "updated" : "created";
|
|
124
|
+
this.log(`‣ Successfully ${action} the translations directory at ${targetCtx.abspath}`);
|
|
89
125
|
}
|
|
90
|
-
async listAllTranslations(pageParams = {}, translationsFetchedSoFar = []) {
|
|
126
|
+
async listAllTranslations(filters = {}, pageParams = {}, translationsFetchedSoFar = []) {
|
|
91
127
|
const props = (0, _object.merge)(this.props, {
|
|
92
128
|
flags: {
|
|
93
129
|
...pageParams,
|
|
94
130
|
limit: _page.MAX_PAGINATION_LIMIT
|
|
95
131
|
}
|
|
96
132
|
});
|
|
97
|
-
const resp = await this.apiV1.listTranslations(props);
|
|
133
|
+
const resp = await this.apiV1.listTranslations(props, filters);
|
|
98
134
|
if (!(0, _request.isSuccessResp)(resp)) {
|
|
99
135
|
const message = (0, _request.formatErrorRespMessage)(resp);
|
|
100
136
|
this.error(new _error.ApiError(message));
|
|
@@ -104,21 +140,36 @@ class TranslationPull extends _baseCommand.default {
|
|
|
104
140
|
...translationsFetchedSoFar,
|
|
105
141
|
...entries
|
|
106
142
|
];
|
|
107
|
-
return pageInfo.after ? this.listAllTranslations({
|
|
143
|
+
return pageInfo.after ? this.listAllTranslations(filters, {
|
|
108
144
|
after: pageInfo.after
|
|
109
145
|
}, translations) : translations;
|
|
110
146
|
}
|
|
111
147
|
}
|
|
148
|
+
TranslationPull.summary = "Pull one or more translations from an environment into a local file system.";
|
|
112
149
|
TranslationPull.flags = {
|
|
113
150
|
environment: _core.Flags.string({
|
|
114
|
-
default: "development"
|
|
151
|
+
default: "development",
|
|
152
|
+
summary: "The environment to use."
|
|
153
|
+
}),
|
|
154
|
+
all: _core.Flags.boolean({
|
|
155
|
+
summary: "Whether to pull all translations from the specified environment."
|
|
115
156
|
}),
|
|
116
|
-
all: _core.Flags.boolean(),
|
|
117
157
|
"translations-dir": _flag.dirPath({
|
|
158
|
+
summary: "The target directory path to pull all translations into.",
|
|
118
159
|
dependsOn: [
|
|
119
160
|
"all"
|
|
120
161
|
]
|
|
121
162
|
}),
|
|
122
|
-
"hide-uncommitted-changes": _core.Flags.boolean(
|
|
123
|
-
|
|
163
|
+
"hide-uncommitted-changes": _core.Flags.boolean({
|
|
164
|
+
summary: "Hide any uncommitted changes."
|
|
165
|
+
}),
|
|
166
|
+
force: _core.Flags.boolean({
|
|
167
|
+
summary: "Remove the confirmation prompt."
|
|
168
|
+
})
|
|
169
|
+
};
|
|
170
|
+
TranslationPull.args = {
|
|
171
|
+
translationRef: _core.Args.string({
|
|
172
|
+
description: _translation.translationRefDescription,
|
|
173
|
+
required: false
|
|
174
|
+
})
|
|
124
175
|
};
|
|
@@ -62,9 +62,10 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
62
62
|
}
|
|
63
63
|
class TranslationPush extends _baseCommand.default {
|
|
64
64
|
async run() {
|
|
65
|
-
|
|
65
|
+
const { flags } = this.props;
|
|
66
|
+
// 1. First read all translation files found for the given command.
|
|
66
67
|
const target = await _translation.ensureValidCommandTarget(this.props, this.runContext);
|
|
67
|
-
const [translations, readErrors] = await _translation.
|
|
68
|
+
const [translations, readErrors] = await _translation.readAllForCommandTarget(target);
|
|
68
69
|
if (readErrors.length > 0) {
|
|
69
70
|
this.error((0, _error.formatErrors)(readErrors, {
|
|
70
71
|
prependBy: "\n\n"
|
|
@@ -73,13 +74,17 @@ class TranslationPush extends _baseCommand.default {
|
|
|
73
74
|
if (translations.length === 0) {
|
|
74
75
|
this.error(`No translation files found in ${target.context.abspath}`);
|
|
75
76
|
}
|
|
76
|
-
// Then validate them all ahead of pushing them.
|
|
77
|
+
// 2. Then validate them all ahead of pushing them.
|
|
77
78
|
_ux.spinner.start(`‣ Validating`);
|
|
78
79
|
const apiErrors = await _validate.default.validateAll(this.apiV1, this.props, translations);
|
|
79
80
|
if (apiErrors.length > 0) {
|
|
80
|
-
this.error((0, _error.formatErrors)(apiErrors
|
|
81
|
+
this.error((0, _error.formatErrors)(apiErrors, {
|
|
82
|
+
prependBy: "\n\n"
|
|
83
|
+
}));
|
|
81
84
|
}
|
|
82
|
-
|
|
85
|
+
_ux.spinner.stop();
|
|
86
|
+
// 3. Finally push up each translation file, abort on the first error.
|
|
87
|
+
_ux.spinner.start(`‣ Pushing`);
|
|
83
88
|
for (const translation of translations){
|
|
84
89
|
// eslint-disable-next-line no-await-in-loop
|
|
85
90
|
const resp = await this.apiV1.upsertTranslation(this.props, {
|
|
@@ -93,10 +98,13 @@ class TranslationPush extends _baseCommand.default {
|
|
|
93
98
|
this.error((0, _error.formatError)(error));
|
|
94
99
|
}
|
|
95
100
|
_ux.spinner.stop();
|
|
101
|
+
// 4. Display a success message.
|
|
96
102
|
const handledRefs = translations.map((t)=>t.ref);
|
|
97
|
-
|
|
103
|
+
const actioned = flags.commit ? "pushed and committed" : "pushed";
|
|
104
|
+
this.log(`‣ Successfully ${actioned} ${translations.length} translation(s):\n` + (0, _string.indentString)(handledRefs.join("\n"), 4));
|
|
98
105
|
}
|
|
99
106
|
}
|
|
107
|
+
TranslationPush.summary = "Push one or more translations from a local file system to Knock.";
|
|
100
108
|
TranslationPush.flags = {
|
|
101
109
|
environment: _core.Flags.string({
|
|
102
110
|
summary: "Pushing a translation is only allowed in the development environment",
|
|
@@ -105,8 +113,11 @@ TranslationPush.flags = {
|
|
|
105
113
|
_const.KnockEnv.Development
|
|
106
114
|
]
|
|
107
115
|
}),
|
|
108
|
-
all: _core.Flags.boolean(
|
|
116
|
+
all: _core.Flags.boolean({
|
|
117
|
+
summary: "Whether to push all translations from the target directory."
|
|
118
|
+
}),
|
|
109
119
|
"translations-dir": _flag.dirPath({
|
|
120
|
+
summary: "The target directory path to find all translations to push.",
|
|
110
121
|
dependsOn: [
|
|
111
122
|
"all"
|
|
112
123
|
]
|
|
@@ -122,9 +133,9 @@ TranslationPush.flags = {
|
|
|
122
133
|
]
|
|
123
134
|
})
|
|
124
135
|
};
|
|
125
|
-
TranslationPush.args =
|
|
126
|
-
{
|
|
127
|
-
|
|
136
|
+
TranslationPush.args = {
|
|
137
|
+
translationRef: _core.Args.string({
|
|
138
|
+
description: _translation.translationRefDescription,
|
|
128
139
|
required: false
|
|
129
|
-
}
|
|
130
|
-
|
|
140
|
+
})
|
|
141
|
+
};
|
|
@@ -62,7 +62,7 @@ function _interopRequireWildcard(obj, nodeInterop) {
|
|
|
62
62
|
class TranslationValidate extends _baseCommand.default {
|
|
63
63
|
async run() {
|
|
64
64
|
const target = await _translation.ensureValidCommandTarget(this.props, this.runContext);
|
|
65
|
-
const [translations, readErrors] = await _translation.
|
|
65
|
+
const [translations, readErrors] = await _translation.readAllForCommandTarget(target);
|
|
66
66
|
if (readErrors.length > 0) {
|
|
67
67
|
this.error((0, _error.formatErrors)(readErrors, {
|
|
68
68
|
prependBy: "\n\n"
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>Whoami
|
|
8
|
+
});
|
|
9
|
+
const _baseCommand = /*#__PURE__*/ _interopRequireDefault(require("../lib/base-command"));
|
|
10
|
+
const _request = require("../lib/helpers/request");
|
|
11
|
+
const _string = require("../lib/helpers/string");
|
|
12
|
+
function _interopRequireDefault(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
class Whoami extends _baseCommand.default {
|
|
18
|
+
async run() {
|
|
19
|
+
const resp = await (0, _request.withSpinner)(()=>this.apiV1.whoami());
|
|
20
|
+
const { flags } = this.props;
|
|
21
|
+
if (flags.json) return resp.data;
|
|
22
|
+
this.log(`‣ Successfully verified the provided service token:`);
|
|
23
|
+
const info = [
|
|
24
|
+
`Account name: ${resp.data.account_name}`,
|
|
25
|
+
`Service token name: ${resp.data.service_token_name}`
|
|
26
|
+
];
|
|
27
|
+
this.log((0, _string.indentString)(info.join("\n"), 4));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
Whoami.summary = "Verify the provided service token.";
|
|
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;
|