@knocklabs/cli 0.1.21 → 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 +141 -41
- 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/pull.js +157 -0
- package/dist/commands/push.js +175 -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 +32 -0
- package/oclif.manifest.json +961 -260
- package/package.json +8 -8
- package/dist/lib/type-generator.js +0 -100
|
@@ -0,0 +1,171 @@
|
|
|
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 GuidePush;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@oclif/core");
|
|
12
|
+
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
13
|
+
const _const = require("../../lib/helpers/const");
|
|
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 _request = require("../../lib/helpers/request");
|
|
18
|
+
const _string = require("../../lib/helpers/string");
|
|
19
|
+
const _ux = require("../../lib/helpers/ux");
|
|
20
|
+
const _guide = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/marshal/guide"));
|
|
21
|
+
const _validate = /*#__PURE__*/ _interop_require_default(require("./validate"));
|
|
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 GuidePush extends _basecommand.default {
|
|
82
|
+
async run() {
|
|
83
|
+
const { flags } = this.props;
|
|
84
|
+
// 1. First read all guide directories found for the given command.
|
|
85
|
+
const target = await _guide.ensureValidCommandTarget(this.props, this.runContext);
|
|
86
|
+
const [guides, readErrors] = await _guide.readAllForCommandTarget(target, {
|
|
87
|
+
withExtractedFiles: true
|
|
88
|
+
});
|
|
89
|
+
if (readErrors.length > 0) {
|
|
90
|
+
this.error((0, _error.formatErrors)(readErrors, {
|
|
91
|
+
prependBy: "\n\n"
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
if (guides.length === 0) {
|
|
95
|
+
this.error(`No guide directories found in ${target.context.abspath}`);
|
|
96
|
+
}
|
|
97
|
+
// 2. Then validate them all ahead of pushing them.
|
|
98
|
+
_ux.spinner.start(`‣ Validating`);
|
|
99
|
+
const apiErrors = await _validate.default.validateAll(this.apiV1, this.props, guides);
|
|
100
|
+
if (apiErrors.length > 0) {
|
|
101
|
+
this.error((0, _error.formatErrors)(apiErrors, {
|
|
102
|
+
prependBy: "\n\n"
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
_ux.spinner.stop();
|
|
106
|
+
// 3. Finally push up each guide, abort on the first error.
|
|
107
|
+
_ux.spinner.start(`‣ Pushing`);
|
|
108
|
+
for (const guide of guides){
|
|
109
|
+
const props = (0, _objectisomorphic.merge)(this.props, {
|
|
110
|
+
flags: {
|
|
111
|
+
annotate: true
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
// eslint-disable-next-line no-await-in-loop
|
|
115
|
+
const resp = await this.apiV1.upsertGuide(props, {
|
|
116
|
+
...guide.content,
|
|
117
|
+
key: guide.key
|
|
118
|
+
});
|
|
119
|
+
if ((0, _request.isSuccessResp)(resp)) {
|
|
120
|
+
// Update the guide directory with the successfully pushed guide
|
|
121
|
+
// payload from the server.
|
|
122
|
+
// eslint-disable-next-line no-await-in-loop
|
|
123
|
+
await _guide.writeGuideDirFromData(guide, resp.data.guide);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const error = new _error.SourceError((0, _request.formatErrorRespMessage)(resp), _guide.guideJsonPath(guide), "ApiError");
|
|
127
|
+
this.error((0, _error.formatError)(error));
|
|
128
|
+
}
|
|
129
|
+
_ux.spinner.stop();
|
|
130
|
+
// 4. Display a success message.
|
|
131
|
+
const guideKeys = guides.map((g)=>g.key);
|
|
132
|
+
const actioned = flags.commit ? "pushed and committed" : "pushed";
|
|
133
|
+
this.log(`‣ Successfully ${actioned} ${guides.length} guide(s):\n` + (0, _string.indentString)(guideKeys.join("\n"), 4));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Hide until guides are released in GA.
|
|
137
|
+
_define_property(GuidePush, "hidden", true);
|
|
138
|
+
_define_property(GuidePush, "summary", "Push one or more guides from a local file system to Knock.");
|
|
139
|
+
_define_property(GuidePush, "flags", {
|
|
140
|
+
environment: _core.Flags.string({
|
|
141
|
+
summary: "Pushing a guide is only allowed in the development environment",
|
|
142
|
+
default: _const.KnockEnv.Development,
|
|
143
|
+
options: [
|
|
144
|
+
_const.KnockEnv.Development
|
|
145
|
+
]
|
|
146
|
+
}),
|
|
147
|
+
all: _core.Flags.boolean({
|
|
148
|
+
summary: "Whether to push all guides from the target directory."
|
|
149
|
+
}),
|
|
150
|
+
"guides-dir": _flag.dirPath({
|
|
151
|
+
summary: "The target directory path to find all guides to push.",
|
|
152
|
+
dependsOn: [
|
|
153
|
+
"all"
|
|
154
|
+
]
|
|
155
|
+
}),
|
|
156
|
+
commit: _core.Flags.boolean({
|
|
157
|
+
summary: "Push and commit the guide(s) at the same time"
|
|
158
|
+
}),
|
|
159
|
+
"commit-message": _core.Flags.string({
|
|
160
|
+
summary: "Use the given value as the commit message",
|
|
161
|
+
char: "m",
|
|
162
|
+
dependsOn: [
|
|
163
|
+
"commit"
|
|
164
|
+
]
|
|
165
|
+
})
|
|
166
|
+
});
|
|
167
|
+
_define_property(GuidePush, "args", {
|
|
168
|
+
guideKey: _core.Args.string({
|
|
169
|
+
required: false
|
|
170
|
+
})
|
|
171
|
+
});
|
|
@@ -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 GuideValidate;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@oclif/core");
|
|
12
|
+
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
13
|
+
const _const = require("../../lib/helpers/const");
|
|
14
|
+
const _error = require("../../lib/helpers/error");
|
|
15
|
+
const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
|
|
16
|
+
const _request = require("../../lib/helpers/request");
|
|
17
|
+
const _string = require("../../lib/helpers/string");
|
|
18
|
+
const _ux = require("../../lib/helpers/ux");
|
|
19
|
+
const _guide = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/marshal/guide"));
|
|
20
|
+
function _define_property(obj, key, value) {
|
|
21
|
+
if (key in obj) {
|
|
22
|
+
Object.defineProperty(obj, key, {
|
|
23
|
+
value: value,
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
obj[key] = value;
|
|
30
|
+
}
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
function _interop_require_default(obj) {
|
|
34
|
+
return obj && obj.__esModule ? obj : {
|
|
35
|
+
default: obj
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
39
|
+
if (typeof WeakMap !== "function") return null;
|
|
40
|
+
var cacheBabelInterop = new WeakMap();
|
|
41
|
+
var cacheNodeInterop = new WeakMap();
|
|
42
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
43
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
44
|
+
})(nodeInterop);
|
|
45
|
+
}
|
|
46
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
47
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
48
|
+
return obj;
|
|
49
|
+
}
|
|
50
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
51
|
+
return {
|
|
52
|
+
default: obj
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
56
|
+
if (cache && cache.has(obj)) {
|
|
57
|
+
return cache.get(obj);
|
|
58
|
+
}
|
|
59
|
+
var newObj = {
|
|
60
|
+
__proto__: null
|
|
61
|
+
};
|
|
62
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
63
|
+
for(var key in obj){
|
|
64
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
65
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
66
|
+
if (desc && (desc.get || desc.set)) {
|
|
67
|
+
Object.defineProperty(newObj, key, desc);
|
|
68
|
+
} else {
|
|
69
|
+
newObj[key] = obj[key];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
newObj.default = obj;
|
|
74
|
+
if (cache) {
|
|
75
|
+
cache.set(obj, newObj);
|
|
76
|
+
}
|
|
77
|
+
return newObj;
|
|
78
|
+
}
|
|
79
|
+
class GuideValidate extends _basecommand.default {
|
|
80
|
+
async run() {
|
|
81
|
+
// 1. Read all guide directories found for the given command.
|
|
82
|
+
const target = await _guide.ensureValidCommandTarget(this.props, this.runContext);
|
|
83
|
+
const [guides, readErrors] = await _guide.readAllForCommandTarget(target, {
|
|
84
|
+
withExtractedFiles: true
|
|
85
|
+
});
|
|
86
|
+
if (readErrors.length > 0) {
|
|
87
|
+
this.error((0, _error.formatErrors)(readErrors, {
|
|
88
|
+
prependBy: "\n\n"
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
if (guides.length === 0) {
|
|
92
|
+
this.error(`No guide directories found in ${target.context.abspath}`);
|
|
93
|
+
}
|
|
94
|
+
// 2. Validate each guide data.
|
|
95
|
+
_ux.spinner.start(`‣ Validating`);
|
|
96
|
+
const apiErrors = await GuideValidate.validateAll(this.apiV1, this.props, guides);
|
|
97
|
+
if (apiErrors.length > 0) {
|
|
98
|
+
this.error((0, _error.formatErrors)(apiErrors, {
|
|
99
|
+
prependBy: "\n\n"
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
_ux.spinner.stop();
|
|
103
|
+
// 3. Display a success message.
|
|
104
|
+
const guideKeys = guides.map((g)=>g.key);
|
|
105
|
+
this.log(`‣ Successfully validated ${guides.length} guide(s):\n` + (0, _string.indentString)(guideKeys.join("\n"), 4));
|
|
106
|
+
}
|
|
107
|
+
static async validateAll(api, props, guides) {
|
|
108
|
+
// TODO: Throw an error if a non validation error (e.g. authentication error)
|
|
109
|
+
// instead of printing out same error messages repeatedly.
|
|
110
|
+
const errorPromises = guides.map(async (guide)=>{
|
|
111
|
+
const resp = await api.validateGuide(props, {
|
|
112
|
+
...guide.content,
|
|
113
|
+
key: guide.key
|
|
114
|
+
});
|
|
115
|
+
if ((0, _request.isSuccessResp)(resp)) return;
|
|
116
|
+
const error = new _error.SourceError((0, _request.formatErrorRespMessage)(resp), _guide.guideJsonPath(guide), "ApiError");
|
|
117
|
+
return error;
|
|
118
|
+
});
|
|
119
|
+
const errors = (await Promise.all(errorPromises)).filter((e)=>Boolean(e));
|
|
120
|
+
return errors;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
_define_property(GuideValidate, "summary", "Validate one or more guides from a local file system.");
|
|
124
|
+
// Hide until guides are released in GA.
|
|
125
|
+
_define_property(GuideValidate, "hidden", true);
|
|
126
|
+
_define_property(GuideValidate, "flags", {
|
|
127
|
+
environment: _core.Flags.string({
|
|
128
|
+
summary: "Validating a guide is only done in the development environment",
|
|
129
|
+
default: _const.KnockEnv.Development,
|
|
130
|
+
options: [
|
|
131
|
+
_const.KnockEnv.Development
|
|
132
|
+
]
|
|
133
|
+
}),
|
|
134
|
+
all: _core.Flags.boolean({
|
|
135
|
+
summary: "Whether to validate all guides from the target directory."
|
|
136
|
+
}),
|
|
137
|
+
"guides-dir": _flag.dirPath({
|
|
138
|
+
summary: "The target directory path to find all guides to validate.",
|
|
139
|
+
dependsOn: [
|
|
140
|
+
"all"
|
|
141
|
+
]
|
|
142
|
+
})
|
|
143
|
+
});
|
|
144
|
+
_define_property(GuideValidate, "args", {
|
|
145
|
+
guideKey: _core.Args.string({
|
|
146
|
+
required: false
|
|
147
|
+
})
|
|
148
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
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 Pull;
|
|
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 _flag = /*#__PURE__*/ _interop_require_wildcard(require("../lib/helpers/flag"));
|
|
15
|
+
const _ux = require("../lib/helpers/ux");
|
|
16
|
+
const _resources = require("../lib/resources");
|
|
17
|
+
const _pull = /*#__PURE__*/ _interop_require_default(require("./layout/pull"));
|
|
18
|
+
const _pull1 = /*#__PURE__*/ _interop_require_default(require("./partial/pull"));
|
|
19
|
+
const _pull2 = /*#__PURE__*/ _interop_require_default(require("./translation/pull"));
|
|
20
|
+
const _pull3 = /*#__PURE__*/ _interop_require_default(require("./workflow/pull"));
|
|
21
|
+
function _define_property(obj, key, value) {
|
|
22
|
+
if (key in obj) {
|
|
23
|
+
Object.defineProperty(obj, key, {
|
|
24
|
+
value: value,
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
obj[key] = value;
|
|
31
|
+
}
|
|
32
|
+
return obj;
|
|
33
|
+
}
|
|
34
|
+
function _interop_require_default(obj) {
|
|
35
|
+
return obj && obj.__esModule ? obj : {
|
|
36
|
+
default: obj
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
40
|
+
if (typeof WeakMap !== "function") return null;
|
|
41
|
+
var cacheBabelInterop = new WeakMap();
|
|
42
|
+
var cacheNodeInterop = new WeakMap();
|
|
43
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
44
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
45
|
+
})(nodeInterop);
|
|
46
|
+
}
|
|
47
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
48
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
49
|
+
return obj;
|
|
50
|
+
}
|
|
51
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
52
|
+
return {
|
|
53
|
+
default: obj
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
57
|
+
if (cache && cache.has(obj)) {
|
|
58
|
+
return cache.get(obj);
|
|
59
|
+
}
|
|
60
|
+
var newObj = {
|
|
61
|
+
__proto__: null
|
|
62
|
+
};
|
|
63
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
64
|
+
for(var key in obj){
|
|
65
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
66
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
67
|
+
if (desc && (desc.get || desc.set)) {
|
|
68
|
+
Object.defineProperty(newObj, key, desc);
|
|
69
|
+
} else {
|
|
70
|
+
newObj[key] = obj[key];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
newObj.default = obj;
|
|
75
|
+
if (cache) {
|
|
76
|
+
cache.set(obj, newObj);
|
|
77
|
+
}
|
|
78
|
+
return newObj;
|
|
79
|
+
}
|
|
80
|
+
class Pull extends _basecommand.default {
|
|
81
|
+
async run() {
|
|
82
|
+
const { flags } = this.props;
|
|
83
|
+
const targetDirCtx = flags["knock-dir"];
|
|
84
|
+
const prompt = targetDirCtx.exists ? `Pull latest resources into ${targetDirCtx.abspath}?\n This will overwrite the contents of this directory.` : `Create a new resources directory at ${targetDirCtx.abspath}?`;
|
|
85
|
+
const input = flags.force || await (0, _ux.promptToConfirm)(prompt);
|
|
86
|
+
if (!input) return;
|
|
87
|
+
const args = [
|
|
88
|
+
"--all",
|
|
89
|
+
"--environment",
|
|
90
|
+
flags.environment,
|
|
91
|
+
...flags["hide-uncommitted-changes"] ? [
|
|
92
|
+
"--hide-uncommitted-changes"
|
|
93
|
+
] : [],
|
|
94
|
+
...flags["service-token"] ? [
|
|
95
|
+
"--service-token",
|
|
96
|
+
flags["service-token"]
|
|
97
|
+
] : [],
|
|
98
|
+
// Always use the force flag to skip prompts
|
|
99
|
+
"--force"
|
|
100
|
+
];
|
|
101
|
+
for (const resourceType of _resources.ALL_RESOURCE_TYPES){
|
|
102
|
+
// eslint-disable-next-line no-await-in-loop
|
|
103
|
+
await runResourcePullCommand(resourceType, targetDirCtx, args);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
_define_property(Pull, "summary", "Pull all resources from an environment into a local file system.");
|
|
108
|
+
_define_property(Pull, "flags", {
|
|
109
|
+
environment: _core.Flags.string({
|
|
110
|
+
default: "development",
|
|
111
|
+
summary: "The environment to use."
|
|
112
|
+
}),
|
|
113
|
+
"knock-dir": _flag.dirPath({
|
|
114
|
+
summary: "The target directory path to pull all resources into.",
|
|
115
|
+
required: true
|
|
116
|
+
}),
|
|
117
|
+
"hide-uncommitted-changes": _core.Flags.boolean({
|
|
118
|
+
summary: "Hide any uncommitted changes."
|
|
119
|
+
}),
|
|
120
|
+
force: _core.Flags.boolean({
|
|
121
|
+
summary: "Remove the confirmation prompt."
|
|
122
|
+
})
|
|
123
|
+
});
|
|
124
|
+
const runResourcePullCommand = async (resourceType, targetDirCtx, args)=>{
|
|
125
|
+
const subdirPath = _nodepath.resolve(targetDirCtx.abspath, _resources.RESOURCE_SUBDIRS[resourceType]);
|
|
126
|
+
switch(resourceType){
|
|
127
|
+
case "email_layout":
|
|
128
|
+
return _pull.default.run([
|
|
129
|
+
...args,
|
|
130
|
+
"--layouts-dir",
|
|
131
|
+
subdirPath
|
|
132
|
+
]);
|
|
133
|
+
case "partial":
|
|
134
|
+
return _pull1.default.run([
|
|
135
|
+
...args,
|
|
136
|
+
"--partials-dir",
|
|
137
|
+
subdirPath
|
|
138
|
+
]);
|
|
139
|
+
case "translation":
|
|
140
|
+
return _pull2.default.run([
|
|
141
|
+
...args,
|
|
142
|
+
"--translations-dir",
|
|
143
|
+
subdirPath
|
|
144
|
+
]);
|
|
145
|
+
case "workflow":
|
|
146
|
+
return _pull3.default.run([
|
|
147
|
+
...args,
|
|
148
|
+
"--workflows-dir",
|
|
149
|
+
subdirPath
|
|
150
|
+
]);
|
|
151
|
+
default:
|
|
152
|
+
{
|
|
153
|
+
const invalidResourceType = resourceType;
|
|
154
|
+
throw new Error(`Unknown resource type: ${invalidResourceType}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
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 Push;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _nodepath = /*#__PURE__*/ _interop_require_wildcard(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 _flag = /*#__PURE__*/ _interop_require_wildcard(require("../lib/helpers/flag"));
|
|
17
|
+
const _resources = require("../lib/resources");
|
|
18
|
+
const _push = /*#__PURE__*/ _interop_require_default(require("./layout/push"));
|
|
19
|
+
const _push1 = /*#__PURE__*/ _interop_require_default(require("./partial/push"));
|
|
20
|
+
const _push2 = /*#__PURE__*/ _interop_require_default(require("./translation/push"));
|
|
21
|
+
const _push3 = /*#__PURE__*/ _interop_require_default(require("./workflow/push"));
|
|
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 Push extends _basecommand.default {
|
|
82
|
+
async run() {
|
|
83
|
+
const { flags } = this.props;
|
|
84
|
+
const targetDirCtx = flags["knock-dir"];
|
|
85
|
+
if (!targetDirCtx.exists) {
|
|
86
|
+
this.error(`Directory ${targetDirCtx.abspath} does not exist`);
|
|
87
|
+
}
|
|
88
|
+
const args = [
|
|
89
|
+
"--all",
|
|
90
|
+
"--environment",
|
|
91
|
+
flags.environment,
|
|
92
|
+
...flags["service-token"] ? [
|
|
93
|
+
"--service-token",
|
|
94
|
+
flags["service-token"]
|
|
95
|
+
] : [],
|
|
96
|
+
...flags.commit ? [
|
|
97
|
+
"--commit"
|
|
98
|
+
] : [],
|
|
99
|
+
...flags["commit-message"] ? [
|
|
100
|
+
"--commit-message",
|
|
101
|
+
flags["commit-message"]
|
|
102
|
+
] : []
|
|
103
|
+
];
|
|
104
|
+
// Note: Because we're pushing the different resource types sequentially,
|
|
105
|
+
// if one of the push commands fails, we may end up in a partially pushed
|
|
106
|
+
// state, with only some of the resources upserted. This is the best we can
|
|
107
|
+
// do until we have a bulk push mAPI endpoint.
|
|
108
|
+
for (const resourceType of _resources.ALL_RESOURCE_TYPES){
|
|
109
|
+
// eslint-disable-next-line no-await-in-loop
|
|
110
|
+
await runResourcePushCommand(resourceType, targetDirCtx, args);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
_define_property(Push, "summary", "Push all resources from a local file system to Knock.");
|
|
115
|
+
_define_property(Push, "flags", {
|
|
116
|
+
environment: _core.Flags.string({
|
|
117
|
+
summary: "Pushing resources is only allowed in the development environment",
|
|
118
|
+
default: _const.KnockEnv.Development,
|
|
119
|
+
options: [
|
|
120
|
+
_const.KnockEnv.Development
|
|
121
|
+
]
|
|
122
|
+
}),
|
|
123
|
+
"knock-dir": _flag.dirPath({
|
|
124
|
+
summary: "The target directory path to find all resources to push.",
|
|
125
|
+
required: true
|
|
126
|
+
}),
|
|
127
|
+
commit: _core.Flags.boolean({
|
|
128
|
+
summary: "Push and commit the resource(s) at the same time"
|
|
129
|
+
}),
|
|
130
|
+
"commit-message": _core.Flags.string({
|
|
131
|
+
summary: "Use the given value as the commit message",
|
|
132
|
+
char: "m",
|
|
133
|
+
dependsOn: [
|
|
134
|
+
"commit"
|
|
135
|
+
]
|
|
136
|
+
})
|
|
137
|
+
});
|
|
138
|
+
const runResourcePushCommand = async (resourceType, targetDirCtx, args)=>{
|
|
139
|
+
const subdirPath = _nodepath.resolve(targetDirCtx.abspath, _resources.RESOURCE_SUBDIRS[resourceType]);
|
|
140
|
+
const hasResources = await _fsextra.pathExists(subdirPath);
|
|
141
|
+
if (!hasResources) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
switch(resourceType){
|
|
145
|
+
case "email_layout":
|
|
146
|
+
return _push.default.run([
|
|
147
|
+
...args,
|
|
148
|
+
"--layouts-dir",
|
|
149
|
+
subdirPath
|
|
150
|
+
]);
|
|
151
|
+
case "partial":
|
|
152
|
+
return _push1.default.run([
|
|
153
|
+
...args,
|
|
154
|
+
"--partials-dir",
|
|
155
|
+
subdirPath
|
|
156
|
+
]);
|
|
157
|
+
case "translation":
|
|
158
|
+
return _push2.default.run([
|
|
159
|
+
...args,
|
|
160
|
+
"--translations-dir",
|
|
161
|
+
subdirPath
|
|
162
|
+
]);
|
|
163
|
+
case "workflow":
|
|
164
|
+
return _push3.default.run([
|
|
165
|
+
...args,
|
|
166
|
+
"--workflows-dir",
|
|
167
|
+
subdirPath
|
|
168
|
+
]);
|
|
169
|
+
default:
|
|
170
|
+
{
|
|
171
|
+
const invalidResourceType = resourceType;
|
|
172
|
+
throw new Error(`Unknown resource type: ${invalidResourceType}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
@@ -17,8 +17,9 @@ const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers
|
|
|
17
17
|
const _objectisomorphic = require("../../lib/helpers/object.isomorphic");
|
|
18
18
|
const _page = require("../../lib/helpers/page");
|
|
19
19
|
const _request = require("../../lib/helpers/request");
|
|
20
|
+
const _typegen = require("../../lib/helpers/typegen");
|
|
20
21
|
const _ux = require("../../lib/helpers/ux");
|
|
21
|
-
const
|
|
22
|
+
const _workflow = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/marshal/workflow"));
|
|
22
23
|
function _define_property(obj, key, value) {
|
|
23
24
|
if (key in obj) {
|
|
24
25
|
Object.defineProperty(obj, key, {
|
|
@@ -82,17 +83,17 @@ class WorkflowGenerateTypes extends _basecommand.default {
|
|
|
82
83
|
async run() {
|
|
83
84
|
const { flags } = this.props;
|
|
84
85
|
const fileExtension = flags["output-file"].abspath.split(".").pop();
|
|
85
|
-
const targetLanguage = (0,
|
|
86
|
+
const targetLanguage = (0, _typegen.getLanguageFromExtension)(fileExtension);
|
|
86
87
|
if (!targetLanguage) {
|
|
87
88
|
this.error(new _error.ApiError(`Unsupported file extension: ${fileExtension}. We currently support .ts, .rb, .go, .py files only.`));
|
|
88
89
|
}
|
|
89
90
|
_ux.spinner.start(`‣ Loading workflows`);
|
|
90
|
-
// 1. List all workflows in the
|
|
91
|
+
// 1. List all workflows in the target environment.
|
|
91
92
|
const workflows = await this.listAllWorkflows();
|
|
92
93
|
_ux.spinner.stop();
|
|
93
94
|
// 2. Generate types for all workflows.
|
|
94
95
|
_ux.spinner.start(`‣ Generating types`);
|
|
95
|
-
const { result, workflows: workflowsWithValidTypes } = await
|
|
96
|
+
const { result, workflows: workflowsWithValidTypes } = await _workflow.generateWorkflowTypes(workflows, targetLanguage);
|
|
96
97
|
_ux.spinner.stop();
|
|
97
98
|
if (!result) {
|
|
98
99
|
this.log(`‣ No workflows with valid trigger data JSON schema found, skipping type generation`);
|
|
@@ -125,7 +126,7 @@ class WorkflowGenerateTypes extends _basecommand.default {
|
|
|
125
126
|
}, workflows) : workflows;
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
|
-
_define_property(WorkflowGenerateTypes, "description", "Generate types for all workflows in
|
|
129
|
+
_define_property(WorkflowGenerateTypes, "description", "Generate types for all workflows in an environment and write them to a file.");
|
|
129
130
|
_define_property(WorkflowGenerateTypes, "flags", {
|
|
130
131
|
environment: _core.Flags.string({
|
|
131
132
|
summary: "Select the environment to generate types for.",
|