@speedkit/cli 2.8.0 → 2.9.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,72 @@
1
+ # [2.9.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.8.0...v2.9.0) (2024-03-15)
2
+
3
+
4
+ ### Features
5
+
6
+ * adjust eslint configuration ([5d7a0b9](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/5d7a0b98615612a32f87208dbf7d5017996ab7ca))
7
+
8
+ # [2.8.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.7.0...v2.8.0) (2024-03-08)
9
+
10
+
11
+ ### Features
12
+
13
+ * **onboarding:** load serverConfig for documentHandlerRequests ([4953244](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/49532441ab1e927373be886d926e56231d04a6ae))
14
+
15
+ # [2.7.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.6.0...v2.7.0) (2024-03-06)
16
+
17
+
18
+ ### Features
19
+
20
+ * optimise package json ([6b1b8b2](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/6b1b8b29a04e1ff08ff30e4d18c73168e8ca7aee))
21
+
22
+ # [2.6.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.5.0...v2.6.0) (2024-03-05)
23
+
24
+
25
+ ### Features
26
+
27
+ * add updateNotificationPlugin ([b81b4c0](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/b81b4c0575b81b52b541c4a30b43d6c9deaa17b5))
28
+ * **origins:** merge main ([4c43612](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/4c43612d403453809b10a2f3f7bd284364591373))
29
+ * **updateNotification:** add missing config ([bb33eda](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/bb33eda03ab129320e9c93960469bbb35cce09dc))
30
+ * **versionNotify:** update packageLockJson ([520b212](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/520b212543b78ea2d34e8eeafb44319e9785357a))
31
+
32
+ # [2.5.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.4.1...v2.5.0) (2024-03-05)
33
+
34
+
35
+ ### Features
36
+
37
+ * **onboarding:** allow vmDocumentHandler to requestAllModules from outer NodeJs ([82dbeb1](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/82dbeb1a261e4a3b72f63f3a3576ee12f68c3912))
38
+
39
+ ## [2.4.1](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.4.0...v2.4.1) (2024-03-01)
40
+
41
+
42
+ ### Bug Fixes
43
+
44
+ * **customer-config:** update config customer template ([a69a47d](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/a69a47de326b813650f5364bcd4cdfa1659b9563))
45
+
46
+ # [2.4.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.3.0...v2.4.0) (2024-03-01)
47
+
48
+
49
+ ### Features
50
+
51
+ * update dependencies ([ee809a7](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/ee809a7beb2077d6db5c150126964facf307e9a3))
52
+
53
+ # [2.3.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.2.0...v2.3.0) (2024-03-01)
54
+
55
+
56
+ ### Features
57
+
58
+ * **customer-config:** disable all sites by default ([b2c9e9d](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/b2c9e9dcc20c98619691986191cff75843237f9b))
59
+ * **deploy:** merge main ([8f8aac2](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/8f8aac2119b9d02a25bf32a073f4a283d99d7f5a))
60
+ * **diff:** add diffExecutionTemplate ([04a8aa6](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/04a8aa6d4224ce142264a03905090c58ee59edf7))
61
+ * **documentHandler:** fix fileCreation on mac ([424c116](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/424c116887c2190d672b66d9e99b5d17cdc6eae6))
62
+ * **onboarding:** add support for predictive-preloading ([4ac6a21](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/4ac6a21f6603426e89628f5256bda9f0d7855d87))
63
+ * **pull:** add check for changed files ([3251875](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/3251875b36e717d63b0a60fc43a4dcdf9a5febd0))
64
+ * **pull:** add delete and create Actions ([306e46d](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/306e46dcacdc52d9a36fd41359a276b7c58abfb7))
65
+ * **pull:** add delete- and createFileActions ([7e0e66e](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/7e0e66e498e117ed13e720e625f41adbb7b07e51))
66
+ * **pull:** add testingFramework ([35cc8ec](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/35cc8eca3f99c90174a3766e31e5d19730af912f))
67
+ * **pull:** merge main ([f73a729](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/f73a7298192b111b6245ac099b51ee57fa4a5c48))
68
+ * **pull:** remove tryCatch from pullCommand ([90b873c](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/90b873c2e2205b05d3670de8af7e842cef8ad395))
69
+ * **pullService:** add tests ([e07e7a9](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/e07e7a900d53e75fde1948666cd9a27926d5f302))
70
+ * **sync:** pull command ([8b2b43a](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/8b2b43a299f9b7ccb11779dacdabf1329cd6274f))
71
+ * **userConfig:** add configFile for cli ([b6e052e](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/b6e052e21a25b7b6800156977ed58b6ee5ecf93b))
72
+ * **userConfig:** update readme.md ([55a1f5b](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/55a1f5bb3ec816a2a38b429cd19fb8a1bc74c21d))
package/README.md CHANGED
@@ -74,7 +74,7 @@ $ npm install -g @speedkit/cli
74
74
  $ sk COMMAND
