@tangelo/tangelo-configuration-toolkit 1.14.4 → 1.15.1

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/index.js CHANGED
@@ -124,9 +124,34 @@ else {
124
124
  }
125
125
 
126
126
 
127
- global._tdiSubmoduleExists = fs.existsSync(path.join(_paths.repo, _paths.tdi));
128
- global._isPre42 = fs.existsSync(path.join(_paths.repo, _paths.tdi, 'create_new_project')); // folder changed in 4.2
129
- global._isPre51 = !fs.existsSync(path.join(_paths.repo, _paths.tdi, 'src')); // folder changed in 5.1 (check new folder because old one could still exist after branch switch)
127
+ global._tdiSubmoduleExists = () => fs.existsSync(path.join(_paths.repo, _paths.tdi));
128
+ global._isPre42 = () => fs.existsSync(path.join(_paths.repo, _paths.tdi, 'create_new_project')); // folder changed in 4.2
129
+ global._isPre51 = () => !fs.existsSync(path.join(_paths.repo, _paths.tdi, 'src')); // folder changed in 5.1 (check new folder because old one could still exist after branch switch)
130
+
131
+ global._modulesTdi = {
132
+ absolutePathTdi: path.join(_paths.repo, _paths.tdi),
133
+ ensureDepsUpToDate() {
134
+ if (this.depsUpToDate) return;
135
+ try {
136
+ _info('Checking installed dependencies in submodule');
137
+ execSync('npm list', {cwd: this.absolutePathTdi, stdio: 'ignore'});
138
+ } catch (e) {
139
+ _info('Updating dependencies in submodule');
140
+ execSync('npm update', {cwd: this.absolutePathTdi, stdio: 'ignore'});
141
+ }
142
+ this.depsUpToDate = true;
143
+ },
144
+ require(module) {
145
+ this.ensureDepsUpToDate();
146
+ _info(`Loading ${path.join(_paths.tdi, 'tct', module)}\n`);
147
+ try {
148
+ return require(path.join(this.absolutePathTdi, 'tct', module));
149
+ }
150
+ catch (e) {
151
+ _error('Module could not be loaded');
152
+ }
153
+ }
154
+ };
130
155
 
131
156
 
132
157
  process.on('beforeExit', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangelo/tangelo-configuration-toolkit",
3
- "version": "1.14.4",
3
+ "version": "1.15.1",
4
4
  "engines": {
5
5
  "node": ">=14.0.0"
6
6
  },
package/src/cli.js CHANGED
@@ -119,10 +119,9 @@ module.exports = function cli () {
119
119
  ['$0 git --update tdi --branch 5.4', 'Update TDI submodule to latest in specified branch']
120
120
  ])
121
121
  .check((argv, options) => {
122
- const passedOpts = Object.keys(argv).filter(k => !['_', '$0', 'server', 's', 'filter', 'f', 'branch', 'b'].includes(k)); // also filter options with defaults
123
- const hasOpts = Object.keys(options)[0];
124
- if (hasOpts && !passedOpts[0]) yargs.showHelp();
125
- return true;
122
+ const nonDefaultOptions = Object.keys(options.key).filter(o => !Object.keys(options.default).includes(o));
123
+ if (nonDefaultOptions.some(o => argv[o])) return true;
124
+ else throw new Error("Pass a non-default option");
126
125
  })
127
126
  .strict()
128
127
  .wrap(100)
