@tangelo/tangelo-configuration-toolkit 1.24.1 → 1.24.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangelo/tangelo-configuration-toolkit",
3
- "version": "1.24.1",
3
+ "version": "1.24.3",
4
4
  "engines": {
5
5
  "node": ">=14.0.0"
6
6
  },
package/src/cli.js CHANGED
@@ -77,7 +77,10 @@ module.exports = function cli () {
77
77
  reset: {alias: 'r', desc: 'Reset repository to last commit', conflicts: ['i', 'c', 'u']},
78
78
  clone: {alias: 'c', desc: 'Clone a client repository and do basic setup', conflicts: ['i', 'r', 'u']},
79
79
  'update-repo': {alias: 'ur', desc: 'Update repository', conflicts: ['i', 'r', 'c']},
80
- 'update-submodule': {alias: 'us', desc: 'Update TDI submodule, optionally pass release branch (without "release/")', conflicts: ['i', 'r', 'c']},
80
+ 'update-submodule': {alias: 'us', desc: 'Update TDI submodule, optionally pass release branch (without "release/")', conflicts: ['i', 'r', 'c'], type:"string",
81
+ // Running --us with no argument should default to true - defaulting to empty string throws a yargs error
82
+ coerce: (v => v || true)
83
+ },
81
84
  dates: {alias: 'd', desc: '[hidden] Use i.c.w. update-submodule, pass 2 dates in format yyyy-mm-dd', conflicts: ['i', 'r', 'c'], implies: 'update-submodule', requiresArg: true, array: true, hidden: !_devmode}
82
85
  },
83
86
  handler: require('./modules/git')
@@ -1,9 +1,9 @@
1
1
  const execGitCommand = require('./exec-git-command');
2
2
  const path = require('path');
3
+ const compareVersions = require('compare-versions');
3
4
 
