@knocklabs/cli 0.1.4 → 0.1.6

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 CHANGED
@@ -16,7 +16,7 @@ $ npm install -g @knocklabs/cli
16
16
  $ knock COMMAND
17
17
  running command...
18
18
  $ knock (--version)
19
- @knocklabs/cli/0.1.4 linux-x64 node-v18.16.1
19
+ @knocklabs/cli/0.1.6 linux-x64 node-v18.18.0
20
20
  $ knock --help [COMMAND]
21
21
  USAGE
22
22
  $ knock COMMAND
@@ -30,6 +30,11 @@ USAGE
30
30
  * [`knock commit`](#knock-commit)
31
31
  * [`knock commit promote`](#knock-commit-promote)
32
32
  * [`knock help [COMMANDS]`](#knock-help-commands)
33
+ * [`knock layout get EMAILLAYOUTKEY`](#knock-layout-get-emaillayoutkey)
34
+ * [`knock layout list`](#knock-layout-list)
35
+ * [`knock layout pull [EMAILLAYOUTKEY]`](#knock-layout-pull-emaillayoutkey)
36
+ * [`knock layout push [EMAILLAYOUTKEY]`](#knock-layout-push-emaillayoutkey)
37
+ * [`knock layout validate [EMAILLAYOUTKEY]`](#knock-layout-validate-emaillayoutkey)
33
38
  * [`knock plugins`](#knock-plugins)
34
39
  * [`knock plugins:install PLUGIN...`](#knock-pluginsinstall-plugin)
35
40
  * [`knock plugins:inspect PLUGIN...`](#knock-pluginsinspect-plugin)
@@ -70,7 +75,7 @@ FLAGS
70
75
  --service-token=<value> (required) The service token to authenticate with.
71
76
  ```
72
77
 
73
- _See code: [dist/commands/commit/index.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.4/dist/commands/commit/index.ts)_
78
+ _See code: [dist/commands/commit/index.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/commit/index.ts)_
74
79
 
75
80
  ## `knock commit promote`
76
81
 
@@ -86,6 +91,8 @@ FLAGS
86
91
  --to=<value> (required) The destination environment to promote changes from the preceding environment.
87
92
  ```
88
93
 
94
+ _See code: [dist/commands/commit/promote.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/commit/promote.ts)_
95
+
89
96
  ## `knock help [COMMANDS]`
90
97
 
91
98
  Display help for knock.
@@ -104,7 +111,111 @@ DESCRIPTION
104
111
  Display help for knock.
105
112
  ```
106
113
 
107
- _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.11/src/commands/help.ts)_
114
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.20/src/commands/help.ts)_
115
+
116
+ ## `knock layout get EMAILLAYOUTKEY`
117
+
118
+ Display a single email layout from an environment.
119
+
120
+ ```
121
+ USAGE
122
+ $ knock layout get EMAILLAYOUTKEY --service-token <value> [--environment <value>] [--hide-uncommitted-changes]
123
+ [--json]
124
+
125
+ FLAGS
126
+ --environment=<value> [default: development] The environment to use.
127
+ --hide-uncommitted-changes Hide any uncommitted changes.
128
+ --service-token=<value> (required) The service token to authenticate with.
129
+
130
+ GLOBAL FLAGS
131
+ --json Format output as json.
132
+ ```
133
+
134
+ _See code: [dist/commands/layout/get.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/layout/get.ts)_
135
+
136
+ ## `knock layout list`
137
+
138
+ Display all email layouts for an environment.
139
+
140
+ ```
141
+ USAGE
142
+ $ knock layout list --service-token <value> [--environment <value>] [--hide-uncommitted-changes] [--after
143
+ <value>] [--before <value>] [--limit <value>] [--json]
144
+
145
+ FLAGS
146
+ --after=<value> The cursor after which to fetch the next page.
147
+ --before=<value> The cursor before which to fetch the previous page.
148
+ --environment=<value> [default: development] The environment to use.
149
+ --hide-uncommitted-changes Hide any uncommitted changes.
150
+ --limit=<value> The total number of entries to fetch per page.
151
+ --service-token=<value> (required) The service token to authenticate with.
152
+
153
+ GLOBAL FLAGS
154
+ --json Format output as json.
155
+ ```
156
+
157
+ _See code: [dist/commands/layout/list.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/layout/list.ts)_
158
+
159
+ ## `knock layout pull [EMAILLAYOUTKEY]`
160
+
161
+ Pull one or more email layouts from an environment into a local file system.
162
+
163
+ ```
164
+ USAGE
165
+ $ knock layout pull [EMAILLAYOUTKEY] --service-token <value> [--environment <value>] [--layouts-dir <value>
166
+ --all] [--hide-uncommitted-changes] [--force]
167
+
168
+ FLAGS
169
+ --all Whether to pull all email layouts from the specified environment.
170
+ --environment=<value> [default: development] The environment to use.
171
+ --force Remove the confirmation prompt.
172
+ --hide-uncommitted-changes Hide any uncommitted changes.
173
+ --layouts-dir=<value> The target directory path to pull all email layouts into.
174
+ --service-token=<value> (required) The service token to authenticate with.
175
+ ```
176
+
177
+ _See code: [dist/commands/layout/pull.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/layout/pull.ts)_
178
+
179
+ ## `knock layout push [EMAILLAYOUTKEY]`
180
+
181
+ Push one or more email layouts from a local file system to Knock.
182
+
183
+ ```
184
+ USAGE
185
+ $ knock layout push [EMAILLAYOUTKEY] --service-token <value> [--environment development] [--layouts-dir <value>
186
+ --all] [-m <value> --commit]
187
+
188
+ FLAGS
189
+ -m, --commit-message=<value> Use the given value as the commit message
190
+ --all Whether to push all layouts from the target directory.
191
+ --commit Push and commit the layout(s) at the same time
192
+ --environment=<option> [default: development] Pushing an email layout is only allowed in the development
193
+ environment
194
+ <options: development>
195
+ --layouts-dir=<value> The target directory path to find all layouts to push.
196
+ --service-token=<value> (required) The service token to authenticate with.
197
+ ```
198
+
199
+ _See code: [dist/commands/layout/push.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/layout/push.ts)_
200
+
201
+ ## `knock layout validate [EMAILLAYOUTKEY]`
202
+
203
+ Validate one or more layouts from a local file system.
204
+
205
+ ```
206
+ USAGE
207
+ $ knock layout validate [EMAILLAYOUTKEY] --service-token <value> [--environment development] [--layouts-dir <value>
208
+ --all]
209
+
210
+ FLAGS
211
+ --all Whether to validate all layouts from the target directory.
212
+ --environment=<option> [default: development] Validating a layout is only done in the development environment
213
+ <options: development>
214
+ --layouts-dir=<value> The target directory path to find all layouts to validate.
215
+ --service-token=<value> (required) The service token to authenticate with.
216
+ ```
217
+
218
+ _See code: [dist/commands/layout/validate.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/layout/validate.ts)_
108
219
 
109
220
  ## `knock plugins`
110
221
 
@@ -127,7 +238,7 @@ EXAMPLES
127
238
  $ knock plugins
128
239
  ```
129
240
 
130
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.1.6/src/commands/plugins/index.ts)_
241
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.9.1/src/commands/plugins/index.ts)_
131
242
 
132
243
  ## `knock plugins:install PLUGIN...`
133
244
 
@@ -192,6 +303,8 @@ EXAMPLES
192
303
  $ knock plugins:inspect myplugin
193
304
  ```
194
305
 
306
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.9.1/src/commands/plugins/inspect.ts)_
307
+
195
308
  ## `knock plugins:install PLUGIN...`
196
309
 
197
310
  Installs a plugin into the CLI.
@@ -230,6 +343,8 @@ EXAMPLES
230
343
  $ knock plugins:install someuser/someplugin
231
344
  ```
232
345
 
346
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.9.1/src/commands/plugins/install.ts)_
347
+
233
348
  ## `knock plugins:link PLUGIN`
234
349
 
235
350
  Links a plugin into the CLI for development.
@@ -242,8 +357,9 @@ ARGUMENTS
242
357
  PATH [default: .] path to plugin
243
358
 
244
359
  FLAGS
245
- -h, --help Show CLI help.
360
+ -h, --help Show CLI help.
246
361
  -v, --verbose
362
+ --[no-]install Install dependencies after linking the plugin.
247
363
 
248
364
  DESCRIPTION
249
365
  Links a plugin into the CLI for development.
@@ -257,6 +373,8 @@ EXAMPLES
257
373
  $ knock plugins:link myplugin
258
374
  ```
259
375
 
376
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.9.1/src/commands/plugins/link.ts)_
377
+
260
378
  ## `knock plugins:uninstall PLUGIN...`
261
379
 
262
380
  Removes a plugin from the CLI.
@@ -303,6 +421,8 @@ ALIASES
303
421
  $ knock plugins remove
304
422
  ```
305
423
 
424
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.9.1/src/commands/plugins/uninstall.ts)_
425
+
306
426
  ## `knock plugins:uninstall PLUGIN...`
307
427
 
308
428
  Removes a plugin from the CLI.
@@ -342,6 +462,8 @@ DESCRIPTION
342
462
  Update installed plugins.
343
463
  ```
344
464
 
465
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v3.9.1/src/commands/plugins/update.ts)_
466
+
345
467
  ## `knock translation get TRANSLATIONREF`
346
468
 
347
469
  Display a single translation from an environment.
@@ -365,6 +487,8 @@ GLOBAL FLAGS
365
487
  --json Format output as json.
366
488
  ```
367
489
 
490
+ _See code: [dist/commands/translation/get.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/translation/get.ts)_
491
+
368
492
  ## `knock translation list`
369
493
 
370
494
  Display all translations for an environment.
@@ -386,6 +510,8 @@ GLOBAL FLAGS
386
510
  --json Format output as json.
387
511
  ```
388
512
 
513
+ _See code: [dist/commands/translation/list.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/translation/list.ts)_
514
+
389
515
  ## `knock translation pull [TRANSLATIONREF]`
390
516
 
391
517
  Pull one or more translations from an environment into a local file system.
@@ -409,6 +535,8 @@ FLAGS
409
535
  --translations-dir=<value> The target directory path to pull all translations into.
410
536
  ```
411
537
 
538
+ _See code: [dist/commands/translation/pull.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/translation/pull.ts)_
539
+
412
540
  ## `knock translation push [TRANSLATIONREF]`
413
541
 
414
542
  Push one or more translations from a local file system to Knock.
@@ -434,6 +562,8 @@ FLAGS
434
562
  --translations-dir=<value> The target directory path to find all translations to push.
435
563
  ```
436
564
 
565
+ _See code: [dist/commands/translation/push.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/translation/push.ts)_
566
+
437
567
  ## `knock translation validate [TRANSLATIONREF]`
438
568
 
439
569
  Validate one or more translations from a local file system.
@@ -457,6 +587,8 @@ FLAGS
457
587
  --translations-dir=<value> The target directory path to find all translations to validate.
458
588
  ```
459
589
 
590
+ _See code: [dist/commands/translation/validate.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/translation/validate.ts)_
591
+
460
592
  ## `knock whoami`
461
593
 
462
594
  Verify the provided service token.
@@ -472,7 +604,7 @@ GLOBAL FLAGS
472
604
  --json Format output as json.
473
605
  ```
474
606
 
475
- _See code: [dist/commands/whoami.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.4/dist/commands/whoami.ts)_
607
+ _See code: [dist/commands/whoami.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/whoami.ts)_
476
608
 
477
609
  ## `knock workflow activate WORKFLOWKEY`
478
610
 
@@ -499,6 +631,8 @@ DESCRIPTION
499
631
  with `false` in order to deactivate it.
500
632
  ```
501
633
 
634
+ _See code: [dist/commands/workflow/activate.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/workflow/activate.ts)_
635
+
502
636
  ## `knock workflow get WORKFLOWKEY`
503
637
 
504
638
  Display a single workflow from an environment.
@@ -517,6 +651,8 @@ GLOBAL FLAGS
517
651
  --json Format output as json.
518
652
  ```
519
653
 
654
+ _See code: [dist/commands/workflow/get.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/workflow/get.ts)_
655
+
520
656
  ## `knock workflow list`
521
657
 
522
658
  Display all workflows for an environment.
@@ -538,6 +674,8 @@ GLOBAL FLAGS
538
674
  --json Format output as json.
539
675
  ```
540
676
 
677
+ _See code: [dist/commands/workflow/list.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/workflow/list.ts)_
678
+
541
679
  ## `knock workflow pull [WORKFLOWKEY]`
542
680
 
543
681
  Pull one or more workflows from an environment into a local file system.
@@ -556,6 +694,8 @@ FLAGS
556
694
  --workflows-dir=<value> The target directory path to pull all workflows into.
557
695
  ```
558
696
 
697
+ _See code: [dist/commands/workflow/pull.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/workflow/pull.ts)_
698
+
559
699
  ## `knock workflow push [WORKFLOWKEY]`
560
700
 
561
701
  Push one or more workflows from a local file system to Knock.
@@ -575,6 +715,8 @@ FLAGS
575
715
  --workflows-dir=<value> The target directory path to find all workflows to push.
576
716
  ```
577
717
 
718
+ _See code: [dist/commands/workflow/push.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/workflow/push.ts)_
719
+
578
720
  ## `knock workflow run WORKFLOWKEY`
579
721
 
580
722
  Test run a workflow using the latest version from Knock.
@@ -594,6 +736,8 @@ FLAGS
594
736
  --tenant=<value> A tenant id for the workflow run.
595
737
  ```
596
738
 
739
+ _See code: [dist/commands/workflow/run.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/workflow/run.ts)_
740
+
597
741
  ## `knock workflow validate [WORKFLOWKEY]`
598
742
 
599
743
  Validate one or more workflows from a local file system.
@@ -610,4 +754,6 @@ FLAGS
610
754
  --service-token=<value> (required) The service token to authenticate with.
611
755
  --workflows-dir=<value> The target directory path to find all workflows to validate.
612
756
  ```
757
+
758
+ _See code: [dist/commands/workflow/validate.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.6/dist/commands/workflow/validate.ts)_
613
759
  <!-- commandsstop -->
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>EmailLayoutGet
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
+ function _interopRequireDefault(obj) {
14
+ return obj && obj.__esModule ? obj : {
15
+ default: obj
16
+ };
17
+ }
18
+ class EmailLayoutGet extends _baseCommand.default {
19
+ async run() {
20
+ const { flags } = this.props;
21
+ const resp = await (0, _request.withSpinner)(()=>this.apiV1.getEmailLayout(this.props));
22
+ if (flags.json) return resp.data;
23
+ this.render(resp.data);
24
+ }
25
+ render(email_layout) {
26
+ const { emailLayoutKey } = this.props.args;
27
+ const { environment: env , "hide-uncommitted-changes": commitedOnly } = this.props.flags;
28
+ const qualifier = env === "development" && !commitedOnly ? "(including uncommitted)" : "";
29
+ this.log(`‣ Showing email layout \`${emailLayoutKey}\` in \`${env}\` environment ${qualifier}\n`);
30
+ /*
31
+ * Email layout table
32
+ */ const rows = [
33
+ {
34
+ key: "Key",
35
+ value: email_layout.key
36
+ },
37
+ {
38
+ key: "Name",
39
+ value: email_layout.name
40
+ },
41
+ {
42
+ key: "Updated at",
43
+ value: (0, _date.formatDate)(email_layout.updated_at)
44
+ },
45
+ {
46
+ key: "Created at",
47
+ value: (0, _date.formatDate)(email_layout.created_at)
48
+ }
49
+ ];
50
+ _core.ux.table(rows, {
51
+ key: {
52
+ header: "Email layout",
53
+ minWidth: 24
54
+ },
55
+ value: {
56
+ header: "",
57
+ minWidth: 16
58
+ }
59
+ });
60
+ this.log("");
61
+ if (email_layout.footer_links) {
62
+ const footerLinks = (email_layout.footer_links || []).map((link)=>({
63
+ key: link.text,
64
+ value: link.url
65
+ }));
66
+ _core.ux.table(footerLinks, {
67
+ key: {
68
+ header: "Footer Links",
69
+ minWidth: 24
70
+ },
71
+ value: {
72
+ header: "",
73
+ minWidth: 16
74
+ }
75
+ });
76
+ }
77
+ }
78
+ }
79
+ EmailLayoutGet.summary = "Display a single email layout from an environment.";
80
+ EmailLayoutGet.flags = {
81
+ environment: _core.Flags.string({
82
+ default: "development",
83
+ summary: "The environment to use."
84
+ }),
85
+ "hide-uncommitted-changes": _core.Flags.boolean({
86
+ summary: "Hide any uncommitted changes."
87
+ })
88
+ };
89
+ EmailLayoutGet.args = {
90
+ emailLayoutKey: _core.Args.string({
91
+ required: true
92
+ })
93
+ };
94
+ EmailLayoutGet.enableJsonFlag = true;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>EmailLayoutList
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 _object = require("../../lib/helpers/object");
13
+ const _page = require("../../lib/helpers/page");
14
+ const _request = require("../../lib/helpers/request");
15
+ function _interopRequireDefault(obj) {
16
+ return obj && obj.__esModule ? obj : {
17
+ default: obj
18
+ };
19
+ }
20
+ class EmailLayoutList extends _baseCommand.default {
21
+ async run() {
22
+ const resp = await this.request();
23
+ const { flags } = this.props;
24
+ if (flags.json) return resp.data;
25
+ this.render(resp.data);
26
+ }
27
+ async request(pageParams = {}) {
28
+ const props = (0, _object.merge)(this.props, {
29
+ flags: {
30
+ ...pageParams
31
+ }
32
+ });
33
+ return (0, _request.withSpinner)(()=>this.apiV1.listEmailLayouts(props));
34
+ }
35
+ async render(data) {
36
+ const { entries } = data;
37
+ const { environment: env , "hide-uncommitted-changes": commitedOnly } = this.props.flags;
38
+ const qualifier = env === "development" && !commitedOnly ? "(including uncommitted)" : "";
39
+ this.log(`‣ Showing ${entries.length} email layouts in \`${env}\` environment ${qualifier}\n`);
40
+ /*
41
+ * Email layouts table
42
+ */ _core.ux.table(entries, {
43
+ key: {
44
+ header: "Key"
45
+ },
46
+ name: {
47
+ header: "Name"
48
+ },
49
+ updated_at: {
50
+ header: "Updated at",
51
+ get: (entry)=>(0, _date.formatDate)(entry.updated_at)
52
+ },
53
+ created_at: {
54
+ header: "Created at",
55
+ get: (entry)=>(0, _date.formatDate)(entry.created_at)
56
+ }
57
+ });
58
+ return this.prompt(data);
59
+ }
60
+ async prompt(data) {
61
+ const { page_info } = data;
62
+ const pageAction = await (0, _page.maybePromptPageAction)(page_info);
63
+ const pageParams = pageAction && (0, _page.paramsForPageAction)(pageAction, page_info);
64
+ if (pageParams) {
65
+ this.log("\n");
66
+ const resp = await this.request(pageParams);
67
+ return this.render(resp.data);
68
+ }
69
+ }
70
+ }
71
+ EmailLayoutList.summary = "Display all email layouts for an environment.";
72
+ EmailLayoutList.flags = {
73
+ environment: _core.Flags.string({
74
+ default: "development",
75
+ summary: "The environment to use."
76
+ }),
77
+ "hide-uncommitted-changes": _core.Flags.boolean({
78
+ summary: "Hide any uncommitted changes."
79
+ }),
80
+ ..._page.pageFlags
81
+ };
82
+ EmailLayoutList.enableJsonFlag = true;
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>EmailLayoutPull
8
+ });
9
+ const _nodePath = /*#__PURE__*/ _interopRequireWildcard(require("node:path"));
10
+ const _core = require("@oclif/core");
11
+ const _baseCommand = /*#__PURE__*/ _interopRequireDefault(require("../../lib/base-command"));
12
+ const _error = require("../../lib/helpers/error");
13
+ const _flag = /*#__PURE__*/ _interopRequireWildcard(require("../../lib/helpers/flag"));
14
+ const _object = require("../../lib/helpers/object");
15
+ const _page = require("../../lib/helpers/page");
16
+ const _request = require("../../lib/helpers/request");
17
+ const _ux = require("../../lib/helpers/ux");
18
+ const _emailLayout = /*#__PURE__*/ _interopRequireWildcard(require("../../lib/marshal/email-layout"));
19
+ const _runContext = require("../../lib/run-context");
20
+ function _interopRequireDefault(obj) {
21
+ return obj && obj.__esModule ? obj : {
22
+ default: obj
23
+ };
24
+ }
25
+ function _getRequireWildcardCache(nodeInterop) {
26
+ if (typeof WeakMap !== "function") return null;
27
+ var cacheBabelInterop = new WeakMap();
28
+ var cacheNodeInterop = new WeakMap();
29
+ return (_getRequireWildcardCache = function(nodeInterop) {
30
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
31
+ })(nodeInterop);
32
+ }
33
+ function _interopRequireWildcard(obj, nodeInterop) {
34
+ if (!nodeInterop && obj && obj.__esModule) {
35
+ return obj;
36
+ }
37
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
38
+ return {
39
+ default: obj
40
+ };
41
+ }
42
+ var cache = _getRequireWildcardCache(nodeInterop);
43
+ if (cache && cache.has(obj)) {
44
+ return cache.get(obj);
45
+ }
46
+ var newObj = {};
47
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
48
+ for(var key in obj){
49
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
50
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
51
+ if (desc && (desc.get || desc.set)) {
52
+ Object.defineProperty(newObj, key, desc);
53
+ } else {
54
+ newObj[key] = obj[key];
55
+ }
56
+ }
57
+ }
58
+ newObj.default = obj;
59
+ if (cache) {
60
+ cache.set(obj, newObj);
61
+ }
62
+ return newObj;
63
+ }
64
+ class EmailLayoutPull extends _baseCommand.default {
65
+ async run() {
66
+ const { args , flags } = this.props;
67
+ if (flags.all && args.emailLayoutKey) {
68
+ return this.error(`emailLayoutKey arg \`${args.emailLayoutKey}\` cannot also be provided when using --all`);
69
+ }
70
+ return flags.all ? this.pullAllEmailLayouts() : this.pullOneEmailLayout();
71
+ }
72
+ // Pull one email layout
73
+ async pullOneEmailLayout() {
74
+ const { flags } = this.props;
75
+ const dirContext = await this.getEmailLayoutDirContext();
76
+ if (dirContext.exists) {
77
+ this.log(`‣ Found \`${dirContext.key}\` at ${dirContext.abspath}`);
78
+ } else {
79
+ const prompt = `Create a new email layout directory \`${dirContext.key}\` at ${dirContext.abspath}?`;
80
+ const input = flags.force || await (0, _ux.promptToConfirm)(prompt);
81
+ if (!input) return;
82
+ }
83
+ const resp = await (0, _request.withSpinner)(()=>{
84
+ const props = (0, _object.merge)(this.props, {
85
+ args: {
86
+ emailLayoutKey: dirContext.key
87
+ },
88
+ flags: {
89
+ annotate: true
90
+ }
91
+ });
92
+ return this.apiV1.getEmailLayout(props);
93
+ });
94
+ await _emailLayout.writeEmailLayoutDirFromData(dirContext, resp.data);
95
+ const action = dirContext.exists ? "updated" : "created";
96
+ this.log(`‣ Successfully ${action} \`${dirContext.key}\` at ${dirContext.abspath}`);
97
+ }
98
+ // Pull all email layouts
99
+ async pullAllEmailLayouts() {
100
+ const { flags } = this.props;
101
+ const defaultToCwd = {
102
+ abspath: this.runContext.cwd,
103
+ exists: true
104
+ };
105
+ const targetDirCtx = flags["layouts-dir"] || defaultToCwd;
106
+ const prompt = targetDirCtx.exists ? `Pull latest layouts into ${targetDirCtx.abspath}?\n This will overwrite the contents of this directory.` : `Create a new layouts directory at ${targetDirCtx.abspath}?`;
107
+ const input = flags.force || await (0, _ux.promptToConfirm)(prompt);
108
+ if (!input) return;
109
+ _ux.spinner.start(`‣ Loading`);
110
+ const emailLayouts = await this.listAllEmailLayouts();
111
+ await _emailLayout.writeEmailLayoutIndexDir(targetDirCtx, emailLayouts);
112
+ _ux.spinner.stop();
113
+ const action = targetDirCtx.exists ? "updated" : "created";
114
+ this.log(`‣ Successfully ${action} the layouts directory at ${targetDirCtx.abspath}`);
115
+ }
116
+ async listAllEmailLayouts(pageParams = {}, emailLayoutsFetchedSoFar = []) {
117
+ const props = (0, _object.merge)(this.props, {
118
+ flags: {
119
+ ...pageParams,
120
+ annotate: true,
121
+ limit: _page.MAX_PAGINATION_LIMIT
122
+ }
123
+ });
124
+ const resp = await this.apiV1.listEmailLayouts(props);
125
+ if (!(0, _request.isSuccessResp)(resp)) {
126
+ const message = (0, _request.formatErrorRespMessage)(resp);
127
+ this.error(new _error.ApiError(message));
128
+ }
129
+ const { entries , page_info: pageInfo } = resp.data;
130
+ const emailLayouts = [
131
+ ...emailLayoutsFetchedSoFar,
132
+ ...entries
133
+ ];
134
+ return pageInfo.after ? this.listAllEmailLayouts({
135
+ after: pageInfo.after
136
+ }, emailLayouts) : emailLayouts;
137
+ }
138
+ async getEmailLayoutDirContext() {
139
+ const { emailLayoutKey } = this.props.args;
140
+ const { resourceDir , cwd: runCwd } = this.runContext;
141
+ // Inside an existing resource dir, use it if valid for the target email layout.
142
+ if (resourceDir) {
143
+ const target = {
144
+ commandId: _baseCommand.default.id,
145
+ type: "email_layout",
146
+ key: emailLayoutKey
147
+ };
148
+ return (0, _runContext.ensureResourceDirForTarget)(resourceDir, target);
149
+ }
150
+ // Not inside any existing email layout directory, which means either create a
151
+ // new email layout directory in the cwd, or update it if there is one already.
152
+ if (emailLayoutKey) {
153
+ const dirPath = _nodePath.resolve(runCwd, emailLayoutKey);
154
+ const exists = await _emailLayout.isEmailLayoutDir(dirPath);
155
+ return {
156
+ type: "email_layout",
157
+ key: emailLayoutKey,
158
+ abspath: dirPath,
159
+ exists
160
+ };
161
+ }
162
+ // Not in any email layout directory, nor a email layout key arg was given so error.
163
+ return this.error("Missing 1 required arg:\nemailLayoutKey");
164
+ }
165
+ }
166
+ EmailLayoutPull.summary = "Pull one or more email layouts from an environment into a local file system.";
167
+ EmailLayoutPull.flags = {
168
+ environment: _core.Flags.string({
169
+ default: "development",
170
+ summary: "The environment to use."
171
+ }),
172
+ all: _core.Flags.boolean({
173
+ summary: "Whether to pull all email layouts from the specified environment."
174
+ }),
175
+ "layouts-dir": _flag.dirPath({
176
+ summary: "The target directory path to pull all email layouts into.",
177
+ dependsOn: [
178
+ "all"
179
+ ],
180
+ aliases: [
181
+ "email-layouts-dir"
182
+ ]
183
+ }),
184
+ "hide-uncommitted-changes": _core.Flags.boolean({
185
+ summary: "Hide any uncommitted changes."
186
+ }),
187
+ force: _core.Flags.boolean({
188
+ summary: "Remove the confirmation prompt."
189
+ })
190
+ };
191
+ EmailLayoutPull.args = {
192
+ emailLayoutKey: _core.Args.string({
193
+ required: false
194
+ })
195
+ };