@tangelo/tangelo-configuration-toolkit 1.14.3 → 1.14.4

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.
@@ -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 (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);
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, newXprFile) => {
17
+ _info('Initializing xpr file(s):');
18
+ const xprFiles = [...globby.sync(`*.xpr`)];
19
+ // Add newXprFile at the start of xprFiles if it does not already exists:
20
+ if (newXprFile && xprFiles.indexOf(newXprFile)===-1) xprFiles.unshift(newXprFile);
21
+
22
+ // Copy xpr file from TDI if it does not exists yet;
23
+ if (xprFiles[0] && !newXprFile) _write(`Found: ${xprFiles.join(', ')}`);
24
+ else {
25
+ if (!newXprFile) {
26
+ // Set xpr filename to customer name (assumes correct upsert scripts structure)
27
+ const customers = new Set;
28
+ _repoconfig.forEach(p => customers.add(p.customer_name));
29
+ xprFiles.push(convertToValidFilename([...customers].join(' - ')) + '.xpr');
30
+ }
31
+ // Copy new xpr file
32
+ fs.copySync(path.join(_paths.repo, 'tangelo-default-implementation/src/[customer].xpr'), path.join(_paths.repo, xprFiles[0]));
33
+ _write(`Created: '${xprFiles[0]}'`);
34
+ }
35
+
36
+ // Search for transformationScenarios/masterfiles based on TDI submodule oxygenProjectFile config
37
+ _info('\nSearching for transformationScenarios/masterfiles');
38
+ config.oxygenProjectFile.forEach(
39
+ pf => {
40
+ // Collect transformation scenarios and add them to the transformationScenarios array; add individual stylesheets to the masterFiles set.
41
+ if (pf.transformation) getTransformations(pf.transformation);
42
+ // Add files to the masterfiles set.
43
+ else if (pf.masterfile) getMasterfiles(pf.masterfile);
44
+ }
45
+ );
46
+
47
+ // update all .xpr files with collected transformation scenarios and masterfiles.
48
+ transformXprFile(xprFiles);
49
+ };
50
+
51
+ const getTransformations = config => {
52
+ _repoconfig.forEach(rc => {
53
+ // get pathname of customer/project
54
+ const [customerPath, projectPath] = config.location === 'database' ? rc.path_dbconfig : rc.path_cmscustom;
55
+
56
+ // set pathname of customer/project in location glob-expression
57
+ const location = path.join(
58
+ _paths.repo,
59
+ config.files.replace(/\[customer\]/, customerPath).replace(/\[project\]/, projectPath)
60
+ );
61
+
62
+ globby
63
+ .sync(`${location}`)
64
+ .forEach(f => {
65
+ // extract baseStrings from file
66
+ const fileString = fs.readFileSync(f).toString();
67
+ const baseStrings = fileString.match(RegExp(config.extracts.base, 'gm'));
68
+
69
+ if (fileString.replace(/\s|^prompt\s.*$/gm, '') !== '') {
70
+ if (baseStrings) {
71
+ baseStrings.forEach(s => {
72
+ // extract type, name, files info from baseString
73
+ const type = config.extracts.type ? s.match(RegExp(config.extracts.type))[1] : config.values.type;
74
+ const name = config.extracts.name ? s.match(RegExp(config.extracts.name))[1] : config.values.name;
75
+ const files = s.match(RegExp(config.extracts.files))[1];
76
+
77
+ // Add transformation scenario to the transformationScenario array
78
+ transformationScenarios.push({
79
+ 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.
80
+ transformationScenario: files,
81
+ location: config.location === 'txp' ? siteStylesheetsPath : cmscustomPath
82
+ });
83
+
84
+ // Add each non-tdi stylesheet in transformation scenario to the masterFiles set
85
+ files.split(',').forEach(f => {
86
+ const filePath = `${config.location === 'txp' ? siteStylesheetsPath : cmscustomPath}${f}`;
87
+ if (!f.startsWith('tdi')) masterFiles.add(filePath);
88
+ });
89
+ });
90
+ } else {
91
+ _write(`No transformation scenarios found in ${f} for '${config.extracts.base}'`);
92
+ }
93
+ }
94
+ });
95
+ });
96
+
97
+ };
98
+
99
+
100
+ const getMasterfiles = config => {
101
+ globby
102
+ .sync(`${path.join(_paths.repo, config.files)}`)
103
+ .forEach(cf => {
104
+ // Check if masterfile should be extracted from file
105
+ const fileString = fs.readFileSync(cf).toString();
106
+ if (fileString.replace(/\s|^prompt\s.*$/gm, '')!=='') {
107
+ if (config.extracts) {
108
+ // extract baseStrings from file
109
+ const baseStrings = fileString.match(RegExp(config.extracts.base, 'gm'));
110
+
111
+ if (baseStrings) {
112
+ baseStrings.forEach(s => {
113
+ // extract (comma-separated) list of masterfiles
114
+ const filesString = s.match(RegExp(config.extracts.files))[1];
115
+ if (!filesString) _error(`No masterfiles found in '${s}' for '${config.extracts.files}'`);
116
+
117
+ // Add each non-tdi masterfile to the masterFiles set
118
+ filesString.split(',').forEach(f => {
119
+ if (!f.startsWith('tdi')){
120
+ const filePath = `${config.location === 'txp' ? siteStylesheetsPath : cmscustomPath}${f}`;
121
+ masterFiles.add(filePath);
122
+ }
123
+ });
124
+ });
125
+ } else {
126
+ _write(`No masterfiles found in ${cf} for '${config.extracts.base}'`);
127
+ }
128
+ } else { // Add synced file to masterfiles; strip path from c:/... hence it starts with config/cmscustom or config/txp/site-stylesheets
129
+ const filePath = config.location === 'txp' ? `${siteStylesheetsPath}${cf.split(siteStylesheetsPath)[1]}` : `${cmscustomPath}${cf.split(cmscustomPath)[1]}`;
130
+ masterFiles.add(filePath);
131
+ }
132
+ }
133
+ });
134
+
135
+ };
136
+
137
+ const transformXprFile = xprFiles => {
138
+ _info('\nUpdating xpr file(s):');
139
+ // create with: xslt3 -t -xsl:createProjectFile.xsl -export:createProjectFile.sef.json v -nogo'
140
+
141
+ xprFiles
142
+ .forEach(xprFile => {
143
+ // Transform xpr; add masterfiles and transformationScenarios as parameters of the stylesheet
144
+ _write(`${xprFile}\n`);
145
+ SaxonJS.transform({
146
+ stylesheetText: fs.readFileSync(sefFilePath),
147
+ stylesheetBaseURI: 'createProjectFile.sef.json',
148
+ sourceFileName: path.join(_paths.repo, xprFile),
149
+ destination: 'serialized',
150
+ stylesheetParams: {
151
+ 'masterfiles': [...masterFiles],
152
+ 'Q{}transformationScenarios': transformationScenarios
153
+ }
154
+ }, 'async')
155
+ .then(output => {
156
+ // Write result of transformation to xpr file
157
+ fs.writeFileSync(path.join(_paths.repo, xprFile), output.principalResult);
158
+ })
159
+ .catch(e => _warn(`Failed to update: ${xprFile}\n ${e}`));
160
+ });
161
+ };
162
+
163
+
164
+ module.exports = function oxygen (arg) {
165
+ // Set projects transformation scenarios and masterfiles in oXygen project file
166
+ // - Will try to preserve manually added entries in the transformation scenarios and masterfiles
167
+ // - Will remove non existing masterfiles or masterfiles that start with a '_'
168
+
169
+ if (!fs.existsSync(spConfigPath) || !fs.existsSync(sefFilePath)) {
170
+ _error(`Cannot find required files in TDI submodule. Try updating TDI submodule.`);
171
+ }
172
+
173
+ const newXprFile = (typeof arg === 'string') ? convertToValidFilename(arg) + '.xpr' : null;
174
+ createProjectFile(require(spConfigPath), newXprFile);
175
175
  };
