@speedkit/cli 4.35.1 → 4.36.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.
Files changed (99) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +42 -7
  3. package/dist/commands/bulk-deploy.d.ts +19 -0
  4. package/dist/commands/bulk-deploy.js +52 -0
  5. package/dist/commands/deploy.d.ts +2 -0
  6. package/dist/commands/deploy.js +32 -2
  7. package/dist/services/cli/cli-service.js +42 -2
  8. package/dist/services/cli/cli-service.spec.js +41 -0
  9. package/dist/services/deploy/bulk/bulk-deploy-model.d.ts +46 -0
  10. package/dist/services/deploy/bulk/bulk-deploy-model.js +27 -0
  11. package/dist/services/deploy/bulk/bulk-deploy-service-factory.d.ts +11 -0
  12. package/dist/services/deploy/bulk/bulk-deploy-service-factory.js +24 -0
  13. package/dist/services/deploy/bulk/bulk-deploy-service.d.ts +47 -0
  14. package/dist/services/deploy/bulk/bulk-deploy-service.js +201 -0
  15. package/dist/services/deploy/bulk/bulk-deploy-service.spec.d.ts +1 -0
  16. package/dist/services/deploy/bulk/bulk-deploy-service.spec.js +146 -0
  17. package/dist/services/deploy/bulk/config-deploy-factory.d.ts +13 -0
  18. package/dist/services/deploy/bulk/config-deploy-factory.js +20 -0
  19. package/dist/services/deploy/bulk/index.d.ts +5 -0
  20. package/dist/services/deploy/bulk/index.js +5 -0
  21. package/dist/services/deploy/bulk/touched-configs.d.ts +12 -0
  22. package/dist/services/deploy/bulk/touched-configs.js +54 -0
  23. package/dist/services/deploy/bulk/touched-configs.spec.d.ts +1 -0
  24. package/dist/services/deploy/bulk/touched-configs.spec.js +77 -0
  25. package/dist/services/deploy/checks/activation/customer-approval-check.d.ts +3 -1
  26. package/dist/services/deploy/checks/activation/customer-approval-check.js +5 -2
  27. package/dist/services/deploy/checks/activation/customer-approval-check.spec.js +18 -15
  28. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.d.ts +3 -1
  29. package/dist/services/deploy/checks/post-deploy/deprecated-deployment-detection-check.js +6 -3
  30. package/dist/services/deploy/checks/post-deploy/save-files-check.d.ts +3 -1
  31. package/dist/services/deploy/checks/post-deploy/save-files-check.js +5 -2
  32. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.d.ts +3 -1
  33. package/dist/services/deploy/checks/pre-deploy/device-detection-changed-check.js +9 -5
  34. package/dist/services/deploy/checks/pre-deploy/split-change-check.d.ts +3 -1
  35. package/dist/services/deploy/checks/pre-deploy/split-change-check.js +8 -5
  36. package/dist/services/deploy/checks/pre-deploy/split-change-check.spec.d.ts +1 -0
  37. package/dist/services/deploy/checks/pre-deploy/split-change-check.spec.js +55 -0
  38. package/dist/services/deploy/context/deploy-context.d.ts +21 -1
  39. package/dist/services/deploy/context/deploy-context.js +30 -1
  40. package/dist/services/deploy/deploy-service-factory.d.ts +13 -1
  41. package/dist/services/deploy/deploy-service-factory.js +36 -15
  42. package/dist/services/deploy/error/deploy-aborted-error.d.ts +12 -0
  43. package/dist/services/deploy/error/deploy-aborted-error.js +16 -0
  44. package/dist/services/deploy/handler/customer-config-handler.d.ts +3 -1
  45. package/dist/services/deploy/handler/customer-config-handler.js +11 -7
  46. package/dist/services/deploy/handler/install-resource-handler.d.ts +3 -1
  47. package/dist/services/deploy/handler/install-resource-handler.js +12 -7
  48. package/dist/services/deploy/handler/install-resource-modifier/deleted-file-check.d.ts +3 -1
  49. package/dist/services/deploy/handler/install-resource-modifier/deleted-file-check.js +5 -2
  50. package/dist/services/deploy/handler/module-handler.d.ts +3 -1
  51. package/dist/services/deploy/handler/module-handler.js +7 -4
  52. package/dist/services/deploy/handler/module-handler.spec.d.ts +1 -0
  53. package/dist/services/deploy/handler/module-handler.spec.js +49 -0
  54. package/dist/services/deploy/handler/server-config-handler.d.ts +3 -1
  55. package/dist/services/deploy/handler/server-config-handler.js +6 -3
  56. package/dist/services/deploy/mr/base-config-reader.d.ts +25 -0
  57. package/dist/services/deploy/mr/base-config-reader.js +52 -0
  58. package/dist/services/deploy/mr/index.d.ts +6 -0
  59. package/dist/services/deploy/mr/index.js +6 -0
  60. package/dist/services/deploy/mr/live-state-check.d.ts +38 -0
  61. package/dist/services/deploy/mr/live-state-check.js +81 -0
  62. package/dist/services/deploy/mr/live-state-check.spec.d.ts +1 -0
  63. package/dist/services/deploy/mr/live-state-check.spec.js +74 -0
  64. package/dist/services/deploy/mr/merge-request-deploy-model.d.ts +59 -0
  65. package/dist/services/deploy/mr/merge-request-deploy-model.js +50 -0
  66. package/dist/services/deploy/mr/merge-request-deploy-service-factory.d.ts +20 -0
  67. package/dist/services/deploy/mr/merge-request-deploy-service-factory.js +46 -0
  68. package/dist/services/deploy/mr/merge-request-deploy-service.d.ts +61 -0
  69. package/dist/services/deploy/mr/merge-request-deploy-service.js +189 -0
  70. package/dist/services/deploy/mr/merge-request-description.d.ts +16 -0
  71. package/dist/services/deploy/mr/merge-request-description.js +27 -0
  72. package/dist/services/deploy/mr/merge-request-description.spec.d.ts +1 -0
  73. package/dist/services/deploy/mr/merge-request-description.spec.js +55 -0
  74. package/dist/services/deploy/policy/auto-deploy-policy.d.ts +43 -0
  75. package/dist/services/deploy/policy/auto-deploy-policy.js +77 -0
  76. package/dist/services/deploy/policy/auto-deploy-policy.spec.d.ts +1 -0
  77. package/dist/services/deploy/policy/auto-deploy-policy.spec.js +83 -0
  78. package/dist/services/deploy/policy/deploy-policy-model.d.ts +61 -0
  79. package/dist/services/deploy/policy/deploy-policy-model.js +41 -0
  80. package/dist/services/deploy/policy/index.d.ts +2 -0
  81. package/dist/services/deploy/policy/index.js +2 -0
  82. package/dist/services/deploy/policy/interactive-deploy-policy.d.ts +15 -0
  83. package/dist/services/deploy/policy/interactive-deploy-policy.js +16 -0
  84. package/dist/services/diff/diff-model.d.ts +5 -1
  85. package/dist/services/diff/diff-model.js +5 -1
  86. package/dist/services/diff/diff-service-factory.js +1 -1
  87. package/dist/services/diff/diff-service.d.ts +2 -1
  88. package/dist/services/diff/diff-service.js +6 -4
  89. package/dist/services/git/git-repository-model.d.ts +13 -0
  90. package/dist/services/git/git-repository-model.js +1 -0
  91. package/dist/services/git/git-repository.d.ts +35 -0
  92. package/dist/services/git/git-repository.js +120 -0
  93. package/dist/services/git/git-repository.spec.d.ts +1 -0
  94. package/dist/services/git/git-repository.spec.js +87 -0
  95. package/dist/services/git/index.d.ts +2 -0
  96. package/dist/services/git/index.js +2 -0
  97. package/dist/services/integration-api/spec/speed-kit-config-file.spec.js +1 -1
  98. package/oclif.manifest.json +140 -34
  99. package/package.json +1 -1
