@elliemae/ds-legacy-codemods 1.0.0-rc.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.
Files changed (33) hide show
  1. package/bin/cli/code-mods/cli.mjs +34 -0
  2. package/bin/cli/code-mods/command-arguments/promptCheckEmPackagesInconsistencies.mjs +22 -0
  3. package/bin/cli/code-mods/command-arguments/promptDeprecatedPackages.mjs +13 -0
  4. package/bin/cli/code-mods/command-arguments/promptFixLegacyImports.mjs +21 -0
  5. package/bin/cli/code-mods/command-arguments/promptHelpMigrateToV3.mjs +21 -0
  6. package/bin/cli/code-mods/command-arguments/promptMissingPackages.mjs +29 -0
  7. package/bin/cli/code-mods/command-logics/check-deprecated-packages/constants.mjs +87 -0
  8. package/bin/cli/code-mods/command-logics/check-deprecated-packages/getEmDsPackagesFromNPMLS.mjs +18 -0
  9. package/bin/cli/code-mods/command-logics/check-deprecated-packages/index.mjs +19 -0
  10. package/bin/cli/code-mods/command-logics/check-deprecated-packages/logResults.mjs +35 -0
  11. package/bin/cli/code-mods/command-logics/check-missing-packages/index.mjs +113 -0
  12. package/bin/cli/code-mods/command-logics/check-packages-inconsistencies/getPackageJsonEmDsVersions.mjs +43 -0
  13. package/bin/cli/code-mods/command-logics/check-packages-inconsistencies/index.mjs +96 -0
  14. package/bin/cli/code-mods/command-logics/execute-commands-map.mjs +31 -0
  15. package/bin/cli/code-mods/command-logics/fix-legacy-imports/index.mjs +29 -0
  16. package/bin/cli/code-mods/command-logics/fix-legacy-imports/legacyImportMap.mjs +105 -0
  17. package/bin/cli/code-mods/command-logics/help-migrate-to-v3/constants.mjs +284 -0
  18. package/bin/cli/code-mods/command-logics/help-migrate-to-v3/getSolutions.mjs +106 -0
  19. package/bin/cli/code-mods/command-logics/help-migrate-to-v3/index.mjs +90 -0
  20. package/bin/cli/code-mods/command-logics/help-migrate-to-v3/logMatch.mjs +39 -0
  21. package/bin/cli/code-mods/command-logics/help-migrate-to-v3/matchDsBasicImports.mjs +20 -0
  22. package/bin/cli/code-mods/command-logics/help-migrate-to-v3/replaceFromSolutions.mjs +15 -0
  23. package/bin/cli/code-mods/commands.mjs +11 -0
  24. package/bin/cli/code-mods/inquirer-questions-prompter.mjs +60 -0
  25. package/bin/cli/utils/CLI_COLORS.mjs +81 -0
  26. package/bin/cli/utils/generatePathFromCurrentFolder.mjs +11 -0
  27. package/bin/cli/utils/getLatestDimsumVersion.mjs +15 -0
  28. package/bin/cli/utils/globArray.mjs +11 -0
  29. package/bin/cli/utils/index.mjs +5 -0
  30. package/bin/cli/utils/matchHelpers.mjs +38 -0
  31. package/bin/cli/utils/replaceFromMap.mjs +15 -0
  32. package/bin/ds-codemods.mjs +4 -0
  33. package/package.json +55 -0
