shru-design-system 0.1.1 → 0.1.2

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/scripts/init.js CHANGED
@@ -1,14 +1,33 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /**
4
- * shru-design-system init script
4
+ * Design system init script
5
5
  * Sets up Tailwind CSS and required configuration
6
+ * This file is part of the design system library
6
7
  */
7
8
 
8
9
  const fs = require('fs');
9
10
  const path = require('path');
10
11
  const { execSync } = require('child_process');
11
12
 
13
+ // Get package name dynamically from package.json
14
+ function getPackageName() {
15
+ try {
16
+ const packageJsonPath = path.join(__dirname, '..', 'package.json');
17
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
18
+ return packageJson.name || 'shru-design-system';
19
+ } catch (error) {
20
+ // Fallback if package.json can't be read
21
+ return 'shru-design-system';
22
+ }
23
+ }
24
+
25
+ const PACKAGE_NAME = getPackageName();
26
+ const LIBRARY_NAME = `${PACKAGE_NAME} library`;
27
+
28
+ // Configuration constants
29
+ const TAILWIND_VERSION = '^3.4.0';
30
+
12
31
  const colors = {
13
32
  reset: '\x1b[0m',
14
33
  green: '\x1b[32m',
@@ -49,8 +68,8 @@ function createTailwindConfig() {
49
68
  const existing = fs.readFileSync(configPath, 'utf8');
50
69
 
51
70
  // Check if our config is already there
52
- if (existing.includes('shru-design-system')) {
53
- log('Configuration already includes shru-design-system setup.', 'green');
71
+ if (existing.includes(PACKAGE_NAME)) {
72
+ log(`Configuration already includes ${PACKAGE_NAME} setup.`, 'green');
54
73
  return;
55
74
  }
56
75
 
@@ -60,11 +79,12 @@ function createTailwindConfig() {
60
79
  }
61
80
 
62
81
  const config = `/** @type {import('tailwindcss').Config} */
82
+ // This file was created by ${LIBRARY_NAME}
63
83
  export default {
64
84
  content: [
65
85
  "./index.html",
66
86
  "./src/**/*.{js,ts,jsx,tsx}",
67
- "./node_modules/shru-design-system/dist/**/*.{js,mjs}",
87
+ "./node_modules/${PACKAGE_NAME}/dist/**/*.{js,mjs}",
68
88
  ],
69
89
  theme: {
70
90
  extend: {
@@ -122,7 +142,8 @@ function createPostCSSConfig() {
122
142
  return;
123
143
  }
124
144
 
125
- const config = `export default {
145
+ const config = `// This file was created by ${LIBRARY_NAME}
146
+ export default {
126
147
  plugins: {
127
148
  tailwindcss: {},
128
149
  autoprefixer: {},
@@ -155,7 +176,7 @@ function createCSSFile() {
155
176
  // Append to existing file
156
177
  const cssVars = `
157
178
 
158
- /* shru-design-system CSS variables */
179
+ /* Design system CSS variables - Created by ${LIBRARY_NAME} */
159
180
  @layer base {
160
181
  :root {
161
182
  --background: 0 0% 100%;
@@ -197,6 +218,7 @@ function createCSSFile() {
197
218
  @tailwind components;
198
219
  @tailwind utilities;
199
220
 
221
+ /* This file was created by ${LIBRARY_NAME} */
200
222
  @layer base {
201
223
  :root {
202
224
  --background: 0 0% 100%;
@@ -234,6 +256,350 @@ function createCSSFile() {
234
256
  log('Created src/index.css', 'green');
235
257
  }
236
258
 
259
+ function createTokenFiles() {
260
+ const publicDir = path.join(process.cwd(), 'public');
261
+ const tokensDir = path.join(publicDir, 'tokens');
262
+ const themesDir = path.join(tokensDir, 'themes');
263
+
264
+ // Create directories
265
+ if (!fs.existsSync(publicDir)) {
266
+ fs.mkdirSync(publicDir, { recursive: true });
267
+ }
268
+ if (!fs.existsSync(tokensDir)) {
269
+ fs.mkdirSync(tokensDir, { recursive: true });
270
+ }
271
+ if (!fs.existsSync(themesDir)) {
272
+ fs.mkdirSync(themesDir, { recursive: true });
273
+ }
274
+
275
+ // Create base.json
276
+ const basePath = path.join(tokensDir, 'base.json');
277
+ if (!fs.existsSync(basePath)) {
278
+ const baseJson = {
279
+ "_createdBy": LIBRARY_NAME,
280
+ "color": {
281
+ "primary": "{palette.blue.500}",
282
+ "primary-hover": "{palette.blue.600}",
283
+ "primary-foreground": "{palette.white}",
284
+ "secondary": "{palette.gray.100}",
285
+ "secondary-foreground": "{palette.gray.900}",
286
+ "background": "{palette.white}",
287
+ "foreground": "{palette.gray.900}",
288
+ "card": "{palette.white}",
289
+ "card-foreground": "{palette.gray.900}",
290
+ "popover": "{palette.white}",
291
+ "popover-foreground": "{palette.gray.900}",
292
+ "muted": "{palette.gray.100}",
293
+ "muted-foreground": "{palette.gray.500}",
294
+ "accent": "{palette.gray.100}",
295
+ "accent-foreground": "{palette.gray.900}",
296
+ "destructive": "{palette.red.500}",
297
+ "destructive-foreground": "{palette.white}",
298
+ "border": "{palette.gray.200}",
299
+ "input": "{palette.gray.200}",
300
+ "ring": "{palette.gray.400}",
301
+ "skeleton": "{palette.gray.200}"
302
+ },
303
+ "spacing": {
304
+ "component": {
305
+ "xs": "0.25rem",
306
+ "sm": "0.5rem",
307
+ "md": "1rem",
308
+ "lg": "1.5rem",
309
+ "xl": "2rem"
310
+ },
311
+ "base": "0.25rem"
312
+ },
313
+ "typography": {
314
+ "font": {
315
+ "body": "var(--font-sans)",
316
+ "sans": "var(--font-sans)",
317
+ "mono": "var(--font-mono)"
318
+ }
319
+ },
320
+ "shape": {
321
+ "radius": {
322
+ "button": "0.375rem",
323
+ "card": "0.5rem",
324
+ "input": "0.375rem"
325
+ }
326
+ }
327
+ };
328
+ fs.writeFileSync(basePath, JSON.stringify(baseJson, null, 2));
329
+ log('Created public/tokens/base.json', 'green');
330
+ } else {
331
+ log('public/tokens/base.json already exists. Skipping...', 'yellow');
332
+ }
333
+
334
+ // Create palettes.json
335
+ const palettesPath = path.join(tokensDir, 'palettes.json');
336
+ if (!fs.existsSync(palettesPath)) {
337
+ const palettesJson = {
338
+ "_createdBy": LIBRARY_NAME,
339
+ "palette": {
340
+ "white": "#ffffff",
341
+ "black": "#000000",
342
+ "transparent": "transparent",
343
+ "gray": {
344
+ "50": "#f9fafb",
345
+ "100": "#f3f4f6",
346
+ "200": "#e5e7eb",
347
+ "300": "#d1d5db",
348
+ "400": "#9ca3af",
349
+ "500": "#6b7280",
350
+ "600": "#4b5563",
351
+ "700": "#374151",
352
+ "800": "#1f2937",
353
+ "900": "#111827",
354
+ "950": "#030712"
355
+ },
356
+ "blue": {
357
+ "50": "#eff6ff",
358
+ "100": "#dbeafe",
359
+ "200": "#bfdbfe",
360
+ "300": "#93c5fd",
361
+ "400": "#60a5fa",
362
+ "500": "#3b82f6",
363
+ "600": "#2563eb",
364
+ "700": "#1d4ed8",
365
+ "800": "#1e40af",
366
+ "900": "#1e3a8a",
367
+ "950": "#172554"
368
+ },
369
+ "red": {
370
+ "50": "#fef2f2",
371
+ "100": "#fee2e2",
372
+ "200": "#fecaca",
373
+ "300": "#fca5a5",
374
+ "400": "#f87171",
375
+ "500": "#ef4444",
376
+ "600": "#dc2626",
377
+ "700": "#b91c1c",
378
+ "800": "#991b1b",
379
+ "900": "#7f1d1d",
380
+ "950": "#450a0a"
381
+ }
382
+ }
383
+ };
384
+ fs.writeFileSync(palettesPath, JSON.stringify(palettesJson, null, 2));
385
+ log('Created public/tokens/palettes.json', 'green');
386
+ } else {
387
+ log('public/tokens/palettes.json already exists. Skipping...', 'yellow');
388
+ }
389
+
390
+ // Create theme directories and files
391
+ const themeCategories = ['color', 'typography', 'shape', 'density', 'animation', 'custom'];
392
+
393
+ themeCategories.forEach(category => {
394
+ const categoryDir = path.join(themesDir, category);
395
+ if (!fs.existsSync(categoryDir)) {
396
+ fs.mkdirSync(categoryDir, { recursive: true });
397
+ }
398
+ });
399
+
400
+ // Create color/white.json
401
+ const whiteThemePath = path.join(themesDir, 'color', 'white.json');
402
+ if (!fs.existsSync(whiteThemePath)) {
403
+ const whiteTheme = {
404
+ "_createdBy": LIBRARY_NAME,
405
+ "color": {
406
+ "primary": "{palette.blue.500}",
407
+ "primary-foreground": "{palette.white}",
408
+ "background": "{palette.white}",
409
+ "foreground": "{palette.gray.900}",
410
+ "card": "{palette.white}",
411
+ "card-foreground": "{palette.gray.900}",
412
+ "popover": "{palette.white}",
413
+ "popover-foreground": "{palette.gray.900}",
414
+ "secondary": "{palette.gray.100}",
415
+ "secondary-foreground": "{palette.gray.900}",
416
+ "muted": "{palette.gray.100}",
417
+ "muted-foreground": "{palette.gray.500}",
418
+ "accent": "{palette.gray.100}",
419
+ "accent-foreground": "{palette.gray.900}",
420
+ "destructive": "{palette.red.500}",
421
+ "destructive-foreground": "{palette.white}",
422
+ "border": "{palette.gray.200}",
423
+ "input": "{palette.gray.200}",
424
+ "ring": "{palette.gray.400}",
425
+ "skeleton": "{palette.gray.200}"
426
+ }
427
+ };
428
+ fs.writeFileSync(whiteThemePath, JSON.stringify(whiteTheme, null, 2));
429
+ log('Created public/tokens/themes/color/white.json', 'green');
430
+ }
431
+
432
+ // Create color/dark.json
433
+ const darkThemePath = path.join(themesDir, 'color', 'dark.json');
434
+ if (!fs.existsSync(darkThemePath)) {
435
+ const darkTheme = {
436
+ "_createdBy": LIBRARY_NAME,
437
+ "color": {
438
+ "primary": "{palette.blue.400}",
439
+ "primary-foreground": "{palette.gray.900}",
440
+ "background": "{palette.gray.900}",
441
+ "foreground": "{palette.gray.50}",
442
+ "card": "{palette.gray.800}",
443
+ "card-foreground": "{palette.gray.50}",
444
+ "popover": "{palette.gray.800}",
445
+ "popover-foreground": "{palette.gray.50}",
446
+ "secondary": "{palette.gray.800}",
447
+ "secondary-foreground": "{palette.gray.50}",
448
+ "muted": "{palette.gray.800}",
449
+ "muted-foreground": "{palette.gray.400}",
450
+ "accent": "{palette.gray.800}",
451
+ "accent-foreground": "{palette.gray.50}",
452
+ "destructive": "{palette.red.500}",
453
+ "destructive-foreground": "{palette.white}",
454
+ "border": "{palette.gray.700}",
455
+ "input": "{palette.gray.700}",
456
+ "ring": "{palette.gray.600}",
457
+ "skeleton": "{palette.gray.700}"
458
+ }
459
+ };
460
+ fs.writeFileSync(darkThemePath, JSON.stringify(darkTheme, null, 2));
461
+ log('Created public/tokens/themes/color/dark.json', 'green');
462
+ }
463
+
464
+ // Create typography/sans.json
465
+ const sansThemePath = path.join(themesDir, 'typography', 'sans.json');
466
+ if (!fs.existsSync(sansThemePath)) {
467
+ const sansTheme = {
468
+ "_createdBy": LIBRARY_NAME,
469
+ "typography": {
470
+ "font": {
471
+ "body": "system-ui, -apple-system, sans-serif",
472
+ "sans": "system-ui, -apple-system, sans-serif"
473
+ }
474
+ }
475
+ };
476
+ fs.writeFileSync(sansThemePath, JSON.stringify(sansTheme, null, 2));
477
+ log('Created public/tokens/themes/typography/sans.json', 'green');
478
+ }
479
+
480
+ // Create typography/serif.json
481
+ const serifThemePath = path.join(themesDir, 'typography', 'serif.json');
482
+ if (!fs.existsSync(serifThemePath)) {
483
+ const serifTheme = {
484
+ "_createdBy": LIBRARY_NAME,
485
+ "typography": {
486
+ "font": {
487
+ "body": "Georgia, serif",
488
+ "sans": "Georgia, serif"
489
+ }
490
+ }
491
+ };
492
+ fs.writeFileSync(serifThemePath, JSON.stringify(serifTheme, null, 2));
493
+ log('Created public/tokens/themes/typography/serif.json', 'green');
494
+ }
495
+
496
+ // Create shape/smooth.json
497
+ const smoothThemePath = path.join(themesDir, 'shape', 'smooth.json');
498
+ if (!fs.existsSync(smoothThemePath)) {
499
+ const smoothTheme = {
500
+ "_createdBy": LIBRARY_NAME,
501
+ "shape": {
502
+ "radius": {
503
+ "button": "0.5rem",
504
+ "card": "0.75rem",
505
+ "input": "0.5rem"
506
+ }
507
+ }
508
+ };
509
+ fs.writeFileSync(smoothThemePath, JSON.stringify(smoothTheme, null, 2));
510
+ log('Created public/tokens/themes/shape/smooth.json', 'green');
511
+ }
512
+
513
+ // Create shape/sharp.json
514
+ const sharpThemePath = path.join(themesDir, 'shape', 'sharp.json');
515
+ if (!fs.existsSync(sharpThemePath)) {
516
+ const sharpTheme = {
517
+ "_createdBy": LIBRARY_NAME,
518
+ "shape": {
519
+ "radius": {
520
+ "button": "0",
521
+ "card": "0",
522
+ "input": "0"
523
+ }
524
+ }
525
+ };
526
+ fs.writeFileSync(sharpThemePath, JSON.stringify(sharpTheme, null, 2));
527
+ log('Created public/tokens/themes/shape/sharp.json', 'green');
528
+ }
529
+
530
+ // Create density/comfortable.json
531
+ const comfortableThemePath = path.join(themesDir, 'density', 'comfortable.json');
532
+ if (!fs.existsSync(comfortableThemePath)) {
533
+ const comfortableTheme = {
534
+ "_createdBy": LIBRARY_NAME,
535
+ "spacing": {
536
+ "component": {
537
+ "xs": "0.5rem",
538
+ "sm": "0.75rem",
539
+ "md": "1.25rem",
540
+ "lg": "2rem",
541
+ "xl": "2.5rem"
542
+ }
543
+ }
544
+ };
545
+ fs.writeFileSync(comfortableThemePath, JSON.stringify(comfortableTheme, null, 2));
546
+ log('Created public/tokens/themes/density/comfortable.json', 'green');
547
+ }
548
+
549
+ // Create density/compact.json
550
+ const compactThemePath = path.join(themesDir, 'density', 'compact.json');
551
+ if (!fs.existsSync(compactThemePath)) {
552
+ const compactTheme = {
553
+ "_createdBy": LIBRARY_NAME,
554
+ "spacing": {
555
+ "component": {
556
+ "xs": "0.25rem",
557
+ "sm": "0.5rem",
558
+ "md": "0.75rem",
559
+ "lg": "1rem",
560
+ "xl": "1.5rem"
561
+ }
562
+ }
563
+ };
564
+ fs.writeFileSync(compactThemePath, JSON.stringify(compactTheme, null, 2));
565
+ log('Created public/tokens/themes/density/compact.json', 'green');
566
+ }
567
+
568
+ // Create animation/gentle.json
569
+ const gentleThemePath = path.join(themesDir, 'animation', 'gentle.json');
570
+ if (!fs.existsSync(gentleThemePath)) {
571
+ const gentleTheme = {
572
+ "_createdBy": LIBRARY_NAME,
573
+ "animation": {
574
+ "duration": {
575
+ "fast": "150ms",
576
+ "normal": "300ms",
577
+ "slow": "500ms"
578
+ }
579
+ }
580
+ };
581
+ fs.writeFileSync(gentleThemePath, JSON.stringify(gentleTheme, null, 2));
582
+ log('Created public/tokens/themes/animation/gentle.json', 'green');
583
+ }
584
+
585
+ // Create animation/brisk.json
586
+ const briskThemePath = path.join(themesDir, 'animation', 'brisk.json');
587
+ if (!fs.existsSync(briskThemePath)) {
588
+ const briskTheme = {
589
+ "_createdBy": LIBRARY_NAME,
590
+ "animation": {
591
+ "duration": {
592
+ "fast": "100ms",
593
+ "normal": "200ms",
594
+ "slow": "300ms"
595
+ }
596
+ }
597
+ };
598
+ fs.writeFileSync(briskThemePath, JSON.stringify(briskTheme, null, 2));
599
+ log('Created public/tokens/themes/animation/brisk.json', 'green');
600
+ }
601
+ }
602
+
237
603
  function checkMainFile() {
238
604
  const possiblePaths = [
239
605
  path.join(process.cwd(), 'src', 'main.tsx'),
@@ -263,12 +629,12 @@ function checkMainFile() {
263
629
 
264
630
  // Main execution
265
631
  function main() {
266
- log('\nšŸš€ Setting up shru-design-system...\n', 'blue');
632
+ log(`\nšŸš€ Setting up ${PACKAGE_NAME}...\n`, 'blue');
267
633
 
268
634
  // Check and install Tailwind
269
635
  if (!checkPackageInstalled('tailwindcss')) {
270
636
  log('Tailwind CSS not found. Installing...', 'yellow');
271
- if (!installPackage('tailwindcss@^3.4.0')) {
637
+ if (!installPackage(`tailwindcss@${TAILWIND_VERSION}`)) {
272
638
  log('Failed to install Tailwind CSS. Please install manually.', 'red');
273
639
  process.exit(1);
274
640
  }
@@ -290,6 +656,7 @@ function main() {
290
656
  createTailwindConfig();
291
657
  createPostCSSConfig();
292
658
  createCSSFile();
659
+ createTokenFiles();
293
660
  checkMainFile();
294
661
 
295
662
  log('\nāœ… Setup complete!', 'green');
@@ -297,9 +664,12 @@ function main() {
297
664
  log('1. Make sure to import the CSS file in your entry point:', 'yellow');
298
665
  log(" import './index.css'", 'blue');
299
666
  log('2. Start using components:', 'yellow');
300
- log(" import { Button } from 'shru-design-system'", 'blue');
667
+ log(` import { Button, ThemeToggle } from '${PACKAGE_NAME}'`, 'blue');
668
+ log('\nšŸ’” Custom Token Files:', 'blue');
669
+ log(' You can add custom theme files to public/tokens/themes/{category}/', 'yellow');
670
+ log(' Example: public/tokens/themes/color/ocean.json', 'blue');
671
+ log(' The ThemeToggle will automatically discover and use them.', 'blue');
301
672
  log('\n');
302
673
  }
303
674
 
304
675
  main();
305
-