Skip to content
Browse files

bump version 4.1

  • Loading branch information...
1 parent 22e4f29 commit 5c34d7106a9a4aecf5ca937dbd55c46c0f8bfa05 @dominictarr committed Sep 8, 2011
Showing with 60 additions and 37 deletions.
  1. +58 −24 examples/recursive.js
  2. +2 −13 package.json
View
82 examples/recursive.js
@@ -6,29 +6,63 @@
var ctrl = require('../')
, path = require('path')
, fs = require('fs')
- , d = require('d-utils')
- , rec = {}
-
+ , d = require('d-utils')
-function rec (dir, callback) {
- ctrl([
- [fs.lstat, dir], //check is file
- function (stat, callback) {
- callback(!stat.isDirectory)
- },
- [fs.readdir, dir],
- function (list, callback) {
- var ls =
- d.mapKeys(list, function (key) {
- return [[d.tryCatchPass(rec, function (err, callback) {
- if(err === true)
- callback()
- else callback(err)
- }, d.fallthrough), path.join(dir, key)]]
+ var ls =
+ ctrl([
+ function (fn, cb) {
+ fs.lstat(fn, function (err, stat) {
+ if(err)
+ cb(err)
+ else {
+ stat.name = fn
+ cb(null, stat)
+ }
})
- console.log(ls)
- ctrl([ls])(callback)
- }
- ])(callback)
-}
-rec(process.cwd(), console.log)
+ },
+ 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)
View
15 package.json
@@ -1,27 +1,16 @@
{
"name": "ctrlflow",
"description": "yet another async control flow lib",
- "version": "4.0.0",
+ "version": "4.1.0",
"homepage": "https://github.com/dominictarr/ctrlflow",
"repository": {
"type": "git",
"url": "git://github.com/dominictarr/ctrlflow.git"
},
"author": "Dominic <dominic.tarr@gmail.com>",
"main": "./ctrlflow.js",
- "directories": {
- "lib": "."
- },
- "dependencies":{
+ "dependencies": {
"curry": "0.0.x",
"d-utils": "~1.4"
- },
- "devDependencies":{
- "meta-test": ">=0.0.2"
- , "it-is": "*"
- , "curry": "*"
- },
- "engines": {
- "node": ">=0.2.0"
}
}

0 comments on commit 5c34d71

Please sign in to comment.
Something went wrong with that request. Please try again.