@tangelo/tangelo-configuration-toolkit 1.10.4 → 1.11.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.
package/index.js CHANGED
@@ -80,7 +80,7 @@ global._git = {
80
80
  user: execGitCommand(`config --get user.email`, _paths.repo),
81
81
  commitLocal: execGitCommand(`log -1 --format=%D;%H;%cd --date=iso-strict`, _paths.repo, ['branch', 'hash', 'date']),
82
82
  commitLocalTdi: {
83
- hash: execGitCommand('rev-parse HEAD', path.join(_paths.repo, _paths.tdi)),
83
+ ...execGitCommand(`log -1 --format=%D;%H;%cd --date=short`, path.join(_paths.repo, _paths.tdi),['tags', 'hash', 'date']),
84
84
  after (commitHash) {
85
85
  return execGitCommand(`merge-base --is-ancestor ${commitHash} ${this.hash}`, path.join(_paths.repo, _paths.tdi), null, 0);
86
86
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangelo/tangelo-configuration-toolkit",
3
- "version": "1.10.4",
3
+ "version": "1.11.0",
4
4
  "description": "Tangelo Configuration Toolkit is a command-line toolkit which offers support for developing a Tangelo configuration.",
5
5
  "bin": {
6
6
  "tct": "bin/index.js",
@@ -21,6 +21,7 @@
21
21
  "@babel/preset-env": "^7.16.11",
22
22
  "cli-spinner": "^0.2.10",
23
23
  "compare-versions": "^4.1.1",
24
+ "console-table-printer": "^2.11.1",
24
25
  "del": "^6.0.0",
25
26
  "event-stream": "^4.0.1",
26
27
  "find-up": "^5.0.0",
package/src/cli.js CHANGED
@@ -92,6 +92,15 @@ module.exports = function cli () {
92
92
  remove: {alias: 'r', desc: 'Remove project configuration', conflicts: ['i', 'c', 'g']}
93
93
  },
94
94
  handler: require('./modules/sql')
95
+ }).command({
96
+ command: 'versions',
97
+ aliases: ['v'],
98
+ desc: 'Show version information',
99
+ builder: {
100
+ find: {alias: 'f', desc: `Find all version information [choices: "sort-project"(default),"sort-type"]`},
101
+ server: {alias: 's', desc: 'Pass server name (set in config file)', default: _appconfig.defaultServer}
102
+ },
103
+ handler: require('./modules/version')
95
104
  })
96
105
  .recommendCommands()
97
106
  .option('config', {alias: 'c', desc: 'Show loaded appconfig', global: false})
@@ -65,8 +65,8 @@ module.exports = {
65
65
  if (ftpConfig.host && !(ftpConfig.port && ftpConfig.parallel && ftpConfig.username)) _error('Config is incomplete!');
66
66
 
67
67
  this.localTransfer = !ftpConfig.host;
68
- this.envDev = /\.dev\.tangelo\.nl$/.test(ftpConfig.host);
69
68
  this.deliveryPack = serverConfig.mode == 'delivery-pack';
69
+ this.envDev = this.localTransfer && !this.deliveryPack || /\.dev\.tangelo\.nl$/.test(ftpConfig.host);
70
70
 
71
71
  if (this.deliveryPack) {
72
72
  const dateStr = new Date().toISOString().replace(/(.*)T(\d+):(\d+):(\d+).*/g, '$1_$2$3$4');
@@ -44,6 +44,7 @@ const remote = {
44
44
  sshI.execCommand(command[0])
45
45
  .then(result => {
46
46
  if (result.stderr) _warn(result.stderr);
47
+ else if (command[1] === '') _write(result.stdout);
47
48
  else _info(command[1] || command[0], true);
48
49
 
49
50
  executing--;
@@ -6,7 +6,7 @@ const path = require('path');
6
6
  module.exports = function migrate (argv) {
7
7
  if (_isPre51) _error('This command only works when using branch release/5.1 and up.');
8
8
 
9
- let filter = path.join(_paths.apply, argv.filter); // Default set filter with filter added to the command argument -f
9
+ let filter = path.join(_paths.apply, argv.filter).toFws(); // Default set filter with filter added to the command argument -f
10
10
 
11
11
  const scripts =
12
12
  globby
@@ -24,10 +24,17 @@ module.exports = function migrate (argv) {
24
24
  value: s
25
25
  }))
26
26
  ;
27
-
27
+
28
+ // Search scriptname set in commandline in scripts and return in cmdlScript if found
29
+ const cmdlScript = Object.values(scripts).filter(s => s.name === `${argv.execute}`)[0];
30
+ if (cmdlScript) {
31
+ _info(`Migration: ${cmdlScript.name}`);
32
+ };
33
+
28
34
  inquirer
29
35
  .prompt([{
30
- message: 'Choose a migration: ', name: 'script', type: 'list', choices: scripts, pageSize: 5, loop: false
36
+ message: 'Choose a migration: ', name: 'script', type: 'list', choices: scripts, pageSize: 5, loop: false,
37
+ when: !(cmdlScript) // Only show choice for migration when no script is set in commandline
31
38
  },{
32
39
  message: 'Choose filter: ', name: 'filter', type: 'list', pageSize: 5, loop: false,
33
40
  choices: [{name: `- All`, value:argv.filter},{name:'- Choose active projects',value:'projects'}],
@@ -41,6 +48,11 @@ module.exports = function migrate (argv) {
41
48
  _write();
42
49
  _info(`Working folder set to: ${_paths.repo}`);
43
50
 
51
+ if (cmdlScript) {
52
+ // Set script to execute to script entered in commandline
53
+ a.script = cmdlScript.value;
54
+ }
55
+
44
56
  if (a.filter === 'projects' && _repoconfig.length > a.projects.length) {
45
57
  // push paths of chosen active documents to projectFolders (only if not all projects are chosen)
46
58
  const projectFolders = [];
@@ -0,0 +1,174 @@
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.info}`.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
+
174
+ };