@tangelo/tangelo-configuration-toolkit 1.11.1 → 1.12.0

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