@@ -2,12 +2,14 @@ import { PostDeployCheckInterface } from "../../deploy-service-model.js";
2
2
  import { FileListInterface } from "../../../integration-api/index.js";
3
3
  import { CliService } from "../../../cli/index.js";
4
4
  import { ConfigApiService } from "../../../config-api/index.js";
5
+ import { DeployPolicyInterface } from "../../policy/index.js";
5
6
  export declare class DeprecatedDeploymentDetectionCheck implements PostDeployCheckInterface {
6
7
  private fileList;
7
8
  private cli;
8
9
  private configApi;
9
10
  private app;
10
- constructor(fileList: FileListInterface, cli: CliService, configApi: ConfigApiService, app: string);
11
+ private policy;
12
+ constructor(fileList: FileListInterface, cli: CliService, configApi: ConfigApiService, app: string, policy: DeployPolicyInterface);
11
13
  check(): Promise<void>;
12
14
  private deleteDeploymentJobDefinition;
13
15
  }
@@ -1,16 +1,19 @@
1
1
  import { INTEGRATION_FILES } from "../../../../models/files.js";
2
2
  import { safe } from "../../../../helpers/safe.js";
3
3
  import { PostDeployDeploymentDetectionError } from "../../error/post-deploy-deployment-detection-error.js";
