@tangelo/tangelo-configuration-toolkit 1.8.0-beta.2 → 1.8.0-beta.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/index.js CHANGED
@@ -5,9 +5,10 @@ String.prototype.toFws = function(){
5
5
  };
6
6
 
7
7
 
8
- const findUp = require('find-up');
9
- const fs = require('fs-extra');
10
- const path = require('path');
8
+ const findUp = require('find-up');
9
+ const fs = require('fs-extra');
10
+ const {getPath} = require('global-modules-path');
11
+ const path = require('path');
11
12
 
12
13
  const execGitCommand = require('./src/lib/exec-git-command');
13
14
 
@@ -56,8 +57,12 @@ _paths.repoconfig = path.join(_paths.repo, appname+'-repoconfig.json');
56
57
  _paths.apply = process.cwd().replace(_paths.repo, '').substr(1);
57
58
 
58
59
 
59
- global._package = require('./package.json');
60
- global._appdata = fs.readJsonSync(_paths.appdata, {throws: false}) || {versionLastChecked: 0, versionIsLatest: true};
60
+ global._appdata = fs.readJsonSync(_paths.appdata, {throws: false}) || {};
61
+ global._packages = {
62
+ TCT: {name: '@tangelo/tangelo-configuration-toolkit', version: require('./package.json')?.version},
63
+ FDT: {name: '@fontoxml/fontoxml-development-tools'}
64
+ }
65
+ _packages.FDT.version = require(`${getPath(_packages.FDT.name)}/package.json`)?.version;
61
66
 
62
67
  try { global._appconfig = _paths.appconfig && fs.readJsonSync(_paths.appconfig) || {}; }
