components-differ 1.2.2 → 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.
- package/README.md +33 -76
- package/dist/components.js +130 -0
- package/dist/create-diff.js +77 -0
- package/dist/extract-imports.js +90 -0
- package/dist/git.js +117 -0
- package/dist/index.js +136 -0
- package/dist/parse-file-path.js +73 -0
- package/dist/release.js +50 -0
- package/dist/resolve-imports.js +103 -0
- package/package.json +14 -43
- package/src/components.ts +170 -0
- package/src/create-diff.ts +156 -0
- package/src/extract-imports.ts +87 -0
- package/{dist/src/git.mjs → src/git.ts} +45 -27
- package/src/index.ts +173 -0
- package/{dist/src/parse-file-path.mjs → src/parse-file-path.ts} +45 -12
- package/src/release.ts +71 -0
- package/src/resolve-imports.ts +121 -0
- package/tsconfig.json +15 -0
- package/dist/index.mjs +0 -114
- package/dist/src/components.mjs +0 -111
- package/dist/src/create-diff.mjs +0 -96
package/src/release.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
type VersionBump = "patch" | "minor" | "major";
|
|
4
|
+
|
|
5
|
+
function run(command: string, args: string[] = []) {
|
|
6
|
+
const full = [command, ...args].join(" ");
|
|
7
|
+
console.log(`\n$ ${full}`);
|
|
8
|
+
|
|
9
|
+
const result = spawnSync(command, args, {
|
|
10
|
+
stdio: "inherit",
|
|
11
|
+
shell: process.platform === "win32",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
if (result.status !== 0) {
|
|
15
|
+
console.error(`\nCommand failed: ${full}`);
|
|
16
|
+
process.exit(result.status === null ? 1 : result.status);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function getVersionBumpFromArgs(): VersionBump {
|
|
21
|
+
const type = (process.argv[2] as VersionBump | undefined) ?? "patch";
|
|
22
|
+
if (!["patch", "minor", "major"].includes(type)) {
|
|
23
|
+
console.error(
|
|
24
|
+
`Invalid version bump "${type}". Use one of: patch, minor, major.`
|
|
25
|
+
);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
return type;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function ensureCleanGit() {
|
|
32
|
+
const result = spawnSync("git", ["status", "--porcelain"], {
|
|
33
|
+
encoding: "utf8",
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
if (result.status !== 0) {
|
|
37
|
+
console.error("Failed to check git status.");
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if ((result.stdout ?? "").trim().length > 0) {
|
|
42
|
+
console.error(
|
|
43
|
+
"Git working tree is not clean. Commit or stash your changes before releasing."
|
|
44
|
+
);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function main() {
|
|
50
|
+
const bump = getVersionBumpFromArgs();
|
|
51
|
+
|
|
52
|
+
console.log("Ensuring clean git working tree...");
|
|
53
|
+
ensureCleanGit();
|
|
54
|
+
|
|
55
|
+
console.log("\nBuilding project...");
|
|
56
|
+
run("npm", ["run", "build"]);
|
|
57
|
+
|
|
58
|
+
console.log(`\nBumping version (${bump})...`);
|
|
59
|
+
run("npm", ["version", bump]);
|
|
60
|
+
|
|
61
|
+
console.log("\nPublishing to npm...");
|
|
62
|
+
run("npm", ["publish"]);
|
|
63
|
+
|
|
64
|
+
console.log("\nRelease complete.");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
main().catch((err) => {
|
|
68
|
+
console.error(err);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
});
|
|
71
|
+
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ComponentsConfig } from "./components.js";
|
|
3
|
+
import { extractPathSpecifiers } from "./extract-imports.js";
|
|
4
|
+
import type { ScannedFile } from "./git.js";
|
|
5
|
+
|
|
6
|
+
const EXTENSIONS = [".tsx", ".ts", ".jsx", ".js", ".mts", ".mjs", ".cts", ".cjs"];
|
|
7
|
+
const INDEX_NAMES = ["index.tsx", "index.ts", "index.jsx", "index.js"];
|
|
8
|
+
|
|
9
|
+
/** Build [aliasPrefix, pathPrefix] pairs, longest first. pathPrefix is project-relative (e.g. src/lib when isSrcDir). */
|
|
10
|
+
function getAliasEntries(config: ComponentsConfig & { isSrcDir?: boolean }): [string, string][] {
|
|
11
|
+
const entries: [string, string][] = [];
|
|
12
|
+
const prefix = config.isSrcDir ? "src/" : "";
|
|
13
|
+
const keys: (keyof ComponentsConfig)[] = ["components", "utils", "ui", "lib", "hooks"];
|
|
14
|
+
for (const k of keys) {
|
|
15
|
+
const v = config[k];
|
|
16
|
+
if (typeof v === "string" && v.startsWith("@/")) {
|
|
17
|
+
const pathPart = v.replace(/^@\//, "").replace(/\/$/, "");
|
|
18
|
+
entries.push([v.replace(/\/$/, ""), prefix + pathPart]);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
entries.push(["@", config.isSrcDir ? "src" : ""]);
|
|
22
|
+
entries.sort((a, b) => b[0].length - a[0].length);
|
|
23
|
+
return entries;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Resolve a path-like import specifier to a project-relative file path.
|
|
28
|
+
* Tries common extensions and /index.*. Returns the first path that exists in projectPaths.
|
|
29
|
+
*/
|
|
30
|
+
function resolveSpecifier(
|
|
31
|
+
specifier: string,
|
|
32
|
+
fromFilePath: string,
|
|
33
|
+
aliasEntries: [string, string][],
|
|
34
|
+
projectPaths: Set<string>,
|
|
35
|
+
rootFallback: string,
|
|
36
|
+
): string | null {
|
|
37
|
+
const normalizedFrom = fromFilePath.replace(/\\/g, "/");
|
|
38
|
+
const fromDir = path.dirname(normalizedFrom).replace(/\\/g, "/");
|
|
39
|
+
|
|
40
|
+
let candidate: string;
|
|
41
|
+
|
|
42
|
+
if (specifier.startsWith(".") || specifier.startsWith("/")) {
|
|
43
|
+
candidate = path.normalize(path.join(fromDir, specifier)).replace(/\\/g, "/");
|
|
44
|
+
} else {
|
|
45
|
+
// Alias: @/components/Button -> components/Button
|
|
46
|
+
let matched = false;
|
|
47
|
+
for (const [aliasPrefix, pathPrefix] of aliasEntries) {
|
|
48
|
+
const prefix = aliasPrefix === "@" ? "@/" : aliasPrefix.endsWith("/") ? aliasPrefix : aliasPrefix + "/";
|
|
49
|
+
if (specifier === aliasPrefix || specifier.startsWith(prefix)) {
|
|
50
|
+
const suffix = specifier.slice(prefix.length).replace(/^\//, "");
|
|
51
|
+
candidate = path.normalize(path.join(pathPrefix, suffix)).replace(/\\/g, "/");
|
|
52
|
+
matched = true;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!matched) {
|
|
57
|
+
const suffix = specifier.replace(/^@\//, "").replace(/^~\//, "");
|
|
58
|
+
candidate = path.normalize(path.join(rootFallback, suffix)).replace(/\\/g, "/");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!candidate) return null;
|
|
63
|
+
if (projectPaths.has(candidate)) return candidate;
|
|
64
|
+
|
|
65
|
+
for (const ext of EXTENSIONS) {
|
|
66
|
+
const p = candidate.endsWith(ext) ? candidate : candidate + ext;
|
|
67
|
+
if (projectPaths.has(p)) return p;
|
|
68
|
+
}
|
|
69
|
+
for (const name of INDEX_NAMES) {
|
|
70
|
+
const p = candidate.endsWith("/") ? candidate + name : candidate + "/" + name;
|
|
71
|
+
if (projectPaths.has(p)) return p;
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Expand the list of included files by recursively adding any project file
|
|
78
|
+
* that is imported (via relative or alias path) by an already-included file.
|
|
79
|
+
* Uses TypeScript/JS import syntax only.
|
|
80
|
+
*/
|
|
81
|
+
export function expandIncludedFiles(
|
|
82
|
+
includedFiles: ScannedFile[],
|
|
83
|
+
allProjectFiles: ScannedFile[],
|
|
84
|
+
config: ComponentsConfig & { isSrcDir?: boolean },
|
|
85
|
+
): ScannedFile[] {
|
|
86
|
+
const projectPathToFile = new Map<string, ScannedFile>();
|
|
87
|
+
for (const f of allProjectFiles) {
|
|
88
|
+
const key = f.path.replace(/\\/g, "/");
|
|
89
|
+
projectPathToFile.set(key, f);
|
|
90
|
+
}
|
|
91
|
+
const projectPaths = new Set(projectPathToFile.keys());
|
|
92
|
+
const aliasEntries = getAliasEntries(config);
|
|
93
|
+
const rootFallback = config.isSrcDir ? "src" : "";
|
|
94
|
+
|
|
95
|
+
const includedPaths = new Set<string>();
|
|
96
|
+
for (const f of includedFiles) {
|
|
97
|
+
includedPaths.add(f.path.replace(/\\/g, "/"));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let added = true;
|
|
101
|
+
while (added) {
|
|
102
|
+
added = false;
|
|
103
|
+
for (const file of [...includedFiles]) {
|
|
104
|
+
const content = file.content;
|
|
105
|
+
const fromPath = file.path.replace(/\\/g, "/");
|
|
106
|
+
for (const spec of extractPathSpecifiers(content)) {
|
|
107
|
+
const resolved = resolveSpecifier(spec, fromPath, aliasEntries, projectPaths, rootFallback);
|
|
108
|
+
if (resolved && !includedPaths.has(resolved)) {
|
|
109
|
+
const scanned = projectPathToFile.get(resolved);
|
|
110
|
+
if (scanned) {
|
|
111
|
+
includedFiles.push(scanned);
|
|
112
|
+
includedPaths.add(resolved);
|
|
113
|
+
added = true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return includedFiles;
|
|
121
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"resolveJsonModule": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"strict": false,
|
|
12
|
+
"skipLibCheck": true
|
|
13
|
+
},
|
|
14
|
+
"include": ["src"]
|
|
15
|
+
}
|
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();
|
package/dist/src/components.mjs
DELETED
|
@@ -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
|
-
}
|
package/dist/src/create-diff.mjs
DELETED
|
@@ -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
|
-
}
|