@knocklabs/cli 0.1.0-rc.0 → 0.1.0-rc.1

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.0-rc.0 darwin-arm64 node-v16.4.0
19
+ @knocklabs/cli/0.1.0-rc.1 darwin-arm64 node-v16.4.0
20
20
  $ knock --help [COMMAND]
21
21
  USAGE
22
22
  $ knock COMMAND
@@ -27,6 +27,8 @@ USAGE
27
27
  # Commands
28
28
 
29
29
  <!-- commands -->
30
+ * [`knock commit`](#knock-commit)
31
+ * [`knock commit promote`](#knock-commit-promote)
30
32
  * [`knock help [COMMANDS]`](#knock-help-commands)
31
33
  * [`knock ping`](#knock-ping)
32
34
  * [`knock plugins`](#knock-plugins)
@@ -38,10 +40,41 @@ USAGE
38
40
  * [`knock plugins:uninstall PLUGIN...`](#knock-pluginsuninstall-plugin-1)
39
41
  * [`knock plugins:uninstall PLUGIN...`](#knock-pluginsuninstall-plugin-2)
40
42
  * [`knock plugins update`](#knock-plugins-update)
43
+ * [`knock workflow activate WORKFLOWKEY`](#knock-workflow-activate-workflowkey)
41
44
  * [`knock workflow get WORKFLOWKEY`](#knock-workflow-get-workflowkey)
42
45
  * [`knock workflow list`](#knock-workflow-list)
43
46
  * [`knock workflow pull [WORKFLOWKEY]`](#knock-workflow-pull-workflowkey)
44
47
  * [`knock workflow push [WORKFLOWKEY]`](#knock-workflow-push-workflowkey)
48
+ * [`knock workflow validate [WORKFLOWKEY]`](#knock-workflow-validate-workflowkey)
49
+
50
+ ## `knock commit`
51
+
52
+ ```
53
+ USAGE
54
+ $ knock commit --service-token <value> [--environment development] [-m <value>] [--force]
55
+
56
+ FLAGS
57
+ -m, --commit-message=<value> Use the given value as the commit message
58
+ --environment=<option> [default: development] Committing changes applies to the development environment only,
59
+ use `commit promote` to promote changes to a later environment
60
+ <options: development>
61
+ --force
62
+ --service-token=<value> (required) The service token to authenticate with
63
+ ```
64
+
65
+ _See code: [dist/commands/commit/index.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.0-rc.1/dist/commands/commit/index.ts)_
66
+
67
+ ## `knock commit promote`
68
+
69
+ ```
70
+ USAGE
71
+ $ knock commit promote --service-token <value> --to <value> [--force]
72
+
73
+ FLAGS
74
+ --force
75
+ --service-token=<value> (required) The service token to authenticate with
76
+ --to=<value> (required) The destination environment to promote changes from the preceding environment
77
+ ```
45
78
 
46
79
  ## `knock help [COMMANDS]`
47
80
 
@@ -61,7 +94,7 @@ DESCRIPTION
61
94
  Display help for knock.
62
95
  ```
63
96
 
64
- _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.2/src/commands/help.ts)_
97
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.6/src/commands/help.ts)_
65
98
 
66
99
  ## `knock ping`
67
100
 
@@ -72,7 +105,7 @@ USAGE
72
105
  $ knock ping --service-token <value>
73
106
 
74
107
  FLAGS
75
- --service-token=<value> (required) service token to authenticate with
108
+ --service-token=<value> (required) The service token to authenticate with
76
109
 
77
110
  DESCRIPTION
78
111
  Ping the Knock management API to verify access.
@@ -81,7 +114,7 @@ EXAMPLES
81
114
  $ knock ping
82
115
  ```
83
116
 
84
- _See code: [dist/commands/ping.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.0-rc.0/dist/commands/ping.ts)_
117
+ _See code: [dist/commands/ping.ts](https://github.com/knocklabs/knock-cli/blob/v0.1.0-rc.1/dist/commands/ping.ts)_
85
118
 
86
119
  ## `knock plugins`
87
120
 
@@ -101,7 +134,7 @@ EXAMPLES
101
134
  $ knock plugins
102
135
  ```
103
136
 
104
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.3.0/src/commands/plugins/index.ts)_
137
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v2.3.2/src/commands/plugins/index.ts)_
105
138
 
106
139
  ## `knock plugins:install PLUGIN...`
107
140
 
@@ -316,17 +349,31 @@ DESCRIPTION
316
349
  Update installed plugins.
317
350
  ```
318
351
 
352
+ ## `knock workflow activate WORKFLOWKEY`
353
+
354
+ ```
355
+ USAGE
356
+ $ knock workflow activate WORKFLOWKEY --service-token <value> --environment <value> [--status true|false] [--force]
357
+
358
+ FLAGS
359
+ --environment=<value> (required)
360
+ --force
361
+ --service-token=<value> (required) The service token to authenticate with
362
+ --status=<option> [default: true]
363
+ <options: true|false>
364
+ ```
365
+
319
366
  ## `knock workflow get WORKFLOWKEY`
320
367
 
321
368
  ```
322
369
  USAGE
323
- $ knock workflow get [WORKFLOWKEY] --service-token <value> [--environment <value>] [--hide-uncommitted-changes]
370
+ $ knock workflow get WORKFLOWKEY --service-token <value> [--environment <value>] [--hide-uncommitted-changes]
324
371
  [--json]
325
372
 
326
373
  FLAGS
327
374
  --environment=<value> [default: development]
328
375
  --hide-uncommitted-changes
329
- --service-token=<value> (required) service token to authenticate with
376
+ --service-token=<value> (required) The service token to authenticate with
330
377
 
331
378
  GLOBAL FLAGS
332
379
  --json Format output as json.
@@ -345,7 +392,7 @@ FLAGS
345
392
  --environment=<value> [default: development]
346
393
  --hide-uncommitted-changes
347
394
  --limit=<value>
348
- --service-token=<value> (required) service token to authenticate with
395
+ --service-token=<value> (required) The service token to authenticate with
349
396
 
350
397
  GLOBAL FLAGS
351
398
  --json Format output as json.
@@ -360,18 +407,32 @@ USAGE
360
407
  FLAGS
361
408
  --environment=<value> [default: development]
362
409
  --hide-uncommitted-changes
363
- --service-token=<value> (required) service token to authenticate with
410
+ --service-token=<value> (required) The service token to authenticate with
364
411
  ```
365
412
 
366
413
  ## `knock workflow push [WORKFLOWKEY]`
367
414
 
368
415
  ```
369
416
  USAGE
370
- $ knock workflow push [WORKFLOWKEY] --service-token <value> [--environment development]
417
+ $ knock workflow push [WORKFLOWKEY] --service-token <value> [--environment development] [-m <value> --commit]
418
+
419
+ FLAGS
420
+ -m, --commit-message=<value> Use the given value as the commit message
421
+ --commit Push and commit the workflow(s) at the same time
422
+ --environment=<option> [default: development] Pushing a workflow is only allowed in the development environment
423
+ <options: development>
424
+ --service-token=<value> (required) The service token to authenticate with
425
+ ```
426
+
427
+ ## `knock workflow validate [WORKFLOWKEY]`
428
+
429
+ ```
430
+ USAGE
431
+ $ knock workflow validate [WORKFLOWKEY] --service-token <value> [--environment development]
371
432
 
372
433
  FLAGS
373
- --environment=<option> [default: development]
434
+ --environment=<option> [default: development] Validating a workflow is only done in the development environment
374
435
  <options: development>
375
- --service-token=<value> (required) service token to authenticate with
436
+ --service-token=<value> (required) The service token to authenticate with
376
437
  ```
377
438
  <!-- commandsstop -->
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>Commit
8
+ });
9
+ const _core = require("@oclif/core");
10
+ const _enquirer = /*#__PURE__*/ _interopRequireDefault(require("enquirer"));
11
+ const _baseCommand = /*#__PURE__*/ _interopRequireDefault(require("../../lib/base-command"));
12
+ const _const = require("../../lib/helpers/const");
13
+ const _request = require("../../lib/helpers/request");
14
+ function _interopRequireDefault(obj) {
15
+ return obj && obj.__esModule ? obj : {
16
+ default: obj
17
+ };
18
+ }
19
+ // TODO(KNO-2647): Abstract this out as a helper.
20
+ const promptToConfirm = async ()=>{
21
+ try {
22
+ const { input } = await _enquirer.default.prompt({
23
+ type: "confirm",
24
+ name: "input",
25
+ message: "Commit all changes in the development environment?"
26
+ });
27
+ return input;
28
+ } catch (error) {
29
+ console.log(error);
30
+ }
31
+ };
32
+ class Commit extends _baseCommand.default {
33
+ async run() {
34
+ const { flags } = this.props;
35
+ // Confirm first as we are about to commit changes to go live in the
36
+ // development environment, unless forced.
37
+ if (!flags.force) {
38
+ const input = await promptToConfirm();
39
+ if (!input) return;
40
+ }
41
+ await (0, _request.withSpinner)(()=>this.apiV1.commitAllChanges(this.props));
42
+ this.log(`‣ Successfully committed all changes in \`${flags.environment}\` environment`);
43
+ }
44
+ }
45
+ Commit.flags = {
46
+ environment: _core.Flags.string({
47
+ summary: "Committing changes applies to the development environment only, use `commit promote` to promote changes to a later environment",
48
+ default: _const.KnockEnv.Development,
49
+ options: [
50
+ _const.KnockEnv.Development
51
+ ]
52
+ }),
53
+ "commit-message": _core.Flags.string({
54
+ summary: "Use the given value as the commit message",
55
+ char: "m"
56
+ }),
57
+ force: _core.Flags.boolean()
58
+ };
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>CommitPromote
8
+ });
9
+ const _core = require("@oclif/core");
10
+ const _enquirer = /*#__PURE__*/ _interopRequireDefault(require("enquirer"));
11
+ const _baseCommand = /*#__PURE__*/ _interopRequireDefault(require("../../lib/base-command"));
12
+ const _request = require("../../lib/helpers/request");
13
+ function _interopRequireDefault(obj) {
14
+ return obj && obj.__esModule ? obj : {
15
+ default: obj
16
+ };
17
+ }
18
+ const promptToConfirm = async ({ flags })=>{
19
+ try {
20
+ const { input } = await _enquirer.default.prompt({
21
+ type: "confirm",
22
+ name: "input",
23
+ message: `Promote all changes to \`${flags.to}\` environment?`
24
+ });
25
+ return input;
26
+ } catch (error) {
27
+ console.log(error);
28
+ }
29
+ };
30
+ class CommitPromote extends _baseCommand.default {
31
+ async run() {
32
+ const { flags } = this.props;
33
+ // Confirm first as we are about to promote changes to go live in the target
34
+ // environment, unless forced.
35
+ if (!flags.force) {
36
+ const input = await promptToConfirm(this.props);
37
+ if (!input) return;
38
+ }
39
+ await (0, _request.withSpinner)(()=>this.apiV1.promoteAllChanges(this.props));
40
+ this.log(`‣ Successfully promoted all changes to \`${flags.to}\` environment`);
41
+ }
42
+ }
43
+ CommitPromote.flags = {
44
+ to: _core.Flags.string({
45
+ summary: "The destination environment to promote changes from the preceding environment",
46
+ required: true
47
+ }),
48
+ force: _core.Flags.boolean()
49
+ };
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>WorkflowActivate
8
+ });
9
+ const _core = require("@oclif/core");
10
+ const _enquirer = /*#__PURE__*/ _interopRequireDefault(require("enquirer"));
11
+ const _baseCommand = /*#__PURE__*/ _interopRequireDefault(require("../../lib/base-command"));
12
+ const _flag = require("../../lib/helpers/flag");
13
+ const _request = require("../../lib/helpers/request");
14
+ function _interopRequireDefault(obj) {
15
+ return obj && obj.__esModule ? obj : {
16
+ default: obj
17
+ };
18
+ }
19
+ const promptToConfirm = async ({ flags , args })=>{
20
+ const action = flags.status ? "Activate" : "Deactivate";
21
+ try {
22
+ const { input } = await _enquirer.default.prompt({
23
+ type: "confirm",
24
+ name: "input",
25
+ message: `${action} \`${args.workflowKey}\` workflow in \`${flags.environment}\` environment?`
26
+ });
27
+ return input;
28
+ } catch (error) {
29
+ console.log(error);
30
+ }
31
+ };
32
+ class WorkflowActivate extends _baseCommand.default {
33
+ async run() {
34
+ const { args , flags } = this.props;
35
+ // 1. Confirm before activating or deactivating the workflow, unless forced.
36
+ if (!flags.force) {
37
+ const input = await promptToConfirm(this.props);
38
+ if (!input) return;
39
+ }
40
+ // 2. Proceed to make a request to set the workflow status.
41
+ const actioning = flags.status ? "Activating" : "Deactivating";
42
+ await (0, _request.withSpinner)(()=>{
43
+ return this.apiV1.activateWorkflow(this.props);
44
+ }, {
45
+ action: `‣ ${actioning}`
46
+ });
47
+ const actioned = flags.status ? "activated" : "deactivated";
48
+ this.log(`‣ Successfully ${actioned} \`${args.workflowKey}\` workflow in \`${flags.environment}\` environment`);
49
+ }
50
+ }
51
+ WorkflowActivate.flags = {
52
+ // Do not default to any env for this command, since this action runs
53
+ // directly in each environment outside the commit and promote flow.
54
+ environment: _core.Flags.string({
55
+ required: true
56
+ }),
57
+ status: (0, _flag.booleanStr)({
58
+ default: true
59
+ }),
60
+ force: _core.Flags.boolean()
61
+ };
62
+ WorkflowActivate.args = [
63
+ {
64
+ name: "workflowKey",
65
+ required: true
66
+ }
67
+ ];
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>WorkflowNew
8
+ });
9
+ const _nodePath = /*#__PURE__*/ _interopRequireWildcard(require("node:path"));
10
+ const _core = require("@oclif/core");
11
+ const _fsExtra = /*#__PURE__*/ _interopRequireWildcard(require("fs-extra"));
12
+ const _baseCommand = /*#__PURE__*/ _interopRequireDefault(require("../../lib/base-command"));
13
+ const _object = require("../../lib/helpers/object");
14
+ const _spinner = /*#__PURE__*/ _interopRequireWildcard(require("../../lib/helpers/spinner"));
15
+ const _workflow = /*#__PURE__*/ _interopRequireWildcard(require("../../lib/marshal/workflow"));
16
+ function _interopRequireDefault(obj) {
17
+ return obj && obj.__esModule ? obj : {
18
+ default: obj
19
+ };
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
+ }
60
+ class WorkflowNew extends _baseCommand.default {
61
+ async run() {
62
+ const { args , flags } = this.props;
63
+ const { cwd , resourceDir } = this.runContext;
64
+ _spinner.start("‣ Validating");
65
+ // 1. Ensure we aren't in any existing resource directory already.
66
+ // TODO: In the future, maybe check for the project context and if we are in
67
+ // /workflows directory.
68
+ if (resourceDir) {
69
+ return this.error(`Cannot generate inside an existing ${resourceDir.type} directory`);
70
+ }
71
+ // 2. Ensure the workflow key is in the valid format.
72
+ const workflowKeyError = _workflow.validateWorkflowKey(args.workflowKey);
73
+ if (workflowKeyError) {
74
+ return this.error(`Invalid workflow key \`${args.workflowKey}\` (${workflowKeyError})`);
75
+ }
76
+ // 3. Parse and validate the steps flag, if given.
77
+ const [steps, stepsError] = _workflow.parseStepsInput(flags.steps || "");
78
+ if (stepsError) {
79
+ return this.error(`Invalid --steps \`${flags.steps}\` (${stepsError})`);
80
+ }
81
+ // 4. Ensure not to overwrite any existing path accidentally.
82
+ const newWorkflowDirPath = _nodePath.resolve(cwd, args.workflowKey);
83
+ const pathExists = await _fsExtra.pathExists(newWorkflowDirPath);
84
+ if (pathExists && !flags.force) {
85
+ return this.error(`Cannot overwrite an existing path at ${newWorkflowDirPath}` + " (use --force to overwrite)");
86
+ }
87
+ _spinner.stop();
88
+ // 5-A. We are good to generate a new workflow directory.
89
+ const dirContext = {
90
+ type: "workflow",
91
+ key: args.workflowKey,
92
+ abspath: newWorkflowDirPath,
93
+ exists: await _workflow.isWorkflowDir(newWorkflowDirPath)
94
+ };
95
+ const attrs = {
96
+ name: args.workflowKey,
97
+ steps
98
+ };
99
+ await _workflow.generateWorkflowDir(dirContext, attrs);
100
+ this.log(`‣ Successfully generated a workflow directory at ${dirContext.abspath}`);
101
+ // 5-B. Lastly warn if this workflow already exists in Knock.
102
+ const isExistingWorkflow = await this.checkExistingWorkflow();
103
+ if (isExistingWorkflow) {
104
+ this.log("");
105
+ this.warn(`Workflow \`${args.workflowKey}\` already exists in \`development\` environment`);
106
+ }
107
+ }
108
+ async checkExistingWorkflow() {
109
+ const props = (0, _object.merge)(this.props, {
110
+ flags: {
111
+ environment: "development"
112
+ }
113
+ });
114
+ try {
115
+ const resp = await this.apiV1.getWorkflow(props);
116
+ return resp.status === 200;
117
+ } catch {}
118
+ }
119
+ }
120
+ WorkflowNew.flags = {
121
+ steps: _core.Flags.string({
122
+ aliases: [
123
+ "step"
124
+ ]
125
+ }),
126
+ force: _core.Flags.boolean()
127
+ };
128
+ WorkflowNew.args = [
129
+ {
130
+ name: "workflowKey",
131
+ required: true
132
+ }
133
+ ];
134
+ // TODO(KNO-3072): Unhide after we move the generator logic to the backend.
135
+ WorkflowNew.hidden = true;
@@ -92,8 +92,8 @@ class WorkflowPull extends _baseCommand.default {
92
92
  });
93
93
  return this.apiV1.getWorkflow(props);
94
94
  });
95
- // 3. Write the workflow with the workflow directory context.
96
- await _workflow.writeWorkflowDir(resp.data, dirContext);
95
+ // 3. Write the fetched workflow to create or update the workflow directory.
96
+ await _workflow.writeWorkflowDirFromData(dirContext, resp.data);
97
97
  const action = dirContext.exists ? "updated" : "created";
98
98
  this.log(`‣ Successfully ${action} \`${dirContext.key}\` at ${dirContext.abspath}`);
99
99
  }
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "default", {
9
9
  const _nodePath = /*#__PURE__*/ _interopRequireWildcard(require("node:path"));
10
10
  const _core = require("@oclif/core");
11
11
  const _baseCommand = /*#__PURE__*/ _interopRequireDefault(require("../../lib/base-command"));
12
+ const _const = require("../../lib/helpers/const");
12
13
  const _dirContext = require("../../lib/helpers/dir-context");
13
14
  const _error = require("../../lib/helpers/error");
14
15
  const _object = require("../../lib/helpers/object");
@@ -84,7 +85,7 @@ class WorkflowPush extends _baseCommand.default {
84
85
  });
85
86
  // 4. Update the workflow directory with the successfully pushed workflow
86
87
  // payload from the server.
87
- await _workflow.writeWorkflowDir(resp.data.workflow, dirContext);
88
+ await _workflow.writeWorkflowDirFromData(dirContext, resp.data.workflow);
88
89
  this.log(`‣ Successfully pushed \`${dirContext.key}\`, and updated ${dirContext.abspath}`);
89
90
  }
90
91
  async getWorkflowDirContext() {
@@ -112,11 +113,21 @@ class WorkflowPush extends _baseCommand.default {
112
113
  }
113
114
  }
114
115
  WorkflowPush.flags = {
115
- // TODO: Maybe make environments into an enum.
116
116
  environment: _core.Flags.string({
117
- default: "development",
117
+ summary: "Pushing a workflow is only allowed in the development environment",
118
+ default: _const.KnockEnv.Development,
118
119
  options: [
119
- "development"
120
+ _const.KnockEnv.Development
121
+ ]
122
+ }),
123
+ commit: _core.Flags.boolean({
124
+ summary: "Push and commit the workflow(s) at the same time"
125
+ }),
126
+ "commit-message": _core.Flags.string({
127
+ summary: "Use the given value as the commit message",
128
+ char: "m",
129
+ dependsOn: [
130
+ "commit"
120
131
  ]
121
132
  })
122
133
  };
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>WorkflowValidate
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 _const = require("../../lib/helpers/const");
13
+ const _dirContext = require("../../lib/helpers/dir-context");
14
+ const _error = require("../../lib/helpers/error");
15
+ const _object = require("../../lib/helpers/object");
16
+ const _request = require("../../lib/helpers/request");
17
+ const _workflow = /*#__PURE__*/ _interopRequireWildcard(require("../../lib/marshal/workflow"));
18
+ function _interopRequireDefault(obj) {
19
+ return obj && obj.__esModule ? obj : {
20
+ default: obj
21
+ };
22
+ }
23
+ function _getRequireWildcardCache(nodeInterop) {
24
+ if (typeof WeakMap !== "function") return null;
25
+ var cacheBabelInterop = new WeakMap();
26
+ var cacheNodeInterop = new WeakMap();
27
+ return (_getRequireWildcardCache = function(nodeInterop) {
28
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
29
+ })(nodeInterop);
30
+ }
31
+ function _interopRequireWildcard(obj, nodeInterop) {
32
+ if (!nodeInterop && obj && obj.__esModule) {
33
+ return obj;
34
+ }
35
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
36
+ return {
37
+ default: obj
38
+ };
39
+ }
40
+ var cache = _getRequireWildcardCache(nodeInterop);
41
+ if (cache && cache.has(obj)) {
42
+ return cache.get(obj);
43
+ }
44
+ var newObj = {};
45
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
46
+ for(var key in obj){
47
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
48
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
49
+ if (desc && (desc.get || desc.set)) {
50
+ Object.defineProperty(newObj, key, desc);
51
+ } else {
52
+ newObj[key] = obj[key];
53
+ }
54
+ }
55
+ }
56
+ newObj.default = obj;
57
+ if (cache) {
58
+ cache.set(obj, newObj);
59
+ }
60
+ return newObj;
61
+ }
62
+ class WorkflowValidate extends _baseCommand.default {
63
+ async run() {
64
+ // 1. Retrieve the target workflow directory context.
65
+ const dirContext = await this.getWorkflowDirContext();
66
+ this.log(`‣ Reading \`${dirContext.key}\` at ${dirContext.abspath}`);
67
+ // 2. Read the workflow.json with its template files.
68
+ const [workflow, errors] = await _workflow.readWorkflowDir(dirContext, {
69
+ withTemplateFiles: true
70
+ });
71
+ if (errors.length > 0) {
72
+ this.error(`Found the following errors in \`${dirContext.key}\` ${_workflow.WORKFLOW_JSON}\n\n` + (0, _error.formatErrors)(errors));
73
+ }
74
+ // 3. Validate the compiled workflow data.
75
+ await (0, _request.withSpinner)(()=>{
76
+ const props = (0, _object.merge)(this.props, {
77
+ args: {
78
+ workflowKey: dirContext.key
79
+ }
80
+ });
81
+ return this.apiV1.validateWorkflow(props, workflow);
82
+ }, {
83
+ action: "‣ Validating"
84
+ });
85
+ this.log(`‣ Successfully validated \`${dirContext.key}\``);
86
+ }
87
+ async getWorkflowDirContext() {
88
+ const { workflowKey } = this.props.args;
89
+ const { resourceDir , cwd: runCwd } = this.runContext;
90
+ if (resourceDir) {
91
+ const target = {
92
+ commandId: _baseCommand.default.id,
93
+ type: "workflow",
94
+ key: workflowKey
95
+ };
96
+ return (0, _dirContext.ensureResourceDirForTarget)(resourceDir, target);
97
+ }
98
+ if (workflowKey) {
99
+ const dirPath = _nodePath.resolve(runCwd, workflowKey);
100
+ const exists = await _workflow.isWorkflowDir(dirPath);
101
+ return exists ? {
102
+ type: "workflow",
103
+ key: workflowKey,
104
+ abspath: dirPath,
105
+ exists
106
+ } : this.error(`Cannot locate a workflow directory for \`${workflowKey}\``);
107
+ }
108
+ return this.error("Missing 1 required arg:\nworkflowKey");
109
+ }
110
+ }
111
+ WorkflowValidate.flags = {
112
+ environment: _core.Flags.string({
113
+ summary: "Validating a workflow is only done in the development environment",
114
+ default: _const.KnockEnv.Development,
115
+ options: [
116
+ _const.KnockEnv.Development
117
+ ]
118
+ })
119
+ };
120
+ WorkflowValidate.args = [
121
+ {
122
+ name: "workflowKey",
123
+ required: false
124
+ }
125
+ ];