bundler/publish.js
function walk(dir, before, after, handler, name = null, depth = 0) {
	const listed = fs.readdirAsync(
		dir
	).then((list) => Promise.map(list, (item) => {
		const child = path.resolve(dir, item);

		const result = fs.lstatAsync(
			child
		).then((stat) => ({
			path: child,
			name: item,
			isFile: stat.isFile(),
			enterDir: stat.isDirectory()
		}));

		return(result);
	}));

	const result = listed.then(
		(items) => before(items, depth)
	).then((items) => Promise.map(
		items,
		(item) => item.enterDir && walk(item.path, before, after, handler, item.name, depth + 1)
	)).then(
		(children) => after(listed.value(), children)
	).then((dependencyList) => {
		handler(dir, dependencyList, name, depth);
		return(dependencyList);
	}).catch((err) => {});

	return(result);
}
function walk(dir, before, after, handler, name = null, depth = 0) {
	const listed = fs.readdirAsync(
		dir
	).then((list) => Promise.map(list, (item) => {
		const child = path.resolve(dir, item);

		const result = fs.lstatAsync(
			child
		).then((stat) => ({
			path: child,
			name: item,
			isFile: stat.isFile(),
			enterDir: stat.isDirectory()
		}));

		return(result);
	}));

	const result = listed.then(
		(items) => before(items, depth)
	).then((items) => Promise.map(
		items,
		(item) => item.enterDir && walk(item.path, before, after, handler, item.name, depth + 1)
	)).then(
		(children) => after(listed.value(), children)
	).then((dependencyList) => {
		handler(dir, dependencyList, name, depth);
		return(dependencyList);
	}).catch((err) => {});

	return(result);
}
function walk ( dir , before , after , handler , name = null , depth = 0 ) { const listed = fs . readdirAsync ( dir ) . then ( ( list ) => Promise . map ( list , ( item ) => { const child = path . resolve ( dir , item ) ; const result = fs . lstatAsync ( child ) . then ( ( stat ) => ( { path : child , name : item , isFile : stat . isFile ( ) , enterDir : stat . isDirectory ( ) } ) ) ; return ( result ) ; } ) ) ; const result = listed . then ( ( items ) => before ( items , depth ) ) . then ( ( items ) => Promise . map ( items , ( item ) => item . enterDir && walk ( item . path , before , after , handler , item . name , depth + 1 ) ) ) . then ( ( children ) => after ( listed . value ( ) , children ) ) . then ( ( dependencyList ) => { handler ( dir , dependencyList , name , depth ) ; return ( dependencyList ) ; } ) . catch ( ( err ) => { } ) ; return ( result ) ; }
Recursively walk a directory tree.
@param dir Path to root of tree to explore.
@param before Function called with contents of each directory, before
entering subdirectories. Directories have an enterDir flag set and
clearing it prevents recursing inside.
@param after Function called for each directory after exploring
subdirectories. Return value should contain a list of dependencies.
@param name Name of the current npm package.
@param depth Current recursion depth in directory tree.
@return List of strings returned by the "after" callback, without any
empty strings or name of the current NPM package.
Recursively walk a directory tree .