@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.
- package/bin/cli/code-mods/cli.mjs +34 -0
- package/bin/cli/code-mods/command-arguments/promptCheckEmPackagesInconsistencies.mjs +22 -0
- package/bin/cli/code-mods/command-arguments/promptDeprecatedPackages.mjs +13 -0
- package/bin/cli/code-mods/command-arguments/promptFixLegacyImports.mjs +21 -0
- package/bin/cli/code-mods/command-arguments/promptHelpMigrateToV3.mjs +21 -0
- package/bin/cli/code-mods/command-arguments/promptMissingPackages.mjs +29 -0
- package/bin/cli/code-mods/command-logics/check-deprecated-packages/constants.mjs +87 -0
- package/bin/cli/code-mods/command-logics/check-deprecated-packages/getEmDsPackagesFromNPMLS.mjs +18 -0
- package/bin/cli/code-mods/command-logics/check-deprecated-packages/index.mjs +19 -0
- package/bin/cli/code-mods/command-logics/check-deprecated-packages/logResults.mjs +35 -0
- package/bin/cli/code-mods/command-logics/check-missing-packages/index.mjs +113 -0
- package/bin/cli/code-mods/command-logics/check-packages-inconsistencies/getPackageJsonEmDsVersions.mjs +43 -0
- package/bin/cli/code-mods/command-logics/check-packages-inconsistencies/index.mjs +96 -0
- package/bin/cli/code-mods/command-logics/execute-commands-map.mjs +31 -0
- package/bin/cli/code-mods/command-logics/fix-legacy-imports/index.mjs +29 -0
- package/bin/cli/code-mods/command-logics/fix-legacy-imports/legacyImportMap.mjs +105 -0
- package/bin/cli/code-mods/command-logics/help-migrate-to-v3/constants.mjs +284 -0
- package/bin/cli/code-mods/command-logics/help-migrate-to-v3/getSolutions.mjs +106 -0
- package/bin/cli/code-mods/command-logics/help-migrate-to-v3/index.mjs +90 -0
- package/bin/cli/code-mods/command-logics/help-migrate-to-v3/logMatch.mjs +39 -0
- package/bin/cli/code-mods/command-logics/help-migrate-to-v3/matchDsBasicImports.mjs +20 -0
- package/bin/cli/code-mods/command-logics/help-migrate-to-v3/replaceFromSolutions.mjs +15 -0
- package/bin/cli/code-mods/commands.mjs +11 -0
- package/bin/cli/code-mods/inquirer-questions-prompter.mjs +60 -0
- package/bin/cli/utils/CLI_COLORS.mjs +81 -0
- package/bin/cli/utils/generatePathFromCurrentFolder.mjs +11 -0
- package/bin/cli/utils/getLatestDimsumVersion.mjs +15 -0
- package/bin/cli/utils/globArray.mjs +11 -0
- package/bin/cli/utils/index.mjs +5 -0
- package/bin/cli/utils/matchHelpers.mjs +38 -0
- package/bin/cli/utils/replaceFromMap.mjs +15 -0
- package/bin/ds-codemods.mjs +4 -0
- package/package.json +55 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const replaceFromSolutions = (fileContent, solutions) => {
|
|
2
|
+
let finalString = fileContent;
|
|
3
|
+
if (typeof fileContent !== 'string' || !Array.isArray(solutions)) {
|
|
4
|
+
const error = `expected string, array arguments but received ${typeof fileContent}, ${typeof solutions}`;
|
|
5
|
+
console.error(error);
|
|
6
|
+
throw new Error(`expected string, array arguments but received ${typeof fileContent}, ${typeof solutions}`);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
solutions.forEach(({ fullMatch, solution }) => {
|
|
10
|
+
finalString = finalString.split(fullMatch).join(solution);
|
|
11
|
+
});
|
|
12
|
+
return finalString;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default replaceFromSolutions;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const COMMANDS = {
|
|
2
|
+
FIX_LEGACY_IMPORTS: 'fix-legacy-imports',
|
|
3
|
+
FIX_LEGACY_IMPORTS_REVERT: 'fix-legacy-imports:revert',
|
|
4
|
+
CHECK_DEPRECATED_PACKAGES: 'check-deprecated-packages',
|
|
5
|
+
CHECK_PACKAGES_INCONSISTENCIES: 'check-packages-inconsistencies',
|
|
6
|
+
CHECK_MISSING_PACKAGES: 'check-missing-packages',
|
|
7
|
+
HELP_MIGRATE_TO_V3: 'help-migrate-to-v3',
|
|
8
|
+
EXIT: 'exit',
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const COMMANDS_ARRAY = Object.values(COMMANDS);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import inquirer from 'inquirer';
|
|
2
|
+
import { COMMANDS, COMMANDS_ARRAY } from './commands.mjs';
|
|
3
|
+
import { getLegacyImportsQuestions } from './command-arguments/promptFixLegacyImports.mjs';
|
|
4
|
+
import { getPackagesInconsistenciesQuestions } from './command-arguments/promptCheckEmPackagesInconsistencies.mjs';
|
|
5
|
+
import { getDeprecatedPackagesQuestions } from './command-arguments/promptDeprecatedPackages.mjs';
|
|
6
|
+
import { getHelpMigrateToV3Questions } from './command-arguments/promptHelpMigrateToV3.mjs';
|
|
7
|
+
import { getMissingPackagesQuestions } from './command-arguments/promptMissingPackages.mjs';
|
|
8
|
+
|
|
9
|
+
async function promptForMissingScriptSpecificOptions({ originalOptions, promptOptions }) {
|
|
10
|
+
const script = originalOptions.script || promptOptions.script;
|
|
11
|
+
const scriptQuestions = [];
|
|
12
|
+
switch (script) {
|
|
13
|
+
case COMMANDS.FIX_LEGACY_IMPORTS_REVERT:
|
|
14
|
+
case COMMANDS.FIX_LEGACY_IMPORTS:
|
|
15
|
+
scriptQuestions.push(...getLegacyImportsQuestions(originalOptions));
|
|
16
|
+
break;
|
|
17
|
+
case COMMANDS.CHECK_PACKAGES_INCONSISTENCIES:
|
|
18
|
+
scriptQuestions.push(...getPackagesInconsistenciesQuestions(originalOptions));
|
|
19
|
+
break;
|
|
20
|
+
case COMMANDS.CHECK_MISSING_PACKAGES:
|
|
21
|
+
scriptQuestions.push(...getMissingPackagesQuestions(originalOptions));
|
|
22
|
+
break;
|
|
23
|
+
case COMMANDS.CHECK_DEPRECATED_PACKAGES:
|
|
24
|
+
scriptQuestions.push(...getDeprecatedPackagesQuestions(originalOptions));
|
|
25
|
+
break;
|
|
26
|
+
case COMMANDS.HELP_MIGRATE_TO_V3:
|
|
27
|
+
scriptQuestions.push(...getHelpMigrateToV3Questions(originalOptions));
|
|
28
|
+
break;
|
|
29
|
+
default:
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const answers = await inquirer.prompt(scriptQuestions);
|
|
34
|
+
return {
|
|
35
|
+
...originalOptions,
|
|
36
|
+
...promptOptions,
|
|
37
|
+
...answers,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function promptForMissingOptions(options) {
|
|
42
|
+
const questions = [];
|
|
43
|
+
if (!options.script) {
|
|
44
|
+
questions.push({
|
|
45
|
+
type: 'list',
|
|
46
|
+
name: 'script',
|
|
47
|
+
message: 'Please choose which command to run',
|
|
48
|
+
choices: COMMANDS_ARRAY,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const answers = await inquirer.prompt(questions);
|
|
52
|
+
const scriptSpecificAnswears = await promptForMissingScriptSpecificOptions({
|
|
53
|
+
originalOptions: { ...options },
|
|
54
|
+
promptOptions: { ...answers },
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
...scriptSpecificAnswears,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
|
2
|
+
export const CLI_COLORS = {
|
|
3
|
+
reset: '\x1b[0m',
|
|
4
|
+
bold: '\x1b[1m',
|
|
5
|
+
dim: '\x1b[2m',
|
|
6
|
+
underline: '\x1b[4m',
|
|
7
|
+
strikethrough: '\x1b[9m',
|
|
8
|
+
black: '\x1b[30m',
|
|
9
|
+
red: '\x1b[31m',
|
|
10
|
+
green: '\x1b[32m',
|
|
11
|
+
yellow: '\x1b[33m',
|
|
12
|
+
blue: '\x1b[34m',
|
|
13
|
+
magenta: '\x1b[35m',
|
|
14
|
+
cyan: '\x1b[36m',
|
|
15
|
+
white: '\x1b[37m',
|
|
16
|
+
gray: '\x1b[90m',
|
|
17
|
+
brightRed: '\x1b[91m',
|
|
18
|
+
brightGreen: '\x1b[92m',
|
|
19
|
+
brightYellow: '\x1b[93m',
|
|
20
|
+
brightBlue: '\x1b[94m',
|
|
21
|
+
brightMagenta: '\x1b[95m',
|
|
22
|
+
brightCyan: '\x1b[96m',
|
|
23
|
+
brightWhite: '\x1b[97m',
|
|
24
|
+
bgBlack: '\x1b[40m',
|
|
25
|
+
bgRed: '\x1b[41m',
|
|
26
|
+
bgGreen: '\x1b[42m',
|
|
27
|
+
bgYellow: '\x1b[43m',
|
|
28
|
+
bgBlue: '\x1b[44m',
|
|
29
|
+
bgMagenta: '\x1b[45m',
|
|
30
|
+
bgCyan: '\x1b[46m',
|
|
31
|
+
bgWhite: '\x1b[47m',
|
|
32
|
+
bgGray: '\x1b[100m',
|
|
33
|
+
bgBrightRed: '\x1b[101m',
|
|
34
|
+
bgBrightGreen: '\x1b[102m',
|
|
35
|
+
bgBrightYellow: '\x1b[103m',
|
|
36
|
+
bgBrightBlue: '\x1b[104m',
|
|
37
|
+
bgBrightMagenta: '\x1b[105m',
|
|
38
|
+
bgBrightCyan: '\x1b[106m',
|
|
39
|
+
bgBrightWhite: '\x1b[107m',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const {
|
|
43
|
+
bold,
|
|
44
|
+
brightYellow,
|
|
45
|
+
red,
|
|
46
|
+
cyan,
|
|
47
|
+
green,
|
|
48
|
+
white,
|
|
49
|
+
yellow,
|
|
50
|
+
bgRed,
|
|
51
|
+
reset,
|
|
52
|
+
brightRed,
|
|
53
|
+
brightCyan,
|
|
54
|
+
brightMagenta,
|
|
55
|
+
brightGreen,
|
|
56
|
+
} = CLI_COLORS;
|
|
57
|
+
export const boldBrightYellowBgRedStr = (str) => `${bold}${brightYellow}${bgRed}${str}${reset}`;
|
|
58
|
+
|
|
59
|
+
export const boldBrightRedStr = (str) => `${bold}${brightRed}${str}${reset}`;
|
|
60
|
+
export const boldRedStr = (str) => `${bold}${red}${str}${reset}`;
|
|
61
|
+
export const boldBrightCyanStr = (str) => `${bold}${brightCyan}${str}${reset}`;
|
|
62
|
+
export const boldCyanStr = (str) => `${bold}${cyan}${str}${reset}`;
|
|
63
|
+
export const boldGreenStr = (str) => `${bold}${green}${str}${reset}`;
|
|
64
|
+
|
|
65
|
+
export const brightGreenStr = (str) => `${brightGreen}${str}${reset}`;
|
|
66
|
+
export const brightRedStr = (str) => `${brightRed}${str}${reset}`;
|
|
67
|
+
export const brightMagentaStr = (str) => `${brightMagenta}${str}${reset}`;
|
|
68
|
+
export const brightCyanStr = (str) => `${brightCyan}${str}${reset}`;
|
|
69
|
+
export const brightYellowStr = (str) => `${brightYellow}${str}${reset}`;
|
|
70
|
+
|
|
71
|
+
export const greenStr = (str) => `${green}${str}${reset}`;
|
|
72
|
+
export const redStr = (str) => `${red}${str}${reset}`;
|
|
73
|
+
export const whiteStr = (str) => `${white}${str}${reset}`;
|
|
74
|
+
export const yellowStr = (str) => `${yellow}${str}${reset}`;
|
|
75
|
+
|
|
76
|
+
export const severityLoggingMap = {
|
|
77
|
+
1: boldBrightYellowBgRedStr,
|
|
78
|
+
2: boldBrightRedStr,
|
|
79
|
+
3: boldRedStr,
|
|
80
|
+
4: redStr,
|
|
81
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
/**
|
|
3
|
+
* prepend process.cwd() to a string and convert to POSIX (glob compatible) slashes ( \ -- to --> /).
|
|
4
|
+
*
|
|
5
|
+
* @param {string} stringToPrependTo the string to prepend the CWD and make glob compatible
|
|
6
|
+
* @returns {string} paths with prepent CWD and glob compatible POSIX slashes ( \ -- to --> /).
|
|
7
|
+
*/
|
|
8
|
+
export const generatePathFromCurrentFolder = (...stringToPrependTo) =>
|
|
9
|
+
path.join(process.cwd(), ...stringToPrependTo).replace(/\\/g, '/');
|
|
10
|
+
|
|
11
|
+
export default generatePathFromCurrentFolder;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import pacote from 'pacote';
|
|
2
|
+
import { getVersions } from './matchHelpers.mjs';
|
|
3
|
+
|
|
4
|
+
export const getLatestDimsumVersion = async () => {
|
|
5
|
+
const packageInfos = await pacote.packument('@elliemae/ds-legacy-button');
|
|
6
|
+
const distTags = packageInfos['dist-tags'];
|
|
7
|
+
const latestVersion = distTags.latest;
|
|
8
|
+
const latestVersionParsed = getVersions(latestVersion);
|
|
9
|
+
return {
|
|
10
|
+
packageInfos,
|
|
11
|
+
distTags,
|
|
12
|
+
latestVersion,
|
|
13
|
+
latestVersionParsed,
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { glob } from 'glob';
|
|
2
|
+
|
|
3
|
+
export const globArray = (globPatterns, globOptions = {}) => {
|
|
4
|
+
if (!Array.isArray(globPatterns)) {
|
|
5
|
+
throw new Error('array of glob patterns required but not received');
|
|
6
|
+
}
|
|
7
|
+
const patternsResults = globPatterns.map((globPattern) => glob.sync(globPattern, globOptions));
|
|
8
|
+
return [].concat(...patternsResults);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default globArray;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* eslint-disable complexity */
|
|
2
|
+
/* eslint-disable max-statements */
|
|
3
|
+
export function getVersions(fullVersion) {
|
|
4
|
+
const [majorAsString, minorAsString, buildWithTag = '', tagRevisionAsString] = fullVersion.split('.');
|
|
5
|
+
const [buildAsString, tag] = buildWithTag.split('-');
|
|
6
|
+
const major = Number.parseInt(majorAsString, 10);
|
|
7
|
+
const minor = Number.parseInt(minorAsString, 10);
|
|
8
|
+
const build = Number.parseInt(buildAsString, 10);
|
|
9
|
+
const tagRevision = tagRevisionAsString ? Number.parseInt(tagRevisionAsString, 10) : undefined;
|
|
10
|
+
return { fullVersion, major, minor, build, tag, tagRevision };
|
|
11
|
+
}
|
|
12
|
+
export function getMatchVersions(match = {}) {
|
|
13
|
+
const fullVersion = match.version || '';
|
|
14
|
+
return getVersions(fullVersion);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getHighestMatchVersion(matches = []) {
|
|
18
|
+
const highestVersion = {};
|
|
19
|
+
matches.forEach((match) => {
|
|
20
|
+
const versions = getMatchVersions(match);
|
|
21
|
+
const { fullVersion, major, minor, build, tag, tagRevision } = versions;
|
|
22
|
+
|
|
23
|
+
const isCurrentHigher =
|
|
24
|
+
!highestVersion.fullVersion ||
|
|
25
|
+
major > highestVersion.major ||
|
|
26
|
+
(highestVersion.major === major && minor > highestVersion.minor) ||
|
|
27
|
+
(highestVersion.major === major && minor === highestVersion.minor && build > highestVersion.build);
|
|
28
|
+
if (isCurrentHigher) {
|
|
29
|
+
highestVersion.fullVersion = fullVersion;
|
|
30
|
+
highestVersion.major = major;
|
|
31
|
+
highestVersion.minor = minor;
|
|
32
|
+
highestVersion.build = build;
|
|
33
|
+
highestVersion.tag = tag;
|
|
34
|
+
highestVersion.tagRevision = tagRevision;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return highestVersion;
|
|
38
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const replaceFromMap = (originString, replacementMap) => {
|
|
2
|
+
let finalString = originString;
|
|
3
|
+
if (typeof originString !== 'string' || typeof replacementMap !== 'object') {
|
|
4
|
+
const error = `expected string, object arguments but received ${typeof originString}, ${typeof replacementMap}`;
|
|
5
|
+
console.error(error);
|
|
6
|
+
throw new Error(`expected string, object arguments but received ${typeof originString}, ${typeof replacementMap}`);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
Object.entries(replacementMap).forEach(([find, replace]) => {
|
|
10
|
+
finalString = finalString.split(find).join(replace);
|
|
11
|
+
});
|
|
12
|
+
return finalString;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default replaceFromMap;
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elliemae/ds-legacy-codemods",
|
|
3
|
+
"version": "1.0.0-rc.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "ICE MT - Dimsum - Code Mods",
|
|
6
|
+
"files": [
|
|
7
|
+
"bin"
|
|
8
|
+
],
|
|
9
|
+
"bin": {
|
|
10
|
+
"@elliemae/ds-legacy-codemods": "./bin/ds-codemods.mjs",
|
|
11
|
+
"ds-codemods": "./bin/ds-codemods.mjs"
|
|
12
|
+
},
|
|
13
|
+
"sideEffects": [
|
|
14
|
+
"*.css",
|
|
15
|
+
"*.scss"
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://git.elliemae.io/platform-ui/dimsum-legacy.git"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"pnpm": ">=8",
|
|
23
|
+
"node": ">=18"
|
|
24
|
+
},
|
|
25
|
+
"author": "ICE MT",
|
|
26
|
+
"jestSonar": {
|
|
27
|
+
"sonar56x": true,
|
|
28
|
+
"reportPath": "reports",
|
|
29
|
+
"reportFile": "tests.xml",
|
|
30
|
+
"indent": 4
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"arg": "~5.0.2",
|
|
34
|
+
"depcheck": "~1.4.3",
|
|
35
|
+
"fs": "~0.0.1-security",
|
|
36
|
+
"fs-extra": "~11.1.1",
|
|
37
|
+
"glob": "~10.2.5",
|
|
38
|
+
"inquirer": "~9.2.4",
|
|
39
|
+
"pacote": "~15.2.0",
|
|
40
|
+
"path": "~0.12.7"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public",
|
|
44
|
+
"typeSafety": false
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"try-codemods": "npx ./",
|
|
48
|
+
"dev:install": "pnpm --filter {.}... i --no-lockfile",
|
|
49
|
+
"eslint:fix": "eslint --ext='.js,.jsx,.test.js,.ts,.tsx' --fix --config='../../.eslintrc.js' bin/",
|
|
50
|
+
"try-check-deprecated-packages": "npx ./ check-deprecated-packages --cwd=\"test-ables/check-deprecated-packages/with-deprecated\"",
|
|
51
|
+
"try-check-deprecated-packages-no-dimsum": "npx ./ check-deprecated-packages --cwd=\"test-ables/check-deprecated-packages/without-dimsum-packages\"",
|
|
52
|
+
"try-help-migrate-to-v3": "npx ./ help-migrate-to-v3 --globPattern=\"test-ables/help-migrate-to-v3/**/*.js,./**/*.jsx,./**/*.ts,./**/*.tsx\" --globPatternIgnore=\"**/node_modules/**/*\"",
|
|
53
|
+
"checkDeps": "exit 0 | echo"
|
|
54
|
+
}
|
|
55
|
+
}
|