components-differ 1.0.7 → 1.0.8

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.
Files changed (52) hide show
  1. package/README.md +8 -0
  2. package/dist/components.d.ts +6 -0
  3. package/dist/components.d.ts.map +1 -0
  4. package/dist/components.js +106 -0
  5. package/dist/components.js.map +1 -0
  6. package/dist/create-diff.d.ts +14 -0
  7. package/dist/create-diff.d.ts.map +1 -0
  8. package/dist/create-diff.js +61 -0
  9. package/dist/create-diff.js.map +1 -0
  10. package/dist/git.d.ts +5 -0
  11. package/dist/git.d.ts.map +1 -0
  12. package/dist/git.js +120 -0
  13. package/dist/git.js.map +1 -0
  14. package/dist/index.d.ts +3 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +103 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/parse-file-path.d.ts +3 -0
  19. package/dist/parse-file-path.d.ts.map +1 -0
  20. package/dist/parse-file-path.js +36 -0
  21. package/dist/parse-file-path.js.map +1 -0
  22. package/dist/types.d.ts +34 -0
  23. package/dist/types.d.ts.map +1 -0
  24. package/dist/types.js +2 -0
  25. package/dist/types.js.map +1 -0
  26. package/package.json +18 -7
  27. package/index.mjs +0 -114
  28. package/src/components.mjs +0 -98
  29. package/src/create-diff.mjs +0 -91
  30. package/src/git.mjs +0 -141
  31. package/src/parse-file-path.mjs +0 -32
  32. package/tests/fixtures/non-src-dir/app/page.tsx +0 -1
  33. package/tests/fixtures/non-src-dir/components/comp.tsx +0 -1
  34. package/tests/fixtures/non-src-dir/components/ui/new-ui-comp.tsx +0 -1
  35. package/tests/fixtures/non-src-dir/components/ui/select.tsx +0 -1
  36. package/tests/fixtures/non-src-dir/components.json +0 -20
  37. package/tests/fixtures/non-src-dir/hooks/hook.ts +0 -1
  38. package/tests/fixtures/non-src-dir/lib/lib.ts +0 -1
  39. package/tests/fixtures/non-src-dir/non-src-sub/test.ts +0 -1
  40. package/tests/fixtures/non-src-dir/package.json +0 -42
  41. package/tests/fixtures/src-dir/components.json +0 -20
  42. package/tests/fixtures/src-dir/non-src-sub/test.ts +0 -1
  43. package/tests/fixtures/src-dir/package.json +0 -42
  44. package/tests/fixtures/src-dir/src/app/page.tsx +0 -1
  45. package/tests/fixtures/src-dir/src/components/comp.tsx +0 -1
  46. package/tests/fixtures/src-dir/src/components/ui/new-ui-comp.tsx +0 -1
  47. package/tests/fixtures/src-dir/src/components/ui/select.tsx +0 -1
  48. package/tests/fixtures/src-dir/src/hooks/hook.ts +0 -1
  49. package/tests/fixtures/src-dir/src/lib/lib.ts +0 -1
  50. package/tests/tests/__snapshots__/test-fixtures.spec.mjs.snap +0 -129
  51. package/tests/tests/parse-file-path.spec.mjs +0 -105
  52. package/tests/tests/test-fixtures.spec.mjs +0 -86