75
75
  running command...
76
76
  $ sk (--version)
77
- @speedkit/cli/2.8.0 linux-x64 node-v20.11.1
77
+ @speedkit/cli/2.9.0 linux-x64 node-v20.11.1
78
78
  $ sk --help [COMMAND]
79
79
  USAGE
80
80
  $ sk COMMAND
@@ -1,10 +1,10 @@
1
- import { Command } from '@oclif/core';
1
+ import { Command } from "@oclif/core";
2
2
  export default class GenerateCustomerConfig extends Command {
3
3
  static description: string;
4
+ static examples: string[];
4
5
  static flags: {
5
6
  app: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
6
7
  customersDir: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
7
8
  };
8
- static examples: string[];
9
9
  run(): Promise<void>;
10
10
  }
@@ -4,23 +4,23 @@ const core_1 = require("@oclif/core");
4
4
  const cli_parameters_1 = require("../models/cli-parameters");
5
5
  const customer_config_1 = require("../services/customer-config");
6
6
  class GenerateCustomerConfig extends core_1.Command {
7
- static description = 'Generates a customer config guided by a wizard 🧙‍';
7
+ static description = "Generates a customer config guided by a wizard 🧙‍";
8
+ static examples = [
9
+ `$ sk generate-customer-config -${cli_parameters_1.CLIParametersChar.AppName} <${cli_parameters_1.CLIParameters.AppName}> -${cli_parameters_1.CLIParametersChar.CustomersDir} <${cli_parameters_1.CLIParameters.CustomersDir}>`,
10
+ `$ sk generate-customer-config -${cli_parameters_1.CLIParametersChar.AppName} ${cli_parameters_1.CLIParametersExample.AppName} -${cli_parameters_1.CLIParametersChar.CustomersDir} ${cli_parameters_1.CLIParametersExample.CustomersDir}`,
11
+ ];
8
12
  static flags = {
9
13
  [cli_parameters_1.CLIParameters.AppName]: core_1.Flags.string({
10
- description: `The SK app name which is also being used the config output directory name (kebab-case)`,
11
14
  char: cli_parameters_1.CLIParametersChar.AppName,
15
+ description: "The SK app name which is also being used the config output directory name (kebab-case)",
12
16
  }),
13
17
  [cli_parameters_1.CLIParameters.CustomersDir]: core_1.Flags.string({
18
+ char: cli_parameters_1.CLIParametersChar.CustomersDir,
14
19
  description: `Name of the sk-onboarding directory where all customer configs are being stored (default: "${cli_parameters_1.CLIParametersExample.CustomersDir}")`,
15
- char: cli_parameters_1.CLIParametersChar.CustomersDir
16
20
  }),
17
21
  };
18
- static examples = [
19
- `$ sk generate-customer-config -${cli_parameters_1.CLIParametersChar.AppName} <${cli_parameters_1.CLIParameters.AppName}> -${cli_parameters_1.CLIParametersChar.CustomersDir} <${cli_parameters_1.CLIParameters.CustomersDir}>`,
20
- `$ sk generate-customer-config -${cli_parameters_1.CLIParametersChar.AppName} ${cli_parameters_1.CLIParametersExample.AppName} -${cli_parameters_1.CLIParametersChar.CustomersDir} ${cli_parameters_1.CLIParametersExample.CustomersDir}`,
21
- ];
22
22
  async run() {
23
- const { flags: { app, customersDir } } = await this.parse(GenerateCustomerConfig);
23
+ const { flags: { app, customersDir }, } = await this.parse(GenerateCustomerConfig);
24
24
  const context = new customer_config_1.CustomerConfigServiceContext(app, customersDir);
25
25
  const customerConfigService = await new customer_config_1.CustomerConfigServiceFactory(context).buildService();
26
26
  await customerConfigService.generateConfig();
@@ -1,4 +1,4 @@
1
- import { Command } from '@oclif/core';
1
+ import { Command } from "@oclif/core";
2
2
  export default class GeneratePopConfig extends Command {
3
3
  static args: {
4
4
  app: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
@@ -8,9 +8,9 @@ export default class GeneratePopConfig extends Command {
8
8
  static flags: {
9
9
  coverage: import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
10
10
  deploy: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
- 'pop-limit': import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
12
- 'traffic-share': import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
13
- 'use-rum': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
+ "pop-limit": import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
12
+ "traffic-share": import("@oclif/core/lib/interfaces").OptionFlag<number, import("@oclif/core/lib/interfaces").CustomOptions>;
13
+ "use-rum": import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
14
14
  };
15
15
  createPopPrewarmingCode(popConfig: string): Promise<string>;
16
16
  deployPrewarmingConfig(app: string, config: string, deploy: boolean | undefined): Promise<void>;
@@ -11,54 +11,113 @@ const cli_2 = require("../services/cli");
11
11
  const config_api_service_1 = tslib_1.__importDefault(require("../services/config-api-service"));
12
12
  const diff_service_1 = require("../services/diff-service");
13
13
  const POP_REMAPPING = {
14
- HHN: 'FRA',
14
+ HHN: "FRA",
15
15
  };
16
16
  const SHIELDS = [
17
- { condition: () => true, pop: 'FRA', shield: 'Default Shield' },
18
- { condition: ({ region }) => region.startsWith('US'), pop: 'LGA', shield: 'United States Shield' },
19
- { condition: ({ region }) => region.startsWith('SA'), pop: 'GRU', shield: 'South America Shield' },
20
- { condition: ({ region }) => region.startsWith('APAC'), pop: 'SYD', shield: 'APAC Shield' },
21
- { condition: ({ pop }) => ['KUL', 'QPG'].includes(pop), pop: 'QPG', shield: 'Singapore Shield' },
22
- { condition: ({ pop }) => ['HKG', 'ICN', 'MNL'].includes(pop), pop: 'HKG', shield: 'Hongkong Shield' },
23
- { condition: ({ region }) => region === 'Asia-South', pop: 'DEL', shield: 'Asia South Shield' },
24
- { condition: ({ region }) => region === 'North-America', pop: 'YYZ', shield: 'North America Shield' },
25
- { condition: ({ pop }) => ['DXB', 'FJR'].includes(pop), pop: 'FJR', shield: 'United Arab Emirates Shield' },
26
- { condition: ({ region }) => region === 'South-Africa', pop: 'JNB', shield: 'South Africa Shield' },
17
+ { condition: () => true, pop: "FRA", shield: "Default Shield" },
18
+ {
19
+ condition: ({ region }) => region.startsWith("US"),
20
+ pop: "LGA",
21
+ shield: "United States Shield",
22
+ },
23
+ {
24
+ condition: ({ region }) => region.startsWith("SA"),
25
+ pop: "GRU",
26
+ shield: "South America Shield",
27
+ },
28
+ {
29
+ condition: ({ region }) => region.startsWith("APAC"),
30
+ pop: "SYD",
31
+ shield: "APAC Shield",
32
+ },
33
+ {
34
+ condition: ({ pop }) => ["KUL", "QPG"].includes(pop),
35
+ pop: "QPG",
36
+ shield: "Singapore Shield",
37
+ },
38
+ {
39
+ condition: ({ pop }) => ["HKG", "ICN", "MNL"].includes(pop),
40
+ pop: "HKG",
41
+ shield: "Hongkong Shield",
42
+ },
43
+ {
44
+ condition: ({ region }) => region === "Asia-South",
45
+ pop: "DEL",
46
+ shield: "Asia South Shield",
47
+ },
48
+ {
49
+ condition: ({ region }) => region === "North-America",
50
+ pop: "YYZ",
51
+ shield: "North America Shield",
52
+ },
53
+ {
54
+ condition: ({ pop }) => ["DXB", "FJR"].includes(pop),
55
+ pop: "FJR",
56
+ shield: "United Arab Emirates Shield",
57
+ },
58
+ {
59
+ condition: ({ region }) => region === "South-Africa",
60
+ pop: "JNB",
61
+ shield: "South Africa Shield",
62
+ },
27
63
  ];
28
- const percentageFormatter = new Intl.NumberFormat('en-US', { minimumFractionDigits: 1, style: 'percent' });
64
+ const percentageFormatter = new Intl.NumberFormat("en-US", {
65
+ minimumFractionDigits: 1,
66
+ style: "percent",
67
+ });
29
68
  class GeneratePopConfig extends core_1.Command {
30
69
  static args = {
31
70
  [cli_parameters_1.CLIParameters.AppName]: core_1.Args.string({
32
- description: 'The customers appName',
71
+ description: "The customers appName",
33
72
  hidden: false,
34
73
  name: cli_parameters_1.CLIParameters.AppName,
35
74
  required: true, // make the arg required with `required: true`
36
75
  }),
37
76
  };
38
- static description = 'Generate a pop config for the given app';
77
+ static description = "Generate a pop config for the given app";
39
78
  static examples = [
40
79
  `$ sk generate-pop-config <${cli_parameters_1.CLIParameters.AppName}>`,
41
80
  `$ sk generate-pop-config --use-rum <${cli_parameters_1.CLIParameters.AppName}>`,
42
- '$ sk generate-pop-config --coverage 95 appName',
43
- '$ sk generate-pop-config --no-deploy appName',
44
- '$ sk generate-pop-config --deploy appName',
45
- '$ sk generate-pop-config --coverage 95 --pop-limit 6 --traffic-share 2 --deploy appName',
81
+ "$ sk generate-pop-config --coverage 95 appName",
82
+ "$ sk generate-pop-config --no-deploy appName",
83
+ "$ sk generate-pop-config --deploy appName",
84
+ "$ sk generate-pop-config --coverage 95 --pop-limit 6 --traffic-share 2 --deploy appName",
46
85
  ];
47
86
  static flags = {
48
- coverage: core_1.Flags.integer({ char: 'c', default: 95, description: 'The percentage of traffic which should be covered through prewarming.' }),
49
- deploy: core_1.Flags.boolean({ allowNo: true, char: 'd', description: 'Default it diffs with the deployed config and ask for deployment. If the flag is passed deployment will be skipped or forced.' }),
50
- 'pop-limit': core_1.Flags.integer({ char: 'p', default: 5, description: 'The maximal pop count which should prewarmed.' }),
51
- 'traffic-share': core_1.Flags.integer({ char: 't', default: 5, description: 'The minimum traffic share in percent a pop must have to be actually prewarmed.' }),
52
- 'use-rum': core_1.Flags.boolean({ char: 'r', default: false, description: 'Compute the pop statistics based on RUM. Otherwise the real Speed Kit traffic is used.' }),
87
+ coverage: core_1.Flags.integer({
88
+ char: "c",
89
+ default: 95,
90
+ description: "The percentage of traffic which should be covered through prewarming.",
91
+ }),
92
+ deploy: core_1.Flags.boolean({
93
+ allowNo: true,
94
+ char: "d",
95
+ description: "Default it diffs with the deployed config and ask for deployment. If the flag is passed deployment will be skipped or forced.",
96
+ }),
97
+ "pop-limit": core_1.Flags.integer({
98
+ char: "p",
99
+ default: 5,
100
+ description: "The maximal pop count which should prewarmed.",
101
+ }),
102
+ "traffic-share": core_1.Flags.integer({
103
+ char: "t",
104
+ default: 5,
105
+ description: "The minimum traffic share in percent a pop must have to be actually prewarmed.",
106
+ }),
107
+ "use-rum": core_1.Flags.boolean({
108
+ char: "r",
109
+ default: false,
110
+ description: "Compute the pop statistics based on RUM. Otherwise the real Speed Kit traffic is used.",
111
+ }),
53
112
  };
54
113
  async createPopPrewarmingCode(popConfig) {
55
- const revalidationTemplate = await (0, file_helper_1.readLocalFile)(__dirname, '../templates/speedKit.Revalidated.js');
56
- const pops = await (0, file_helper_1.readLocalFile)(__dirname, '../templates/pops.js');
114
+ const revalidationTemplate = await (0, file_helper_1.readLocalFile)(__dirname, "../templates/speedKit.Revalidated.js");
115
+ const pops = await (0, file_helper_1.readLocalFile)(__dirname, "../templates/pops.js");
57
116
  popConfig = pops + popConfig;
58
- return revalidationTemplate.replace('{{config}}', popConfig);
117
+ return revalidationTemplate.replace("{{config}}", popConfig);
59
118
  }
60
119
  async deployPrewarmingConfig(app, config, deploy) {
61
- const moduleName = 'speedKit.Revalidated';
120
+ const moduleName = "speedKit.Revalidated";
62
121
  const db = await cli_1.account.login({ app });
63
122
  const configService = new config_api_service_1.default(db, app);
64
123
  const cliService = new cli_2.CliServiceFactory().getService();
@@ -66,19 +125,21 @@ class GeneratePopConfig extends core_1.Command {
66
125
  const popPrewarmingCode = await this.createPopPrewarmingCode(config);
67
126
  const popPrewarmingCodePath = await diffService.writeContentToTemporalFile(`generated_${moduleName}`, popPrewarmingCode);
68
127
  const remoteConfig = await configService.getRemoteModule(moduleName);
69
- const doDeploy = deploy ?? await diffService.shouldDeployModule(moduleName, remoteConfig, popPrewarmingCodePath);
128
+ const doDeploy = deploy ??
129
+ (await diffService.shouldDeployModule(moduleName, remoteConfig, popPrewarmingCodePath));
70
130
  if (doDeploy) {
71
- const content = await (0, promises_1.readFile)(popPrewarmingCodePath, { encoding: 'utf8' });
131
+ const content = await (0, promises_1.readFile)(popPrewarmingCodePath, {
132
+ encoding: "utf8",
133
+ });
72
134
  await configService.saveRemoteModule(content, moduleName);
73
135
  this.log(`Changes for module ${moduleName} were updated successfully`);
74
136
  }
75
137
  }
76
138
  async run() {
77
- const { args: { app }, flags: { coverage, deploy, 'pop-limit': popLimit, 'traffic-share': minimalShare, 'use-rum': useRum } } = await this.parse(GeneratePopConfig);
139
+ const { args: { app }, flags: { coverage, deploy, "pop-limit": popLimit, "traffic-share": minimalShare, "use-rum": useRum, }, } = await this.parse(GeneratePopConfig);
78
140
  const athenaService = new athena_service_1.AthenaService();
79
141
  const result = await athenaService.getUsedPopsPerOrigin(app, useRum);
80
- const originStats = this.generateOriginStats(result)
81
- .filter(stats => stats.hits > 1000);
142
+ const originStats = this.generateOriginStats(result).filter((stats) => stats.hits > 1000);
82
143
  this.printStats(originStats, coverage / 100, minimalShare / 100, popLimit);
83
144
  const popConfig = this.generatePopConfig(originStats, coverage / 100, minimalShare / 100, popLimit);
84
145
  await this.deployPrewarmingConfig(app, popConfig, deploy);
@@ -89,9 +150,13 @@ class GeneratePopConfig extends core_1.Command {
89
150
  computeCoverageAndShare(totalHits, segmentedStats) {
90
151
  segmentedStats = segmentedStats.sort(this.byHitsDesc);
91
152
  let segmentHits = 0;
92
- return segmentedStats.map(segment => {
153
+ return segmentedStats.map((segment) => {
93
154
  segmentHits += segment.hits;
94
- return { ...segment, coverage: segmentHits / totalHits, share: segment.hits / totalHits };
155
+ return {
156
+ ...segment,
157
+ coverage: segmentHits / totalHits,
158
+ share: segment.hits / totalHits,
159
+ };
95
160
  });
96
161
  }
97
162
  generateOriginStats(result) {
@@ -99,38 +164,51 @@ class GeneratePopConfig extends core_1.Command {
99
164
  for (let { hits, origin, pop, region } of result) {
100
165
  pop = POP_REMAPPING[pop] ?? pop;
101
166
  const shieldInfo = this.getShieldInfo(region, pop);
102
- const stats = originStats[origin] = originStats[origin] ?? {
167
+ // eslint-disable-next-line no-multi-assign
168
+ const stats = (originStats[origin] = originStats[origin] ?? {
103
169
  hits: 0,
104
170
  origin,
105
171
  pops: {},
106
172
  regions: {},
107
173
  shields: {},
108
- };
174
+ });
109
175
  stats.hits += hits;
110
- const regionStats = stats.regions[region] = stats.regions[region] ?? { hits: 0, region };
176
+ // eslint-disable-next-line no-multi-assign
177
+ const regionStats = (stats.regions[region] = stats.regions[region] ?? {
178
+ hits: 0,
179
+ region,
180
+ });
111
181
  regionStats.hits += hits;
112
- const shieldStats = stats.shields[shieldInfo.shield] = stats.shields[shieldInfo.shield] ?? { ...shieldInfo, hits: 0 };
182
+ // eslint-disable-next-line no-multi-assign
183
+ const shieldStats = (stats.shields[shieldInfo.shield] = stats.shields[shieldInfo.shield] ?? { ...shieldInfo, hits: 0 });
113
184
  shieldStats.hits += hits;
114
- const popStats = stats.pops[pop] = stats.pops[pop] ?? { hits: 0, pop, region, shield: shieldInfo.pop };
185
+ // eslint-disable-next-line no-multi-assign
186
+ const popStats = (stats.pops[pop] = stats.pops[pop] ?? {
187
+ hits: 0,
188
+ pop,
189
+ region,
190
+ shield: shieldInfo.pop,
191
+ });
115
192
  popStats.hits += hits;
116
193
  }
117
- return Object.values(originStats).map(stats => ({
194
+ return Object.values(originStats)
195
+ .map((stats) => ({
118
196
  hits: stats.hits,
119
197
  origin: stats.origin,
120
198
  pops: this.computeCoverageAndShare(stats.hits, Object.values(stats.pops)),
121
199
  regions: this.computeCoverageAndShare(stats.hits, Object.values(stats.regions)),
122
200
  shields: this.computeCoverageAndShare(stats.hits, Object.values(stats.shields)),
123
- })).sort(this.byHitsDesc);
201
+ }))
202
+ .sort(this.byHitsDesc);
124
203
  }
125
204
  generatePopConfig(originStats, coverage, minimalShare, popLimit) {
126
205
  const originConfigs = { DEFAULT: [] };
127
206
  for (const originStat of originStats) {
128
- originConfigs[originStat.origin] = this.generatePrewarmingConfig(originStat, coverage, minimalShare, popLimit).pops
129
- .map(pop => 'POP.' + pop);
207
+ originConfigs[originStat.origin] = this.generatePrewarmingConfig(originStat, coverage, minimalShare, popLimit).pops.map((pop) => "POP." + pop);
130
208
  }
131
- const serializedConfig = JSON.stringify(originConfigs, null, ' ')
132
- .replaceAll(/"(POP.*?)"/g, '$1')
133
- .replaceAll(/\[(.*?)]/gs, match => match.replaceAll(/\s+/gs, ' '));
209
+ const serializedConfig = JSON.stringify(originConfigs, null, " ")
210
+ .replaceAll(/"(POP.*?)"/g, "$1")
211
+ .replaceAll(/\[(.*?)]/gs, (match) => match.replaceAll(/\s+/gs, " "));
134
212
  return `/* global POP */
135
213
  /** @type PopConfig */
136
214
  const ORIGIN_POPS = ${serializedConfig}`;
@@ -152,12 +230,17 @@ const ORIGIN_POPS = ${serializedConfig}`;
152
230
  let shieldCoverage = 0;
153
231
  for (const shieldStats of originStat.shields) {
154
232
  // if we are pre warming the shield through an edge pop we increase the edge coverage of the edge and the shield pop
155
- const shieldPop = originStat.pops.find(pop => pop.pop === shieldStats.pop);
233
+ const shieldPop = originStat.pops.find((pop) => pop.pop === shieldStats.pop);
156
234
  edgeCoverage += shieldPop?.share ?? 0; // in the case the shield pop does not receive any direct traffic
157
235
  shieldCoverage += shieldStats.share;
158
236
  let { pop } = shieldStats;
159
237
  // We try to use the top edge pop of the shield, if that pop still has enough traffic
160
- const bestEdgePopOfShield = originStat.pops.find(popStats => popStats.shield == pop && popStats.pop != pop && popStats.share > minimalShare);
238
+ const bestEdgePopOfShield = originStat.pops.find((popStats) =>
239
+ // eslint-disable-next-line eqeqeq
240
+ popStats.shield == pop &&
241
+ // eslint-disable-next-line eqeqeq
242
+ popStats.pop != pop &&
243
+ popStats.share > minimalShare);
161
244
  if (bestEdgePopOfShield) {
162
245
  edgeCoverage += bestEdgePopOfShield.share;
163
246
  pop = bestEdgePopOfShield.pop;
@@ -167,8 +250,11 @@ const ORIGIN_POPS = ${serializedConfig}`;
167
250
  break;
168
251
  }
169
252
  for (const pop of originStat.pops) {
170
- if (pops.length < popLimit // when the shield pre warming list is short, we can add additional big traffic pops
171
- && pop.share > minimalShare && !pops.includes(pop.pop) && pop.shield != pop.pop) {
253
+ if (pops.length < popLimit && // when the shield pre warming list is short, we can add additional big traffic pops
254
+ pop.share > minimalShare &&
255
+ !pops.includes(pop.pop) &&
256
+ // eslint-disable-next-line eqeqeq
257
+ pop.shield != pop.pop) {
172
258
  pops.push(pop.pop);
173
259
  edgeCoverage += pop.share;
174
260
  }
@@ -196,35 +282,39 @@ const ORIGIN_POPS = ${serializedConfig}`;
196
282
  let shieldingRequired = false;
197
283
  for (const originStat of originStats) {
198
284
  this.log(`${originStat.origin} ${originStat.hits}`);
199
- this.log(' Regions:');
285
+ this.log(" Regions:");
200
286
  for (const regionStats of originStat.regions) {
201
287
  this.log(` ${regionStats.region} ${regionStats.hits} ${percentageFormatter.format(regionStats.coverage)}`);
202
- if (regionStats.coverage >= coverage || regionStats.share < minimalShare)
288
+ if (regionStats.coverage >= coverage ||
289
+ regionStats.share < minimalShare)
203
290
  break;
204
291
  }
205
- this.log(' Shields:');
292
+ this.log(" Shields:");
206
293
  for (const shieldStats of originStat.shields) {
207
294
  this.log(` ${shieldStats.shield} (${shieldStats.pop}) ${shieldStats.hits} ${percentageFormatter.format(shieldStats.coverage)}`);
208
- if (shieldStats.coverage >= coverage || shieldStats.share < minimalShare)
295
+ if (shieldStats.coverage >= coverage ||
296
+ shieldStats.share < minimalShare)
209
297
  break;
210
298
  }
211
- this.log(' Pops:');
299
+ this.log(" Pops:");
212
300
  for (const popStats of originStat.pops) {
213
301
  this.log(` ${popStats.pop} ${popStats.hits} ${percentageFormatter.format(popStats.coverage)} - shield: ${popStats.shield}`);
214
302
  if (popStats.coverage >= coverage || popStats.share < minimalShare)
215
303
  break;
216
304
  }
217
305
  const config = this.generatePrewarmingConfig(originStat, coverage, minimalShare, popLimit);
218
- this.log(' --------------------');
306
+ this.log(" --------------------");
219
307
  if (config.requiresShielding)
220
- this.log(' Final shield coverage: ' + percentageFormatter.format(config.shieldCoverage));
221
- this.log(' Final edge coverage: ' + percentageFormatter.format(config.edgeCoverage));
222
- this.log(' Final pop list: ' + config.pops.join(', '));
223
- this.log('');
308
+ this.log(" Final shield coverage: " +
309
+ percentageFormatter.format(config.shieldCoverage));
310
+ this.log(" Final edge coverage: " +
311
+ percentageFormatter.format(config.edgeCoverage));
312
+ this.log(" Final pop list: " + config.pops.join(", "));
313
+ this.log("");
224
314
  shieldingRequired ||= config.requiresShielding;
225
315
  }
226
316
  if (shieldingRequired) {
227
- this.warn('The prewarming configuration needs enabled shielding to work properly!');
317
+ this.warn("The prewarming configuration needs enabled shielding to work properly!");
228
318
  }
229
319
  }
230
320
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Require the assert module from Chai
4
+ const { expect } = require('chai');
5
+ // Dummy function to test
6
+ function add(a, b) {
7
+ return a + b;
8
+ }
9
+ // Describe your test suite
10
+ describe('(dummy) add function test', () => {
11
+ // It block describes a single test
12
+ it('should add two numbers', () => {
13
+ // Call our function with some test inputs
14
+ const result = add(2, 3);
15
+ // Assert that our function returned the correct value
16
+ expect(result).to.equal(5);
17
+ });
18
+ // Add more tests here
19
+ });
@@ -696,5 +696,5 @@
696
696
  ]
697
697
  }
698
698
  },
699
- "version": "2.8.0"
699
+ "version": "2.9.0"
700
700
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@speedkit/cli",
3
3
  "description": "Speed Kit CLI",
4
- "version": "2.8.0",
4
+ "version": "2.9.0",
5
5
  "author": {
6
6
  "name": "Baqend.com",
7
7
  "email": "info@baqend.com"
@@ -15,16 +15,14 @@
15
15
  },
16
16
  "scripts": {
17
17
  "prepare": "husky install",
18
- "lint": "eslint --ext .ts,.vue --ignore-path .gitignore src",
19
- "lint-fix": "eslint --fix --ext .ts,.vue --ignore-path .gitignore src",
20
18
  "prebuild": "shx rm -rf dist",
21
- "build": "tsc -b && copyfiles -u 1 src/**/*hbs ./dist && copyfiles -u 1 src/**/*js ./dist && npm run build-dashboard",
22
- "build-dashboard": "copyfiles -u 1 src/services/onboarding/dashboard/frontend-dist/**/*.html dist && copyfiles -u 1 src/services/onboarding/dashboard/frontend-dist/**/*.js dist && copyfiles -u 1 src/services/onboarding/dashboard/frontend-dist/**/*.css dist",
19
+ "build": "tsc -b && copyfiles -u 1 src/**/*hbs ./dist && copyfiles -u 1 src/**/*js ./dist && npm run build:dashboard",
20
+ "build:dashboard": "copyfiles -u 1 src/services/onboarding/dashboard/frontend-dist/**/*.html dist && copyfiles -u 1 src/services/onboarding/dashboard/frontend-dist/**/*.js dist && copyfiles -u 1 src/services/onboarding/dashboard/frontend-dist/**/*.css dist",
23
21
  "postbuild": "oclif manifest && oclif readme",
24
22
  "prepack": "npm run build",
25
- "postpack": "rimraf rm -f oclif.manifest.json",
26
- "test": "mocha \"test/**/*.test.ts\"",
27
- "coverage": "nyc --extension .ts mocha \"test/**/*.test.ts\""
23
+ "test": "mocha --reporter mocha-junit-reporter --reporter-options mochaFile=junit.xml",
24
+ "coverage": "nyc mocha",
25
+ "coverage:report": "nyc --reporter cobertura mocha"
28
26
  },
29
27
  "bin": {
30
28
  "sk": "bin/run",
@@ -37,10 +35,9 @@
37
35
  "oclif"
38
36
  ],
39
37
  "files": [
40
- "/bin",
41
- "/dist",
42
- "/npm-shrinkwrap.json",
43
- "/oclif.manifest.json"
38
+ "dist",
39
+ "oclif.manifest.json",
40
+ "CHANGELOG.md"
44
41
  ],
45
42
  "oclif": {
46
43
  "commands": "./dist/commands",
@@ -100,6 +97,7 @@
100
97
  "devDependencies": {
101
98
  "@commitlint/cli": "^17.7.1",
102
99
  "@commitlint/config-conventional": "^17.7.0",
100
+ "@istanbuljs/nyc-config-typescript": "^1.0.2",
103
101
  "@oclif/prettier-config": "^0.2.1",
104
102
  "@oclif/test": "^3",
105
103
  "@types/chai": "^4.3.10",
@@ -115,9 +113,12 @@
115
113
  "eslint-config-oclif": "^5.0.0",
116
114
  "eslint-config-oclif-typescript": "^3.0.13",
117
115
  "eslint-config-prettier": "^9.0.0",
116
+ "eslint-plugin-prettier": "^5.0.0",
118
117
  "globby": "^11",
119
118
  "husky": "^8.0.3",
119
+ "lint-staged": "^14.0.1",
120
120
  "mocha": "^10.1.0",
121
+ "mocha-junit-reporter": "^2.2.1",
121
122
  "mock-fs": "^5.2.0",
122
123
  "nyc": "^15.1.0",
123
124
  "oclif": "^4.0.3",
@@ -127,5 +128,10 @@
127
128
  "tslib": "^2.4.0",
128
129
  "typescript": "^5.2.2",
129
130
  "typescript-json-serializer": "^4.3.0"
131
+ },
132
+ "lint-staged": {
133
+ "*.ts": [
134
+ "eslint --fix"
135
+ ]
130
136
  }
131
137
  }
package/bin/dev.cmd DELETED
@@ -1,3 +0,0 @@
1
- @echo off
2
-
3
- node "%~dp0\dev" %*
package/bin/run.cmd DELETED
@@ -1,3 +0,0 @@
1
- @echo off
2
-
3
- node "%~dp0\run" %*