npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pal-cli

v1.0.0

Published

Command line tool for generating Angular controllers, directives, and services

Downloads

3

Readme

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-cli

Configuration

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:

  • -m or --module: Angular module on which to create the controller. Default: app
  • -d or --dependencies: A comma-separated list of dependencies to inject into the controller. Wrap in quotes to preserve special characters like $
  • -a or --array_syntax: [Toggle] Use array syntax for dependency injection
  • -c or --classy: [Toggle] Use Angular Classy syntax for controller syntax

Example

pal make:controller LoginCtrl -d '$scope,$http,$q,$timeout' -m myModule -a

Running 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:

  • -m or --module: Angular module on which to create the directive. Default: app
  • -d or --dependencies: A comma-separated list of dependencies to inject into the directive. Wrap in quotes to preserve special characters like $
  • -t or --template: Template URL for the directive
  • -r or --restrict: Directive restrict type: A, E or AE. Default: E
  • -a or --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 -a

Running 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:

  • -m or --module: Angular module on which to create the factory. Default: app
  • -d or --dependencies: A comma-separated list of dependencies to inject into the factory. Wrap in quotes to preserve special characters like $
  • -a or --array_syntax: [Toggle] Use array syntax for dependency injection

Example

pal make:factory Users -d '$http,$q,AccountService' -m myModule -a

Running 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:

  • -m or --module: Angular module on which to create the service. Default: app
  • -d or --dependencies: A comma-separated list of dependencies to inject into the service. Wrap in quotes to preserve special characters like $
  • -a or --array_syntax: [Toggle] Use array syntax for dependency injection

Example

pal make:service AccountService -d '$http,$q' -m myModule -a

Running 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:config

Example

pal make:config

Running 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_dir

Running 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.js
  • controller_array.js
  • controller_classy.js
  • directive.js
  • directive_array.js
  • factory.js
  • factory_array.js
  • service.js
  • service_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_templates

Keywords

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, E or AE

Template files:

  • controller.js: Used for command make:controller
  • controller_array.js: Used for commands make:controller -a and make:controller --array_syntax
  • controller_classy.js: Used for commands make:controller -c and make:controller --classy
  • directive.js: Used for command make:directive
  • directive_array.js: Used for commands make:directive -a and make:directive --array_syntax
  • factory.js: Used for command make:factory
  • factory_array.js: Used for commands make:factory -a and make:factory --array_syntax
  • service.js: Used for command make:service
  • service_array.js: Used for commands make:service -a and make: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