UNPKG

3.29 kBJavaScriptView Raw
1#!/usr/bin/env node
2(function () {
3 "use strict";
4
5 var walk = require('../lib/walk'),
6 count = 0,
7 saneCount = 0;
8
9 function sort(a,b) {
10 a= a.toLowerCase();
11 b= b.toLowerCase();
12 if (a > b) return -1;
13 if (a < b) return 1;
14 return 0;
15 }
16
17 process.argv.forEach(function(startpath, index) {
18 if (index > 1) {
19 emitter = walk(startpath);
20
21 // Non-`stat`ed Nodes
22 emitter.on('name', function (path, file, stat) {
23 saneCount += 1;
24 //console.log( ["[", count, "] ", path, '/', file].join('') )
25 //console.log( [path, '/', file].join('') )
26 });
27 emitter.on('names', function (path, files, stats) {
28 files.sort(sort);
29 //console.log('sort: ' + files.join(' ; '));
30 });
31
32
33
34 // Single `stat`ed Nodes
35 emitter.on('error', function (path, err, next) {
36 next()
37 // ignore
38 });
39 emitter.on('directoryError', function (path, stats, next) {
40 next();
41 });
42 emitter.on('nodeError', function (path, stats, next) {
43 next();
44 });
45 /*
46 emitter.on('node', function (path, stat, next) {
47 count += 1;
48 console.log( [path, '/', stat.name].join('') )
49 //console.log( ["[", count, "] ", path, '/', stat.name].join('') )
50 next();
51 });
52 */
53 emitter.on('file', function (path, stat, next) {
54 count += 1;
55 console.log( [path, '/', stat.name].join('') )
56 //console.log( ["[", count, "] ", path, '/', stat.name].join('') )
57 next();
58 });
59 emitter.on('directory', function (path, stat, next) {
60 count += 1;
61 console.log( [path, '/', stat.name].join('') )
62 next();
63 });
64 emitter.on('symbolicLink', function (path, stat, next) {
65 count += 1;
66 console.log( [path, '/', stat.name].join('') )
67 next();
68 });
69 /*
70 emitter.on('blockDevice', function (path, stat, next) {
71 next();
72 });
73 emitter.on('characterDevice', function (path, stat, next) {
74 next();
75 });
76 emitter.on('FIFO', function (path, stat, next) {
77 next();
78 });
79 emitter.on('socket', function (path, stat, next) {
80 next();
81 });
82 */
83
84
85
86 // Grouped `stat`ed Nodes
87 emitter.on('errors', function (path, stats, next) {
88 next();
89 });
90 /*
91 emitter.on('nodes', function (path, stats, next) {
92 next();
93 });
94 */
95 emitter.on('files', function (path, stats, next) {
96 next();
97 });
98 emitter.on('directories', function (path, stats, next) {
99 //delete stats[1];
100 next();
101 });
102 emitter.on('symbolicLinks', function (path, stats, next) {
103 next();
104 });
105 /*
106 emitter.on('blockDevices', function (path, stats, next) {
107 next();
108 });
109 emitter.on('characterDevices', function (path, stats, next) {
110 next();
111 });
112 emitter.on('FIFOs', function (path, stats, next) {
113 next();
114 });
115 emitter.on('sockets', function (path, stats, next) {
116 next();
117 });
118 */
119
120
121
122 // The end of all things
123 emitter.on('end', function () {
124 console.log("The eagle has landed. [" + count + " == " + saneCount + "]");
125 });
126 }
127 });
128
129}());