@@ -56,8 +56,8 @@ module.exports = {
56
56
  resolve();
57
57
  });
58
58
  })
59
- .then(() => cmdExec(`${fdt} editor upgrade --version ${fontoVersion} --non-interactive`))
60
- .then(() => [fdt])
59
+ .then(() => cmdExec(`${fdt} editor upgrade --version ${fontoVersion} --non-interactive`))
60
+ .then(() => [fdt])
61
61
  ;
62
62
  },
63
63
 
@@ -154,7 +154,7 @@ module.exports = {
154
154
  else _write(result, '\n');
155
155
  }
156
156
  )
157
- .then(() => [fdt])
157
+ .then(() => [fdt])
158
158
  ;
159
159
  },
160
160
 
@@ -205,7 +205,7 @@ module.exports = {
205
205
  else _write(result, '\n');
206
206
  }
207
207
  )
208
- .then(() => [fdt])
208
+ .then(() => [fdt])
209
209
  ;
210
210
  },
211
211
 
@@ -31,7 +31,7 @@ module.exports = function fonto (argv) {
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
33
  .map(p => ([p.replace('manifest.json', ''), fs.readJsonSync(p).sdkVersion.replace(/Nightlies.*/, 'nightly')])
34
- );
34
+ );
35
35
 
36
36
  if (fontoPaths.length===0) _error('No Fonto instance found.');
37
37
 
@@ -61,13 +61,13 @@ module.exports = function fonto (argv) {
61
61
  _write(fontoVersionNew+'\n');
62
62
  return resolve([fdtCommand(fontoVersionNew), fontoVersionNew]);
63
63
  })
64
- .then(argv.init && commands.init)
65
- .then(argv.schema && commands.schema)
66
- .then(argv.elements && commands.elements)
67
- .then(argv.attributes && commands.attributes)
68
- .then(argv.localize && commands.localize)
69
- .then(argv.build && commands.build)
70
- .then(argv.run && commands.run)
64
+ .then(argv.init && commands.init)
65
+ .then(argv.schema && commands.schema)
66
+ .then(argv.elements && commands.elements)
67
+ .then(argv.attributes && commands.attributes)
68
+ .then(argv.localize && commands.localize)
69
+ .then(argv.build && commands.build)
70
+ .then(argv.run && commands.run)
71
71
  ;
72
72
  });
73
73
  });
@@ -146,7 +146,7 @@ module.exports = function git (argv) {
146
146
  if (fs.existsSync(tdiMigrationFilePath)) {
147
147
  const migrations = require(tdiMigrationFilePath);
148
148
  const fromTdiDate = tdiFromDateCustom ? new Date(tdiFromDateCustom) : (tdiBranch.commonAncestor) ? tdiBranch.commonAncestor.date: _git.commitTdi.local().date;
149
- const toTdiDate = tdiToDateCustom ? new Date(tdiToDateCustom) : new Date(execGitCommand(`log -1 --format=%cd --date=iso-strict`, path.join(_paths.repo, _paths.tdi), ['date']).date);
149
+ const toTdiDate = tdiToDateCustom ? new Date(tdiToDateCustom) : new Date();
150
150
 
151
151
  _info(`TDI commits requiring migration between ${_formatDate(fromTdiDate)} and ${_formatDate(toTdiDate)}`);
152
152
  // Filter the migrations that should be applied/considered; Also display older releases migrations