@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,19 +1,19 @@
1
- // based on gulp-batch-replace
2
-
3
- const es = require('event-stream'), minimatch = require("minimatch"), istextorbinary = require('istextorbinary');
4
-
5
- const execReplace = (c, s, r) => Buffer.from(s instanceof RegExp ? String(c).replace(s,r) : String(c).split(s).join(r));
6
-
7
- module.exports = (arr) => {
8
- return es.map((file, callback) => {
9
- if(file.contents instanceof Buffer) {
10
- arr.forEach(e => {
11
- // exec if no glob is passed or if glob matches, and it's a text file
12
- if ((!e[2] || minimatch(file.path,e[2])) && istextorbinary.isText(file.path,file)) {
13
- file.contents = execReplace(file.contents, e[0], e[1]);
14
- }
15
- });
16
- }
17
- callback(null,file);
18
- });
19
- };
1
+ // based on gulp-batch-replace
2
+
3
+ const es = require('event-stream'), minimatch = require('minimatch'), istextorbinary = require('istextorbinary');
4
+
5
+ const execReplace = (c, s, r) => Buffer.from(s instanceof RegExp ? String(c).replace(s, r) : String(c).split(s).join(r));
6
+
7
+ module.exports = (arr) => {
8
+ return es.map((file, callback) => {
9
+ if(file.contents instanceof Buffer) {
10
+ arr.forEach(e => {
11
+ // exec if no glob is passed or if glob matches, and it's a text file
12
+ if ((!e[2] || minimatch(file.path, e[2])) && istextorbinary.isText(file.path, file)) {
13
+ file.contents = execReplace(file.contents, e[0], e[1]);
14
+ }
15
+ });
16
+ }
17
+ callback(null, file);
18
+ });
19
+ };
@@ -13,17 +13,17 @@ const resolveImports = (fp, file) => {
13
13
  const xiPath = g1.includes('cmscustom') ? g1.replace('#{cmscustompath}', cmscustompath) : path.resolve(fp.dir, g1);
14
14
  const xiFile =
15
15
  fs.readFileSync(xiPath).toString()
16
- .replace(/[\s\S]*?<x:config[^>]*>([\s\S]*?)<\/x:config>/, '$1') // only return contents of x:config element
17
- .replace(/<(\w+)\/>/g, '<$1></$1>') // self-closing html tags can cause problems
18
- .replace(/url="(\.\.\/)+pls\//g, 'url="#{plsservlet}') // replace relative references to plsservlet by bind (4.1 compatibility)
19
- .replace(/url="(\.\.\/)+/g, 'url="#{cmspath}') // replace relative references to cmspath by bind (4.1 compatibility)
20
- .replace(/(<x:javascript\s+src=")([^#].*?)("\s*\/>)/g, (match, g1, g2, g3) => { // correct all javascript refs to paths relative to cmscustompath bind
21
- const newPath = path.resolve(fp.dir, path.resolve(path.dirname(xiPath), g2))
22
- .replace(/.*cmscustom./, '#{cmscustompath}')
23
- .replace(/\\/g, '/')
16
+ .replace(/[\s\S]*?<x:config[^>]*>([\s\S]*?)<\/x:config>/, '$1') // only return contents of x:config element
17
+ .replace(/<(\w+)\/>/g, '<$1></$1>') // self-closing html tags can cause problems
18
+ .replace(/url="(\.\.\/)+pls\//g, 'url="#{plsservlet}') // replace relative references to plsservlet by bind (4.1 compatibility)
19
+ .replace(/url="(\.\.\/)+/g, 'url="#{cmspath}') // replace relative references to cmspath by bind (4.1 compatibility)
20
+ .replace(/(<x:javascript\s+src=")([^#].*?)("\s*\/>)/g, (match, g1, g2, g3) => { // correct all javascript refs to paths relative to cmscustompath bind
21
+ const newPath = path.resolve(fp.dir, path.resolve(path.dirname(xiPath), g2))
22
+ .replace(/.*cmscustom./, '#{cmscustompath}')
23
+ .replace(/\\/g, '/')
24
24
  ;
25
- return [g1, newPath, g3].join('');
26
- })
25
+ return [g1, newPath, g3].join('');
26
+ })
27
27
  ;
28
28
  return resolveImports(path.parse(xiPath), xiFile);
29
29
  });
@@ -34,7 +34,7 @@ const resolveImports = (fp, file) => {
34
34
 
35
35
  const resolveIncludes = (fp, file) => {
36
36
  const rootEl = fp.ext=='.xsd' ? 'xs:schema' : 'xsl:stylesheet';
37
- const rootRe = RegExp('[\\s\\S]*?<'+rootEl+'[^>]*>([\\s\\S]*?)<\/'+rootEl+'>');
37
+ const rootRe = RegExp('[\\s\\S]*?<'+rootEl+'[^>]*>([\\s\\S]*?)</'+rootEl+'>');
38
38
 
39
39
  let fileNew = file.replace(/<!--(?:(?!-->)[\s\S])*?-->/g, ''); // first remove all comments (so disabled includes are not resolved)
40
40
 
@@ -47,8 +47,8 @@ const resolveIncludes = (fp, file) => {
47
47
  const xiPath = path.resolve(fp.dir, g1);
48
48
  try {
49
49
  const xiFile = fs.readFileSync(xiPath).toString() // get file
50
- .replace(rootRe, '$1') // return contents of root element
51
- .replace(/<\/?xs:any[^>]*>/g, '') // remove xs:any(Attribute) elements (causes error in xopus if in root file) (4.1 compatibility)
50
+ .replace(rootRe, '$1') // return contents of root element
51
+ .replace(/<\/?xs:any[^>]*>/g, '') // remove xs:any(Attribute) elements (causes error in xopus if in root file) (4.1 compatibility)
52
52
  ;
53
53
  return resolveIncludes(path.parse(xiPath), xiFile);
54
54
  }
@@ -61,7 +61,7 @@ const resolveIncludes = (fp, file) => {
61
61
  return fileNew;
62
62
  };
63
63
 
64
- module.exports = (arr) => {
64
+ module.exports = () => {
65
65
  return es.map((file, callback) => {
66
66
  const fp = path.parse(file.path);
67
67
 
@@ -29,33 +29,33 @@ module.exports = function(ftpConfig, remotedir) {
29
29
  ;
30
30
 
31
31
  sftp.connect(ftpConfig)
32
- .then(() => Promise.all(paths.map(p => parallel( // check if all directories exist
33
- () => sftp.exists(p).then(r => {
34
- if (!!r) paths.splice(paths.indexOf(p), 1) // if exists, remove from paths
32
+ .then(() => Promise.all(paths.map(p => parallel( // check if all directories exist
33
+ () => sftp.exists(p).then(r => {
34
+ if (r) paths.splice(paths.indexOf(p), 1); // if exists, remove from paths
35
+ })
36
+ ))))
37
+ .then(() => Promise.all(paths.map(p => serial( // create directories that do not exist, which cannot be done parallel
38
+ () => {
39
+ _write(p.replace(remotedir, '').lblack);
40
+ return sftp.mkdir(p, true).catch(err => _warn(err));
41
+ }
42
+ ))))
43
+ .then(() => Promise.all(files.map(file => parallel( // upload files
44
+ () => {
45
+ ftpConfig.eventPut(file);
46
+ return ( // use fastPut for files larger than 3mb; since it requires a local path we assume these files are not changed in the gulp pipeline
47
+ file.contents.length > 3000000 ? sftp.fastPut(file.originalRelativePath, file.destination) : sftp.put(file.contents, file.destination)
48
+ ).catch(err => _warn(`File transfer failed${err ? ': '+err : ''}`));
49
+ }
50
+ ))))
51
+ .then(() => {
52
+ _info(`${files.length} file(s) transferred`);
53
+ cb();
54
+ return sftp.end();
35
55
  })
36
- ))))
37
- .then(() => Promise.all(paths.map(p => serial( // create directories that do not exist, which cannot be done parallel
38
- () => {
39
- _write(p.replace(remotedir, '').lblack);
40
- return sftp.mkdir(p, true).catch(err => _warn(err));
41
- }
42
- ))))
43
- .then(() => Promise.all(files.map(file => parallel( // upload files
44
- () => {
45
- ftpConfig.eventPut(file);
46
- return ( // use fastPut for files larger than 3mb; since it requires a local path we assume these files are not changed in the gulp pipeline
47
- file.contents.length > 3000000 ? sftp.fastPut(file.originalRelativePath, file.destination) : sftp.put(file.contents, file.destination)
48
- ).catch(err => _warn(`File transfer failed${err ? ': '+err : ''}`));
49
- }
50
- ))))
51
- .then(() => {
52
- _info(`${files.length} file(s) transferred`);
53
- cb();
54
- return sftp.end();
55
- })
56
- .catch(err => _error(`Could not connect to server${err ? ': '+err.message : ''}`));
56
+ .catch(err => _error(`Could not connect to server${err ? ': '+err.message : ''}`));
57
57
  }
58
58
 
59
59
  )
60
- .resume(); // required for triggering 'end' event
60
+ .resume(); // required for triggering 'end' event
61
61
  };
@@ -1,11 +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
- };
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
+ };
@@ -4,16 +4,16 @@ const exec = require('util').promisify(require('child_process').exec);
4
4
 
5
5
  const doUpdateCheck = (package) => (
6
6
  exec(`npm view -g ${_packages[package].name} version`)
7
- .then(r => {
8
- const versionAvailable = r.stdout.match(/([\d/.]+)/)[1];
9
- if (!_packages[package].version) _warn(`${package} is not installed! Run ` + `npm i -g ${_packages[package].name}`.white);
10
- else if (compare(_packages[package].version, versionAvailable, '<')) {
11
- _appdata._update({[`updateCheck${package}`]: {executed: new Date(), versionAvailable}});
12
- return versionAvailable;
13
- }
14
- else _appdata._update({[`updateCheck${package}`]: {executed: new Date()}});
15
- })
16
- .catch(e => _warn(`Failed checking latest version of ${package}.`))
7
+ .then(r => {
8
+ const versionAvailable = r.stdout.match(/([\d/.]+)/)[1];
9
+ if (!_packages[package].version) _warn(`${package} is not installed! Run ` + `npm i -g ${_packages[package].name}`.white);
10
+ else if (compare(_packages[package].version, versionAvailable, '<')) {
11
+ _appdata._update({[`updateCheck${package}`]: {executed: new Date(), versionAvailable}});
12
+ return versionAvailable;
13
+ }
14
+ else _appdata._update({[`updateCheck${package}`]: {executed: new Date()}});
15
+ })
16
+ .catch(e => _warn(`Failed checking latest version of ${package}.`))
17
17
  );
18
18
 
19
19
  let checkUpdatesDone = false;
@@ -23,7 +23,7 @@ module.exports = function packageUpdateCheck () {
23
23
  if (!checkUpdatesDone) { // check if updatecheck has ran before because async calls below trigger beforeExit again
24
24
  checkUpdatesDone = true;
25
25
 
26
- ['TCT', 'FDT'].forEach(p => {
26
+ ['TCT'].forEach(p => {
27
27
  const updateMsg = (va) => `| Update ${p} to ${va} | ` + `npm i -g ${_packages[p].name}`.white;
28
28
  const {versionAvailable} = _appdata[`updateCheck${p}`] || {};
29
29
 
@@ -36,4 +36,4 @@ module.exports = function packageUpdateCheck () {
36
36
  }
37
37
  });
38
38
  }
39
- }
39
+ };
@@ -1,4 +1,4 @@
1
- const styles = { bold: 1, underline: 4, black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, white: 37, lblack: 90, lred: 91, lgreen: 92, lyellow: 93, lblue: 94, lmagenta: 95, lcyan: 96, lwhite: 97 };
1
+ const styles = {bold: 1, underline: 4, black: 30, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, white: 37, lblack: 90, lred: 91, lgreen: 92, lyellow: 93, lblue: 94, lmagenta: 95, lcyan: 96, lwhite: 97};
2
2
 
3
3
  for (const name in styles ) {
4
4
  const style = styles[name];
@@ -9,5 +9,5 @@ for (const name in styles ) {
9
9
  }
10
10
 
11
11
  String.prototype.__defineGetter__('nostyle', function () {
12
- return this.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,'');
12
+ return this.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
13
13
  });
@@ -1,5 +1,5 @@
1
1
  const {Worker} = require('worker_threads');
2
- const {Spinner} = require("cli-spinner")
2
+ const {Spinner} = require('cli-spinner');
3
3
 
4
4
 
5
5
  module.exports = function workerWithSpinner (spinnerTxt, workerFn, postMsg, onMessageFn) {
@@ -13,7 +13,7 @@ module.exports = function workerWithSpinner (spinnerTxt, workerFn, postMsg, onMe
13
13
  });
14
14
  };
15
15
 
16
- return new Promise((resolve, reject) => {
16
+ return new Promise((resolve) => {
17
17
  const worker = new Worker(`(${wFnWrap.toString()})(${workerFn.toString()})`, {eval: true});
18
18
  worker.on('message', msg => {
19
19
  spinner.stop(true);
@@ -24,4 +24,4 @@ module.exports = function workerWithSpinner (spinnerTxt, workerFn, postMsg, onMe
24
24
  worker.postMessage(postMsg);
25
25
  });
26
26
 
27
- }
27
+ };
@@ -4,7 +4,7 @@ const inquirer = require('inquirer');
4
4
  const oxygen = require('./oxygen');
5
5
  const path = require('path');
6
6
 
7
- const createSymlink = (t, p, desc) => {
7
+ const createSymlink = (t, p) => {
8
8
  const up = p.replace(/[^/]+/g, '..').replace(/^..\//, '');
9
9
  fs.symlink(path.join(up, _paths.tdi, t), p, 'dir', err => {
10
10
  if (err) {
@@ -20,11 +20,11 @@ const createSymlinks = () => {
20
20
  const src = _isPre51 ? 'sources' : 'src';
21
21
  createSymlink(src + '/config/cmscustom/tdi', 'config/cmscustom/tdi', 'TDI');
22
22
  globby
23
- .sync('config/cmscustom/!(tdi)/**/fonto')
24
- .forEach(p => {
25
- createSymlink(src + '/config/cmscustom/tdi/fonto/packages-shared', p + '/packages-shared', 'Fonto');
26
- });
27
- }
23
+ .sync('config/cmscustom/!(tdi)/**/fonto')
24
+ .forEach(p => {
25
+ createSymlink(src + '/config/cmscustom/tdi/fonto/packages-shared', p + '/packages-shared', 'Fonto');
26
+ });
27
+ };
28
28
 
29
29
 
30
30
  module.exports = function build (argv) {
@@ -41,23 +41,23 @@ module.exports = function build (argv) {
41
41
  const {projectNew, projectCopy} = require(path.join(_paths.repo, _paths.tdi, 'tct/build/project'));
42
42
 
43
43
  inquirer
44
- .prompt([{
45
- message: 'Create project: ', name: 'project', type: 'list',
46
- choices: [
47
- {name: 'New from TDI submodule', value: 'TDI'},
48
- ...(
49
- _repoconfig.projects
50
- ? (_repoconfig.projects || []).map(p => ({name: 'Copy of ' + p.name, value: p})) // when using repoconfig file (old)
51
- : (_repoconfig || []).map(p => ({name: `Copy of ${p.customer_name} ${p.project_name}`, value: p}))
52
- )
53
- ]
54
- }])
55
- .then(a => {
56
- if (a.project=='TDI') projectNew(createSymlinks);
57
- else {
58
- projectCopy(createSymlinks, a.project);
59
- }
60
- });
44
+ .prompt([{
45
+ message: 'Create project: ', name: 'project', type: 'list',
46
+ choices: [
47
+ {name: 'New from TDI submodule', value: 'TDI'},
48
+ ...(
49
+ _repoconfig.projects
50
+ ? (_repoconfig.projects || []).map(p => ({name: 'Copy of ' + p.name, value: p})) // when using repoconfig file (old)
51
+ : (_repoconfig || []).map(p => ({name: `Copy of ${p.customer_name} ${p.project_name}`, value: p}))
52
+ )
53
+ ]
54
+ }])
55
+ .then(a => {
56
+ if (a.project=='TDI') projectNew(createSymlinks);
57
+ else {
58
+ projectCopy(createSymlinks, a.project);
59
+ }
60
+ });
61
61
  }
62
62
 
63
63
  if (argv.symlinks) {
@@ -74,43 +74,43 @@ module.exports = function build (argv) {
74
74
  }
75
75
 
76
76
  if (argv.config) {
77
- if (_git.commitLocalTdi.after(_git.commitLocalTdi.stopUsingRepoconfigFile)) _error('This option only works for older repo\'s using a repoconfig file.');
77
+ if (_git.commitTdi.after(_git.commitTdi.stopUsingRepoconfigFile)) _error('This option only works for older repo\'s using a repoconfig file.');
78
78
 
79
79
 
80
80
  inquirer
81
- .prompt([{message: 'Be sure paths for projects are [customer]/[project]. Continue?', name: 'confirm', type: 'confirm'}])
82
- .then(({confirm}) => {
83
- if (!confirm) return;
84
-
85
- const customer = {}, projects = [];
86
-
87
- globby
88
- .sync('database/config/**/txd_document_types.sql')
89
- .forEach(p => {
90
- const dtSqlInsert = fs.readFileSync(p).toString().match(/select(.*?)from/s)[1];
91
- const ntSqlInsert = fs.readFileSync(p.replace('txd_document_types', 'txd_node_types')).toString().match(/select(.*?)from/s)[1];
92
-
93
- const dtDisplayName = dtSqlInsert.match(/'([^']+)' display_name/)[1];
94
- const ntName = ntSqlInsert.match(/'([^']+)' name/)[1];
95
- const xpiDir = ntSqlInsert.match(/'([^']+)' xsl_prep_inc/)[1];
96
-
97
- customer.name = dtDisplayName.split(/ (.+)/)[0];
98
- customer.abbr = ntName.split('_')[0];
99
- customer.dirname = xpiDir.split('/')[0];
100
-
101
- projects.push({
102
- name: dtDisplayName.split(/ (.+)/)[1],
103
- abbr: ntName.split('_')[1],
104
- dirname: xpiDir.split('/')[1],
105
- idrange: dtSqlInsert.match(/(\d+)\d{3} id/)[1]
106
- });
81
+ .prompt([{message: 'Be sure paths for projects are [customer]/[project]. Continue?', name: 'confirm', type: 'confirm'}])
82
+ .then(({confirm}) => {
83
+ if (!confirm) return;
84
+
85
+ const customer = {}, projects = [];
86
+
87
+ globby
88
+ .sync('database/config/**/txd_document_types.sql')
89
+ .forEach(p => {
90
+ const dtSqlInsert = fs.readFileSync(p).toString().match(/select(.*?)from/s)[1];
91
+ const ntSqlInsert = fs.readFileSync(p.replace('txd_document_types', 'txd_node_types')).toString().match(/select(.*?)from/s)[1];
92
+
93
+ const dtDisplayName = dtSqlInsert.match(/'([^']+)' display_name/)[1];
94
+ const ntName = ntSqlInsert.match(/'([^']+)' name/)[1];
95
+ const xpiDir = ntSqlInsert.match(/'([^']+)' xsl_prep_inc/)[1];
96
+
97
+ customer.name = dtDisplayName.split(/ (.+)/)[0];
98
+ customer.abbr = ntName.split('_')[0];
99
+ customer.dirname = xpiDir.split('/')[0];
100
+
101
+ projects.push({
102
+ name: dtDisplayName.split(/ (.+)/)[1],
103
+ abbr: ntName.split('_')[1],
104
+ dirname: xpiDir.split('/')[1],
105
+ idrange: dtSqlInsert.match(/(\d+)\d{3} id/)[1]
106
+ });
107
+ });
108
+
109
+ _repoconfig.update({customer, projects, applink: 'None'});
110
+
111
+ _write(`\nFile '${_paths.repoconfig}' has been created.`);
112
+ _repoconfig.projects;
107
113
  });
108
-
109
- _repoconfig.update({customer, projects, applink: 'None'});
110
-
111
- _write(`\nFile '${_paths.repoconfig}' has been created.`);
112
- _repoconfig.projects
113
- });
114
114
  }
115
115
 
116
116
  if (argv.oxygen) oxygen();