@@ -0,0 +1,34 @@
1
+ import arg from 'arg';
2
+ import { promptForMissingOptions } from './inquirer-questions-prompter.mjs';
3
+ import { executeCommandsMap } from './command-logics/execute-commands-map.mjs';
4
+
5
+ function parseArgumentsIntoOptions(rawArgs) {
6
+ const args = arg(
7
+ {
8
+ '--cwd': String,
9
+ '--globPattern': String,
10
+ '--globPatternIgnore': String,
11
+ '--projectFolderPath': String,
12
+ '--ignorePackagesGlobPattern': String,
13
+ '--ignoreFilesGlobPattern': String,
14
+ },
15
+ {
16
+ argv: rawArgs.slice(2),
17
+ },
18
+ );
19
+ return {
20
+ cwd: args['--cwd'],
21
+ globPattern: args['--globPattern'],
22
+ globPatternIgnore: args['--globPatternIgnore'],
23
+ projectFolderPath: args['--projectFolderPath'],
24
+ ignorePackagesGlobPattern: args['--ignorePackagesGlobPattern'],
25
+ ignoreFilesGlobPattern: args['--ignoreFilesGlobPattern'],
26
+ script: args._[0],
27
+ };
28
+ }
29
+
30
+ export async function cli(args) {
31
+ let options = parseArgumentsIntoOptions(args);
32
+ options = await promptForMissingOptions(options);
33
+ executeCommandsMap(args, options);
34
+ }
@@ -0,0 +1,22 @@
1
+ export const getPackagesInconsistenciesQuestions = (originalOptions) => {
2
+ const extraOptions = [];
3
+ const { globPattern, globPatternIgnore } = originalOptions;
4
+ if (!globPattern && globPattern !== '') {
5
+ extraOptions.push({
6
+ type: 'input',
7
+ name: 'globPattern',
8
+ message:
9
+ 'Please provide a comma separated list of globPatterns catching the file in which to check for inconsistencies',
10
+ default: './package.json', // './packages/ds-codemods/test-ables/check-packages-inconsistencies/package.json.test',
11
+ });
12
+ }
13
+ if (!globPatternIgnore && globPatternIgnore !== '') {
14
+ extraOptions.push({
15
+ type: 'input',
16
+ name: 'globPatternIgnore',
17
+ message: 'Please provide a comma separated list of ignored files for your globPattern',
18
+ default: '**/node_modules/**/*',
19
+ });
20
+ }
21
+ return extraOptions;
22
+ };
@@ -0,0 +1,13 @@
1
+ export const getDeprecatedPackagesQuestions = (originalOptions) => {
2
+ const extraOptions = [];
3
+ const { cwd } = originalOptions;
4
+ if (!cwd && cwd !== '') {
5
+ extraOptions.push({
6
+ type: 'input',
7
+ name: 'globPatternIgnore',
8
+ message: 'Please provide the project root directory (where node_modules folder lives)',
9
+ default: './',
10
+ });
11
+ }
12
+ return extraOptions;
13
+ };
@@ -0,0 +1,21 @@
1
+ export const getLegacyImportsQuestions = (originalOptions) => {
2
+ const extraOptions = [];
3
+ const { globPattern, globPatternIgnore } = originalOptions;
4
+ if (!globPattern && globPattern !== '') {
5
+ extraOptions.push({
6
+ type: 'input',
7
+ name: 'globPattern',
8
+ message: 'Please provide a comma separated list of globPatterns catching the file in which to fix the imports',
9
+ default: './**/*.js,./**/*.jsx,./**/*.ts,./**/*.tsx',
10
+ });
11
+ }
12
+ if (!globPatternIgnore && globPatternIgnore !== '') {
13
+ extraOptions.push({
14
+ type: 'input',
15
+ name: 'globPatternIgnore',
16
+ message: 'Please provide a comma separated list of ignored files for your globPattern',
17
+ default: '**/node_modules/**/*',
18
+ });
19
+ }
20
+ return extraOptions;
21
+ };
@@ -0,0 +1,21 @@
1
+ export const getHelpMigrateToV3Questions = (originalOptions) => {
2
+ const extraOptions = [];
3
+ const { globPattern, globPatternIgnore } = originalOptions;
4
+ if (!globPattern && globPattern !== '') {
5
+ extraOptions.push({
6
+ type: 'input',
7
+ name: 'globPattern',
8
+ message: 'Please provide a comma separated list of globPatterns catching the file in which to fix the imports',
9
+ default: './**/*.js,./**/*.jsx,./**/*.ts,./**/*.tsx',
10
+ });
11
+ }
12
+ if (!globPatternIgnore && globPatternIgnore !== '') {
13
+ extraOptions.push({
14
+ type: 'input',
15
+ name: 'globPatternIgnore',
16
+ message: 'Please provide a comma separated list of ignored files for your globPattern',
17
+ default: '**/node_modules/**/*',
18
+ });
19
+ }
20
+ return extraOptions;
21
+ };
@@ -0,0 +1,29 @@
1
+ export const getMissingPackagesQuestions = (originalOptions) => {
2
+ const extraOptions = [];
3
+ const { projectFolderPath, ignorePackagesGlobPattern, ignoreFilesGlobPattern } = originalOptions;
4
+ if (!projectFolderPath && projectFolderPath !== '') {
5
+ extraOptions.push({
6
+ type: 'input',
7
+ name: 'projectFolderPath',
8
+ message: 'path to the project folder containing package.json file',
9
+ default: './',
10
+ });
11
+ }
12
+ if (!ignorePackagesGlobPattern && ignorePackagesGlobPattern !== '') {
13
+ extraOptions.push({
14
+ type: 'input',
15
+ name: 'ignorePackagesGlobPattern',
16
+ message: 'Please provide a comma separated list of globPatterns for ignored packages, if any.',
17
+ default: '',
18
+ });
19
+ }
20
+ if (!ignoreFilesGlobPattern && ignoreFilesGlobPattern !== '') {
21
+ extraOptions.push({
22
+ type: 'input',
23
+ name: 'ignoreFilesGlobPattern',
24
+ message: 'Please provide a comma separated list of globPatterns for ignored files, if any.',
25
+ default: '**/*.eslintrc.js',
26
+ });
27
+ }
28
+ return extraOptions;
29
+ };
@@ -0,0 +1,87 @@
1
+ export const SEVERITY = {
2
+ NON_STARTER: ['Failing to upgrade will make the project impossible to start/use', 1],
3
+ KNOWN_ISSUES: [
4
+ 'The component has unfixable known issues. Failing to upgrade means APP will have to live with those',
5
+ 2,
6
+ ],
7
+ FRAGILE_AND_UNMANTAINED: [
8
+ 'Failing to upgrade will make the project fragile and any error will have to be addressed by the APP team',
9
+ 3,
10
+ ],
11
+ UNMANTAINED: ['Failing to upgrade will mean that any error will have to be addressed by the APP team', 4],
12
+ };
13
+
14
+ export const SOLUTIONS = {
15
+ REMOVED: 'the component has been regarded as supreflous and has hencheforth been removed in favor of examples',
16
+ NEW_VERSION_BREAKING: 'the component impedes further enhancments/bugfixes, a new version ex-novo has been created.',
17
+ };
18
+
19
+ export const DEPRECATED_PACKAGES = {
20
+ '@elliemae/ds-legacy-datagrids': {
21
+ name: 'data-grid',
22
+ solution: SOLUTIONS.NEW_VERSION_BREAKING,
23
+ severity: SEVERITY.KNOWN_ISSUES,
24
+ // TODO create relative confluence
25
+ confluence: 'https://confluence.elliemae.io/display/FEAE/Breaking+changes+-+Migration+steps+and+rationale',
26
+ },
27
+ '@elliemae/ds-legacy-date-picker': {
28
+ name: 'date-picker',
29
+ solution: SOLUTIONS.NEW_VERSION_BREAKING,
30
+ severity: SEVERITY.KNOWN_ISSUES,
31
+ // TODO create relative confluence
32
+ confluence: 'https://confluence.elliemae.io/display/FEAE/Breaking+changes+-+Migration+steps+and+rationale',
33
+ },
34
+ '@elliemae/ds-legacy-date-range-picker': {
35
+ name: 'date-range-picker',
36
+ solution: SOLUTIONS.NEW_VERSION_BREAKING,
37
+ severity: SEVERITY.KNOWN_ISSUES,
38
+ // TODO create relative confluence
39
+ confluence: 'https://confluence.elliemae.io/display/FEAE/Breaking+changes+-+Migration+steps+and+rationale',
40
+ },
41
+ '@elliemae/ds-legacy-date-time-picker': {
42
+ name: 'date-time-picker',
43
+ solution: SOLUTIONS.NEW_VERSION_BREAKING,
44
+ severity: SEVERITY.KNOWN_ISSUES,
45
+ // TODO create relative confluence
46
+ confluence: 'https://confluence.elliemae.io/display/FEAE/Breaking+changes+-+Migration+steps+and+rationale',
47
+ },
48
+ '@elliemae/ds-legacy-time-picker': {
49
+ name: 'time-picker',
50
+ solution: SOLUTIONS.NEW_VERSION_BREAKING,
51
+ severity: SEVERITY.KNOWN_ISSUES,
52
+ // TODO create relative confluence
53
+ confluence: 'https://confluence.elliemae.io/display/FEAE/Breaking+changes+-+Migration+steps+and+rationale',
54
+ },
55
+ '@elliemae/ds-legacy-button-group': {
56
+ name: 'button-group',
57
+ solution: SOLUTIONS.REMOVED,
58
+ severity: SEVERITY.NON_STARTER,
59
+ confluence: 'https://confluence.elliemae.io/display/FEAE/Button+Group+-+Dimsum+2.x',
60
+ },
61
+ '@elliemae/ds-legacy-card-array': {
62
+ name: 'card-array',
63
+ solution: SOLUTIONS.REMOVED,
64
+ severity: SEVERITY.NON_STARTER,
65
+ confluence: 'https://confluence.elliemae.io/display/FEAE/Card+Array+-+Dimsum+2.x',
66
+ },
67
+ '@elliemae/ds-legacy-form': {
68
+ subComponents: [
69
+ {
70
+ name: 'combobox',
71
+ solution: SOLUTIONS.NEW_VERSION_BREAKING,
72
+ severity: SEVERITY.FRAGILE_AND_UNMANTAINED,
73
+ confluence: 'https://confluence.elliemae.io/display/FEAE/Combo-box+-+Dimsum+2.x',
74
+ },
75
+ ],
76
+ },
77
+ '@elliemae/ds-legacy-combobox-v1': {
78
+ subComponents: [
79
+ {
80
+ name: 'combobox',
81
+ solution: SOLUTIONS.NEW_VERSION_BREAKING,
82
+ severity: SEVERITY.FRAGILE_AND_UNMANTAINED,
83
+ confluence: 'https://confluence.elliemae.io/display/FEAE/Combo-box+-+Dimsum+2.x',
84
+ },
85
+ ],
86
+ },
87
+ };
@@ -0,0 +1,18 @@
1
+ /* eslint-disable max-statements */
2
+ export function getEmDsPackagesFromNPMLS(npmLsStdout = '') {
3
+ const dsPackageRegExp = /@elliemae\/ds-.*?@(.*)/gm;
4
+ const matches = [];
5
+ if (npmLsStdout) {
6
+ const npmLsMatches = [...npmLsStdout.matchAll(dsPackageRegExp)];
7
+ npmLsMatches.forEach(([fullMatch, version]) => {
8
+ const matchObj = {
9
+ fullMatch,
10
+ version,
11
+ package: fullMatch.split(version)[0].slice(0, -1),
12
+ };
13
+ matches.push(matchObj);
14
+ });
15
+ }
16
+
17
+ return matches;
18
+ }
@@ -0,0 +1,19 @@
1
+ import { exec } from 'child_process';
2
+ import { getEmDsPackagesFromNPMLS } from './getEmDsPackagesFromNPMLS.mjs';
3
+ import { logResults, logCyanQuestion } from './logResults.mjs';
4
+
5
+ const npmLs = async ({ cwd }) => {
6
+ const [, stdout] = await new Promise((resolve) => {
7
+ exec('npm ls', { cwd }, (...cbRes) => resolve(cbRes));
8
+ });
9
+ if (stdout) return getEmDsPackagesFromNPMLS(stdout);
10
+ return [];
11
+ };
12
+
13
+ export const checkDeprecatedPackages = async (options) => {
14
+ const installedPackages = await npmLs(options);
15
+ if (installedPackages.length === 0) logCyanQuestion('no dimsum packages found... did you specify the correct cwd?');
16
+ logResults(installedPackages);
17
+ };
18
+
19
+ export default checkDeprecatedPackages;
@@ -0,0 +1,35 @@
1
+ import {
2
+ severityLoggingMap,
3
+ yellowStr,
4
+ boldCyanStr,
5
+ boldGreenStr,
6
+ brightCyanStr,
7
+ whiteStr,
8
+ } from '../../../utils/CLI_COLORS.mjs';
9
+ import { DEPRECATED_PACKAGES } from './constants.mjs';
10
+
11
+ const logDeprecatedComponent = ({ name, solution, severity, confluence }) => {
12
+ const [sevDesc, sevLevel] = severity;
13
+ const chalkLog = severityLoggingMap[sevLevel];
14
+ console.log(yellowStr('--------------------------------'));
15
+ console.log(boldCyanStr(`${name} deprecation!`));
16
+ console.log(chalkLog(sevDesc));
17
+ console.log(boldGreenStr(solution));
18
+ console.log(whiteStr(confluence));
19
+ console.log(yellowStr('--------------------------------'));
20
+ };
21
+
22
+ export function logCyanQuestion(question) {
23
+ console.log(brightCyanStr(question));
24
+ }
25
+
26
+ export function logResults(detectedPackages) {
27
+ detectedPackages.forEach((pack) => {
28
+ const deprecatedMetaInfo = DEPRECATED_PACKAGES[pack.package];
29
+ if (deprecatedMetaInfo) {
30
+ const { subComponents, ...metainfo } = deprecatedMetaInfo;
31
+ if (JSON.stringify(metainfo) !== '{}') logDeprecatedComponent(metainfo);
32
+ if (subComponents) subComponents.forEach(logDeprecatedComponent);
33
+ }
34
+ });
35
+ }
@@ -0,0 +1,113 @@
1
+ /* eslint-disable no-console */
2
+ import fs from 'fs';
3
+ import fse from 'fs-extra';
4
+ import path from 'path';
5
+ import depcheck from 'depcheck';
6
+ import {
7
+ brightYellowStr,
8
+ brightRedStr,
9
+ brightMagentaStr,
10
+ boldBrightCyanStr,
11
+ greenStr,
12
+ } from '../../../utils/CLI_COLORS.mjs';
13
+ import { generatePathFromCurrentFolder } from '../../../utils/index.mjs';
14
+
15
+ function generateFolderIfNotExistSync(finalDir) {
16
+ if (!fs.existsSync(finalDir)) {
17
+ fs.mkdirSync(finalDir, { recursive: true });
18
+ }
19
+ }
20
+
21
+ const overWriteFile = fse.outputFileSync;
22
+ const getPackageName = () => process.cwd().split('/').pop();
23
+ const getRoot = () => process.cwd().split('/packages')[0];
24
+ // everything beetween "root" and "package name" is the "taxonomy" (including the "package name")
25
+ const getTaxonomy = () => process.cwd().split('/packages')[1];
26
+
27
+ const logUnusedDep = (unused) => {
28
+ console.log(brightYellowStr('### Found unused dependencies :>>'));
29
+ console.log('```');
30
+ console.log(unused.dependencies);
31
+ console.log('```');
32
+ };
33
+ const logUnusedDevDep = (unused) => {
34
+ console.log(brightMagentaStr('### Found unused dev dependencies :>>'));
35
+ console.log('```');
36
+ console.log(unused.devDependencies);
37
+ console.log('```');
38
+ };
39
+ const logMissing = (unused) => {
40
+ const missingString = [...Object.keys(unused.missing)].map((pack) => `\t${pack}`).join(',\n');
41
+ console.log(brightRedStr('### Found missing dependencies :>>'));
42
+ console.log('```');
43
+ console.log('{');
44
+ console.log(missingString);
45
+ console.log('}');
46
+ console.log('```');
47
+ const root = getRoot();
48
+ const pck = getPackageName();
49
+ const taxonomy = getTaxonomy();
50
+ const folder = `${root}/checkdeps`;
51
+ try {
52
+ generateFolderIfNotExistSync(folder);
53
+ overWriteFile(`${folder}/${pck}.txt`, `${taxonomy}/\n${missingString}`);
54
+ } catch {
55
+ console.error('error generating files');
56
+ }
57
+ };
58
+
59
+ export const checkMissingPackages = async (options) => {
60
+ const { projectFolderPath, ignorePackagesGlobPattern, ignoreFilesGlobPattern } = options;
61
+ const ignorePatterns = ignorePackagesGlobPattern
62
+ .split(',')
63
+ .map((pattern) => (pattern && pattern !== '' ? generatePathFromCurrentFolder(pattern) : ''));
64
+ const ignoreMatches = ignoreFilesGlobPattern
65
+ .split(',')
66
+ .map((pattern) => (pattern && pattern !== '' ? generatePathFromCurrentFolder(pattern) : ''));
67
+ const depCheckOptions = {
68
+ ignoreBinPackage: false, // ignore the packages with bin entry
69
+ skipMissing: false, // skip calculation of missing dependencies
70
+ parsers: {
71
+ // the target parsers
72
+ '**/*.js': depcheck.parser.jsx,
73
+ '**/*.jsx': depcheck.parser.jsx,
74
+ '**/*.ts': depcheck.parser.typescript,
75
+ '**/*.tsx': depcheck.parser.typescript,
76
+ },
77
+ detectors: [
78
+ depcheck.detector.requireCallExpression,
79
+ depcheck.detector.requireResolveCallExpression,
80
+ depcheck.detector.importDeclaration,
81
+ depcheck.detector.typescriptImportType,
82
+ depcheck.detector.exportDeclaration,
83
+ ],
84
+ specials: [
85
+ // the target special parsers
86
+ depcheck.special.babel,
87
+ depcheck.special.bin,
88
+ depcheck.special.eslint,
89
+ depcheck.special.husky,
90
+ depcheck.special.jest,
91
+ depcheck.special.mocha,
92
+ depcheck.special.prettier,
93
+ depcheck.special.tslint,
94
+ depcheck.special.webpack,
95
+ ],
96
+ ignorePatterns,
97
+ ignoreMatches,
98
+ };
99
+ const pathToRoot = generatePathFromCurrentFolder(projectFolderPath);
100
+
101
+ depcheck(pathToRoot, depCheckOptions).then((unused) => {
102
+ const unusedDep = Array.isArray(unused.dependencies) && unused.dependencies.length > 0;
103
+ const unusedDevDep = Array.isArray(unused.devDependencies) && unused.devDependencies.length > 0;
104
+ const missing = Object.keys(unused.missing).length > 0;
105
+ const hasErrors = unusedDep || unusedDevDep || missing;
106
+ console.log(boldBrightCyanStr(`# Dependencies results for ${getPackageName()}`));
107
+ // console.log(boldBrightCyanStr(`[${pathToRoot}](${pathToRoot}package.json)`));
108
+ // if (unusedDep) logUnusedDep(unused);
109
+ // if (unusedDevDep) logUnusedDevDep(unused);
110
+ if (missing) logMissing(unused, pathToRoot);
111
+ if (!hasErrors) console.log(greenStr(`no problems found!`));
112
+ });
113
+ };
@@ -0,0 +1,43 @@
1
+ /* eslint-disable max-statements */
2
+ export function getPackageJsonEmDsVersions(packageJsonAsString = '') {
3
+ const dependenciesRegExp = /"dependencies": {(.*?)},?/gs;
4
+ const devDependenciesRegExp = /"devDependencies": {(.*?)},?/gs;
5
+ const peerDependenciesRegExp = /"peerDependencies": {(.*?)},?/gs;
6
+ const dsPackageRegExp = /"@elliemae\/ds-.*?": "(.*?)",?/gm;
7
+
8
+ const [dependenciesString] = packageJsonAsString.match(dependenciesRegExp) || [];
9
+ const [devDependenciesString] = packageJsonAsString.match(devDependenciesRegExp) || [];
10
+ const [peerDependenciesString] = packageJsonAsString.match(peerDependenciesRegExp) || [];
11
+
12
+ const matches = [];
13
+ const dependenciesMatches = [];
14
+ const devDependenciesMatches = [];
15
+ const peerDependenciesMatches = [];
16
+
17
+ if (dependenciesString) {
18
+ const depMatches = [...dependenciesString.matchAll(dsPackageRegExp)];
19
+ depMatches.forEach(([fullMatch, version]) => {
20
+ const matchObj = { fullMatch, version, dependencyType: 'dependency' };
21
+ matches.push(matchObj);
22
+ dependenciesMatches.push(matchObj);
23
+ });
24
+ }
25
+ if (devDependenciesString) {
26
+ const devDepMatches = [...devDependenciesString.matchAll(dsPackageRegExp)];
27
+ devDepMatches.forEach(([fullMatch, version]) => {
28
+ const matchObj = { fullMatch, version, dependencyType: 'devDependency' };
29
+ matches.push(matchObj);
30
+ devDependenciesMatches.push(matchObj);
31
+ });
32
+ }
33
+ if (peerDependenciesString) {
34
+ const peerDepMatches = [...peerDependenciesString.matchAll(dsPackageRegExp)];
35
+ peerDepMatches.forEach(([fullMatch, version]) => {
36
+ const matchObj = { fullMatch, version, dependencyType: 'peerDependency' };
37
+ matches.push(matchObj);
38
+ peerDependenciesMatches.push(matchObj);
39
+ });
40
+ }
41
+
42
+ return { matches, dependenciesMatches, devDependenciesMatches, peerDependenciesMatches };
43
+ }
@@ -0,0 +1,96 @@
1
+ /* eslint-disable max-len */
2
+ /* eslint-disable complexity */
3
+ /* eslint-disable max-statements */
4
+ import fs from 'fs';
5
+ import {
6
+ yellowStr,
7
+ boldBrightYellowBgRedStr,
8
+ brightYellowStr,
9
+ boldRedStr,
10
+ boldBrightCyanStr,
11
+ brightCyanStr,
12
+ brightGreenStr,
13
+ redStr,
14
+ } from '../../../utils/CLI_COLORS.mjs';
15
+ import { getPackageJsonEmDsVersions } from './getPackageJsonEmDsVersions.mjs';
16
+ import {
17
+ generatePathFromCurrentFolder,
18
+ globArray,
19
+ getHighestMatchVersion,
20
+ getLatestDimsumVersion,
21
+ } from '../../../utils/index.mjs';
22
+
23
+ const getErrors = (highestVersion, matches = []) => {
24
+ const errors = [];
25
+ let hasErrors = false;
26
+ matches.forEach((match) => {
27
+ const { version } = match;
28
+ if (version !== highestVersion.fullVersion) {
29
+ hasErrors = true;
30
+ errors.push({ ...match, suggestedVersion: highestVersion.fullVersion });
31
+ }
32
+ });
33
+ return { errors, hasErrors };
34
+ };
35
+ export const checkPackagesInconsistencies = async (options) => {
36
+ const csvGlobs = options.globPattern.split(',').map((pattern) => generatePathFromCurrentFolder(pattern));
37
+
38
+ const ignoredPatterns = options.globPatternIgnore.split(',');
39
+ const globOptions = { ignore: ignoredPatterns };
40
+
41
+ const pathToFileToProcess = globArray(csvGlobs, globOptions);
42
+ const { latestVersionParsed } = await getLatestDimsumVersion();
43
+
44
+ console.log(
45
+ brightCyanStr(
46
+ `detected latest dimsum version: ${yellowStr(`${latestVersionParsed.major}.${latestVersionParsed.minor}.X`)}`,
47
+ ),
48
+ );
49
+ pathToFileToProcess.forEach((path) => {
50
+ console.log(`checking ${path} for incosistencies...`);
51
+ const fileContent = fs.readFileSync(path, {
52
+ encoding: 'utf8',
53
+ flag: 'r',
54
+ });
55
+ if (fileContent && typeof fileContent === 'string') {
56
+ const { matches } = getPackageJsonEmDsVersions(fileContent);
57
+ if (matches) {
58
+ console.log(brightCyanStr(`Found dimsum dependencies:`), matches);
59
+ const highestVersion = getHighestMatchVersion(matches);
60
+ console.log(`checking for incosistencies...`);
61
+ const { errors, hasErrors } = getErrors(highestVersion, matches);
62
+
63
+ if (hasErrors) {
64
+ console.log(yellowStr('Your Package json has some Elliemae dimsum inconsistencies'));
65
+ console.log(errors);
66
+ console.log(yellowStr('Please solve them as soon as possible to avoid unexpected errors'));
67
+ } else {
68
+ console.log(yellowStr('no dimsum incosistencies detected!'));
69
+ }
70
+ console.log(`checking for outdated version...`);
71
+ const shouldUpdateToNewest =
72
+ highestVersion.major < latestVersionParsed.major ||
73
+ (highestVersion.major === latestVersionParsed.major && highestVersion.minor < latestVersionParsed.minor - 6);
74
+ if (shouldUpdateToNewest) {
75
+ console.log(boldBrightYellowBgRedStr('We detected that you are using a version that is too outdated'));
76
+ console.log(brightYellowStr(`Detected (highest) version:`, boldRedStr(highestVersion.fullVersion)));
77
+ console.log(brightYellowStr(`Latest version:`, boldBrightCyanStr(latestVersionParsed.fullVersion)));
78
+ console.log(boldBrightYellowBgRedStr('Please update to the newest version release as soon as possible!'));
79
+ } else {
80
+ console.log(yellowStr('you are using an aceptable dimsum version!'));
81
+ }
82
+ if (!hasErrors && !shouldUpdateToNewest) console.log(brightGreenStr('no immediate action is required!'));
83
+ if (highestVersion.minor !== latestVersionParsed.minor)
84
+ console.log(
85
+ brightYellowStr(
86
+ '\tstill, please consider updating to latest version as soon as possible to avoid more difficult updates in the future!',
87
+ ),
88
+ );
89
+ }
90
+ } else {
91
+ console.log(redStr(`failed to load package.json file, are you executing this in the right directory?`));
92
+ }
93
+ });
94
+ };
95
+
96
+ export default checkPackagesInconsistencies;
@@ -0,0 +1,31 @@
1
+ import { fixLegacyImports } from './fix-legacy-imports/index.mjs';
2
+ import { checkPackagesInconsistencies } from './check-packages-inconsistencies/index.mjs';
3
+ import { checkMissingPackages } from './check-missing-packages/index.mjs';
4
+ import { checkDeprecatedPackages } from './check-deprecated-packages/index.mjs';
5
+ import { helpMigrateToV3 } from './help-migrate-to-v3/index.mjs';
6
+ import { COMMANDS } from '../commands.mjs';
7
+
8
+ export async function executeCommandsMap(args, options) {
9
+ switch (options.script) {
10
+ case COMMANDS.FIX_LEGACY_IMPORTS:
11
+ fixLegacyImports(options);
12
+ break;
13
+ case COMMANDS.FIX_LEGACY_IMPORTS_REVERT:
14
+ fixLegacyImports(options, true);
15
+ break;
16
+ case COMMANDS.CHECK_PACKAGES_INCONSISTENCIES:
17
+ checkPackagesInconsistencies(options);
18
+ break;
19
+ case COMMANDS.CHECK_MISSING_PACKAGES:
20
+ checkMissingPackages(options);
21
+ break;
22
+ case COMMANDS.CHECK_DEPRECATED_PACKAGES:
23
+ checkDeprecatedPackages(options);
24
+ break;
25
+ case COMMANDS.HELP_MIGRATE_TO_V3:
26
+ helpMigrateToV3(options);
27
+ break;
28
+ default:
29
+ break;
30
+ }
31
+ }
@@ -0,0 +1,29 @@
1
+ import fs from 'fs';
2
+ import fse from 'fs-extra';
3
+ import { generatePathFromCurrentFolder, replaceFromMap, globArray } from '../../../utils/index.mjs';
4
+ import { legacyImportMap, legacyImportMapRevert } from './legacyImportMap.mjs';
5
+
6
+ export const fixLegacyImports = (options, isRevert = false) => {
7
+ const csvGlobs = options.globPattern.split(',').map((pattern) => generatePathFromCurrentFolder(pattern));
8
+
9
+ const ignoredPatterns = options.globPatternIgnore.split(',');
10
+ const globOptions = { ignore: ignoredPatterns };
11
+
12
+ const pathToFileToProcess = globArray(csvGlobs, globOptions);
13
+
14
+ const replaceMap = isRevert ? legacyImportMapRevert : legacyImportMap;
15
+ console.log('replaceMap :>> ', replaceMap);
16
+ pathToFileToProcess.forEach((path) => {
17
+ console.log('path :>> ', path);
18
+ const fileContent = fs.readFileSync(path, {
19
+ encoding: 'utf8',
20
+ flag: 'r',
21
+ });
22
+ if (fileContent && typeof fileContent === 'string') {
23
+ const newContent = replaceFromMap(fileContent, replaceMap);
24
+ fse.outputFileSync(path, newContent);
25
+ }
26
+ });
27
+ };
28
+
29
+ export default fixLegacyImports;