@machinemetrics/mm-react-components 0.2.3-2 → 0.2.3-21
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/README.md +89 -30
- package/agent-docs/agent-documentation-reference.md +364 -0
- package/agent-docs/ai-agent-guide.md +558 -0
- package/agent-docs/ai-agent-init-guide.md +465 -0
- package/agent-docs/chakra-migration-readme.md +265 -0
- package/agent-docs/chakra-migration-troubleshooting.md +649 -0
- package/agent-docs/component-mapping-reference.md +466 -0
- package/agent-docs/init-readme.md +283 -0
- package/agent-docs/init-troubleshooting.md +550 -0
- package/agent-docs/setup-reference.md +365 -0
- package/dist/App.d.ts.map +1 -1
- package/dist/README.md +89 -30
- package/dist/components/ui/alert-dialog.d.ts +15 -0
- package/dist/components/ui/alert-dialog.d.ts.map +1 -0
- package/dist/components/ui/alert.d.ts +10 -0
- package/dist/components/ui/alert.d.ts.map +1 -0
- package/dist/components/ui/avatar.d.ts +7 -0
- package/dist/components/ui/avatar.d.ts.map +1 -0
- package/dist/components/ui/breadcrumb.d.ts +12 -0
- package/dist/components/ui/breadcrumb.d.ts.map +1 -0
- package/dist/components/ui/button.d.ts.map +1 -1
- package/dist/components/ui/card.d.ts +10 -0
- package/dist/components/ui/card.d.ts.map +1 -0
- package/dist/components/ui/chart.d.ts +41 -0
- package/dist/components/ui/chart.d.ts.map +1 -0
- package/dist/components/ui/command.d.ts +19 -0
- package/dist/components/ui/command.d.ts.map +1 -0
- package/dist/components/ui/data-table/TableView.d.ts +1 -1
- package/dist/components/ui/data-table/TableView.d.ts.map +1 -1
- package/dist/components/ui/data-table/cards/ResponsiveTable.d.ts +1 -1
- package/dist/components/ui/data-table/cards/ResponsiveTable.d.ts.map +1 -1
- package/dist/components/ui/data-table/cards/RowCard.d.ts +2 -1
- package/dist/components/ui/data-table/cards/RowCard.d.ts.map +1 -1
- package/dist/components/ui/data-table/index.d.ts +3 -1
- package/dist/components/ui/data-table/index.d.ts.map +1 -1
- package/dist/components/ui/data-table/pagination.d.ts +3 -1
- package/dist/components/ui/data-table/pagination.d.ts.map +1 -1
- package/dist/components/ui/data-table/parts/BatchActionsToolbar.d.ts +7 -0
- package/dist/components/ui/data-table/parts/BatchActionsToolbar.d.ts.map +1 -0
- package/dist/components/ui/data-table/parts/CellContent.d.ts +7 -0
- package/dist/components/ui/data-table/parts/CellContent.d.ts.map +1 -0
- package/dist/components/ui/data-table/parts/ColGroup.d.ts +7 -0
- package/dist/components/ui/data-table/parts/ColGroup.d.ts.map +1 -0
- package/dist/components/ui/data-table/parts/SortableHeader.d.ts +13 -0
- package/dist/components/ui/data-table/parts/SortableHeader.d.ts.map +1 -0
- package/dist/components/ui/data-table/parts/TableBody.d.ts +11 -0
- package/dist/components/ui/data-table/parts/TableBody.d.ts.map +1 -0
- package/dist/components/ui/data-table/parts/TableHeader.d.ts +15 -0
- package/dist/components/ui/data-table/parts/TableHeader.d.ts.map +1 -0
- package/dist/components/ui/data-table/toolbar/DataTableToolbar.d.ts +2 -1
- package/dist/components/ui/data-table/toolbar/DataTableToolbar.d.ts.map +1 -1
- package/dist/components/ui/data-table/types.d.ts +33 -10
- package/dist/components/ui/data-table/types.d.ts.map +1 -1
- package/dist/components/ui/data-table/useTableController.d.ts +12 -1
- package/dist/components/ui/data-table/useTableController.d.ts.map +1 -1
- package/dist/components/ui/data-table/utils.d.ts +2 -0
- package/dist/components/ui/data-table/utils.d.ts.map +1 -1
- package/dist/components/ui/date-picker.d.ts +36 -0
- package/dist/components/ui/date-picker.d.ts.map +1 -0
- package/dist/components/ui/dropdown-menu.d.ts +1 -1
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -1
- package/dist/components/ui/form.d.ts +25 -0
- package/dist/components/ui/form.d.ts.map +1 -0
- package/dist/components/ui/hero-metric-card/HeroMetricCard.d.ts +4 -0
- package/dist/components/ui/hero-metric-card/HeroMetricCard.d.ts.map +1 -0
- package/dist/components/ui/hero-metric-card/HeroMetricCardItem.d.ts +4 -0
- package/dist/components/ui/hero-metric-card/HeroMetricCardItem.d.ts.map +1 -0
- package/dist/components/ui/hero-metric-card/constants.d.ts +13 -0
- package/dist/components/ui/hero-metric-card/constants.d.ts.map +1 -0
- package/dist/components/ui/hero-metric-card/grid.d.ts +4 -0
- package/dist/components/ui/hero-metric-card/grid.d.ts.map +1 -0
- package/dist/components/ui/hero-metric-card/hooks.d.ts +6 -0
- package/dist/components/ui/hero-metric-card/hooks.d.ts.map +1 -0
- package/dist/components/ui/hero-metric-card/index.d.ts +5 -0
- package/dist/components/ui/hero-metric-card/index.d.ts.map +1 -0
- package/dist/components/ui/hero-metric-card/parsing.d.ts +11 -0
- package/dist/components/ui/hero-metric-card/parsing.d.ts.map +1 -0
- package/dist/components/ui/hero-metric-card/refs.d.ts +3 -0
- package/dist/components/ui/hero-metric-card/refs.d.ts.map +1 -0
- package/dist/components/ui/hero-metric-card/trend.d.ts +4 -0
- package/dist/components/ui/hero-metric-card/trend.d.ts.map +1 -0
- package/dist/components/ui/hero-metric-card/types.d.ts +60 -0
- package/dist/components/ui/hero-metric-card/types.d.ts.map +1 -0
- package/dist/components/ui/hero-metric-card/utils.d.ts +10 -0
- package/dist/components/ui/hero-metric-card/utils.d.ts.map +1 -0
- package/dist/components/ui/pagination.d.ts +14 -0
- package/dist/components/ui/pagination.d.ts.map +1 -0
- package/dist/components/ui/progress.d.ts +1 -0
- package/dist/components/ui/progress.d.ts.map +1 -1
- package/dist/components/ui/separator.d.ts +5 -0
- package/dist/components/ui/separator.d.ts.map +1 -0
- package/dist/components/ui/simple-pagination.d.ts +8 -0
- package/dist/components/ui/simple-pagination.d.ts.map +1 -0
- package/dist/components/ui/sonner.d.ts +4 -0
- package/dist/components/ui/sonner.d.ts.map +1 -0
- package/dist/components/ui/spinner-carbide.d.ts +5 -0
- package/dist/components/ui/spinner-carbide.d.ts.map +1 -0
- package/dist/components/ui/spinner.d.ts +4 -0
- package/dist/components/ui/spinner.d.ts.map +1 -0
- package/dist/components/ui/textarea.d.ts +4 -0
- package/dist/components/ui/textarea.d.ts.map +1 -0
- package/dist/docs/GETTING_STARTED.md +13 -5
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/lib/mm-react-components.css +1 -0
- package/dist/main.d.ts +1 -2
- package/dist/main.d.ts.map +1 -1
- package/dist/mm-react-components.es.js +16740 -7065
- package/dist/mm-react-components.es.js.map +1 -1
- package/dist/mm-react-components.umd.js +28 -11
- package/dist/mm-react-components.umd.js.map +1 -1
- package/dist/preview/AlertDialogPreview.d.ts +2 -0
- package/dist/preview/AlertDialogPreview.d.ts.map +1 -0
- package/dist/preview/AlertPreview.d.ts +2 -0
- package/dist/preview/AlertPreview.d.ts.map +1 -0
- package/dist/preview/AvatarPreview.d.ts +2 -0
- package/dist/preview/AvatarPreview.d.ts.map +1 -0
- package/dist/preview/BreadcrumbPreview.d.ts +2 -0
- package/dist/preview/BreadcrumbPreview.d.ts.map +1 -0
- package/dist/preview/CardPreview.d.ts +2 -0
- package/dist/preview/CardPreview.d.ts.map +1 -0
- package/dist/preview/ChartPreview.d.ts +2 -0
- package/dist/preview/ChartPreview.d.ts.map +1 -0
- package/dist/preview/ColorsPreview.d.ts +7 -0
- package/dist/preview/ColorsPreview.d.ts.map +1 -0
- package/dist/preview/CommandPreview.d.ts +2 -0
- package/dist/preview/CommandPreview.d.ts.map +1 -0
- package/dist/preview/DataTablePreview.d.ts.map +1 -1
- package/dist/preview/DatePickerPreview.d.ts +2 -0
- package/dist/preview/DatePickerPreview.d.ts.map +1 -0
- package/dist/preview/DateRangePickerPreview.d.ts.map +1 -1
- package/dist/preview/FormPreview.d.ts +2 -0
- package/dist/preview/FormPreview.d.ts.map +1 -0
- package/dist/preview/HeroMetricCardPreview.d.ts +2 -0
- package/dist/preview/HeroMetricCardPreview.d.ts.map +1 -0
- package/dist/preview/PaginationPreview.d.ts +2 -0
- package/dist/preview/PaginationPreview.d.ts.map +1 -0
- package/dist/preview/SeparatorPreview.d.ts +2 -0
- package/dist/preview/SeparatorPreview.d.ts.map +1 -0
- package/dist/preview/SonnerPreview.d.ts +2 -0
- package/dist/preview/SonnerPreview.d.ts.map +1 -0
- package/dist/preview/SpinnerPreview.d.ts +2 -0
- package/dist/preview/SpinnerPreview.d.ts.map +1 -0
- package/dist/preview/TextareaPreview.d.ts +2 -0
- package/dist/preview/TextareaPreview.d.ts.map +1 -0
- package/dist/scripts/chakra-to-shadcn-migrator/chakra-to-shadcn.config.json +577 -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 +125 -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/scripts/init.cjs +216 -0
- package/dist/scripts/npx-init.cjs +418 -0
- package/dist/tailwind.base.config.js +89 -0
- package/dist/themes/carbide.css +369 -91
- package/package.json +40 -10
- package/src/index.css +111 -498
- package/dist/index.css +0 -536
- package/dist/themes/base.css +0 -536
- package/dist/themes/complete.css +0 -8
- package/scripts/README.md +0 -171
- package/scripts/chakra-to-shadcn-migrator/README.md +0 -107
- package/src/themes/base.css +0 -536
- package/src/themes/carbide.css +0 -1257
- package/src/themes/complete.css +0 -8
- /package/{scripts → dist/scripts}/chakra-to-shadcn-migrator/bin/chakra-to-shadcn.js +0 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MM React Components - Zero-Config Init Script
|
|
5
|
+
*
|
|
6
|
+
* Simple initialization script for the MachineMetrics React Components library
|
|
7
|
+
* Uses the zero-config approach with pre-compiled CSS (no build tools needed)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/* eslint-disable no-undef */
|
|
11
|
+
|
|
12
|
+
const { execSync } = require('child_process');
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
const path = require('path');
|
|
15
|
+
const readline = require('readline');
|
|
16
|
+
|
|
17
|
+
// Colors for console output
|
|
18
|
+
const colors = {
|
|
19
|
+
reset: '\x1b[0m',
|
|
20
|
+
bright: '\x1b[1m',
|
|
21
|
+
green: '\x1b[32m',
|
|
22
|
+
blue: '\x1b[34m',
|
|
23
|
+
cyan: '\x1b[36m',
|
|
24
|
+
yellow: '\x1b[33m',
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function log(message, color = 'reset') {
|
|
28
|
+
console.log(`${colors[color]}${message}${colors.reset}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function detectChakraUI() {
|
|
32
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
33
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
38
|
+
const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
deps['@chakra-ui/react'] ||
|
|
42
|
+
deps['@chakra-ui/core'] ||
|
|
43
|
+
deps['@chakra-ui/system']
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function askQuestion(question) {
|
|
48
|
+
const rl = readline.createInterface({
|
|
49
|
+
input: process.stdin,
|
|
50
|
+
output: process.stdout,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return new Promise((resolve) => {
|
|
54
|
+
rl.question(question, (answer) => {
|
|
55
|
+
rl.close();
|
|
56
|
+
resolve(answer);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function main() {
|
|
62
|
+
log('🚀 MM React Components - Zero-Config Setup', 'bright');
|
|
63
|
+
log(
|
|
64
|
+
'Installing MachineMetrics React Components with pre-compiled CSS...\n',
|
|
65
|
+
'blue',
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
// Check for Chakra UI before installation
|
|
70
|
+
const hasChakra = detectChakraUI();
|
|
71
|
+
|
|
72
|
+
// Install the component library
|
|
73
|
+
log('📦 Installing MM React Components...', 'cyan');
|
|
74
|
+
execSync('npm install @machinemetrics/mm-react-components@beta', {
|
|
75
|
+
stdio: 'inherit',
|
|
76
|
+
});
|
|
77
|
+
log('✅ MM React Components installed', 'green');
|
|
78
|
+
|
|
79
|
+
log('\n💡 Zero-config mode: No build tools needed!', 'yellow');
|
|
80
|
+
log(' Using pre-compiled CSS (118 KB, 18 KB gzipped)\n', 'cyan');
|
|
81
|
+
|
|
82
|
+
// Create simple CSS import (zero-config approach)
|
|
83
|
+
const srcPath = path.join(process.cwd(), 'src');
|
|
84
|
+
const indexCssPath = path.join(srcPath, 'index.css');
|
|
85
|
+
|
|
86
|
+
// Ensure src directory exists
|
|
87
|
+
if (!fs.existsSync(srcPath)) {
|
|
88
|
+
fs.mkdirSync(srcPath, { recursive: true });
|
|
89
|
+
log('✅ Created src/ directory', 'green');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (fs.existsSync(indexCssPath)) {
|
|
93
|
+
const cssContent = fs.readFileSync(indexCssPath, 'utf8');
|
|
94
|
+
if (!cssContent.includes('@machinemetrics/mm-react-components')) {
|
|
95
|
+
const newCssContent = `/* MM React Components - Pre-compiled CSS (zero-config) */
|
|
96
|
+
@import '@machinemetrics/mm-react-components/styles';
|
|
97
|
+
|
|
98
|
+
${cssContent}`;
|
|
99
|
+
fs.writeFileSync(indexCssPath, newCssContent);
|
|
100
|
+
log('✅ Added MM styles import to existing index.css', 'green');
|
|
101
|
+
} else {
|
|
102
|
+
log('✅ MM styles import already present in index.css', 'green');
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
const cssContent = `/* MM React Components - Pre-compiled CSS (zero-config) */
|
|
106
|
+
@import '@machinemetrics/mm-react-components/styles';
|
|
107
|
+
`;
|
|
108
|
+
|
|
109
|
+
fs.writeFileSync(indexCssPath, cssContent);
|
|
110
|
+
log('✅ Created index.css with MM styles import', 'green');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Success message
|
|
114
|
+
log('\n🎉 Zero-Config Setup Complete!', 'green');
|
|
115
|
+
log('\n📚 Next steps:', 'bright');
|
|
116
|
+
log(' 1. Add Carbide class to your root element:');
|
|
117
|
+
log(' document.documentElement.classList.add("carbide")', 'cyan');
|
|
118
|
+
log(' 2. Import components:');
|
|
119
|
+
log(
|
|
120
|
+
' import { Button, Input } from "@machinemetrics/mm-react-components"',
|
|
121
|
+
'cyan',
|
|
122
|
+
);
|
|
123
|
+
log(' 3. Use components - everything is pre-styled and ready!');
|
|
124
|
+
|
|
125
|
+
log('\n✅ What you got:', 'bright');
|
|
126
|
+
log(' • Pre-compiled CSS with all Tailwind utilities');
|
|
127
|
+
log(' • Carbide industrial theme');
|
|
128
|
+
log(' • Dark mode support');
|
|
129
|
+
log(' • All component styles (focus, hover, etc.)');
|
|
130
|
+
log(' • Google Fonts included');
|
|
131
|
+
|
|
132
|
+
log('\n💡 No build tools needed!', 'yellow');
|
|
133
|
+
log(' This is a zero-config setup - everything just works!');
|
|
134
|
+
|
|
135
|
+
log('\n📖 Advanced setup (optional):', 'bright');
|
|
136
|
+
log(' Want custom Tailwind config? See docs/DEPENDENCIES.md');
|
|
137
|
+
log(' For theme-only CSS, see docs/CSS_EXPORTS.md');
|
|
138
|
+
|
|
139
|
+
// Offer Chakra migration if detected
|
|
140
|
+
if (hasChakra) {
|
|
141
|
+
log('\n🔄 Chakra UI Detected!', 'yellow');
|
|
142
|
+
log(
|
|
143
|
+
' We can help you migrate from Chakra UI to MM React Components\n',
|
|
144
|
+
'cyan',
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
const answer = await askQuestion(
|
|
148
|
+
' Would you like to run the Chakra UI migration now? (y/N): ',
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
if (answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes') {
|
|
152
|
+
log('\n🔄 Starting Chakra UI migration...', 'cyan');
|
|
153
|
+
|
|
154
|
+
const migrationScriptPath = path.join(
|
|
155
|
+
__dirname,
|
|
156
|
+
'chakra-to-shadcn-migrator',
|
|
157
|
+
'bin',
|
|
158
|
+
'chakra-to-shadcn.js',
|
|
159
|
+
);
|
|
160
|
+
const migrationConfigPath = path.join(
|
|
161
|
+
__dirname,
|
|
162
|
+
'chakra-to-shadcn-migrator',
|
|
163
|
+
'chakra-to-shadcn.config.json',
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
if (fs.existsSync(migrationScriptPath)) {
|
|
167
|
+
try {
|
|
168
|
+
execSync(
|
|
169
|
+
`node "${migrationScriptPath}" --config "${migrationConfigPath}" --apply`,
|
|
170
|
+
{
|
|
171
|
+
stdio: 'inherit',
|
|
172
|
+
},
|
|
173
|
+
);
|
|
174
|
+
log('\n✅ Chakra UI migration complete!', 'green');
|
|
175
|
+
} catch (error) {
|
|
176
|
+
log('\n⚠️ Migration encountered issues', 'yellow');
|
|
177
|
+
log(` ${error.message}`, 'yellow');
|
|
178
|
+
log(
|
|
179
|
+
' You can run it manually: node scripts/chakra-to-shadcn-migrator/chakra-to-shadcn.js',
|
|
180
|
+
'cyan',
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
log(
|
|
185
|
+
'\n⚠️ Migration script not found at expected location',
|
|
186
|
+
'yellow',
|
|
187
|
+
);
|
|
188
|
+
log(
|
|
189
|
+
' Clone the repo to access migration tools: https://github.com/machinemetrics/mm-react-components',
|
|
190
|
+
'cyan',
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
log('\n No problem! You can migrate later with:', 'cyan');
|
|
195
|
+
log(
|
|
196
|
+
' node scripts/chakra-to-shadcn-migrator/chakra-to-shadcn.js --apply',
|
|
197
|
+
'cyan',
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
log('\n🚀 Happy coding!', 'cyan');
|
|
203
|
+
} catch (error) {
|
|
204
|
+
log(`❌ Setup failed: ${error.message}`, 'red');
|
|
205
|
+
process.exit(1);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (require.main === module) {
|
|
210
|
+
main().catch((error) => {
|
|
211
|
+
log(`❌ Setup failed: ${error.message}`, 'red');
|
|
212
|
+
process.exit(1);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
module.exports = { main };
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MM React Components - NPX Initialization Script
|
|
5
|
+
*
|
|
6
|
+
* This script is designed to be run via npx only
|
|
7
|
+
* Usage: npx @machinemetrics/mm-react-components init
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/* eslint-disable no-undef, no-unused-vars */
|
|
11
|
+
|
|
12
|
+
const { execSync } = require('child_process');
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
const path = require('path');
|
|
15
|
+
const readline = require('readline');
|
|
16
|
+
|
|
17
|
+
// Read the version from package.json
|
|
18
|
+
// When built, this script is at dist/scripts/npx-init.cjs, so go up two levels
|
|
19
|
+
const packageJsonPath = path.join(__dirname, '..', '..', 'package.json');
|
|
20
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
21
|
+
const version = packageJson.version;
|
|
22
|
+
|
|
23
|
+
// Colors for console output
|
|
24
|
+
const colors = {
|
|
25
|
+
reset: '\x1b[0m',
|
|
26
|
+
bright: '\x1b[1m',
|
|
27
|
+
green: '\x1b[32m',
|
|
28
|
+
blue: '\x1b[34m',
|
|
29
|
+
cyan: '\x1b[36m',
|
|
30
|
+
yellow: '\x1b[33m',
|
|
31
|
+
red: '\x1b[31m',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function log(message, color = 'reset') {
|
|
35
|
+
console.log(`${colors[color]}${message}${colors.reset}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function logWarning(message) {
|
|
39
|
+
log(`⚠️ ${message}`, 'yellow');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function detectChakraUI() {
|
|
43
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
44
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
49
|
+
const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
deps['@chakra-ui/react'] ||
|
|
53
|
+
deps['@chakra-ui/core'] ||
|
|
54
|
+
deps['@chakra-ui/system']
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function askQuestion(question) {
|
|
59
|
+
const rl = readline.createInterface({
|
|
60
|
+
input: process.stdin,
|
|
61
|
+
output: process.stdout,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return new Promise((resolve) => {
|
|
65
|
+
rl.question(question, (answer) => {
|
|
66
|
+
rl.close();
|
|
67
|
+
resolve(answer);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function checkReactProject() {
|
|
73
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
74
|
+
|
|
75
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
76
|
+
log(
|
|
77
|
+
'❌ No package.json found. Please run this script from your React project root.',
|
|
78
|
+
'red',
|
|
79
|
+
);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
84
|
+
|
|
85
|
+
if (!packageJson.dependencies?.react && !packageJson.devDependencies?.react) {
|
|
86
|
+
log(
|
|
87
|
+
"❌ React not found in dependencies. Please ensure you're in a React project.",
|
|
88
|
+
'red',
|
|
89
|
+
);
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return packageJson;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function main() {
|
|
97
|
+
log('🚀 MM React Components - NPX Setup', 'bright');
|
|
98
|
+
log(
|
|
99
|
+
'Setting up MachineMetrics React Components in your project...\n',
|
|
100
|
+
'blue',
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
// Check if we're in a React project
|
|
105
|
+
checkReactProject();
|
|
106
|
+
log('✅ React project detected', 'green');
|
|
107
|
+
|
|
108
|
+
// Check for Chakra UI before installation
|
|
109
|
+
const hasChakra = detectChakraUI();
|
|
110
|
+
|
|
111
|
+
// Install the component library
|
|
112
|
+
log(`📦 Installing MM React Components v${version}...`, 'cyan');
|
|
113
|
+
execSync(`npm install @machinemetrics/mm-react-components@beta`, {
|
|
114
|
+
stdio: 'inherit',
|
|
115
|
+
});
|
|
116
|
+
log('✅ MM React Components installed', 'green');
|
|
117
|
+
|
|
118
|
+
log('\n💡 Zero-config mode: No build tools needed!', 'yellow');
|
|
119
|
+
log(' Using pre-compiled CSS (118 KB, 18 KB gzipped)\n', 'cyan');
|
|
120
|
+
|
|
121
|
+
// Check React version compatibility
|
|
122
|
+
log('🔍 Checking React version compatibility...', 'cyan');
|
|
123
|
+
try {
|
|
124
|
+
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
|
|
125
|
+
const reactVersion =
|
|
126
|
+
packageJson.dependencies?.react || packageJson.devDependencies?.react;
|
|
127
|
+
|
|
128
|
+
if (reactVersion && reactVersion.includes('18')) {
|
|
129
|
+
log(
|
|
130
|
+
'⚠️ React 18 detected - upgrading to React 19 for compatibility',
|
|
131
|
+
'yellow',
|
|
132
|
+
);
|
|
133
|
+
execSync(
|
|
134
|
+
'npm install react@^19.1.1 react-dom@^19.1.1 react-scripts@latest',
|
|
135
|
+
{ stdio: 'inherit' },
|
|
136
|
+
);
|
|
137
|
+
log('✅ React upgraded to v19 with compatible react-scripts', 'green');
|
|
138
|
+
} else if (reactVersion && reactVersion.includes('19')) {
|
|
139
|
+
log(
|
|
140
|
+
'✅ React 19 detected - checking react-scripts compatibility',
|
|
141
|
+
'green',
|
|
142
|
+
);
|
|
143
|
+
// Check if react-scripts needs updating for React 19
|
|
144
|
+
try {
|
|
145
|
+
const packageJson = JSON.parse(
|
|
146
|
+
fs.readFileSync('package.json', 'utf8'),
|
|
147
|
+
);
|
|
148
|
+
const scriptsVersion = packageJson.dependencies?.['react-scripts'];
|
|
149
|
+
if (scriptsVersion && scriptsVersion.includes('5.0')) {
|
|
150
|
+
log(
|
|
151
|
+
'⚠️ Updating react-scripts for React 19 compatibility',
|
|
152
|
+
'yellow',
|
|
153
|
+
);
|
|
154
|
+
execSync('npm install react-scripts@latest', { stdio: 'inherit' });
|
|
155
|
+
log('✅ react-scripts updated', 'green');
|
|
156
|
+
}
|
|
157
|
+
} catch (_error) {
|
|
158
|
+
log('⚠️ Could not check react-scripts version', 'yellow');
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
log(
|
|
162
|
+
'⚠️ Unknown React version - attempting to install React 19',
|
|
163
|
+
'yellow',
|
|
164
|
+
);
|
|
165
|
+
execSync(
|
|
166
|
+
'npm install react@^19.1.1 react-dom@^19.1.1 react-scripts@latest',
|
|
167
|
+
{ stdio: 'inherit' },
|
|
168
|
+
);
|
|
169
|
+
log('✅ React 19 installed', 'green');
|
|
170
|
+
}
|
|
171
|
+
} catch (_error) {
|
|
172
|
+
log('⚠️ Could not check React version, continuing...', 'yellow');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Setup CSS (zero-config approach)
|
|
176
|
+
const srcPath = path.join(process.cwd(), 'src');
|
|
177
|
+
const indexCssPath = path.join(srcPath, 'index.css');
|
|
178
|
+
|
|
179
|
+
// Ensure src directory exists
|
|
180
|
+
if (!fs.existsSync(srcPath)) {
|
|
181
|
+
fs.mkdirSync(srcPath, { recursive: true });
|
|
182
|
+
log('✅ Created src/ directory', 'green');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Setup CSS with pre-compiled styles
|
|
186
|
+
const cssContent = `/* MM React Components - Pre-compiled CSS (zero-config) */
|
|
187
|
+
@import '@machinemetrics/mm-react-components/styles';
|
|
188
|
+
`;
|
|
189
|
+
|
|
190
|
+
if (fs.existsSync(indexCssPath)) {
|
|
191
|
+
const existingContent = fs.readFileSync(indexCssPath, 'utf8');
|
|
192
|
+
if (!existingContent.includes('@machinemetrics/mm-react-components')) {
|
|
193
|
+
fs.writeFileSync(indexCssPath, cssContent + '\n' + existingContent);
|
|
194
|
+
log('✅ Added MM styles import to existing index.css', 'green');
|
|
195
|
+
} else {
|
|
196
|
+
log('✅ MM styles import already present in index.css', 'green');
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
fs.writeFileSync(indexCssPath, cssContent);
|
|
200
|
+
log('✅ Created index.css with MM styles import', 'green');
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Create example component
|
|
204
|
+
const examplesDir = path.join(process.cwd(), 'mm-components-examples');
|
|
205
|
+
if (!fs.existsSync(examplesDir)) {
|
|
206
|
+
fs.mkdirSync(examplesDir);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const exampleComponent = `import React from 'react';
|
|
210
|
+
import { Button, Input, Label, Card, CardHeader, CardTitle, CardDescription, CardContent } from '@machinemetrics/mm-react-components';
|
|
211
|
+
|
|
212
|
+
export function MMComponentsExample() {
|
|
213
|
+
return (
|
|
214
|
+
<div className="carbide p-8 space-y-6">
|
|
215
|
+
<h1 className="text-3xl font-bold">MM React Components</h1>
|
|
216
|
+
|
|
217
|
+
{/* Button Examples */}
|
|
218
|
+
<div className="space-y-4">
|
|
219
|
+
<h2 className="text-xl font-semibold">Buttons</h2>
|
|
220
|
+
<div className="flex gap-4">
|
|
221
|
+
<Button>Default</Button>
|
|
222
|
+
<Button variant="secondary">Secondary</Button>
|
|
223
|
+
<Button variant="outline">Outline</Button>
|
|
224
|
+
<Button variant="destructive">Destructive</Button>
|
|
225
|
+
</div>
|
|
226
|
+
</div>
|
|
227
|
+
|
|
228
|
+
{/* Form Example */}
|
|
229
|
+
<div className="space-y-4">
|
|
230
|
+
<h2 className="text-xl font-semibold">Form Components</h2>
|
|
231
|
+
<div className="w-96 space-y-4">
|
|
232
|
+
<div>
|
|
233
|
+
<Label htmlFor="machine-name">Machine Name</Label>
|
|
234
|
+
<Input id="machine-name" placeholder="Enter machine name" />
|
|
235
|
+
</div>
|
|
236
|
+
<Button>Save Configuration</Button>
|
|
237
|
+
</div>
|
|
238
|
+
</div>
|
|
239
|
+
|
|
240
|
+
{/* Card Example using actual Card components */}
|
|
241
|
+
<div className="space-y-4">
|
|
242
|
+
<h2 className="text-xl font-semibold">Card Components</h2>
|
|
243
|
+
<Card className="w-96">
|
|
244
|
+
<CardHeader>
|
|
245
|
+
<CardTitle>Machine Status</CardTitle>
|
|
246
|
+
<CardDescription>CNC-101 • Floor 1, Bay A</CardDescription>
|
|
247
|
+
</CardHeader>
|
|
248
|
+
<CardContent>
|
|
249
|
+
<div className="space-y-2">
|
|
250
|
+
<div className="flex justify-between">
|
|
251
|
+
<span className="text-sm text-muted-foreground">Status</span>
|
|
252
|
+
<span className="text-sm font-medium">Running</span>
|
|
253
|
+
</div>
|
|
254
|
+
<div className="flex justify-between">
|
|
255
|
+
<span className="text-sm text-muted-foreground">Uptime</span>
|
|
256
|
+
<span className="text-sm font-medium">127h 45m</span>
|
|
257
|
+
</div>
|
|
258
|
+
</div>
|
|
259
|
+
<div className="mt-4">
|
|
260
|
+
<Button>View Details</Button>
|
|
261
|
+
</div>
|
|
262
|
+
</CardContent>
|
|
263
|
+
</Card>
|
|
264
|
+
</div>
|
|
265
|
+
</div>
|
|
266
|
+
);
|
|
267
|
+
}`;
|
|
268
|
+
|
|
269
|
+
fs.writeFileSync(
|
|
270
|
+
path.join(examplesDir, 'MMComponentsExample.tsx'),
|
|
271
|
+
exampleComponent,
|
|
272
|
+
);
|
|
273
|
+
log('✅ Created example component', 'green');
|
|
274
|
+
|
|
275
|
+
// Create JavaScript theme activation example
|
|
276
|
+
const themeActivationExample = `// MM React Components - Zero Config Setup
|
|
277
|
+
// The CSS is already imported via @import in index.css
|
|
278
|
+
|
|
279
|
+
// Activate the Carbide industrial theme by adding the class to your root element
|
|
280
|
+
|
|
281
|
+
// Option 1: Add to HTML (recommended)
|
|
282
|
+
// In your index.html or App component:
|
|
283
|
+
// <div className="carbide">
|
|
284
|
+
// <App />
|
|
285
|
+
// </div>
|
|
286
|
+
|
|
287
|
+
// Option 2: JavaScript activation
|
|
288
|
+
// Add this to your main entry file (e.g., src/main.tsx or src/index.tsx):
|
|
289
|
+
document.documentElement.classList.add('carbide');
|
|
290
|
+
|
|
291
|
+
// The carbide theme provides:
|
|
292
|
+
// • Industrial-appropriate colors and styling
|
|
293
|
+
// • Dark mode support
|
|
294
|
+
// • Enhanced focus states for accessibility
|
|
295
|
+
// • Pre-compiled Tailwind utilities
|
|
296
|
+
|
|
297
|
+
// No build tools needed!`;
|
|
298
|
+
|
|
299
|
+
fs.writeFileSync(
|
|
300
|
+
path.join(examplesDir, 'theme-activation.js'),
|
|
301
|
+
themeActivationExample,
|
|
302
|
+
);
|
|
303
|
+
log('✅ Created theme activation example', 'green');
|
|
304
|
+
|
|
305
|
+
// Success message
|
|
306
|
+
log(`\n🎉 Zero-Config Setup Complete!`, 'green');
|
|
307
|
+
log('\n📚 What was installed:', 'bright');
|
|
308
|
+
log(` • @machinemetrics/mm-react-components@${version}`);
|
|
309
|
+
log(' • Pre-compiled CSS with all styles');
|
|
310
|
+
log(' • Example component in mm-components-examples/');
|
|
311
|
+
log(' • Theme activation example in mm-components-examples/');
|
|
312
|
+
|
|
313
|
+
log('\n✅ What you got:', 'bright');
|
|
314
|
+
log(' • Pre-compiled CSS with all Tailwind utilities');
|
|
315
|
+
log(' • Carbide industrial theme');
|
|
316
|
+
log(' • Dark mode support');
|
|
317
|
+
log(' • All component styles (focus, hover, etc.)');
|
|
318
|
+
log(' • Google Fonts included');
|
|
319
|
+
|
|
320
|
+
log('\n💡 No build tools needed!', 'yellow');
|
|
321
|
+
log(' This is a zero-config setup - everything just works!');
|
|
322
|
+
|
|
323
|
+
log('\n🚀 Next steps:', 'bright');
|
|
324
|
+
log(' 1. Add Carbide class to your root element:');
|
|
325
|
+
log(' document.documentElement.classList.add("carbide")', 'cyan');
|
|
326
|
+
log(' 2. Import components:');
|
|
327
|
+
log(
|
|
328
|
+
' import { Button, Input } from "@machinemetrics/mm-react-components"',
|
|
329
|
+
'cyan',
|
|
330
|
+
);
|
|
331
|
+
log(' 3. Check out the example:');
|
|
332
|
+
log(' ./mm-components-examples/MMComponentsExample.tsx', 'cyan');
|
|
333
|
+
log(' 4. Use components - everything is pre-styled and ready!');
|
|
334
|
+
|
|
335
|
+
log('\n📖 Documentation:', 'bright');
|
|
336
|
+
log(' • Getting Started: docs/GETTING_STARTED.md');
|
|
337
|
+
log(' • CSS Options: docs/CSS_EXPORTS.md');
|
|
338
|
+
log(' • Dependencies: docs/DEPENDENCIES.md');
|
|
339
|
+
log(' • GitHub: https://github.com/machinemetrics/mm-react-components');
|
|
340
|
+
|
|
341
|
+
// Offer Chakra migration if detected
|
|
342
|
+
if (hasChakra) {
|
|
343
|
+
log('\n🔄 Chakra UI Detected!', 'yellow');
|
|
344
|
+
log(
|
|
345
|
+
' We can help you migrate from Chakra UI to MM React Components\n',
|
|
346
|
+
'cyan',
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
const answer = await askQuestion(
|
|
350
|
+
' Would you like to run the Chakra UI migration now? (y/N): ',
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
if (answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes') {
|
|
354
|
+
log('\n🔄 Starting Chakra UI migration...', 'cyan');
|
|
355
|
+
|
|
356
|
+
const migrationScriptPath = path.join(
|
|
357
|
+
__dirname,
|
|
358
|
+
'chakra-to-shadcn-migrator',
|
|
359
|
+
'bin',
|
|
360
|
+
'chakra-to-shadcn.js',
|
|
361
|
+
);
|
|
362
|
+
const migrationConfigPath = path.join(
|
|
363
|
+
__dirname,
|
|
364
|
+
'chakra-to-shadcn-migrator',
|
|
365
|
+
'chakra-to-shadcn.config.json',
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
if (fs.existsSync(migrationScriptPath)) {
|
|
369
|
+
try {
|
|
370
|
+
execSync(
|
|
371
|
+
`node "${migrationScriptPath}" --config "${migrationConfigPath}" --apply`,
|
|
372
|
+
{
|
|
373
|
+
stdio: 'inherit',
|
|
374
|
+
},
|
|
375
|
+
);
|
|
376
|
+
log('\n✅ Chakra UI migration complete!', 'green');
|
|
377
|
+
} catch (error) {
|
|
378
|
+
log('\n⚠️ Migration encountered issues', 'yellow');
|
|
379
|
+
log(` ${error.message}`, 'yellow');
|
|
380
|
+
log(
|
|
381
|
+
' You can run it manually: node scripts/chakra-to-shadcn-migrator/chakra-to-shadcn.js',
|
|
382
|
+
'cyan',
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
} else {
|
|
386
|
+
log(
|
|
387
|
+
'\n⚠️ Migration script not found at expected location',
|
|
388
|
+
'yellow',
|
|
389
|
+
);
|
|
390
|
+
log(
|
|
391
|
+
' Clone the repo to access migration tools: https://github.com/machinemetrics/mm-react-components',
|
|
392
|
+
'cyan',
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
} else {
|
|
396
|
+
log('\n No problem! You can migrate later with:', 'cyan');
|
|
397
|
+
log(
|
|
398
|
+
' node scripts/chakra-to-shadcn-migrator/chakra-to-shadcn.js --apply',
|
|
399
|
+
'cyan',
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
log('\n🚀 Happy coding!', 'cyan');
|
|
405
|
+
} catch (error) {
|
|
406
|
+
log(`❌ Setup failed: ${error.message}`, 'red');
|
|
407
|
+
process.exit(1);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (require.main === module) {
|
|
412
|
+
main().catch((error) => {
|
|
413
|
+
log(`❌ Setup failed: ${error.message}`, 'red');
|
|
414
|
+
process.exit(1);
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
module.exports = { main };
|