Skip to content

Instantly share code, notes, and snippets.

@juanmanavarro
Last active May 27, 2019 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanmanavarro/57a149ce4c559e940a869b6b57c18df2 to your computer and use it in GitHub Desktop.
Save juanmanavarro/57a149ce4c559e940a869b6b57c18df2 to your computer and use it in GitHub Desktop.
(function() {
'use strict';
angular
.module('app')
.component('tm%ComponentName%', tm%ComponentName%());
/* @ngInject */
function tm%ComponentName%() {
var component = {
templateUrl: '/templates/components/%component-name%.html',
controller: Controller,
};
return component;
}
Controller.$inject = [];
/* @ngInject */
function Controller() {
var vm = this;
}
})();
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class MakeAngularComponent extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:ng-component {name : The name of the component camelcased}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Make angular component';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$component_directory = kebab_case($this->argument('name'));
\File::makeDirectory(resource_path('assets/js/components/' . $component_directory));
// component file generation
$js_file_path = $component_directory . '/' . kebab_case($this->argument('name')) . '.component.js';
$component_template_contents = file_get_contents(resource_path('ng-templates/component'));
$component_template_contents = str_replace('%ComponentName%', ucfirst(camel_case($this->argument('name'))), $component_template_contents);
$component_template_contents = str_replace('%component-name%', kebab_case($this->argument('name')), $component_template_contents);
\File::put(resource_path('assets/js/components/' . $js_file_path), $component_template_contents);
// html file generation
$template_file_path = $component_directory . '/' . kebab_case($this->argument('name')) . '.html';
\File::put(resource_path('assets/js/components/' . $template_file_path), '');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment