Exemple #1
0
 public static function runserver($command)
 {
     array_shift($command);
     array_shift($command);
     $cmd_string = implode(':', $command);
     $regex = "/^([a-zA-Z_][a-zA-Z0-9_]*[a-zA-Z0-9])\$/";
     if (preg_match_all($regex, $cmd_string, $regex_output)) {
         $project = $regex_output[0][0];
         if (file_exists('dist/' . $project)) {
             fwrite(STDOUT, "");
             fwrite(STDOUT, Color::BOLD_GREEN . '[RUNNING PROJECT]: ' . $project . Color::RESET . PHP_EOL);
             fwrite(STDOUT, "url-> " . Color::UNDERLINE_BLUE . "http://localhost:9000" . Color::RESET . PHP_EOL);
             fwrite(STDOUT, Drawing::SUCCESS_BOX('Stirlingframe->Run server:', "# Project `{$project}` is running", "# Press Ctrl + c to stop running"));
             fwrite(STDOUT, PHP_EOL);
             chdir('dist/' . $project);
             //                exec("open http://localhost:9000");
             exec('php -S localhost:9000');
         } else {
             fwrite(STDOUT, "");
             $header = 'Stirlingframe run error:';
             $desc = '# Project `' . $project . '` not exist';
             fwrite(STDOUT, Color::BOLD_RED . '[ERROR]: unable to run project.' . Color::RESET . PHP_EOL);
             fwrite(STDOUT, Drawing::ERROR_BOX($header, $desc));
             fwrite(STDOUT, PHP_EOL);
         }
     }
 }
Exemple #2
0
 public static function delete($command)
 {
     array_shift($command);
     array_shift($command);
     $cmd_string = implode(':', $command);
     if (preg_match_all("/^(project|app)[:]([a-zA-z][a-zA-z0-9]+)\$/", $cmd_string, $regex_output)) {
         $type = $regex_output[1][0];
         $name = $regex_output[2][0];
         switch ($type) {
             case 'project':
                 $dir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'dist' . DIRECTORY_SEPARATOR . $name;
                 if (file_exists($dir)) {
                     $chk = true;
                     $confirm = "Are you sure you want to " . Color::RED . "delete" . Color::RESET . " `{$name}` [no/yes]?" . Color::RESET . ': ';
                     fwrite(STDOUT, "");
                     fwrite(STDOUT, $confirm);
                     while ($chk) {
                         $handle = fopen("php://stdin", "r");
                         $line = fgets($handle);
                         if (trim($line) != 'yes' and trim($line) != 'no') {
                             fwrite(STDOUT, "");
                             fwrite(STDOUT, "Just type '" . Color::BOLD_GREEN . "yes'" . Color::RESET . " or '" . Color::BOLD_GREEN . "no'" . Color::RESET . PHP_EOL);
                             fwrite(STDOUT, $confirm);
                         } else {
                             $chk = false;
                         }
                     }
                     if (trim($line) == 'no') {
                         fwrite(STDOUT, "");
                         fwrite(STDOUT, '[ABORTED]: ' . Color::BOLD_UNDERLINE . "Nothing is deleted." . Color::RESET . PHP_EOL . PHP_EOL);
                     } else {
                         self::$i = 0;
                         self::$allfiles = self::count_files($dir . '/');
                         StopWatch::start();
                         self::rrmdir($dir);
                         $seconds = round(StopWatch::elapsed(), 4);
                         fwrite(STDERR, "");
                         fwrite(STDERR, PHP_EOL);
                         fwrite(STDOUT, "");
                         fwrite(STDOUT, Color::BOLD_GREEN . '[SUCCESS]: Project deleted.' . Color::RESET . PHP_EOL);
                         fwrite(STDOUT, Drawing::SUCCESS_BOX('Stirlingframe->Delelte:', "# Project `{$name}` has been delete.", "# " . self::$allfiles . " files have been removed in " . $seconds . "s."));
                         fwrite(STDOUT, PHP_EOL);
                     }
                 } else {
                     fwrite(STDOUT, "");
                     $header = 'Stirlingframe delete error:';
                     $desc = '# Project `' . $name . '` not exist';
                     fwrite(STDOUT, Color::BOLD_RED . '[ERROR]: Can\'t delete project.' . Color::RESET . PHP_EOL);
                     fwrite(STDOUT, Drawing::ERROR_BOX($header, $desc));
                     fwrite(STDOUT, PHP_EOL);
                 }
                 break;
             case 'app':
                 fwrite(STDOUT, '$create ' . $type . ' ' . $name . PHP_EOL);
                 break;
         }
     } else {
         $msg = Color::CYAN . '$' . Color::RESET . ' delete [project|app] [name]               ';
         fwrite(STDOUT, "");
         fwrite(STDOUT, Color::BOLD_RED . '[ERROR]: Invalid command.' . Color::RESET . PHP_EOL);
         fwrite(STDOUT, Drawing::ERROR_BOX('Stirlingframe create error:', '# Invalid parameters: command should be', $msg));
         fwrite(STDOUT, PHP_EOL);
     }
 }