gtx-cli 2.6.9 → 2.6.10

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.6.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [#986](https://github.com/generaltranslation/gt/pull/986) [`b943ac2`](https://github.com/generaltranslation/gt/commit/b943ac200d8ec41219b3c09a669f94590fec0f65) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - chore: include branchid in gt config
8
+
3
9
  ## 2.6.9
4
10
 
5
11
  ### Patch Changes
package/dist/cli/base.js CHANGED
@@ -105,8 +105,7 @@ export class BaseCLI {
105
105
  if (!settings.stageTranslations) {
106
106
  // Update settings.stageTranslations to true
107
107
  settings.stageTranslations = true;
108
- await updateConfig({
109
- configFilepath: settings.config,
108
+ await updateConfig(settings.config, {
110
109
  stageTranslations: true,
111
110
  });
112
111
  }
@@ -56,12 +56,19 @@ export async function handleStage(options, settings, library, stage) {
56
56
  }
57
57
  const templateData = allFiles.find((file) => file.fileId === TEMPLATE_FILE_ID);
58
58
  if (templateData?.versionId) {
59
- await updateConfig({
60
- configFilepath: settings.config,
59
+ await updateConfig(settings.config, {
61
60
  _versionId: templateData.versionId,
61
+ _branchId: branchData.currentBranch.id,
62
62
  });
63
63
  }
64
64
  }
65
+ // Always delete branch id from config if branching is disabled
66
+ // Avoids incorrect CDN queries at runtime
67
+ if (!settings.branchOptions.enabled) {
68
+ await updateConfig(settings.config, {
69
+ _branchId: null,
70
+ });
71
+ }
65
72
  return {
66
73
  fileVersionData,
67
74
  jobData,
@@ -1,10 +1,21 @@
1
+ /**
2
+ * Options for updating the config file.
3
+ *
4
+ * Since these are all string values, we can use null to mark them for removal
5
+ */
6
+ type UpdateConfigOptions = {
7
+ projectId?: string | null;
8
+ _versionId?: string | null;
9
+ _branchId?: string | null;
10
+ stageTranslations?: boolean | null;
11
+ };
1
12
  /**
2
13
  * Update the config file version id, locales, and projectId (if necessary)
3
- * @param {Record<string, any>} configObject - The config object to write if the file does not exist.
14
+ * @param {string} configFilepath - The path to the config file.
15
+ * @param {UpdateConfigOptions} options - The options to update the config file with.
16
+ * @returns {Promise<void>} - A promise that resolves when the config file is updated.
17
+ *
18
+ * Hint: Mark a field as null to remove it from the config file.
4
19
  */
5
- export default function updateConfig({ configFilepath, projectId, _versionId, stageTranslations, }: {
6
- configFilepath: string;
7
- projectId?: string;
8
- _versionId?: string;
9
- stageTranslations?: boolean;
10
- }): Promise<void>;
20
+ export default function updateConfig(configFilepath: string, options: UpdateConfigOptions): Promise<void>;
21
+ export {};
@@ -3,15 +3,21 @@ import { displayUpdatedConfigFile } from '../../console/logging.js';
3
3
  import { logger } from '../../console/logger.js';
4
4
  /**
5
5
  * Update the config file version id, locales, and projectId (if necessary)
6
- * @param {Record<string, any>} configObject - The config object to write if the file does not exist.
6
+ * @param {string} configFilepath - The path to the config file.
7
+ * @param {UpdateConfigOptions} options - The options to update the config file with.
8
+ * @returns {Promise<void>} - A promise that resolves when the config file is updated.
9
+ *
10
+ * Hint: Mark a field as null to remove it from the config file.
7
11
  */
8
- export default async function updateConfig({ configFilepath, projectId, _versionId, stageTranslations, }) {
12
+ export default async function updateConfig(configFilepath, options) {
9
13
  // Filter out empty string values from the config object
14
+ const { projectId, _versionId, _branchId, stageTranslations } = options;
10
15
  const newContent = {
11
16
  ...(projectId && { projectId }),
12
17
  ...(_versionId && { _versionId }),
18
+ ...(_branchId && { _branchId }),
19
+ // Omit when false
13
20
  ...(stageTranslations && { stageTranslations }),
14
- // ...(locales && { locales }), // Don't override locales
15
21
  };
16
22
  try {
17
23
  // if file exists
@@ -24,9 +30,11 @@ export default async function updateConfig({ configFilepath, projectId, _version
24
30
  ...oldContent,
25
31
  ...newContent,
26
32
  };
33
+ // Apply null filter to remove values that were marked for removal
34
+ const filteredContent = applyNullFilter(mergedContent, options);
27
35
  // write to file
28
- const mergedJsonContent = JSON.stringify(mergedContent, null, 2);
29
- await fs.promises.writeFile(configFilepath, mergedJsonContent, 'utf-8');
36
+ const jsonContent = JSON.stringify(filteredContent, null, 2);
37
+ await fs.promises.writeFile(configFilepath, jsonContent, 'utf-8');
30
38
  // show update in console
31
39
  displayUpdatedConfigFile(configFilepath);
32
40
  }
@@ -34,3 +42,16 @@ export default async function updateConfig({ configFilepath, projectId, _version
34
42
  logger.error(`An error occurred while updating ${configFilepath}: ${error}`);
35
43
  }
36
44
  }
45
+ // --- Helper functions --- //
46
+ /**
47
+ * Remove values from object if they were marked for removal
48
+ */
49
+ function applyNullFilter(obj, filter) {
50
+ const result = { ...obj };
51
+ for (const key of Object.keys(filter)) {
52
+ if (filter[key] === null) {
53
+ delete result[key];
54
+ }
55
+ }
56
+ return result;
57
+ }
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "2.6.9";
1
+ export declare const PACKAGE_VERSION = "2.6.10";
@@ -1,2 +1,2 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
- export const PACKAGE_VERSION = '2.6.9';
2
+ export const PACKAGE_VERSION = '2.6.10';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.6.9",
3
+ "version": "2.6.10",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [