@react-datatable/cli 1.2.2 → 1.2.3

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.
@@ -40,10 +40,57 @@ const VALID_FRAMEWORKS = new Set([
40
40
  "astro",
41
41
  "laravel",
42
42
  "manual",
43
- "generic",
44
43
  ])
45
44
  const VALID_PERSISTENCE = new Set(["local-storage", "session-storage"])
45
+ const VALID_THEMES = new Set(["auto", "import", "none"])
46
46
  const DEFAULT_MANIFEST_URL = "https://react-datatable.com/api/install/manifest"
47
+ const REQUIRED_THEME_VARIABLES = [
48
+ "--background",
49
+ "--foreground",
50
+ "--card",
51
+ "--card-foreground",
52
+ "--popover",
53
+ "--popover-foreground",
54
+ "--primary",
55
+ "--primary-foreground",
56
+ "--secondary",
57
+ "--secondary-foreground",
58
+ "--muted",
59
+ "--muted-foreground",
60
+ "--accent",
61
+ "--accent-foreground",
62
+ "--destructive",
63
+ "--destructive-foreground",
64
+ "--border",
65
+ "--input",
66
+ "--ring",
67
+ "--radius",
68
+ ]
69
+ const REQUIRED_TAILWIND_THEME_VARIABLES = [
70
+ "--color-background",
71
+ "--color-foreground",
72
+ "--color-card",
73
+ "--color-card-foreground",
74
+ "--color-popover",
75
+ "--color-popover-foreground",
76
+ "--color-primary",
77
+ "--color-primary-foreground",
78
+ "--color-secondary",
79
+ "--color-secondary-foreground",
80
+ "--color-muted",
81
+ "--color-muted-foreground",
82
+ "--color-accent",
83
+ "--color-accent-foreground",
84
+ "--color-destructive",
85
+ "--color-destructive-foreground",
86
+ "--color-border",
87
+ "--color-input",
88
+ "--color-ring",
89
+ "--radius-sm",
90
+ "--radius-md",
91
+ "--radius-lg",
92
+ "--radius-xl",
93
+ ]
47
94
 