4
+ import { DeployQuestion } from "../../policy/index.js";
4
5
  export class DeprecatedDeploymentDetectionCheck {
5
6
  fileList;
6
7
  cli;
7
8
  configApi;
8
9
  app;
9
- constructor(fileList, cli, configApi, app) {
10
+ policy;
11
+ constructor(fileList, cli, configApi, app, policy) {
10
12
  this.fileList = fileList;
11
13
  this.cli = cli;
12
14
  this.configApi = configApi;
13
15
  this.app = app;
16
+ this.policy = policy;
14
17
  }
15
18
  async check() {
16
19
  this.cli.startAction("POST:CHECK:DEPLOYMENT_DETECTION", "[postDeployCheck] deploymentDetection");
@@ -36,7 +39,7 @@ export class DeprecatedDeploymentDetectionCheck {
36
39
  this.cli.successAction("POST:CHECK:DEPLOYMENT_DETECTION");
37
40
  if (deployCheckJob) {
38
41
  this.cli.writeWarning(`Found active Job for ${this.cli.style.bold("deprecated")} deploymentDetection in app: ${this.app}`);
39
- if (await this.cli.confirm("Delete job for deploymentDetection?")) {
42
+ if (await this.policy.confirm(DeployQuestion.DeleteDeprecatedJob, "Delete job for deploymentDetection?")) {
40
43
  await this.deleteDeploymentJobDefinition(deployCheckJob);
41
44
  }
42
45
  }
@@ -44,7 +47,7 @@ export class DeprecatedDeploymentDetectionCheck {
44
47
  moduleResult.data &&
45
48
  moduleResult.data.length > 0) {
46
49
  this.cli.writeWarning(`Found ${this.cli.style.bold("deprecated")} module deploymentDetection in app: ${this.app}`);
47
- if (await this.cli.confirm("Delete module deploymentDetection?")) {
50
+ if (await this.policy.confirm(DeployQuestion.DeleteDeprecatedModule, "Delete module deploymentDetection?")) {
48
51
  this.cli.startAction("POST:CHECK:DEPLOYMENT_DETECTION:DELETE", "Delete module deploymentDetection");
49
52
  await this.configApi.deleteModule(INTEGRATION_FILES.DEPRECATED.DEPLOYMENT_DETECTION);
50
53
  this.cli.successAction("POST:CHECK:DEPLOYMENT_DETECTION:DELETE");
@@ -1,10 +1,12 @@
1
1
  import { CliService } from "../../../cli/index.js";
2
2
  import { FileListInterface, InstallResourceFile } from "../../../integration-api/index.js";
3
3
  import { PostDeployCheckInterface } from "../../deploy-service-model.js";
4
+ import { DeployPolicyInterface } from "../../policy/index.js";
4
5
  export default class SaveFilesCheck implements PostDeployCheckInterface {
6
+ private policy;
5
7
  private fileList;
6
8
  private readonly cli;
7
- constructor(fileList: FileListInterface, cli: CliService);
9
+ constructor(fileList: FileListInterface, cli: CliService, policy: DeployPolicyInterface);
8
10
  check(): Promise<void>;
9
11
  safeFiles(fileList: InstallResourceFile[]): Promise<void>;
10
12
  }
@@ -1,9 +1,12 @@
1
1
  import { safe } from "../../../../helpers/safe.js";
2
2
  import { SafeFileError } from "../../error/safe-file-error.js";
3
+ import { DeployQuestion } from "../../policy/index.js";
3
4
  export default class SaveFilesCheck {
5
+ policy;
4
6
  fileList;
5
7
  cli;
6
- constructor(fileList, cli) {
8
+ constructor(fileList, cli, policy) {
9
+ this.policy = policy;
7
10
  this.fileList = fileList;
8
11
  this.cli = cli;
9
12
  }
@@ -14,7 +17,7 @@ export default class SaveFilesCheck {
14
17
  if (fileList.length === 0) {
15
18
  return;
16
19
  }
17
- if (!(await this.cli.confirm(`Changes to localFiles will be saved now. Proceed?`))) {
20
+ if (!(await this.policy.confirm(DeployQuestion.SaveLocalFiles, `Changes to localFiles will be saved now. Proceed?`))) {
18
21
  return;
19
22
  }
20
23
  this.cli.startAction("POST:DEPLOY:SAVE_FILES", "safe changed files");
@@ -1,6 +1,7 @@
1
1
  import { FileListInterface, CustomerConfig } from "../../../integration-api/index.js";
2
2
  import { CliServiceInterface } from "../../../cli/index.js";
3
3
  import { ConfigApiService } from "../../../config-api/index.js";
4
+ import { DeployPolicyInterface } from "../../policy/index.js";
4
5
  export declare class DeviceDetectionChangedCheck {
5
6
  private cli;
6
7
  private fileList;
@@ -8,7 +9,8 @@ export declare class DeviceDetectionChangedCheck {
8
9
  private customerConfig;
9
10
  private configName;
10
11
  private isProduction;
11
- constructor(cli: CliServiceInterface, fileList: FileListInterface, configApi: ConfigApiService, customerConfig: CustomerConfig, configName: string, isProduction: boolean);
12
+ private policy;
13
+ constructor(cli: CliServiceInterface, fileList: FileListInterface, configApi: ConfigApiService, customerConfig: CustomerConfig, configName: string, isProduction: boolean, policy: DeployPolicyInterface);
12
14
  check(): Promise<void>;
13
15
  private checkForChangedDeviceDetection;
14
16
  private getActiveInstallResource;
@@ -1,6 +1,9 @@
1
1
  import { VirtualSpeedKitConfigFile, } from "../../../integration-api/index.js";
2
2
  import { INTEGRATION_FILES } from "../../../../models/files.js";
3
3
  import { safe } from "../../../../helpers/safe.js";
4
+ import { DeployQuestion } from "../../policy/index.js";
5
+ import { DeployAbortedError } from "../../error/deploy-aborted-error.js";
6
+ import ApplicationError from "../../../error-handling/error/application-error.js";
4
7
  export class DeviceDetectionChangedCheck {
5
8
  cli;
6
9
  fileList;
@@ -8,13 +11,15 @@ export class DeviceDetectionChangedCheck {
8
11
  customerConfig;
9
12
  configName;
10
13
  isProduction;
11
- constructor(cli, fileList, configApi, customerConfig, configName, isProduction) {
14
+ policy;
15
+ constructor(cli, fileList, configApi, customerConfig, configName, isProduction, policy) {
12
16
  this.cli = cli;
13
17
  this.fileList = fileList;
14
18
  this.configApi = configApi;
15
19
  this.customerConfig = customerConfig;
16
20
  this.configName = configName;
17
21
  this.isProduction = isProduction;
22
+ this.policy = policy;
18
23
  }
19
24
  async check() {
20
25
  if (
@@ -47,9 +52,9 @@ export class DeviceDetectionChangedCheck {
47
52
  return;
48
53
  }
49
54
  // this.cli.table(changes, { origin: {}, type: {}, old: {}, new: {} });
50
- const result = await this.cli.confirm(`Detected change in ${changes.join(" | ")}. ${this.cli.style.red("Was this checked by QA?")}`, false);
55
+ const result = await this.policy.confirm(DeployQuestion.DeviceDetectionChange, `Detected change in ${changes.join(" | ")}. ${this.cli.style.red("Was this checked by QA?")}`, false);
51
56
  if (!result) {
52
- this.cli.exit(0);
57
+ throw new DeployAbortedError("the device detection change was not confirmed");
53
58
  }
54
59
  }
55
60
  async checkForChangedDeviceDetection(speedKitConfigFile, activeSpeedKitConfig) {
@@ -94,8 +99,7 @@ export class DeviceDetectionChangedCheck {
94
99
  const activeInstallResourceResponse = await safe(this.configApi.getActiveInstall(this.configName));
95
100
  if (activeInstallResourceResponse.success !== true) {
96
101
  this.cli.failAction("PRE:CHECK:DEVICE_DETECTION", "Could not load active install resource");
97
- this.cli.exit(1);
98
- return;
102
+ throw new ApplicationError(`Could not load the active install resource of ${this.configName}`);
99
103
  }
100
104
  return activeInstallResourceResponse.data;
101
105
  }
@@ -1,6 +1,7 @@
1
1
  import { FileListInterface, CustomerConfig } from "../../../integration-api/index.js";
2
2
  import { CliServiceInterface } from "../../../cli/index.js";
3
3
  import { ConfigApiService } from "../../../config-api/index.js";
4
+ import { DeployPolicyInterface } from "../../policy/index.js";
4
5
  export declare class SplitChangeCheck {
5
6
  private cli;
6
7
  private fileList;
@@ -8,7 +9,8 @@ export declare class SplitChangeCheck {
8
9
  private customerConfig;
9
10
  private configName;
10
11
  private isProduction;
11
- constructor(cli: CliServiceInterface, fileList: FileListInterface, configApi: ConfigApiService, customerConfig: CustomerConfig, configName: string, isProduction: boolean);
12
+ private policy;
13
+ constructor(cli: CliServiceInterface, fileList: FileListInterface, configApi: ConfigApiService, customerConfig: CustomerConfig, configName: string, isProduction: boolean, policy: DeployPolicyInterface);
12
14
  check(): Promise<void>;
13
15
  private checkSplitsForEachOrigin;
14
16
  private getActiveInstallResource;
@@ -2,6 +2,8 @@ import { VirtualSpeedKitConfigFile, } from "../../../integration-api/index.js";
2
2
  import { INTEGRATION_FILES } from "../../../../models/files.js";
3
3
  import { safe } from "../../../../helpers/safe.js";
4
4
  import ApplicationError from "../../../error-handling/error/application-error.js";
5
+ import { DeployQuestion } from "../../policy/index.js";
6
+ import { DeployAbortedError } from "../../error/deploy-aborted-error.js";
5
7
  export class SplitChangeCheck {
6
8
  cli;
7
9
  fileList;
@@ -9,13 +11,15 @@ export class SplitChangeCheck {
9
11
  customerConfig;
10
12
  configName;
11
13
  isProduction;
12
- constructor(cli, fileList, configApi, customerConfig, configName, isProduction) {
14
+ policy;
15
+ constructor(cli, fileList, configApi, customerConfig, configName, isProduction, policy) {
13
16
  this.cli = cli;
14
17
  this.fileList = fileList;
15
18
  this.configApi = configApi;
16
19
  this.customerConfig = customerConfig;
17
20
  this.configName = configName;
18
21
  this.isProduction = isProduction;
22
+ this.policy = policy;
19
23
  }
20
24
  async check() {
21
25
  if (
@@ -50,9 +54,9 @@ export class SplitChangeCheck {
50
54
  }
51
55
  // @ts-expect-error incompatible type
52
56
  this.cli.table(changes, { origin: {}, type: {}, old: {}, new: {} });
53
- const result = await this.cli.confirm("Split change detected. Do you want to continue?", false);
57
+ const result = await this.policy.confirm(DeployQuestion.SplitChange, "Split change detected. Do you want to continue?", false);
54
58
  if (!result) {
55
- this.cli.exit(0);
59
+ throw new DeployAbortedError("the split change was not confirmed");
56
60
  }
57
61
  }
58
62
  async checkSplitsForEachOrigin(speedKitConfigFile, activeSpeedKitConfig) {
@@ -116,8 +120,7 @@ export class SplitChangeCheck {
116
120
  const activeInstallResourceResponse = await safe(this.configApi.getActiveInstall(this.configName));
117
121
  if (activeInstallResourceResponse.success !== true) {
118
122
  this.cli.failAction("PRE:CHECK:SPLIT_CHANGE", "Could not load active install resource");
119
- this.cli.exit(1);
120
- return;
123
+ throw new ApplicationError(`Could not load the active install resource of ${this.configName}`);
121
124
  }
122
125
  return activeInstallResourceResponse.data;
123
126
  }
@@ -0,0 +1,55 @@
1
+ import { expect } from "chai";
2
+ import { describe, it } from "mocha";
3
+ import { Chalk } from "chalk";
4
+ import { SplitChangeCheck } from "./split-change-check.js";
5
+ import { DeployAbortedError } from "../../error/deploy-aborted-error.js";
6
+ import { CustomerConfig, } from "../../../integration-api/index.js";
7
+ /** A local config that serves half of the traffic. */
8
+ const LOCAL_SPLIT = { split: 0.5, splitTestId: "test-id" };
9
+ /** The active config of the app, which serves none. */
10
+ const REMOTE_CONFIG = "window.speedKit = { appName: APP, split: 0 };";
11
+ function checkAnswering(answer) {
12
+ const cli = {
13
+ style: new Chalk({ level: 0 }),
14
+ startAction: () => undefined,
15
+ successAction: () => undefined,
16
+ failAction: () => undefined,
17
+ table: () => undefined,
18
+ writeError: () => undefined,
19
+ };
20
+ const speedKitConfig = {
21
+ remoteKey: "config",
22
+ shouldSkipFile: () => false,
23
+ evaluate: async () => LOCAL_SPLIT,
24
+ };
25
+ const fileList = {
26
+ hasFile: () => true,
27
+ getSpeedKitConfig: () => speedKitConfig,
28
+ };
29
+ const configApi = {
30
+ getActiveInstall: async () => ({ config: REMOTE_CONFIG }),
31
+ };
32
+ const customer = CustomerConfig.createFrom({
33
+ app: "test-app",
34
+ origins: ["https://www.example.com"],
35
+ swPath: "/sw.js",
36
+ scope: "/",
37
+ });
38
+ const policy = {
39
+ confirm: async () => answer,
40
+ text: async () => "",
41
+ };
42
+ return new SplitChangeCheck(cli, fileList, configApi, customer, "production", true, policy);
43
+ }
44
+ describe("SplitChangeCheck", () => {
45
+ it("aborts the deploy when the split change is not confirmed", async () => {
46
+ const error = await checkAnswering(false)
47
+ .check()
48
+ .catch((error) => error);
49
+ expect(error).to.be.instanceOf(DeployAbortedError);
50
+ expect(error.reason).to.equal("the split change was not confirmed");
51
+ });
52
+ it("lets the deploy continue when the split change is confirmed", async () => {
53
+ await checkAnswering(true).check();
54
+ });
55
+ });
@@ -4,9 +4,29 @@ export default class DeployContext {
4
4
  readonly configName: string;
5
5
  readonly dryRun: boolean;
6
6
  readonly useTestConfig: boolean;
7
+ /** Leave out the modules and the server config, which a bulk never deploys. */
8
+ readonly installFilesOnly: boolean;
9
+ /**
10
+ * Leave out the checks that run after the upload. Each of them asks the
11
+ * app for its jobs and its modules, which a run over many customers pays
12
+ * for once per customer.
13
+ */
14
+ readonly skipPostDeployChecks: boolean;
15
+ /** Open the diff tool for a file that differs, as a person expects. */
16
+ readonly opensDiffTool: boolean;
7
17
  static flags: Record<string, Command.Flag>;
8
18
  readonly artifacts?: string[];
9
19
  readonly isProduction: boolean;
10
- constructor(customerPath: string, configName?: string, artifacts?: string, dryRun?: boolean, useTestConfig?: boolean);
20
+ constructor(customerPath: string, configName?: string, artifacts?: string, dryRun?: boolean, useTestConfig?: boolean,
21
+ /** Leave out the modules and the server config, which a bulk never deploys. */
22
+ installFilesOnly?: boolean,
23
+ /**
24
+ * Leave out the checks that run after the upload. Each of them asks the
25
+ * app for its jobs and its modules, which a run over many customers pays
26
+ * for once per customer.
27
+ */
28
+ skipPostDeployChecks?: boolean,
29
+ /** Open the diff tool for a file that differs, as a person expects. */
30
+ opensDiffTool?: boolean);
11
31
  hasArtifacts(): boolean;
12
32
  }
@@ -9,6 +9,9 @@ export default class DeployContext {
9
9
  configName;
10
10
  dryRun;
11
11
  useTestConfig;
12
+ installFilesOnly;
13
+ skipPostDeployChecks;
14
+ opensDiffTool;
12
15
  static flags = {
13
16
  ...CLI_CONFIG_NAME,
14
17
  ...CLI_CONFIG_IS_TEST,
@@ -26,14 +29,40 @@ export default class DeployContext {
26
29
  char: "a",
27
30
  description: "which files to upload",
28
31
  }),
32
+ mr: Flags.integer({
33
+ description: "deploy the reviewed change of this merged merge request, without questions",
34
+ }),
35
+ description: Flags.string({
36
+ dependsOn: ["mr"],
37
+ description: "the description every installation of the run gets, asked while it is left out",
38
+ }),
39
+ approval: Flags.string({
40
+ options: ["approved", "testing", "skip"],
41
+ default: "skip",
42
+ dependsOn: ["mr"],
43
+ description: "what to do with a customer that approves every rollout themselves",
44
+ }),
29
45
  };
30
46
  artifacts;
31
47
  isProduction;
32
- constructor(customerPath, configName = DEFAULT_CONFIG_NAME, artifacts, dryRun = false, useTestConfig = false) {
48
+ constructor(customerPath, configName = DEFAULT_CONFIG_NAME, artifacts, dryRun = false, useTestConfig = false,
49
+ /** Leave out the modules and the server config, which a bulk never deploys. */
50
+ installFilesOnly = false,
51
+ /**
52
+ * Leave out the checks that run after the upload. Each of them asks the
53
+ * app for its jobs and its modules, which a run over many customers pays
54
+ * for once per customer.
55
+ */
56
+ skipPostDeployChecks = false,
57
+ /** Open the diff tool for a file that differs, as a person expects. */
58
+ opensDiffTool = true) {
33
59
  this.customerPath = customerPath;
34
60
  this.configName = configName;
35
61
  this.dryRun = dryRun;
36
62
  this.useTestConfig = useTestConfig;
63
+ this.installFilesOnly = installFilesOnly;
64
+ this.skipPostDeployChecks = skipPostDeployChecks;
65
+ this.opensDiffTool = opensDiffTool;
37
66
  this.artifacts = artifacts ? artifacts.split(ARTIFACTS_SEPARATOR) : [];
38
67
  this.isProduction = configName.toLowerCase().includes("prod");
39
68
  }
@@ -1,11 +1,23 @@
1
1
  import { UserCliConfig } from "../../helpers/cli-config.js";
2
2
  import DeployContext from "./context/deploy-context.js";
3
3
  import DeployService from "./deploy-service.js";
4
+ import { FileListInterface } from "../integration-api/index.js";
5
+ import { ConfigApiService } from "../config-api/index.js";
6
+ import { DeployPolicyInterface } from "./policy/index.js";
4
7
  export default class DeployServiceFactory {
5
8
  private context;
6
9
  private cliConfig;
10
+ /** The answers of the deploy. A person answers while this is left out. */
11
+ private policyOverride?;
7
12
  private service?;
8
- constructor(context: DeployContext, cliConfig: UserCliConfig);
13
+ /** The configuration on disk, as the service it built deploys it. */
14
+ files?: FileListInterface;
15
+ /** The name the installation has in the app. */
16
+ configName?: string;
17
+ configApi?: ConfigApiService;
18
+ constructor(context: DeployContext, cliConfig: UserCliConfig,
19
+ /** The answers of the deploy. A person answers while this is left out. */
20
+ policyOverride?: DeployPolicyInterface);
9
21
  buildService(): Promise<DeployService>;
10
22
  private build;
11
23
  private getConfigApi;
@@ -9,20 +9,30 @@ import InstallResourceHandler from "./handler/install-resource-handler.js";
9
9
  import DeletedFileCheck from "./handler/install-resource-modifier/deleted-file-check.js";
10
10
  import ModuleHandler from "./handler/module-handler.js";
11
11
  import ServerConfigHandler from "./handler/server-config-handler.js";
12
- import { IntegrationApiFactory, IntegrationApiContext, DEFAULT_BLOCKED_FOLDERS, } from "../integration-api/index.js";
12
+ import { IntegrationApiFactory, IntegrationApiContext, FILE_TYPE, DEFAULT_BLOCKED_FOLDERS, } from "../integration-api/index.js";
13
13
  import { SplitChangeCheck } from "./checks/pre-deploy/split-change-check.js";
14
14
  import { ConfigApiContext, ConfigApiServiceFactory, } from "../config-api/index.js";
15
15
  import { DeprecatedDeploymentDetectionCheck } from "./checks/post-deploy/deprecated-deployment-detection-check.js";
16
16
  import { DeviceDetectionChangedCheck } from "./checks/pre-deploy/device-detection-changed-check.js";
17
17
  import { RefreshDeploymentJobCheck } from "./checks/post-deploy/refresh-deployment-job-check.js";
18
18
  import { CustomerApprovalCheck } from "./checks/activation/customer-approval-check.js";
19
+ import { InteractiveDeployPolicy, } from "./policy/index.js";
19
20
  export default class DeployServiceFactory {
20
21
  context;
21
22
  cliConfig;
23
+ policyOverride;
22
24
  service = undefined;
23
- constructor(context, cliConfig) {
25
+ /** The configuration on disk, as the service it built deploys it. */
26
+ files = undefined;
27
+ /** The name the installation has in the app. */
28
+ configName = undefined;
29
+ configApi = undefined;
30
+ constructor(context, cliConfig,
31
+ /** The answers of the deploy. A person answers while this is left out. */
32
+ policyOverride) {
24
33
  this.context = context;
25
34
  this.cliConfig = cliConfig;
35
+ this.policyOverride = policyOverride;
26
36
  }
27
37
  async buildService() {
28
38
  if (!(this.service instanceof DeployService)) {
@@ -35,19 +45,25 @@ export default class DeployServiceFactory {
35
45
  const customer = files.getCustomerConfig().config;
36
46
  const configName = customer.name || this.context.configName;
37
47
  const configApi = this.getConfigApi(customer.app);
38
- const diffService = new DiffServiceFactory(new DiffContext(this.cliConfig.diffExec, this.cliConfig.diffExecTemplate)).getService();
48
+ this.files = files;
49
+ this.configName = configName;
50
+ this.configApi = configApi;
51
+ const diffService = new DiffServiceFactory(new DiffContext(this.cliConfig.diffExec, this.cliConfig.diffExecTemplate, this.context.opensDiffTool)).getService();
39
52
  const cliService = new CliServiceFactory().getService();
53
+ const policy = this.policyOverride ?? new InteractiveDeployPolicy(cliService);
40
54
  const installResourceBuilder = new InstallResourceBuilder(configApi);
41
- const deletedFilesChecker = new DeletedFileCheck(cliService, this.context.hasArtifacts());
55
+ const deletedFilesChecker = new DeletedFileCheck(cliService, policy, this.context.hasArtifacts());
42
56
  this.service = new DeployService(files, [
43
- new CustomerConfigHandler(customer, configApi, configName, diffService, cliService, installResourceBuilder),
44
- new InstallResourceHandler(customer, configApi, configName, diffService, cliService, installResourceBuilder, deletedFilesChecker, new CustomerApprovalCheck(cliService, customer)),
45
- new ModuleHandler(configApi, diffService, cliService, []),
46
- new ServerConfigHandler(configApi, diffService, cliService),
57
+ new CustomerConfigHandler(customer, configApi, configName, diffService, cliService, installResourceBuilder, policy),
58
+ new InstallResourceHandler(customer, configApi, configName, diffService, cliService, installResourceBuilder, deletedFilesChecker, new CustomerApprovalCheck(cliService, customer, policy), policy),
59
+ new ModuleHandler(configApi, diffService, cliService, [], policy),
60
+ new ServerConfigHandler(configApi, diffService, cliService, policy),
47
61
  ], cliService, [
48
- new SplitChangeCheck(cliService, files, configApi, customer, configName, this.context.isProduction),
49
- new DeviceDetectionChangedCheck(cliService, files, configApi, customer, configName, this.context.isProduction),
50
- ], await this.getPostDeployChecks(files, cliService, configApi, customer.app), this.context.dryRun);
62
+ new SplitChangeCheck(cliService, files, configApi, customer, configName, this.context.isProduction, policy),
63
+ new DeviceDetectionChangedCheck(cliService, files, configApi, customer, configName, this.context.isProduction, policy),
64
+ ], this.context.skipPostDeployChecks
65
+ ? []
66
+ : await this.getPostDeployChecks(files, cliService, configApi, customer.app, policy), this.context.dryRun);
51
67
  }
52
68
  getConfigApi(app) {
53
69
  const configApiContext = new ConfigApiContext(app);
@@ -56,13 +72,18 @@ export default class DeployServiceFactory {
56
72
  async getIntegrationFiles() {
57
73
  const integrationApiContext = new IntegrationApiContext(this.context.customerPath, this.context.configName, this.context.artifacts, DEFAULT_BLOCKED_FOLDERS, this.context.useTestConfig);
58
74
  const integrationApi = new IntegrationApiFactory(integrationApiContext, this.cliConfig).buildService();
59
- return integrationApi.run();
75
+ const files = await integrationApi.run();
76
+ if (this.context.installFilesOnly) {
77
+ files.filter((file) => file.type === FILE_TYPE.INSTALL_FILE ||
78
+ file.type === FILE_TYPE.CUSTOMER_FILE);
79
+ }
80
+ return files;
60
81
  }
61
- async getPostDeployChecks(files, cliService, configApi, app) {
82
+ async getPostDeployChecks(files, cliService, configApi, app, policy) {
62
83
  return [
63
- new SaveFilesCheck(files, cliService),
84
+ new SaveFilesCheck(files, cliService, policy),
64
85
  new RevalidatedModuleCheck(configApi, cliService, app),
65
- new DeprecatedDeploymentDetectionCheck(files, cliService, configApi, app),
86
+ new DeprecatedDeploymentDetectionCheck(files, cliService, configApi, app, policy),
66
87
  new RefreshDeploymentJobCheck(await configApi.client.getEntityManager(), cliService),
67
88
  ];
68
89
  }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A deploy that stopped on purpose, because a question was answered with no.
3
+ *
4
+ * This is not a failure: the command reports the reason and ends with 0. A
5
+ * caller that deploys several configurations catches it, records the reason
6
+ * and continues with the next configuration.
7
+ */
8
+ export declare class DeployAbortedError extends Error {
9
+ readonly reason: string;
10
+ readonly code = "DEPLOY_ABORTED";
11
+ constructor(reason: string);
12
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A deploy that stopped on purpose, because a question was answered with no.
3
+ *
4
+ * This is not a failure: the command reports the reason and ends with 0. A
5
+ * caller that deploys several configurations catches it, records the reason
6
+ * and continues with the next configuration.
7
+ */
8
+ export class DeployAbortedError extends Error {
9
+ reason;
10
+ code = "DEPLOY_ABORTED";
11
+ constructor(reason) {
12
+ super(reason);
13
+ this.reason = reason;
14
+ this.name = "DeployAbortedError";
15
+ }
16
+ }
@@ -4,6 +4,7 @@ import { DiffService } from "../../diff/index.js";
4
4
  import { CliService } from "../../cli/index.js";
5
5
  import InstallResourceBuilder from "../builder/install-resource-builder.js";
6
6
  import { ConfigApiService } from "../../config-api/index.js";
7
+ import { DeployPolicyInterface } from "../policy/index.js";
7
8
  export default class CustomerConfigHandler implements DeployHandlerInterface {
8
9
  private readonly customer;
9
10
  private readonly configApi;
@@ -11,7 +12,8 @@ export default class CustomerConfigHandler implements DeployHandlerInterface {
11
12
  private diffService;
12
13
  private cli;
13
14
  private builder;
14
- constructor(customer: CustomerConfig, configApi: ConfigApiService, configName: string, diffService: DiffService, cli: CliService, builder: InstallResourceBuilder);
15
+ private policy;
16
+ constructor(customer: CustomerConfig, configApi: ConfigApiService, configName: string, diffService: DiffService, cli: CliService, builder: InstallResourceBuilder, policy: DeployPolicyInterface);
15
17
  canHandle(type: FILE_TYPE): boolean;
16
18
  handle(files: CustomerConfigFile[]): Promise<void>;
17
19
  upload(files: CustomerConfigFile[]): Promise<void>;
@@ -1,5 +1,7 @@
1
1
  import { FILE_TYPE, } from "../../integration-api/index.js";
2
2
  import chalk from "chalk";
3
+ import { DeployQuestion } from "../policy/index.js";
4
+ import { DeployAbortedError } from "../error/deploy-aborted-error.js";
3
5
  export default class CustomerConfigHandler {
4
6
  customer;
5
7
  configApi;
@@ -7,13 +9,15 @@ export default class CustomerConfigHandler {
7
9
  diffService;
8
10
  cli;
9
11
  builder;
10
- constructor(customer, configApi, configName, diffService, cli, builder) {
12
+ policy;
13
+ constructor(customer, configApi, configName, diffService, cli, builder, policy) {
11
14
  this.customer = customer;
12
15
  this.configApi = configApi;
13
16
  this.configName = configName;
14
17
  this.diffService = diffService;
15
18
  this.cli = cli;
16
19
  this.builder = builder;
20
+ this.policy = policy;
17
21
  }
18
22
  canHandle(type) {
19
23
  return type === FILE_TYPE.CUSTOMER_FILE;
@@ -42,7 +46,8 @@ export default class CustomerConfigHandler {
42
46
  const { updatedFile } = await this.diffService.diffContent(file.name, JSON.stringify(installResource.origins, null, 4), JSON.stringify(config.origins, null, 4));
43
47
  const origins = JSON.parse(updatedFile);
44
48
  file.updateOrigins(origins);
45
- if (!(await this.cli.confirm("Update origins?", true))) {
49
+ const updateOrigins = await this.policy.confirm(DeployQuestion.UpdateOrigins, "Update origins?", true);
50
+ if (!updateOrigins) {
46
51
  file.skipFile();
47
52
  return;
48
53
  }
@@ -66,11 +71,10 @@ export default class CustomerConfigHandler {
66
71
  this.cli.spacer();
67
72
  this.cli.writeWarning(`No ${chalk.underline("active")} remote config named ${chalk.bold(configName)} found in app ${chalk.bold(appName)}`);
68
73
  this.cli.spacer();
69
- if (await this.cli.confirm("Continue creating a new config?")) {
70
- this.cli.write(`New configuration named ${chalk.bold(configName)} will be created in app ${chalk.bold(appName)}`, true);
71
- }
72
- else {
73
- this.cli.exit();
74
+ const createConfig = await this.policy.confirm(DeployQuestion.CreateConfig, "Continue creating a new config?");
75
+ if (!createConfig) {
76
+ throw new DeployAbortedError(`no active configuration named ${configName} exists in app ${appName}`);
74
77
  }
78
+ this.cli.write(`New configuration named ${chalk.bold(configName)} will be created in app ${chalk.bold(appName)}`, true);
75
79
  }
76
80
  }
@@ -6,6 +6,7 @@ import DeletedFileCheck from "./install-resource-modifier/deleted-file-check.js"
6
6
  import { CustomerConfig, FILE_TYPE, InstallResourceInterface } from "../../integration-api/index.js";
7
7
  import { ConfigApiService } from "../../config-api/index.js";
8
8
  import { CustomerApprovalCheck } from "../checks/activation/customer-approval-check.js";
9
+ import { DeployPolicyInterface } from "../policy/index.js";
9
10
  export default class InstallResourceHandler implements DeployHandlerInterface {
10
11
  private readonly customer;
11
12
  private readonly configApi;
@@ -15,7 +16,8 @@ export default class InstallResourceHandler implements DeployHandlerInterface {
15
16
  private builder;
16
17
  private deletedFilesChecker;
17
18
  private customerApprovalCheck;
18
- constructor(customer: CustomerConfig, configApi: ConfigApiService, configName: string, diffService: DiffService, cli: CliService, builder: InstallResourceBuilder, deletedFilesChecker: DeletedFileCheck, customerApprovalCheck: CustomerApprovalCheck);
19
+ private policy;
20
+ constructor(customer: CustomerConfig, configApi: ConfigApiService, configName: string, diffService: DiffService, cli: CliService, builder: InstallResourceBuilder, deletedFilesChecker: DeletedFileCheck, customerApprovalCheck: CustomerApprovalCheck, policy: DeployPolicyInterface);
19
21
  canHandle(type: FILE_TYPE): boolean;
20
22
  handle(files: InstallResourceInterface[]): Promise<void>;
21
23
  upload(files: InstallResourceInterface[]): Promise<void>;