components-differ 1.2.2 → 1.2.4

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/dist/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,111 +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
- "button-group",
14
- "calendar",
15
- "card",
16
- "carousel",
17
- "chart",
18
- "checkbox",
19
- "collapsible",
20
- "combobox",
21
- "command",
22
- "context-menu",
23
- "data-table",
24
- "date-picker",
25
- "dialog",
26
- "drawer",
27
- "dropdown-menu",
28
- "empty",
29
- "field",
30
- "form",
31
- "hover-card",
32
- "input",
33
- "input-group",
34
- "input-otp",
35
- "item",
36
- "kbd",
37
- "label",
38
- "menubar",
39
- "native-select",
40
- "navigation-menu",
41
- "pagination",
42
- "popover",
43
- "progress",
44
- "radio-group",
45
- "resizable",
46
- "scroll-area",
47
- "select",
48
- "separator",
49
- "sheet",
50
- "sidebar",
51
- "skeleton",
52
- "slider",
53
- "sonner",
54
- "spinner",
55
- "switch",
56
- "table",
57
- "tabs",
58
- "textarea",
59
- "toast",
60
- "toggle",
61
- "toggle-group",
62
- "tooltip",
63
- "typography",
64
- ];
65
-
66
- export function findComponentFiles(config, originalFiles) {
67
- const registryDependencies = [];
68
- const compDir = config.ui.replace("@/", config.isSrcDir ? "src/" : "");
69
- for (const { path: filePath } of originalFiles) {
70
- if (filePath.startsWith(compDir)) {
71
- const fileExtension = path.extname(filePath);
72
- const fileName = path.basename(filePath, fileExtension);
73
- if (
74
- (fileExtension === ".tsx" || fileExtension === ".jsx") &&
75
- WHITELISTED_COMPONENTS.includes(fileName)
76
- ) {
77
- registryDependencies.push(path.basename(filePath, fileExtension));
78
- }
79
- }
80
- }
81
- return registryDependencies;
82
- }
83
-
84
- export function readComponentsManifest(dir) {
85
- const manifestPath = path.join(dir, "./components.json");
86
- if (fs.existsSync(manifestPath)) {
87
- const config = JSON.parse(fs.readFileSync(manifestPath, "utf-8")).aliases;
88
- return config;
89
- } else {
90
- console.error("Components manifest not found");
91
- process.exit(1);
92
- }
93
- }
94
-
95
- export function getAliasedPaths(config) {
96
- return [
97
- config.components.replace("@/", ""),
98
- config.utils.replace("@/", ""),
99
- config.ui.replace("@/", ""),
100
- config.lib.replace("@/", ""),
101
- config.hooks.replace("@/", ""),
102
- ];
103
- }
104
-
105
- export function isBuiltinComponent(config, filePath) {
106
- if (filePath.startsWith(config.ui.replace("@/", ""))) {
107
- const component = path.basename(filePath, path.extname(filePath));
108
- return WHITELISTED_COMPONENTS.includes(component);
109
- }
110
- return false;
111
- }
@@ -1,96 +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
- const initialDependencies = initialPackageJson.dependencies ?? {};
25
- const currentDependencies = currentPackageJson.dependencies ?? {};
26
- const initialDevDependencies = initialPackageJson.devDependencies ?? {};
27
- const currentDevDependencies = currentPackageJson.devDependencies ?? {};
28
-
29
- output.dependencies = Object.keys(currentDependencies).filter(
30
- (dep) => !Object.prototype.hasOwnProperty.call(initialDependencies, dep)
31
- );
32
- output.devDependencies = Object.keys(currentDevDependencies).filter(
33
- (dep) => !Object.prototype.hasOwnProperty.call(initialDevDependencies, dep)
34
- );
35
- }
36
-
37
- function scanWithSrcDir(output, config, alteredFiles) {
38
- for (const { path, content } of alteredFiles) {
39
- if (path.startsWith("src/")) {
40
- addFile(output, config, true, path.replace("src/", ""), content);
41
- } else {
42
- addFile(output, config, false, path, content);
43
- }
44
- }
45
- }
46
-
47
- function isInAppDir(path) {
48
- return path.startsWith("app/");
49
- }
50
-
51
- function scanWithoutSrcDir(output, config, alteredFiles) {
52
- const aliasedPaths = getAliasedPaths(config);
53
-
54
- for (const { path, content } of alteredFiles) {
55
- addFile(
56
- output,
57
- config,
58
- aliasedPaths.includes(path) || isInAppDir(path),
59
- path,
60
- content
61
- );
62
- }
63
- }
64
-
65
- export function createDiff({
66
- name,
67
- config,
68
- alteredFiles,
69
- specificFiles,
70
- currentFiles,
71
- currentPackageJson,
72
- }) {
73
- const output = {
74
- name,
75
- type: "registry:block",
76
- dependencies: [],
77
- devDependencies: [],
78
- registryDependencies: [],
79
- files: [],
80
- tailwind: {},
81
- cssVars: {},
82
- meta: {},
83
- };
84
-
85
- if (config.isSrcDir) {
86
- scanWithSrcDir(output, config, alteredFiles);
87
- } else {
88
- scanWithoutSrcDir(output, config, alteredFiles);
89
- }
90
-
91
- output.registryDependencies = findComponentFiles(config, currentFiles);
92
-
93
- addDependencies(output, specificFiles["./package.json"], currentPackageJson);
94
-
95
- return output;
96
- }