48
95
  main().catch((error) => {
49
96
  console.error(error instanceof Error ? error.message : String(error))
@@ -84,6 +131,7 @@ async function main() {
84
131
  withViews: options.withViews,
85
132
  withOnlineExample: options.withOnlineExample,
86
133
  noInstall: options.noInstall,
134
+ theme: options.theme,
87
135
  manifestUrl: options.manifestUrl,
88
136
  }
89
137
 
@@ -106,6 +154,7 @@ function parseInstallArgs(args) {
106
154
  withOnlineExample: false,
107
155
  persistence: "local-storage",
108
156
  noInstall: false,
157
+ theme: "auto",
109
158
  manifestUrl: process.env.REACT_DATATABLE_INSTALL_MANIFEST_URL ?? DEFAULT_MANIFEST_URL,
110
159
  }
111
160
 
@@ -150,6 +199,17 @@ function parseInstallArgs(args) {
150
199
  case "--no-install":
151
200
  options.noInstall = true
152
201
  break
202
+ case "--theme": {
203
+ const theme = readFlagValue(args, ++index, "--theme")
204
+ if (!VALID_THEMES.has(theme)) {
205
+ throw new Error(`Invalid --theme "${theme}". Expected auto, import, or none.`)
206
+ }
207
+ options.theme = theme
208
+ break
209
+ }
210
+ case "--no-theme":
211
+ options.theme = "none"
212
+ break
153
213
  case "--manifest-url":
154
214
  options.manifestUrl = readFlagValue(args, ++index, "--manifest-url")
155
215
  break
@@ -206,7 +266,7 @@ async function detectFramework(cwd, packageJson) {
206
266
  }
207
267
 
208
268
  if (dependencies.next) {
209
- if (await pathExists(path.join(cwd, "pages"))) {
269
+ if (await pathExists(path.join(cwd, "pages")) || await pathExists(path.join(cwd, "src", "pages"))) {
210
270
  return "next-pages"
211
271
  }
212
272
 
@@ -217,7 +277,7 @@ async function detectFramework(cwd, packageJson) {
217
277
  return "vite"
218
278
  }
219
279
 
220
- return "generic"
280
+ return "manual"
221
281
  }
222
282
 
223
283
  async function detectPackageManager(cwd) {
@@ -249,11 +309,7 @@ async function pathExists(filePath) {
249
309
  }
250
310
 
251
311
  function buildModulePlan(options) {
252
- const modules = ["core"]
253
-
254
- if (options.withOnlineExample) {
255
- modules.push("server")
256
- }
312
+ const modules = ["core", "server", "starter"]
257
313
 
258
314
  if (options.withViews || options.withOnlineExample || options.withUrlSync) {
259
315
  modules.push("examples")
@@ -274,10 +330,11 @@ function printDryRunPlan(plan) {
274
330
  console.log(`URL sync example: ${plan.withUrlSync ? "included" : "not included"}`)
275
331
  console.log(`Saved views example: ${plan.withViews ? "included" : "not included"}`)
276
332
  console.log(`Online example: ${plan.withOnlineExample ? "included" : "not included"}`)
333
+ console.log(`Theme setup: ${plan.theme}`)
277
334
  console.log("")
278
335
  console.log("Would copy licensed source archive(s) after token validation.")
279
336
  console.log(`Would install core dependencies: ${plan.dependencies.join(" ")}`)
280
- console.log("Would add Tailwind @source for the target when a safe global CSS file is detected.")
337
+ console.log("Would configure Tailwind @source and datatable theme CSS when a safe global CSS file is detected.")
281
338
  console.log("No app-level providers will be modified.")
282
339
 
283
340
  if (plan.noInstall) {
@@ -310,7 +367,7 @@ async function installDatatable(cwd, plan, token) {
310
367
  await writeFile(path.join(targetPath, "LICENSE.react-datatable.txt"), manifest.license.text)
311
368
  }
312
369
 
313
- await addTailwindSourceIfPossible(installRoot, targetPath)
370
+ await configureTailwindCssIfPossible(installRoot, plan)
314
371
 
315
372
  if (!plan.noInstall) {
316
373
  installDependencies(plan.packageManager, manifest.modules.core?.dependencies ?? CORE_DEPENDENCIES, cwd)
@@ -319,6 +376,10 @@ async function installDatatable(cwd, plan, token) {
319
376
  console.log("react-datatable installed")
320
377
  console.log(`Target: ${path.relative(cwd, targetPath) || "."}`)
321
378
  console.log(`Modules: ${plan.modules.join(", ")}`)
379
+ console.log("")
380
+ console.log("Try it:")
381
+ console.log(` import { DatatableStarter } from "${formatStarterImportPath(plan.target)}"`)
382
+ console.log(" render <DatatableStarter />")
322
383
  if (plan.noInstall) {
323
384
  console.log("Dependency installation skipped by --no-install.")
324
385
  }
@@ -435,21 +496,53 @@ async function extractArchive(archivePath, destinationDir) {
435
496
  }
436
497
  }
437
498
 
438
- async function addTailwindSourceIfPossible(root, targetPath) {
499
+ async function configureTailwindCssIfPossible(root, plan) {
439
500
  const cssPath = await findTailwindCssFile(root)
440
501
  if (!cssPath) {
502
+ console.warn("Warning: could not find a Tailwind CSS entry file. Add Tailwind source scanning and the datatable theme import manually.")
441
503
  return
442
504
  }
443
505
 
444
- const source = await readFile(cssPath, "utf8")
445
- const relativeTarget = toPosixRelative(path.dirname(cssPath), targetPath)
446
- const directive = `@source "${relativeTarget}";`
506
+ const originalSource = await readFile(cssPath, "utf8")
507
+ let source = originalSource
508
+ const themeStatus = getThemeStatus(source)
509
+ const themeImport = buildThemeImportDirective(root, cssPath, plan)
510
+
511
+ if (plan.theme === "none") {
512
+ if (!themeStatus.complete) {
513
+ console.warn(`Warning: datatable theme setup skipped by --no-theme. Missing required theme tokens: ${themeStatus.missing.join(", ")}.`)
514
+ }
515
+ } else if (plan.theme === "import" || !themeStatus.complete) {
516
+ if (themeStatus.present.length > 0 && !themeStatus.complete) {
517
+ console.warn(`Warning: existing Tailwind theme is missing required theme tokens: ${themeStatus.missing.join(", ")}. Importing datatable defaults without overwriting existing declarations.`)
518
+ }
519
+ source = addCssImportIfMissing(source, themeImport)
520
+ }
521
+
522
+ const targetPath = path.resolve(root, plan.target)
523
+ const sourceTargets = [targetPath]
524
+ if (plan.modules.includes("starter")) {
525
+ sourceTargets.push(path.join(path.dirname(targetPath), "react-datatable-starter"))
526
+ }
527
+
528
+ const directives = sourceTargets
529
+ .map((sourceTarget) => {
530
+ const relativeTarget = toPosixRelative(path.dirname(cssPath), sourceTarget)
531
+ return {
532
+ relativeTarget,
533
+ directive: `@source "${relativeTarget}";`,
534
+ }
535
+ })
536
+ .filter(({ directive }) => !source.includes(directive))
447
537
 
448
- if (source.includes(directive) || source.includes(relativeTarget)) {
538
+ if (directives.length === 0) {
539
+ if (source !== originalSource) {
540
+ await writeFile(cssPath, `${source.trimEnd()}\n`)
541
+ }
449
542
  return
450
543
  }
451
544
 
452
- await writeFile(cssPath, `${source.trimEnd()}\n${directive}\n`)
545
+ await writeFile(cssPath, `${source.trimEnd()}\n${directives.map(({ directive }) => directive).join("\n")}\n`)
453
546
  }
454
547
 
455
548
  async function findTailwindCssFile(root) {
@@ -459,6 +552,7 @@ async function findTailwindCssFile(root) {
459
552
  "src/globals.css",
460
553
  "src/app/globals.css",
461
554
  "src/styles.css",
555
+ "src/styles/app.css",
462
556
  "src/styles/global.css",
463
557
  "app/globals.css",
464
558
  "app/app.css",
@@ -480,7 +574,7 @@ async function findTailwindCssFile(root) {
480
574
  }
481
575
 
482
576
  function containsTailwindDirective(source) {
483
- return /@import\s+["']tailwindcss["']/.test(source) || /@tailwind\s+/.test(source) || /@source\s+/.test(source)
577
+ return /@import\s+["']tailwindcss["']/.test(source) || /@source\s+/.test(source)
484
578
  }
485
579
 
486
580
  function toPosixRelative(fromDir, toPath) {
@@ -488,6 +582,65 @@ function toPosixRelative(fromDir, toPath) {
488
582
  return relativePath.startsWith(".") ? relativePath : `./${relativePath}`
489
583
  }
490
584
 
585
+ function buildThemeImportDirective(root, cssPath, plan) {
586
+ const themePath = path.join(path.resolve(root, plan.target), "styles", "datatable.css")
587
+ return `@import "${toPosixRelative(path.dirname(cssPath), themePath)}";`
588
+ }
589
+
590
+ function addCssImportIfMissing(source, directive) {
591
+ if (source.includes(directive)) {
592
+ return source
593
+ }
594
+
595
+ const lines = source.split("\n")
596
+ const tailwindImportIndex = lines.findIndex((line) => /@import\s+["']tailwindcss["']/.test(line.trim()))
597
+ if (tailwindImportIndex >= 0) {
598
+ lines.splice(tailwindImportIndex + 1, 0, directive)
599
+ return lines.join("\n")
600
+ }
601
+
602
+ let insertIndex = 0
603
+ for (let index = 0; index < lines.length; index += 1) {
604
+ const line = lines[index].trim()
605
+ if (line === "") {
606
+ continue
607
+ }
608
+ if (/^@import\s+/.test(line)) {
609
+ insertIndex = index + 1
610
+ continue
611
+ }
612
+ break
613
+ }
614
+
615
+ lines.splice(insertIndex, 0, directive)
616
+ return lines.join("\n")
617
+ }
618
+
619
+ function getThemeStatus(source) {
620
+ const variables = [...REQUIRED_THEME_VARIABLES, ...REQUIRED_TAILWIND_THEME_VARIABLES]
621
+ const missing = variables.filter((variable) => !hasCssVariableDeclaration(source, variable))
622
+ const present = variables.filter((variable) => hasCssVariableDeclaration(source, variable))
623
+
624
+ return {
625
+ complete: missing.length === 0,
626
+ missing,
627
+ present,
628
+ }
629
+ }
630
+
631
+ function hasCssVariableDeclaration(source, variable) {
632
+ return new RegExp(`${escapeRegExp(variable)}\\s*:`).test(source)
633
+ }
634
+
635
+ function escapeRegExp(value) {
636
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
637
+ }
638
+
639
+ function formatStarterImportPath(target) {
640
+ const starterPath = path.posix.join(path.posix.dirname(target.split(path.sep).join("/")), "react-datatable-starter")
641
+ return starterPath.startsWith(".") ? starterPath : `./${starterPath}`
642
+ }
643
+
491
644
  function installDependencies(packageManager, dependencies, cwd) {
492
645
  if (dependencies.length === 0) {
493
646
  return
@@ -513,12 +666,14 @@ function printHelp() {
513
666
 
514
667
  Options:
515
668
  --dry-run
516
- --framework vite | next-app | next-pages | tanstack-start | react-router | astro | laravel | manual | generic
669
+ --framework vite | next-app | next-pages | tanstack-start | react-router | astro | laravel | manual
517
670
  --target src/react-datatable
518
671
  --manifest-url https://react-datatable.com/api/install/manifest
519
672
  --with-url-sync
520
673
  --with-views
521
674
  --with-online-example
522
675
  --persistence local-storage | session-storage
676
+ --theme auto | import | none
677
+ --no-theme
523
678
  --no-install`)
524
679
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@react-datatable/cli",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "Licensed source installer for react-datatable.",
5
5
  "type": "module",
6
6
  "bin": {
7
- "react-datatable": "./bin/react-datatable.mjs"
7
+ "react-datatable": "bin/react-datatable.mjs"
8
8
  },
9
9
  "files": [
10
10
  "bin"