fs-jetpack
Advanced tools
Comparing version 0.6.5 to 0.7.0
@@ -0,1 +1,5 @@ | ||
0.7.0 (2015-07-20) | ||
------------------- | ||
* **(breaking change)** `matching` option in `copy()` and `find()` resolves glob patterns to the folder you want copy or find stuff in (previously CWD was used). | ||
0.6.5 (2015-06-19) | ||
@@ -2,0 +6,0 @@ ------------------- |
@@ -21,3 +21,3 @@ "use strict"; | ||
if (options.matching) { | ||
parsedOptions.allowedToCopy = matcher.create(options.matching, from, options.cwd); | ||
parsedOptions.allowedToCopy = matcher.create(options.matching, from); | ||
} else { | ||
@@ -45,5 +45,5 @@ parsedOptions.allowedToCopy = function () { | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Sync | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -85,5 +85,5 @@ var copySync = function (inspectData, to) { | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Async | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -115,22 +115,2 @@ var promisedReadFile = Q.denodeify(fs.readFile); | ||
options = parseOptions(options, from); | ||
// Checks before copying | ||
exists.async(from) | ||
.then(function (srcPathExists) { | ||
if (!srcPathExists) { | ||
throw generateNoSourceError(from); | ||
} else { | ||
return exists.async(to) | ||
} | ||
}) | ||
.then(function (destPathExists) { | ||
if (destPathExists && !options.overwrite) { | ||
throw generateDestinationExistsError(to); | ||
} else { | ||
startCopying(); | ||
} | ||
}) | ||
.catch(deferred.reject); | ||
var startCopying = function () { | ||
@@ -158,10 +138,30 @@ | ||
options = parseOptions(options, from); | ||
// Checks before copying | ||
exists.async(from) | ||
.then(function (srcPathExists) { | ||
if (!srcPathExists) { | ||
throw generateNoSourceError(from); | ||
} else { | ||
return exists.async(to); | ||
} | ||
}) | ||
.then(function (destPathExists) { | ||
if (destPathExists && !options.overwrite) { | ||
throw generateDestinationExistsError(to); | ||
} else { | ||
startCopying(); | ||
} | ||
}) | ||
.catch(deferred.reject); | ||
return deferred.promise; | ||
}; | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// API | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
module.exports.sync = sync; | ||
module.exports.async = async; |
@@ -24,5 +24,5 @@ "use strict"; | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Sync | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -73,5 +73,5 @@ var sync = function (path, criteria) { | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Async | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -115,3 +115,3 @@ var promisedStat = Q.denodeify(fs.stat); | ||
var checkWhatWeHaveNow = function () { | ||
var deferred = Q.defer(); | ||
var checkDeferred = Q.defer(); | ||
@@ -126,7 +126,7 @@ promisedStat(path) | ||
// pass stat further down. | ||
deferred.resolve(undefined); | ||
checkDeferred.resolve(undefined); | ||
}) | ||
.catch(deferred.reject); | ||
.catch(checkDeferred.reject); | ||
} else { | ||
deferred.resolve(stat); | ||
checkDeferred.resolve(stat); | ||
} | ||
@@ -137,14 +137,14 @@ }) | ||
// Path doesn't exist | ||
deferred.resolve(undefined); | ||
checkDeferred.resolve(undefined); | ||
} else { | ||
// This is other error that nonexistent path, so end here. | ||
deferred.reject(err); | ||
checkDeferred.reject(err); | ||
} | ||
}); | ||
return deferred.promise; | ||
return checkDeferred.promise; | ||
}; | ||
var checkWhatShouldBe = function (stat) { | ||
var deferred = Q.defer(); | ||
var checkDeferred = Q.defer(); | ||
@@ -157,6 +157,6 @@ var needToCheckMoreCriteria = function () { | ||
empty(path) | ||
.then(deferred.resolve, deferred.reject); | ||
.then(checkDeferred.resolve, checkDeferred.reject); | ||
} else { | ||
// Everything done! | ||
deferred.resolve(); | ||
checkDeferred.resolve(); | ||
} | ||
@@ -170,3 +170,3 @@ }; | ||
promisedChmod(path, criteria.mode) | ||
.then(checkEmptiness, deferred.reject); | ||
.then(checkEmptiness, checkDeferred.reject); | ||
} else { | ||
@@ -183,3 +183,3 @@ checkEmptiness(); | ||
promisedMkdirp(path, { mode: criteria.mode }) | ||
.then(deferred.resolve, deferred.reject); | ||
.then(checkDeferred.resolve, checkDeferred.reject); | ||
} else { | ||
@@ -194,3 +194,3 @@ // Directory exists, but we still don't | ||
return deferred.promise; | ||
return checkDeferred.promise; | ||
}; | ||
@@ -205,7 +205,7 @@ | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// API | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
module.exports.sync = sync; | ||
module.exports.async = async; |
"use strict"; | ||
var pathUtil = require('path'); | ||
var fs = require('fs'); | ||
var Q = require('q'); | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Sync | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -19,5 +18,4 @@ var sync = function (path) { | ||
return 'file'; | ||
} else { | ||
return 'other'; | ||
} | ||
return 'other'; | ||
} catch (err) { | ||
@@ -32,5 +30,5 @@ if (err.code !== 'ENOENT' && err.code !== 'ENOTDIR') { | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Async | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -59,7 +57,7 @@ var async = function (path) { | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// API | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
module.exports.sync = sync; | ||
module.exports.async = async; |
@@ -38,3 +38,3 @@ // Simple operations on a file: read, write, append. | ||
return data; | ||
} | ||
}; | ||
@@ -46,7 +46,7 @@ var makeNicerJsonParsingError = function (path, err) { | ||
return nicerError; | ||
} | ||
}; | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// SYNC | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -85,3 +85,3 @@ var readSync = function (path, returnAs) { | ||
return data; | ||
} | ||
}; | ||
@@ -100,3 +100,3 @@ var writeFileSync = function (path, data, options) { | ||
} | ||
} | ||
}; | ||
@@ -110,3 +110,3 @@ var writeAtomicSync = function (path, data, options) { | ||
fs.renameSync(path + newExt, path); | ||
} | ||
}; | ||
@@ -122,3 +122,3 @@ var writeSync = function (path, data, options) { | ||
writeStrategy(path, data, { mode: options.mode }); | ||
} | ||
}; | ||
@@ -137,7 +137,7 @@ var appendSync = function (path, data, options) { | ||
} | ||
} | ||
}; | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// ASYNC | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -186,3 +186,3 @@ var promisedReadFile = Q.denodeify(fs.readFile); | ||
return deferred.promise; | ||
} | ||
}; | ||
@@ -227,3 +227,3 @@ var writeFileAsync = function (path, data, options) { | ||
return deferred.promise; | ||
} | ||
}; | ||
@@ -239,3 +239,3 @@ var writeAsync = function (path, data, options) { | ||
return writeStrategy(path, data, { mode: options.mode }); | ||
} | ||
}; | ||
@@ -262,7 +262,7 @@ var appendAsync = function (path, data, options) { | ||
return deferred.promise; | ||
} | ||
}; | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// API | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -269,0 +269,0 @@ module.exports.read = readSync; |
"use strict"; | ||
var pathUtil = require('path'); | ||
var fs = require('fs'); | ||
@@ -21,5 +20,5 @@ var Q = require('q'); | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Sync | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -58,3 +57,3 @@ var sync = function (path, criteria) { | ||
mode: mode, | ||
jsonIndent: criteria.jsonIndent | ||
jsonIndent: criteria.jsonIndent, | ||
}); | ||
@@ -72,3 +71,3 @@ } | ||
mode: criteria.mode, | ||
jsonIndent: criteria.jsonIndent | ||
jsonIndent: criteria.jsonIndent, | ||
}); | ||
@@ -79,5 +78,5 @@ | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Async | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -94,3 +93,3 @@ var promisedStat = Q.denodeify(fs.stat); | ||
var checkWhatWeHaveNow = function () { | ||
var deferred = Q.defer(); | ||
var checkDeferred = Q.defer(); | ||
@@ -104,7 +103,7 @@ promisedStat(path) | ||
// Clear stat variable to indicate now nothing is there | ||
deferred.resolve(undefined); | ||
checkDeferred.resolve(undefined); | ||
}) | ||
.catch(deferred.reject); | ||
.catch(checkDeferred.reject); | ||
} else { | ||
deferred.resolve(stat); | ||
checkDeferred.resolve(stat); | ||
} | ||
@@ -115,14 +114,14 @@ }) | ||
// Path doesn't exist. | ||
deferred.resolve(undefined); | ||
checkDeferred.resolve(undefined); | ||
} else { | ||
// This is other error. Must end here. | ||
deferred.reject(err); | ||
checkDeferred.reject(err); | ||
} | ||
}); | ||
return deferred.promise; | ||
return checkDeferred.promise; | ||
}; | ||
var checkWhatShouldBe = function (stat) { | ||
var deferred = Q.defer(); | ||
var checkDeferred = Q.defer(); | ||
@@ -139,5 +138,5 @@ if (!stat) { | ||
mode: criteria.mode, | ||
jsonIndent: criteria.jsonIndent | ||
jsonIndent: criteria.jsonIndent, | ||
}) | ||
.then(deferred.resolve, deferred.reject); | ||
.then(checkDeferred.resolve, checkDeferred.reject); | ||
@@ -150,2 +149,11 @@ } else { | ||
var checkMode = function () { | ||
if (criteria.mode !== undefined && criteria.mode !== mode) { | ||
promisedChmod(path, criteria.mode) | ||
.then(checkDeferred.resolve, checkDeferred.reject); | ||
} else { | ||
checkDeferred.resolve(); | ||
} | ||
}; | ||
var checkContent = function () { | ||
@@ -155,5 +163,5 @@ if (criteria.content !== undefined) { | ||
mode: mode, | ||
jsonIndent: criteria.jsonIndent | ||
jsonIndent: criteria.jsonIndent, | ||
}) | ||
.then(deferred.resolve, deferred.reject); | ||
.then(checkDeferred.resolve, checkDeferred.reject); | ||
} else { | ||
@@ -164,15 +172,6 @@ checkMode(); | ||
var checkMode = function () { | ||
if (criteria.mode !== undefined && criteria.mode !== mode) { | ||
promisedChmod(path, criteria.mode) | ||
.then(deferred.resolve, deferred.reject); | ||
} else { | ||
deferred.resolve(); | ||
} | ||
}; | ||
checkContent(); | ||
} | ||
return deferred.promise; | ||
return checkDeferred.promise; | ||
}; | ||
@@ -187,7 +186,7 @@ | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// API | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
module.exports.sync = sync; | ||
module.exports.async = async; |
@@ -9,3 +9,3 @@ "use strict"; | ||
var matchesAnyOfGlobs = matcher.create(options.matching, tree.absolutePath, options.cwd); | ||
var matchesAnyOfGlobs = matcher.create(options.matching, tree.absolutePath); | ||
@@ -39,5 +39,11 @@ return inspector.utils.flattenTree(tree).filter(function (inspectObj) { | ||
//--------------------------------------------------------- | ||
var generatePathNotDirectoryError = function (path) { | ||
var err = new Error("Path you want to find stuff in must be a directory " + path); | ||
err.code = 'ENOTDIR'; | ||
return err; | ||
}; | ||
// --------------------------------------------------------- | ||
// Sync | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -48,3 +54,3 @@ var sync = function (path, options, returnAs) { | ||
relativePath: true, | ||
absolutePath: true | ||
absolutePath: true, | ||
}); | ||
@@ -54,2 +60,4 @@ | ||
throw generatePathDoesntExistError(path); | ||
} else if (tree.type !== 'dir') { | ||
throw generatePathNotDirectoryError(path); | ||
} | ||
@@ -61,5 +69,5 @@ | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Async | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -71,3 +79,3 @@ var async = function (path, options, returnAs) { | ||
relativePath: true, | ||
absolutePath: true | ||
absolutePath: true, | ||
}) | ||
@@ -77,2 +85,4 @@ .then(function (tree) { | ||
throw generatePathDoesntExistError(path); | ||
} else if (tree.type !== 'dir') { | ||
throw generatePathNotDirectoryError(path); | ||
} | ||
@@ -89,7 +99,7 @@ | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// API | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
module.exports.sync = sync; | ||
module.exports.async = async; |
@@ -67,5 +67,5 @@ "use strict"; | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Sync | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -94,5 +94,4 @@ var fileChecksum = function (path, algo) { | ||
return null; | ||
} else { | ||
throw err; | ||
} | ||
throw err; | ||
} | ||
@@ -120,5 +119,4 @@ | ||
return null; | ||
} else { | ||
throw err; | ||
} | ||
throw err; | ||
} | ||
@@ -142,9 +140,2 @@ | ||
var treeSync = function (path, options) { | ||
options = options || {}; | ||
options.symlinks = true; | ||
return crawlTreeSync(path, options, null); | ||
}; | ||
var crawlTreeSync = function (path, options, parent) { | ||
@@ -185,2 +176,9 @@ var treeBranch = inspectSync(path, options); | ||
var treeSync = function (path, options) { | ||
options = options || {}; | ||
options.symlinks = true; | ||
return crawlTreeSync(path, options, null); | ||
}; | ||
var createTreeWalkerSync = function (startPath) { | ||
@@ -190,3 +188,3 @@ var allFiles = flattenTree(treeSync(startPath, { | ||
relativePath: true, | ||
mode: true | ||
mode: true, | ||
})); | ||
@@ -199,9 +197,9 @@ return { | ||
return allFiles.shift(); | ||
} | ||
} | ||
}, | ||
}; | ||
}; | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Async | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -218,6 +216,6 @@ var promisedStat = Q.denodeify(fs.stat); | ||
var s = fs.createReadStream(path); | ||
s.on('data', function(data) { | ||
s.on('data', function (data) { | ||
hash.update(data); | ||
}); | ||
s.on('end', function() { | ||
s.on('end', function () { | ||
deferred.resolve(hash.digest('hex')); | ||
@@ -277,22 +275,2 @@ }); | ||
promisedReaddir(path) | ||
.then(function (simpleList) { | ||
if (!useInspect) { | ||
// Only list of paths is required. We are done. | ||
deferred.resolve(simpleList); | ||
} else { | ||
turnSimpleListIntoInspectObjectsList(simpleList); | ||
} | ||
}) | ||
.catch(function (err) { | ||
// Detection if path exists | ||
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') { | ||
// Doesn't exist or is a file, not directory. | ||
// Return null instead of throwing. | ||
deferred.resolve(null); | ||
} else { | ||
deferred.reject(err); | ||
} | ||
}); | ||
var turnSimpleListIntoInspectObjectsList = function (pathsList) { | ||
@@ -322,12 +300,25 @@ var inspectConfig = {}; | ||
promisedReaddir(path) | ||
.then(function (simpleList) { | ||
if (!useInspect) { | ||
// Only list of paths is required. We are done. | ||
deferred.resolve(simpleList); | ||
} else { | ||
turnSimpleListIntoInspectObjectsList(simpleList); | ||
} | ||
}) | ||
.catch(function (err) { | ||
// Detection if path exists | ||
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') { | ||
// Doesn't exist or is a file, not directory. | ||
// Return null instead of throwing. | ||
deferred.resolve(null); | ||
} else { | ||
deferred.reject(err); | ||
} | ||
}); | ||
return deferred.promise; | ||
}; | ||
var treeAsync = function (path, options) { | ||
options = options || {}; | ||
options.symlinks = true; | ||
return crawlTreeAsync(path, options); | ||
}; | ||
var crawlTreeAsync = function (path, options, parent) { | ||
@@ -399,2 +390,9 @@ var deferred = Q.defer(); | ||
var treeAsync = function (path, options) { | ||
options = options || {}; | ||
options.symlinks = true; | ||
return crawlTreeAsync(path, options); | ||
}; | ||
var createTreeWalkerAsync = function (startPath) { | ||
@@ -406,3 +404,3 @@ var deferred = Q.defer(); | ||
relativePath: true, | ||
mode: true | ||
mode: true, | ||
}) | ||
@@ -417,3 +415,3 @@ .then(function (wholeTree) { | ||
return allFiles.shift(); | ||
} | ||
}, | ||
}); | ||
@@ -425,5 +423,5 @@ }); | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// API | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -441,3 +439,3 @@ module.exports.inspect = inspectSync; | ||
module.exports.utils = { | ||
flattenTree: flattenTree | ||
flattenTree: flattenTree, | ||
}; |
@@ -27,3 +27,3 @@ // The main thing. Here everything starts. | ||
return cwdPath || process.cwd(); | ||
} | ||
}; | ||
@@ -39,3 +39,3 @@ var cwd = function () { | ||
return jetpackContext(pathUtil.resolve.apply(null, pathParts)); | ||
} | ||
}; | ||
@@ -45,9 +45,9 @@ // resolves path to inner CWD path of this jetpack instance | ||
return pathUtil.resolve(getCwdPath(), path); | ||
} | ||
}; | ||
var path = function () { | ||
var getPath = function () { | ||
// add CWD base path as first element of arguments array | ||
Array.prototype.unshift.call(arguments, getCwdPath()); | ||
return pathUtil.resolve.apply(null, arguments); | ||
} | ||
}; | ||
@@ -64,3 +64,3 @@ var normalizeOptions = function (options) { | ||
cwd: cwd, | ||
path: path, | ||
path: getPath, | ||
@@ -80,3 +80,3 @@ append: function (path, data, options) { | ||
options = normalizeOptions(options); | ||
return copy.async(resolvePath(from), resolvePath(to), options) | ||
return copy.async(resolvePath(from), resolvePath(to), options); | ||
}, | ||
@@ -175,7 +175,7 @@ | ||
removeAsync: function (path) { | ||
return remove.async(resolvePath(path)) | ||
return remove.async(resolvePath(path)); | ||
}, | ||
rename: function (path, newName) { | ||
path = resolvePath(path) | ||
path = resolvePath(path); | ||
var newPath = pathUtil.join(pathUtil.dirname(path), newName); | ||
@@ -185,3 +185,3 @@ move.sync(path, newPath); | ||
renameAsync: function (path, newName) { | ||
path = resolvePath(path) | ||
path = resolvePath(path); | ||
var newPath = pathUtil.join(pathUtil.dirname(path), newName); | ||
@@ -205,4 +205,4 @@ return move.async(path, newPath); | ||
}; | ||
} | ||
}; | ||
module.exports = jetpackContext; |
@@ -15,5 +15,5 @@ "use strict"; | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Sync | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -43,5 +43,5 @@ var sync = function (from, to) { | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Async | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -62,3 +62,3 @@ var promisedRename = Q.denodeify(fs.rename); | ||
// Hah, no idea. | ||
deferred.reject(err); | ||
deferred.reject(); | ||
} | ||
@@ -103,7 +103,7 @@ }) | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// API | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
module.exports.sync = sync; | ||
module.exports.async = async; |
@@ -6,5 +6,5 @@ "use strict"; | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Sync | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -15,17 +15,17 @@ var sync = function (path) { | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Async | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
var qRimraf = Q.denodeify(rimraf); | ||
var async = function(path, options) { | ||
var async = function (path) { | ||
return qRimraf(path); | ||
} | ||
}; | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// API | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
module.exports.sync = sync; | ||
module.exports.async = async; |
@@ -8,5 +8,5 @@ "use strict"; | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Sync | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -27,5 +27,5 @@ var sync = function (symlinkValue, path) { | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// Async | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
@@ -35,3 +35,3 @@ var promisedSymlink = Q.denodeify(fs.symlink); | ||
var async = function(symlinkValue, path) { | ||
var async = function (symlinkValue, path) { | ||
var deferred = Q.defer(); | ||
@@ -55,9 +55,9 @@ | ||
return deferred.promise; | ||
} | ||
}; | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
// API | ||
//--------------------------------------------------------- | ||
// --------------------------------------------------------- | ||
module.exports.sync = sync; | ||
module.exports.async = async; |
@@ -5,6 +5,5 @@ // Matcher for glob patterns (e.g. *.txt, /a/b/**/z) | ||
var pathUtil = require('path'); | ||
var Minimatch = require('minimatch').Minimatch; | ||
var create = function (patterns, basePath, cwd) { | ||
var create = function (patterns, basePath) { | ||
@@ -15,18 +14,31 @@ if (typeof patterns === 'string') { | ||
// Convert patterns to absolute paths | ||
patterns = patterns.map(function (pattern) { | ||
var hasSlash = (pattern.indexOf('/') !== -1); | ||
// All patterns without slash are left as they are | ||
if (hasSlash) { | ||
// Maybe already is in the format we wanted | ||
var isAbsolute = /^!?\//.test(pattern); // Starts with '/' or '!/' | ||
if (!isAbsolute) { | ||
var isNegated = (pattern[0] === '!'); | ||
// TODO Refactor this. It's ugly! | ||
patterns = patterns.map(function (pattern) { | ||
// Turn relative matchers into absolute | ||
// (change "./a/b" to "/path/to/copy/a/b") | ||
if (/^!?\.\//.test(pattern)) { | ||
return pattern.replace('.', basePath); | ||
} | ||
// Convert pattern defined according to current CWD into absolute. | ||
if (pattern.indexOf('/') !== -1 && !/^!?\//.test(pattern)) { | ||
var index = 0; | ||
// Be aware of negation sign at the beginning. | ||
if (pattern[0] === '!') { | ||
index = 1; | ||
// Remove starting characters which have meaning '!' and '.' | ||
// and first slash to normalize the path. | ||
if (isNegated) { | ||
pattern = pattern.substring(1); | ||
} | ||
if (pattern[0] === '.') { | ||
pattern = pattern.substring(1); | ||
} | ||
if (pattern[0] === '/') { | ||
pattern = pattern.substring(1); | ||
} | ||
// Finally construct ready pattern | ||
if (isNegated) { | ||
pattern = '!' + basePath + '/' + pattern; | ||
} else { | ||
pattern = basePath + '/' + pattern; | ||
} | ||
} | ||
return pattern.substring(0, index) + cwd + '/' + pattern.substring(index); | ||
} | ||
@@ -39,3 +51,3 @@ return pattern; | ||
matchBase: true, | ||
nocomment: true | ||
nocomment: true, | ||
}); | ||
@@ -42,0 +54,0 @@ }); |
{ | ||
"name": "fs-jetpack", | ||
"description": "Better file system API", | ||
"version": "0.6.5", | ||
"version": "0.7.0", | ||
"author": "Jakub Szwacz <jakub@szwacz.com>", | ||
@@ -13,7 +13,10 @@ "dependencies": { | ||
"devDependencies": { | ||
"eslint": "^0.24.0", | ||
"fs-extra": "^0.16.3", | ||
"jasmine": "^2.2.1" | ||
"jasmine": "^2.2.1", | ||
"precommit-hook": "^3.0.0" | ||
}, | ||
"scripts": { | ||
"test": "node_modules/.bin/jasmine" | ||
"test": "node_modules/.bin/jasmine", | ||
"lint": "node_modules/.bin/eslint ." | ||
}, | ||
@@ -30,3 +33,7 @@ "main": "main.js", | ||
"file system" | ||
], | ||
"pre-commit": [ | ||
"lint", | ||
"test" | ||
] | ||
} |
fs-jetpack [![Build Status](https://travis-ci.org/szwacz/fs-jetpack.svg?branch=master)](https://travis-ci.org/szwacz/fs-jetpack) [![Build status](https://ci.appveyor.com/api/projects/status/er206e91fpuuqf58?svg=true)](https://ci.appveyor.com/project/szwacz/fs-jetpack) | ||
========== | ||
Node's [file system API](http://nodejs.org/api/fs.html) is very low level and because of that too often painful to use. Let's build better API on top of standard one, so you can do more work with less code. That's what **fs-jetpack** is all about. | ||
Node's [fs library](http://nodejs.org/api/fs.html) is very low level and because of that often painful to use. *fs-jetpack* wants to fix that by giving you completely rethought, much more conveninet API to work with file system. | ||
@@ -15,7 +15,7 @@ #### [Jump to API Docs](#api) | ||
```javascript | ||
var jetpack = requite('fs-jetpack'); | ||
var jetpack = require('fs-jetpack'); | ||
``` | ||
#What's cool about jetpack? | ||
# What's cool about jetpack? | ||
@@ -61,9 +61,9 @@ ## Promises instead of callbacks | ||
## Throws errors at you as the last resort | ||
Everyone who did something with files for sure seen *"ENOENT, no such file or directory"* error. Jetpack tries to recover from that error if possible. | ||
Everyone who did something with files for sure seen (and probably hates) *"ENOENT, no such file or directory"* error. Jetpack tries to recover from that error if possible. | ||
1. For wrte/creation operations, if any of parent directories doesn't exist jetpack will just create them as well. | ||
2. For read/inspect operations, if file or directory doesn't exist `null` is returned instead of throwing. | ||
## This is just a powerful API (examples) | ||
## Jetpack can do more in less code (examples) | ||
All methods play nicely with each other. Here are few examples what it gives you. | ||
**Note:** All examples are synchronous. Unfortunately asynchronous versions of them will be uglier :) | ||
**Note:** All examples are synchronous. Unfortunately asynchronous equvalents won't be that pretty. | ||
@@ -85,18 +85,20 @@ #### Great for build scripts | ||
#### Files creation in declarative style | ||
Let's say you want to create folder structure: | ||
``` | ||
. | ||
|- greets | ||
|- greet.txt | ||
|- greet.json | ||
|- greets-i18n | ||
|- polish.txt | ||
``` | ||
Peace of cake with jetpack! | ||
```js | ||
// To create structure... | ||
// (CWD path) | ||
// |- greets | ||
// |- greet.txt | ||
// |- greet.json | ||
// |- greets-i18n | ||
// |- polish.txt | ||
jetpack | ||
.dir('greets') | ||
.file('greet.txt', { content: 'Hello World!' }) | ||
.file('greet.json', { content: { greet: 'Hello World!' } }) | ||
.file('greet.txt', { content: 'Hello world!' }) | ||
.file('greet.json', { content: { greet: 'Hello world!' } }) | ||
.cwd('..') | ||
.dir('greets-i18n') | ||
.file('polish.txt', { content: 'Cześć!' }); | ||
.file('polish.txt', { content: 'Witaj świecie!' }); | ||
``` | ||
@@ -189,18 +191,19 @@ | ||
```javascript | ||
// Copies a file (and replaces it if one already exists in "somewhere" direcotry) | ||
jetpack.copy('file.txt', 'somwhere/file.txt', { overwrite: true }); | ||
// Copies a file (and replaces it if one already exists in 'copied' direcotry) | ||
jetpack.copy('file.txt', 'copied/file.txt', { overwrite: true }); | ||
// Copies only .md files from my-dir to somewhere/my-dir | ||
jetpack.copy('my-dir', 'somewhere/my-dir', { matching: '*.md' }); | ||
// Copies only .md files inside 'dir' to 'copied-dir' | ||
jetpack.copy('dir', 'copied-dir', { matching: '*.md' }); | ||
// Can copy also specyfic path anhored to CWD | ||
jetpack.copy('my_dir', 'somewhere/my_dir', { | ||
matching: ['my_dir/images/**'] | ||
}); | ||
// Can add many globs as an array | ||
jetpack.copy('dir', 'copied-dir', { matching: ['*.md', '*.txt'] }); | ||
// When glob pattern starts with './' it means it is anchored to base directory | ||
// you want to copy. Here will be copied only .jpg files from my-dir/images | ||
// and .md files from my-dir/articles | ||
jetpack.copy('my_dir', 'somewhere/my_dir', { | ||
matching: ['./images/**/*.jpg', './articles/**/*.md' ] | ||
// Supports negation patterns as well | ||
jetpack.copy('dir', 'copied-dir', { matching: ['*.md', '!top-secret.md'] }); | ||
// All patterns are anchored to dir you want to copy, not to CWD. | ||
// So in this example directory 'dir1/dir2/images' will be copied | ||
// to 'copied-dir2/images' | ||
jetpack.copy('dir1/dir2', 'copied-dir2', { | ||
matching: 'images/**' | ||
}); | ||
@@ -333,3 +336,3 @@ ``` | ||
* `'absolutePath'` (default) returns array of absolute paths. | ||
* `'relativePath'` returns array of relative paths. The paths are relative to `path` you started search in. | ||
* `'relativePath'` returns array of relative paths. The paths are relative to `path` you started search in, not to CWD. | ||
* `'inspect'` returns array of objects like you called [inspect](#inspect) on every of those files. | ||
@@ -345,2 +348,5 @@ | ||
// Finds all .js files inside 'my-project' but with exclusion of 'vendor' directory. | ||
jetpack.find('my-project', { matching: ['*.js', '!vendor/**/*'] }); | ||
// Finds all jpg and png files and gives you back the list of inspect objects | ||
@@ -347,0 +353,0 @@ // (like you called jetpack.inspect on every of those paths) |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -6,3 +8,2 @@ | ||
var fse = require('fs-extra'); | ||
var pathUtil = require('path'); | ||
var helper = require('./support/spec_helper'); | ||
@@ -9,0 +10,0 @@ var jetpack = require('..'); |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -6,3 +8,2 @@ | ||
var fse = require('fs-extra'); | ||
var pathUtil = require('path'); | ||
var helper = require('./support/spec_helper'); | ||
@@ -130,3 +131,3 @@ var jetpack = require('..'); | ||
jetpack.copy('a', 'b'); | ||
throw "to make sure this code throws" | ||
throw new Error("to make sure this code throws"); | ||
} catch (err) { | ||
@@ -191,3 +192,3 @@ expectations(err); | ||
jetpack.copy('a', 'b'); | ||
throw "to make sure this code throws"; | ||
throw new Error("to make sure this code throws"); | ||
} catch (err) { | ||
@@ -272,9 +273,9 @@ expectations(err); | ||
it("by pattern anchored to CWD", function (done) { | ||
it("by pattern anchored to copied directory", function (done) { | ||
var preparations = function () { | ||
helper.clearWorkingDir(); | ||
fse.outputFileSync('dir/file.txt', '1'); | ||
fse.outputFileSync('dir/a/file.txt', '2'); | ||
fse.outputFileSync('dir/a/b/file.txt', '3'); | ||
fse.outputFileSync('x/y/dir/file.txt', '1'); | ||
fse.outputFileSync('x/y/dir/a/file.txt', '2'); | ||
fse.outputFileSync('x/y/dir/a/b/file.txt', '3'); | ||
}; | ||
@@ -290,3 +291,3 @@ | ||
preparations(); | ||
jetpack.copy('dir', 'copy', { matching: 'dir/a/*.txt' }); | ||
jetpack.copy('x/y/dir', 'copy', { matching: 'a/*.txt' }); | ||
expectations(); | ||
@@ -296,3 +297,3 @@ | ||
preparations(); | ||
jetpack.copyAsync('dir', 'copy', { matching: 'dir/a/*.txt' }) | ||
jetpack.copyAsync('x/y/dir', 'copy', { matching: 'a/*.txt' }) | ||
.then(function () { | ||
@@ -304,15 +305,13 @@ expectations(); | ||
it("by patterns anchored to './' (internals of about to be copied directory)", function (done) { | ||
it("can use ./ as indication of anchor directory", function (done) { | ||
var preparations = function () { | ||
helper.clearWorkingDir(); | ||
fse.outputFileSync('dir/file.txt', '1'); | ||
fse.outputFileSync('dir/a/file.txt', '2'); | ||
fse.outputFileSync('dir/a/b/file.txt', '3'); | ||
fse.outputFileSync('x/y/a.txt', '123'); | ||
fse.outputFileSync('x/y/b/a.txt', '456'); | ||
}; | ||
var expectations = function () { | ||
expect('copy/file.txt').not.toExist(); | ||
expect('copy/a/file.txt').toBeFileWithContent('2'); | ||
expect('copy/a/b/file.txt').not.toExist(); | ||
expect('copy/a.txt').toExist(); | ||
expect('copy/b/a.txt').not.toExist(); | ||
}; | ||
@@ -322,3 +321,3 @@ | ||
preparations(); | ||
jetpack.copy('dir', 'copy', { matching: './a/*.txt' }); | ||
jetpack.copy('x/y', 'copy', { matching: './a.txt' }); | ||
expectations(); | ||
@@ -328,3 +327,3 @@ | ||
preparations(); | ||
jetpack.copyAsync('dir', 'copy', { matching: './a/*.txt' }) | ||
jetpack.copyAsync('x/y', 'copy', { matching: './a.txt' }) | ||
.then(function () { | ||
@@ -336,11 +335,13 @@ expectations(); | ||
it("works also if copying single file", function (done) { | ||
it("matching works also if copying single file", function (done) { | ||
var preparations = function () { | ||
helper.clearWorkingDir(); | ||
fse.outputFileSync('a', '1'); | ||
fse.outputFileSync('a', '123'); | ||
fse.outputFileSync('x', '456'); | ||
}; | ||
var expectations = function () { | ||
expect('b').not.toExist(); | ||
expect('a-copy').not.toExist(); | ||
expect('x-copy').toExist(); | ||
}; | ||
@@ -350,3 +351,4 @@ | ||
preparations(); | ||
jetpack.copy('a', 'b', { matching: 'x' }); | ||
jetpack.copy('a', 'a-copy', { matching: 'x' }); | ||
jetpack.copy('x', 'x-copy', { matching: 'x' }); | ||
expectations(); | ||
@@ -356,4 +358,7 @@ | ||
preparations(); | ||
jetpack.copyAsync('a', 'b', { matching: 'x' }) | ||
jetpack.copyAsync('a', 'a-copy', { matching: 'x' }) | ||
.then(function () { | ||
return jetpack.copyAsync('x', 'x-copy', { matching: 'x' }); | ||
}) | ||
.then(function () { | ||
expectations(); | ||
@@ -368,13 +373,13 @@ done(); | ||
helper.clearWorkingDir(); | ||
fse.mkdirsSync('dir/a/b'); | ||
fse.mkdirsSync('dir/a/x'); | ||
fse.mkdirsSync('dir/a/y'); | ||
fse.mkdirsSync('dir/a/z'); | ||
fse.mkdirsSync('x/y/dir/a/b'); | ||
fse.mkdirsSync('x/y/dir/a/x'); | ||
fse.mkdirsSync('x/y/dir/a/y'); | ||
fse.mkdirsSync('x/y/dir/a/z'); | ||
}; | ||
var expectations = function () { | ||
expect('copy/a/b').toBeDirectory(); | ||
expect('copy/a/x').not.toExist(); | ||
expect('copy/a/y').not.toExist(); | ||
expect('copy/a/z').not.toExist(); | ||
expect('copy/dir/a/b').toBeDirectory(); | ||
expect('copy/dir/a/x').not.toExist(); | ||
expect('copy/dir/a/y').not.toExist(); | ||
expect('copy/dir/a/z').not.toExist(); | ||
}; | ||
@@ -384,9 +389,11 @@ | ||
preparations(); | ||
jetpack.copy('dir', 'copy', { matching: [ | ||
'**', | ||
// Three different pattern types to test: | ||
'!x', | ||
'!dir/a/y', | ||
'!./a/z' | ||
]}); | ||
jetpack.copy('x/y', 'copy', { | ||
matching: [ | ||
'**', | ||
// Three different pattern types to test: | ||
'!x', | ||
'!dir/a/y', | ||
'!./dir/a/z', | ||
], | ||
}); | ||
expectations(); | ||
@@ -396,9 +403,11 @@ | ||
preparations(); | ||
jetpack.copyAsync('dir', 'copy', { matching: [ | ||
'**', | ||
// Three different pattern types to test: | ||
'!x', | ||
'!dir/a/y', | ||
'!./a/z' | ||
]}) | ||
jetpack.copyAsync('x/y', 'copy', { | ||
matching: [ | ||
'**', | ||
// Three different pattern types to test: | ||
'!x', | ||
'!dir/a/y', | ||
'!./dir/a/z', | ||
], | ||
}) | ||
.then(function () { | ||
@@ -461,3 +470,3 @@ expectations(); | ||
preparations(); | ||
var data = jetpack.copy('to_copy', 'copied'); | ||
jetpack.copy('to_copy', 'copied'); | ||
expectations(); | ||
@@ -464,0 +473,0 @@ |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -30,3 +32,3 @@ | ||
//ASYNC | ||
// ASYNC | ||
preparations(); | ||
@@ -56,3 +58,3 @@ jetpack.dirAsync('x') | ||
//ASYNC | ||
// ASYNC | ||
preparations(); | ||
@@ -204,4 +206,4 @@ jetpack.dirAsync('x') | ||
var expectations = function (ret) { | ||
expect(ret.cwd()).toBe(pathUtil.resolve('a')); | ||
var expectations = function (jetpackContext) { | ||
expect(jetpackContext.cwd()).toBe(pathUtil.resolve('a')); | ||
}; | ||
@@ -211,4 +213,4 @@ | ||
preparations(); | ||
var ret = jetpack.dir('a'); | ||
expectations(ret); | ||
var jetpackContextSync = jetpack.dir('a'); | ||
expectations(jetpackContextSync); | ||
@@ -218,4 +220,4 @@ // ASYNC | ||
jetpack.dirAsync('a') | ||
.then(function (ret) { | ||
expectations(ret); | ||
.then(function (jetpackContextAsync) { | ||
expectations(jetpackContextAsync); | ||
done(); | ||
@@ -237,3 +239,3 @@ }); | ||
var expectations = function (ret) { | ||
var expectations = function () { | ||
expect('x').toBeDirectory(); | ||
@@ -240,0 +242,0 @@ }; |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -6,3 +8,2 @@ | ||
var fse = require('fs-extra'); | ||
var pathUtil = require('path'); | ||
var helper = require('./support/spec_helper'); | ||
@@ -16,9 +17,9 @@ var jetpack = require('..'); | ||
// SYNC | ||
var exists = jetpack.exists('file.txt'); | ||
expect(exists).toBe(false); | ||
var existsSync = jetpack.exists('file.txt'); | ||
expect(existsSync).toBe(false); | ||
// ASYNC | ||
jetpack.existsAsync('file.txt') | ||
.then(function (exists) { | ||
expect(exists).toBe(false); | ||
.then(function (existsAsync) { | ||
expect(existsAsync).toBe(false); | ||
done(); | ||
@@ -32,9 +33,9 @@ }); | ||
// SYNC | ||
var exists = jetpack.exists('a'); | ||
expect(exists).toBe('dir'); | ||
var existsSync = jetpack.exists('a'); | ||
expect(existsSync).toBe('dir'); | ||
// ASYNC | ||
jetpack.existsAsync('a') | ||
.then(function (exists) { | ||
expect(exists).toBe('dir'); | ||
.then(function (existsAsync) { | ||
expect(existsAsync).toBe('dir'); | ||
done(); | ||
@@ -48,9 +49,9 @@ }); | ||
// SYNC | ||
var exists = jetpack.exists('text.txt'); | ||
expect(exists).toBe('file'); | ||
var existsSync = jetpack.exists('text.txt'); | ||
expect(existsSync).toBe('file'); | ||
// ASYNC | ||
jetpack.existsAsync('text.txt') | ||
.then(function (exists) { | ||
expect(exists).toBe('file'); | ||
.then(function (existsAsync) { | ||
expect(existsAsync).toBe('file'); | ||
done(); | ||
@@ -66,9 +67,9 @@ }); | ||
// SYNC | ||
var exists = jetContext.exists('text.txt'); | ||
expect(exists).toBe('file'); | ||
var existsSync = jetContext.exists('text.txt'); | ||
expect(existsSync).toBe('file'); | ||
// ASYNC | ||
jetContext.existsAsync('text.txt') | ||
.then(function (exists) { | ||
expect(exists).toBe('file'); | ||
.then(function (existsAsync) { | ||
expect(existsAsync).toBe('file'); | ||
done(); | ||
@@ -89,9 +90,9 @@ }); | ||
// SYNC | ||
var exists = jetpack.exists('text.txt/something'); | ||
expect(exists).toBe(false); | ||
var existsSync = jetpack.exists('text.txt/something'); | ||
expect(existsSync).toBe(false); | ||
// ASYNC | ||
jetpack.existsAsync('text.txt/something') | ||
.then(function (exists) { | ||
expect(exists).toBe(false); | ||
.then(function (existsAsync) { | ||
expect(existsAsync).toBe(false); | ||
done(); | ||
@@ -98,0 +99,0 @@ }); |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -6,3 +8,2 @@ | ||
var fse = require('fs-extra'); | ||
var pathUtil = require('path'); | ||
var helper = require('./support/spec_helper'); | ||
@@ -155,3 +156,3 @@ var jetpack = require('..'); | ||
var expectations = function (content) { | ||
var expectations = function () { | ||
var sizeA = fse.statSync('a.json').size; | ||
@@ -205,3 +206,3 @@ var sizeB = fse.statSync('b.json').size; | ||
jetpack.fileAsync('file.txt', { content: '123' }) | ||
.then(function() { | ||
.then(function () { | ||
expectations(); | ||
@@ -266,9 +267,9 @@ done(); | ||
// SYNC | ||
var jetpackContext = jetpack.file('file.txt'); | ||
expect(jetpackContext).toBe(jetpack); | ||
var jetpackContextSync = jetpack.file('file.txt'); | ||
expect(jetpackContextSync).toBe(jetpack); | ||
// ASYNC | ||
jetpack.fileAsync('file.txt') | ||
.then(function (jetpackContext) { | ||
expect(jetpackContext).toBe(jetpack); | ||
.then(function (jetpackContextAsync) { | ||
expect(jetpackContextAsync).toBe(jetpack); | ||
done(); | ||
@@ -275,0 +276,0 @@ }); |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -27,15 +29,15 @@ | ||
// SYNC | ||
var found = jetpack.find('a', { matching: '*.txt' }); // default | ||
expectations(found); | ||
found = jetpack.find('a', { matching: '*.txt' }, 'absolutePath'); // explicit | ||
expectations(found); | ||
var foundSync = jetpack.find('a', { matching: '*.txt' }); // default | ||
expectations(foundSync); | ||
foundSync = jetpack.find('a', { matching: '*.txt' }, 'absolutePath'); // explicit | ||
expectations(foundSync); | ||
// ASYNC | ||
jetpack.findAsync('a', { matching: '*.txt' }) // default | ||
.then(function (found) { | ||
expectations(found); | ||
.then(function (foundAsync) { | ||
expectations(foundAsync); | ||
return jetpack.findAsync('a', { matching: '*.txt' }, 'absolutePath'); // explicit | ||
}) | ||
.then(function (found) { | ||
expectations(found); | ||
.then(function (foundAsync) { | ||
expectations(foundAsync); | ||
done(); | ||
@@ -59,9 +61,9 @@ }); | ||
// SYNC | ||
var found = jetpack.find('a', { matching: '*.txt' }, 'relativePath'); | ||
expectations(found); | ||
var foundSync = jetpack.find('a', { matching: '*.txt' }, 'relativePath'); | ||
expectations(foundSync); | ||
// ASYNC | ||
jetpack.findAsync('a', { matching: '*.txt' }, 'relativePath') | ||
.then(function (found) { | ||
expectations(found); | ||
.then(function (foundAsync) { | ||
expectations(foundAsync); | ||
done(); | ||
@@ -84,9 +86,9 @@ }); | ||
// SYNC | ||
var found = jetpack.find('a', { matching: '*.txt' }, 'inspect'); | ||
expectations(found); | ||
var foundSync = jetpack.find('a', { matching: '*.txt' }, 'inspect'); | ||
expectations(foundSync); | ||
// ASYNC | ||
jetpack.findAsync('a', { matching: '*.txt' }, 'inspect') | ||
.then(function (found) { | ||
expectations(found); | ||
.then(function (foundAsync) { | ||
expectations(foundAsync); | ||
done(); | ||
@@ -109,9 +111,9 @@ }); | ||
// SYNC | ||
var found = jetpack.find('a', { matching: '*.txt' }); | ||
expectations(found); | ||
var foundSync = jetpack.find('a', { matching: '*.txt' }); | ||
expectations(foundSync); | ||
// ASYNC | ||
jetpack.findAsync('a', { matching: '*.txt' }) | ||
.then(function (found) { | ||
expectations(found); | ||
.then(function (foundAsync) { | ||
expectations(foundAsync); | ||
done(); | ||
@@ -136,3 +138,3 @@ }); | ||
'./b/file.txt', | ||
'./x/y/z' | ||
'./x/y/z', | ||
]); | ||
@@ -144,9 +146,9 @@ }; | ||
// SYNC | ||
var found = jetpack.find('a', { matching: ['*.txt', 'z'] }, 'relativePath'); | ||
expectations(found); | ||
var foundSync = jetpack.find('a', { matching: ['*.txt', 'z'] }, 'relativePath'); | ||
expectations(foundSync); | ||
// ASYNC | ||
jetpack.findAsync('a', { matching: ['*.txt', 'z'] }, 'relativePath') | ||
.then(function (found) { | ||
expectations(found); | ||
.then(function (foundAsync) { | ||
expectations(foundAsync); | ||
done(); | ||
@@ -156,8 +158,8 @@ }); | ||
it("deals with glob anchored with ./", function (done) { | ||
it("anchors globs to directory you're finding in", function (done) { | ||
var preparations = function () { | ||
fse.outputFileSync('a/b/file.txt', '1'); | ||
fse.outputFileSync('a/b/file.md', '2'); | ||
fse.outputFileSync('a/b/c/file.txt', '3'); | ||
fse.outputFileSync('x/y/a/b/file.txt', '1'); | ||
fse.outputFileSync('x/y/a/b/file.md', '2'); | ||
fse.outputFileSync('x/y/a/b/c/file.txt', '3'); | ||
}; | ||
@@ -173,9 +175,9 @@ | ||
// SYNC | ||
var found = jetpack.find('a', { matching: './b/*.txt' }, 'relativePath'); | ||
expectations(found); | ||
var foundSync = jetpack.find('x/y/a', { matching: 'b/*.txt' }, 'relativePath'); | ||
expectations(foundSync); | ||
// ASYNC | ||
jetpack.findAsync('a', { matching: './b/*.txt' }, 'relativePath') | ||
.then(function (found) { | ||
expectations(found); | ||
jetpack.findAsync('x/y/a', { matching: 'b/*.txt' }, 'relativePath') | ||
.then(function (foundAsync) { | ||
expectations(foundAsync); | ||
done(); | ||
@@ -185,8 +187,7 @@ }); | ||
it("deals with glob anchored to CWD", function (done) { | ||
it("can use ./ as indication of anchor directory", function (done) { | ||
var preparations = function () { | ||
fse.outputFileSync('a/b/file.txt', '1'); | ||
fse.outputFileSync('a/b/file.md', '2'); | ||
fse.outputFileSync('a/b/c/file.txt', '3'); | ||
fse.outputFileSync('x/y/a.txt', '123'); | ||
fse.outputFileSync('x/y/b/a.txt', '456'); | ||
}; | ||
@@ -196,3 +197,3 @@ | ||
var normalizedFound = helper.convertToUnixPathSeparators(found); | ||
expect(normalizedFound).toEqual(['./b/file.txt']); | ||
expect(normalizedFound).toEqual(['./a.txt']); | ||
}; | ||
@@ -203,9 +204,9 @@ | ||
// SYNC | ||
var found = jetpack.find('a', { matching: 'a/b/*.txt' }, 'relativePath'); | ||
expectations(found); | ||
var foundSync = jetpack.find('x/y', { matching: './a.txt' }, 'relativePath'); | ||
expectations(foundSync); | ||
// ASYNC | ||
jetpack.findAsync('a', { matching: 'a/b/*.txt' }, 'relativePath') | ||
.then(function (found) { | ||
expectations(found); | ||
jetpack.findAsync('x/y', { matching: './a.txt' }, 'relativePath') | ||
.then(function (foundAsync) { | ||
expectations(foundAsync); | ||
done(); | ||
@@ -219,6 +220,6 @@ }); | ||
helper.clearWorkingDir(); | ||
fse.mkdirsSync('a/b'); | ||
fse.mkdirsSync('a/x'); | ||
fse.mkdirsSync('a/y'); | ||
fse.mkdirsSync('a/z'); | ||
fse.mkdirsSync('x/y/a/b'); | ||
fse.mkdirsSync('x/y/a/x'); | ||
fse.mkdirsSync('x/y/a/y'); | ||
fse.mkdirsSync('x/y/a/z'); | ||
}; | ||
@@ -228,3 +229,3 @@ | ||
var normalizedFound = helper.convertToUnixPathSeparators(found); | ||
expect(normalizedFound).toEqual(['./b']); | ||
expect(normalizedFound).toEqual(['./a/b']); | ||
}; | ||
@@ -234,22 +235,26 @@ | ||
preparations(); | ||
var found = jetpack.find('a', { matching: [ | ||
'a/*', | ||
// Three different pattern types to test: | ||
'!x', | ||
'!a/y', | ||
'!./z' | ||
]}, 'relativePath'); | ||
expectations(found); | ||
var foundSync = jetpack.find('x/y', { | ||
matching: [ | ||
'a/*', | ||
// Three different pattern types to test: | ||
'!x', | ||
'!a/y', | ||
'!./a/z', | ||
], | ||
}, 'relativePath'); | ||
expectations(foundSync); | ||
// ASYNC | ||
preparations(); | ||
jetpack.findAsync('a', { matching: [ | ||
'a/*', | ||
// Three different pattern types to test: | ||
'!x', | ||
'!a/y', | ||
'!./z' | ||
]}, 'relativePath') | ||
.then(function (found) { | ||
expectations(found); | ||
jetpack.findAsync('x/y', { | ||
matching: [ | ||
'a/*', | ||
// Three different pattern types to test: | ||
'!x', | ||
'!a/y', | ||
'!./a/z', | ||
], | ||
}, 'relativePath') | ||
.then(function (foundAsync) { | ||
expectations(foundAsync); | ||
done(); | ||
@@ -259,22 +264,20 @@ }); | ||
it("works even if provided path is a file", function (done) { | ||
it("throws if path doesn't exist", function (done) { | ||
var preparations = function () { | ||
fse.outputFileSync('file.txt', '1'); | ||
var expectations = function (err) { | ||
expect(err.code).toBe('ENOENT'); | ||
expect(err.message).toMatch(/^Path you want to find stuff in doesn't exist/); | ||
}; | ||
var expectations = function (found) { | ||
expect(found).toEqual(['.']); | ||
}; | ||
preparations(); | ||
// SYNC | ||
var found = jetpack.find('file.txt', { matching: '*.txt' }, 'relativePath'); | ||
expectations(found); | ||
try { | ||
jetpack.find('a', { matching: '*.txt' }); | ||
} catch(err) { | ||
expectations(err); | ||
} | ||
// ASYNC | ||
jetpack.findAsync('file.txt', { matching: '*.txt' }, 'relativePath') | ||
.then(function (found) { | ||
expectations(found); | ||
jetpack.findAsync('a', { matching: '*.txt' }) | ||
.catch(function (err) { | ||
expectations(err); | ||
done(); | ||
@@ -284,12 +287,18 @@ }); | ||
it("throws nice error if path doesn't exist", function (done) { | ||
it("throws if path is a file, not a directory", function (done) { | ||
var preparations = function () { | ||
fse.outputFileSync('a/b', 'abc'); | ||
}; | ||
var expectations = function (err) { | ||
expect(err.code).toBe('ENOENT'); | ||
expect(err.message).toMatch(/^Path you want to find stuff in doesn't exist/); | ||
expect(err.code).toBe('ENOTDIR'); | ||
expect(err.message).toMatch(/^Path you want to find stuff in must be a directory/); | ||
}; | ||
preparations(); | ||
// SYNC | ||
try { | ||
jetpack.find('a', { matching: '*.txt' }); | ||
jetpack.find('a/b', { matching: '*.txt' }); | ||
} catch(err) { | ||
@@ -300,3 +309,3 @@ expectations(err); | ||
// ASYNC | ||
jetpack.findAsync('a', { matching: '*.txt' }) | ||
jetpack.findAsync('a/b', { matching: '*.txt' }) | ||
.catch(function (err) { | ||
@@ -323,9 +332,9 @@ expectations(err); | ||
// SYNC | ||
var found = jetContext.find('b', { matching: '*.txt' }, 'inspect'); | ||
expectations(found); | ||
var foundSync = jetContext.find('b', { matching: '*.txt' }, 'inspect'); | ||
expectations(foundSync); | ||
// ASYNC | ||
jetContext.findAsync('b', { matching: '*.txt' }, 'inspect') | ||
.then(function (found) { | ||
expectations(found); | ||
.then(function (foundAsync) { | ||
expectations(foundAsync); | ||
done(); | ||
@@ -332,0 +341,0 @@ }); |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -6,3 +8,2 @@ | ||
var fse = require('fs-extra'); | ||
var pathUtil = require('path'); | ||
var helper = require('./support/spec_helper'); | ||
@@ -19,3 +20,3 @@ var jetpack = require('..'); | ||
fse.outputFileSync('dir/subdir/file.txt', 'defg'); | ||
} | ||
}; | ||
@@ -31,4 +32,4 @@ var expectations = function (data) { | ||
type: 'file', | ||
size: 3 | ||
},{ | ||
size: 3, | ||
}, { | ||
name: 'subdir', | ||
@@ -41,9 +42,9 @@ type: 'dir', | ||
type: 'file', | ||
size: 4 | ||
} | ||
] | ||
} | ||
] | ||
size: 4, | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
} | ||
}; | ||
@@ -53,9 +54,9 @@ preparations(); | ||
// SYNC | ||
var tree = jetpack.inspectTree('dir'); | ||
expectations(tree); | ||
var treeSync = jetpack.inspectTree('dir'); | ||
expectations(treeSync); | ||
// ASYNC | ||
jetpack.inspectTreeAsync('dir') | ||
.then(function (tree) { | ||
expectations(tree); | ||
.then(function (treeAsync) { | ||
expectations(treeAsync); | ||
done(); | ||
@@ -72,3 +73,3 @@ }); | ||
fse.outputFileSync('dir/subdir/file.txt', 'defg'); | ||
} | ||
}; | ||
@@ -88,3 +89,3 @@ var expectations = function (data) { | ||
expect(data.children[3].children[0].size).toBe(4); | ||
} | ||
}; | ||
@@ -94,9 +95,9 @@ preparations(); | ||
// SYNC | ||
var tree = jetpack.inspectTree('dir'); | ||
expectations(tree); | ||
var treeSync = jetpack.inspectTree('dir'); | ||
expectations(treeSync); | ||
// ASYNC | ||
jetpack.inspectTreeAsync('dir') | ||
.then(function (tree) { | ||
expectations(tree); | ||
.then(function (treeAsync) { | ||
expectations(treeAsync); | ||
done(); | ||
@@ -125,9 +126,9 @@ }); | ||
// SYNC | ||
var tree = jetpack.inspectTree('dir', { checksum: 'md5' }); | ||
expectations(tree); | ||
var treeSync = jetpack.inspectTree('dir', { checksum: 'md5' }); | ||
expectations(treeSync); | ||
// ASYNC | ||
jetpack.inspectTreeAsync('dir', { checksum: 'md5' }) | ||
.then(function (tree) { | ||
expectations(tree); | ||
.then(function (treeAsync) { | ||
expectations(treeAsync); | ||
done(); | ||
@@ -156,9 +157,9 @@ }); | ||
// SYNC | ||
var tree = jetpack.inspectTree('dir', { checksum: 'md5' }); | ||
expectations(tree); | ||
var treeSync = jetpack.inspectTree('dir', { checksum: 'md5' }); | ||
expectations(treeSync); | ||
// ASYNC | ||
jetpack.inspectTreeAsync('dir', { checksum: 'md5' }) | ||
.then(function (tree) { | ||
expectations(tree); | ||
.then(function (treeAsync) { | ||
expectations(treeAsync); | ||
done(); | ||
@@ -172,3 +173,3 @@ }); | ||
fse.outputFileSync('dir/subdir/file.txt', 'defg'); | ||
} | ||
}; | ||
@@ -196,3 +197,3 @@ var expectations = function (data) { | ||
expect(data.children[0].children[0].relativePath).toBe('./subdir/file.txt'); | ||
} | ||
}; | ||
@@ -202,9 +203,9 @@ preparations(); | ||
// SYNC | ||
var tree = jetpack.inspectTree('dir', { relativePath: true }); | ||
expectations(tree); | ||
var treeSync = jetpack.inspectTree('dir', { relativePath: true }); | ||
expectations(treeSync); | ||
// ASYNC | ||
jetpack.inspectTreeAsync('dir', { relativePath: true }) | ||
.then(function (tree) { | ||
expectations(tree); | ||
.then(function (treeAsync) { | ||
expectations(treeAsync); | ||
done(); | ||
@@ -218,3 +219,3 @@ }); | ||
fse.outputFileSync('dir/file.txt', 'abc'); | ||
} | ||
}; | ||
@@ -225,5 +226,5 @@ var expectations = function (data) { | ||
type: 'file', | ||
size: 3 | ||
size: 3, | ||
}); | ||
} | ||
}; | ||
@@ -233,9 +234,9 @@ preparations(); | ||
// SYNC | ||
var tree = jetpack.inspectTree('dir/file.txt'); | ||
expectations(tree); | ||
var treeSync = jetpack.inspectTree('dir/file.txt'); | ||
expectations(treeSync); | ||
// ASYNC | ||
jetpack.inspectTreeAsync('dir/file.txt') | ||
.then(function (tree) { | ||
expectations(tree); | ||
.then(function (treeAsync) { | ||
expectations(treeAsync); | ||
done(); | ||
@@ -249,3 +250,3 @@ }); | ||
fse.mkdirsSync('empty'); | ||
} | ||
}; | ||
@@ -257,5 +258,5 @@ var expectations = function (data) { | ||
size: 0, | ||
children: [] | ||
children: [], | ||
}); | ||
} | ||
}; | ||
@@ -265,9 +266,9 @@ preparations(); | ||
// SYNC | ||
var tree = jetpack.inspectTree('empty'); | ||
expectations(tree); | ||
var treeSync = jetpack.inspectTree('empty'); | ||
expectations(treeSync); | ||
// ASYNC | ||
jetpack.inspectTreeAsync('empty') | ||
.then(function (tree) { | ||
expectations(tree); | ||
.then(function (treeAsync) { | ||
expectations(treeAsync); | ||
done(); | ||
@@ -284,9 +285,9 @@ }); | ||
// SYNC | ||
var data = jetpack.inspectTree('nonexistent'); | ||
expectations(data); | ||
var dataSync = jetpack.inspectTree('nonexistent'); | ||
expectations(dataSync); | ||
// ASYNC | ||
jetpack.inspectTreeAsync('nonexistent') | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -311,9 +312,9 @@ }); | ||
// SYNC | ||
var data = jetContext.inspectTree('b.txt'); | ||
expectations(data); | ||
var dataSync = jetContext.inspectTree('b.txt'); | ||
expectations(dataSync); | ||
// ASYNC | ||
jetContext.inspectTreeAsync('b.txt') | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -334,3 +335,3 @@ }); | ||
fse.symlinkSync('dir/file.txt', 'dir/symlinked_file.txt'); | ||
} | ||
}; | ||
@@ -346,9 +347,9 @@ var expectations = function (data) { | ||
size: 3, | ||
},{ | ||
}, { | ||
name: 'symlinked_file.txt', | ||
type: 'symlink', | ||
pointsAt: 'dir/file.txt', | ||
}] | ||
}], | ||
}); | ||
} | ||
}; | ||
@@ -358,9 +359,9 @@ preparations(); | ||
// SYNC | ||
var data = jetpack.inspectTree('dir'); | ||
expectations(data); | ||
var dataSync = jetpack.inspectTree('dir'); | ||
expectations(dataSync); | ||
// ASYNC | ||
jetpack.inspectTreeAsync('dir') | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -367,0 +368,0 @@ }); |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -6,3 +8,2 @@ | ||
var fse = require('fs-extra'); | ||
var pathUtil = require('path'); | ||
var helper = require('./support/spec_helper'); | ||
@@ -18,3 +19,3 @@ var jetpack = require('..'); | ||
fse.outputFileSync('dir/file.txt', 'abc'); | ||
} | ||
}; | ||
@@ -27,3 +28,3 @@ var expectations = function (data) { | ||
}); | ||
} | ||
}; | ||
@@ -33,9 +34,9 @@ preparations(); | ||
// SYNC | ||
var data = jetpack.inspect('dir/file.txt'); | ||
expectations(data); | ||
var dataSync = jetpack.inspect('dir/file.txt'); | ||
expectations(dataSync); | ||
// ASYNC | ||
jetpack.inspectAsync('dir/file.txt') | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -49,3 +50,3 @@ }); | ||
fse.mkdirsSync('dir/empty'); | ||
} | ||
}; | ||
@@ -57,3 +58,3 @@ var expectations = function (data) { | ||
}); | ||
} | ||
}; | ||
@@ -63,9 +64,9 @@ preparations(); | ||
// SYNC | ||
var data = jetpack.inspect('dir/empty'); | ||
expectations(data); | ||
var dataSync = jetpack.inspect('dir/empty'); | ||
expectations(dataSync); | ||
// ASYNC | ||
jetpack.inspectAsync('dir/empty') | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -82,9 +83,9 @@ }); | ||
// SYNC | ||
var data = jetpack.inspect('nonexistent'); | ||
expectations(data); | ||
var dataSync = jetpack.inspect('nonexistent'); | ||
expectations(dataSync); | ||
// ASYNC | ||
jetpack.inspectAsync('nonexistent') | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -98,3 +99,3 @@ }); | ||
fse.outputFileSync('dir/file.txt', 'abc'); | ||
} | ||
}; | ||
@@ -105,3 +106,3 @@ var expectations = function (data) { | ||
expect(typeof data.changeTime.getTime).toBe('function'); | ||
} | ||
}; | ||
@@ -111,9 +112,9 @@ preparations(); | ||
// SYNC | ||
var data = jetpack.inspect('dir/file.txt', { times: true }); | ||
expectations(data); | ||
var dataSync = jetpack.inspect('dir/file.txt', { times: true }); | ||
expectations(dataSync); | ||
// ASYNC | ||
jetpack.inspectAsync('dir/file.txt', { times: true }) | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -127,7 +128,7 @@ }); | ||
fse.outputFileSync('dir/file.txt', 'abc'); | ||
} | ||
}; | ||
var expectations = function (data) { | ||
expect(data.absolutePath).toBe(jetpack.path('dir/file.txt')); | ||
} | ||
}; | ||
@@ -137,9 +138,9 @@ preparations(); | ||
// SYNC | ||
var data = jetpack.inspect('dir/file.txt', { absolutePath: true }); | ||
expectations(data); | ||
var dataSync = jetpack.inspect('dir/file.txt', { absolutePath: true }); | ||
expectations(dataSync); | ||
// ASYNC | ||
jetpack.inspectAsync('dir/file.txt', { absolutePath: true }) | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -165,4 +166,4 @@ }); | ||
preparations(); | ||
var data = jetContext.inspect('b.txt'); | ||
expectations(data); | ||
var dataSync = jetContext.inspect('b.txt'); | ||
expectations(dataSync); | ||
@@ -172,4 +173,4 @@ // ASYNC | ||
jetContext.inspectAsync('b.txt') | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -185,3 +186,3 @@ }); | ||
content: 'abc', | ||
expected: '900150983cd24fb0d6963f7d28e17f72' | ||
expected: '900150983cd24fb0d6963f7d28e17f72', | ||
}, | ||
@@ -191,3 +192,3 @@ { | ||
content: 'abc', | ||
expected: 'a9993e364706816aba3e25717850c26c9cd0d89d' | ||
expected: 'a9993e364706816aba3e25717850c26c9cd0d89d', | ||
}, | ||
@@ -197,3 +198,3 @@ { | ||
content: 'abc', | ||
expected: 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad' | ||
expected: 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad', | ||
}, | ||
@@ -203,3 +204,3 @@ { | ||
content: '', // just to check if we are counting checksums of empty file correctly | ||
expected: 'd41d8cd98f00b204e9800998ecf8427e' | ||
expected: 'd41d8cd98f00b204e9800998ecf8427e', | ||
}, | ||
@@ -212,7 +213,7 @@ ].forEach(function (test) { | ||
fse.outputFileSync('file.txt', test.content); | ||
} | ||
}; | ||
var expectations = function (data) { | ||
expect(data[test.name]).toBe(test.expected); | ||
} | ||
}; | ||
@@ -222,9 +223,9 @@ preparations(); | ||
// SYNC | ||
var data = jetpack.inspect('file.txt', { checksum: test.name }); | ||
expectations(data); | ||
var dataSync = jetpack.inspect('file.txt', { checksum: test.name }); | ||
expectations(dataSync); | ||
// ASYNC | ||
jetpack.inspectAsync('file.txt', { checksum: test.name }) | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -248,7 +249,7 @@ }); | ||
fse.outputFileSync('dir/file.txt', 'abc'); | ||
} | ||
}; | ||
var expectations = function (data) { | ||
expect(typeof data.mode).toBe('number'); | ||
} | ||
}; | ||
@@ -258,9 +259,9 @@ preparations(); | ||
// SYNC | ||
var data = jetpack.inspect('dir/file.txt', { mode: true }); | ||
expectations(data); | ||
var dataSync = jetpack.inspect('dir/file.txt', { mode: true }); | ||
expectations(dataSync); | ||
// ASYNC | ||
jetpack.inspectAsync('dir/file.txt', { mode: true }) | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -275,3 +276,3 @@ }); | ||
fse.symlinkSync('dir/file.txt', 'symlinked_file.txt'); | ||
} | ||
}; | ||
@@ -284,3 +285,3 @@ var expectations = function (data) { | ||
}); | ||
} | ||
}; | ||
@@ -290,9 +291,9 @@ preparations(); | ||
// SYNC | ||
var data = jetpack.inspect('symlinked_file.txt'); | ||
expectations(data); | ||
var dataSync = jetpack.inspect('symlinked_file.txt'); | ||
expectations(dataSync); | ||
// ASYNC | ||
jetpack.inspectAsync('symlinked_file.txt') | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -307,3 +308,3 @@ }); | ||
fse.symlinkSync('dir/file.txt', 'symlinked_file.txt'); | ||
} | ||
}; | ||
@@ -314,5 +315,5 @@ var expectations = function (data) { | ||
type: 'symlink', | ||
pointsAt: 'dir/file.txt' | ||
pointsAt: 'dir/file.txt', | ||
}); | ||
} | ||
}; | ||
@@ -322,9 +323,9 @@ preparations(); | ||
// SYNC | ||
var data = jetpack.inspect('symlinked_file.txt', { symlinks: true }); | ||
expectations(data); | ||
var dataSync = jetpack.inspect('symlinked_file.txt', { symlinks: true }); | ||
expectations(dataSync); | ||
// ASYNC | ||
jetpack.inspectAsync('symlinked_file.txt', { symlinks: true }) | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -331,0 +332,0 @@ }); |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -6,3 +8,2 @@ | ||
var fse = require('fs-extra'); | ||
var pathUtil = require('path'); | ||
var helper = require('./support/spec_helper'); | ||
@@ -21,7 +22,7 @@ var jetpack = require('..'); | ||
fse.outputFileSync('dir/subdir/file.txt', 'defg'); | ||
} | ||
}; | ||
var expectations = function (data) { | ||
expect(data).toEqual(['empty', 'empty.txt', 'file.txt', 'subdir']); | ||
} | ||
}; | ||
@@ -31,9 +32,9 @@ preparations(); | ||
// SYNC | ||
var list = jetpack.list('dir'); | ||
expectations(list); | ||
var listSync = jetpack.list('dir'); | ||
expectations(listSync); | ||
// ASYNC | ||
jetpack.listAsync('dir') | ||
.then(function (list) { | ||
expectations(list); | ||
.then(function (listAsync) { | ||
expectations(listAsync); | ||
done(); | ||
@@ -48,3 +49,3 @@ }); | ||
fse.mkdirsSync('dir/next'); | ||
} | ||
}; | ||
@@ -57,8 +58,8 @@ var expectations = function (data) { | ||
size: 3, | ||
},{ | ||
}, { | ||
name: 'next', | ||
type: 'dir', | ||
} | ||
}, | ||
]); | ||
} | ||
}; | ||
@@ -68,9 +69,9 @@ preparations(); | ||
// SYNC | ||
var list = jetpack.list('dir', true); | ||
expectations(list); | ||
var listSync = jetpack.list('dir', true); | ||
expectations(listSync); | ||
// ASYNC | ||
jetpack.listAsync('dir', true) | ||
.then(function (list) { | ||
expectations(list); | ||
.then(function (listAsync) { | ||
expectations(listAsync); | ||
done(); | ||
@@ -84,7 +85,7 @@ }); | ||
fse.outputFileSync('dir/file.txt', 'abc'); | ||
} | ||
}; | ||
var expectations = function (data) { | ||
expect(data[0].md5).toBeDefined(); | ||
} | ||
}; | ||
@@ -94,9 +95,9 @@ preparations(); | ||
// SYNC | ||
var list = jetpack.list('dir', { checksum: 'md5' }); | ||
expectations(list); | ||
var listSync = jetpack.list('dir', { checksum: 'md5' }); | ||
expectations(listSync); | ||
// ASYNC | ||
jetpack.listAsync('dir', { checksum: 'md5' }) | ||
.then(function (list) { | ||
expectations(list); | ||
.then(function (listAsync) { | ||
expectations(listAsync); | ||
done(); | ||
@@ -113,9 +114,9 @@ }); | ||
// SYNC | ||
var data = jetpack.list('nonexistent'); | ||
expectations(data); | ||
var dataSync = jetpack.list('nonexistent'); | ||
expectations(dataSync); | ||
// ASYNC | ||
jetpack.listAsync('nonexistent') | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -138,9 +139,9 @@ }); | ||
// SYNC | ||
var list = jetpack.list('file.txt'); | ||
expectations(list); | ||
var listSync = jetpack.list('file.txt'); | ||
expectations(listSync); | ||
// ASYNC | ||
jetpack.listAsync('file.txt') | ||
.then(function (list) { | ||
expectations(list); | ||
.then(function (listAsync) { | ||
expectations(listAsync); | ||
done(); | ||
@@ -166,4 +167,4 @@ }); | ||
preparations(); | ||
var data = jetContext.list('b'); | ||
expectations(data); | ||
var dataSync = jetContext.list('b'); | ||
expectations(dataSync); | ||
@@ -173,4 +174,4 @@ // ASYNC | ||
jetContext.listAsync('b') | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -177,0 +178,0 @@ }); |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -6,3 +8,2 @@ | ||
var fse = require('fs-extra'); | ||
var pathUtil = require('path'); | ||
var helper = require('./support/spec_helper'); | ||
@@ -103,3 +104,3 @@ var jetpack = require('..'); | ||
jetpack.move('a', 'b'); | ||
throw "to make sure this code throws" | ||
throw new Error("to make sure this code throws"); | ||
} catch (err) { | ||
@@ -106,0 +107,0 @@ expectations(err); |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -6,3 +8,2 @@ | ||
var fse = require('fs-extra'); | ||
var pathUtil = require('path'); | ||
var helper = require('./support/spec_helper'); | ||
@@ -27,6 +28,6 @@ var jetpack = require('..'); | ||
preparations(); | ||
var content = jetpack.read('file.txt'); // defaults to 'utf8' | ||
expectations(content); | ||
content = jetpack.read('file.txt', 'utf8'); // explicitly said | ||
expectations(content); | ||
var contentSync = jetpack.read('file.txt'); // defaults to 'utf8' | ||
expectations(contentSync); | ||
contentSync = jetpack.read('file.txt', 'utf8'); // explicitly said | ||
expectations(contentSync); | ||
@@ -36,8 +37,8 @@ // ASYNC | ||
jetpack.readAsync('file.txt') // defaults to 'utf8' | ||
.then(function (content) { | ||
expectations(content); | ||
.then(function (contentAsync) { | ||
expectations(contentAsync); | ||
return jetpack.readAsync('file.txt', 'utf8'); // explicitly said | ||
}) | ||
.then(function (content) { | ||
expectations(content); | ||
.then(function (contentAsync) { | ||
expectations(contentAsync); | ||
done(); | ||
@@ -63,4 +64,4 @@ }); | ||
preparations(); | ||
var content = jetpack.read('file.txt', 'buf'); | ||
expectations(content); | ||
var contentSync = jetpack.read('file.txt', 'buf'); | ||
expectations(contentSync); | ||
@@ -70,4 +71,4 @@ // ASYNC | ||
jetpack.readAsync('file.txt', 'buf') | ||
.then(function (content) { | ||
expectations(content); | ||
.then(function (contentAsync) { | ||
expectations(contentAsync); | ||
done(); | ||
@@ -80,3 +81,3 @@ }); | ||
var obj = { | ||
utf8: "ąćłźż" | ||
utf8: "ąćłźż", | ||
}; | ||
@@ -89,3 +90,3 @@ | ||
var expectations = function () { | ||
var expectations = function (content) { | ||
expect(content).toEqual(obj); | ||
@@ -96,4 +97,4 @@ }; | ||
preparations(); | ||
var content = jetpack.read('file.json', 'json'); | ||
expectations(content); | ||
var contentSync = jetpack.read('file.json', 'json'); | ||
expectations(contentSync); | ||
@@ -103,4 +104,4 @@ // ASYNC | ||
jetpack.readAsync('file.json', 'json') | ||
.then(function (content) { | ||
expectations(content); | ||
.then(function (contentAsync) { | ||
expectations(contentAsync); | ||
done(); | ||
@@ -142,3 +143,3 @@ }); | ||
utf8: "ąćłźż", | ||
date: new Date() | ||
date: new Date(), | ||
}; | ||
@@ -157,4 +158,4 @@ | ||
preparations(); | ||
var content = jetpack.read('file.json', 'jsonWithDates'); | ||
expectations(content); | ||
var contentSync = jetpack.read('file.json', 'jsonWithDates'); | ||
expectations(contentSync); | ||
@@ -164,4 +165,4 @@ // ASYNC | ||
jetpack.readAsync('file.json', 'jsonWithDates') | ||
.then(function (content) { | ||
expectations(content); | ||
.then(function (contentAsync) { | ||
expectations(contentAsync); | ||
done(); | ||
@@ -178,9 +179,9 @@ }); | ||
// SYNC | ||
var content = jetpack.read('nonexistent.txt'); | ||
expectations(content); | ||
var contentSync = jetpack.read('nonexistent.txt'); | ||
expectations(contentSync); | ||
// ASYNC | ||
jetpack.readAsync('nonexistent.txt') | ||
.then(function (content) { | ||
expectations(content); | ||
.then(function (contentAsync) { | ||
expectations(contentAsync); | ||
done(); | ||
@@ -204,4 +205,4 @@ }); | ||
try { | ||
var content = jetpack.read('dir'); | ||
throw 'to make sure this code throws'; | ||
jetpack.read('dir'); | ||
throw new Error('to make sure this code throws'); | ||
} catch (err) { | ||
@@ -234,9 +235,9 @@ expectations(err); | ||
// SYNC | ||
var data = jetContext.read('file.txt'); | ||
expectations(data); | ||
var dataSync = jetContext.read('file.txt'); | ||
expectations(dataSync); | ||
// ASYNC | ||
jetContext.readAsync('file.txt') | ||
.then(function (data) { | ||
expectations(data); | ||
.then(function (dataAsync) { | ||
expectations(dataAsync); | ||
done(); | ||
@@ -243,0 +244,0 @@ }); |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -6,3 +8,2 @@ | ||
var fse = require('fs-extra'); | ||
var pathUtil = require('path'); | ||
var helper = require('./support/spec_helper'); | ||
@@ -93,3 +94,3 @@ var jetpack = require('..'); | ||
preparations(); | ||
jetContext.remove('b') | ||
jetContext.remove('b'); | ||
expectations(); | ||
@@ -96,0 +97,0 @@ |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -6,3 +8,2 @@ | ||
var fse = require('fs-extra'); | ||
var pathUtil = require('path'); | ||
var helper = require('./support/spec_helper'); | ||
@@ -9,0 +10,0 @@ var jetpack = require('..'); |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -6,3 +8,2 @@ | ||
var fse = require('fs-extra'); | ||
var pathUtil = require('path'); | ||
var helper = require('./support/spec_helper'); | ||
@@ -9,0 +10,0 @@ var jetpack = require('..'); |
@@ -17,3 +17,3 @@ 'use strict'; | ||
pass: pass, | ||
message: message | ||
message: message, | ||
}; | ||
@@ -31,6 +31,6 @@ }, | ||
pass: pass, | ||
message: message | ||
message: message, | ||
}; | ||
} | ||
} | ||
}, | ||
}; | ||
}; | ||
@@ -41,3 +41,3 @@ | ||
compare: function (path) { | ||
var pass = false; | ||
var pass; | ||
var message = 'Path ' + path + ' should be directory'; | ||
@@ -47,9 +47,12 @@ try { | ||
pass = stat.isDirectory(); | ||
} catch (err) {} | ||
} catch (err) { | ||
// For sure not a directory. | ||
pass = false; | ||
} | ||
return { | ||
pass: pass, | ||
message: message | ||
message: message, | ||
}; | ||
} | ||
} | ||
}, | ||
}; | ||
}; | ||
@@ -76,6 +79,6 @@ | ||
pass: pass, | ||
message: message | ||
message: message, | ||
}; | ||
} | ||
} | ||
}, | ||
}; | ||
}; | ||
@@ -102,6 +105,6 @@ | ||
pass: pass, | ||
message: message | ||
message: message, | ||
}; | ||
} | ||
} | ||
}, | ||
}; | ||
}; |
@@ -0,3 +1,7 @@ | ||
/* eslint-env jasmine */ | ||
// Boilerplate code for every test. | ||
"use strict"; | ||
var fse = require('fs-extra'); | ||
@@ -9,3 +13,3 @@ var pathUtil = require('path'); | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 500; | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; | ||
@@ -24,3 +28,3 @@ var originalCwd = process.cwd(); | ||
if (fse.readdirSync('.').length > 0) { | ||
throw "Clearing working directory failed!"; | ||
throw new Error("Clearing working directory failed!"); | ||
} | ||
@@ -42,3 +46,3 @@ }; | ||
if (pathUtil.basename(process.cwd()) !== 'fs-jetpack-test') { | ||
throw "CWD switch failed!"; | ||
throw new Error("CWD switch failed!"); | ||
} | ||
@@ -45,0 +49,0 @@ |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -6,3 +8,2 @@ | ||
var fse = require('fs-extra'); | ||
var pathUtil = require('path'); | ||
var helper = require('./support/spec_helper'); | ||
@@ -9,0 +10,0 @@ var jetpack = require('..'); |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -67,2 +69,9 @@ | ||
it("{a,b}", function () { | ||
var test = matcher.create(['*.{jpg,png}']); | ||
expect(test('a.jpg')).toBe(true); | ||
expect(test('b.png')).toBe(true); | ||
expect(test('c.txt')).toBe(false); | ||
}); | ||
it("?", function () { | ||
@@ -69,0 +78,0 @@ var test = matcher.create(['a?c']); |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -6,3 +8,2 @@ | ||
var fse = require('fs-extra'); | ||
var pathUtil = require('path'); | ||
var helper = require('./support/spec_helper'); | ||
@@ -9,0 +10,0 @@ var jetpack = require('..'); |
@@ -0,1 +1,3 @@ | ||
/* eslint-env jasmine */ | ||
"use strict"; | ||
@@ -6,3 +8,2 @@ | ||
var fse = require('fs-extra'); | ||
var pathUtil = require('path'); | ||
var helper = require('./support/spec_helper'); | ||
@@ -70,3 +71,3 @@ var jetpack = require('..'); | ||
var obj = { | ||
utf8: "ąćłźż" | ||
utf8: "ąćłźż", | ||
}; | ||
@@ -100,3 +101,3 @@ | ||
var obj = { | ||
utf8: "ąćłźż" | ||
utf8: "ąćłźż", | ||
}; | ||
@@ -141,3 +142,3 @@ | ||
var obj = { | ||
date: new Date() | ||
date: new Date(), | ||
}; | ||
@@ -144,0 +145,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
194765
47
4821
553
4