This module is needed for caching data. It can search for files with certain extension in folders. Collect file contents or contents could be through a flaw require function. Also caches template files swigJs.
npm install utils-igor
var dirCache = require('./index');
var async = require('async');
var ut = require('util');
async.series([
(done) => {
console.log('Test scan all file in folder');
dirCache.scan({dirs : 'for-example/views1'}, (e, scan) => {
if (e) {
console.log('Error initail', e);
return done();
}
scan.run((e, res) => {
console.log('err ', e);
console.log('res ', ut.inspect(res, false, null));
done();
});
}) ;
},
(done) => {
console.log('Test read two folders. Get only html files');
dirCache.read({
dirs : ['for-example/views1', 'for-example/views'],
exts : ['.html']
}, (e, scan) => {
if (e) {
console.log('Error initail', e);
return done();
}
scan.run((e, res) => {
console.log('err ', e);
console.log('res ', ut.inspect(res, false, null));
done();
});
}) ;
},
(done) => {
console.log('Test get files for swig');
dirCache.swig({
dirs : 'for-example/views1',
exts : '.html'
}, (e, scan) => {
if (e) {
console.log('Error initail', e);
return done();
}
scan.run((e, res) => {
console.log('err ', e);
console.log('res ', ut.inspect(res, false, null));
done();
});
}) ;
},
(done) => {
console.log('Test get files for required js, json and call exporst if is function');
dirCache.required({
dirs : 'for-example/controllers'
}, (e, scan) => {
if (e) {
console.log('Error initail', e);
return done();
}
scan.run((e, res) => {
console.log('err ', e);
console.log('res ', ut.inspect(res, false, null));
done();
});
}) ;
},
(done) => {
console.log('Test get files for required js');
dirCache.required({
dirs : 'for-example/controllers',
isCall : false,
exts : '.js'
}, (e, scan) => {
if (e) {
console.log('Error initail', e);
return done();
}
scan.run((e, res) => {
console.log('err ', e);
console.log('res ', ut.inspect(res, false, null));
done();
});
}) ;
},
(done) => {
console.log('Test get files for required js with call with a specified method');
dirCache.required({
dirs : 'for-example/controllers',
isCall : false,
call : 'init',
exts : '.js'
}, (e, scan) => {
if (e) {
console.log('Error initail', e);
return done();
}
scan.run((e, res) => {
console.log('err ', e);
console.log('res ', ut.inspect(res, false, null));
done();
});
}) ;
}
], function (e) {
console.log('The end :)');
});
- cacheDir
- module.exports :
Object
⏏- ~Frame
- .err(mess) ⇒
Object
- .warn(mess, that)
- .err(mess) ⇒
- ~Scan
- new Scan(options, cb)
- .valid(options)
- .beforeValid(options) ⇒
Object
- .iterValid(options, k, v) ⇒
boolean
- .isCorrectExt(file) ⇒
boolean
- .isAll() ⇒
boolean
- .run(cb) ⇒
*
- ~Swig
- ~Reader
- ~Reuired
- .beforeValid(options) ⇒
Object
- .fileGet(dir, file, endFile) ⇒
*
- .beforeValid(options) ⇒
- ~Cache
- ~Frame
- module.exports :
Exports classes
It is a frame for other classes
Kind: inner class of module.exports
- ~Frame
- .err(mess) ⇒
Object
- .warn(mess, that)
- .err(mess) ⇒
Return error object and set flag for stop process
Kind: instance method of Frame
Param |
---|
mess |
Get text for message
Kind: instance method of Frame
Param | Type |
---|---|
mess | String |
that | Class |
Search files in folders
Kind: inner class of module.exports
- ~Scan
- new Scan(options, cb)
- .valid(options)
- .beforeValid(options) ⇒
Object
- .iterValid(options, k, v) ⇒
boolean
- .isCorrectExt(file) ⇒
boolean
- .isAll() ⇒
boolean
- .run(cb) ⇒
*
Set option to class and run callback
Param | Type |
---|---|
options | object |
cb | function |
Validates options
Kind: instance method of Scan
Param | Type |
---|---|
options | Object |
Hook before validates options
Kind: instance method of Scan
Param | Type |
---|---|
options | Object |
Hook for iter validates options
Kind: instance method of Scan
Param | Type |
---|---|
options | Object |
k | String |
v | String |
Check extension file
Kind: instance method of Scan
Param | Type |
---|---|
file | String |
Check use all extension
Kind: instance method of Scan
Start search process
Kind: instance method of Scan
Param | Type |
---|---|
cb | function |
Get text swig template files and jon partial
Kind: inner class of module.exports
Start collected process
Kind: instance method of Swig
Param | Type |
---|---|
cb | function |
Get text files
Kind: instance method of Swig
Param | Type |
---|---|
dir | String |
file | String |
endFile | function |
Write text to result
Kind: instance method of Swig
Param | Type |
---|---|
pathFile | String |
dir | String |
file | String |
data | String |
cb | function |
Write data to result
Kind: instance method of Swig
Param | Type |
---|---|
pathFile | String |
dir | String |
{Stringfile | |
{Stringdata | |
cb | function |
Clears data from the extra line breaks
Kind: instance method of Swig
Param | Type |
---|---|
data | String |
Get text any files
Kind: inner class of module.exports
Write text to result
Kind: instance method of Reader
Param | Type |
---|---|
pathFile | String |
dir | String |
file | String |
data | String |
endFile | function |
Get files via function require
Kind: inner class of module.exports
- ~Reuired
- .beforeValid(options) ⇒
Object
- .fileGet(dir, file, endFile) ⇒
*
- .beforeValid(options) ⇒
Overwrite before valid
Kind: instance method of Reuired
Param | Type |
---|---|
options | String |
Overwrite fileGet
Kind: instance method of Reuired
Param | Type |
---|---|
dir | String |
file | String |
endFile | function |
Create object for saving data
Kind: inner class of module.exports