@knocklabs/cli 0.1.22 → 0.1.23
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 +102 -43
- package/dist/commands/commit/list.js +21 -1
- package/dist/commands/guide/activate.js +121 -0
- package/dist/commands/guide/generate-types.js +148 -0
- package/dist/commands/guide/get.js +139 -0
- package/dist/commands/guide/list.js +112 -0
- package/dist/commands/guide/pull.js +209 -0
- package/dist/commands/guide/push.js +171 -0
- package/dist/commands/guide/validate.js +148 -0
- package/dist/commands/workflow/generate-types.js +6 -5
- package/dist/lib/api-v1.js +61 -0
- package/dist/lib/helpers/const.js +4 -4
- package/dist/lib/helpers/date.js +3 -3
- package/dist/lib/helpers/error.js +8 -8
- package/dist/lib/helpers/flag.js +7 -7
- package/dist/lib/helpers/json.js +5 -5
- package/dist/lib/helpers/object.isomorphic.js +8 -8
- package/dist/lib/helpers/page.js +9 -9
- package/dist/lib/helpers/request.js +4 -4
- package/dist/lib/helpers/string.js +3 -3
- package/dist/lib/helpers/typegen.js +59 -0
- package/dist/lib/helpers/ux.js +3 -3
- package/dist/lib/marshal/email-layout/helpers.js +5 -5
- package/dist/lib/marshal/email-layout/processor.isomorphic.js +3 -3
- package/dist/lib/marshal/email-layout/reader.js +5 -5
- package/dist/lib/marshal/email-layout/writer.js +4 -4
- package/dist/lib/marshal/guide/helpers.js +283 -0
- package/dist/lib/marshal/guide/index.js +3 -0
- package/dist/lib/marshal/guide/processor.isomorphic.js +3 -3
- package/dist/lib/marshal/guide/reader.js +193 -0
- package/dist/lib/marshal/guide/writer.js +175 -0
- package/dist/lib/marshal/index.isomorphic.js +7 -7
- package/dist/lib/marshal/message-type/helpers.js +5 -5
- package/dist/lib/marshal/message-type/processor.isomorphic.js +3 -3
- package/dist/lib/marshal/message-type/reader.js +5 -5
- package/dist/lib/marshal/message-type/writer.js +4 -4
- package/dist/lib/marshal/partial/helpers.js +5 -5
- package/dist/lib/marshal/partial/processor.isomorphic.js +3 -3
- package/dist/lib/marshal/partial/reader.js +5 -5
- package/dist/lib/marshal/partial/writer.js +4 -4
- package/dist/lib/marshal/shared/const.isomorphic.js +3 -3
- package/dist/lib/marshal/shared/helpers.isomorphic.js +9 -2
- package/dist/lib/marshal/shared/helpers.js +4 -4
- package/dist/lib/marshal/translation/helpers.js +10 -10
- package/dist/lib/marshal/translation/processor.isomorphic.js +6 -6
- package/dist/lib/marshal/translation/writer.js +3 -3
- package/dist/lib/marshal/workflow/generator.js +4 -4
- package/dist/lib/marshal/workflow/helpers.js +53 -10
- package/dist/lib/marshal/workflow/processor.isomorphic.js +5 -5
- package/dist/lib/marshal/workflow/reader.js +5 -5
- package/dist/lib/marshal/workflow/writer.js +5 -5
- package/dist/lib/resources.js +3 -3
- package/oclif.manifest.json +615 -54
- package/package.json +8 -8
- package/dist/lib/type-generator.js +0 -100
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return GuideGenerateTypes;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
|
|
12
|
+
const _core = require("@oclif/core");
|
|
13
|
+
const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
|
|
14
|
+
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
15
|
+
const _const = require("../../lib/helpers/const");
|
|
16
|
+
const _error = require("../../lib/helpers/error");
|
|
17
|
+
const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
|
|
18
|
+
const _objectisomorphic = require("../../lib/helpers/object.isomorphic");
|
|
19
|
+
const _page = require("../../lib/helpers/page");
|
|
20
|
+
const _request = require("../../lib/helpers/request");
|
|
21
|
+
const _typegen = require("../../lib/helpers/typegen");
|
|
22
|
+
const _ux = require("../../lib/helpers/ux");
|
|
23
|
+
const _guide = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/marshal/guide"));
|
|
24
|
+
function _define_property(obj, key, value) {
|
|
25
|
+
if (key in obj) {
|
|
26
|
+
Object.defineProperty(obj, key, {
|
|
27
|
+
value: value,
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true
|
|
31
|
+
});
|
|
32
|
+
} else {
|
|
33
|
+
obj[key] = value;
|
|
34
|
+
}
|
|
35
|
+
return obj;
|
|
36
|
+
}
|
|
37
|
+
function _interop_require_default(obj) {
|
|
38
|
+
return obj && obj.__esModule ? obj : {
|
|
39
|
+
default: obj
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
43
|
+
if (typeof WeakMap !== "function") return null;
|
|
44
|
+
var cacheBabelInterop = new WeakMap();
|
|
45
|
+
var cacheNodeInterop = new WeakMap();
|
|
46
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
47
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
48
|
+
})(nodeInterop);
|
|
49
|
+
}
|
|
50
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
51
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
52
|
+
return obj;
|
|
53
|
+
}
|
|
54
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
55
|
+
return {
|
|
56
|
+
default: obj
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
60
|
+
if (cache && cache.has(obj)) {
|
|
61
|
+
return cache.get(obj);
|
|
62
|
+
}
|
|
63
|
+
var newObj = {
|
|
64
|
+
__proto__: null
|
|
65
|
+
};
|
|
66
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
67
|
+
for(var key in obj){
|
|
68
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
69
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
70
|
+
if (desc && (desc.get || desc.set)) {
|
|
71
|
+
Object.defineProperty(newObj, key, desc);
|
|
72
|
+
} else {
|
|
73
|
+
newObj[key] = obj[key];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
newObj.default = obj;
|
|
78
|
+
if (cache) {
|
|
79
|
+
cache.set(obj, newObj);
|
|
80
|
+
}
|
|
81
|
+
return newObj;
|
|
82
|
+
}
|
|
83
|
+
const supportedExts = _typegen.supportedExtensions.join(", ");
|
|
84
|
+
class GuideGenerateTypes extends _basecommand.default {
|
|
85
|
+
async run() {
|
|
86
|
+
const { flags } = this.props;
|
|
87
|
+
const outputFilePath = flags["output-file"].abspath;
|
|
88
|
+
const extension = _nodepath.default.extname(outputFilePath);
|
|
89
|
+
const targetLang = (0, _typegen.getLanguageFromExtension)(extension);
|
|
90
|
+
if (!targetLang) {
|
|
91
|
+
this.error(new _error.ApiError(`Unsupported file extension: ${extension}. We currently support ${supportedExts} files only.`));
|
|
92
|
+
}
|
|
93
|
+
_ux.spinner.start(`‣ Loading guides`);
|
|
94
|
+
// 1. List all guides in the target environment.
|
|
95
|
+
const guides = await this.listAllGuides();
|
|
96
|
+
_ux.spinner.stop();
|
|
97
|
+
// 2. Generate types for all guides and its step contents.
|
|
98
|
+
_ux.spinner.start(`‣ Generating types`);
|
|
99
|
+
const { result, count, mapping } = await _guide.generateTypes(guides, targetLang);
|
|
100
|
+
_ux.spinner.stop();
|
|
101
|
+
if (!result) {
|
|
102
|
+
this.log(`‣ No guides with content JSON schema found, skipping type generation`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
// 3. Write the generated types to the output file.
|
|
106
|
+
await _fsextra.outputFile(outputFilePath, result.lines.join("\n"));
|
|
107
|
+
// 4. If for typescript, render and append the types index at the end.
|
|
108
|
+
if (targetLang === "typescript") {
|
|
109
|
+
const lines = _guide.generateIndexTypeTS(mapping);
|
|
110
|
+
await _fsextra.appendFile(outputFilePath, lines.join("\n"));
|
|
111
|
+
}
|
|
112
|
+
this.log(`‣ Successfully generated types for ${count} message type(s) and wrote them to ${outputFilePath}`);
|
|
113
|
+
}
|
|
114
|
+
async listAllGuides(pageParams = {}, guidesFetchedSoFar = []) {
|
|
115
|
+
const props = (0, _objectisomorphic.merge)(this.props, {
|
|
116
|
+
flags: {
|
|
117
|
+
...pageParams,
|
|
118
|
+
limit: _page.MAX_PAGINATION_LIMIT,
|
|
119
|
+
// Generate json schemas for guide contents so we can generate types.
|
|
120
|
+
"include-json-schema": true
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
const resp = await this.apiV1.listGuides(props);
|
|
124
|
+
if (!(0, _request.isSuccessResp)(resp)) {
|
|
125
|
+
const message = (0, _request.formatErrorRespMessage)(resp);
|
|
126
|
+
this.error(new _error.ApiError(message));
|
|
127
|
+
}
|
|
128
|
+
const { entries, page_info: pageInfo } = resp.data;
|
|
129
|
+
const guides = [
|
|
130
|
+
...guidesFetchedSoFar,
|
|
131
|
+
...entries
|
|
132
|
+
];
|
|
133
|
+
return pageInfo.after ? this.listAllGuides({
|
|
134
|
+
after: pageInfo.after
|
|
135
|
+
}, guides) : guides;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
_define_property(GuideGenerateTypes, "description", "Generate types for all guides in an environment and write them to a file.");
|
|
139
|
+
_define_property(GuideGenerateTypes, "flags", {
|
|
140
|
+
environment: _core.Flags.string({
|
|
141
|
+
summary: "Select the environment to generate types for.",
|
|
142
|
+
default: _const.KnockEnv.Development
|
|
143
|
+
}),
|
|
144
|
+
"output-file": _flag.filePath({
|
|
145
|
+
summary: `The output file to write the generated types to. We currently support ${supportedExts} files only. Your file extension will determine the target language for the generated types.`,
|
|
146
|
+
required: true
|
|
147
|
+
})
|
|
148
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return GuideGet;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@oclif/core");
|
|
12
|
+
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
13
|
+
const _date = require("../../lib/helpers/date");
|
|
14
|
+
const _error = require("../../lib/helpers/error");
|
|
15
|
+
const _request = require("../../lib/helpers/request");
|
|
16
|
+
const _ux = require("../../lib/helpers/ux");
|
|
17
|
+
const _conditions = require("../../lib/marshal/conditions");
|
|
18
|
+
const _helpers = require("../../lib/marshal/guide/helpers");
|
|
19
|
+
function _define_property(obj, key, value) {
|
|
20
|
+
if (key in obj) {
|
|
21
|
+
Object.defineProperty(obj, key, {
|
|
22
|
+
value: value,
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
obj[key] = value;
|
|
29
|
+
}
|
|
30
|
+
return obj;
|
|
31
|
+
}
|
|
32
|
+
function _interop_require_default(obj) {
|
|
33
|
+
return obj && obj.__esModule ? obj : {
|
|
34
|
+
default: obj
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
class GuideGet extends _basecommand.default {
|
|
38
|
+
async run() {
|
|
39
|
+
_ux.spinner.start("‣ Loading");
|
|
40
|
+
const { guide } = await this.loadGuide();
|
|
41
|
+
_ux.spinner.stop();
|
|
42
|
+
const { flags } = this.props;
|
|
43
|
+
if (flags.json) return guide;
|
|
44
|
+
this.render(guide);
|
|
45
|
+
}
|
|
46
|
+
async loadGuide() {
|
|
47
|
+
const guideResp = await this.apiV1.getGuide(this.props);
|
|
48
|
+
if (!(0, _request.isSuccessResp)(guideResp)) {
|
|
49
|
+
const message = (0, _request.formatErrorRespMessage)(guideResp);
|
|
50
|
+
_core.ux.error(new _error.ApiError(message));
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
guide: guideResp.data
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
render(guide) {
|
|
57
|
+
const { guideKey } = this.props.args;
|
|
58
|
+
const { environment: env, "hide-uncommitted-changes": committedOnly } = this.props.flags;
|
|
59
|
+
const qualifier = env === "development" && !committedOnly ? "(including uncommitted)" : "";
|
|
60
|
+
this.log(`‣ Showing guide \`${guideKey}\` in \`${env}\` environment ${qualifier}\n`);
|
|
61
|
+
/*
|
|
62
|
+
* Guide table
|
|
63
|
+
*/ const rows = [
|
|
64
|
+
{
|
|
65
|
+
key: "Name",
|
|
66
|
+
value: guide.name
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
key: "Key",
|
|
70
|
+
value: guide.key
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
key: "Type",
|
|
74
|
+
value: guide.type || "-"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: "Status",
|
|
78
|
+
value: (0, _helpers.formatStatusWithSchedule)(guide)
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
key: "Description",
|
|
82
|
+
value: guide.description || "-"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
key: "Content",
|
|
86
|
+
value: guide.steps.length > 0 ? (0, _helpers.formatStep)(guide.steps[0]) : "-"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
key: "Targeting audience",
|
|
90
|
+
value: guide.target_audience_key || "(All users)"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
key: "Targeting conditions",
|
|
94
|
+
value: guide.target_property_conditions ? (0, _conditions.formatConditions)(guide.target_property_conditions) : "-"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
key: "Activation",
|
|
98
|
+
value: (0, _helpers.formatActivationRules)(guide.activation_location_rules)
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
key: "Created at",
|
|
102
|
+
value: (0, _date.formatDateTime)(guide.created_at)
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
key: "Updated at",
|
|
106
|
+
value: (0, _date.formatDateTime)(guide.updated_at)
|
|
107
|
+
}
|
|
108
|
+
];
|
|
109
|
+
_core.ux.table(rows, {
|
|
110
|
+
key: {
|
|
111
|
+
header: "Guide",
|
|
112
|
+
minWidth: 24
|
|
113
|
+
},
|
|
114
|
+
value: {
|
|
115
|
+
header: "",
|
|
116
|
+
minWidth: 24
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
this.log("");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
_define_property(GuideGet, "summary", "Display a single guide from an environment.");
|
|
123
|
+
// Hide until guides are released in GA.
|
|
124
|
+
_define_property(GuideGet, "hidden", true);
|
|
125
|
+
_define_property(GuideGet, "flags", {
|
|
126
|
+
environment: _core.Flags.string({
|
|
127
|
+
default: "development",
|
|
128
|
+
summary: "The environment to use."
|
|
129
|
+
}),
|
|
130
|
+
"hide-uncommitted-changes": _core.Flags.boolean({
|
|
131
|
+
summary: "Hide any uncommitted changes."
|
|
132
|
+
})
|
|
133
|
+
});
|
|
134
|
+
_define_property(GuideGet, "args", {
|
|
135
|
+
guideKey: _core.Args.string({
|
|
136
|
+
required: true
|
|
137
|
+
})
|
|
138
|
+
});
|
|
139
|
+
_define_property(GuideGet, "enableJsonFlag", true);
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return GuideList;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@oclif/core");
|
|
12
|
+
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
13
|
+
const _date = require("../../lib/helpers/date");
|
|
14
|
+
const _objectisomorphic = require("../../lib/helpers/object.isomorphic");
|
|
15
|
+
const _page = require("../../lib/helpers/page");
|
|
16
|
+
const _request = require("../../lib/helpers/request");
|
|
17
|
+
const _helpers = require("../../lib/marshal/guide/helpers");
|
|
18
|
+
function _define_property(obj, key, value) {
|
|
19
|
+
if (key in obj) {
|
|
20
|
+
Object.defineProperty(obj, key, {
|
|
21
|
+
value: value,
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true
|
|
25
|
+
});
|
|
26
|
+
} else {
|
|
27
|
+
obj[key] = value;
|
|
28
|
+
}
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
31
|
+
function _interop_require_default(obj) {
|
|
32
|
+
return obj && obj.__esModule ? obj : {
|
|
33
|
+
default: obj
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
class GuideList extends _basecommand.default {
|
|
37
|
+
async run() {
|
|
38
|
+
const resp = await this.request();
|
|
39
|
+
const { flags } = this.props;
|
|
40
|
+
if (flags.json) return resp.data;
|
|
41
|
+
this.render(resp.data);
|
|
42
|
+
}
|
|
43
|
+
async request(pageParams = {}) {
|
|
44
|
+
const props = (0, _objectisomorphic.merge)(this.props, {
|
|
45
|
+
flags: {
|
|
46
|
+
...pageParams
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return (0, _request.withSpinner)(()=>this.apiV1.listGuides(props));
|
|
50
|
+
}
|
|
51
|
+
async render(data) {
|
|
52
|
+
const { entries } = data;
|
|
53
|
+
const { environment: env, "hide-uncommitted-changes": committedOnly } = this.props.flags;
|
|
54
|
+
const qualifier = env === "development" && !committedOnly ? "(including uncommitted)" : "";
|
|
55
|
+
this.log(`‣ Showing ${entries.length} guides in \`${env}\` environment ${qualifier}\n`);
|
|
56
|
+
/*
|
|
57
|
+
* Guides list table
|
|
58
|
+
*/ _core.ux.table(entries, {
|
|
59
|
+
key: {
|
|
60
|
+
header: "Key"
|
|
61
|
+
},
|
|
62
|
+
name: {
|
|
63
|
+
header: "Name"
|
|
64
|
+
},
|
|
65
|
+
type: {
|
|
66
|
+
header: "Type",
|
|
67
|
+
get: (entry)=>entry.type || "-"
|
|
68
|
+
},
|
|
69
|
+
channel: {
|
|
70
|
+
header: "Channel",
|
|
71
|
+
get: (entry)=>entry.channel_key || "-"
|
|
72
|
+
},
|
|
73
|
+
status: {
|
|
74
|
+
header: "Status",
|
|
75
|
+
get: (entry)=>(0, _helpers.formatStatusWithSchedule)(entry)
|
|
76
|
+
},
|
|
77
|
+
description: {
|
|
78
|
+
header: "Description",
|
|
79
|
+
get: (entry)=>entry.description || "-"
|
|
80
|
+
},
|
|
81
|
+
updated_at: {
|
|
82
|
+
header: "Updated at",
|
|
83
|
+
get: (entry)=>(0, _date.formatDate)(entry.updated_at)
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
return this.prompt(data);
|
|
87
|
+
}
|
|
88
|
+
async prompt(data) {
|
|
89
|
+
const { page_info } = data;
|
|
90
|
+
const pageAction = await (0, _page.maybePromptPageAction)(page_info);
|
|
91
|
+
const pageParams = pageAction && (0, _page.paramsForPageAction)(pageAction, page_info);
|
|
92
|
+
if (pageParams) {
|
|
93
|
+
this.log("\n");
|
|
94
|
+
const resp = await this.request(pageParams);
|
|
95
|
+
return this.render(resp.data);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
_define_property(GuideList, "summary", "Display all guides for an environment.");
|
|
100
|
+
// Hide until guides are released in GA.
|
|
101
|
+
_define_property(GuideList, "hidden", true);
|
|
102
|
+
_define_property(GuideList, "flags", {
|
|
103
|
+
environment: _core.Flags.string({
|
|
104
|
+
default: "development",
|
|
105
|
+
summary: "The environment to use."
|
|
106
|
+
}),
|
|
107
|
+
"hide-uncommitted-changes": _core.Flags.boolean({
|
|
108
|
+
summary: "Hide any uncommitted changes."
|
|
109
|
+
}),
|
|
110
|
+
..._page.pageFlags
|
|
111
|
+
});
|
|
112
|
+
_define_property(GuideList, "enableJsonFlag", true);
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return GuidePull;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _nodepath = /*#__PURE__*/ _interop_require_wildcard(require("node:path"));
|
|
12
|
+
const _core = require("@oclif/core");
|
|
13
|
+
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
14
|
+
const _error = require("../../lib/helpers/error");
|
|
15
|
+
const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
|
|
16
|
+
const _objectisomorphic = require("../../lib/helpers/object.isomorphic");
|
|
17
|
+
const _page = require("../../lib/helpers/page");
|
|
18
|
+
const _request = require("../../lib/helpers/request");
|
|
19
|
+
const _ux = require("../../lib/helpers/ux");
|
|
20
|
+
const _guide = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/marshal/guide"));
|
|
21
|
+
const _runcontext = require("../../lib/run-context");
|
|
22
|
+
function _define_property(obj, key, value) {
|
|
23
|
+
if (key in obj) {
|
|
24
|
+
Object.defineProperty(obj, key, {
|
|
25
|
+
value: value,
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
obj[key] = value;
|
|
32
|
+
}
|
|
33
|
+
return obj;
|
|
34
|
+
}
|
|
35
|
+
function _interop_require_default(obj) {
|
|
36
|
+
return obj && obj.__esModule ? obj : {
|
|
37
|
+
default: obj
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
41
|
+
if (typeof WeakMap !== "function") return null;
|
|
42
|
+
var cacheBabelInterop = new WeakMap();
|
|
43
|
+
var cacheNodeInterop = new WeakMap();
|
|
44
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
45
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
46
|
+
})(nodeInterop);
|
|
47
|
+
}
|
|
48
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
49
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
50
|
+
return obj;
|
|
51
|
+
}
|
|
52
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
53
|
+
return {
|
|
54
|
+
default: obj
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
58
|
+
if (cache && cache.has(obj)) {
|
|
59
|
+
return cache.get(obj);
|
|
60
|
+
}
|
|
61
|
+
var newObj = {
|
|
62
|
+
__proto__: null
|
|
63
|
+
};
|
|
64
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
65
|
+
for(var key in obj){
|
|
66
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
67
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
68
|
+
if (desc && (desc.get || desc.set)) {
|
|
69
|
+
Object.defineProperty(newObj, key, desc);
|
|
70
|
+
} else {
|
|
71
|
+
newObj[key] = obj[key];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
newObj.default = obj;
|
|
76
|
+
if (cache) {
|
|
77
|
+
cache.set(obj, newObj);
|
|
78
|
+
}
|
|
79
|
+
return newObj;
|
|
80
|
+
}
|
|
81
|
+
class GuidePull extends _basecommand.default {
|
|
82
|
+
async run() {
|
|
83
|
+
const { args, flags } = this.props;
|
|
84
|
+
if (flags.all && args.guideKey) {
|
|
85
|
+
return this.error(`guideKey arg \`${args.guideKey}\` cannot also be provided when using --all`);
|
|
86
|
+
}
|
|
87
|
+
return flags.all ? this.pullAllGuides() : this.pullOneGuide();
|
|
88
|
+
}
|
|
89
|
+
async pullOneGuide() {
|
|
90
|
+
const { flags } = this.props;
|
|
91
|
+
const dirContext = await this.getGuideDirContext();
|
|
92
|
+
if (dirContext.exists) {
|
|
93
|
+
this.log(`‣ Found \`${dirContext.key}\` at ${dirContext.abspath}`);
|
|
94
|
+
} else {
|
|
95
|
+
const prompt = `Create a new guide directory \`${dirContext.key}\` at ${dirContext.abspath}?`;
|
|
96
|
+
const input = flags.force || await (0, _ux.promptToConfirm)(prompt);
|
|
97
|
+
if (!input) return;
|
|
98
|
+
}
|
|
99
|
+
const resp = await (0, _request.withSpinner)(()=>{
|
|
100
|
+
const props = (0, _objectisomorphic.merge)(this.props, {
|
|
101
|
+
args: {
|
|
102
|
+
guideKey: dirContext.key
|
|
103
|
+
},
|
|
104
|
+
flags: {
|
|
105
|
+
annotate: true
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return this.apiV1.getGuide(props);
|
|
109
|
+
});
|
|
110
|
+
await _guide.writeGuideDirFromData(dirContext, resp.data);
|
|
111
|
+
const action = dirContext.exists ? "updated" : "created";
|
|
112
|
+
this.log(`‣ Successfully ${action} \`${dirContext.key}\` at ${dirContext.abspath}`);
|
|
113
|
+
}
|
|
114
|
+
async pullAllGuides() {
|
|
115
|
+
const { flags } = this.props;
|
|
116
|
+
const defaultToCwd = {
|
|
117
|
+
abspath: this.runContext.cwd,
|
|
118
|
+
exists: true
|
|
119
|
+
};
|
|
120
|
+
const targetDirCtx = flags["guides-dir"] || defaultToCwd;
|
|
121
|
+
const prompt = targetDirCtx.exists ? `Pull latest guides into ${targetDirCtx.abspath}?\n This will overwrite the contents of this directory.` : `Create a new guides directory at ${targetDirCtx.abspath}?`;
|
|
122
|
+
const input = flags.force || await (0, _ux.promptToConfirm)(prompt);
|
|
123
|
+
if (!input) return;
|
|
124
|
+
_ux.spinner.start(`‣ Loading`);
|
|
125
|
+
const guides = await this.listAllGuides();
|
|
126
|
+
await _guide.writeGuidesIndexDir(targetDirCtx, guides);
|
|
127
|
+
_ux.spinner.stop();
|
|
128
|
+
const action = targetDirCtx.exists ? "updated" : "created";
|
|
129
|
+
this.log(`‣ Successfully ${action} the guides directory at ${targetDirCtx.abspath}`);
|
|
130
|
+
}
|
|
131
|
+
async listAllGuides(pageParams = {}, guidesFetchedSoFar = []) {
|
|
132
|
+
const props = (0, _objectisomorphic.merge)(this.props, {
|
|
133
|
+
flags: {
|
|
134
|
+
...pageParams,
|
|
135
|
+
annotate: true,
|
|
136
|
+
limit: _page.MAX_PAGINATION_LIMIT
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
const resp = await this.apiV1.listGuides(props);
|
|
140
|
+
if (!(0, _request.isSuccessResp)(resp)) {
|
|
141
|
+
const message = (0, _request.formatErrorRespMessage)(resp);
|
|
142
|
+
this.error(new _error.ApiError(message));
|
|
143
|
+
}
|
|
144
|
+
const { entries, page_info: pageInfo } = resp.data;
|
|
145
|
+
const guides = [
|
|
146
|
+
...guidesFetchedSoFar,
|
|
147
|
+
...entries
|
|
148
|
+
];
|
|
149
|
+
return pageInfo.after ? this.listAllGuides({
|
|
150
|
+
after: pageInfo.after
|
|
151
|
+
}, guides) : guides;
|
|
152
|
+
}
|
|
153
|
+
async getGuideDirContext() {
|
|
154
|
+
const { guideKey } = this.props.args;
|
|
155
|
+
const { resourceDir, cwd: runCwd } = this.runContext;
|
|
156
|
+
// Inside an existing resource dir, use it if valid for the target guide.
|
|
157
|
+
if (resourceDir) {
|
|
158
|
+
const target = {
|
|
159
|
+
commandId: _basecommand.default.id,
|
|
160
|
+
type: "guide",
|
|
161
|
+
key: guideKey
|
|
162
|
+
};
|
|
163
|
+
return (0, _runcontext.ensureResourceDirForTarget)(resourceDir, target);
|
|
164
|
+
}
|
|
165
|
+
// Not inside any existing guide directory, which means either create a
|
|
166
|
+
// new guide directory in the cwd, or update it if there is one already.
|
|
167
|
+
if (guideKey) {
|
|
168
|
+
const dirPath = _nodepath.resolve(runCwd, guideKey);
|
|
169
|
+
const exists = await _guide.isGuideDir(dirPath);
|
|
170
|
+
return {
|
|
171
|
+
type: "guide",
|
|
172
|
+
key: guideKey,
|
|
173
|
+
abspath: dirPath,
|
|
174
|
+
exists
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
// Not in any guide directory, nor a guide key arg was given so error.
|
|
178
|
+
return this.error("Missing 1 required arg:\nguideKey");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Hide until guides are released in GA.
|
|
182
|
+
_define_property(GuidePull, "hidden", true);
|
|
183
|
+
_define_property(GuidePull, "summary", "Pull one or more guides from an environment into a local file system.");
|
|
184
|
+
_define_property(GuidePull, "flags", {
|
|
185
|
+
environment: _core.Flags.string({
|
|
186
|
+
default: "development",
|
|
187
|
+
summary: "The environment to use."
|
|
188
|
+
}),
|
|
189
|
+
all: _core.Flags.boolean({
|
|
190
|
+
summary: "Whether to pull all guides from the specified environment."
|
|
191
|
+
}),
|
|
192
|
+
"guides-dir": _flag.dirPath({
|
|
193
|
+
summary: "The target directory path to pull all guides into.",
|
|
194
|
+
dependsOn: [
|
|
195
|
+
"all"
|
|
196
|
+
]
|
|
197
|
+
}),
|
|
198
|
+
"hide-uncommitted-changes": _core.Flags.boolean({
|
|
199
|
+
summary: "Hide any uncommitted changes."
|
|
200
|
+
}),
|
|
201
|
+
force: _core.Flags.boolean({
|
|
202
|
+
summary: "Remove the confirmation prompt."
|
|
203
|
+
})
|
|
204
|
+
});
|
|
205
|
+
_define_property(GuidePull, "args", {
|
|
206
|
+
guideKey: _core.Args.string({
|
|
207
|
+
required: false
|
|
208
|
+
})
|
|
209
|
+
});
|