88 * This script downloads and installs Cursor rules into your project's .cursor/rules directory.
99 */
1010
11- // ANSI color codes for terminal output
1211const COLORS = [
1312 'red ' => "\033[0;31m " ,
1413 'green ' => "\033[0;32m " ,
1716 'reset ' => "\033[0m " ,
1817];
1918
20- /**
21- * Print colored message to terminal.
22- */
2319function colorize (string $ message , string $ color ): string {
2420 return COLORS [$ color ] . $ message . COLORS ['reset ' ];
2521}
2622
27- /**
28- * Print message to terminal.
29- */
3023function println (string $ message = '' ): void {
3124 echo $ message . PHP_EOL ;
3225}
3326
34- /**
35- * Get user input with optional default value.
36- */
3727function prompt (string $ message , string $ default = '' ): string {
28+ // Check if input is piped
29+ $ isPiped = !posix_isatty (STDIN );
30+ if ($ isPiped ) {
31+ return $ default ;
32+ }
33+
3834 echo $ message . ($ default ? " [ {$ default }] " : '' ) . ': ' ;
39- $ input = trim (fgets (STDIN ));
40- return $ input ?: $ default ;
35+ $ input = fgets (STDIN );
36+ if ($ input === false ) {
37+ return $ default ;
38+ }
39+ return trim ($ input ) ?: $ default ;
4140}
4241
43- /**
44- * Download a file from URL.
45- */
4642function downloadFile (string $ url , string $ destination ): bool {
4743 $ ch = curl_init ($ url );
4844 if ($ ch === FALSE ) {
@@ -67,7 +63,6 @@ function downloadFile(string $url, string $destination): bool {
6763 return $ success !== FALSE ;
6864}
6965
70- // Script start
7166println (colorize ('Cursor Rules Installer ' , 'blue ' ));
7267println ('================================ ' );
7368println ();
@@ -93,7 +88,6 @@ function downloadFile(string $url, string $destination): bool {
9388 'vue-best-practices.mdc ' ,
9489];
9590
96- // Check if target directory exists
9791if (!file_exists ($ targetDir )) {
9892 println (colorize ("Notice: Directory ' {$ targetDir }' does not exist. " , 'yellow ' ));
9993 println ("It will be created during installation. " );
@@ -114,7 +108,6 @@ function downloadFile(string $url, string $destination): bool {
114108println ();
115109println ('Starting installation... ' );
116110
117- // Create directory if it doesn't exist
118111if (!file_exists ($ targetDir )) {
119112 if (!mkdir ($ targetDir , 0755 , TRUE )) {
120113 println (colorize ("Error: Failed to create directory ' {$ targetDir }' " , 'red ' ));
@@ -123,7 +116,6 @@ function downloadFile(string $url, string $destination): bool {
123116 println (colorize ("Created directory: {$ targetDir }" , 'green ' ));
124117}
125118
126- // Download and install rules
127119$ installedFiles = [];
128120foreach ($ ruleFiles as $ file ) {
129121 $ url = "{$ baseUrl }/ {$ file }" ;
@@ -137,7 +129,6 @@ function downloadFile(string $url, string $destination): bool {
137129 }
138130}
139131
140- // Installation summary
141132println ();
142133println (colorize ('Installation Complete! ' , 'green ' ));
143134println ('-------------------------------- ' );
@@ -149,5 +140,4 @@ function downloadFile(string $url, string $destination): bool {
149140println (colorize ('Cursor rules have been installed successfully! ' , 'green ' ));
150141println ('You can now use these rules in your project. ' );
151142
152- // Self-delete
153143@unlink (__FILE__ );
0 commit comments