4
5
  module.exports = function getTdiBranch(toBranchName) {
5
6
  const tdiPath = path.join(_paths.repo, _paths.tdi);
6
- const tdiBranch = {};
7
7
 
8
8
  // Fetch all
9
9
  _info(`Fetch TDI submodule`);
@@ -22,17 +22,26 @@ module.exports = function getTdiBranch(toBranchName) {
22
22
  const releaseBranches = execGitCommand(`branch --all --contains ${_git.commitTdi.local().hash}`, tdiPath).match(/remotes\/origin\/release\/[^\s]+/gsm);
23
23
  if (!releaseBranches || releaseBranches.error) _error(`Could not retrieve TDI release branches`);
24
24
 
25
- // Get the first possible branch; prefer release/5.1 over release/5.2:
26
- releaseBranches.sort((a, b) => a > b ? 1 : -1);
25
+ // Create a sorted list of release branches with their versions:
26
+ const sortedBranches = releaseBranches
27
+ .map(branch => {
28
+ return {
29
+ name: branch.replace('remotes/origin/', ''),
30
+ version: branch.replace('remotes/origin/release/', '')
31
+ }
32
+ })
33
+ .sort((a, b) => compareVersions(a.version, b.version));
27
34
 
28
- // Set branch name of firstBranch without 'remotes/origin/'
29
- tdiBranch.name = releaseBranches[0].replace(/remotes\/origin\//g, '');
35
+ // Choose the first possible branch; prefer release/5.1 over release/5.2:
36
+ const tdiBranch = sortedBranches[0];
30
37
 
31
38
  // In case of branch switch set from.name to the old branch and name to the new branch
32
39
  if (toBranch) {
33
- if (tdiBranch.name > toBranch) _error(`You cannot downgrade to a lower release branch with TCT.`);
34
- tdiBranch.from = {name: tdiBranch.name};
40
+ const toVersion = toBranch?.replace('release/', '');
41
+ if (compareVersions.compare(tdiBranch.version, toVersion, '>')) _error(`You cannot downgrade to a lower release branch with TCT.`);
42
+ tdiBranch.from = {name: tdiBranch.name, version: tdiBranch.version};
35
43
  tdiBranch.name = toBranch;
44
+ tdiBranch.version = toVersion;
36
45
 
37
46
  const branchHash = execGitCommand(`rev-parse origin/${toBranch}`, tdiPath);
38
47
  const commonAncestorHash = execGitCommand(`merge-base ${_git.commitTdi.local().hash} ${branchHash}`, tdiPath);
@@ -164,7 +164,11 @@ async function combineTranslations(file, enc, cb) {
164
164
  const language = file.basename.match(/custom-UI-text(_.+?)?\.properties/)[1] ?? '';
165
165
 
166
166
  // Read matching tdi translation file
167
- const tdiTranslationPath = `cmscustom/tdi/custom-UI-text/custom-UI-text${language}.properties`;
167
+ const tdiTranslationPath = path.join(
168
+ // Current working directory can be either repo root for delivery pack or config folder otherwise, so adjust path accordingly
169
+ file.cwd.split(path.sep).pop() == 'config' ? '' : 'config',
170
+ `cmscustom/tdi/custom-UI-text/custom-UI-text${language}.properties`
171
+ );
168
172
  let tdiTranslations;
169
173
  try {
170
174
  tdiTranslations = await fs.readFile(tdiTranslationPath, enc);
@@ -172,14 +172,14 @@ function updateRepo () {
172
172
  */
173
173
  function updateSubmodule({dates = [], updateSubmodule: releaseBranchName}) {
174
174
  const [dateCustomFrom, dateCustomTo] = dates;
175
- const toBranchName = typeof releaseBranchName !== 'boolean' ? releaseBranchName : null;
175
+ const targetVersion = typeof releaseBranchName !== 'boolean' ? releaseBranchName : null;
176
176
 
177
177
  if (dateCustomFrom) _warn(`While testing the "TDI commits requiring migration" note that the submodule is not changed.`);
178
- if (dateCustomFrom && !toBranchName) _error(`Specify a release branch for testing the migration, e.g. "--us 5.6".`);
178
+ if (dateCustomFrom && !targetVersion) _error(`Specify a release branch for testing the migration, e.g. "--us 5.6".`);
179
179
 
180
180
  // For testing the migrations (dates argument is specified); submodule pull, fetch, updates fail or result in switching to the release-branch; while we want to test the migration in the current submodule branch / symlink to TDI-project. Therefore all submodule actions should not be applied when the dates argument is specified. As the release of the current submodule cannot be determined you also need to specify the toBranchName so you can test the migrations you want.
181
- const branch = !dateCustomFrom ? getTdiBranch(toBranchName) : {'name': `release/${toBranchName}`};
182
- const branchUpgrade = branch.from ? branch.from.name < branch.name : false;
181
+ const branch = !dateCustomFrom ? getTdiBranch(targetVersion) : {'name': `release/${targetVersion}`, 'version': targetVersion};
182
+ const branchUpgrade = branch.from ? compare(branch.from.version, branch.version, '<') : false;
183
183
 
184
184
  if (branchUpgrade) _info(`Current branch '${branch.from.name}' will be updated to '${branch.name}'\nCommon ancestor will be used in selecting TDI commits requiring migration: ${_formatDate(branch.commonAncestor.date)}`);
185
185
  _info(`Branch ${branch.name} is ${branch.commitsBehind} commits behind.\n`);
@@ -203,8 +203,6 @@ function updateSubmodule({dates = [], updateSubmodule: releaseBranchName}) {
203
203
  const migrations = _modulesTdi.require('git/tdiCommitsRequiringMigration.js');
204
204
  const fromDate = dateCustomFrom ? new Date(dateCustomFrom) : branch.commonAncestor?.date ?? dateBeforeUpdate;
205
205
  const toDate = dateCustomTo ? new Date(dateCustomTo) : new Date();
206
- const fromVersion = branch.from?.name?.replace('release/', '');
207
- const toVersion = branch.name.replace('release/', '');
208
206
 
209
207
  _info(`TDI commits requiring migration between ${_formatDate(fromDate)} and ${_formatDate(toDate)}`);
210
208
  // Filter the migrations that should be applied/considered; Also display older releases migrations
@@ -214,11 +212,11 @@ function updateSubmodule({dates = [], updateSubmodule: releaseBranchName}) {
214
212
 
215
213
  if (branchUpgrade) {
216
214
  // For branch upgrades, include all migrations for versions newer than the current one, and include new migrations for the current version
217
- const isTargetBranch = compare(r.release, toVersion, '<=') && compare(r.release, fromVersion, '>');
218
- return isTargetBranch || (r.release === fromVersion && withinDateRange);
215
+ const isTargetBranch = compare(r.release, branch.version, '<=') && compare(r.release, branch.from.version, '>');
216
+ return isTargetBranch || (r.release === branch.from.version && withinDateRange);
219
217
  } else {
220
218
  // For non-branch upgrades, only include new migrations for the current branch
221
- return r.release === toVersion && withinDateRange;
219
+ return r.release === branch.version && withinDateRange;
222
220
  }
223
221
  }));
224
222
 
@@ -227,7 +225,7 @@ function updateSubmodule({dates = [], updateSubmodule: releaseBranchName}) {
227
225
  migrationsFiltered
228
226
  .sort((a, b) => Date(a.releases[0].date) > Date(b.releases[0].date) ? 1 : -1)
229
227
  .forEach(m => {
230
- const date = _formatDate(new Date(m.releases.filter(r => branch.name >= `release/${r.release}`)[0].date));
228
+ const date = _formatDate(new Date(m.releases.filter(r => compare(branch.version, r.release, '>='))[0].date));
231
229
  relevantMigrationCount += m.callback(date, relevantMigrationCount+1) === 1 ? 1 : 0;
232
230
  });
233
231