@tangelo/tangelo-configuration-toolkit 1.8.0-beta.2 → 1.8.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 = fs.readJsonSync(`${getPath(_packages.FDT.name)}/package.json`, {throws: false})?.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.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",
@@ -33,17 +34,17 @@
33
34
  "gulp-plumber": "^1.2.1",
34
35
  "gulp-print": "^5.0.2",
35
36
  "gulp-sass": "^5.0.0",
36
- "gulp-simple-rename": "^0.1.3",
37
37
  "gulp-sourcemaps": "^3.0.0",
38
38
  "inquirer": "^8.2.0",
39
39
  "istextorbinary": "^6.0.0",
40
40
  "minimatch": "^3.0.4",
41
41
  "node-ssh": "^12.0.2",
42
42
  "object-assign-deep": "^0.4.0",
43
- "replace-in-file": "^6.0.0",
44
- "sass": "^1.43.4",
43
+ "replace-in-file": "^3.4.4",
44
+ "sass": "^1.43.5",
45
45
  "saxon-js": "^2.3.0",
46
46
  "scp2": "^0.5.0",
47
+ "through2": "^4.0.2",
47
48
  "tiny-lr": "^2.0.0",
48
49
  "yargs": "^16.2.0"
49
50
  },
package/src/cli.js CHANGED
@@ -1,13 +1,32 @@
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 (!_packages[package].version) _warn(`${package} is not installed! Run ` + `npm i -g ${_packages[package].name}`.white);
14
+ else if (compare(_packages[package].version, versionAvailable, '<')) {
15
+ updateAppdata({[`updateCheck${package}`]: {executed: new Date(), versionAvailable}});
16
+ return versionAvailable;
17
+ }
18
+ else updateAppdata({[`updateCheck${package}`]: {executed: new Date()}});
19
+ })
20
+ .catch(e => _warn(`Failed checking latest version of ${package}.`))
21
+ );
22
+
4
23
 
5
24
  module.exports = function cli () {
6
25
 
7
26
  _write();
8
27
 
9
28
  const txtTitle = 'Tangelo Configuration Toolkit'.bold.underline.cyan;
10
- const txtVersion = `v${_package.version}${_appdata.versionIsLatest ? '' : ' (new version available)'}`.lblack;
29
+ const txtVersion = `v${_packages.TCT.version}`.lblack;
11
30
 
12
31
  const {argv} = yargs
13
32
  .scriptName('tct')
@@ -95,8 +114,6 @@ module.exports = function cli () {
95
114
  })
96
115
  .recommendCommands()
97
116
  .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
117
  .version(false)
101
118
  .help(false)
102
119
  .example([
@@ -123,53 +140,36 @@ module.exports = function cli () {
123
140
  _write(_appconfig);
124
141
  }
125
142
 
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
143
  }
142
144
 
143
145
 
144
146
  let checkUpdatesDone = false;
145
147
 
146
148
  process.on('beforeExit', () => {
147
-
148
- if (_appdata._changed) {
149
- delete _appdata._changed;
150
- fs.writeJsonSync(_paths.appdata, _appdata, {spaces: 2});
151
- }
152
-
153
149
  _write(); // print empty line before and after update check
154
150
 
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
- ) {
151
+ if (!checkUpdatesDone) { // check if updatecheck has ran before because async calls below trigger beforeExit again
162
152
  checkUpdatesDone = true;
163
- _info('Checking for updates...');
164
153
 
165
- // check tct version
166
- getLatestPackageVersion({package: 'TCT', version: _package.version});
154
+ ['TCT', 'FDT'].forEach(p => {
155
+ const updateMsg = (va) => `| Update ${p} to ${va} | ` + `npm i -g ${_packages[p].name}`.white;
156
+ const {versionAvailable} = _appdata[`updateCheck${p}`] || {};
157
+
158
+ if (new Date() - new Date(_appdata[`updateCheck${p}`]?.executed || 0) > 1000*3600*24*7) { // check every week
159
+ checkForPackageUpdate(p).then(r => r && _warn(updateMsg(r)));
160
+ }
161
+ else if (versionAvailable) {
162
+ if (compare(_packages[p].version, versionAvailable, '<')) _warn(updateMsg(versionAvailable));
163
+ else updateAppdata({[`updateCheck${p}`]: {executed: new Date()}});
164
+ }
165
+ });
166
+ }
167
167
 
168
- // check fdt version
169
- getCurrentPackageVersion({package: 'FDT'})
170
- .then(getLatestPackageVersion)
171
- ;
168
+ if (_appdata._changed) {
169
+ delete _appdata._changed;
170
+ fs.writeJsonSync(_paths.appdata, _appdata, {spaces: 2});
172
171
  }
172
+
173
173
  });
174
174
 
175
175
  }
