dslinter 0.1.1 → 0.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.1.3
4
+
5
+ [compare changes](https://github.com/jrmybtlr/DSLinter/compare/v0.1.2...v0.1.3)
6
+
7
+ ## v0.1.2
8
+
9
+ [compare changes](https://github.com/jrmybtlr/DSLinter/compare/v0.1.1...v0.1.2)
10
+
3
11
  ## v0.1.1
4
12
 
5
13
  [compare changes](https://github.com/jrmybtlr/DSLinter/compare/v0.1.0...v0.1.1)
package/README.md CHANGED
@@ -48,6 +48,7 @@ The crates.io crate **`dslint`** is a **different project**. Use **`cargo instal
48
48
  Typical usage:
49
49
 
50
50
  ```bash
51
+ npx dslinter init # scaffold src/playground/buildRegistry.ts
51
52
  npx dslinter # dev (watch + dashboard)
52
53
  npx dslinter --report /path/to/repo --json
53
54
  npx dslinter --report --output public/dslint-report.json
@@ -71,11 +72,53 @@ Set `DSLINT_SERVE_PORT` to override the default scanner port (`7878`). Your Vite
71
72
  @import "dslinter/theme.css";
72
73
  ```
73
74
 
75
+ ## Live component previews (consumer Vite apps)
76
+
77
+ If the dashboard shows **“Scan snapshot — no live preview”** for a component that appears in the catalog, the scanner found the file but Vite did not load it. Wire previews in three steps:
78
+
79
+ 1. **Scaffold** (optional): `npx dslinter init` → `src/playground/buildRegistry.ts`; for Inertia/Laravel (`resources/js/…`) use `npx dslinter init --laravel`
80
+ 2. **Glob** must cover nested paths, e.g. `import.meta.glob("../components/**/*.{tsx,jsx}", { eager: true })`
81
+ 3. **App**: pass `playgroundEntries` and `playgroundJoinSkips` from the registry into `DashboardLayout`
82
+
83
+ ```tsx
84
+ import { useMemo } from "react";
85
+ import { DashboardLayout, useWorkspaceReport } from "dslinter";
86
+ import {
87
+ buildPlaygroundEntries,
88
+ getPlaygroundJoinSkips,
89
+ } from "./playground/buildRegistry";
90
+
91
+ const dslinterReport = useWorkspaceReport({
92
+ reportUrl: "/dslint-report.json",
93
+ watchUrl: "/events",
94
+ });
95
+
96
+ const playgroundEntries = useMemo(
97
+ () => buildPlaygroundEntries(dslinterReport.report),
98
+ [dslinterReport.report],
99
+ );
100
+ const playgroundJoinSkips = useMemo(
101
+ () => getPlaygroundJoinSkips(dslinterReport.report),
102
+ [dslinterReport.report],
103
+ );
104
+
105
+ <DashboardLayout
106
+ playgroundEntries={playgroundEntries}
107
+ playgroundJoinSkips={playgroundJoinSkips}
108
+ dslinterReport={dslinterReport}
109
+ />;
110
+ ```
111
+
112
+ In dev, skipped joins are also logged to the console. The inspect pane shows the expected Vite glob key when a preview fails.
113
+
114
+ Run the scanner from the **project root** (`npx dslinter .`) so `playgrounds[].rel_path` matches your repo layout.
115
+
74
116
  ## Wiring the layout
75
117
 
76
118
  `DashboardLayout` needs:
77
119
 
78
120
  - **`playgroundEntries`** — from the report’s `playgrounds` list joined to your React modules (see repo `demo/src/playground/buildRegistry.ts`).
121
+ - **`playgroundJoinSkips`** (optional) — from `buildPlaygroundEntriesFromReportWithSkips` for richer inspect-pane hints.
79
122
  - **`tokenCatalog`** — token wall data (see `demo/src/tokenCatalog.ts`).
80
123
  - **`dslinterReport`** — from `useWorkspaceReport({ reportUrl: "/dslint-report.json", ... })`.
81
124
 
package/bin/dslinter.mjs CHANGED
@@ -6,10 +6,16 @@ import { parseDslinterArgs } from "./lib/parse-args.mjs";
6
6
  import { runScannerInternal } from "./lib/run-scanner.mjs";
7
7
  import { runBuildMode } from "./modes/build.mjs";
8
8
  import { runDevMode } from "./modes/dev.mjs";
9
+ import { runInitMode } from "./modes/init.mjs";
9
10
  import { runReportMode } from "./modes/report.mjs";
10
11
 
11
12
  const rawArgs = process.argv.slice(2);
12
13
 
14
+ if (rawArgs[0] === "init") {
15
+ runInitMode({ argv: rawArgs.slice(1) });
16
+ process.exit(0);
17
+ }
18
+
13
19
  if (process.env.DSLINTER_INTERNAL === "1") {
14
20
  runScannerInternal(rawArgs);
15
21
  }
@@ -0,0 +1,101 @@
1
+ import { copyFileSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
2
+ import { dirname, join, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+
5
+ const packageRoot = join(dirname(fileURLToPath(import.meta.url)), "../..");
6
+
7
+ /**
8
+ * @param {string} targetDir
9
+ * @returns {"laravel" | "default"}
10
+ */
11
+ function detectInitLayout(targetDir) {
12
+ if (existsSync(join(targetDir, "resources", "js"))) return "laravel";
13
+ return "default";
14
+ }
15
+
16
+ /**
17
+ * @param {{ targetDir?: string; layout?: "laravel" | "default"; argv?: string[] }} opts
18
+ */
19
+ export function runInitMode(opts = {}) {
20
+ const argv = opts.argv ?? [];
21
+ const forceLaravel = argv.includes("--laravel") || argv.includes("--resources-js");
22
+ const targetDir = resolve(
23
+ opts.targetDir ?? argv.find((a) => !a.startsWith("-")) ?? process.cwd(),
24
+ );
25
+ const layout =
26
+ opts.layout ?? (forceLaravel ? "laravel" : detectInitLayout(targetDir));
27
+
28
+ const registryDir =
29
+ layout === "laravel"
30
+ ? join(targetDir, "resources", "js", "playground")
31
+ : join(targetDir, "src", "playground");
32
+ const registryPath = join(registryDir, "buildRegistry.ts");
33
+ const templateName =
34
+ layout === "laravel" ? "buildRegistry.laravel.ts" : "buildRegistry.ts";
35
+ const templatePath = join(
36
+ packageRoot,
37
+ "templates",
38
+ "playground",
39
+ templateName,
40
+ );
41
+
42
+ if (existsSync(registryPath)) {
43
+ process.stderr.write(
44
+ `dslinter init: ${registryPath} already exists — remove it first to re-scaffold.\n`,
45
+ );
46
+ process.exit(1);
47
+ }
48
+
49
+ mkdirSync(registryDir, { recursive: true });
50
+ copyFileSync(templatePath, registryPath);
51
+
52
+ const snippetPath = join(registryDir, "vite.dslinter.snippet.ts");
53
+ const snippetTemplate = join(
54
+ packageRoot,
55
+ "templates",
56
+ "vite.dslinter.snippet.ts",
57
+ );
58
+ if (!existsSync(snippetPath) && existsSync(snippetTemplate)) {
59
+ copyFileSync(snippetTemplate, snippetPath);
60
+ }
61
+
62
+ const appHintPath = join(registryDir, "README.txt");
63
+ writeFileSync(
64
+ appHintPath,
65
+ [
66
+ "Wire live component previews in your App:",
67
+ "",
68
+ " import { useMemo } from 'react';",
69
+ " import { DashboardLayout, useWorkspaceReport } from 'dslinter';",
70
+ layout === "laravel"
71
+ ? " import { buildPlaygroundEntries } from '@/playground/buildRegistry';"
72
+ : " import { buildPlaygroundEntries } from './playground/buildRegistry';",
73
+ "",
74
+ " const dslinterReport = useWorkspaceReport({ reportUrl: '/dslint-report.json', watchUrl: '/events' });",
75
+ " const playgroundEntries = useMemo(() => buildPlaygroundEntries(dslinterReport.report), [dslinterReport.report]);",
76
+ "",
77
+ " <DashboardLayout playgroundEntries={playgroundEntries} dslinterReport={dslinterReport} ... />",
78
+ "",
79
+ "Run the scanner from the repo root: npx dslinter .",
80
+ "",
81
+ ].join("\n"),
82
+ );
83
+
84
+ process.stdout.write(
85
+ [
86
+ "dslinter init: wrote playground registry",
87
+ ` ${registryPath}`,
88
+ "",
89
+ `Layout: ${layout}`,
90
+ "",
91
+ "Next:",
92
+ ` 1. Import buildPlaygroundEntries in your App (see ${registryDir}/README.txt)`,
93
+ " 2. Merge vite.dslinter.snippet.ts into vite.config.ts (proxy + react dedupe)",
94
+ layout === "laravel"
95
+ ? " (Inertia: glob uses resources/js/** — not @dslint-scan unless you add the alias snippet)"
96
+ : "",
97
+ " 3. Run npx dslinter . from the project root",
98
+ "",
99
+ ].join("\n"),
100
+ );
101
+ }