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 ( / g i t h u b \. c o m \/ ( [ ^ \/ ] + ) \/ ( [ ^ \/ ] + ) / ) ;
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 } ;
0 commit comments