@commercetools-frontend/deployment-cli 0.1.0 → 0.2.0

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.
@@ -2,8 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
6
- var mri = require('mri');
5
+ var cac = require('cac');
7
6
  var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
8
7
  var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
9
8
  var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
@@ -23,8 +22,6 @@ var fetch = require('node-fetch');
23
22
 
24
23
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
25
24
 
26
- var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanceProperty);
27
- var mri__default = /*#__PURE__*/_interopDefault(mri);
28
25
  var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
29
26
  var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
30
27
  var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
@@ -40,6 +37,64 @@ var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
40
37
  var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
41
38
  var fetch__default = /*#__PURE__*/_interopDefault(fetch);
42
39
 
40
+ var pkgJson = {
41
+ name: "@commercetools-frontend/deployment-cli",
42
+ version: "0.2.0",
43
+ description: "CLI to manage Custom Applications deployments in Google Storage.",
44
+ keywords: [
45
+ "commercetools",
46
+ "cli",
47
+ "deployment"
48
+ ],
49
+ license: "MIT",
50
+ main: "dist/commercetools-frontend-deployment-cli.cjs.js",
51
+ module: "dist/commercetools-frontend-deployment-cli.esm.js",
52
+ bin: "bin/cli.js",
53
+ files: [
54
+ "cli",
55
+ "dist",
56
+ "package.json",
57
+ "LICENSE",
58
+ "README.md"
59
+ ],
60
+ scripts: {
61
+ typecheck: "tsc --noEmit"
62
+ },
63
+ dependencies: {
64
+ "@babel/core": "^7.21.3",
65
+ "@babel/runtime": "^7.21.0",
66
+ "@babel/runtime-corejs3": "^7.21.0",
67
+ cac: "^6.7.14",
68
+ cosmiconfig: "8.1.3",
69
+ lodash: "4.17.21",
70
+ "node-fetch": "2.6.9",
71
+ "p-retry": "4.6.2",
72
+ prompts: "2.4.2"
73
+ },
74
+ devDependencies: {
75
+ "@tsconfig/node18": "1.0.3",
76
+ "@types/lodash": "^4.14.191",
77
+ "@types/node": "18.16.5",
78
+ "@types/node-fetch": "2.6.3",
79
+ "@types/prompts": "2.4.4",
80
+ msw: "1.2.1",
81
+ typescript: "^4.9.5"
82
+ },
83
+ engines: {
84
+ node: ">=14",
85
+ npm: ">=6"
86
+ },
87
+ publishConfig: {
88
+ access: "public"
89
+ },
90
+ preconstruct: {
91
+ entrypoints: [
92
+ "./cli.ts",
93
+ "./index.ts"
94
+ ]
95
+ }
96
+ };
97
+
43
98
  async function loadConfig() {
44
99
  const deploymentConfigExplorer = cosmiconfig.cosmiconfig('deployment');
45
100
  const defaultConfig = {
@@ -509,6 +564,7 @@ function createCircleCiClient(_ref) {
509
564
  };
510
565
  }
511
566
 
567
+ const cli = cac.cac('deployment-cli');
512
568
  async function run() {
513
569
  const config = await loadConfig();
514
570
  throwIfConfigurationLacksRequiredValues(config);
@@ -516,53 +572,37 @@ async function run() {
516
572
  projectName: config.CircleCI.projectName,
517
573
  apiBaseUrl: config.CircleCI.apiBaseUrl
518
574
  });
519
- try {
520
- var _context;
521
- const cliFlags = mri__default["default"](_sliceInstanceProperty__default["default"](_context = process.argv).call(_context, 2), {
522
- alias: {
523
- help: ['h']
524
- },
525
- boolean: ['dry-run', 'debug', 'yes'],
526
- default: {
527
- branch: 'main'
528
- }
529
- });
530
- const cliCommands = cliFlags._;
531
- if (cliCommands.length === 0 ||
532
- // @ts-expect-error mri is not typed for the help command.
533
- cliCommands.help && cliCommands.length === 0) {
534
- console.log("\nUsage: deployment-cli [command] [flags]\n\nDisplays help information.\n\nCommand:\n approve Approves a job and by this triggers a deployment of a component. It requires a \"CIRCLE_TOKEN\" environment variable (https://circleci.com/docs/2.0/managing-api-tokens/).\n\nOptions:\n --approval-job The name of the approval job to approve a deployment with.\n --deployment-job (optional) The name of the deployment job triggered by the approval job. If passed the CLI will print a URL to the deployment triggered on CircleCI.\n --deployment (optional) The name of a deployment configured in the configuration file.\n --build-revision <git-sha> (optional) The git commit SHA that needs to be deployed. If not specified, the last successful pipeline is used.\n --branch (optional) The git branch to deploy from. If not specified, defaults to 'main'.\n --yes (optional) Skip all confirmation prompts. Useful in Continuous integration (CI) to automatically answer confirmation questions.\n\nGeneral options:\n --dry-run (optional) Simulate a deployment.\n --debug (optional) Print additional debug information.\n");
535
- process.exit(0);
536
- }
537
- const cliCommand = cliCommands[0];
538
- if (cliFlags['dry-run']) {
539
- console.log("\n \uD83D\uDE4A Do not worry. This is a dry run!\n ");
540
- }
541
- console.log("\uD83C\uDFC3 Running ".concat(cliCommand, " command"));
542
- switch (cliCommand) {
543
- case 'approve':
544
- {
545
- throwIfRequiredEnvironmentVariableIsUnset(['CIRCLE_TOKEN']);
546
- await approve({
547
- deployment: cliFlags.deployment,
548
- branch: cliFlags.branch,
549
- approvalJob: cliFlags['approval-job'],
550
- deploymentJob: cliFlags['deployment-job'],
551
- buildRevision: cliFlags['build-revision'],
552
- yes: cliFlags.yes,
553
- debug: cliFlags.debug,
554
- dryRun: cliFlags['dry-run']
555
- }, config, circleCiApis);
556
- process.exit(0);
557
- }
558
- // eslint-disable-next-line no-fallthrough
559
- default:
560
- throw new Error("\uD83D\uDC80 Unknown command \"".concat(cliCommand, "\"."));
575
+
576
+ // General CLI options
577
+ cli.option('--dry-run', '(optional) Simulate a deployment.', {
578
+ default: false
579
+ });
580
+ cli.option('--debug', '(optional) Print additional debug information.', {
581
+ default: false
582
+ });
583
+
584
+ // Default command
585
+ cli.command('').usage('\n\n Approve deployment jobs on CI for different components related to MC.').action(cli.outputHelp);
586
+
587
+ // Command: Approve
588
+ const usageApprove = 'Approves a job and by this triggers a deployment of a component. It requires a "CIRCLE_TOKEN" environment variable (https://circleci.com/docs/2.0/managing-api-tokens/).';
589
+ cli.command('approve', usageApprove).usage("approve \n\n ".concat(usageApprove)).option('--approval-job <string>', 'The name of the approval job to approve a deployment with.').option('--deployment-job [string]', '(optional) The name of the deployment job triggered by the approval job. If passed the CLI will print a URL to the deployment triggered on CircleCI.').option('--deployment [string]', '(optional) The name of a deployment configured in the configuration file.').option('--build-revision [git-sha]', '(optional) The git commit SHA that needs to be deployed. If not specified, the last successful pipeline is used.').option('--branch [string]', '(optional) The git branch to deploy from. If not specified.', {
590
+ default: 'main'
591
+ }).option('--yes', '(optional) Skip all confirmation prompts. Useful in Continuous integration (CI) to automatically answer confirmation questions.', {
592
+ default: false
593
+ }).action(async options => {
594
+ if (options.dryRun) {
595
+ console.log("\uD83D\uDE4A Do not worry. This is a dry run!");
561
596
  }
562
- } catch (error) {
563
- console.error(error);
564
- process.exit(1);
565
- }
597
+ throwIfRequiredEnvironmentVariableIsUnset(['CIRCLE_TOKEN']);
598
+ await approve(options, config, circleCiApis);
599
+ });
600
+ cli.help();
601
+ cli.version(pkgJson.version);
602
+ cli.parse(process.argv, {
603
+ run: false
604
+ });
605
+ await cli.runMatchedCommand();
566
606
  }
567
607
 
568
608
  exports.run = run;
@@ -2,8 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var _sliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/slice');
6
- var mri = require('mri');
5
+ var cac = require('cac');
7
6
  var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
8
7
  var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
9
8
  var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
@@ -23,8 +22,6 @@ var fetch = require('node-fetch');
23
22
 
24
23
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
25
24
 
26
- var _sliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_sliceInstanceProperty);
27
- var mri__default = /*#__PURE__*/_interopDefault(mri);
28
25
  var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