@@ -0,0 +1,11 @@
1
+ // replacement for the official (but deprecated) gulp-simple-rename
2
+ // kept same name because of usage in tdi
3
+
4
+ const through2 = require('through2');
5
+
6
+ module.exports = (fn) => {
7
+ return through2.obj((file, enc, cb) => {
8
+ file.path = fn(file.path);
9
+ cb(null, file);
10
+ });
11
+ };
@@ -2,17 +2,15 @@ const fs = require('fs-extra');
2
2
  const globby = require('globby');
3
3
  const gulp = require('gulp');
4
4
  const {NodeSSH} = require('node-ssh');
5
- const path = require('path');
6
5
  const through2 = require('through2');
7
6
  const {spawnSync} = require('child_process');
8
7
 
9
- const g_babel = require('gulp-babel');
10
8
  const g_babel_env = require('babel-preset-es2015-without-strict');
9
+ const g_babel = require('gulp-babel');
11
10
  const g_eol = require('gulp-eol');
12
11
  const g_filter = require('gulp-filter');
13
12
  const g_plumber = require('gulp-plumber');
14
13
  const g_print = require('gulp-print');
15
- const g_rename = require('gulp-simple-rename');
16
14
  const g_replace = require('../../lib/gulp-batch-replace-with-filter');
17
15
  const g_resolveIncl = require('../../lib/gulp-resolve-includes');
18
16
  const g_sass = require('gulp-sass')(require('sass'));
@@ -157,7 +155,7 @@ const transfer = (paths, lrServer) => {
157
155
  .pipe(xpsF.restore)
158
156
  .pipe(jsF)
159
157
  .pipe(g_sourcemaps.init())
160
- .pipe(g_babel({ presets: [g_babel_env], comments: false, minified: true }))
158
+ .pipe(g_babel({presets: [g_babel_env], comments: false, minified: true}))
161
159
  .pipe(g_sourcemaps.write('.'))
162
160
  .pipe(jsF.restore)
163
161
  .pipe(sassF)
@@ -170,8 +168,8 @@ const transfer = (paths, lrServer) => {
170
168
  .pipe(shF.restore)
171
169
  .pipe(g_plumber.stop())
172
170
  .pipe(g_replace(c.replaceStrings))
173
- .pipe(g_rename(path => path.replace(/fonto[\\\/]dist/, 'fonto').replace(/(fonto[\\\/]).+(assets[\\\/]schemas)/, '$1$2'))) // change destination path for fonto build and schemas
174
171
  .pipe(through2.obj((file, enc, cb) => {
172
+ file.path = file.path.replace(/(fonto)(?:[\\\/]dist|.+([\\\/]assets[\\\/]schemas))/, '$1$2'); // change destination path for fonto build and schemas
175
173
  if (!file.relative.endsWith('.map')) files.push(file.relative); // collect all file paths in array for livereload
176
174
  cb(null, file);
177
175
  }))
@@ -37,9 +37,12 @@ module.exports = function git (argv) {
37
37
 
38
38
  if (argv.hasOwnProperty('init')) {
39
39
  const remoteTdiUrl = `${_paths.gitremote}/${_paths.tdi}.git`;
40
- const branches =
41
- execSync('git ls-remote --heads ' + remoteTdiUrl)
42
- .toString()
40
+ let branches;
41
+
42
+ try { branches = execSync('git ls-remote --heads ' + remoteTdiUrl, {encoding: 'UTF-8'}) }
43
+ catch (e) { _error(' '); } // execSync already prints an error to the console
44
+
45
+ branches = branches
43
46
  .match(/refs\/heads\/\S+/g)
44
47
  .map(s => s.replace('refs/heads/', ''))
45
48
  .sort((a, b) => {
@@ -5,7 +5,6 @@ const path = require('path');
5
5
  const rif = require('replace-in-file');
6
6
 
7
7
 
8
- const rifSync = (options) => rif.sync(options).filter(result => result.hasChanged).map(result => result.file);
9
8
  const getPaths = (search, filter) =>
10
9
  globby
11
10
  .sync(search, {dot: true, ignore: [_paths.tdi + '/**','**/cmscustom/tdi/**']})
@@ -48,9 +47,9 @@ module.exports = function steps (step, dry, filter) {
48
47
  r.to = r.fromtoPairs.map(p => p[1]);
49
48
  }
50
49
 
51
- r.files = rifSync(r); // execute first time
50
+ r.files = rif.sync(r); // execute first time
52
51
  const filesModCount = r.files.length; // save file count
53
- for (let i=0; i<20 && !dry && r.files[0]; i++) r.files = rifSync(r); // execute repeatedly for modified files only (with safety limit of 20)
52
+ for (let i=0; i<20 && !dry && r.files[0]; i++) r.files = rif.sync(r); // execute repeatedly for modified files only (with safety limit of 20)
54
53
 
55
54
  _write('Files modified:', filesModCount);
56
55
  });
@@ -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
- };