This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
recursive.js
68 lines (62 loc) · 1.48 KB
/
recursive.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
57
58
59
60
61
62
63
64
65
66
67
68
//
// switch the names of two files.
//
var ctrl = require('../')
, path = require('path')
, fs = require('fs')
, d = require('d-utils')
var ls =
ctrl([
function (fn, cb) {
fs.lstat(fn, function (err, stat) {
if(err)
cb(err)
else {
stat.name = fn
cb(null, stat)
}
})
},
function tryParse (file, cb) {
if(/package\.json$/.exec(file.name)) {
try {
JSON.parse(fs.readFileSync(file.name))
} catch (err) {
console.log(file.name, err.message)
}
/*ctrl([
[fs.readFile, file.name, 'utf-8']
, ctrl.toAsync(JSON.parse)
, [d.fallthrough, file]
])(cb)*/
}
//else
cb(null, file)
}
, function (file, next) {
if(file.isDirectory())
ctrl([
[fs.readdir, file.name]
, function (fn,next) {
next(null, d.map(d.filter(fn, /^[^.]/), function (v) {return path.join(file.name, v)}))
}
, ctrl.parallel.map(ls)
])(next)
else
next(null, file)
}
])
ls(process.argv[2] || process.cwd(), function (err, data) {
if(err)
throw err
/* function print(file) {
if(Array.isArray(file))
d.each(file, function (f) {
print(f)
})
else
console.log(file.name)
}
print(data)*/
})
//ls(process.cwd(), console.log)