components-differ 1.2.1 → 1.2.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/README.md CHANGED
@@ -1,31 +1,106 @@
1
- # ShadCN Project Differ
1
+ # components-differ
2
2
 
3
- This CLI tool figures out the difference between the initial commit of a ShadCN project and the current state of the project and creates a new ShadCN JSON output file with the changes. This ShadCN JSON file can then be used with the ShadCN CLI to generate a new project or add to an existing project.
3
+ `components-differ` is a CLI that inspects a Shadcn-based project and emits a [registry-item](https://ui.shadcn.com/docs/registry/registry-item-json) compatible JSON bundle. The generated bundle captures only the delta between the project’s initial template commit and the current working tree, making it easy to distribute curated component packs or bootstrap new installations.
4
4
 
5
- # Steps
5
+ ## Features
6
6
 
7
- 1. Create a new NextJS app
8
- 2. Add ShadCN to the app
9
- 3. Create a new initial commit; `rm -fr .git && git init && git add . && git commit -m "Initial commit"` or `npx components-differ --init`
10
- 4. Make your updates to the project
11
- 5. Run the CLI tool; `npx components-differ`
7
+ - ⚡️ **Quick diffing** Scans the git history to compare the initial commit against the current state of the repository.
8
+ - 🧠 **Alias aware** – Understands `components.json` aliases and supports projects with or without a `src/` directory.
9
+ - 📦 **Full registry support** Outputs files using the latest Shadcn registry types (`registry:ui`, `registry:block`, `registry:page`, `registry:file`, `registry:theme`, etc.).
10
+ - 🧩 **Automated dependency detection** – Detects new npm dependencies/devDependencies introduced since the initial commit.
11
+ - 🛠️ **Build+publish ready** Includes a reproducible build step, release helpers, and Vitest coverage.
12
12
 
13
- The reason we are recreating the initial commit is so that the resulting JSON output is only the changes to the project after ShadCN was added, and not the entire project history.
13
+ ## Installation
14
14
 
15
- You can then take the resulting JSON ouput and host it on a URL, then use that with the ShadCN CLI to generate a new project or add to an existing project.
15
+ ```bash
16
+ pnpm install components-differ
17
+ # or
18
+ npm install components-differ
19
+ # or
20
+ yarn add components-differ
21
+ ```
22
+
23
+ For one-off usage you can run the CLI with `npx`:
24
+
25
+ ```bash
26
+ npx components-differ
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ### 1. Prepare your project
32
+
33
+ 1. Scaffold a new Next.js application.
34
+ 2. Install [shadcn/ui](https://ui.shadcn.com/docs/components).
35
+ 3. Commit the pristine template so that the first commit represents the baseline.
36
+
37
+ You can use the built-in init helper to automate step 3:
16
38
 
17
39
  ```bash
18
- npx shadcn@latest init http://your-json-output-url
40
+ npx components-differ --init
19
41
  ```
20
42
 
21
- You can use the `--src-dir` flag if you want to use the `src` directory in your project.
43
+ This command wipes the current `.git` folder, initializes a new repository, creates an initial commit, and provisions a sensible `.gitignore`.
44
+
45
+ ### 2. Make changes
46
+
47
+ Add or modify components, hooks, utilities, env files, Tailwind styles, or any other project files.
22
48
 
23
- Or you can add the JSON output to an existing project:
49
+ ### 3. Generate the registry diff
24
50
 
25
51
  ```bash
26
- npx shadcn@latest add http://your-json-output-url
52
+ npx components-differ
27
53
  ```
28
54
 
29
- # Why is this useful?
55
+ The CLI prints a JSON payload describing:
56
+
57
+ - File list with appropriate registry types and targets.
58
+ - New registry dependencies detected in your component directory.
59
+ - Added npm dependencies and devDependencies.
60
+
61
+ You can pipe this JSON to a file or publish it to a URL and consume it with the official Shadcn CLI:
62
+
63
+ ```bash
64
+ npx shadcn@latest init https://your-domain.com/registry.json
65
+ npx shadcn@latest add https://your-domain.com/registry.json
66
+ ```
67
+
68
+ ## CLI Options
69
+
70
+ | Flag | Description |
71
+ | ---- | ----------- |
72
+ | `--name <name>` | Overrides the generated registry item `name`. Defaults to the current folder name. |
73
+ | `--init` | Re-initializes git and creates the baseline commit described above. |
74
+
75
+ ## Development
76
+
77
+ ```bash
78
+ pnpm install # install dependencies
79
+ pnpm test # run Vitest suite (snapshot + unit tests)
80
+ pnpm run build # build the distributable into dist/
81
+ pnpm run release # build, test, and publish (requires npm auth + clean git tree)
82
+ ```
83
+
84
+ The project relies on git worktrees to obtain the baseline commit, so ensure your repository has at least one commit before running the CLI in development.
85
+
86
+ ## How It Works
87
+
88
+ 1. **Worktree clone** – `scanForAlteredFiles` creates a temporary git worktree of the initial commit.
89
+ 2. **File classification** – `parseFilePath` maps files to Shadcn registry types (page, ui, block, theme, style, lib, hook, file, item) while honoring `components.json` aliases and `src/` directory layouts.
90
+ 3. **Manifest parsing** – `readComponentsManifest` reads alias definitions and determines whether the project uses `src/`.
91
+ 4. **Dependency diff** – `createDiff` compares the current `package.json` with the baseline to capture dependency changes.
92
+ 5. **Output assembly** – Files, registry dependencies, metadata, Tailwind placeholders, and CSS variables are assembled into a registry item schema.
93
+
94
+ ## Releasing
95
+
96
+ 1. Update `package.json` version (use `pnpm node ./scripts/bump-version.mjs` for a patch bump).
97
+ 2. Ensure the working tree is clean.
98
+ 3. Run `pnpm run release` to build, test, and publish to npm.
99
+
100
+ ## Contributing
101
+
102
+ Pull requests are welcome! Please accompany feature changes with unit tests or snapshot updates as appropriate. If you’re unsure where files are classified or need new registry types, check `src/parse-file-path.mjs` and corresponding tests under `tests/tests`.
103
+
104
+ ## License
30
105
 
31
- This allows library maintainers or SaaS services to create a one step installer for their library or service into an existing project, or to bootstrap a new project with the library or service.
106
+ MIT © Components Host
@@ -52,8 +52,8 @@ export function parseFilePath(wasInSrcDir, config, filePath, content) {
52
52
  out.type = "registry:component";
53
53
  out.target = undefined;
54
54
  } else {
55
- out.type = "registry:item";
56
- out.target = undefined;
55
+ out.type = "registry:file";
56
+ out.target = `./${sanitizedTargetPath}`;
57
57
  }
58
58
 
59
59
  if (out.type === "registry:example") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "components-differ",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Simple CLI to create Shadcn components from project",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",