-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader-common.js
56 lines (44 loc) · 1.25 KB
/
loader-common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var glob = require('glob')
, path = require('path')
, fs = require('fs')
, pathEndsWith = require('path-ends-with')
function getGlobFiles (subtaskGlob) {
return glob.sync(subtaskGlob).filter(function (f) {
return !fs.lstatSync(f).isDirectory()
})
}
function defaultFiles (subtaskGlob) {
var defaultGlobPath = path.join(
subtaskGlob,
'**/*.tasks.js'
)
return glob.sync(defaultGlobPath)
}
function globFilesOrDefault (subtaskGlob) {
var files = getGlobFiles(subtaskGlob)
var noFiles = files.length == 0
, globIsDir = noFiles && fs.lstatSync(subtaskGlob).isDirectory()
if (globIsDir)
files = defaultFiles(subtaskGlob)
return files
}
function processTaskFiles (files) {
return files.map(function (f) {
var ext = path.extname(f)
, name = path.basename(f, ext)
if (pathEndsWith(f, '.tasks' + ext))
name = path.basename(f, '.tasks')
return path.resolve(f)
})
}
// NOTE: 'singleton' pattern; fine for a development lib
var loader = module.exports
// NOTE: this is ONLY FOR TESTING
loader.__gulp__ = require('gulp')
loader.__set_gulp__ = function (g) {
loader.__gulp__ = g
}
loader.load = function (subtaskGlob) {
var files = globFilesOrDefault(subtaskGlob)
return processTaskFiles(files)
}