0.1.3 • Published 9 years ago

skivvy-factory v0.1.3

Weekly downloads
4
License
ISC
Repository
github
Last release
9 years ago

skivvy-factory

npm version Stability Build Status

Create Skivvy tasks from Factory templates

Overview

Skivvy is a modular task runner for reusable build systems, and Factory provides a quick and easy template scaffolding tool for Node. skivvy-factory unites the two, allowing you to turn your Factory templates into reusable Skivvy tasks.

Installation

npm install skivvy-factory --save-dev

Example

As a local Skivvy task:

var skivvyFactory = require('skivvy-factory');

module.exports = skivvyFactory({
	description: 'Create a component',
	template: 'templates/component',
	placeholders: [
		{
			name: 'name',
			message: 'Component name'
		},
		{
			name: 'author',
			message: 'Author',
			default: '<%= project.author %>'
		}
	],
	options: {
		destination: '<%= environment.paths.components %>',
		overwrite: true
	},
	context: {
		license: '<%= project.license %>'
	}
});

After saving this to your skivvy_tasks folder, you can launch your template by running the following commands (where create-component.js is the filename of the task):

# Configure the task
skivvy config --config.paths.components=src/components

# Create a new component
skivvy run create-component

# Create another new component, hard-coding the
# "name" value and preventing accidental overwrite:
skivvy run create-component --config.context.name=foo --config.options.overwrite=false

Within a Skivvy task package:

var skivvyFactory = require('skivvy-factory');

var path = require('path');

exports.tasks = {
	'create-component': skivvyFactory({
		description: 'Create a component',
		template: path.join(__dirname, 'templates/component'),
		placeholders: [
			{
				name: 'name',
				message: 'Component name'
			},
			{
				name: 'author',
				message: 'Author',
				default: '<%= package.author %>'
			}
		],
		options: {
			destination: '<%= package.paths.components %>',
			overwrite: true
		},
		context: {,
			license: '<%= package.license %>'
		}
	}),
	'create-service': skivvyFactory({
		description: 'Create a service',
		template: path.join(__dirname, 'templates/service'),
		placeholders: [
			{
				name: 'name',
				message: 'Service name'
			},
			{
				name: 'author',
				message: 'Author',
				default: '<%= package.author %>'
			}
		],
		options: {
			destination: '<%= package.paths.services %>',
			overwrite: true
		},
		context: {
			license: '<%= package.license %>'
		}
	})
};

exports.defaults = {
	paths: {
		component: null,
		service: null
	},
	author: '<%= project.author %>',
	license: '<%= project.license %>'
}

After installing this package, you can launch your templates by running the following commands, where PACKAGE_NAME is the name of the package:

# Configure the package
skivvy config --package=PACKAGE_NAME --config.paths.components=src/components --config.paths.services=src/services

# Create a new component
skivvy run create-component

# Create a service
skivvy run create-service

# Create another new component, hard-coding the
# "name" value and preventing accidental overwrite:
skivvy run create-component --config.context.name=foo --config.options.overwrite=false

Usage

skivvyFactory(options)

Create a Skivvy task from a Factory template

Options:

NameTypeRequiredDefaultDescription
templatestringYesN/APath to the Factory template folder
optionsobjectYesN/AFactory copy options
options.destinationstringYesN/ADestination directory for output files
options.overwritebooleanNofalseWhether to overwrite existing files
placeholdersArrayNo[]Array of inquirer prompts used to gather data for injecting into templates
contextobjectNo{}Preset template placeholder values
getContextfunctionNonullFunction that transforms placeholder values before they are passed to the template
descriptionstringNonullSkivvy task description
Notes:
  • Values within the options, placeholders and context option values can use Skivvy task config placeholder values.

  • getContext has the following signature:

    	##### `function(context)`
    
    	###### Arguments:
    
    	| Name | Type | Description |
    	| ---- | ---- | ----------- |
    	| `context` | `object` | Key/value object containing placeholder values, gathered from factory `context` and template `placeholders` |
    
    	###### Returns:
    
    	`object` Key/value object containing transformed context placeholder for use in templates

Returns:

function Skivvy task