@react-datatable/cli 1.2.1 → 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,14 +376,84 @@ 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
  }
386
+ printLicenseSummary(manifest.license, path.relative(cwd, path.join(targetPath, "LICENSE.react-datatable.txt")) || "LICENSE.react-datatable.txt")
325
387
  } finally {
326
388
  await rm(tempDir, { recursive: true, force: true })
327
389
  }
328
390
  }
329
391
 
392
+ function printLicenseSummary(license, licensePath) {
393
+ if (!license?.licenseType || !license?.licenseeName) {
394
+ return
395
+ }
396
+
397
+ console.log("")
398
+ console.log("License Summary:")
399
+ console.log(`- Licensed to: ${license.licenseeName}`)
400
+ console.log(`- License type: ${formatLicenseType(license.licenseType)}`)
401
+
402
+ if (license.licenseType === "commercial") {
403
+ console.log("- Scope: Use in unlimited internal or commercial applications for the licensed company or individual.")
404
+ console.log("- Source code: May be modified for licensed applications and kept in private repositories.")
405
+ console.log("- Distribution: May be bundled only as part of compiled production builds.")
406
+ console.log("- Not allowed: resale, redistribution, sublicensing, open-source publishing, or transfer to another company or client.")
407
+ } else if (license.licenseType === "trial") {
408
+ const trialPeriod = formatTrialPeriod(license.startsAt, license.expiresAt)
409
+ if (trialPeriod) {
410
+ console.log(`- Trial period: ${trialPeriod}`)
411
+ }
412
+ console.log("- Purpose: Trying and evaluating the software during the trial period.")
413
+ console.log("- Not allowed: internal applications, commercial applications, production deployment, customer-facing products, or revenue-generating products.")
414
+ console.log("- Source code: May not be published open source, redistributed, sublicensed, resold, or transferred.")
415
+ } else if (license.licenseType === "community") {
416
+ console.log("- Scope: Non-commercial projects only.")
417
+ console.log("- Source code: May be modified for those non-commercial projects and kept private.")
418
+ console.log("- Distribution: May be bundled only as part of compiled production builds for non-commercial projects.")
419
+ console.log("- Revocation: License may be revoked without prior notice; after revocation, the software must be removed within 90 days.")
420
+ console.log("- Not allowed: commercial use, internal business use, resale, redistribution, sublicensing, open-source publishing, or transfer.")
421
+ }
422
+
423
+ console.log("")
424
+ console.log("For binding terms, read:")
425
+ console.log(licensePath)
426
+ }
427
+
428
+ function formatLicenseType(type) {
429
+ if (type === "commercial") return "Commercial"
430
+ if (type === "trial") return "Trial"
431
+ if (type === "community") return "Community"
432
+ return type
433
+ }
434
+
435
+ function formatTrialPeriod(startsAt, expiresAt) {
436
+ if (!startsAt || !expiresAt) {
437
+ return ""
438
+ }
439
+
440
+ return `${formatLicenseDate(startsAt)} to ${formatLicenseDate(expiresAt)}`
441
+ }
442
+
443
+ function formatLicenseDate(value) {
444
+ const date = new Date(value)
445
+ if (Number.isNaN(date.getTime())) {
446
+ return String(value)
447
+ }
448
+
449
+ return new Intl.DateTimeFormat("en-US", {
450
+ month: "long",
451
+ day: "numeric",
452
+ year: "numeric",
453
+ timeZone: "UTC",
454
+ }).format(date)
455
+ }
456
+
330
457
  async function fetchInstallManifest(manifestUrl, token) {
331
458
  const response = await fetch(manifestUrl, {
332
459
  method: "POST",
@@ -369,21 +496,53 @@ async function extractArchive(archivePath, destinationDir) {
369
496
  }
370
497
  }
371
498
 
372
- async function addTailwindSourceIfPossible(root, targetPath) {
499
+ async function configureTailwindCssIfPossible(root, plan) {
373
500
  const cssPath = await findTailwindCssFile(root)
374
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.")
375
503
  return
376
504
  }
377
505
 
378
- const source = await readFile(cssPath, "utf8")
379
- const relativeTarget = toPosixRelative(path.dirname(cssPath), targetPath)
380
- 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)
381
510
 
382
- if (source.includes(directive) || source.includes(relativeTarget)) {
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))
537
+
538
+ if (directives.length === 0) {
539
+ if (source !== originalSource) {
540
+ await writeFile(cssPath, `${source.trimEnd()}\n`)
541
+ }
383
542
  return
384
543
  }
385
544
 
386
- await writeFile(cssPath, `${source.trimEnd()}\n${directive}\n`)
545
+ await writeFile(cssPath, `${source.trimEnd()}\n${directives.map(({ directive }) => directive).join("\n")}\n`)
387
546
  }
388
547
 
389
548
  async function findTailwindCssFile(root) {
@@ -393,6 +552,7 @@ async function findTailwindCssFile(root) {
393
552
  "src/globals.css",
394
553
  "src/app/globals.css",
395
554
  "src/styles.css",
555
+ "src/styles/app.css",
396
556
  "src/styles/global.css",
397
557
  "app/globals.css",
398
558
  "app/app.css",
@@ -414,7 +574,7 @@ async function findTailwindCssFile(root) {
414
574
  }
415
575
 
416
576
  function containsTailwindDirective(source) {
417
- 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)
418
578
  }
419
579
 
420
580
  function toPosixRelative(fromDir, toPath) {
@@ -422,6 +582,65 @@ function toPosixRelative(fromDir, toPath) {
422
582
  return relativePath.startsWith(".") ? relativePath : `./${relativePath}`
423
583
  }
424
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
+
425
644
  function installDependencies(packageManager, dependencies, cwd) {
426
645
  if (dependencies.length === 0) {
427
646
  return
@@ -447,12 +666,14 @@ function printHelp() {
447
666
 
448
667
  Options:
449
668
  --dry-run
450
- --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
451
670
  --target src/react-datatable
452
671
  --manifest-url https://react-datatable.com/api/install/manifest
453
672
  --with-url-sync
454
673
  --with-views
455
674
  --with-online-example
456
675
  --persistence local-storage | session-storage
676
+ --theme auto | import | none
677
+ --no-theme
457
678
  --no-install`)
458
679
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@react-datatable/cli",
3
- "version": "1.2.1",
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"