22
33const fs = require ( "fs" ) ;
44const path = require ( "path" ) ;
5+ const readline = require ( "readline" ) ;
56
6- function createCollectionTemplate ( collectionId ) {
7- if ( ! collectionId ) {
8- console . error ( "Collection ID is required" ) ;
9- console . log ( "Usage: node create-collection.js <collection-id>" ) ;
10- process . exit ( 1 ) ;
11- }
7+ const rl = readline . createInterface ( {
8+ input : process . stdin ,
9+ output : process . stdout
10+ } ) ;
1211
13- // Validate collection ID format
14- if ( ! / ^ [ a - z 0 - 9 - ] + $ / . test ( collectionId ) ) {
15- console . error ( "Collection ID must contain only lowercase letters, numbers, and hyphens" ) ;
16- process . exit ( 1 ) ;
17- }
12+ function prompt ( question ) {
13+ return new Promise ( ( resolve ) => {
14+ rl . question ( question , resolve ) ;
15+ } ) ;
16+ }
1817
19- const collectionsDir = path . join ( __dirname , "collections" ) ;
20- const filePath = path . join ( collectionsDir , `${ collectionId } .collection.yml` ) ;
18+ async function createCollectionTemplate ( ) {
19+ try {
20+ console . log ( "🎯 Collection Creator" ) ;
21+ console . log ( "This tool will help you create a new collection manifest.\n" ) ;
2122
22- // Check if file already exists
23- if ( fs . existsSync ( filePath ) ) {
24- console . error ( `Collection ${ collectionId } already exists at ${ filePath } ` ) ;
25- process . exit ( 1 ) ;
26- }
23+ // Get collection ID
24+ let collectionId ;
25+ if ( process . argv [ 2 ] ) {
26+ collectionId = process . argv [ 2 ] ;
27+ } else {
28+ collectionId = await prompt ( "Collection ID (lowercase, hyphens only): " ) ;
29+ }
2730
28- // Ensure collections directory exists
29- if ( ! fs . existsSync ( collectionsDir ) ) {
30- fs . mkdirSync ( collectionsDir , { recursive : true } ) ;
31- }
31+ // Validate collection ID format
32+ if ( ! collectionId ) {
33+ console . error ( "❌ Collection ID is required" ) ;
34+ process . exit ( 1 ) ;
35+ }
3236
33- // Create a friendly name from the ID
34- const friendlyName = collectionId
35- . split ( "-" )
36- . map ( word => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) )
37- . join ( " " ) ;
38-
39- // Template content
40- const template = `id: ${ collectionId }
41- name: ${ friendlyName }
42- description: A collection of related prompts, instructions, and chat modes for ${ friendlyName . toLowerCase ( ) } .
43- tags: [${ collectionId . split ( "-" ) . slice ( 0 , 3 ) . join ( ", " ) } ] # Add relevant tags
37+ if ( ! / ^ [ a - z 0 - 9 - ] + $ / . test ( collectionId ) ) {
38+ console . error ( "❌ Collection ID must contain only lowercase letters, numbers, and hyphens" ) ;
39+ process . exit ( 1 ) ;
40+ }
41+
42+ const collectionsDir = path . join ( __dirname , "collections" ) ;
43+ const filePath = path . join ( collectionsDir , `${ collectionId } .collection.yml` ) ;
44+
45+ // Check if file already exists
46+ if ( fs . existsSync ( filePath ) ) {
47+ console . log ( `⚠️ Collection ${ collectionId } already exists at ${ filePath } ` ) ;
48+ console . log ( "💡 Please edit that file instead or choose a different ID." ) ;
49+ process . exit ( 1 ) ;
50+ }
51+
52+ // Ensure collections directory exists
53+ if ( ! fs . existsSync ( collectionsDir ) ) {
54+ fs . mkdirSync ( collectionsDir , { recursive : true } ) ;
55+ }
56+
57+ // Get collection name
58+ const defaultName = collectionId
59+ . split ( "-" )
60+ . map ( word => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) )
61+ . join ( " " ) ;
62+
63+ let collectionName = await prompt ( `Collection name (default: ${ defaultName } ): ` ) ;
64+ if ( ! collectionName . trim ( ) ) {
65+ collectionName = defaultName ;
66+ }
67+
68+ // Get description
69+ const defaultDescription = `A collection of related prompts, instructions, and chat modes for ${ collectionName . toLowerCase ( ) } .` ;
70+ let description = await prompt ( `Description (default: ${ defaultDescription } ): ` ) ;
71+ if ( ! description . trim ( ) ) {
72+ description = defaultDescription ;
73+ }
74+
75+ // Get tags
76+ let tags = [ ] ;
77+ const tagInput = await prompt ( "Tags (comma-separated, or press Enter for defaults): " ) ;
78+ if ( tagInput . trim ( ) ) {
79+ tags = tagInput . split ( "," ) . map ( tag => tag . trim ( ) ) . filter ( tag => tag ) ;
80+ } else {
81+ // Generate some default tags from the collection ID
82+ tags = collectionId . split ( "-" ) . slice ( 0 , 3 ) ;
83+ }
84+
85+ // Template content
86+ const template = `id: ${ collectionId }
87+ name: ${ collectionName }
88+ description: ${ description }
89+ tags: [${ tags . join ( ", " ) } ]
4490items:
4591 # Add your collection items here
4692 # Example:
@@ -55,22 +101,23 @@ display:
55101 show_badge: false # set to true to show collection badge on items
56102` ;
57103
58- try {
59104 fs . writeFileSync ( filePath , template ) ;
60105 console . log ( `✅ Created collection template: ${ filePath } ` ) ;
61- console . log ( "\nNext steps:" ) ;
106+ console . log ( "\n📝 Next steps:" ) ;
62107 console . log ( "1. Edit the collection manifest to add your items" ) ;
63108 console . log ( "2. Update the name, description, and tags as needed" ) ;
64109 console . log ( "3. Run 'node validate-collections.js' to validate" ) ;
65110 console . log ( "4. Run 'node update-readme.js' to generate documentation" ) ;
66- console . log ( "\nCollection template contents:" ) ;
111+ console . log ( "\n📄 Collection template contents:" ) ;
67112 console . log ( template ) ;
113+
68114 } catch ( error ) {
69- console . error ( `Error creating collection template: ${ error . message } ` ) ;
115+ console . error ( `❌ Error creating collection template: ${ error . message } ` ) ;
70116 process . exit ( 1 ) ;
117+ } finally {
118+ rl . close ( ) ;
71119 }
72120}
73121
74- // Get collection ID from command line arguments
75- const collectionId = process . argv [ 2 ] ;
76- createCollectionTemplate ( collectionId ) ;
122+ // Run the interactive creation process
123+ createCollectionTemplate ( ) ;
0 commit comments