@eui/tools 6.1.0 → 6.1.1

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 +1 @@
1
- 6.1.0
1
+ 6.1.1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## 6.1.1 (2022-11-06)
2
+
3
+ ##### Chores
4
+
5
+ * **other:**
6
+ * cleanup sandbox add audit pc score - EUI-6448 [EUI-6448](https://webgate.ec.europa.eu/CITnet/jira/browse/EUI-6448) ([71addfb8](https://webgate.ec.europa.eu/CITnet/stash/scm/csdr/eui-tools.git/commits/71addfb8f8b2cc4f392e1efb8a49c98948bd1a87))
7
+ * audit final testing - EUI-6448 [EUI-6448](https://webgate.ec.europa.eu/CITnet/jira/browse/EUI-6448) ([e2c35c10](https://webgate.ec.europa.eu/CITnet/stash/scm/csdr/eui-tools.git/commits/e2c35c10bbea2445a67b89934d210843b7c6bc00))
8
+ * refactoring / cleanup - added audit specific - EUI-6448 [EUI-6448](https://webgate.ec.europa.eu/CITnet/jira/browse/EUI-6448) ([0dc58643](https://webgate.ec.europa.eu/CITnet/stash/scm/csdr/eui-tools.git/commits/0dc58643aa52cfdf2126275ecefa38fbe30e9f97))
9
+ ##### Bug Fixes
10
+
11
+ * **other:**
12
+ * wrong method call ([de9642f5](https://webgate.ec.europa.eu/CITnet/stash/scm/csdr/eui-tools.git/commits/de9642f59c7683c3605a9876e412c50589f474cb))
13
+
14
+ * * *
15
+ * * *
1
16
  ## 6.1.0 (2022-11-04)
2
17
 
3
18
  ##### Chores
@@ -8,6 +8,7 @@ const args = process.argv.slice(2);
8
8
  const scriptIndex = args.findIndex(
9
9
  x => x === 'clean-package' ||
10
10
  x === 'clean-all' ||
11
+ x === 'audit-package' ||
11
12
  x === 'build-package' ||
12
13
  x === 'build-package-pr-scan' ||
13
14
  x === 'build-package-sub' ||
@@ -47,6 +48,7 @@ const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
47
48
  switch (script) {
48
49
  case 'clean-package':
49
50
  case 'clean-all':
51
+ case 'audit-package':
50
52
  case 'build-package':
51
53
  case 'build-package-pr-scan':
52
54
  case 'build-package-sub':
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ const auditUtils = require('../../scripts/csdr/audit/audit-utils');
4
+ const configUtils = require('../../scripts/csdr/config/config-utils');
5
+
6
+ Promise.resolve()
7
+ .then(() => {
8
+ const pkg = configUtils.packages.getPackage();
9
+ return auditUtils.styles.audit(pkg);
10
+ })
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const installUtils = require('../../scripts/csdr/install/install-utils');
4
- const configUtils = require('../../scripts/csdr/config/config-utils');
5
4
  const tools = require('../../scripts/utils/tools');
6
5
 
7
6
  const { pkg } = tools.getArgs();
@@ -9,10 +8,8 @@ const { pkg } = tools.getArgs();
9
8
  Promise.resolve()
10
9
  .then(() => {
11
10
 
12
- const resolvedPkg = configUtils.packages.getPackage(pkg, false, true);
13
-
14
11
  if (pkg) {
15
- return installUtils.localDev.install(resolvedPkg);
12
+ return installUtils.localDev.installPackage(pkg);
16
13
  } else {
17
14
  return installUtils.localDev.install();
18
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eui/tools",
3
- "version": "6.1.0",
3
+ "version": "6.1.1",
4
4
  "tag": "latest",
5
5
  "license": "EUPL-1.1",
6
6
  "description": "eUI common tools and scripts",
package/sandbox.js CHANGED
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
+ const moment = require('moment');
5
+ const execa = require('execa');
4
6
  const glob = require('glob');
5
7
  const tools = require('./scripts/utils/tools');
6
8
  const semver = require('semver');
@@ -586,14 +588,7 @@ const versionUtils = require('./scripts/csdr/version/version-utils');
586
588
 
587
589
  // })
588
590
 
589
- // return Promise.resolve()
590
- // .then(() => {
591
- // const a = configUtils.packages.getCsdrRemotePackages()
592
- // .map((p) => {
593
- // return { name: p.name, npmPkg: p.npmPkg }
594
- // });
595
- // console.log(tools.sortArray(a, 'name'));
596
- // })
591
+
597
592
  // return Promise.resolve()
598
593
  // .then(() => {
599
594
  // console.log('t1')
@@ -774,16 +769,6 @@ const versionUtils = require('./scripts/csdr/version/version-utils');
774
769
 
775
770
 
776
771
 
777
- // const pkg = configUtils.packages.getPackage('opsys-epc-esub-bo-ui', true);
778
-
779
- // Promise.resolve()
780
- // .then(() => {
781
- // return metadataUtils.package.getPackageVersionsByMajor(pkg, '9', false)
782
- // })
783
- // .then((versions) => {
784
- // console.log(versions);
785
- // console.log(versions.splice(-1)[0].version);
786
- // })
787
772
 
788
773
 
789
774
  // PROJECT VERSION CSDR BUILD TESTING (à la carte way === MWP / PMO MOBILE / SEDIA)
@@ -908,3 +893,137 @@ const versionUtils = require('./scripts/csdr/version/version-utils');
908
893
  // }
909
894
 
910
895
  // migrateConfig();
896
+
897
+
898
+
899
+ // const pkg = configUtils.packages.getPackage('ppxms-core-ui', true);
900
+
901
+ // Promise.resolve()
902
+ // .then(() => {
903
+ // return metadataUtils.package.getPackageVersionsByMajor(pkg, '1')
904
+ // })
905
+ // .then((versions) => {
906
+ // console.log(versions);
907
+ // console.log(versions.splice(-1)[0].version);
908
+ // })
909
+
910
+ // return Promise.resolve()
911
+ // .then(() => {
912
+ // const a = configUtils.packages.getCsdrRemotePackages(10, 'sedia')
913
+ // .map((p) => {
914
+ // return { name: p.name, npmPkg: p.npmPkg }
915
+ // });
916
+ // console.log(tools.sortArray(a, 'name'));
917
+ // })
918
+
919
+ // Promise.resolve()
920
+ // .then(() => {
921
+ // const prj = configUtils.projects.getCsdrProject('my-workplace-host-playground');
922
+ // return installUtils.projects.getLocalProjectRemoteDeps(prj);
923
+ // })
924
+
925
+ // Promise.resolve()
926
+ // .then(() => {
927
+
928
+ // })
929
+
930
+
931
+
932
+
933
+
934
+
935
+ // STYLES AUDIT TESTS
936
+
937
+ Promise.resolve()
938
+ .then(() => {
939
+ const { pkg } = tools.getArgs();
940
+ const p = configUtils.packages.getPackage(pkg, true);
941
+ return auditUtils.styles.audit(p);
942
+ })
943
+
944
+ // const installPackages = async packages => {
945
+ // const promises = packages.map(async p => {
946
+ // const pkg = configUtils.packages.getPackageByNpmPkg(p.npmPkg, true);
947
+ // await gitUtils.cloneRepo(pkg.repository, pkg.paths.root, false, true);
948
+ // })
949
+
950
+ // await Promise.all(promises);
951
+ // }
952
+
953
+
954
+ // Promise.resolve()
955
+ // .then(() => {
956
+ // return metadataUtils.common.getDevopsMetadata();
957
+ // })
958
+ // .then((metadata) => {
959
+ // let packages = metadata.packages.filter((p) => {
960
+ // return moment(p.date, 'YYYYMMDD-H24:mm') > moment().subtract(12, 'months');
961
+ // }).filter((p) => {
962
+ // return p.name.indexOf('ui') > -1 &&
963
+ // p.name.indexOf('remote') === -1 && p.npmPkg !== undefined &&
964
+ // p.name.indexOf('sfc') === -1 && p.name.indexOf('sedia') === -1;
965
+ // })
966
+
967
+ // console.log(packages);
968
+ // console.log(packages.length);
969
+
970
+ // packages = packages.filter((p) => {
971
+ // return !tools.isDirExists(path.join(process.cwd(), 'packages', p.name));
972
+ // })
973
+
974
+ // console.log(packages.length);
975
+
976
+ // // installPackages(packages);
977
+ // })
978
+
979
+ // Promise.resolve()
980
+ // .then(() => {
981
+ // let folders = tools.getFolders(path.join(process.cwd(), 'packages'));
982
+ // folders = folders.filter((f) => {
983
+ // const scopes = ['cc','csdr','eac','opsys','mywp','sygma','redress','ppams','ppxms','urf'];
984
+ // return scopes.some((s) => {
985
+ // return f.includes(s);
986
+ // })
987
+ // })
988
+ // .filter((f) => {
989
+ // return tools.isFileExists(path.join(process.cwd(), 'packages', f, 'dependencies-composite.json'));
990
+ // })
991
+
992
+ // const JSONResult = [];
993
+ // folders.forEach((f) => {
994
+ // const pkg = configUtils.packages.getPackage(f, true);
995
+ // const report = auditUtils.styles.runStylesAudit(pkg);
996
+ // JSONResult.push(report);
997
+ // })
998
+
999
+ // const sumarryResult = JSONResult.map((p) => {
1000
+ // return {
1001
+ // package: p.package,
1002
+ // score: p.score,
1003
+ // total: p.total,
1004
+ // pcScore: p.pcScore
1005
+ // }
1006
+ // })
1007
+
1008
+ // const finalResult = {
1009
+ // summary: tools.sortArray(sumarryResult, 'pcScore', 'desc'),
1010
+ // details: JSONResult
1011
+ // }
1012
+
1013
+ // tools.writeJsonFileSync(path.join(process.cwd(), 'audit-styles.json'), finalResult);
1014
+ // tools.writeJsonFileSync(path.join(process.cwd(), 'audit-styles-summary.json'), sumarryResult);
1015
+
1016
+
1017
+ // // folders.forEach((f) => {
1018
+ // // try {
1019
+ // // const pPath = path.join(process.cwd(), 'packages', f);
1020
+ // // console.log(pPath);
1021
+
1022
+ // // execa.shellSync(`git pull`, { cwd: pPath, stdio: 'inherit' });
1023
+ // // execa.shellSync(`git checkout next/eui10`, { cwd: pPath, stdio: 'inherit' });
1024
+ // // } catch(e) {
1025
+ // // console.log(e);
1026
+ // // }
1027
+ // // })
1028
+
1029
+ // })
@@ -1,100 +1,5 @@
1
1
  'use strict';
2
2
 
3
- // GLOBAL
4
- const path = require('path');
5
- const execa = require('execa');
6
-
7
- // LOCAL
8
- const tools = require('../../utils/tools');
9
- const notificationUtils = require('../../utils/notification/notification-utils');
10
-
11
- const { dryRun } = tools.getArgs();
12
-
13
- const getVulnerabilitiesList = () => {
14
- let auditContent;
15
- const auditFile = path.join(process.cwd(), 'audit.json');
16
-
17
- if (tools.isFileExists(auditFile)) {
18
- auditContent = tools.getFileContent(auditFile);
19
- } else {
20
- tools.logWarning(`${auditFile} not found... unable to precess audit content`);
21
- return null;
22
- }
23
-
24
- let auditContentArray = [];
25
- let vulnerabilitiesFound = {};
26
-
27
- // yarn audit output uses a specific json-lines format, we need to split it first
28
- auditContentArray = auditContent.split('\n');
29
-
30
- // extracting the audit summary lines
31
- auditContentArray.forEach((c) => {
32
- try {
33
- const parsedContent = JSON.parse(c);
34
- if (parsedContent && parsedContent.type === 'auditSummary') {
35
- vulnerabilitiesFound = parsedContent.data.vulnerabilities;
36
- }
37
- } catch(e) {} // it can fail
38
- })
39
-
40
- return vulnerabilitiesFound;
41
- }
42
-
43
-
44
- module.exports.audit = (pkg) => {
45
- if (dryRun) return;
46
-
47
- return Promise.resolve()
48
-
49
- // first pass to display the visual report into the CI logs
50
- .then(() => {
51
- return Promise.resolve()
52
- .then(() => {
53
- return execa.shellSync('yarn audit --level high', { cwd: process.cwd(), stdio: 'inherit' });
54
- })
55
- .catch((e) => {}) // it can fail
56
- })
57
-
58
- // second pass to extract the audit summary lines
59
- .then(() => {
60
- return Promise.resolve()
61
- .then(() => {
62
- const auditFile = path.join(process.cwd(), 'audit.json');
63
- tools.logInfo(`Creating audit file`)
64
- return execa.shellSync(`yarn audit --level high --json > ${auditFile}`, { cwd: process.cwd(), stdio: 'inherit' });
65
- })
66
- .then(() => {
67
- tools.logSuccess();
68
- return null;
69
- })
70
- .catch((e) => {
71
- tools.logError('Auditing detected vulnerabilities in dependencies');
72
- return getVulnerabilitiesList();
73
- })
74
- })
75
-
76
- // sending output to slack channel
77
- .then((vulnerabilityReport) => {
78
- if (!vulnerabilityReport) {
79
- tools.logSuccess('OK, no vulnerabilities detected');
80
-
81
- return notificationUtils.package.sendPackageMessage({
82
- package: pkg,
83
- text: 'Dependencies audit : NO vulnerabilities detected'
84
- });
85
-
86
- } else {
87
- tools.logWarning(JSON.stringify(vulnerabilityReport));
88
-
89
- let message = '';
90
- Object.entries(vulnerabilityReport).forEach((v) => {
91
- message += `${v[0]}:*${v[1]}* `;
92
- });
93
-
94
- return notificationUtils.package.sendPackageMessage({
95
- package: pkg,
96
- text: `Dependencies audit detected vulnerabilities : ${message}`
97
- });
98
- }
99
- })
100
- }
3
+ module.exports.yarn = require('./yarn');
4
+ module.exports.deps = require('./deps');
5
+ module.exports.styles = require('./styles');
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ // GLOBAL
4
+ const path = require('path');
5
+ const glob = require('glob');
6
+
7
+ // LOCAL
8
+ const tools = require('../../utils/tools');
9
+ const notificationUtils = require('../../utils/notification/notification-utils');
10
+
11
+
12
+ module.exports.audit = (pkg) => {
13
+ tools.logTitle('Auditiing package internal dependencies complexity');
14
+
15
+ return Promise.resolve()
16
+ .then(() => {
17
+ var depsFound = [];
18
+ var files = glob.sync('**/*.ts', { cwd: pkg.paths.pkgLibFolder, nodir: true, follow: true, dot: true });
19
+ files.forEach(file => {
20
+ const filePath = path.join(pkg.paths.pkgLibFolder, file);
21
+ const fileContent = tools.getFileContent(filePath);
22
+ var regex = /@cc\/|@mywp\/|@opsys\/|@sfc\//gi, result, indices = [];
23
+ while ( (result = regex.exec(fileContent)) ) {
24
+ indices.push(result.index);
25
+ }
26
+ if (indices.length !== 0) {
27
+ // tools.logInfo(`Number of occurences found : ${indices.length}`);
28
+ indices.forEach((i) => {
29
+ const endPos = fileContent.substr(i, 40).indexOf("'");
30
+ const dep = fileContent.substr(i, endPos);
31
+ if (endPos > -1) {
32
+ // tools.logInfo(`dep found on : ${dep}`);
33
+ depsFound.push(dep);
34
+
35
+ } else {
36
+ tools.logInfo(`Potential wrong import detected on file : ${file}`);
37
+ const subContent = fileContent.substr(i, 40);
38
+ const detectMultiSlashes = subContent.match(/\//g);
39
+ if (detectMultiSlashes.length > 0) {
40
+ tools.logError('Multislashes on import : ');
41
+ console.log(subContent);
42
+ }
43
+ }
44
+ })
45
+ }
46
+ });
47
+ depsFound = tools.removeArrayDuplicates(depsFound);
48
+ tools.logWarning(`Dependencies found : ${depsFound.length}`);
49
+ console.log(depsFound);
50
+
51
+ return depsFound;
52
+ })
53
+
54
+ .then((depsFound) => {
55
+ var depsLevel;
56
+
57
+ switch(true) {
58
+ case (depsFound.length === 1):
59
+ depsLevel = 'LOW (1)';
60
+ break;
61
+ case (depsFound.length > 1 && depsFound.length <= 3):
62
+ depsLevel = 'MEDIUM (between 1 and 3)';
63
+ break;
64
+ case (depsFound.length > 3 && depsFound.length <= 5):
65
+ depsLevel = 'HIGH (between 3 and 5)';
66
+ break;
67
+ case (depsFound.length > 5):
68
+ depsLevel = 'VERY HIGH (>5)';
69
+ break;
70
+ default:
71
+ depsLevel = 'NONE';
72
+ }
73
+
74
+ var message = `Internal dependencies detected : ${depsFound.length} - deps level: ${depsLevel}\n`;
75
+ message += depsFound.join('\n');
76
+
77
+
78
+ return notificationUtils.package.sendPackageMessage({
79
+ package: pkg,
80
+ text: message
81
+ });
82
+ })
83
+
84
+ .catch((e) => {
85
+ console.log(e);
86
+ })
87
+
88
+ }
89
+