@tangelo/tangelo-configuration-toolkit 1.14.2 → 1.14.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/README.md CHANGED
@@ -1,67 +1,67 @@
1
- # tangelo-configuration-toolkit
2
-
3
- Tangelo Configuration Toolkit is a command-line toolkit which offers support for developing a Tangelo configuration.
4
-
5
- ## Installation
6
-
7
- The toolkit requires [NPM](https://www.npmjs.com/get-npm) on [Node.js®](https://nodejs.org/) (at least version 14.x). An active or maintenance LTS release is recommended. After installing Node.js, you can install the latest version of the Tangelo Configuration Toolkit globally on your system using the following command:
8
-
9
- npm i -g @tangelo/tangelo-configuration-toolkit
10
-
11
- ## Usage
12
-
13
- Get help for the available commands and see version:
14
-
15
- tangelo-configuration-toolkit
16
-
17
- Get help for a specific command, detailing all its arguments:
18
-
19
- tangelo-configuration-toolkit <command>
20
-
21
- Use the `tct` shorthand instead of `tangelo-configuration-toolkit`:
22
-
23
- tct <command>
24
-
25
- ## Config
26
-
27
- ### Global
28
-
29
- The `deploy` command requires server connection information. So you'll have to create a configuration file named `tangelo-configuration-toolkit-appconfig.json` in which such information can be stored. This file will be searched for in an ancestor directory of the current working directory.
30
-
31
- The contents looks like this (all properties are optional):
32
-
33
- {
34
- "sharedConfigPath": "absolute/or/relative/path/to/folder/containing/shared/config",
35
- "servers": [{
36
- "config": {
37
- "port": 22,
38
- "parallel": 4,
39
- "username": "username",
40
- "remotedir": "/absolute/path/to/tangelo/config/folder/on/server"
41
- },
42
- "domains": ["domain.name.com"],
43
- "name": "name-for-local-deploy"
44
- }],
45
- "serverDefaults": {
46
- "config": {
47
- ...
48
- }
49
- }
50
- "defaultServer": "can be set to the name of e.g. your favorite dev server",
51
- "defaultDatabase": "can be set to the tnsname of e.g. your favorite dev server"
52
- }
53
-
54
- When passing a server name, `tct` will look for a full match with a name or a partial match (the start) with a domain.
55
-
56
- ### Repo
57
-
58
- The `build` and `sql` commands make use of a configuration file in the repository named `tangelo-configuration-toolkit-repoconfig.json`. This contains information about the customer projects.
59
-
60
- For a new repository, using `tct build --init` also creates the repoconfig-file. For existing projects not having the repoconfig-file, you can use `tct build --config` to generate it.
61
-
62
- ### oXygen
63
-
64
- The `build -x` commands set projects transformation scenarios and masterfiles in the oXygen project file with the following functionality:
65
- - Will try to preserve manually added entries in the transformation scenarios and masterfiles
66
- - Will remove non existing masterfiles or masterfiles that start with a '_'
67
- - No masterfiles / scenarios will be added if their path match with oXygens hidden directory patterns
1
+ # tangelo-configuration-toolkit
2
+
3
+ Tangelo Configuration Toolkit is a command-line toolkit which offers support for developing a Tangelo configuration.
4
+
5
+ ## Installation
6
+
7
+ The toolkit requires [NPM](https://www.npmjs.com/get-npm) on [Node.js®](https://nodejs.org/) (at least version 14.x). An active or maintenance LTS release is recommended. After installing Node.js, you can install the latest version of the Tangelo Configuration Toolkit globally on your system using the following command:
8
+
9
+ npm i -g @tangelo/tangelo-configuration-toolkit
10
+
11
+ ## Usage
12
+
13
+ Get help for the available commands and see version:
14
+
15
+ tangelo-configuration-toolkit
16
+
17
+ Get help for a specific command, detailing all its arguments:
18
+
19
+ tangelo-configuration-toolkit <command>
20
+
21
+ Use the `tct` shorthand instead of `tangelo-configuration-toolkit`:
22
+
23
+ tct <command>
24
+
25
+ ## Config
26
+
27
+ ### Global
28
+
29
+ The `deploy` command requires server connection information. So you'll have to create a configuration file named `tangelo-configuration-toolkit-appconfig.json` in which such information can be stored. This file will be searched for in an ancestor directory of the current working directory.
30
+
31
+ The contents looks like this (all properties are optional):
32
+
33
+ {
34
+ "sharedConfigPath": "absolute/or/relative/path/to/folder/containing/shared/config",
35
+ "servers": [{
36
+ "config": {
37
+ "port": 22,
38
+ "parallel": 4,
39
+ "username": "username",
40
+ "remotedir": "/absolute/path/to/tangelo/config/folder/on/server"
41
+ },
42
+ "domains": ["domain.name.com"],
43
+ "name": "name-for-local-deploy"
44
+ }],
45
+ "serverDefaults": {
46
+ "config": {
47
+ ...
48
+ }
49
+ }
50
+ "defaultServer": "can be set to the name of e.g. your favorite dev server",
51
+ "defaultDatabase": "can be set to the tnsname of e.g. your favorite dev server"
52
+ }
53
+
54
+ When passing a server name, `tct` will look for a full match with a name or a partial match (the start) with a domain.
55
+
56
+ ### Repo
57
+
58
+ The `build` and `sql` commands make use of a configuration file in the repository named `tangelo-configuration-toolkit-repoconfig.json`. This contains information about the customer projects.
59
+
60
+ For a new repository, using `tct build --init` also creates the repoconfig-file. For existing projects not having the repoconfig-file, you can use `tct build --config` to generate it.
61
+
62
+ ### oXygen
63
+
64
+ The `build -x` commands set projects transformation scenarios and masterfiles in the oXygen project file with the following functionality:
65
+ - Will try to preserve manually added entries in the transformation scenarios and masterfiles
66
+ - Will remove non existing masterfiles or masterfiles that start with a '_'
67
+ - No masterfiles / scenarios will be added if their path match with oXygens hidden directory patterns
package/bin/index.js CHANGED
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env node
2
-
1
+ #!/usr/bin/env node
2
+
3
3
  require('..');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangelo/tangelo-configuration-toolkit",
3
- "version": "1.14.2",
3
+ "version": "1.14.3",
4
4
  "engines": {
5
5
  "node": ">=14.0.0"
6
6
  },
@@ -1,44 +1,44 @@
1
- const execGitCommand = require('./exec-git-command');
2
- const path = require('path');
3
-
4
- module.exports = function getTdiBranch(toBranchName) {
5
- const tdiBranch = {};
6
- // Fetch all
7
- _info(`Fetch TDI submodule`);
8
- const cmdFetch = execGitCommand('fetch -pf --all', path.join(_paths.repo, _paths.tdi));
9
- if (cmdFetch.error) _warn(`Fetch failed\n${cmdFetch.error}`);
10
-
11
- let toBranch;
12
- if (toBranchName) {
13
- // Check if specified branch exists; we will update to this branch
14
- toBranch = String(toBranchName).replace(/(?:release\/)?(\d+(?:\.[\dxt]+)*)/, `release/$1`);
15
- const branchExists = execGitCommand(`branch --remote`, path.join(_paths.repo, _paths.tdi)).match(`origin/${toBranch}`);
16
- if (!branchExists) _error(`TDI branch "${toBranch}" does not exist. Note that TCT can only update to a release branch.`);
17
- }
18
-
19
- // Get remote release branches containing TDI HEAD commit
20
- const releaseBranches = execGitCommand(`branch --all --contains ${_git.commitTdi.local().hash}`, path.join(_paths.repo, _paths.tdi)).match(/remotes\/origin\/release\/[^\s]+/gsm);
21
- if (!releaseBranches || releaseBranches.error) _error(`Could not retrieve TDI release branches`);
22
-
23
- // Get the first possible branch; prefer release/5.1 over release/5.2:
24
- releaseBranches.sort((a, b) => a > b ? 1 : -1);
25
-
26
- // Set branch name of firstBranch without 'remotes/origin/'
27
- tdiBranch.name = releaseBranches[0].replace(/remotes\/origin\//g, '');
28
-
29
- // In case of branch switch set from.name to the old branch and name to the new branch
30
- if (toBranch) {
31
- if (tdiBranch.name > toBranch) _error(`You cannot downgrade to a lower release branch with TCT.`);
32
- tdiBranch.from = {name: tdiBranch.name};
33
- tdiBranch.name = toBranch;
34
-
35
- const branchHash = execGitCommand(`rev-parse origin/${toBranch}`, path.join(_paths.repo, _paths.tdi));
36
- const commonAncestorHash = execGitCommand(`merge-base ${_git.commitTdi.local().hash} ${branchHash}`, path.join(_paths.repo, _paths.tdi));
37
- const commonAncestorDate = execGitCommand(`show ${commonAncestorHash} --no-patch --format=%cd --date=iso-strict `, path.join(_paths.repo, _paths.tdi), ['date']).date;
38
- tdiBranch.commonAncestor = {date: new Date(commonAncestorDate)};
39
- }
40
-
41
- // Get number of commits behind
42
- tdiBranch.commitsBehind = execGitCommand(`rev-list HEAD...origin/${tdiBranch.name} --count`, path.join(_paths.repo, _paths.tdi));
43
- return tdiBranch;
1
+ const execGitCommand = require('./exec-git-command');
2
+ const path = require('path');
3
+
4
+ module.exports = function getTdiBranch(toBranchName) {
5
+ const tdiBranch = {};
6
+ // Fetch all
7
+ _info(`Fetch TDI submodule`);
8
+ const cmdFetch = execGitCommand('fetch -pf --all', path.join(_paths.repo, _paths.tdi));
9
+ if (cmdFetch.error) _warn(`Fetch failed\n${cmdFetch.error}`);
10
+
11
+ let toBranch;
12
+ if (toBranchName) {
13
+ // Check if specified branch exists; we will update to this branch
14
+ toBranch = String(toBranchName).replace(/(?:release\/)?(\d+(?:\.[\dxt]+)*)/, `release/$1`);
15
+ const branchExists = execGitCommand(`branch --remote`, path.join(_paths.repo, _paths.tdi)).match(`origin/${toBranch}`);
16
+ if (!branchExists) _error(`TDI branch "${toBranch}" does not exist. Note that TCT can only update to a release branch.`);
17
+ }
18
+
19
+ // Get remote release branches containing TDI HEAD commit
20
+ const releaseBranches = execGitCommand(`branch --all --contains ${_git.commitTdi.local().hash}`, path.join(_paths.repo, _paths.tdi)).match(/remotes\/origin\/release\/[^\s]+/gsm);
21
+ if (!releaseBranches || releaseBranches.error) _error(`Could not retrieve TDI release branches`);
22
+
23
+ // Get the first possible branch; prefer release/5.1 over release/5.2:
24
+ releaseBranches.sort((a, b) => a > b ? 1 : -1);
25
+
26
+ // Set branch name of firstBranch without 'remotes/origin/'
27
+ tdiBranch.name = releaseBranches[0].replace(/remotes\/origin\//g, '');
28
+
29
+ // In case of branch switch set from.name to the old branch and name to the new branch
30
+ if (toBranch) {
31
+ if (tdiBranch.name > toBranch) _error(`You cannot downgrade to a lower release branch with TCT.`);
32
+ tdiBranch.from = {name: tdiBranch.name};
33
+ tdiBranch.name = toBranch;
34
+
35
+ const branchHash = execGitCommand(`rev-parse origin/${toBranch}`, path.join(_paths.repo, _paths.tdi));
36
+ const commonAncestorHash = execGitCommand(`merge-base ${_git.commitTdi.local().hash} ${branchHash}`, path.join(_paths.repo, _paths.tdi));
37
+ const commonAncestorDate = execGitCommand(`show ${commonAncestorHash} --no-patch --format=%cd --date=iso-strict `, path.join(_paths.repo, _paths.tdi), ['date']).date;
38
+ tdiBranch.commonAncestor = {date: new Date(commonAncestorDate)};
39
+ }
40
+
41
+ // Get number of commits behind
42
+ tdiBranch.commitsBehind = execGitCommand(`rev-list HEAD...origin/${tdiBranch.name} --count`, path.join(_paths.repo, _paths.tdi));
43
+ return tdiBranch;
44
44
  };
@@ -1,19 +1,19 @@
1
- // based on gulp-batch-replace
2
-
3
- const es = require('event-stream'), minimatch = require('minimatch'), istextorbinary = require('istextorbinary');
4
-
5
- const execReplace = (c, s, r) => Buffer.from(s instanceof RegExp ? String(c).replace(s, r) : String(c).split(s).join(r));
6
-
7
- module.exports = (arr) => {
8
- return es.map((file, callback) => {
9
- if(file.contents instanceof Buffer) {
10
- arr.forEach(e => {
11
- // exec if no glob is passed or if glob matches, and it's a text file
12
- if ((!e[2] || minimatch(file.path, e[2])) && istextorbinary.isText(file.path, file)) {
13
- file.contents = execReplace(file.contents, e[0], e[1]);
14
- }
15
- });
16
- }
17
- callback(null, file);
18
- });
19
- };
1
+ // based on gulp-batch-replace
2
+
3
+ const es = require('event-stream'), minimatch = require('minimatch'), istextorbinary = require('istextorbinary');
4
+
5
+ const execReplace = (c, s, r) => Buffer.from(s instanceof RegExp ? String(c).replace(s, r) : String(c).split(s).join(r));
6
+
7
+ module.exports = (arr) => {
8
+ return es.map((file, callback) => {
9
+ if(file.contents instanceof Buffer) {
10
+ arr.forEach(e => {
11
+ // exec if no glob is passed or if glob matches, and it's a text file
12
+ if ((!e[2] || minimatch(file.path, e[2])) && istextorbinary.isText(file.path, file)) {
13
+ file.contents = execReplace(file.contents, e[0], e[1]);
14
+ }
15
+ });
16
+ }
17
+ callback(null, file);
18
+ });
19
+ };
@@ -1,11 +1,11 @@
1
- // replacement for the official (but deprecated) gulp-simple-rename
2
- // kept same name because of usage in tdi
3
-
4
- const through2 = require('through2');
5
-
6
- module.exports = (fn) => {
7
- return through2.obj((file, enc, cb) => {
8
- file.path = fn(file.path);
9
- cb(null, file);
10
- });
11
- };
1
+ // replacement for the official (but deprecated) gulp-simple-rename
2
+ // kept same name because of usage in tdi
3
+
4
+ const through2 = require('through2');
5
+
6
+ module.exports = (fn) => {
7
+ return through2.obj((file, enc, cb) => {
8
+ file.path = fn(file.path);
9
+ cb(null, file);
10
+ });
11
+ };
@@ -1,175 +1,175 @@
1
- const fs = require('fs-extra');
2
- const globby = require('globby');
3
- const path = require('path');
4
- const SaxonJS = require('saxon-js');
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');
8
- const cmscustomPath = 'config/cmscustom/';
9
- const siteStylesheetsPath = 'config/txp/site-stylesheets/';
10
-
11
- const masterFiles = new Set;
12
- const transformationScenarios = [];
13
-
14
- const convertToValidFilename = (string) => string.replace(/[/|\\:*?"<>]/g, ' ');
15
-
16
- const createProjectFile = (config, filename) => {
17
- _info('Initializing xpr file(s):');
18
- const xprFiles = [...globby.sync(`*.xpr`)];
19
- const newXprFile = (typeof filename === 'string') ? convertToValidFilename(filename) + '.xpr' : null;
20
- // Add newXprFile at the start of xprFiles if it does not already exists:
21
- if (xprFiles.indexOf(newXprFile)===-1) xprFiles.unshift(newXprFile);
22
-
23
- // Copy xpr file from TDI if it does not exists yet;
24
- if (xprFiles[0] && !newXprFile) _write(`Found: ${xprFiles.join(', ')}`);
25
- else {
26
- if (!newXprFile) {
27
- // Set xpr filename to customer name (assumes correct upsert scripts structure)
28
- const customers = new Set;
29
- _repoconfig.forEach(p => customers.add(p.customer_name));
30
- xprFiles.push(convertToValidFilename([...customers].join(' - ')) + '.xpr');
31
- }
32
- // Copy new xpr file
33
- fs.copySync(path.join(_paths.repo, 'tangelo-default-implementation/src/[customer].xpr'), path.join(_paths.repo, xprFiles[0]));
34
- _write(`Created: '${xprFiles[0]}'`);
35
- }
36
-
37
- // Search for transformationScenarios/masterfiles based on TDI submodule oxygenProjectFile config
38
- _info('\nSearching for transformationScenarios/masterfiles');
39
- config.oxygenProjectFile.forEach(
40
- pf => {
41
- // Collect transformation scenarios and add them to the transformationScenarios array; add individual stylesheets to the masterFiles set.
42
- if (pf.transformation) getTransformations(pf.transformation);
43
- // Add files to the masterfiles set.
44
- else if (pf.masterfile) getMasterfiles(pf.masterfile);
45
- }
46
- );
47
-
48
- // update all .xpr files with collected transformation scenarios and masterfiles.
49
- transformXprFile(xprFiles);
50
- };
51
-
52
- const getTransformations = (config) => {
53
- _repoconfig.forEach(rc => {
54
- // get pathname of customer/project
55
- const [customerPath, projectPath] = config.location == 'database' ? rc.path_dbconfig : rc.path_cmscustom;
56
-
57
- // set pathname of customer/project in location glob-expression
58
- const location = path.join(
59
- _paths.repo,
60
- config.files.replace(/\[customer\]/, customerPath).replace(/\[project\]/, projectPath)
61
- );
62
-
63
- globby
64
- .sync(`${location}`)
65
- .forEach(f => {
66
- // extract baseStrings from file
67
- const fileString = fs.readFileSync(f).toString();
68
- const baseStrings = fileString.match(RegExp(config.extracts.base, 'gm'));
69
-
70
- if (fileString.replace(/\s|^prompt\s.*$/gm, '')!=='') {
71
- if (baseStrings) {
72
- baseStrings.forEach(s => {
73
- // extract type, name, files info from baseString
74
- const type = config.extracts.type ? s.match(RegExp(config.extracts.type))[1] : config.values.type;
75
- const name = config.extracts.name ? s.match(RegExp(config.extracts.name))[1] : config.values.name;
76
- const files = s.match(RegExp(config.extracts.files))[1];
77
-
78
- // Add transformation scenario to the transformationScenario array
79
- transformationScenarios.push({
80
- name: `${type}: ${name} (${rc.customer_name}, ${rc.project_name})`, // note that in createProjectFile.xsl a regex is added that matches scenarios based on this name. This to preserve manually added scenarios.
81
- transformationScenario: files,
82
- location: config.location == 'txp' ? siteStylesheetsPath : cmscustomPath
83
- });
84
-
85
- // Add each non-tdi stylesheet in transformation scenario to the masterFiles set
86
- files.split(',').forEach(f => {
87
- const filePath = `${config.location == 'txp' ? siteStylesheetsPath : cmscustomPath}${f}`;
88
- if (!f.startsWith('tdi')) masterFiles.add(filePath);
89
- });
90
- });
91
- } else {
92
- _write(`No transformation scenarios found in ${f} for '${config.extracts.base}'`);
93
- }
94
- }
95
- });
96
- });
97
-
98
- };
99
-
100
-
101
- const getMasterfiles = (config) => {
102
- globby
103
- .sync(`${path.join(_paths.repo, config.files)}`)
104
- .forEach(cf => {
105
- // Check if masterfile should be extracted from file
106
- const fileString = fs.readFileSync(cf).toString();
107
- if (fileString.replace(/\s|^prompt\s.*$/gm, '')!=='') {
108
- if (config.extracts) {
109
- // extract baseStrings from file
110
- const baseStrings = fileString.match(RegExp(config.extracts.base, 'gm'));
111
-
112
- if (baseStrings) {
113
- baseStrings.forEach(s => {
114
- // extract (comma-separated) list of masterfiles
115
- const filesString = s.match(RegExp(config.extracts.files))[1];
116
- if (!filesString) _error(`No masterfiles found in '${s}' for '${config.extracts.files}'`);
117
-
118
- // Add each non-tdi masterfile to the masterFiles set
119
- filesString.split(',').forEach(f => {
120
- if (!f.startsWith('tdi')){
121
- const filePath = `${config.location == 'txp' ? siteStylesheetsPath : cmscustomPath}${f}`;
122
- masterFiles.add(filePath);
123
- }
124
- });
125
- });
126
- } else {
127
- _write(`No masterfiles found in ${cf} for '${config.extracts.base}'`);
128
- }
129
- } else { // Add synced file to masterfiles; strip path from c:/... hence it starts with config/cmscustom or config/txp/site-stylesheets
130
- const filePath = config.location == 'txp' ? `${siteStylesheetsPath}${cf.split(siteStylesheetsPath)[1]}` : `${cmscustomPath}${cf.split(cmscustomPath)[1]}`;
131
- masterFiles.add(filePath);
132
- }
133
- }
134
- });
135
-
136
- };
137
-
138
- const transformXprFile = (xprFiles) => {
139
- _info('\nUpdating xpr file(s):');
140
- // create with: xslt3 -t -xsl:createProjectFile.xsl -export:createProjectFile.sef.json v -nogo'
141
-
142
- xprFiles
143
- .forEach(xprFile => {
144
- // Transform xpr; add masterfiles and transformationScenarios as parameters of the stylesheet
145
- _write(`${xprFile}\n`);
146
- SaxonJS.transform({
147
- stylesheetText: fs.readFileSync(sefFilePath),
148
- stylesheetBaseURI: 'createProjectFile.sef.json',
149
- sourceFileName: path.join(_paths.repo, xprFile),
150
- destination: 'serialized',
151
- stylesheetParams: {
152
- 'masterfiles': [...masterFiles],
153
- 'Q{}transformationScenarios': transformationScenarios
154
- }
155
- }, 'async')
156
- .then(output => {
157
- // Write result of transformation to xpr file
158
- fs.writeFileSync(path.join(_paths.repo, xprFile), output.principalResult);
159
- })
160
- .catch(e => _warn(`Failed to update: ${xprFile}\n ${e}`));
161
- });
162
- };
163
-
164
-
165
- module.exports = function oxygen (filename) {
166
- // Set projects transformation scenarios and masterfiles in oXygen project file
167
- // - Will try to preserve manually added entries in the transformation scenarios and masterfiles
168
- // - Will remove non existing masterfiles or masterfiles that start with a '_'
169
-
170
- if (!fs.existsSync(spConfigPath) || !fs.existsSync(sefFilePath)) {
171
- _error(`Cannot find required files in TDI submodule. Try updating TDI submodule.`);
172
- }
173
-
174
- createProjectFile(require(spConfigPath), filename);
1
+ const fs = require('fs-extra');
2
+ const globby = require('globby');
3
+ const path = require('path');
4
+ const SaxonJS = require('saxon-js');
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');
8
+ const cmscustomPath = 'config/cmscustom/';
9
+ const siteStylesheetsPath = 'config/txp/site-stylesheets/';
10
+
11
+ const masterFiles = new Set;
12
+ const transformationScenarios = [];
13
+
14
+ const convertToValidFilename = (string) => string.replace(/[/|\\:*?"<>]/g, ' ');
15
+
16
+ const createProjectFile = (config, filename) => {
17
+ _info('Initializing xpr file(s):');
18
+ const xprFiles = [...globby.sync(`*.xpr`)];
19
+ const newXprFile = (typeof filename === 'string') ? convertToValidFilename(filename) + '.xpr' : null;
20
+ // Add newXprFile at the start of xprFiles if it does not already exists:
21
+ if (newXprFile && xprFiles.indexOf(newXprFile)===-1) xprFiles.unshift(newXprFile);
22
+
23
+ // Copy xpr file from TDI if it does not exists yet;
24
+ if (xprFiles[0] && !newXprFile) _write(`Found: ${xprFiles.join(', ')}`);
25
+ else {
26
+ if (!newXprFile) {
27
+ // Set xpr filename to customer name (assumes correct upsert scripts structure)
28
+ const customers = new Set;
29
+ _repoconfig.forEach(p => customers.add(p.customer_name));
30
+ xprFiles.push(convertToValidFilename([...customers].join(' - ')) + '.xpr');
31
+ }
32
+ // Copy new xpr file
33
+ fs.copySync(path.join(_paths.repo, 'tangelo-default-implementation/src/[customer].xpr'), path.join(_paths.repo, xprFiles[0]));
34
+ _write(`Created: '${xprFiles[0]}'`);
35
+ }
36
+
37
+ // Search for transformationScenarios/masterfiles based on TDI submodule oxygenProjectFile config
38
+ _info('\nSearching for transformationScenarios/masterfiles');
39
+ config.oxygenProjectFile.forEach(
40
+ pf => {
41
+ // Collect transformation scenarios and add them to the transformationScenarios array; add individual stylesheets to the masterFiles set.
42
+ if (pf.transformation) getTransformations(pf.transformation);
43
+ // Add files to the masterfiles set.
44
+ else if (pf.masterfile) getMasterfiles(pf.masterfile);
45
+ }
46
+ );
47
+
48
+ // update all .xpr files with collected transformation scenarios and masterfiles.
49
+ transformXprFile(xprFiles);
50
+ };
51
+
52
+ const getTransformations = (config) => {
53
+ _repoconfig.forEach(rc => {
54
+ // get pathname of customer/project
55
+ const [customerPath, projectPath] = config.location == 'database' ? rc.path_dbconfig : rc.path_cmscustom;
56
+
57
+ // set pathname of customer/project in location glob-expression
58
+ const location = path.join(
59
+ _paths.repo,
60
+ config.files.replace(/\[customer\]/, customerPath).replace(/\[project\]/, projectPath)
61
+ );
62
+
63
+ globby
64
+ .sync(`${location}`)
65
+ .forEach(f => {
66
+ // extract baseStrings from file
67
+ const fileString = fs.readFileSync(f).toString();
68
+ const baseStrings = fileString.match(RegExp(config.extracts.base, 'gm'));
69
+
70
+ if (fileString.replace(/\s|^prompt\s.*$/gm, '')!=='') {
71
+ if (baseStrings) {
72
+ baseStrings.forEach(s => {
73
+ // extract type, name, files info from baseString
74
+ const type = config.extracts.type ? s.match(RegExp(config.extracts.type))[1] : config.values.type;
75
+ const name = config.extracts.name ? s.match(RegExp(config.extracts.name))[1] : config.values.name;
76
+ const files = s.match(RegExp(config.extracts.files))[1];
77
+
78
+ // Add transformation scenario to the transformationScenario array
79
+ transformationScenarios.push({
80
+ name: `${type}: ${name} (${rc.customer_name}, ${rc.project_name})`, // note that in createProjectFile.xsl a regex is added that matches scenarios based on this name. This to preserve manually added scenarios.
81
+ transformationScenario: files,
82
+ location: config.location == 'txp' ? siteStylesheetsPath : cmscustomPath
83
+ });
84
+
85
+ // Add each non-tdi stylesheet in transformation scenario to the masterFiles set
86
+ files.split(',').forEach(f => {
87
+ const filePath = `${config.location == 'txp' ? siteStylesheetsPath : cmscustomPath}${f}`;
88
+ if (!f.startsWith('tdi')) masterFiles.add(filePath);
89
+ });
90
+ });
91
+ } else {
92
+ _write(`No transformation scenarios found in ${f} for '${config.extracts.base}'`);
93
+ }
94
+ }
95
+ });
96
+ });
97
+
98
+ };
99
+
100
+
101
+ const getMasterfiles = (config) => {
102
+ globby
103
+ .sync(`${path.join(_paths.repo, config.files)}`)
104
+ .forEach(cf => {
105
+ // Check if masterfile should be extracted from file
106
+ const fileString = fs.readFileSync(cf).toString();
107
+ if (fileString.replace(/\s|^prompt\s.*$/gm, '')!=='') {
108
+ if (config.extracts) {
109
+ // extract baseStrings from file
110
+ const baseStrings = fileString.match(RegExp(config.extracts.base, 'gm'));
111
+
112
+ if (baseStrings) {
113
+ baseStrings.forEach(s => {
114
+ // extract (comma-separated) list of masterfiles
115
+ const filesString = s.match(RegExp(config.extracts.files))[1];
116
+ if (!filesString) _error(`No masterfiles found in '${s}' for '${config.extracts.files}'`);
117
+
118
+ // Add each non-tdi masterfile to the masterFiles set
119
+ filesString.split(',').forEach(f => {
120
+ if (!f.startsWith('tdi')){
121
+ const filePath = `${config.location == 'txp' ? siteStylesheetsPath : cmscustomPath}${f}`;
122
+ masterFiles.add(filePath);
123
+ }
124
+ });
125
+ });
126
+ } else {
127
+ _write(`No masterfiles found in ${cf} for '${config.extracts.base}'`);
128
+ }
129
+ } else { // Add synced file to masterfiles; strip path from c:/... hence it starts with config/cmscustom or config/txp/site-stylesheets
130
+ const filePath = config.location == 'txp' ? `${siteStylesheetsPath}${cf.split(siteStylesheetsPath)[1]}` : `${cmscustomPath}${cf.split(cmscustomPath)[1]}`;
131
+ masterFiles.add(filePath);
132
+ }
133
+ }
134
+ });
135
+
136
+ };
137
+
138
+ const transformXprFile = (xprFiles) => {
139
+ _info('\nUpdating xpr file(s):');
140
+ // create with: xslt3 -t -xsl:createProjectFile.xsl -export:createProjectFile.sef.json v -nogo'
141
+
142
+ xprFiles
143
+ .forEach(xprFile => {
144
+ // Transform xpr; add masterfiles and transformationScenarios as parameters of the stylesheet
145
+ _write(`${xprFile}\n`);
146
+ SaxonJS.transform({
147
+ stylesheetText: fs.readFileSync(sefFilePath),
148
+ stylesheetBaseURI: 'createProjectFile.sef.json',
149
+ sourceFileName: path.join(_paths.repo, xprFile),
150
+ destination: 'serialized',
151
+ stylesheetParams: {
152
+ 'masterfiles': [...masterFiles],
153
+ 'Q{}transformationScenarios': transformationScenarios
154
+ }
155
+ }, 'async')
156
+ .then(output => {
157
+ // Write result of transformation to xpr file
158
+ fs.writeFileSync(path.join(_paths.repo, xprFile), output.principalResult);
159
+ })
160
+ .catch(e => _warn(`Failed to update: ${xprFile}\n ${e}`));
161
+ });
162
+ };
163
+
164
+
165
+ module.exports = function oxygen (filename) {
166
+ // Set projects transformation scenarios and masterfiles in oXygen project file
167
+ // - Will try to preserve manually added entries in the transformation scenarios and masterfiles
168
+ // - Will remove non existing masterfiles or masterfiles that start with a '_'
169
+
170
+ if (!fs.existsSync(spConfigPath) || !fs.existsSync(sefFilePath)) {
171
+ _error(`Cannot find required files in TDI submodule. Try updating TDI submodule.`);
172
+ }
173
+
174
+ createProjectFile(require(spConfigPath), filename);
175
175
  };
@@ -1,201 +1,201 @@
1
- const fs = require('fs-extra');
2
- const globby = require('globby');
3
- const path = require('path');
4
- const {Table} = require('console-table-printer');
5
-
6
- const execGitCommand = require('../../lib/exec-git-command');
7
- const getTdiBranch = require('../../lib/get-tdi-branch');
8
- const c = require('../deploy/config');
9
- const {remote} = require('../deploy/execute');
10
-
11
-
12
- const getGitInfo = () => {
13
- // Version info TDI submodule
14
- const gitSubmoduleInfo = new Table({
15
- columns: [
16
- {name: 'property', title: 'TDI - submodule', alignment: 'left'},
17
- {name: 'value', alignment: 'left'}
18
- ],
19
- });
20
-
21
- // Fetch all
22
- const cmdFetch = execGitCommand('fetch -pf --all', path.join(_paths.repo, _paths.tdi));
23
- if (cmdFetch.error) _warn(`Fetch failed\n${cmdFetch.error}`);
24
-
25
- // Set branch name of firstBranch without 'remotes/origin/'
26
- const tdiBranch = getTdiBranch();
27
-
28
- // Get number of commits behind
29
- tdiBranch.commitsBehind = execGitCommand(`rev-list HEAD...origin/${tdiBranch.name} --count`, path.join(_paths.repo, _paths.tdi));
30
-
31
- // Create table rows for TDI submodule info
32
- gitSubmoduleInfo.addRow({
33
- property: 'Commit date',
34
- value: _formatDate(_git.commitTdi.local().date)
35
- });
36
- if (tdiBranch) {
37
- gitSubmoduleInfo.addRow({
38
- property: 'Branch',
39
- value: tdiBranch.name
40
- });
41
- gitSubmoduleInfo.addRow({
42
- property: 'Commits behind',
43
- value: tdiBranch.commitsBehind
44
- });
45
- } else {
46
- gitSubmoduleInfo.addRow({
47
- property: 'Branch could not be determined',
48
- value: ''
49
- });
50
- }
51
-
52
- // Print TDI submodule info
53
- gitSubmoduleInfo.printTable();
54
- };
55
-
56
- const getFileExtractInfo = (sorting) => {
57
- // version info miscellaneous
58
- const projects = new Set;
59
- const types = new Set;
60
- const versionInfoConfigPath = path.join(_paths.repo, _paths.tdi, 'tct/version/versionInfo.js');
61
- const versionInfo = new Table({
62
- columns: [
63
- {name: 'path', alignment: 'left'},
64
- {name: 'type', alignment: 'left'},
65
- {name: 'version', alignment: 'left'},
66
- {name: 'sort'}
67
- ],
68
- disabledColumns: ['sort'],
69
- sort: (a, b) => a.sort.toLowerCase() > b.sort.toLowerCase() ? 1 : -1
70
- });
71
-
72
- if (fs.existsSync(versionInfoConfigPath)) {
73
- const config = require(versionInfoConfigPath);
74
-
75
- config.forEach(v => {
76
- const location = path.join(_paths.repo, v.glob);
77
-
78
- globby
79
- .sync(location)
80
- .forEach(f => {
81
- const filePathExtract = f.match(/.*(?<path>(cmscustom|site-stylesheets)\/(?<customer>[^/]*)\/(?<project>[^/]*)\/.*)/);
82
- const path = filePathExtract.groups.path || '';
83
- const project = filePathExtract.groups.project || '';
84
-
85
- const fileContent = fs.readFileSync(f).toString();
86
- v.extracts.forEach(e => {
87
- const extract = fileContent.match(e.regex);
88
- if (extract) {
89
- projects.add(project); // Store the projects where versioninfo is found
90
- types.add(e.type); // Store the types for which versioninfo is found
91
- versionInfo.addRow({ // Create row with version information to output
92
- path,
93
- sort: `${sorting=='project' ? project : e.type}_2${sorting=='project' ? e.type : extract.groups.version}`, // Output is sorted on project or type: '_2' ensures it is rendered after the empty row and the row with the project name
94
- type: e.type,
95
- version: extract.groups.version
96
- });
97
- }
98
- });
99
- });
100
- });
101
-
102
- if (sorting=='project') {
103
- // For projects containing version information
104
- projects.forEach(p => {
105
- versionInfo.addRow({ // Add empty row after project
106
- path: '',
107
- sort: `${p}_3`,
108
- type: '',
109
- version: ''
110
- });
111
- versionInfo.addRow({ // Add row with project name
112
- path: `-- ${p}:`,
113
- sort: `${p}_1`,
114
- type: '',
115
- version: ''
116
- }, {
117
- color: 'yellow'
118
- });
119
- });
120
- }
121
- else if (sorting=='type') {
122
- types.forEach(t => {
123
- versionInfo.addRow({ // Add empty row after type
124
- path: '',
125
- sort: `${t}_3`,
126
- type: '',
127
- version: ''
128
- });
129
- });
130
- }
131
- versionInfo.printTable();
132
- }
133
- else {
134
- _warn('Version info of miscellaneous items cannot be extracted:\nCannot find required files in TDI submodule. Try updating TDI submodule.');
135
- }
136
- };
137
-
138
- const getServerInfo = (server) => {
139
- // Remote server info
140
- // common setup
141
- _write();
142
- c.setServer(server);
143
-
144
- if (!c.envDev) {
145
- _info(`Remote version info for '${c.server.ftpConfig.host}':\n`);
146
- remote.add('sudo ~root/scripts/version.sh', '').process();
147
- }
148
- else {
149
- _info('For development environments no server version information is available. Check rancher / database for this information.\nAdd the --server option with a non-dev environment to see version information for that server.');
150
- }
151
- };
152
-
153
-
154
- module.exports = function info (argv) {
155
-
156
- if (argv.doctypes) {
157
- _info('Document type information for this git repository\n');
158
-
159
- const doctypesInfo = new Table({
160
- columns: [
161
- {name: 'id', alignment: 'right'},
162
- {name: 'name', alignment: 'left'},
163
- {name: 'paths', alignment: 'left'}
164
- ],
165
- });
166
-
167
- globby
168
- .sync(_paths.repo + '/database/config/**/txd_document_types.sql')
169
- .forEach((p, i, a) => {
170
- fs.readFileSync(p).toString().match(/select([\s\S]+?)from\s+dual/gmi)
171
- .forEach((dtRow, i, a) => {
172
- const ntSqlInsert = fs.readFileSync(p.replace('txd_document_types', 'txd_node_types')).toString().match(/select(.*?)from\s+dual/s)[1];
173
- const id = dtRow.match(/(\d+) id/)?.[1];
174
- const name = dtRow.match(/'([^']+)' display_name/)?.[1];
175
- const dbPath = p.match(/(database\/config\/(:?.*)\/)txd_document_types.sql/i)?.[1];
176
- const prPath = ntSqlInsert.match(/'([^']+)' xsl_prep_inc/)[1].replace('prepare_xincludes.xsl', '');
177
-
178
- doctypesInfo.addRows([
179
- {id, name, paths: 'config/cmscustom/'+ prPath},
180
- {paths: dbPath}
181
- ]);
182
-
183
- if (i!==a.length-1) doctypesInfo.addRow({});
184
- });
185
-
186
- if (i!==a.length-1) doctypesInfo.addRow({});
187
- });
188
-
189
-
190
- doctypesInfo.printTable();
191
- }
192
-
193
- if (argv.versions) {
194
- _info('Version information for this git repository\n');
195
-
196
- getGitInfo();
197
- getFileExtractInfo(argv.versions);
198
- getServerInfo(argv.server);
199
- }
200
-
201
- };
1
+ const fs = require('fs-extra');
2
+ const globby = require('globby');
3
+ const path = require('path');
4
+ const {Table} = require('console-table-printer');
5
+
6
+ const execGitCommand = require('../../lib/exec-git-command');
7
+ const getTdiBranch = require('../../lib/get-tdi-branch');
8
+ const c = require('../deploy/config');
9
+ const {remote} = require('../deploy/execute');
10
+
11
+
12
+ const getGitInfo = () => {
13
+ // Version info TDI submodule
14
+ const gitSubmoduleInfo = new Table({
15
+ columns: [
16
+ {name: 'property', title: 'TDI - submodule', alignment: 'left'},
17
+ {name: 'value', alignment: 'left'}
18
+ ],
19
+ });
20
+
21
+ // Fetch all
22
+ const cmdFetch = execGitCommand('fetch -pf --all', path.join(_paths.repo, _paths.tdi));
23
+ if (cmdFetch.error) _warn(`Fetch failed\n${cmdFetch.error}`);
24
+
25
+ // Set branch name of firstBranch without 'remotes/origin/'
26
+ const tdiBranch = getTdiBranch();
27
+
28
+ // Get number of commits behind
29
+ tdiBranch.commitsBehind = execGitCommand(`rev-list HEAD...origin/${tdiBranch.name} --count`, path.join(_paths.repo, _paths.tdi));
30
+
31
+ // Create table rows for TDI submodule info
32
+ gitSubmoduleInfo.addRow({
33
+ property: 'Commit date',
34
+ value: _formatDate(_git.commitTdi.local().date)
35
+ });
36
+ if (tdiBranch) {
37
+ gitSubmoduleInfo.addRow({
38
+ property: 'Branch',
39
+ value: tdiBranch.name
40
+ });
41
+ gitSubmoduleInfo.addRow({
42
+ property: 'Commits behind',
43
+ value: tdiBranch.commitsBehind
44
+ });
45
+ } else {
46
+ gitSubmoduleInfo.addRow({
47
+ property: 'Branch could not be determined',
48
+ value: ''
49
+ });
50
+ }
51
+
52
+ // Print TDI submodule info
53
+ gitSubmoduleInfo.printTable();
54
+ };
55
+
56
+ const getFileExtractInfo = (sorting) => {
57
+ // version info miscellaneous
58
+ const projects = new Set;
59
+ const types = new Set;
60
+ const versionInfoConfigPath = path.join(_paths.repo, _paths.tdi, 'tct/version/versionInfo.js');
61
+ const versionInfo = new Table({
62
+ columns: [
63
+ {name: 'path', alignment: 'left'},
64
+ {name: 'type', alignment: 'left'},
65
+ {name: 'version', alignment: 'left'},
66
+ {name: 'sort'}
67
+ ],
68
+ disabledColumns: ['sort'],
69
+ sort: (a, b) => a.sort.toLowerCase() > b.sort.toLowerCase() ? 1 : -1
70
+ });
71
+
72
+ if (fs.existsSync(versionInfoConfigPath)) {
73
+ const config = require(versionInfoConfigPath);
74
+
75
+ config.forEach(v => {
76
+ const location = path.join(_paths.repo, v.glob);
77
+
78
+ globby
79
+ .sync(location)
80
+ .forEach(f => {
81
+ const filePathExtract = f.match(/.*(?<path>(cmscustom|site-stylesheets)\/(?<customer>[^/]*)\/(?<project>[^/]*)\/.*)/);
82
+ const path = filePathExtract.groups.path || '';
83
+ const project = filePathExtract.groups.project || '';
84
+
85
+ const fileContent = fs.readFileSync(f).toString();
86
+ v.extracts.forEach(e => {
87
+ const extract = fileContent.match(e.regex);
88
+ if (extract) {
89
+ projects.add(project); // Store the projects where versioninfo is found
90
+ types.add(e.type); // Store the types for which versioninfo is found
91
+ versionInfo.addRow({ // Create row with version information to output
92
+ path,
93
+ sort: `${sorting=='project' ? project : e.type}_2${sorting=='project' ? e.type : extract.groups.version}`, // Output is sorted on project or type: '_2' ensures it is rendered after the empty row and the row with the project name
94
+ type: e.type,
95
+ version: extract.groups.version
96
+ });
97
+ }
98
+ });
99
+ });
100
+ });
101
+
102
+ if (sorting=='project') {
103
+ // For projects containing version information
104
+ projects.forEach(p => {
105
+ versionInfo.addRow({ // Add empty row after project
106
+ path: '',
107
+ sort: `${p}_3`,
108
+ type: '',
109
+ version: ''
110
+ });
111
+ versionInfo.addRow({ // Add row with project name
112
+ path: `-- ${p}:`,
113
+ sort: `${p}_1`,
114
+ type: '',
115
+ version: ''
116
+ }, {
117
+ color: 'yellow'
118
+ });
119
+ });
120
+ }
121
+ else if (sorting=='type') {
122
+ types.forEach(t => {
123
+ versionInfo.addRow({ // Add empty row after type
124
+ path: '',
125
+ sort: `${t}_3`,
126
+ type: '',
127
+ version: ''
128
+ });
129
+ });
130
+ }
131
+ versionInfo.printTable();
132
+ }
133
+ else {
134
+ _warn('Version info of miscellaneous items cannot be extracted:\nCannot find required files in TDI submodule. Try updating TDI submodule.');
135
+ }
136
+ };
137
+
138
+ const getServerInfo = (server) => {
139
+ // Remote server info
140
+ // common setup
141
+ _write();
142
+ c.setServer(server);
143
+
144
+ if (!c.envDev) {
145
+ _info(`Remote version info for '${c.server.ftpConfig.host}':\n`);
146
+ remote.add('sudo ~root/scripts/version.sh', '').process();
147
+ }
148
+ else {
149
+ _info('For development environments no server version information is available. Check rancher / database for this information.\nAdd the --server option with a non-dev environment to see version information for that server.');
150
+ }
151
+ };
152
+
153
+
154
+ module.exports = function info (argv) {
155
+
156
+ if (argv.doctypes) {
157
+ _info('Document type information for this git repository\n');
158
+
159
+ const doctypesInfo = new Table({
160
+ columns: [
161
+ {name: 'id', alignment: 'right'},
162
+ {name: 'name', alignment: 'left'},
163
+ {name: 'paths', alignment: 'left'}
164
+ ],
165
+ });
166
+
167
+ globby
168
+ .sync(_paths.repo + '/database/config/**/txd_document_types.sql')
169
+ .forEach((p, i, a) => {
170
+ fs.readFileSync(p).toString().match(/select([\s\S]+?)from\s+dual/gmi)
171
+ .forEach((dtRow, i, a) => {
172
+ const ntSqlInsert = fs.readFileSync(p.replace('txd_document_types', 'txd_node_types')).toString().match(/select(.*?)from\s+dual/s)[1];
173
+ const id = dtRow.match(/(\d+) id/)?.[1];
174
+ const name = dtRow.match(/'([^']+)' display_name/)?.[1];
175
+ const dbPath = p.match(/(database\/config\/(:?.*)\/)txd_document_types.sql/i)?.[1];
176
+ const prPath = ntSqlInsert.match(/'([^']+)' xsl_prep_inc/)[1].replace('prepare_xincludes.xsl', '');
177
+
178
+ doctypesInfo.addRows([
179
+ {id, name, paths: 'config/cmscustom/'+ prPath},
180
+ {paths: dbPath}
181
+ ]);
182
+
183
+ if (i!==a.length-1) doctypesInfo.addRow({});
184
+ });
185
+
186
+ if (i!==a.length-1) doctypesInfo.addRow({});
187
+ });
188
+
189
+
190
+ doctypesInfo.printTable();
191
+ }
192
+
193
+ if (argv.versions) {
194
+ _info('Version information for this git repository\n');
195
+
196
+ getGitInfo();
197
+ getFileExtractInfo(argv.versions);
198
+ getServerInfo(argv.server);
199
+ }
200
+
201
+ };
@@ -52,7 +52,7 @@ module.exports = function steps (step, dry, filter) {
52
52
  }
53
53
 
54
54
  let filesModCount = 0;
55
- let maxRepeat = 20;
55
+ let maxRepeat = 15;
56
56
  for (let i=0; i<maxRepeat && r.files[0]; i++) { // execute repeatedly for modified files only (with safety limit of 20)
57
57
  r.files = rif.sync(r).filter(f => f.hasChanged).map(f => f.file);
58
58
  if (i===0) filesModCount = r.files.length; // save count only after first run (after this only subsets are processed)
@@ -1,6 +0,0 @@
1
- {
2
- "sonarlint.connectedMode.project": {
3
- "connectionId": "tangelosoftware",
4
- "projectKey": "tangelosoftware_tangelo-configuration-toolkit"
5
- }
6
- }