-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from electron/cut-snapshot
v1: Cut mksnapshot, update dependencies, promisify
- Loading branch information
Showing
13 changed files
with
3,190 additions
and
1,321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,37 @@ | ||
'use strict' | ||
const fs = process.versions.electron ? require('original-fs') : require('fs') | ||
const glob = require('glob') | ||
|
||
module.exports = function (dir, options, callback) { | ||
const metadata = {} | ||
return glob(dir, options, function (error, filenames) { | ||
if (error) { return callback(error) } | ||
for (const filename of filenames) { | ||
const stat = fs.lstatSync(filename) | ||
const pify = require('pify') | ||
|
||
const fs = pify(process.versions.electron ? require('original-fs') : require('fs')) | ||
const glob = pify(require('glob')) | ||
|
||
function determineFileType (filename) { | ||
return fs.lstat(filename) | ||
.then(stat => { | ||
if (stat.isFile()) { | ||
metadata[filename] = {type: 'file', stat: stat} | ||
return [filename, { type: 'file', stat: stat }] | ||
} else if (stat.isDirectory()) { | ||
metadata[filename] = {type: 'directory', stat: stat} | ||
return [filename, { type: 'directory', stat: stat }] | ||
} else if (stat.isSymbolicLink()) { | ||
metadata[filename] = {type: 'link', stat: stat} | ||
return [filename, { type: 'link', stat: stat }] | ||
} | ||
|
||
return [filename, undefined] | ||
}) | ||
} | ||
|
||
module.exports = function (dir, options) { | ||
const metadata = {} | ||
return glob(dir, options) | ||
.then(filenames => Promise.all(filenames.map(filename => determineFileType(filename)))) | ||
.then(results => { | ||
const filenames = [] | ||
for (const [filename, type] of results) { | ||
filenames.push(filename) | ||
if (type) { | ||
metadata[filename] = type | ||
} | ||
} | ||
} | ||
return callback(null, filenames, metadata) | ||
}) | ||
return [filenames, metadata] | ||
}) | ||
} |
Oops, something went wrong.