mkfiles
v1.6.1
Published
Batch create module directories and files!
Downloads
32
Readme
mkfiles
Introduction:mkfiles is a npm package, it is use for batch create module directories and files.
1. Install
(sudo) npm install mkfiles
2. API
(1) mkfiles(config)
* param: config
* type: Object | Array
* options:
* path -- <String>, <required>, base path, etc: './src/mods/'
* dirs -- <Array>, <optional>, directory list, etc: ['test', 'demo']
* files -- <Array>, <required>, file list, etc:
[
'index.css',
{
file: 'filename',
content: String | Object
}
]
3. Usage
(1) Create a module directory, and create files in the directory.
var mkfiles = require('mkfiles');
var baseDir = './src/mods/';
mkfiles({
path: baseDir + 'exam1',
files: ['a.txt', 'b.txt']
});
result:
./src/mods/
-- exam1
-- a.txt
-- b.txt
(2) Create a module directory, and create files in the directory, then set up file content.
mkfiles({
path: baseDir,
dirs: ['exam2'],
files: [
{
file: 'a.txt',
content: 'default content' // specify the content directly
},
{
file: 'b.txt',
content: {
template: 'My name is {{name}}', // specify the content by template string(only support handlebars)
data: {name: 'haha'}
}
},
{
file: 'c.txt',
content: {
template: 'template.handlebars', // specify the content by template file(only support handlebars), file content is 'My name is {{name}}'
data: {name: 'haha'}
}
}
]
});
result:
./src/mods/
-- exam2
-- a.txt // The file content is 'default content'
-- b.txt // The file content is ’My name is haha'
-- c.txt // The file content is ’My name is haha'
(3) Create multiple module directories at the same time, and create files in the directory.
mkfiles([{
path: baseDir,
dirs: ['exam3'],
files: ['a.txt']
}, {
path: baseDir,
dirs: ['exam4'],
files: ['b.txt']
}]);
result:
./src/mods/
-- exam3
-- a.txt
-- exam4
-- b.txt
(4) Create multiple module directories at the same time, and create same files for each directory.
mkfiles({
path: baseDir,
dirs: ['exam5', 'exam6'],
files: ['a.txt', 'b.txt']
});
result:
./src/mods/
-- exam5
-- a.txt
-- b.txt
-- exam6
-- a.txt
-- b.txt
(5) Create a module contains subdirectories, and create the same file for each subdirectory.
mkfiles({
path: baseDir + 'exam7',
dirs: ['desktop', 'tablet', 'mobile'],
files: ['index.js', 'index.css', 'index.tpl.html']
});
result:
./src/mods/
-- exam7
-- desktop
-- index.js
-- index.css
-- index.tpl.html
-- tablet
-- index.js
-- index.css
-- index.tpl.html
-- mobile
-- index.js
-- index.css
-- index.tpl.html