29
26
  var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
30
27
  var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
@@ -40,6 +37,64 @@ var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
40
37
  var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
41
38
  var fetch__default = /*#__PURE__*/_interopDefault(fetch);
42
39
 
40
+ var pkgJson = {
41
+ name: "@commercetools-frontend/deployment-cli",
42
+ version: "0.2.0",
43
+ description: "CLI to manage Custom Applications deployments in Google Storage.",
44
+ keywords: [
45
+ "commercetools",
46
+ "cli",
47
+ "deployment"
48
+ ],
49
+ license: "MIT",
50
+ main: "dist/commercetools-frontend-deployment-cli.cjs.js",
51
+ module: "dist/commercetools-frontend-deployment-cli.esm.js",
52
+ bin: "bin/cli.js",
53
+ files: [
54
+ "cli",
55
+ "dist",
56
+ "package.json",
57
+ "LICENSE",
58
+ "README.md"
59
+ ],
60
+ scripts: {
61
+ typecheck: "tsc --noEmit"
62
+ },
63
+ dependencies: {
64
+ "@babel/core": "^7.21.3",
65
+ "@babel/runtime": "^7.21.0",
66
+ "@babel/runtime-corejs3": "^7.21.0",
67
+ cac: "^6.7.14",
68
+ cosmiconfig: "8.1.3",
69
+ lodash: "4.17.21",
70
+ "node-fetch": "2.6.9",
71
+ "p-retry": "4.6.2",
72
+ prompts: "2.4.2"
73
+ },
74
+ devDependencies: {
75
+ "@tsconfig/node18": "1.0.3",
76
+ "@types/lodash": "^4.14.191",
77
+ "@types/node": "18.16.5",
78
+ "@types/node-fetch": "2.6.3",
79
+ "@types/prompts": "2.4.4",
80
+ msw: "1.2.1",
81
+ typescript: "^4.9.5"
82
+ },
83
+ engines: {
84
+ node: ">=14",
85
+ npm: ">=6"
86
+ },
87
+ publishConfig: {
88
+ access: "public"
89
+ },
90
+ preconstruct: {
91
+ entrypoints: [
92
+ "./cli.ts",
93
+ "./index.ts"
94
+ ]
95
+ }
96
+ };
97
+
43
98
  async function loadConfig() {
44
99
  const deploymentConfigExplorer = cosmiconfig.cosmiconfig('deployment');
45
100
  const defaultConfig = {
@@ -509,6 +564,7 @@ function createCircleCiClient(_ref) {
509
564
  };
510
565
  }
511
566
 
567
+ const cli = cac.cac('deployment-cli');
512
568
  async function run() {
513
569
  const config = await loadConfig();
514
570
  throwIfConfigurationLacksRequiredValues(config);
@@ -516,53 +572,37 @@ async function run() {
516
572
  projectName: config.CircleCI.projectName,
517
573
  apiBaseUrl: config.CircleCI.apiBaseUrl
518
574
  });
519
- try {
520
- var _context;
521
- const cliFlags = mri__default["default"](_sliceInstanceProperty__default["default"](_context = process.argv).call(_context, 2), {
522
- alias: {
523
- help: ['h']
524
- },
525
- boolean: ['dry-run', 'debug', 'yes'],
526
- default: {
527
- branch: 'main'
528
- }
529
- });
530
- const cliCommands = cliFlags._;
531
- if (cliCommands.length === 0 ||
532
- // @ts-expect-error mri is not typed for the help command.
533
- cliCommands.help && cliCommands.length === 0) {
534
- console.log("\nUsage: deployment-cli [command] [flags]\n\nDisplays help information.\n\nCommand:\n approve Approves a job and by this triggers a deployment of a component. It requires a \"CIRCLE_TOKEN\" environment variable (https://circleci.com/docs/2.0/managing-api-tokens/).\n\nOptions:\n --approval-job The name of the approval job to approve a deployment with.\n --deployment-job (optional) The name of the deployment job triggered by the approval job. If passed the CLI will print a URL to the deployment triggered on CircleCI.\n --deployment (optional) The name of a deployment configured in the configuration file.\n --build-revision <git-sha> (optional) The git commit SHA that needs to be deployed. If not specified, the last successful pipeline is used.\n --branch (optional) The git branch to deploy from. If not specified, defaults to 'main'.\n --yes (optional) Skip all confirmation prompts. Useful in Continuous integration (CI) to automatically answer confirmation questions.\n\nGeneral options:\n --dry-run (optional) Simulate a deployment.\n --debug (optional) Print additional debug information.\n");
535
- process.exit(0);
536
- }
537
- const cliCommand = cliCommands[0];
538
- if (cliFlags['dry-run']) {
539
- console.log("\n \uD83D\uDE4A Do not worry. This is a dry run!\n ");
540
- }
541
- console.log("\uD83C\uDFC3 Running ".concat(cliCommand, " command"));
542
- switch (cliCommand) {
543
- case 'approve':
544
- {
545
- throwIfRequiredEnvironmentVariableIsUnset(['CIRCLE_TOKEN']);
546
- await approve({
547
- deployment: cliFlags.deployment,
548
- branch: cliFlags.branch,
549
- approvalJob: cliFlags['approval-job'],
550
- deploymentJob: cliFlags['deployment-job'],
551
- buildRevision: cliFlags['build-revision'],
552
- yes: cliFlags.yes,
553
- debug: cliFlags.debug,
554
- dryRun: cliFlags['dry-run']
555
- }, config, circleCiApis);
556
- process.exit(0);
557
- }
558
- // eslint-disable-next-line no-fallthrough
559
- default:
560
- throw new Error("\uD83D\uDC80 Unknown command \"".concat(cliCommand, "\"."));
575
+
576
+ // General CLI options
577
+ cli.option('--dry-run', '(optional) Simulate a deployment.', {
578
+ default: false
579
+ });
580
+ cli.option('--debug', '(optional) Print additional debug information.', {
581
+ default: false
582
+ });
583
+
584
+ // Default command
585
+ cli.command('').usage('\n\n Approve deployment jobs on CI for different components related to MC.').action(cli.outputHelp);
586
+
587
+ // Command: Approve
588
+ const usageApprove = 'Approves a job and by this triggers a deployment of a component. It requires a "CIRCLE_TOKEN" environment variable (https://circleci.com/docs/2.0/managing-api-tokens/).';
589
+ cli.command('approve', usageApprove).usage("approve \n\n ".concat(usageApprove)).option('--approval-job <string>', 'The name of the approval job to approve a deployment with.').option('--deployment-job [string]', '(optional) The name of the deployment job triggered by the approval job. If passed the CLI will print a URL to the deployment triggered on CircleCI.').option('--deployment [string]', '(optional) The name of a deployment configured in the configuration file.').option('--build-revision [git-sha]', '(optional) The git commit SHA that needs to be deployed. If not specified, the last successful pipeline is used.').option('--branch [string]', '(optional) The git branch to deploy from. If not specified.', {
590
+ default: 'main'
591
+ }).option('--yes', '(optional) Skip all confirmation prompts. Useful in Continuous integration (CI) to automatically answer confirmation questions.', {
592
+ default: false
593
+ }).action(async options => {
594
+ if (options.dryRun) {
595
+ console.log("\uD83D\uDE4A Do not worry. This is a dry run!");
561
596
  }
562
- } catch (error) {
563
- console.error(error);
564
- process.exit(1);
565
- }
597
+ throwIfRequiredEnvironmentVariableIsUnset(['CIRCLE_TOKEN']);
598
+ await approve(options, config, circleCiApis);
599
+ });
600
+ cli.help();
601
+ cli.version(pkgJson.version);
602
+ cli.parse(process.argv, {
603
+ run: false
604
+ });
605
+ await cli.runMatchedCommand();
566
606
  }
567
607
 
568
608
  exports.run = run;
@@ -1,5 +1,4 @@
1
- import _sliceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/slice';
2
- import mri from 'mri';
1
+ import { cac } from 'cac';
3
2
  import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
4
3
  import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
5
4
  import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
@@ -17,6 +16,64 @@ import _Promise from '@babel/runtime-corejs3/core-js-stable/promise';
17
16
  import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
18
17
  import fetch from 'node-fetch';
19
18
 
19
+ var pkgJson = {
20
+ name: "@commercetools-frontend/deployment-cli",
21
+ version: "0.2.0",
22
+ description: "CLI to manage Custom Applications deployments in Google Storage.",
23
+ keywords: [
24
+ "commercetools",
25
+ "cli",
26
+ "deployment"
27
+ ],
28
+ license: "MIT",
29
+ main: "dist/commercetools-frontend-deployment-cli.cjs.js",
30
+ module: "dist/commercetools-frontend-deployment-cli.esm.js",
31
+ bin: "bin/cli.js",
32
+ files: [
33
+ "cli",
34
+ "dist",
35
+ "package.json",
36
+ "LICENSE",
37
+ "README.md"
38
+ ],
39
+ scripts: {
40
+ typecheck: "tsc --noEmit"
41
+ },
42
+ dependencies: {
43
+ "@babel/core": "^7.21.3",
44
+ "@babel/runtime": "^7.21.0",
45
+ "@babel/runtime-corejs3": "^7.21.0",
46
+ cac: "^6.7.14",
47
+ cosmiconfig: "8.1.3",
48
+ lodash: "4.17.21",
49
+ "node-fetch": "2.6.9",
50
+ "p-retry": "4.6.2",
51
+ prompts: "2.4.2"
52
+ },
53
+ devDependencies: {
54
+ "@tsconfig/node18": "1.0.3",
55
+ "@types/lodash": "^4.14.191",
56
+ "@types/node": "18.16.5",
57
+ "@types/node-fetch": "2.6.3",
58
+ "@types/prompts": "2.4.4",
59
+ msw: "1.2.1",
60
+ typescript: "^4.9.5"
61
+ },
62
+ engines: {
63
+ node: ">=14",
64
+ npm: ">=6"
65
+ },
66
+ publishConfig: {
67
+ access: "public"
68
+ },
69
+ preconstruct: {
70
+ entrypoints: [
71
+ "./cli.ts",
72
+ "./index.ts"
73
+ ]
74
+ }
75
+ };
76
+
20
77
  async function loadConfig() {
21
78
  const deploymentConfigExplorer = cosmiconfig('deployment');
22
79
  const defaultConfig = {
@@ -486,6 +543,7 @@ function createCircleCiClient(_ref) {
486
543
  };
487
544
  }
488
545
 
546
+ const cli = cac('deployment-cli');
489
547
  async function run() {
490
548
  const config = await loadConfig();
491
549
  throwIfConfigurationLacksRequiredValues(config);
@@ -493,53 +551,37 @@ async function run() {
493
551
  projectName: config.CircleCI.projectName,
494
552
  apiBaseUrl: config.CircleCI.apiBaseUrl
495
553
  });
496
- try {
497
- var _context;
498
- const cliFlags = mri(_sliceInstanceProperty(_context = process.argv).call(_context, 2), {
499
- alias: {
500
- help: ['h']
501
- },
502
- boolean: ['dry-run', 'debug', 'yes'],
503
- default: {
504
- branch: 'main'
505
- }
506
- });
507
- const cliCommands = cliFlags._;
508
- if (cliCommands.length === 0 ||
509
- // @ts-expect-error mri is not typed for the help command.
510
- cliCommands.help && cliCommands.length === 0) {
511
- console.log("\nUsage: deployment-cli [command] [flags]\n\nDisplays help information.\n\nCommand:\n approve Approves a job and by this triggers a deployment of a component. It requires a \"CIRCLE_TOKEN\" environment variable (https://circleci.com/docs/2.0/managing-api-tokens/).\n\nOptions:\n --approval-job The name of the approval job to approve a deployment with.\n --deployment-job (optional) The name of the deployment job triggered by the approval job. If passed the CLI will print a URL to the deployment triggered on CircleCI.\n --deployment (optional) The name of a deployment configured in the configuration file.\n --build-revision <git-sha> (optional) The git commit SHA that needs to be deployed. If not specified, the last successful pipeline is used.\n --branch (optional) The git branch to deploy from. If not specified, defaults to 'main'.\n --yes (optional) Skip all confirmation prompts. Useful in Continuous integration (CI) to automatically answer confirmation questions.\n\nGeneral options:\n --dry-run (optional) Simulate a deployment.\n --debug (optional) Print additional debug information.\n");
512
- process.exit(0);
513
- }
514
- const cliCommand = cliCommands[0];
515
- if (cliFlags['dry-run']) {
516
- console.log("\n \uD83D\uDE4A Do not worry. This is a dry run!\n ");
517
- }
518
- console.log("\uD83C\uDFC3 Running ".concat(cliCommand, " command"));
519
- switch (cliCommand) {
520
- case 'approve':
521
- {
522
- throwIfRequiredEnvironmentVariableIsUnset(['CIRCLE_TOKEN']);
523
- await approve({
524
- deployment: cliFlags.deployment,
525
- branch: cliFlags.branch,
526
- approvalJob: cliFlags['approval-job'],
527
- deploymentJob: cliFlags['deployment-job'],
528
- buildRevision: cliFlags['build-revision'],
529
- yes: cliFlags.yes,
530
- debug: cliFlags.debug,
531
- dryRun: cliFlags['dry-run']
532
- }, config, circleCiApis);
533
- process.exit(0);
534
- }
535
- // eslint-disable-next-line no-fallthrough
536
- default:
537
- throw new Error("\uD83D\uDC80 Unknown command \"".concat(cliCommand, "\"."));
554
+
555
+ // General CLI options
556
+ cli.option('--dry-run', '(optional) Simulate a deployment.', {
557
+ default: false
558
+ });
559
+ cli.option('--debug', '(optional) Print additional debug information.', {
560
+ default: false
561
+ });
562
+
563
+ // Default command
564
+ cli.command('').usage('\n\n Approve deployment jobs on CI for different components related to MC.').action(cli.outputHelp);
565
+
566
+ // Command: Approve
567
+ const usageApprove = 'Approves a job and by this triggers a deployment of a component. It requires a "CIRCLE_TOKEN" environment variable (https://circleci.com/docs/2.0/managing-api-tokens/).';
568
+ cli.command('approve', usageApprove).usage("approve \n\n ".concat(usageApprove)).option('--approval-job <string>', 'The name of the approval job to approve a deployment with.').option('--deployment-job [string]', '(optional) The name of the deployment job triggered by the approval job. If passed the CLI will print a URL to the deployment triggered on CircleCI.').option('--deployment [string]', '(optional) The name of a deployment configured in the configuration file.').option('--build-revision [git-sha]', '(optional) The git commit SHA that needs to be deployed. If not specified, the last successful pipeline is used.').option('--branch [string]', '(optional) The git branch to deploy from. If not specified.', {
569
+ default: 'main'
570
+ }).option('--yes', '(optional) Skip all confirmation prompts. Useful in Continuous integration (CI) to automatically answer confirmation questions.', {
571
+ default: false
572
+ }).action(async options => {
573
+ if (options.dryRun) {
574
+ console.log("\uD83D\uDE4A Do not worry. This is a dry run!");
538
575
  }
539
- } catch (error) {
540
- console.error(error);
541
- process.exit(1);
542
- }
576
+ throwIfRequiredEnvironmentVariableIsUnset(['CIRCLE_TOKEN']);
577
+ await approve(options, config, circleCiApis);
578
+ });
579
+ cli.help();
580
+ cli.version(pkgJson.version);
581
+ cli.parse(process.argv, {
582
+ run: false
583
+ });
584
+ await cli.runMatchedCommand();
543
585
  }
544
586
 
545
587
  export { run };
@@ -1,5 +1,5 @@
1
1
  import { TCircleCiClient } from '../apis';
2
2
  import { TDeploymentCLIConfig } from '../helpers';
3
- import type { TApproveCliFlags } from '../types';
4
- declare function approve(cliFlags: TApproveCliFlags, config: TDeploymentCLIConfig, circleCiApis: TCircleCiClient): Promise<void>;
3
+ import type { TAllCliFlags } from '../types';
4
+ declare function approve(cliFlags: TAllCliFlags, config: TDeploymentCLIConfig, circleCiApis: TCircleCiClient): Promise<void>;
5
5
  export default approve;
@@ -28,17 +28,17 @@ declare function throwIfConfigurationLacksRequiredValues(parsedConfiguration: TD
28
28
  declare function throwIfRequiredEnvironmentVariableIsUnset(requiredEnvironmentVariables: string[]): void;
29
29
  type TPaginateToDeploymentPipelineArgs = {
30
30
  circleCiApis: TCircleCiClient;
31
- branch: string;
32
- buildRevision: string;
33
- debug: boolean;
31
+ branch?: string;
32
+ buildRevision?: string;
33
+ debug?: boolean;
34
34
  maxPages: number;
35
35
  };
36
36
  declare function paginateToDeploymentPipeline({ circleCiApis, buildRevision, branch, debug, maxPages, }: TPaginateToDeploymentPipelineArgs): Promise<TDeploymentPipeline | undefined>;
37
37
  type TWaitForDeploymentPipelinePromptArgs = {
38
38
  circleCiApis: TCircleCiClient;
39
- branch: string;
39
+ branch?: string;
40
40
  pagesForPipelineSelection: number;
41
- debug: boolean;
41
+ debug?: boolean;
42
42
  };
43
43
  declare function waitForDeploymentPipelinePrompt({ circleCiApis, branch, pagesForPipelineSelection, debug, }: TWaitForDeploymentPipelinePromptArgs): Promise<TDeploymentPipeline>;
44
44
  type TWaitForConfirmationPromptArgs = {
@@ -59,8 +59,8 @@ type TWaitForDeploymentJobNumberArgs = {
59
59
  circleCiApis: TCircleCiClient;
60
60
  };
61
61
  declare function waitForDeploymentJobNumber({ workflowId, deploymentJob, circleCiApis }: TWaitForDeploymentJobNumberArgs, { debug }: {
62
- debug: boolean;
63
- dryRun: boolean;
64
- yes: boolean;
62
+ debug?: boolean;
63
+ dryRun?: boolean;
64
+ yes?: boolean;
65
65
  }): Promise<number>;
66
66
  export { loadConfig, throwIfRequiredEnvironmentVariableIsUnset, throwIfConfigurationLacksRequiredValues, waitForDeploymentJobNumber, waitForDeploymentPipelinePrompt, waitForConfirmationPrompt, paginateToDeploymentPipeline, getJobUrl, };
@@ -1,23 +1,13 @@
1
1
  type TCliBaseFlags = {
2
- url: string;
3
- application: string;
4
2
  debug: boolean;
5
- yes: boolean;
6
- deployment: string;
7
- branch: string;
8
- };
9
- type TAllParsedCliFlags = TCliBaseFlags & {
10
- buildRevision: string;
11
- approvalJob: string;
12
- deploymentJob: string;
13
3
  dryRun: boolean;
14
4
  };
15
- export type TCliFlags = TCliBaseFlags & {
16
- 'build-revision': string;
17
- 'approval-job': string;
18
- 'deployment-job': string;
19
- 'dry-run': boolean;
5
+ export type TAllCliFlags = TCliBaseFlags & {
6
+ approvalJob: string;
7
+ deploymentJob?: string;
8
+ deployment?: string;
9
+ buildRevision?: string;
10
+ branch: string;
11
+ yes: boolean;
20
12
  };
21
- export type TApproveCliFlags = Pick<TAllParsedCliFlags, 'deployment' | 'approvalJob' | 'deploymentJob' | 'buildRevision' | 'branch' | 'yes' | 'debug' | 'dryRun'>;
22
- export type TCliCommands = 'help' | 'approve';
23
13
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/deployment-cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "CLI to manage Custom Applications deployments in Google Storage.",
5
5
  "keywords": [
6
6
  "commercetools",
@@ -22,9 +22,9 @@
22
22
  "@babel/core": "^7.21.3",
23
23
  "@babel/runtime": "^7.21.0",
24
24
  "@babel/runtime-corejs3": "^7.21.0",
25
+ "cac": "^6.7.14",
25
26
  "cosmiconfig": "8.1.3",
26
27
  "lodash": "4.17.21",
27
- "mri": "1.2.0",
28
28
  "node-fetch": "2.6.9",
29
29
  "p-retry": "4.6.2",
30
30
  "prompts": "2.4.2"
@@ -32,7 +32,7 @@
32
32
  "devDependencies": {
33
33
  "@tsconfig/node18": "1.0.3",
34
34
  "@types/lodash": "^4.14.191",
35
- "@types/node": "18.15.12",
35
+ "@types/node": "18.16.5",
36
36
  "@types/node-fetch": "2.6.3",
37
37
  "@types/prompts": "2.4.4",
38
38
  "msw": "1.2.1",