63
68
  catch({message}) { _error('Error in '+message); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangelo/tangelo-configuration-toolkit",
3
- "version": "1.8.0-beta.2",
3
+ "version": "1.8.0-beta.3",
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",
@@ -25,6 +25,7 @@
25
25
  "event-stream": "^4.0.1",
26
26
  "find-up": "^5.0.0",
27
27
  "fs-extra": "^10.0.0",
28
+ "global-modules-path": "^2.3.1",
28
29
  "globby": "^6.1.0",
29
30
  "gulp": "^4.0.2",
30
31
  "gulp-babel": "^7.0.1",
package/src/cli.js CHANGED
@@ -1,13 +1,31 @@
1
+ const {compare} = require('compare-versions');
2
+ const exec = require('util').promisify(require('child_process').exec);
1
3
  const fs = require('fs-extra');
2
4
  const yargs = require('yargs');
3
- const {getCurrentPackageVersion, getLatestPackageVersion, updatePackage} = require('./lib/npm-package-update');
5
+
6
+
7
+ const updateAppdata = (data) => Object.assign(_appdata, data, {_changed: true});
8
+
9
+ const checkForPackageUpdate = (package) => (
10
+ exec(`npm view -g ${_packages[package].name} version`)
11
+ .then(r => {
12
+ const versionAvailable = r.stdout.match(/([\d/.]+)/)[1];
13
+ if (compare(_packages[package].version, versionAvailable, '<')) {
14
+ updateAppdata({[`updateCheck${package}`]: {executed: new Date(), versionAvailable}});
15
+ return versionAvailable;
16
+ }
17
+ else updateAppdata({[`updateCheck${package}`]: {executed: new Date()}});
18
+ })
19
+ .catch(e => _warn(`Failed checking latest version of ${package}.`))
20
+ );
21
+
4
22
 
5
23
  module.exports = function cli () {
6
24
 
7
25
  _write();
8
26
 
9
27
  const txtTitle = 'Tangelo Configuration Toolkit'.bold.underline.cyan;
10
- const txtVersion = `v${_package.version}${_appdata.versionIsLatest ? '' : ' (new version available)'}`.lblack;
28
+ const txtVersion = `v${_packages.TCT.version}`.lblack;
11
29
 
12
30
  const {argv} = yargs
13
31
  .scriptName('tct')
@@ -95,8 +113,6 @@ module.exports = function cli () {
95
113
  })
96
114
  .recommendCommands()
97
115
  .option('config', {alias: 'c', desc: 'Show loaded appconfig', global: false})
98
- .option('update', {alias: 'u', desc: 'Update this package', global: false})
99
- .option('update-fdt', {alias: 'uf', desc: 'Update the FDT package', global: false})
100
116
  .version(false)
101
117
  .help(false)
102
118
  .example([
@@ -123,53 +139,36 @@ module.exports = function cli () {
123
139
  _write(_appconfig);
124
140
  }
125
141
 
126
- if (argv.update) {
127
- _info('Updating TCT...');
128
- getLatestPackageVersion({package: 'TCT', version: _package.version})
129
- .then(updatePackage)
130
- ;
131
- }
132
-
133
- if (argv.updateFdt) {
134
- _info('Updating FDT...');
135
- getCurrentPackageVersion({package: 'FDT'})
136
- .then(getLatestPackageVersion)
137
- .then(updatePackage)
138
- ;
139
- }
140
-
141
142
  }
142
143
 
143
144
 
144
145
  let checkUpdatesDone = false;
145
146
 
146
147
  process.on('beforeExit', () => {
147
-
148
- if (_appdata._changed) {
149
- delete _appdata._changed;
150
- fs.writeJsonSync(_paths.appdata, _appdata, {spaces: 2});
151
- }
152
-
153
148
  _write(); // print empty line before and after update check
154
149
 
155
- if (!(argv.update || argv.updateFdt) && // not when doing update
156
- (!_appdata.updateCheckTCT?.versionAvailable || !_appdata.updateCheckFDT?.versionAvailable) && // not if already known that update is available
157
- ( new Date() - new Date(_appdata.updateCheckTCT?.executed || 0) > 1000*3600*24*3 ||
158
- new Date() - new Date(_appdata.updateCheckFDT?.executed || 0) > 1000*3600*24*3
159
- ) && // check every 3 days
160
- !checkUpdatesDone // check if updatecheck has ran before because async calls below trigger beforeExit again
161
- ) {
150
+ if (!checkUpdatesDone) { // check if updatecheck has ran before because async calls below trigger beforeExit again
162
151
  checkUpdatesDone = true;
163
- _info('Checking for updates...');
164
152
 
165
- // check tct version
166
- getLatestPackageVersion({package: 'TCT', version: _package.version});
153
+ ['TCT', 'FDT'].forEach(p => {
154
+ const updateMsg = (va) => `| Update ${p} to ${va} | ` + `npm i -g ${_packages[p].name}`.white;
155
+ const {versionAvailable} = _appdata[`updateCheck${p}`] || {};
156
+
157
+ if (new Date() - new Date(_appdata[`updateCheck${p}`]?.executed || 0) > 1000*3600*24*7) { // check every week
158
+ checkForPackageUpdate(p).then(r => r && _warn(updateMsg(r)));
159
+ }
160
+ else if (versionAvailable) {
161
+ if (compare(_packages[p].version, versionAvailable, '<')) _warn(updateMsg(versionAvailable));
162
+ else updateAppdata({[`updateCheck${p}`]: {executed: new Date()}});
163
+ }
164
+ });
165
+ }
167
166
 
168
- // check fdt version
169
- getCurrentPackageVersion({package: 'FDT'})
170
- .then(getLatestPackageVersion)
171
- ;
167
+ if (_appdata._changed) {
168
+ delete _appdata._changed;
169
+ fs.writeJsonSync(_paths.appdata, _appdata, {spaces: 2});
172
170
  }
171
+
173
172
  });
174
173
 
175
174
  }
@@ -1,51 +0,0 @@
1
- const {compare} = require('compare-versions');
2
- const util = require('util');
3
- const exec = util.promisify(require('child_process').exec);
4
-
5
-
6
- const packageNames = {
7
- TCT: '@tangelo/tangelo-configuration-toolkit',
8
- FDT: '@fontoxml/fontoxml-development-tools'
9
- };
10
-
11
- const updateAppdata = (data) => Object.assign(_appdata, data, {_changed: true});
12
-
13
- const getCurrentPackageVersion = ({package}) => (
14
- exec(`npm list -g ${packageNames[package]}`)
15
- .then(r => ({package, version: r.stdout.match(/@([\d/.]+)/)[1]}))
16
- .catch(e => _warn(`Failed checking current version of ${package}.`))
17
- );
18
-
19
- const getLatestPackageVersion = ({package, version}) => (
20
- exec(`npm view -g ${packageNames[package]} version`)
21
- .then(r => {
22
- const versionAvailable = r.stdout.match(/([\d/.]+)/)[1];
23
- if (compare(version, versionAvailable, '>=')) {
24
- updateAppdata({[`updateCheck${package}`]: {executed: new Date()}});
25
- _write(`Using latest version of ${package}.`);
26
- }
27
- else {
28
- updateAppdata({[`updateCheck${package}`]: {executed: new Date(), versionAvailable}});
29
- _write(`New version of ${package} available!`);
30
- }
31
- return {package, version, versionAvailable};
32
- })
33
- .catch(e => _warn(`Failed checking latest version of ${package}.`))
34
- );
35
-
36
- const updatePackage = ({package, version, versionAvailable}) => (
37
- compare(version, versionAvailable, '<') &&
38
- exec(`npm install -g ${packageNames[package]}`)
39
- .then(r => {
40
- updateAppdata({[`updateCheck${package}`]: {executed: new Date()}});
41
- _write(`Updated ${package} to version ${versionAvailable}.`);
42
- })
43
- .catch(e => _warn(`Failed updating latest version of ${package}.`))
44
- );
45
-
46
-
47
- module.exports = {
48
- getCurrentPackageVersion,
49
- getLatestPackageVersion,
50
- updatePackage
51
- };