This Module collects files by given patterns and can create. Arrays or even Files contianing found files. You can Also pass Inheritance paths to find a file.
- fsInheritanceLib
- ~findSingleFile(cfg, file) ⇒
Object
- ~findSinglePath(cfg, fpath) ⇒
Array
- ~findFiles(cfg, files) ⇒
Array
- ~findPaths(cfg, paths) ⇒
Array
- ~findGlobPatterns(cfg, pat) ⇒
Array
- ~findGlobPath(cfg, pat) ⇒
Array
- ~removeDuplicates(arr) ⇒
Array
- ~filterRegex(arr, regex) ⇒
Array
- ~writeAssetLibrary(input, name, dest)
- ~mkLib(cfg, cb) ⇒
Object
|Array
|function
- ~findSingleFile(cfg, file) ⇒
Takes inherit array and single file to search for the file in given inheritance. It then selects the first appearance and returns an object containong origin and path of file found
Kind: inner method of fsInheritanceLib
Returns: Object
- containing origin and path
Param | Type | Description |
---|---|---|
cfg | Object |
config |
file | String |
filename |
Example
var fsIn = require('fs-inheritance-lib')
var config = {
inheritFrom: ['../parent', '../neighbour', '../../ancestor'],
root: 'foo/bar/src'
}
var files = 'file.js'
var result = fsIn.findSingleFile(cfg, files)
// returns an object like this, depending on where the file was found.
// local means found in current working directory.
console.log(result)
// {
// origin: 'local',
// path: 'foo/bar/src/file.js'
// }
// or
// {
// origin: 'neighbour',
// path: 'foo/bar/src/file.js'
// }
This Function returns an array of matching paths for one given pattern
Kind: inner method of fsInheritanceLib
Returns: Array
- containing found paths
Param | Type | Description |
---|---|---|
cfg | Object |
config |
fpath | String |
path |
Example
var fsIn = require('fs-inheritance-lib')
var cfg = {
inheritFrom: ['../parent', '../neighbour', '../../ancestor'],
root: 'foo/bar/baz'
}
var paths = ['client-vars']
var result = fsIn.findSingleFile(conig, paths[1])
console.log(result)
// [
// '../parent/foo/bar/baz/client-vars',
// '../neighbour/foo/bar/baz/client-vars'
// '../ancestor/foo/bar/baz/client-vars'
// ]
Needs a config and an array of files. The config must contain inheritFrom attribute with an array of folders to inherit from. The order of this array defines the priority of the folders to be searched in. First appearance in first inheritance is taken.
Kind: inner method of fsInheritanceLib
Returns: Array
- of files found by given config
Param | Type | Description |
---|---|---|
cfg | Object |
config |
files | Array |
Example
var fsIn = require('fs-inheritance-lib')
var config = {
inheritFrom: ['../parent', '../neighbour', '../../ancestor'],
root: 'foo/bar/src/'
}
var files = [
'file1.js',
'sub/sub1.js',
'file2.js',
'file3.js',
'file.js',
'file4.js'
]
var result = fsIn.findSingleFile(cfg, files)
// returns an object like this, depending on where the file was found.
// local means found in current working directory.
console.log(result)
// [
// '../../ancestor/foo/bar/src/file1.js',
// '../../ancestor/foo/bar/src/sub/sub1.js',
// '../parent/foo/bar/src/file2.js',
// '../neighbour/foo/bar/src/file3.js',
// 'foo/bar/src/file.js',
// 'foo/bar/src/file4.js'
// ]
Needs a config and an array of paths. The config must contain inheritFrom attribute with an array of folders to inherit from. The order of this array defines the priority of the folders to be searched in. First appearance in first inheritance is taken.
Kind: inner method of fsInheritanceLib
Returns: Array
- of paths found
Param | Type | Description |
---|---|---|
cfg | Object |
config |
paths | Array |
Example
var fsIn = require('fs-inheritance-lib')
var config = {
inheritFrom: ['../parent', '../neighbour', '../../ancestor'],
root: 'foo/bar/src/'
}
var paths = [
'client-vars',
'fonts',
'framework',
'mixins',
'module',
'additional'
]
var result = fsIn.fsInheritanceLib.findPaths(config, paths)
console.log(result)
// [
// '../parent/foo/bar/src/client-vars',
// '../neighbour/foo/bar/src/client-vars',
// '../../ancestor/foo/bar/src/client-vars',
// '../../ancestor/foo/bar/src/fonts',
// '../../ancestor/foo/bar/src/framework',
// '../../ancestor/foo/bar/src/mixins',
// '../../ancestor/foo/bar/src/module',
// '../parent/foo/bar/src/additional',
// '../neighbour/foo/bar/src/additional'
// ]
Find Files that match wildcards
Kind: inner method of fsInheritanceLib
Returns: Array
- of files found via wildcards | duplicates are removed
Param | Type | Description |
---|---|---|
cfg | Object |
config |
pat | String |
pattern |
Example
var fsIn = require('fs-inheritance-lib')
var config = {
inheritFrom: ['../parent', '../neighbour', '../../ancestor'],
root: 'foo/bar/src',
loglevel: []
}
var files = [
'** /*.js' // i had to put the sapce before the backslash because of jsdoc issues
]
var result = fsIn.fsInheritanceLib.findGlobPatterns(config, files[0])
console.log(result)
// [
// 'foo/bar/src/file.js',
// 'foo/bar/src/file4.js',
// '../parent/foo/bar/src/file2.js',
// '../neighbour/foo/bar/src/file3.js',
// '../../ancestor/foo/bar/src/file1.js',
// '../../ancestor/foo/bar/src/sub/sub1.js'
// ]
Find global paths by widlcards
Kind: inner method of fsInheritanceLib
Returns: Array
- of paths found mathing pattern
Param | Type | Description |
---|---|---|
cfg | Object |
config |
pat | String |
pattern |
Example
var fsIn = require('fs-inheritance-lib')
var config = {
inheritFrom: ['./', '../parent', '../neighbour', '../../ancestor'],
root: 'foo/bar/src',
loglevel: []
}
var paths = [
'*',
]
var result = fsIn.fsInheritanceLib.findGlobPatterns(config, paths[0])
console.log(result)
// [
// 'foo/bar/src/foo',
// 'foo/bar/src/bar',
// 'foo/bar/src/baz',
// '../parent/foo/bar/src/foo',
// '../parent/foo/bar/src/bar',
// '../parent/foo/bar/src/baz',
// '../neighbour/foo/bar/src/foo',
// '../neighbour/foo/bar/src/bar',
// '../neighbour/foo/bar/src/baz',
// '../../ancestor/foo/bar/src/foo',
// '../../ancestor/foo/bar/src/bar',
// '../../ancestor/foo/bar/src/baz',
// ]
remove duplicates in array
Kind: inner method of fsInheritanceLib
Returns: Array
- without duplicates
Param | Type | Description |
---|---|---|
arr | Array |
with duplicates |
Example
var result = fsInheritanceLib.removeDuplicates(['foo', 'foo', 'bar', 'bar', 'bar', 'baz'])
console.log(result)
// ['foo', 'bar', 'baz']
filter array of strings by matching regex
Kind: inner method of fsInheritanceLib
Returns: Array
- array without matching regex
Param | Type | Description |
---|---|---|
arr | Array |
with matching regex |
regex | String |
that should be used to filter |
Example
var regex = new RegExp('foo', 'g')
var array = ['foofoo', 'barfoo', 'bar', 'baz']
var result = fsInheritanceLib.filterRegex()
console.log(result)
// ['foofoo', 'barfoo']
write a file
Kind: inner method of fsInheritanceLib
Param | Type | Description |
---|---|---|
input | any |
string/object/array that should be written |
name | any |
name of the output file (with extension) |
dest | any |
destination of file |
Example
var string = 'someString'
fsInheritanceLib.writeAssetLibrary(string, 'bar.txt', './')
// creates ./bar.txt with content 'someString'
Kind: inner method of fsInheritanceLib
Descriptiondescription: Make Library collects files or paths and writes a file
it can also have a callback function which returns the data found
Param | Type | Description |
---|---|---|
cfg | Object |
config |
cb | function |
takes optional callback function |
Example
var config = {
root: 'foo/bar/baz',
files: ['foo.js', 'bar.js', 'baz.js'],
outputPath: 'bar/foo',
outputName: 'baz.json'
}
fsInheritanceLib.writeAssetLibrary(config, function(result){
console.log('result')
// ['./foo/bar/baz/foo.js', './foo/bar/baz/bar.js', './foo/bar/baz/baz.js']
// and a file bar/foo/baz.json is created (if the path exists!)
})