/** * Execute the console command. * * @return mixed */ public function fire() { $args = $this->argument(); $opts = $this->option(); $type = $args['type'] ?: 'app'; $file = file_get_contents(__DIR__ . '/../../views/generators/angular/' . $type . '.js.stub'); if ($type == 'app') { $name = $args['name']; } else { $name = $args['name'] . ucfirst(strtolower($type)); } $data = array_dot(['namespace' => $args['name'], 'name' => $name, 'modules' => isset($opts['modules']) ? $opts['modules'] : '']); $file = Str::smrtr($file, $data, ['<%= ', ' %>']); if (!$args['folder']) { $args['folder'] = 'components'; } $path = $opts['path'] . '/' . $args['folder'] . '/' . $args['name'] . '/'; if (isset($opts['bench'])) { $path = 'workench/' . $opts['bench'] . '/public/src/js/'; } if (!is_dir($path)) { mkdir($path, 0775, true); } $filepath = $path . $name . '.js'; file_put_contents($filepath, $file); $this->info($filepath . ' created'); }
/** * Execute the console command. * * @return mixed */ public function fire() { if ($this->confirm('This will override existing assets files, do you whish to continue ?')) { $dir = __DIR__ . '/../../views/generators/assets/'; $files = glob($dir . '*'); $name = $this->ask('What\'s the name of your project ?', 'my-project'); $description = $this->ask('Please describe your project', 'Laravel awesome project'); foreach ($files as $file) { if (is_file($file)) { $tmp = Arx\classes\Str::smrtr(file_get_contents($file), ['project.name' => strtolower(str_slug($name)), 'project.description' => $description], ['<%=', '%>']); $file = str_replace($dir, '', $file); file_put_contents(base_path($file), $tmp); } elseif (is_dir($file)) { $folder = str_replace($dir, '', $file); app('files')->copyDirectory($file, resource_path('assets/' . $folder)); } } $this->info('Default Arx assets created'); } }
/** * Execute the console command. * * @return mixed */ public function fire() { $args = $this->argument(); $opts = $this->option(); $file = file_get_contents(__DIR__ . '/../../views/generators/js/es6-class.js.stub'); # Define the name of the class $parts = explode('/', $args['name']); $className = array_pop($parts); # Define the folder path of the class $folderPath = implode('/', $parts) . '/'; # Prepare data to replace $data = array_dot(['name' => $className]); # Replace data $file = Str::smrtr($file, $data, ['<%= ', ' %>']); # check if folder exist $path = $opts['path'] . '/' . $folderPath; if (!is_dir($path)) { mkdir($path, 0775, true); } $filepath = $path . $className . '.js'; file_put_contents($filepath, $file); $this->info($filepath . ' created'); }
/** * Fastest template engine ever ! * * @return mixed */ public static function smrtr($haystack, $aMatch, $aDelimiter = array("{", "}")) { return Str::smrtr($haystack, $aMatch, $aDelimiter); }