pal-cli v1.0.0
Pal
Pal is a NodeJS command line tool for quickly generating Angular controllers, directives, factories and services from templates. It takes away the pain of manually creating them or remembering their syntax every time you want to use them.
Installation
Pal is available as a Node module on npm. Make sure you have Node and npm installed and run the following to install Pal and make it available globally on your system:
npm install -g pal-cliConfiguration
Pal uses a simple JSON configuration file .palconfig in the root directory of your project. You can use Pal without a .palconfig file, but if you want to override the default options, you have to create one. Use the pal make:config command to create a .palconfig file.
Default .palconfig
{
"angular": {
"controller_dir": "./angular/controllers",
"service_dir": "./angular/services",
"factory_dir": "./angular/factories",
"directive_dir": "./angular/directives"
},
"template_dir": ""
}Available commands
make:controller
Create a new Angular controller in the angular.controller_dir specified in .palconfig (or default to angular/controllers).
Syntax
pal make:controller <name> -d '[dependencies]' -m [module] [-a|-c]Options:
-mor--module: Angular module on which to create the controller. Default:app-dor--dependencies: A comma-separated list of dependencies to inject into the controller. Wrap in quotes to preserve special characters like$-aor--array_syntax: Toggle Use array syntax for dependency injection-cor--classy: Toggle Use Angular Classy syntax for controller syntax
Example
pal make:controller LoginCtrl -d '$scope,$http,$q,$timeout' -m myModule -aRunning the command above will create a new controller in the file LoginCtrl.js with the following contents:
/**
* Login controller
*/
myModule.controller('LoginCtrl', ['$scope', '$http', '$q', '$timeout', function($scope, $http, $q, $timeout) {
}]);make:directive
Create a new Angular directive in the angular.directive_dir specified in .palconfig (or default to angular/directives).
Syntax
pal make:directive <name> -d '[dependencies]' -m [module] -t [template url] -r [restrict type] [-a]Options:
-mor--module: Angular module on which to create the directive. Default:app-dor--dependencies: A comma-separated list of dependencies to inject into the directive. Wrap in quotes to preserve special characters like$-tor--template: Template URL for the directive-ror--restrict: Directive restrict type:A,EorAE. Default:E-aor--array_syntax: Toggle Use array syntax for dependency injection
Example
pal make:directive svgIcons -d '$scope,$timeout' -m myModule -t 'templates/svg-icon.html' -r AE -aRunning the command above will create a new directive in the file svgIcons.js with the following contents:
/**
* svg Icons (directive)
*/
myModule.directive('svgIcons', ['$scope', '$timeout', function($scope, $timeout) {
return {
restrict: 'AE',
templateUrl: 'templates/svg-icon.html',
link: function(scope, element, attr) {
}
};
}]);make:factory
Create a new Angular factory in the angular.factory_dir specified in .palconfig (or default to angular/factories).
Syntax
pal make:factory <name> -d '[dependencies]' -m [module] [-a]Options:
-mor--module: Angular module on which to create the factory. Default:app-dor--dependencies: A comma-separated list of dependencies to inject into the factory. Wrap in quotes to preserve special characters like$-aor--array_syntax: Toggle Use array syntax for dependency injection
Example
pal make:factory Users -d '$http,$q,AccountService' -m myModule -aRunning the command above will create a new factory in the file Users.js with the following contents:
/**
* Users (factory)
*/
myModule.factory('Users', ['$http', '$q', 'AccountService', function($http, $q, AccountService) {
return {
};
}]);make:service
Create a new Angular service in the angular.service_dir specified in .palconfig (or default to angular/services).
Syntax
pal make:service <name> -d '[dependencies]' -m [module] [-a]Options:
-mor--module: Angular module on which to create the service. Default:app-dor--dependencies: A comma-separated list of dependencies to inject into the service. Wrap in quotes to preserve special characters like$-aor--array_syntax: Toggle Use array syntax for dependency injection
Example
pal make:service AccountService -d '$http,$q' -m myModule -aRunning the command above will create a new service in the file AccountService.js with the following contents:
/**
* Account Service (service)
*/
myModule.service('AccountService', ['$http', '$q', function($http, $q) {
}]);make:config
Create a .palconfig file with default options in the current directory
Syntax
pal make:configExample
pal make:configRunning the command above will create a .palconfig file with the following contents:
{
"angular": {
"controller_dir": "./angular/controllers",
"service_dir": "./angular/services",
"factory_dir": "./angular/factories",
"directive_dir": "./angular/directives"
},
"template_dir": ""
}make:templates
Create sample templates for use with Pal in the template_dir specified in .palconfig (or default to pal_templates/).
Syntax
pal make:templates [directory]Example
pal make:templates custom_dirRunning the command above will copy the default template files into the folder custom_dir. It will also set the template_dir option in .palconfig to custom_dir. A .palconfig file will be created if it doesn't already exist.
Default template files:
controller.jscontroller_array.jscontroller_classy.jsdirective.jsdirective_array.jsfactory.jsfactory_array.jsservice.jsservice_array.js
Using custom templates
Pal allows you to specify custom templates from which the controllers, directives, factories and services will be generated. The following command will copy the default templates into your project root in a pal_templates folder. It will also set the template_dir in .palconfig to pal_templates.
pal make:templates pal_templatesKeywords
You can customize the templates however you see fit, placing the following keywords anywhere within the files:
$NAME$: Name of the controller, directive, factory or service$FRIENDLY_NAME$: Human-friendly name of the controller, directive, factory or service (for use in comments)$MODULE_NAME$: Name of the module on which to create the controller, directive, factory or service$DEPENDENCIES$: Comma-separated list of dependencies to inject into the controller, directive, factory or service$DEPENDENCIES_STRING$: Comma-separated list of dependencies with each wrapped in single quotes$TEMPLATE_PATH$: Directive only Path of the directive's template file$RESTRICT_TYPE$: Directive only Directive restrict type:A,EorAE
Template files:
controller.js: Used for commandmake:controllercontroller_array.js: Used for commandsmake:controller -aandmake:controller --array_syntaxcontroller_classy.js: Used for commandsmake:controller -candmake:controller --classydirective.js: Used for commandmake:directivedirective_array.js: Used for commandsmake:directive -aandmake:directive --array_syntaxfactory.js: Used for commandmake:factoryfactory_array.js: Used for commandsmake:factory -aandmake:factory --array_syntaxservice.js: Used for commandmake:serviceservice_array.js: Used for commandsmake:service -aandmake:service --array_syntax
When the templates are compiled, a file is selected (falls back to default template if file not found), the keywords are replaced and the generated file is placed within the directory specified in .palconfig.
License
MIT
11 years ago