Easy and fast library for generate file and folder structures in your projects with a very small effort.
Features:
- Small footprint library.
- You can use interfaces like a prompt with skeleton-prompt.
Skeleton works with generators. A generator are a directory with files, folders and templates that will be created in some location of your file system.
The main file of generator is known as "manifest". Manifest defines all actions that will be done. For example: create, copy o generate files from predefined templates. In this directory we have files and folder structure that contains the templates or files that we will work with it.
Skeleton is a very simplified concept of yeoman generators. I try to avoid the complexity of this project to put in your hands a very useful library.
npm install fskeleton --save
Only create a directory and put inside it a file called manifest.js:
/home/me/fskeleton/sk/
└── manifest.js
Note: you can name this file with other name, but you need to remember it when you instantiate the generator.
You are free to define the internal folder and file structure, like where locate templates, assets and other types of files. My recommendation is follow some methodology. You can study and follow our test fixtures. For example:
/home/me/fskeleton/sk/
├── manifest.js
├── templates
| ├── README.tpl
| └── component.tpl
└── assets
├── asset1.jpg
├── asset2.jpg
└── subdir
├── asset3.txt
└── asset4.jpg
First of all, create a manifest.js
. This file tells Skeleton how deal with
files inside generator. The scaffold property must be defined.
// /home/me/fkeleton/sk/manifest.js
module.exports = {
// Default data for all scaffold
defaultData: {
name: 'unnmaed'
},
scaffold: {
// Creates a folder with rwx permissions (UNIX)
'app/components' : {
action : 'folder',
mode : 0777
},
// Generate a file from template
'app/README.md': {
action : 'template',
path : 'templates/README.tpl',
// Data for template: name will be overriden
data : { name: 'Testing' }
},
// Copy "as it is" the assets/ to app/assets. Including subdirs.
'app/assets/': {
action : 'copy',
path : 'assets/'
}
}
}
You can add to your manifest a before
function to change scaffold object
dynamically. For example:
module.exports = {
// ......
// If we pass data argument with components property, we will add
// dynamically new path and configurations to scaffold object
before: function(scope, data) {
var self = this;
if(typeof data.components !== "undefined") {
data.components.forEach(function(component) {
self.scaffold['app/components/' + component + '.txt'] = {
action : 'template',
path : 'templates/component.tpl',
data : { component: component}
};
});
}
}
// ......
}
There are two ways for deploy structures:
You define all scope object at instantiation time.
var Skeleton = require('fskeleton');
// Optional argument and object. It will create a data object for each path in
// scaffold object. Take care! if some data object is defined, it will be merged
var data = {
components: ['component1', 'component2']
};
var sk = new Skeleton({
generator : '/home/me/fskeleton/sk', // Where is the generator
dest : '/tmp/', // Where will be created the structure
}, data);
// Create structure in file system
sk.create()
.then(function() {
// Do things when finish...
})
;
You can use this way for skeleton-prompt
and ask scope variables like dest
or for complete data
object.
var Skeleton = require('fskeleton');
var data = {
components: ['component1', 'component2']
};
// You can use '/home/me/fskeleton/sk/othermanifes.js', by default it search
// manifest.js
var sk = new Skeleton('/home/me/fskeleton/sk', data);
sk.scope('dest', '/tmp/');
// Create structure in file system
sk.create()
.then(function() {
// Do things when finish...
})
;
Remember that sk.create()
returns a promise object. I use bluebird library.