@tangelo/tangelo-configuration-toolkit 1.11.2 → 1.12.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.
@@ -1,174 +1,158 @@
1
- const {execSync} = require('child_process');
2
- const fs = require('fs-extra');
3
- const globby = require('globby');
4
- const path = require('path');
5
- const {Table} = require('console-table-printer');
6
- const execGitCommand = require('../../lib/exec-git-command');
7
- const c = require('../deploy/config');
8
- const {remote} = require('../deploy/execute');
9
-
10
- const getGitInfo = (argv) => {
11
- // Version info TDI submodule
12
-
13
- const branchInfo = [];
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
- execGitCommand(`fetch -pf --all`, path.join(_paths.repo, _paths.tdi));
23
-
24
- // Get branches containing TDI HEAD commit
25
- const releaseBranches = execGitCommand(`branch --all --contains ${_git.commitLocalTdi.hash}`, path.join(_paths.repo, _paths.tdi)).match(/release\/[^\s]+/gsm);
26
- if (releaseBranches) {
27
- releaseBranches.forEach(b => {
28
- // Get number of commits behind
29
- const count = execGitCommand(`rev-list HEAD...origin/${b} --count`, path.join(_paths.repo, _paths.tdi));
30
- // _info(`debug: [${b}]:${count}`);
31
- // Push number of commits behind to branchInfo
32
- branchInfo.push({name:b,commitsBehind:count});
33
- });
34
- }
35
-
36
- // Get the first possible branch; prefer release/5.1 over release/5.2:
37
- const firstBranch = branchInfo.sort((a, b) => a.name > b.name ? 1 : -1)[0];
38
-
39
- // Create table rows for TDI submodule info
40
- gitSubmoduleInfo.addRow({
41
- property: `Commit date`,
42
- value: `${_git.commitLocalTdi.date.toLocaleDateString(`en-gb`,{day:'numeric',month:'short',year:'numeric',hour:'2-digit',minute:'2-digit'})}`
43
- });
44
- if (firstBranch) {
45
- gitSubmoduleInfo.addRow({
46
- property: `Branch`,
47
- value: `${firstBranch.name}`
48
- });
49
- gitSubmoduleInfo.addRow({
50
- property: `Commits behind`,
51
- value: `${firstBranch.commitsBehind}`
52
- });
53
- } else {
54
- gitSubmoduleInfo.addRow({
55
- property: `Branch could not be determined`,
56
- value: ``
57
- });
58
- }
59
-
60
- // Print TDI submodule info
61
- gitSubmoduleInfo.printTable();
62
- }
63
-
64
- const getFileExtractInfo = (argv) => {
65
- // version info miscellaneous
66
- const sorting = `${argv.find}`.includes(`sort-type`) ? `type` : `project`;
67
- const projects = new Set;
68
- const types = new Set;
69
- const versionInfoConfigPath = path.join(_paths.repo, _paths.tdi, 'tct/version/versionInfo.js');
70
- const versionInfo = new Table({
71
- columns: [
72
- { name: 'path', alignment: 'left'},
73
- { name: 'type', alignment: 'left'},
74
- { name: 'version', alignment: 'left'},
75
- { name: 'sort'}
76
- ],
77
- disabledColumns: ['sort'],
78
- sort: (a, b) => a.sort.toLowerCase() > b.sort.toLowerCase() ? 1 : -1
79
- });
80
-
81
- if (fs.existsSync(versionInfoConfigPath)) {
82
- const config = require(`${versionInfoConfigPath}`);
83
-
84
- config.forEach(v => {
85
- const location = path.join(_paths.repo,v.glob);
86
-
87
- globby
88
- .sync(`${location}`)
89
- .forEach(f => {
90
- const filePathExtract = f.match(/.*(?<path>(cmscustom|site-stylesheets)\/(?<customer>[^\/]*)\/(?<project>[^\/]*)\/.*)/);
91
- const path = filePathExtract.groups.path ? filePathExtract.groups.path : '';
92
- const customer = filePathExtract.groups.customer ? filePathExtract.groups.customer : '';
93
- const project = filePathExtract.groups.project ? filePathExtract.groups.project : '';
94
-
95
- const fileContent = fs.readFileSync(f).toString();
96
- v.extracts.forEach(e => {
97
- const extract = fileContent.match(e.regex);
98
- if (extract) {
99
- projects.add(project); // Store the projects where versioninfo is found
100
- types.add(e.type); // Store the types for which versioninfo is found
101
- versionInfo.addRow( // Create row with version information to output
102
- { path: `${path}`
103
- , 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
104
- , type: `${e.type}`
105
- , version: `${extract.groups.version}`
106
- }
107
- );
108
- }
109
- });
110
- })
111
- });
112
-
113
- if (sorting==`project`) {
114
- /* For projects containing version information */
115
- projects.forEach(p => {
116
- /* Add empty row after project */
117
- versionInfo.addRow(
118
- { path: ``
119
- , sort: `${p}_3`
120
- , type: ``
121
- , version: ``
122
- }
123
- )
124
- /* Add row with project name */
125
- versionInfo.addRow(
126
- { path: `-- ${p}:`
127
- , sort: `${p}_1`
128
- , type: ``
129
- , version: ``
130
- },
131
- { color: 'yellow' }
132
- )
133
- });
134
- } else
135
- if (sorting==`type`) {
136
- types.forEach(t => {
137
- /* Add empty row after type */
138
- versionInfo.addRow(
139
- { path: ``
140
- , sort: `${t}_3`
141
- , type: ``
142
- , version: ``
143
- }
144
- )
145
- });
146
- }
147
- versionInfo.printTable();
148
- } else {
149
- _warn(`Version info of miscellaneous items cannot be extracted:\nCannot find required files in TDI submodule. Try updating TDI submodule.`);
150
- }
151
- }
152
-
153
- const getServerInfo = (argv) => {
154
- // Remote server info
155
- // common setup
156
- _write();
157
- c.setServer(argv.server);
158
-
159
- if (!c.envDev) {
160
- _info(`Remote version info for '${c.server.ftpConfig.host}':\n`)
161
- remote.add('sudo ~root/scripts/version.sh', '').process();
162
- } else {
163
- _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.`);
164
- }
165
- }
166
-
167
- module.exports = function version (argv) {
168
- _info(`Version information of this git repository\n`)
169
-
170
- getGitInfo(argv);
171
- getFileExtractInfo(argv);
172
- getServerInfo(argv);
173
-
1
+ const fs = require('fs-extra');
2
+ const globby = require('globby');
3
+ const path = require('path');
4
+ const {Table} = require('console-table-printer');
5
+ const execGitCommand = require('../../lib/exec-git-command');
6
+ const c = require('../deploy/config');
7
+ const {remote} = require('../deploy/execute');
8
+
9
+ const getGitInfo = () => {
10
+ // Version info TDI submodule
11
+ const gitSubmoduleInfo = new Table({
12
+ columns: [
13
+ {name: 'property', title: 'TDI - submodule', alignment: 'left'},
14
+ {name: 'value', alignment: 'left'}
15
+ ],
16
+ });
17
+
18
+ // Fetch all
19
+ execGitCommand('fetch -pf --all', path.join(_paths.repo, _paths.tdi));
20
+
21
+ // Get branches containing TDI HEAD commit
22
+ const releaseBranches = execGitCommand(`branch --all --contains ${_git.commitTdi.local().hash}`, path.join(_paths.repo, _paths.tdi)).match(/release\/[^\s]+/gsm);
23
+ if (!releaseBranches) _error('Could not retrieve TDI release branches');
24
+ // Get the first possible branch; prefer release/5.1 over release/5.2:
25
+ releaseBranches.sort((a, b) => a.name > b.name ? 1 : -1);
26
+ const firstBranch = {name: releaseBranches[0]};
27
+ // Get number of commits behind
28
+ firstBranch.commitsBehind = execGitCommand(`rev-list HEAD...origin/${firstBranch.name} --count`, path.join(_paths.repo, _paths.tdi));
29
+
30
+ // Create table rows for TDI submodule info
31
+ gitSubmoduleInfo.addRow({
32
+ property: 'Commit date',
33
+ value: _git.commitTdi.local().date.toLocaleDateString('en-gb', {day: 'numeric', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit'})
34
+ });
35
+ if (firstBranch) {
36
+ gitSubmoduleInfo.addRow({
37
+ property: 'Branch',
38
+ value: firstBranch.name
39
+ });
40
+ gitSubmoduleInfo.addRow({
41
+ property: 'Commits behind',
42
+ value: firstBranch.commitsBehind
43
+ });
44
+ } else {
45
+ gitSubmoduleInfo.addRow({
46
+ property: 'Branch could not be determined',
47
+ value: ''
48
+ });
49
+ }
50
+
51
+ // Print TDI submodule info
52
+ gitSubmoduleInfo.printTable();
53
+ };
54
+
55
+ const getFileExtractInfo = (argv) => {
56
+ // version info miscellaneous
57
+ const sorting = argv.find.toString().includes('sort-type') ? 'type' : 'project';
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
+ } else
121
+ 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
+ } else {
133
+ _warn('Version info of miscellaneous items cannot be extracted:\nCannot find required files in TDI submodule. Try updating TDI submodule.');
134
+ }
135
+ };
136
+
137
+ const getServerInfo = (argv) => {
138
+ // Remote server info
139
+ // common setup
140
+ _write();
141
+ c.setServer(argv.server);
142
+
143
+ if (!c.envDev) {
144
+ _info(`Remote version info for '${c.server.ftpConfig.host}':\n`);
145
+ remote.add('sudo ~root/scripts/version.sh', '').process();
146
+ } else {
147
+ _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.');
148
+ }
149
+ };
150
+
151
+ module.exports = function version (argv) {
152
+ _info('Version information of this git repository\n');
153
+
154
+ getGitInfo(argv);
155
+ getFileExtractInfo(argv);
156
+ getServerInfo(argv);
157
+
174
158
  };
@@ -1,7 +0,0 @@
1
- {
2
- "folders": [
3
- {
4
- "path": "."
5
- }
6
- ]
7
- }