You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
jQuery is about selecting elements of a tree, based on their relationships,
and then applying actions on them, but what if you could work with the fs like this?
it would be very simple to express certain highlevel ideas.
Suppose, this expression might mean get all the modules requireable
from the current dir.
sometimes /**/ means /*/ or /*/*/ or /*/*/*/ etc, so i'm extending .../
so that it means ./ and ../ and ../../ and ../../../ etc.
Then we open each file, then filter them, so you only get the first
one that you've seen.
This is exactly like the node_modules pattern, but expressed in one (longish) line.
could also do this
$('.../node_module/$MODULE_NAME/package.json')...
to find that file?
Also, there are some other constructions that would be very simple to do,
like -- rm -rf. rm stops you from unlinking a dir unless it's empty.
you must traverse the tree, (in topological sort order -- leaves first),
and delete each file, and then the containing directory.
// rm -rf dir
$('./dir/**/*').topologicalSort().unlink()
but, you could also delete just, say, the .coffee files.
$('./dir/**/*.coffee').topologicalSort().unlink()
This is the sort of thing that is awkward with the regular unix tools,
because you never know how consistent the recursive option is implemented,
indeed - it's part of each tool, rather than part of the shell.
cp -R could be implemented like this:
//traverse the files width first, to ensure that each dir is created as needed.
//depth first would also work.
$('./dir/**/*').widthFirst().each(function (item, cb) {
var dest = path.resolve('./destDir', path.relative('./dir', item.filename))
if(item.type == 'file')
fs.createReadStream(item.filename).pipe(fs.createWriteStream(dest))
.on('close', cb).on('error', cb)
else if(item.type == 'dir')
fs.mkdir(dest, cb)
})
Of course, it would be just as easy to apply this selectively!
could also define an extended glob syntax like this:
./(node_modules/*)+/package.json which could be used to select the npm dependency tree at the current dir.
here (...) and + have pretty much the same meaning as in regexp.
I completely see the value in this. I'm not savvy enough to flesh out use-cases for developers working with fs but it will be so great to see that this same exact same API can work its magic with a distributed DB / thing.
Activity
dominictarr commentedon Mar 20, 2013
could also define an extended glob syntax like this:
./(node_modules/*)+/package.jsonwhich could be used to select the npm dependency tree at the current dir.here
(...)and+have pretty much the same meaning as in regexp.refset commentedon Mar 20, 2013
I completely see the value in this. I'm not savvy enough to flesh out use-cases for developers working with fs but it will be so great to see that this same exact same API can work its magic with a distributed DB / thing.
dominictarr commentedon Mar 25, 2013
hey @jez0990 what do you think about this: https://github.com/dominictarr/poset/blob/master/scratch.md
refset commentedon Mar 27, 2013
I like the looks of it. I don't completely understand the syntax decisions but it is pretty intuitive to read!