xcaffolder
v0.1.3
Published
**_xcaffolder_** is a simple tool to create quick scaffolds that may include folders structure and files. The idea is allowing the user to define folders and files in a JavaScript template generator, without having to depend on more complex tools like Yeo
Downloads
1
Readme
xcaffolder
xcaffolder is a simple tool to create quick scaffolds that may include folders structure and files. The idea is allowing the user to define folders and files in a JavaScript template generator, without having to depend on more complex tools like Yeoman or similar generators.
Installation
npm i -g xcaffolder
The config file
In order to work properly, xcaffolder needs a really simple JSON config file called .xcaffoldrc
. For the time being, it consists of just one key, pointing to the dir where the user stores the template generators.
The template generator
This is just a JS module that exports two things:
- A
function
called generateTemplate, which receives params (sent by xcaffolder) and returns anobject
or anarray
containing the folder structure or files list, respectively. - A
string
indicating the path in which these files and folders should be created.
A basic example, without any params:
module.exports = {
generateTemplate: () => {
return [
'schema.gql',
'resolver.js'
]
},
path: 'example/path/',
}
A more complex example, with a base dir, which name is set through params:
module.exports = {
generateTemplate: ([ baseDir ]) => {
return {
[baseDir]: [
'schema.gql',
'resolver.js'
]
}
},
path: 'example/path/',
}
As you would expect, you may process the generator params any way you need, since it's just a JavaScript function, as long a you return an array or object that can be understood by xcaffolder.
The arguments
For the time being, the only way of sending arguments to the template generator is from the command line, as a comma-separated list, so basically you can just send strings and numbers. I made it like this because the idea is to send just a few arguments, like the base dir or maybe a couple filenames. If in future versions I see the need to send more arguments, I will have to rethink this.
You can send arguments like this:
xcaffolder baseDir,aFilename,anotherFilename
And you will receive them like this:
module.exports = {
generateTemplate: ([ baseDir, file1, file2 ]) => {
return {
[baseDir]: [ // 'baseDir'
file1, // 'aFilename'
file2 // 'anotherFilename'
]
}
},
path: 'example/path/',
}
Which will create the following structure:
example/path/baseDir
example/path/baseDir/aFilename
example/path/baseDir/anotherFilename
Running xcaffolder
Running xcaffolder is quite straightforward. All you need is the .xcaffoldrc
config file, a folder with at least one template generator and you're ready to go!
You should run it from the folder containing the config file, otherwise xcaffolder wouldn't be able to find the templates generators folder.
Besides the arguments list that is passed to the generator, you may also add the "-d" option, which will make xcaffolder run in "dry mode". This option will output a preview of the structure that will be generated, without actually creating it.
Features future me may implement
- Files content templates
- Better way of sending cli arguments
Collaborating
Don't hesitate to contact me at paulmdorr.me/contact if you have suggestions or questions. Also, feel free to create a new issue or make a pull request on the github repo!