@@ -17,7 +17,7 @@ const createSymlink = (t, p) => {
17
17
 
18
18
  const createSymlinks = () => {
19
19
  _info('Creating symlinks:');
20
- const src = _isPre51 ? 'sources' : 'src';
20
+ const src = _isPre51() ? 'sources' : 'src';
21
21
  createSymlink(src + '/config/cmscustom/tdi', 'config/cmscustom/tdi');
22
22
  globby
23
23
  .sync('config/cmscustom/!(tdi)/**/fonto')
@@ -30,15 +30,15 @@ const createSymlinks = () => {
30
30
  module.exports = function build (argv) {
31
31
 
32
32
  if (argv.init) {
33
- if (_isPre51) _error('This option only works when using branch release/5.1 and up.');
33
+ if (_isPre51()) _error('This option only works when using branch release/5.1 and up.');
34
34
 
35
- require(path.join(_paths.repo, _paths.tdi, 'tct/build/init'))(createSymlinks);
35
+ _modulesTdi.require('build/init')(createSymlinks);
36
36
  }
37
37
 
38
38
  if (argv.project) {
39
- if (_isPre51) _error('This option only works when using branch release/5.1 and up.');
39
+ if (_isPre51()) _error('This option only works when using branch release/5.1 and up.');
40
40
 
41
- const {projectNew, projectCopy} = require(path.join(_paths.repo, _paths.tdi, 'tct/build/project'));
41
+ const {projectNew, projectCopy} = _modulesTdi.require('build/project');
42
42
 
43
43
  inquirer
44
44
  .prompt([{
@@ -3,14 +3,16 @@ const globby = require('globby');
3
3
  const path = require('path');
4
4
  const SaxonJS = require('saxon-js');
5
5
 
6
- const spConfigPath = path.join(_paths.repo, _paths.tdi, 'tct/build/oxygen/stylesheetPaths.json');
7
- const sefFilePath = path.join(_paths.repo, _paths.tdi, 'tct/build/oxygen/createProjectFile.sef.json');
6
+ const spConfigPath = 'build/oxygen/stylesheetPaths.json';
7
+ const sefFilePath = 'build/oxygen/createProjectFile.sef.json';
8
8
  const cmscustomPath = 'config/cmscustom/';
9
9
  const siteStylesheetsPath = 'config/txp/site-stylesheets/';
10
10
 
11
11
  const masterFiles = new Set;
12
12
  const transformationScenarios = [];
13
13
 
14
+ let spConfig, sefFile;
15
+
14
16
  const convertToValidFilename = string => string.replace(/[/|\\:*?"<>]/g, ' ');
15
17
 
16
18
  const createProjectFile = (config, newXprFile) => {
@@ -143,7 +145,7 @@ const transformXprFile = xprFiles => {
143
145
  // Transform xpr; add masterfiles and transformationScenarios as parameters of the stylesheet
144
146
  _write(`${xprFile}\n`);
145
147
  SaxonJS.transform({
146
- stylesheetText: fs.readFileSync(sefFilePath),
148
+ stylesheetText: JSON.stringify(sefFile),
147
149
  stylesheetBaseURI: 'createProjectFile.sef.json',
148
150
  sourceFileName: path.join(_paths.repo, xprFile),
149
151
  destination: 'serialized',
@@ -166,10 +168,11 @@ module.exports = function oxygen (arg) {
166
168
  // - Will try to preserve manually added entries in the transformation scenarios and masterfiles
167
169
  // - Will remove non existing masterfiles or masterfiles that start with a '_'
168
170
 
169
- if (!fs.existsSync(spConfigPath) || !fs.existsSync(sefFilePath)) {
170
- _error(`Cannot find required files in TDI submodule. Try updating TDI submodule.`);
171
- }
171
+ spConfig = _modulesTdi.require(spConfigPath);
172
+ sefFile = _modulesTdi.require(sefFilePath);
173
+
174
+ if (!spConfig || !sefFile) _error(`Cannot find required files in TDI submodule. Try updating TDI submodule.`);
172
175
 
173
176
  const newXprFile = (typeof arg === 'string') ? convertToValidFilename(arg) + '.xpr' : null;
174
- createProjectFile(require(spConfigPath), newXprFile);
177
+ createProjectFile(spConfig, newXprFile);
175
178
  };
@@ -5,13 +5,13 @@ const globby = require('globby');
5
5
  const path = require('path');
6
6
 
7
7
 
8
- const fdtCommand = (fv) => `npx -y ${_packages.FDT.name}@${fv.replace(/^(7\.|8\.[012]\.).*/, '3.12.0')}`;
8
+ const fdtCommand = fv => `npx -y ${_packages.FDT.name}@${fv.replace(/^(7\.|8\.[012]\.).*/, '3.12.0')}`;
9
9
 
10
10
  module.exports = function fonto (argv) {
11
11
 
12
12
  const allowedFontoVersionRegex = (() => {
13
- const cfvPath = path.join(_paths.repo, _paths.tdi, 'tct/fonto/compatibleVersions.json');
14
- if (fs.pathExistsSync(cfvPath)) return RegExp(fs.readJsonSync(cfvPath).regex);
13
+ const cvRegex = _modulesTdi.require('fonto/compatibleVersions.json')?.regex;
14
+ if (cvRegex) return RegExp(cvRegex);
15
15
 
16
16
  // old way: a regex for each basecommit is stored in global._git.commitTdi
17
17
  for (const fv of _git.commitTdi.fontoVersions) {
@@ -19,7 +19,7 @@ module.exports = function fonto (argv) {
19
19
  }
20
20
  })();
21
21
 
22
- if (!_tdiSubmoduleExists) _error('TDI submodule folder is missing.');
22
+ if (!_tdiSubmoduleExists()) _error('TDI submodule folder is missing.');
23
23
 
24
24
  // check if FDT is not installed globally, because then it won't be possible to use specific versions with npx
25
25
  if (fs.pathExistsSync(path.join(_appdata.npmPath, 'node_modules', _packages.FDT.name))) {
@@ -30,8 +30,8 @@ module.exports = function fonto (argv) {
30
30
 
31
31
  // find fonto instances by searching for fonto/manifest.json files
32
32
  const fontoPaths = globby.sync(['**/fonto/manifest.json', 'manifest.json', `!${_paths.tdi}/**`])
33
- .map(p => ([p.replace('manifest.json', ''), fs.readJsonSync(p).sdkVersion.replace(/Nightlies.*/, 'nightly')])
34
- );
33
+ .map(p => ([p.replace('manifest.json', ''), fs.readJsonSync(p).sdkVersion.replace(/Nightlies.*/, 'nightly')]))
34
+ ;
35
35
 
36
36
  if (fontoPaths.length===0) _error('No Fonto instance found.');
37
37
 
@@ -43,14 +43,14 @@ module.exports = function fonto (argv) {
43
43
  .then(() => {
44
44
  process.chdir(path.join(_paths.repo, _paths.apply, fontoPath));
45
45
 
46
- if (fontoPath!='.') _info(`${i>0 ? '\n' : ''}Fonto instance #${i+1}: ${path.join(_paths.apply, fontoPath)}\n`);
46
+ if (fontoPath !== '.') _info(`${i>0 ? '\n' : ''}Fonto instance #${i+1}: ${path.join(_paths.apply, fontoPath)}\n`);
47
47
 
48
48
  // execute commands sequentially and in correct order
49
- return new Promise((resolve) => {
49
+ return new Promise(resolve => {
50
50
  _info('Determining Fonto version:');
51
51
  let fontoVersionNew = typeof argv.init == 'string' ? argv.init : fontoVersionCurrent;
52
52
 
53
- if (fontoVersionNew == 'latest') {
53
+ if (fontoVersionNew === 'latest') {
54
54
  const data = execSync(`${fdtCommand(fontoVersionCurrent)} editor versions`, {encoding: 'UTF-8'});
55
55
  fontoVersionNew = data.match(/\d+\.\d+\.\d+/g).filter(v => allowedFontoVersionRegex.test(v))[0];
56
56
  }
@@ -36,7 +36,6 @@ const cmdExec = commands => new Promise(resolve => {
36
36
  });
37
37
  });
38
38
 
39
- const tdiMigrationFilePath = path.join(_paths.repo, _paths.tdi, 'tct/git/tdiCommitsRequiringMigration.js');
40
39
 
41
40
  module.exports = function git (argv) {
42
41
 
@@ -143,8 +142,8 @@ module.exports = function git (argv) {
143
142
  if (!tdiFromDateCustom) _info(`TDI submodule updated:\n${updateSubmoduleMsg}`);
144
143
 
145
144
  // tdiMigrationFilePath should exist in latest commits of releases 5.3+; As we updated to the latest version this should work
146
- if (fs.existsSync(tdiMigrationFilePath)) {
147
- const migrations = require(tdiMigrationFilePath);
145
+ const migrations = _modulesTdi.require('git/tdiCommitsRequiringMigration.js');
146
+ if (migrations) {
148
147
  const fromTdiDate = tdiFromDateCustom ? new Date(tdiFromDateCustom) : (tdiBranch.commonAncestor) ? tdiBranch.commonAncestor.date: _git.commitTdi.local().date;
149
148
  const toTdiDate = tdiToDateCustom ? new Date(tdiToDateCustom) : new Date();
150
149
 
@@ -57,7 +57,6 @@ const getFileExtractInfo = (sorting) => {
57
57
  // version info miscellaneous
58
58
  const projects = new Set;
59
59
  const types = new Set;
60
- const versionInfoConfigPath = path.join(_paths.repo, _paths.tdi, 'tct/version/versionInfo.js');
61
60
  const versionInfo = new Table({
62
61
  columns: [
63
62
  {name: 'path', alignment: 'left'},
@@ -69,10 +68,10 @@ const getFileExtractInfo = (sorting) => {
69
68
  sort: (a, b) => a.sort.toLowerCase() > b.sort.toLowerCase() ? 1 : -1
70
69
  });
71
70
 
72
- if (fs.existsSync(versionInfoConfigPath)) {
73
- const config = require(versionInfoConfigPath);
71
+ const versionInfoConfig = _modulesTdi.require('version/versionInfo.js');
72
+ if (versionInfoConfig) {
74
73
 
75
- config.forEach(v => {
74
+ versionInfoConfig.forEach(v => {
76
75
  const location = path.join(_paths.repo, v.glob);
77
76
 
78
77
  globby
@@ -4,7 +4,7 @@ const path = require('path');
4
4
 
5
5
 
6
6
  module.exports = function migrate (argv) {
7
- if (_isPre51) _error('This command only works when using branch release/5.1 and up.');
7
+ if (_isPre51()) _error('This command only works when using branch release/5.1 and up.');
8
8
 
9
9
  let filter = path.join(_paths.apply, argv.filter).toFws(); // Default set filter with filter added to the command argument -f
10
10
 
@@ -76,8 +76,8 @@ module.exports = function migrate (argv) {
76
76
  _write();
77
77
  const startTime = new Date();
78
78
 
79
- const scriptPath = path.join(_paths.repo, _paths.tdi, 'tct/migrate', a.script);
80
- require(scriptPath).forEach(step => require('./steps')(step, argv.dry, filter));
79
+ const scriptPath = path.join('migrate', a.script);
80
+ _modulesTdi.require(scriptPath).forEach(step => require('./steps')(step, argv.dry, filter));
81
81
 
82
82
  _perf(startTime);
83
83
  });
@@ -43,7 +43,7 @@ module.exports = function sql (argv) {
43
43
 
44
44
  if (argv.install) {
45
45
  // tdi
46
- const dir = `${_paths.tdi}/${_isPre51 ? 'sources' : 'src'}/database/tdi/${_isPre42 ? 'install/' : ''}`;
46
+ const dir = `${_paths.tdi}/${_isPre51() ? 'sources' : 'src'}/database/tdi/${_isPre42() ? 'install/' : ''}`;
47
47
  runSqlScript(dir + 'install.sql');
48
48
  checkLog(dir + 'tdi-install.log', false);
49
49
  // custom
@@ -96,7 +96,7 @@ module.exports = function sql (argv) {
96
96
  }
97
97
 
98
98
  if (argv.generate) {
99
- const dir = _paths.tdi + (_isPre51 ? '/util/db-config-generator/' : '/tct/sql/generate/');
99
+ const dir = _paths.tdi + (_isPre51() ? '/util/db-config-generator/' : '/tct/sql/generate/');
100
100
  fs.ensureSymlinkSync(_paths.apply, dir + 'dist', 'junction');
101
101
  runSqlScript(dir + 'start.sql');
102
102
  fs.removeSync(dir + 'dist');
@@ -104,7 +104,7 @@ module.exports = function sql (argv) {
104
104
  }
105
105
 
106
106
  if (argv.remove) {
107
- const dir = _paths.tdi + (_isPre51 ? '/util/db-config-remover/' : '/tct/sql/remove/');
107
+ const dir = _paths.tdi + (_isPre51() ? '/util/db-config-remover/' : '/tct/sql/remove/');
108
108
  runSqlScript(dir + 'start.sql');
109
109
  checkLog(dir + 'remove-config.log');
110
110
  }
package/.eslintrc.js DELETED
@@ -1,47 +0,0 @@
1
- module.exports = {
2
- 'env': {
3
- 'browser': true,
4
- 'commonjs': true,
5
- 'es2021': true
6
- },
7
- 'extends': 'eslint:recommended',
8
- 'overrides': [],
9
- 'parserOptions': {'ecmaVersion': 'latest'},
10
- 'globals': {
11
- 'process': 'readonly',
12
- 'Buffer': 'readonly',
13
- '__dirname': 'readonly',
14
- '_write': 'writable',
15
- '_info': 'writable',
16
- '_warn': 'writable',
17
- '_formatDate': 'writable',
18
- '_error': 'writable',
19
- '_perf': 'writable',
20
- '_paths': 'writable',
21
- '_appdata': 'writable',
22
- '_packages': 'writable',
23
- '_appconfig': 'writable',
24
- '_git': 'writable',
25
- '_repoconfig': 'writable',
26
- '_tdiSubmoduleExists': 'writable',
27
- '_isPre42': 'writable',
28
- '_isPre51': 'writable'
29
- },
30
- 'rules': {
31
- 'no-var': ['error'],
32
- 'indent': ['error', 2],
33
- 'quotes': [
34
- 'error',
35
- 'single',
36
- {'avoidEscape': true, 'allowTemplateLiterals': true}
37
- ],
38
- 'semi': ['error', 'always'],
39
- 'comma-style': ['error', 'last'],
40
- 'array-bracket-spacing': ['error', 'never'],
41
- 'object-curly-spacing': ['error', 'never'],
42
- 'key-spacing': ['error'],
43
- 'comma-spacing': ['error'],
44
- 'rest-spread-spacing': ['error', 'never'],
45
- 'spaced-comment': ['error', 'always'],
46
- }
47
- };
@@ -1,35 +0,0 @@
1
- # See https://pre-commit.com for more information
2
- # See https://pre-commit.com/hooks.html for more hooks
3
-
4
- repos:
5
-
6
- - repo: https://github.com/pre-commit/pre-commit-hooks
7
- rev: v4.4.0
8
- hooks:
9
- - id: trailing-whitespace
10
- - id: check-json
11
- - id: check-merge-conflict # checks for files that contain merge conflict strings
12
- - id: check-added-large-files
13
- args: [--maxkb=100]
14
-
15
- - repo: https://github.com/pre-commit/pygrep-hooks
16
- rev: v1.10.0
17
- hooks:
18
- - id: text-unicode-replacement-char # forbid files which have a UTF-8 Unicode replacement character
19
-
20
- - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
21
- rev: v2.10.0
22
- hooks:
23
- - id: pretty-format-yaml
24
- args: [--autofix, --indent, '2']
25
-
26
- - repo: https://github.com/pre-commit/mirrors-eslint
27
- rev: v8.49.0
28
- hooks:
29
- - id: eslint # javascript linter and formatter
30
- args: [--fix]
31
-
32
- - repo: https://github.com/crate-ci/typos
33
- rev: v1.16.11
34
- hooks:
35
- - id: typos # spell checker
@@ -1,6 +0,0 @@
1
- {
2
- "sonarlint.connectedMode.project": {
3
- "connectionId": "tangelosoftware",
4
- "projectKey": "tangelosoftware_tangelo-configuration-toolkit"
5
- }
6
- }
@@ -1,32 +0,0 @@
1
- image: atlassian/default-image:4
2
-
3
- clone:
4
- depth: full # SonarCloud scanner needs the full history to assign issues properly
5
-
6
- definitions:
7
- caches:
8
- sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
9
- services:
10
- docker:
11
- memory: 2048 # For large file line code
12
- steps:
13
- - step: &build-test-sonarcloud
14
- name: Build, test and analyze on SonarCloud
15
- caches:
16
- - sonar
17
- script:
18
- - pipe: sonarsource/sonarcloud-scan:2.0.0
19
- - step: &check-quality-gate-sonarcloud
20
- name: Check the Quality Gate on SonarCloud
21
- script:
22
- - pipe: sonarsource/sonarcloud-quality-gate:0.1.6
23
-
24
- pipelines:
25
- branches:
26
- master:
27
- - step: *build-test-sonarcloud
28
- - step: *check-quality-gate-sonarcloud
29
- pull-requests:
30
- '**':
31
- - step: *build-test-sonarcloud
32
- - step: *check-quality-gate-sonarcloud