shru-design-system 0.1.9 → 0.1.10
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/package.json +1 -1
- package/scripts/init.js +147 -7
package/package.json
CHANGED
package/scripts/init.js
CHANGED
|
@@ -63,19 +63,159 @@ function installPackage(packageName, isDev = true) {
|
|
|
63
63
|
function createTailwindConfig() {
|
|
64
64
|
const configPath = path.join(process.cwd(), 'tailwind.config.js');
|
|
65
65
|
|
|
66
|
+
// Required configs that must be present
|
|
67
|
+
const requiredConfigs = {
|
|
68
|
+
fontFamily: 'fontFamily',
|
|
69
|
+
spacing: 'spacing',
|
|
70
|
+
gap: 'gap',
|
|
71
|
+
transitionDuration: 'transitionDuration'
|
|
72
|
+
};
|
|
73
|
+
|
|
66
74
|
if (fs.existsSync(configPath)) {
|
|
67
|
-
log('tailwind.config.js already exists.
|
|
75
|
+
log('tailwind.config.js already exists. Checking for required configs...', 'yellow');
|
|
68
76
|
const existing = fs.readFileSync(configPath, 'utf8');
|
|
69
77
|
|
|
70
|
-
// Check if
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
// Check if all required configs are present with proper values
|
|
79
|
+
const hasFontFamily = existing.includes('fontFamily') && existing.includes('--font-sans');
|
|
80
|
+
const hasSpacing = existing.includes('spacing:') && existing.includes('component-xs');
|
|
81
|
+
const hasGap = existing.includes('gap:') && existing.includes('component-xs');
|
|
82
|
+
const hasTransitionDuration = existing.includes('transitionDuration') && existing.includes('duration-fast');
|
|
83
|
+
|
|
84
|
+
if (hasFontFamily && hasSpacing && hasGap && hasTransitionDuration) {
|
|
85
|
+
log(`Configuration already includes all required ${PACKAGE_NAME} setup.`, 'green');
|
|
73
86
|
return;
|
|
74
87
|
}
|
|
75
88
|
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
89
|
+
// Track what's missing
|
|
90
|
+
const missingConfigs = [];
|
|
91
|
+
if (!hasFontFamily) missingConfigs.push('fontFamily');
|
|
92
|
+
if (!hasSpacing) missingConfigs.push('spacing');
|
|
93
|
+
if (!hasGap) missingConfigs.push('gap');
|
|
94
|
+
if (!hasTransitionDuration) missingConfigs.push('transitionDuration');
|
|
95
|
+
|
|
96
|
+
// If configs are missing, update the file
|
|
97
|
+
if (missingConfigs.length > 0) {
|
|
98
|
+
log(`Missing required configs: ${missingConfigs.join(', ')}. Updating...`, 'yellow');
|
|
99
|
+
|
|
100
|
+
// Read the existing config
|
|
101
|
+
let updated = existing;
|
|
102
|
+
|
|
103
|
+
// Add fontFamily if missing
|
|
104
|
+
if (!hasFontFamily) {
|
|
105
|
+
const fontFamilyConfig = ` // ⚠️ IF YOU UPDATE fontFamily CONFIG, ALSO UPDATE:
|
|
106
|
+
// 1. test/tailwind.config.js - fontFamily config (test app)
|
|
107
|
+
fontFamily: {
|
|
108
|
+
sans: ["var(--font-sans)", "system-ui", "sans-serif"],
|
|
109
|
+
body: ["var(--font-body)", "var(--font-sans)", "system-ui", "sans-serif"],
|
|
110
|
+
},`;
|
|
111
|
+
|
|
112
|
+
// Insert after borderRadius
|
|
113
|
+
if (existing.includes('borderRadius')) {
|
|
114
|
+
updated = updated.replace(
|
|
115
|
+
/(borderRadius: \{[\s\S]*?\},)/,
|
|
116
|
+
`$1\n${fontFamilyConfig}`
|
|
117
|
+
);
|
|
118
|
+
} else {
|
|
119
|
+
// Insert after colors
|
|
120
|
+
updated = updated.replace(
|
|
121
|
+
/(ring: "hsl\(var\(--ring\)\)",)/,
|
|
122
|
+
`$1\n },\n${fontFamilyConfig}`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Add spacing if missing
|
|
128
|
+
if (!hasSpacing) {
|
|
129
|
+
const spacingConfig = ` // ⚠️ IF YOU UPDATE spacing CONFIG, ALSO UPDATE:
|
|
130
|
+
// 1. test/tailwind.config.js - spacing config (test app)
|
|
131
|
+
spacing: {
|
|
132
|
+
'component-xs': "var(--spacing-component-xs, 0.25rem)",
|
|
133
|
+
'component-sm': "var(--spacing-component-sm, 0.5rem)",
|
|
134
|
+
'component-md': "var(--spacing-component-md, 1rem)",
|
|
135
|
+
'component-lg': "var(--spacing-component-lg, 1.5rem)",
|
|
136
|
+
'component-xl': "var(--spacing-component-xl, 2rem)",
|
|
137
|
+
},`;
|
|
138
|
+
|
|
139
|
+
// Insert after fontFamily or borderRadius
|
|
140
|
+
if (updated.includes('fontFamily')) {
|
|
141
|
+
updated = updated.replace(
|
|
142
|
+
/(fontFamily: \{[\s\S]*?\},)/,
|
|
143
|
+
`$1\n${spacingConfig}`
|
|
144
|
+
);
|
|
145
|
+
} else if (updated.includes('borderRadius')) {
|
|
146
|
+
updated = updated.replace(
|
|
147
|
+
/(borderRadius: \{[\s\S]*?\},)/,
|
|
148
|
+
`$1\n${spacingConfig}`
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Add gap if missing
|
|
154
|
+
if (!hasGap) {
|
|
155
|
+
const gapConfig = ` // ⚠️ IF YOU UPDATE gap CONFIG, ALSO UPDATE:
|
|
156
|
+
// 1. test/tailwind.config.js - gap config (test app)
|
|
157
|
+
gap: {
|
|
158
|
+
'component-xs': "var(--spacing-component-xs, 0.25rem)",
|
|
159
|
+
'component-sm': "var(--spacing-component-sm, 0.5rem)",
|
|
160
|
+
'component-md': "var(--spacing-component-md, 1rem)",
|
|
161
|
+
'component-lg': "var(--spacing-component-lg, 1.5rem)",
|
|
162
|
+
'component-xl': "var(--spacing-component-xl, 2rem)",
|
|
163
|
+
},`;
|
|
164
|
+
|
|
165
|
+
// Insert after spacing
|
|
166
|
+
if (updated.includes('spacing:')) {
|
|
167
|
+
updated = updated.replace(
|
|
168
|
+
/(spacing: \{[\s\S]*?\},)/,
|
|
169
|
+
`$1\n${gapConfig}`
|
|
170
|
+
);
|
|
171
|
+
} else if (updated.includes('fontFamily')) {
|
|
172
|
+
updated = updated.replace(
|
|
173
|
+
/(fontFamily: \{[\s\S]*?\},)/,
|
|
174
|
+
`$1\n${gapConfig}`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Add transitionDuration if missing
|
|
180
|
+
if (!hasTransitionDuration) {
|
|
181
|
+
const transitionConfig = ` // ⚠️ IF YOU UPDATE transitionDuration CONFIG, ALSO UPDATE:
|
|
182
|
+
// 1. test/tailwind.config.js - transitionDuration config (test app)
|
|
183
|
+
transitionDuration: {
|
|
184
|
+
'fast': "var(--duration-fast, 150ms)",
|
|
185
|
+
'normal': "var(--duration-normal, 300ms)",
|
|
186
|
+
'slow': "var(--duration-slow, 500ms)",
|
|
187
|
+
},`;
|
|
188
|
+
|
|
189
|
+
// Insert after gap or spacing
|
|
190
|
+
if (updated.includes('gap:')) {
|
|
191
|
+
updated = updated.replace(
|
|
192
|
+
/(gap: \{[\s\S]*?\},)/,
|
|
193
|
+
`$1\n${transitionConfig}`
|
|
194
|
+
);
|
|
195
|
+
} else if (updated.includes('spacing:')) {
|
|
196
|
+
updated = updated.replace(
|
|
197
|
+
/(spacing: \{[\s\S]*?\},)/,
|
|
198
|
+
`$1\n${transitionConfig}`
|
|
199
|
+
);
|
|
200
|
+
} else if (updated.includes('fontFamily')) {
|
|
201
|
+
updated = updated.replace(
|
|
202
|
+
/(fontFamily: \{[\s\S]*?\},)/,
|
|
203
|
+
`$1\n${transitionConfig}`
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Write the updated config
|
|
209
|
+
fs.writeFileSync(configPath, updated);
|
|
210
|
+
log('Updated tailwind.config.js with missing configs', 'green');
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// If config exists but doesn't have our package name, warn user
|
|
215
|
+
if (!existing.includes(PACKAGE_NAME) && !existing.includes('shru-design-system')) {
|
|
216
|
+
log('Please manually merge the Tailwind config. See docs for details.', 'yellow');
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
79
219
|
}
|
|
80
220
|
|
|
81
221
|
const config = `/** @type {import('tailwindcss').Config} */
|