Skip to content

Commit 29cf49e

Browse files
authored
Merge pull request #29 from Comfy-Org/test/pyproject-generation-validation
[test] Add pyproject.toml generation validation
2 parents abe0907 + 7eb5363 commit 29cf49e

File tree

6 files changed

+484
-8
lines changed

6 files changed

+484
-8
lines changed

bun.lock

Lines changed: 288 additions & 7 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
"release": "bunx standard-version && npm publish",
3737
"start": "next start",
3838
"test": "bun test",
39+
"test:watch": "bun test --watch",
40+
"preview:pyproject": "bun scripts/preview-pyproject-minimal.ts",
41+
"preview:pyproject-repo": "bun scripts/preview-pyproject-toml.ts",
3942
"vercel:build": "vercel build",
4043
"vercel:dev": "vercel dev"
4144
},
@@ -155,6 +158,7 @@
155158
"zx": "^8.5.3"
156159
},
157160
"devDependencies": {
161+
"@jest/globals": "^30.1.2",
158162
"@next/bundle-analyzer": "^15.1.5",
159163
"@types/bun": "^1.1.6",
160164
"@types/d3": "^7.4.3",
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bun
2+
import { mkdir, rm, readFile } from "fs/promises";
3+
import { $ } from "../src/cli/echoBunShell";
4+
import * as path from "path";
5+
import * as os from "os";
6+
7+
/**
8+
* Minimal script to see what comfy node init generates
9+
* Usage: bun scripts/preview-pyproject-minimal.ts
10+
*/
11+
12+
async function previewMinimal() {
13+
const tempDir = path.join(os.tmpdir(), `comfy-pr-minimal-${Date.now()}`);
14+
15+
try {
16+
// Create empty directory
17+
await mkdir(tempDir, { recursive: true });
18+
19+
console.log("🛠️ Running 'comfy node init' in empty directory...\n");
20+
21+
// Run comfy node init in empty directory
22+
await $`cd ${tempDir} && echo N | comfy node init`;
23+
24+
// Read generated file
25+
const content = await readFile(`${tempDir}/pyproject.toml`, "utf8");
26+
27+
console.log("📄 Generated pyproject.toml:\n");
28+
console.log("=".repeat(60));
29+
console.log(content);
30+
console.log("=".repeat(60));
31+
32+
console.log("\n📝 Notes:");
33+
console.log("- In actual PR, the description field would be filled from ComfyUI-Manager DB");
34+
console.log("- The publisher_id would need to be added by the node author");
35+
console.log("- This file would be added to a 'pyproject' branch\n");
36+
37+
} catch (error) {
38+
console.error("❌ Error:", error);
39+
console.error("\n💡 Make sure comfy-cli is installed: pip install comfy-cli");
40+
} finally {
41+
// Cleanup
42+
await rm(tempDir, { recursive: true, force: true }).catch(() => {});
43+
}
44+
}
45+
46+
if (import.meta.main) {
47+
await previewMinimal();
48+
}

scripts/preview-pyproject-toml.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/usr/bin/env bun
2+
import { readFile, writeFile, mkdir, rm } from "fs/promises";
3+
import { $ } from "../src/cli/echoBunShell";
4+
import { existsSync } from "fs";
5+
import * as path from "path";
6+
import * as os from "os";
7+
8+
/**
9+
* Preview what pyproject.toml will be generated for a repository
10+
* Usage: bun scripts/preview-pyproject-toml.ts [--repo GITHUB_URL] [--output FILE]
11+
*/
12+
13+
async function previewPyprojectToml() {
14+
// Parse command line arguments
15+
const args = process.argv.slice(2);
16+
const repoIndex = args.indexOf("--repo");
17+
const outputIndex = args.indexOf("--output");
18+
19+
const repoUrl = repoIndex >= 0 && args[repoIndex + 1]
20+
? args[repoIndex + 1]
21+
: "https://github.com/snomiao/ComfyNode-Registry-test"; // default test repo
22+
23+
const outputFile = outputIndex >= 0 && args[outputIndex + 1]
24+
? args[outputIndex + 1]
25+
: null;
26+
27+
console.log(`\n🔍 Previewing pyproject.toml for: ${repoUrl}\n`);
28+
29+
// Create temporary directory
30+
const tempDir = path.join(os.tmpdir(), `comfy-pr-preview-${Date.now()}`);
31+
await mkdir(tempDir, { recursive: true });
32+
33+
try {
34+
// Clone the repository
35+
console.log("📥 Cloning repository...");
36+
await $`git clone --depth 1 ${repoUrl} ${tempDir}/repo`;
37+
38+
// Change to repo directory
39+
const repoDir = `${tempDir}/repo`;
40+
41+
// Check if pyproject.toml already exists
42+
const existingToml = `${repoDir}/pyproject.toml`;
43+
if (existsSync(existingToml)) {
44+
console.log("⚠️ Repository already has a pyproject.toml file. Backing it up and generating fresh one.\n");
45+
await $`cd ${repoDir} && mv pyproject.toml pyproject.toml.backup`;
46+
}
47+
48+
// Run comfy node init
49+
console.log("🛠️ Running 'comfy node init'...");
50+
await $`cd ${repoDir} && echo N | comfy node init`;
51+
52+
// Read the generated pyproject.toml
53+
const pyprojectContent = await readFile(`${repoDir}/pyproject.toml`, "utf8");
54+
55+
console.log("\n📄 Generated pyproject.toml:\n");
56+
console.log("=" + "=".repeat(59));
57+
console.log(pyprojectContent);
58+
console.log("=" + "=".repeat(59));
59+
60+
// Try to fetch description from ComfyUI-Manager (optional enhancement)
61+
try {
62+
const { fetchRepoDescriptionMap } = await import("../src/fetchRepoDescriptionMap");
63+
const repoDescriptionMap = await fetchRepoDescriptionMap();
64+
const urlParts = repoUrl.match(/github\.com\/([^\/]+)\/([^\/]+)/);
65+
if (urlParts) {
66+
const referenceUrl = `https://github.com/${urlParts[1]}/${urlParts[2]}`;
67+
const description = repoDescriptionMap[referenceUrl];
68+
if (description) {
69+
console.log(`\n💡 Note: The actual PR would replace the description with:\n "${description}"\n`);
70+
}
71+
}
72+
} catch (e) {
73+
console.log("\n💡 Note: Could not fetch description from ComfyUI-Manager database");
74+
}
75+
76+
// Save to output file if specified
77+
if (outputFile) {
78+
await writeFile(outputFile, pyprojectContent);
79+
console.log(`\n✅ Saved to: ${outputFile}`);
80+
}
81+
82+
// Show what modifications would be made
83+
console.log("\n📝 Additional modifications in actual PR:");
84+
console.log(" 1. Description field would be filled from ComfyUI-Manager database");
85+
console.log(" 2. File would be committed with message: 'chore(pyproject): Add pyproject.toml for Custom Node Registry'");
86+
console.log(" 3. Pushed to branch: 'pyproject'\n");
87+
88+
} catch (error) {
89+
console.error("❌ Error:", error);
90+
process.exit(1);
91+
} finally {
92+
// Cleanup
93+
console.log("🧹 Cleaning up temporary files...");
94+
await rm(tempDir, { recursive: true, force: true });
95+
}
96+
}
97+
98+
// Run the preview
99+
if (import.meta.main) {
100+
await previewPyprojectToml();
101+
}
102+
103+
// For testing/mocking purposes, export the function
104+
export { previewPyprojectToml };

scripts/tsconfig.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["ESNext"],
4+
"target": "ESNext",
5+
"module": "ESNext",
6+
"moduleDetection": "force",
7+
"jsx": "preserve",
8+
"allowJs": true,
9+
"moduleResolution": "bundler",
10+
"allowImportingTsExtensions": true,
11+
"verbatimModuleSyntax": true,
12+
"noEmit": true,
13+
"esModuleInterop": true,
14+
"resolvePackageJsonImports": true,
15+
"resolvePackageJsonExports": true,
16+
"strict": true,
17+
"strictNullChecks": true,
18+
"skipLibCheck": true,
19+
"noFallthroughCasesInSwitch": true,
20+
"noUnusedLocals": false,
21+
"noUnusedParameters": false,
22+
"noPropertyAccessFromIndexSignature": false,
23+
"resolveJsonModule": true,
24+
"types": ["bun", "node"],
25+
"baseUrl": "..",
26+
"paths": {
27+
"@/*": ["src/*"]
28+
}
29+
},
30+
"include": [
31+
"*.ts",
32+
"**/*.ts"
33+
],
34+
"exclude": [
35+
"node_modules",
36+
"*.spec.ts"
37+
]
38+
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"node_modules",
5454
"prs/*",
5555
".cache",
56-
"dist"
56+
"dist",
57+
"scripts"
5758
]
5859
}

0 commit comments

Comments
 (0)