package/index.mjs DELETED
@@ -1,114 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from "node:fs";
4
- import path from "node:path";
5
- import { program } from "commander";
6
-
7
- import { scanForAlteredFiles, scanForFiles, hasSrcDir } from "./src/git.mjs";
8
- import { readComponentsManifest } from "./src/components.mjs";
9
- import { createDiff } from "./src/create-diff.mjs";
10
- import { execSync } from "node:child_process";
11
-
12
-
13
- program.option("-n, --name <name>").option('--init');
14
- program.parse();
15
-
16
- const options = program.opts();
17
-
18
- const runCommand = (command) => {
19
- try {
20
- execSync(command, { stdio: "inherit" });
21
- } catch (error) {
22
- console.error(`Failed to execute command: ${command}`);
23
- process.exit(1);
24
- }
25
- };
26
-
27
- const ensureGitignore = () => {
28
- const gitignorePath = path.join(process.cwd(), ".gitignore");
29
- if (!fs.existsSync(gitignorePath)) {
30
- console.log(".gitignore file is missing. Creating one...");
31
- const content = `
32
- /node_modules
33
- /.pnp
34
- .pnp.*
35
- .yarn/*
36
- !.yarn/patches
37
- !.yarn/plugins
38
- !.yarn/releases
39
- !.yarn/versions
40
-
41
- # testing
42
- /coverage
43
-
44
- # next.js
45
- /.next/
46
- /out/
47
-
48
- # production
49
- /build
50
-
51
- # misc
52
- .DS_Store
53
- *.pem
54
-
55
- # debug
56
- npm-debug.log*
57
- yarn-debug.log*
58
- yarn-error.log*
59
-
60
- # env files (can opt-in for committing if needed)
61
- .env*
62
-
63
- # vercel
64
- .vercel
65
-
66
- # typescript
67
- *.tsbuildinfo
68
- next-env.d.ts
69
- `;
70
- fs.writeFileSync(gitignorePath, content, "utf8");
71
- console.log(".gitignore file created with default rules.");
72
- } else {
73
- console.log(".gitignore file already exists.");
74
- }
75
- };
76
-
77
- const main = () => {
78
- if (options.init) {
79
- console.log("Initializing git repository for new component");
80
- // Cross-platform logic
81
- if (process.platform === "win32") {
82
- runCommand("rmdir /s /q .git && git init && git add . && git commit -m \"Initial commit\"");
83
- } else {
84
- runCommand("rm -fr .git && git init && git add . && git commit -m \"Initial commit\"");
85
- }
86
- ensureGitignore()
87
- return;
88
- }
89
-
90
- const name = options.name || path.basename(process.cwd());
91
-
92
- const { alteredFiles, specificFiles } = scanForAlteredFiles([
93
- "./package.json",
94
- ]);
95
- const currentFiles = scanForFiles(process.cwd());
96
-
97
- const currentPackageJson = fs.readFileSync("./package.json", "utf-8");
98
-
99
- const config = readComponentsManifest(process.cwd());
100
- config.isSrcDir = hasSrcDir(process.cwd());
101
-
102
- const output = createDiff({
103
- name,
104
- config,
105
- alteredFiles,
106
- currentFiles,
107
- specificFiles,
108
- currentPackageJson,
109
- });
110
-
111
- console.log(JSON.stringify(output, null, 2));
112
- };
113
-
114
- main();
@@ -1,98 +0,0 @@
1
- import path from "node:path";
2
- import fs from "node:fs";
3
-
4
- const WHITELISTED_COMPONENTS = [
5
- "accordion",
6
- "alert",
7
- "alert-dialog",
8
- "aspect-ratio",
9
- "avatar",
10
- "badge",
11
- "breadcrumb",
12
- "button",
13
- "calendar",
14
- "card",
15
- "carousel",
16
- "chart",
17
- "checkbox",
18
- "collapsible",
19
- "command",
20
- "context-menu",
21
- "table",
22
- "dialog",
23
- "drawer",
24
- "dropdown-menu",
25
- "form",
26
- "hover-card",
27
- "input",
28
- "input-otp",
29
- "label",
30
- "menubar",
31
- "navigation-menu",
32
- "pagination",
33
- "popover",
34
- "progress",
35
- "radio-group",
36
- "resizable",
37
- "scroll-area",
38
- "select",
39
- "separator",
40
- "sheet",
41
- "skeleton",
42
- "slider",
43
- "sonner",
44
- "switch",
45
- "tabs",
46
- "textarea",
47
- "toast",
48
- "toggle",
49
- "toggle-group",
50
- "tooltip",
51
- ];
52
-
53
- export function findComponentFiles(config, originalFiles) {
54
- const registryDependencies = [];
55
- const compDir = config.ui.replace("@/", config.isSrcDir ? "src/" : "");
56
- for (const { path: filePath } of originalFiles) {
57
- if (filePath.startsWith(compDir)) {
58
- const fileExtension = path.extname(filePath);
59
- const fileName = path.basename(filePath, fileExtension);
60
- if (
61
- (fileExtension === ".tsx" || fileExtension === ".jsx") &&
62
- WHITELISTED_COMPONENTS.includes(fileName)
63
- ) {
64
- registryDependencies.push(path.basename(filePath, fileExtension));
65
- }
66
- }
67
- }
68
- return registryDependencies;
69
- }
70
-
71
- export function readComponentsManifest(dir) {
72
- const manifestPath = path.join(dir, "./components.json");
73
- if (fs.existsSync(manifestPath)) {
74
- const config = JSON.parse(fs.readFileSync(manifestPath, "utf-8")).aliases;
75
- return config;
76
- } else {
77
- console.error("Components manifest not found");
78
- process.exit(1);
79
- }
80
- }
81
-
82
- export function getAliasedPaths(config) {
83
- return [
84
- config.components.replace("@/", ""),
85
- config.utils.replace("@/", ""),
86
- config.ui.replace("@/", ""),
87
- config.lib.replace("@/", ""),
88
- config.hooks.replace("@/", ""),
89
- ];
90
- }
91
-
92
- export function isBuiltinComponent(config, filePath) {
93
- if (filePath.startsWith(config.ui.replace("@/", ""))) {
94
- const component = path.basename(filePath, path.extname(filePath));
95
- return WHITELISTED_COMPONENTS.includes(component);
96
- }
97
- return false;
98
- }
@@ -1,91 +0,0 @@
1
- import {
2
- findComponentFiles,
3
- getAliasedPaths,
4
- isBuiltinComponent,
5
- } from "./components.mjs";
6
- import { parseFilePath } from "./parse-file-path.mjs";
7
-
8
- function addFile(output, config, inSrcDir, relativeFilePath, content) {
9
- if (!isBuiltinComponent(config, relativeFilePath)) {
10
- output.files.push(
11
- parseFilePath(inSrcDir, config, `./${relativeFilePath}`, content)
12
- );
13
- }
14
- }
15
-
16
- function addDependencies(
17
- output,
18
- initialPackageContents,
19
- currentPackageContents
20
- ) {
21
- const initialPackageJson = JSON.parse(initialPackageContents);
22
- const currentPackageJson = JSON.parse(currentPackageContents);
23
-
24
- output.dependencies = Object.keys(
25
- currentPackageJson.dependencies || {}
26
- ).filter((dep) => !initialPackageJson.dependencies.hasOwnProperty(dep));
27
- output.devDependencies = Object.keys(
28
- currentPackageJson.devDependencies || {}
29
- ).filter((dep) => !initialPackageJson.devDependencies.hasOwnProperty(dep));
30
- }
31
-
32
- function scanWithSrcDir(output, config, alteredFiles) {
33
- for (const { path, content } of alteredFiles) {
34
- if (path.startsWith("src/")) {
35
- addFile(output, config, true, path.replace("src/", ""), content);
36
- } else {
37
- addFile(output, config, false, path, content);
38
- }
39
- }
40
- }
41
-
42
- function isInAppDir(path) {
43
- return path.startsWith("app/");
44
- }
45
-
46
- function scanWithoutSrcDir(output, config, alteredFiles) {
47
- const aliasedPaths = getAliasedPaths(config);
48
-
49
- for (const { path, content } of alteredFiles) {
50
- addFile(
51
- output,
52
- config,
53
- aliasedPaths.includes(path) || isInAppDir(path),
54
- path,
55
- content
56
- );
57
- }
58
- }
59
-
60
- export function createDiff({
61
- name,
62
- config,
63
- alteredFiles,
64
- specificFiles,
65
- currentFiles,
66
- currentPackageJson,
67
- }) {
68
- const output = {
69
- name,
70
- type: "registry:block",
71
- dependencies: [],
72
- devDependencies: [],
73
- registryDependencies: [],
74
- files: [],
75
- tailwind: {},
76
- cssVars: {},
77
- meta: {},
78
- };
79
-
80
- if (config.isSrcDir) {
81
- scanWithSrcDir(output, config, alteredFiles);
82
- } else {
83
- scanWithoutSrcDir(output, config, alteredFiles);
84
- }
85
-
86
- output.registryDependencies = findComponentFiles(config, currentFiles);
87
-
88
- addDependencies(output, specificFiles["./package.json"], currentPackageJson);
89
-
90
- return output;
91
- }
package/src/git.mjs DELETED
@@ -1,141 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { execSync } from "node:child_process";
4
- import ignore from "ignore";
5
- import { start } from "node:repl";
6
-
7
- const INITIAL_DIR = "_initial";
8
-
9
- const EXCLUDE_DIRS = [
10
- "node_modules",
11
- "dist",
12
- "fonts",
13
- "build",
14
- "public",
15
- "static",
16
- ".next",
17
- ".git",
18
- INITIAL_DIR,
19
- ];
20
-
21
- const EXCLUDE_FILES = [
22
- ".DS_Store",
23
- "next-env.d.ts",
24
- "package-lock.json",
25
- "yarn.lock",
26
- "pnpm-lock.yaml",
27
- "bun.lockb",
28
- "package.json",
29
- "tailwind.config.ts",
30
- "tailwind.config.js",
31
- "components.json",
32
- "favicon.ico",
33
- ];
34
-
35
- function cloneInitialCommit() {
36
- deleteInitialDir();
37
-
38
- try {
39
- // Get the initial commit hash
40
- const initialCommit = execSync("git rev-list --max-parents=0 HEAD")
41
- .toString()
42
- .trim();
43
-
44
- // Clone the initial commit quietly
45
- execSync(`git worktree add -f ${INITIAL_DIR} ${initialCommit}`, {
46
- stdio: "ignore",
47
- });
48
- } catch (error) {
49
- console.error("Error cloning initial commit:", error.message);
50
- process.exit(1);
51
- }
52
- }
53
-
54
- function deleteInitialDir() {
55
- if (fs.existsSync(INITIAL_DIR)) {
56
- fs.rmSync(INITIAL_DIR, { recursive: true });
57
-
58
- try {
59
- execSync("git worktree prune", { stdio: "ignore" });
60
- } catch (error) {
61
- console.error("Error pruning git worktree:", error.message);
62
- }
63
- }
64
- }
65
-
66
- function checkIfFileIsChanged(relativeFilePath) {
67
- const initialFilePath = path.join(INITIAL_DIR, relativeFilePath);
68
- const fullPath = path.join(process.cwd(), relativeFilePath);
69
- if (!fs.existsSync(initialFilePath)) {
70
- return true; // New file
71
- }
72
- const currentContent = fs.readFileSync(fullPath, "utf-8");
73
- const initialContent = fs.readFileSync(initialFilePath, "utf-8");
74
- return currentContent !== initialContent;
75
- }
76
-
77
- export function scanForFiles(startDir, checkFile = false) {
78
- const foundFiles = [];
79
-
80
- let ignorer = () => false;
81
- if (fs.existsSync(path.join(startDir, ".gitignore"))) {
82
- const gitIgnore = ignore().add(
83
- fs.readFileSync(path.join(startDir, ".gitignore")).toString()
84
- );
85
- ignorer = (relativeFilePath) => {
86
- return gitIgnore.ignores(relativeFilePath);
87
- };
88
- }
89
-
90
- function scanDirectory(dir, relativePath = "") {
91
- const entries = fs.readdirSync(dir, { withFileTypes: true });
92
-
93
- for (const entry of entries) {
94
- const fullPath = path.join(dir, entry.name);
95
- const relativeFilePath = path.join(relativePath, entry.name);
96
-
97
- if (entry.isDirectory()) {
98
- if (!EXCLUDE_DIRS.includes(entry.name)) {
99
- scanDirectory(path.join(dir, entry.name), relativeFilePath);
100
- }
101
- } else if (
102
- !checkFile ||
103
- (checkFile && checkIfFileIsChanged(relativeFilePath))
104
- ) {
105
- if (!EXCLUDE_FILES.includes(entry.name) && !ignorer(relativeFilePath)) {
106
- foundFiles.push({
107
- path: relativeFilePath,
108
- content: fs.readFileSync(fullPath, "utf-8"),
109
- });
110
- }
111
- }
112
- }
113
- }
114
-
115
- scanDirectory(startDir);
116
-
117
- return foundFiles;
118
- }
119
-
120
- export function scanForAlteredFiles(specificFilesToReturn = []) {
121
- cloneInitialCommit();
122
-
123
- const alteredFiles = scanForFiles(process.cwd(), true);
124
-
125
- const specificFiles = specificFilesToReturn.reduce((out, file) => {
126
- const fullPath = path.join(process.cwd(), INITIAL_DIR, file);
127
- out[file] = fs.readFileSync(fullPath, "utf-8");
128
- return out;
129
- }, {});
130
-
131
- deleteInitialDir();
132
-
133
- return {
134
- alteredFiles,
135
- specificFiles,
136
- };
137
- }
138
-
139
- export function hasSrcDir(dir) {
140
- return fs.existsSync(path.join(dir, "src"));
141
- }
@@ -1,32 +0,0 @@
1
- function fixAlias(alias) {
2
- return alias.replace("@", ".");
3
- }
4
-
5
- export function parseFilePath(wasInSrcDir, config, filePath, content) {
6
- const out = {
7
- path: filePath,
8
- content,
9
- type: "registry:example",
10
- target: wasInSrcDir ? filePath : `~/${filePath.replace("./", "")}`,
11
- };
12
-
13
- if (filePath.startsWith(fixAlias(config.ui))) {
14
- out.type = "registry:ui";
15
- out.target = undefined;
16
- } else if (filePath.startsWith(fixAlias(config.components))) {
17
- out.type = "registry:block";
18
- out.target = undefined;
19
- } else if (filePath.startsWith(fixAlias(config.hooks))) {
20
- out.type = "registry:hook";
21
- out.target = undefined;
22
- } else if (filePath.startsWith(fixAlias(config.lib))) {
23
- out.type = "registry:lib";
24
- out.target = undefined;
25
- }
26
-
27
- if (out.type === "registry:example") {
28
- out.path = filePath;
29
- }
30
-
31
- return out;
32
- }
@@ -1 +0,0 @@
1
- page;
@@ -1 +0,0 @@
1
- comp;
@@ -1 +0,0 @@
1
- new-ui-comp;
@@ -1,20 +0,0 @@
1
- {
2
- "$schema": "https://ui.shadcn.com/schema.json",
3
- "style": "new-york",
4
- "rsc": true,
5
- "tsx": true,
6
- "tailwind": {
7
- "config": "tailwind.config.ts",
8
- "css": "src/app/globals.css",
9
- "baseColor": "neutral",
10
- "cssVariables": true,
11
- "prefix": ""
12
- },
13
- "aliases": {
14
- "components": "@/components",
15
- "utils": "@/lib/utils",
16
- "ui": "@/components/ui",
17
- "lib": "@/lib",
18
- "hooks": "@/hooks"
19
- }
20
- }
@@ -1 +0,0 @@
1
- hook;
@@ -1 +0,0 @@
1
- lib;
@@ -1 +0,0 @@
1
- non - src - sub;
@@ -1,42 +0,0 @@
1
- {
2
- "name": "template",
3
- "version": "0.1.0",
4
- "private": true,
5
- "scripts": {
6
- "dev": "next dev",
7
- "build": "next build",
8
- "start": "next start",
9
- "lint": "next lint"
10
- },
11
- "dependencies": {
12
- "@radix-ui/react-avatar": "^1.1.0",
13
- "@radix-ui/react-collapsible": "^1.1.0",
14
- "@radix-ui/react-dialog": "^1.1.1",
15
- "@radix-ui/react-dropdown-menu": "^2.1.1",
16
- "@radix-ui/react-icons": "^1.3.0",
17
- "@radix-ui/react-popover": "^1.1.1",
18
- "@radix-ui/react-progress": "^1.1.0",
19
- "@radix-ui/react-separator": "^1.1.0",
20
- "@radix-ui/react-slot": "^1.1.0",
21
- "@workos-inc/authkit-nextjs": "^0.10.1",
22
- "class-variance-authority": "^0.7.0",
23
- "clsx": "^2.1.1",
24
- "lucide-react": "^0.441.0",
25
- "next": "14.2.11",
26
- "react": "^18",
27
- "react-dom": "^18",
28
- "tailwind-merge": "^2.5.2",
29
- "tailwindcss-animate": "^1.0.7",
30
- "vaul": "^0.9.3"
31
- },
32
- "devDependencies": {
33
- "@types/node": "^20",
34
- "@types/react": "^18",
35
- "@types/react-dom": "^18",
36
- "eslint": "^8",
37
- "eslint-config-next": "14.2.11",
38
- "postcss": "^8",
39
- "tailwindcss": "^3.4.1",
40
- "typescript": "^5"
41
- }
42
- }
@@ -1,20 +0,0 @@
1
- {
2
- "$schema": "https://ui.shadcn.com/schema.json",
3
- "style": "new-york",
4
- "rsc": true,
5
- "tsx": true,
6
- "tailwind": {
7
- "config": "tailwind.config.ts",
8
- "css": "src/app/globals.css",
9
- "baseColor": "neutral",
10
- "cssVariables": true,
11
- "prefix": ""
12
- },
13
- "aliases": {
14
- "components": "@/components",
15
- "utils": "@/lib/utils",
16
- "ui": "@/components/ui",
17
- "lib": "@/lib",
18
- "hooks": "@/hooks"
19
- }
20
- }
@@ -1 +0,0 @@
1
- non - src - sub;
@@ -1,42 +0,0 @@
1
- {
2
- "name": "template",
3
- "version": "0.1.0",
4
- "private": true,
5
- "scripts": {
6
- "dev": "next dev",
7
- "build": "next build",
8
- "start": "next start",
9
- "lint": "next lint"
10
- },
11
- "dependencies": {
12
- "@radix-ui/react-avatar": "^1.1.0",
13
- "@radix-ui/react-collapsible": "^1.1.0",
14
- "@radix-ui/react-dialog": "^1.1.1",
15
- "@radix-ui/react-dropdown-menu": "^2.1.1",
16
- "@radix-ui/react-icons": "^1.3.0",
17
- "@radix-ui/react-popover": "^1.1.1",
18
- "@radix-ui/react-progress": "^1.1.0",
19
- "@radix-ui/react-separator": "^1.1.0",
20
- "@radix-ui/react-slot": "^1.1.0",
21
- "@workos-inc/authkit-nextjs": "^0.10.1",
22
- "class-variance-authority": "^0.7.0",
23
- "clsx": "^2.1.1",
24
- "lucide-react": "^0.441.0",
25
- "next": "14.2.11",
26
- "react": "^18",
27
- "react-dom": "^18",
28
- "tailwind-merge": "^2.5.2",
29
- "tailwindcss-animate": "^1.0.7",
30
- "vaul": "^0.9.3"
31
- },
32
- "devDependencies": {
33
- "@types/node": "^20",
34
- "@types/react": "^18",
35
- "@types/react-dom": "^18",
36
- "eslint": "^8",
37
- "eslint-config-next": "14.2.11",
38
- "postcss": "^8",
39
- "tailwindcss": "^3.4.1",
40
- "typescript": "^5"
41
- }
42
- }
@@ -1 +0,0 @@
1
- page;
@@ -1 +0,0 @@
1
- comp;
@@ -1 +0,0 @@
1
- new-ui-comp;
@@ -1 +0,0 @@
1
- hook;
@@ -1 +0,0 @@
1
- lib;