@machinemetrics/mm-react-components 0.2.3-5 → 0.2.3-6
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/dist/scripts/chakra-to-shadcn-migrator/chakra-to-shadcn.config.json +536 -0
- package/dist/scripts/chakra-to-shadcn-migrator/lib/args.js +63 -0
- package/dist/scripts/chakra-to-shadcn-migrator/lib/colors.js +14 -0
- package/dist/scripts/chakra-to-shadcn-migrator/lib/config.js +15 -0
- package/dist/scripts/chakra-to-shadcn-migrator/lib/deps.js +105 -0
- package/dist/scripts/chakra-to-shadcn-migrator/lib/file-io.js +44 -0
- package/dist/scripts/chakra-to-shadcn-migrator/lib/render.js +89 -0
- package/dist/scripts/chakra-to-shadcn-migrator/lib/transform.js +550 -0
- package/dist/scripts/chakra-to-shadcn-migrator/package.json +11 -0
- package/dist/tailwind.base.config.js +88 -0
- package/package.json +4 -4
- package/scripts/init.cjs +1 -1
- /package/{scripts → dist/scripts}/chakra-to-shadcn-migrator/bin/chakra-to-shadcn.js +0 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
export function updateDependencies(projectRoot, config, apply) {
|
|
5
|
+
const pkgPath = path.join(projectRoot, 'package.json');
|
|
6
|
+
const report = {
|
|
7
|
+
packageFound: fs.existsSync(pkgPath),
|
|
8
|
+
removed: [],
|
|
9
|
+
devRemoved: [],
|
|
10
|
+
added: [],
|
|
11
|
+
devAdded: [],
|
|
12
|
+
};
|
|
13
|
+
if (!report.packageFound) return report;
|
|
14
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
15
|
+
const deps = { ...(pkg.dependencies ?? {}) };
|
|
16
|
+
const devDeps = { ...(pkg.devDependencies ?? {}) };
|
|
17
|
+
|
|
18
|
+
for (const dep of config.dependenciesToRemove ?? []) {
|
|
19
|
+
if (dep in deps) {
|
|
20
|
+
report.removed.push({
|
|
21
|
+
name: dep,
|
|
22
|
+
from: 'dependencies',
|
|
23
|
+
version: deps[dep],
|
|
24
|
+
});
|
|
25
|
+
if (apply) delete deps[dep];
|
|
26
|
+
}
|
|
27
|
+
if (dep in devDeps) {
|
|
28
|
+
report.devRemoved.push({
|
|
29
|
+
name: dep,
|
|
30
|
+
from: 'devDependencies',
|
|
31
|
+
version: devDeps[dep],
|
|
32
|
+
});
|
|
33
|
+
if (apply) delete devDeps[dep];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
for (const [dep, version] of Object.entries(config.dependenciesToAdd ?? {})) {
|
|
38
|
+
if (deps[dep] !== version) {
|
|
39
|
+
report.added.push({ name: dep, version });
|
|
40
|
+
if (apply) deps[dep] = version;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for (const [dep, version] of Object.entries(
|
|
45
|
+
config.devDependenciesToAdd ?? {},
|
|
46
|
+
)) {
|
|
47
|
+
if (devDeps[dep] !== version) {
|
|
48
|
+
report.devAdded.push({ name: dep, version });
|
|
49
|
+
if (apply) devDeps[dep] = version;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (apply) {
|
|
54
|
+
const next = { ...pkg };
|
|
55
|
+
next.dependencies = Object.keys(deps).length ? deps : undefined;
|
|
56
|
+
next.devDependencies = Object.keys(devDeps).length ? devDeps : undefined;
|
|
57
|
+
fs.writeFileSync(pkgPath, `${JSON.stringify(next, null, 2)}\n`, 'utf8');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return report;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function renderDependencyReport(report, applied, { bold, colorize }) {
|
|
64
|
+
console.log(bold('\nStep 1 – Align npm dependencies'));
|
|
65
|
+
if (!report.packageFound) {
|
|
66
|
+
console.log(colorize(' package.json not found in project root.', 'red'));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (
|
|
70
|
+
!report.removed.length &&
|
|
71
|
+
!report.devRemoved.length &&
|
|
72
|
+
!report.added.length &&
|
|
73
|
+
!report.devAdded.length
|
|
74
|
+
) {
|
|
75
|
+
console.log(colorize(' No dependency changes required.', 'gray'));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const printEntries = (entries, verb) => {
|
|
80
|
+
for (const entry of entries) {
|
|
81
|
+
const where = entry.from ? ` (${entry.from})` : '';
|
|
82
|
+
console.log(
|
|
83
|
+
` - ${verb} ${colorize(entry.name, 'green')}${where}${entry.version ? ` @ ${entry.version}` : ''}`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
if (!applied) {
|
|
89
|
+
if (report.removed.length || report.devRemoved.length) {
|
|
90
|
+
console.log(colorize(' Remove Chakra packages:', 'yellow'));
|
|
91
|
+
printEntries([...report.removed, ...report.devRemoved], 'remove');
|
|
92
|
+
}
|
|
93
|
+
if (report.added.length || report.devAdded.length) {
|
|
94
|
+
console.log(colorize(' Add Shadcn packages:', 'yellow'));
|
|
95
|
+
printEntries([...report.added, ...report.devAdded], 'add');
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
if (report.removed.length || report.devRemoved.length) {
|
|
99
|
+
printEntries([...report.removed, ...report.devRemoved], 'removed');
|
|
100
|
+
}
|
|
101
|
+
if (report.added.length || report.devAdded.length) {
|
|
102
|
+
printEntries([...report.added, ...report.devAdded], 'added');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
export function collectSourceFiles(projectRoot, customSources, includeTests) {
|
|
5
|
+
const roots = customSources?.length ? customSources : ['src'];
|
|
6
|
+
const files = [];
|
|
7
|
+
const ignoredFolders = new Set([
|
|
8
|
+
'node_modules',
|
|
9
|
+
'.git',
|
|
10
|
+
'dist',
|
|
11
|
+
'build',
|
|
12
|
+
'coverage',
|
|
13
|
+
'.turbo',
|
|
14
|
+
'.next',
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
for (const rootRelative of roots) {
|
|
18
|
+
const rootPath = path.join(projectRoot, rootRelative);
|
|
19
|
+
if (!fs.existsSync(rootPath)) continue;
|
|
20
|
+
walk(rootPath);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function walk(current) {
|
|
24
|
+
const stat = fs.statSync(current);
|
|
25
|
+
if (stat.isDirectory()) {
|
|
26
|
+
const base = path.basename(current);
|
|
27
|
+
if (ignoredFolders.has(base)) return;
|
|
28
|
+
const entries = fs.readdirSync(current);
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
walk(path.join(current, entry));
|
|
31
|
+
}
|
|
32
|
+
} else if (stat.isFile()) {
|
|
33
|
+
if (!/\.[tj]sx?$/.test(current)) return;
|
|
34
|
+
const relative = path.relative(projectRoot, current);
|
|
35
|
+
if (!includeTests) {
|
|
36
|
+
if (relative.includes('__tests__')) return;
|
|
37
|
+
if (/\.test\.|\.spec\.|\.stories\./.test(relative)) return;
|
|
38
|
+
}
|
|
39
|
+
files.push({ absolute: current, relative });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return files;
|
|
44
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export function renderProviderInstructions(config, { bold }) {
|
|
2
|
+
const instructions = config.providerInstructions ?? [];
|
|
3
|
+
if (!instructions.length) return;
|
|
4
|
+
console.log(bold('\nStep 2 – Update top-level providers'));
|
|
5
|
+
instructions.forEach((text, index) => {
|
|
6
|
+
console.log(` ${index + 1}. ${text}`);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function renderPostSteps(config, { bold }) {
|
|
11
|
+
const steps = config.postSteps ?? [];
|
|
12
|
+
if (!steps.length) return;
|
|
13
|
+
console.log(bold('\nStep 4 – Finish up'));
|
|
14
|
+
steps.forEach((step, index) => {
|
|
15
|
+
console.log(` ${index + 1}. ${step}`);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function renderImportReport(reports, applyMode, config, { colorize }) {
|
|
20
|
+
if (!reports.length) {
|
|
21
|
+
console.log(
|
|
22
|
+
colorize(' No Chakra imports were found in the scanned files.', 'gray'),
|
|
23
|
+
);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
for (const fileReport of reports) {
|
|
27
|
+
console.log(`\n • ${colorize(fileReport.file, 'cyan')}`);
|
|
28
|
+
for (const moduleInfo of fileReport.modules) {
|
|
29
|
+
const { module, convertible, manual, missingConfig, skipped } =
|
|
30
|
+
moduleInfo;
|
|
31
|
+
if (missingConfig) {
|
|
32
|
+
console.log(
|
|
33
|
+
` - ${colorize('No mapping config for', 'red')} ${module}.`,
|
|
34
|
+
);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (moduleInfo.jsxReplaced?.length) {
|
|
38
|
+
console.log(
|
|
39
|
+
` - ${colorize('JSX replaced', 'green')}: ${moduleInfo.jsxReplaced.join(', ')}`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
if (moduleInfo.compoundTransformed?.length) {
|
|
43
|
+
console.log(
|
|
44
|
+
` - ${colorize('Compound components', 'green')}: ${moduleInfo.compoundTransformed.join(', ')}`,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
if (manual?.length) {
|
|
48
|
+
const names = manual
|
|
49
|
+
.map((spec) => spec.local || spec.imported)
|
|
50
|
+
.join(', ');
|
|
51
|
+
console.log(
|
|
52
|
+
` - ${colorize('Manual follow-up required', 'yellow')}: ${names}`,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
if (convertible?.length) {
|
|
56
|
+
const names = convertible
|
|
57
|
+
.map(({ specifier, mapping }) => {
|
|
58
|
+
const target =
|
|
59
|
+
mapping.module ??
|
|
60
|
+
config.moduleMappings?.[module]?.default?.module ??
|
|
61
|
+
'n/a';
|
|
62
|
+
const rename =
|
|
63
|
+
mapping.import && mapping.import !== specifier.local
|
|
64
|
+
? ` → ${mapping.import}`
|
|
65
|
+
: '';
|
|
66
|
+
return `${specifier.local}${rename} (${target})`;
|
|
67
|
+
})
|
|
68
|
+
.join(', ');
|
|
69
|
+
console.log(` - ${colorize('Mapped', 'green')} ${names}`);
|
|
70
|
+
}
|
|
71
|
+
if (applyMode && skipped) {
|
|
72
|
+
console.log(
|
|
73
|
+
` - ${colorize('Skipped automatic rewrite', 'red')} – unresolved specifiers remain.`,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (fileReport.importsRemoved?.length) {
|
|
78
|
+
const allRemoved = fileReport.importsRemoved
|
|
79
|
+
.flatMap((r) => r.specifiers)
|
|
80
|
+
.join(', ');
|
|
81
|
+
console.log(
|
|
82
|
+
` - ${colorize('Removed unused imports', 'gray')}: ${allRemoved}`,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
if (applyMode && fileReport.applied) {
|
|
86
|
+
console.log(` ${colorize('✔ Imports/JSX rewritten', 'green')}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|