machinepack-fs
Advanced tools
Comparing version 7.0.0 to 8.0.0
@@ -15,3 +15,3 @@ module.exports = { | ||
dir: { | ||
path: { | ||
example: '/foo/bar/baz', | ||
@@ -29,3 +29,3 @@ description: 'The path to ensure- if nothing exists, a directory will be created here.', | ||
success: { | ||
description: 'Directory was either just created, or already existed, at the specified path.' | ||
description: 'Either a directory already existed, or it was just created, at the specified path.' | ||
} | ||
@@ -37,9 +37,10 @@ | ||
fn: function(inputs, exits) { | ||
var path = require('path'); | ||
var fsx = require('fs-extra'); | ||
// In case we ended up w/ a relative path, make it absolute. | ||
inputs.dir = require('path').resolve(process.cwd(), inputs.dir); | ||
inputs.path = path.resolve(inputs.path); | ||
fsx.ensureDir(inputs.dir, function(err) { | ||
if (err) return exits.error(err); | ||
fsx.ensureDir(inputs.path, function(err) { | ||
if (err) {return exits.error(err);} | ||
return exits.success(); | ||
@@ -46,0 +47,0 @@ }); |
@@ -30,3 +30,4 @@ module.exports = { | ||
defaultsTo: '*', | ||
constant: true | ||
constant: true, | ||
isExemplar: true | ||
} | ||
@@ -39,11 +40,9 @@ | ||
success: { | ||
outputDescription: 'The data which is stored in the JSON file now.', | ||
like: 'schema' | ||
}, | ||
couldNotParse: { | ||
description: 'Could not parse file as JSON.' | ||
}, | ||
success: { | ||
description: 'Returns the data which is now stored in the JSON file.', | ||
getExample: function (inputs){ | ||
return inputs.schema; | ||
} | ||
} | ||
@@ -68,5 +67,2 @@ | ||
}, | ||
success: function (data){ | ||
return exits.success(data); | ||
}, | ||
doesNotExist: function (){ | ||
@@ -92,3 +88,6 @@ try { | ||
} | ||
}//</readJson.doesNotExist> | ||
},//</readJson.doesNotExist> | ||
success: function (data){ | ||
return exits.success(data); | ||
}//</readJson.success> | ||
});//</readJson> | ||
@@ -95,0 +94,0 @@ |
module.exports = { | ||
friendlyName: 'Exists?', | ||
@@ -45,4 +46,6 @@ | ||
} | ||
}; | ||
@@ -124,3 +124,3 @@ module.exports = { | ||
// If this is the top-level directory, exclude it. | ||
if (entry === inputs.dir) return; | ||
if (entry === inputs.dir) { return; } | ||
// Add the new entry to our result list unless it is: | ||
@@ -137,3 +137,3 @@ // • hidden (and the `includeHidden` input is set to false) | ||
// If this is the top-level directory, exclude it. | ||
if (entry===inputs.dir) return; | ||
if (entry===inputs.dir) { return; } | ||
// Add the new entry to our result list unless it is: | ||
@@ -152,3 +152,3 @@ // • hidden (and the `includeHidden` input is set to false) | ||
walker.on('error', function (err){ | ||
if (spinlock) return; | ||
if (spinlock) { return; } | ||
spinlock = true; | ||
@@ -161,3 +161,3 @@ if (err.code === 'ENOENT') { | ||
walker.on('end', function (){ | ||
if (spinlock) return; | ||
if (spinlock) { return; } | ||
spinlock = true; | ||
@@ -164,0 +164,0 @@ return exits.success(results); |
@@ -20,4 +20,5 @@ module.exports = { | ||
force: { | ||
description: 'Whether or not to overwrite a file or directory which already exists at the specified destination.', | ||
example: true | ||
description: 'Overwrite files or directories which might exist at or within the specified destination path?', | ||
example: false, | ||
defaultsTo: false | ||
} | ||
@@ -30,2 +31,6 @@ | ||
success: { | ||
description: 'New directory created successfully.' | ||
}, | ||
alreadyExists: { | ||
@@ -39,11 +44,9 @@ description: 'Something already exists at the specified path (overwrite by enabling the `force` input)' | ||
fn: function (inputs, exits) { | ||
var path = require('path'); | ||
var fsx = require('fs-extra'); | ||
var _ = require('lodash'); | ||
var async = require('async'); | ||
// In case we ended up here w/ a relative path, | ||
// resolve it using the process's CWD | ||
inputs.destination = path.resolve(process.cwd(), inputs.destination); | ||
inputs.destination = path.resolve(inputs.destination); | ||
@@ -53,23 +56,21 @@ // Only override an existing file if `inputs.force` is true | ||
if (exists && !inputs.force) { | ||
return (exits.alreadyExists||exits.error)('Something else already exists at ::' + inputs.destination); | ||
return exits.alreadyExists(); | ||
} | ||
// Don't actually write the file if this is a dry run. | ||
if (inputs.dry) return exits.success(); | ||
async.series([ | ||
function deleteExistingFileIfNecessary(next) { | ||
if (!exists) return next(); | ||
return fsx.remove(inputs.destination, next); | ||
}, | ||
function writeToDisk(next) { | ||
fsx.mkdirs(inputs.destination, next); | ||
// Delete existing files and/or directories if necessary. | ||
(function _deleteExistingFilesAndOrDirsIfNecessary(next) { | ||
if (!exists) { | ||
return next(); | ||
} | ||
], function (err){ | ||
if (err) return exits.error(err); | ||
return exits.success(); | ||
}); | ||
else { | ||
fsx.remove(inputs.destination, next); | ||
} | ||
})(function nowWriteFileToDisk(err){ | ||
if (err) { return exits(err); } | ||
}); | ||
// Now create the directory on disk. | ||
fsx.mkdirs(inputs.destination, next); | ||
});//</after deleting existing file(s)/dir(s) if necessary> | ||
});//</fsx.exists()> | ||
} | ||
@@ -76,0 +77,0 @@ |
@@ -27,2 +27,6 @@ module.exports = { | ||
success: { | ||
description: 'Contents at source path were moved successfully to the destination.' | ||
}, | ||
doesNotExist: { | ||
@@ -36,4 +40,9 @@ description: 'No file or folder exists at the provided souce path.' | ||
fn: function(inputs, exits) { | ||
var path = require('path'); | ||
var fsx = require('fs-extra'); | ||
// Ensure absolute paths. | ||
inputs.source = path.resolve(inputs.source); | ||
inputs.destination = path.resolve(inputs.destination); | ||
fsx.move(inputs.source, inputs.destination, function (err) { | ||
@@ -40,0 +49,0 @@ if (err) { |
@@ -30,3 +30,4 @@ module.exports = { | ||
defaultsTo: '*', | ||
constant: true | ||
constant: true, | ||
isExemplar: true | ||
} | ||
@@ -33,0 +34,0 @@ |
@@ -80,3 +80,11 @@ module.exports = { | ||
file__.once('error', function (err) { | ||
if (alreadyExited) return; | ||
// When receiving subsequent read errors on this Readable stream after | ||
// the first (or after we've exited successfully), the best we can do | ||
// is remain silent. | ||
if (alreadyExited) { | ||
// Note that in the future, we could expose an optional input | ||
// (e.g. `onUnexpectedError`) which accepts a notifier function that | ||
// could be called in this scenario. | ||
return; | ||
} | ||
@@ -101,3 +109,5 @@ if (err.code === 'ENOENT') { | ||
// SO answer at http://stackoverflow.com/a/24471971/486547 for more details & analysis. | ||
require('fs').fstat(fd, function (err, stats) { | ||
fs.fstat(fd, function (err, stats) { | ||
if (alreadyExited) {return;} | ||
if (err) { | ||
@@ -104,0 +114,0 @@ alreadyExited = true; |
@@ -18,5 +18,5 @@ module.exports = { | ||
dir: { | ||
path: { | ||
example: '/Users/mikermcneil/.tmp/foo', | ||
description: 'The absolute path to the file or directory to remove', | ||
description: 'The absolute path to the file or directory to remove.', | ||
required: true | ||
@@ -30,2 +30,5 @@ } | ||
success: { | ||
description: 'The specified file or directory was removed.' | ||
} | ||
@@ -35,6 +38,9 @@ }, | ||
fn: function (inputs, exits) { | ||
var path = require('path'); | ||
var fsx = require('fs-extra'); | ||
fsx.remove(inputs.dir, function(err) { | ||
// Ensure absolute path. | ||
inputs.path = path.resolve(inputs.path); | ||
fsx.remove(inputs.path, function(err) { | ||
if (err) {return exits.error(err);} | ||
@@ -41,0 +47,0 @@ return exits.success(); |
@@ -34,3 +34,4 @@ module.exports = { | ||
extendedDescription: 'Each key will be a variable accessible in the template. For instance, if you supply an array `[{name:"Chandra"}, {name:"Mary"}]` as the key "friends", then you will be able to access `friends` from the template; i.e. `<ul><% _.each(friends, function (friend){ %><li><%= friend.name %></li> <%}); %></ul>` Use `<%= %>` to inject the contents of a variable as-is, `<%- %>` to HTML-escape them first, or `<% %>` to execute some JavaScript code.', | ||
example: {} | ||
example: '===', | ||
readOnly: true | ||
// e.g. { | ||
@@ -96,5 +97,5 @@ // email: { | ||
doesNotExist: exits.noTemplate, | ||
success: function (contents) { | ||
success: function (templateStr) { | ||
MPStrings.template({ | ||
templateStr: contents, | ||
templateStr: templateStr, | ||
data: inputs.data | ||
@@ -105,6 +106,6 @@ }).exec({ | ||
couldNotRender: exits.couldNotRender, | ||
success: function (rendered) { | ||
success: function (renderedStr) { | ||
thisPack.write({ | ||
destination: inputs.destination, | ||
string: rendered, | ||
string: renderedStr, | ||
force: inputs.force | ||
@@ -111,0 +112,0 @@ }).exec({ |
@@ -26,3 +26,3 @@ module.exports = { | ||
example: '/Users/mikermcneil/.tmp/bar.json', | ||
description: 'Absolute path to the destination file (if relative path is provided, will resolve path from current working directory)', | ||
description: 'Absolute path for the destination file (if relative path is provided, will resolve path from current working directory)', | ||
required: true | ||
@@ -32,3 +32,3 @@ }, | ||
force: { | ||
description: 'Overwrite existing file(s)?', | ||
description: 'Overwrite files or directories which might exist at or within the specified destination path?', | ||
example: false, | ||
@@ -43,2 +43,6 @@ defaultsTo: false | ||
success: { | ||
description: 'JSON file written successfully.' | ||
}, | ||
alreadyExists: { | ||
@@ -48,6 +52,2 @@ description: 'A file or folder already exists at the specified destination' | ||
success: { | ||
description: 'JSON file written successfully.' | ||
} | ||
}, | ||
@@ -57,11 +57,9 @@ | ||
fn: function (inputs, exits) { | ||
var path = require('path'); | ||
var fsx = require('fs-extra'); | ||
var _ = require('lodash'); | ||
var async = require('async'); | ||
// In case we ended up here w/ a relative path, | ||
// resolve it using the process's CWD | ||
inputs.destination = path.resolve(process.cwd(), inputs.destination); | ||
inputs.destination = path.resolve(inputs.destination); | ||
@@ -71,19 +69,21 @@ // Only override an existing file if `inputs.force` is true | ||
if (exists && !inputs.force) { | ||
return exits.alreadyExists('Something else already exists at ::' + inputs.destination); | ||
return exits.alreadyExists(); | ||
} | ||
async.series([ | ||
function deleteExistingFileIfNecessary(next) { | ||
if (!exists) return next(); | ||
return fsx.remove(inputs.destination, next); | ||
}, | ||
function writeToDisk(next) { | ||
fsx.outputJson(inputs.destination, inputs.json, next); | ||
// Delete existing files and/or directories if necessary. | ||
(function _deleteExistingFilesAndOrDirsIfNecessary(next) { | ||
if (!exists) { | ||
return next(); | ||
} | ||
], function (err){ | ||
if (err) return exits.error(err); | ||
return exits.success(); | ||
}); | ||
else { | ||
fsx.remove(inputs.destination, next); | ||
} | ||
})(function nowWriteFileToDisk(err){ | ||
if (err) { return exits(err); } | ||
}); | ||
// Now write the JSON file to disk. | ||
fsx.outputJson(inputs.destination, inputs.json, exits); | ||
});//</after deleting existing file(s)/dir(s) if necessary> | ||
});//</fsx.exists()> | ||
} | ||
@@ -90,0 +90,0 @@ |
@@ -24,2 +24,3 @@ module.exports = { | ||
example: 'lots of words, utf8 things you know', | ||
defaultsTo: '' | ||
}, | ||
@@ -44,2 +45,6 @@ | ||
success: { | ||
description: 'File written successfully.' | ||
}, | ||
alreadyExists: { | ||
@@ -49,6 +54,2 @@ description: 'Something already exists at the specified path (overwrite by enabling the `force` input)' | ||
success: { | ||
description: 'File written successfully.' | ||
} | ||
}, | ||
@@ -62,5 +63,2 @@ | ||
// Coerce `string` input into an actual string | ||
inputs.string = inputs.string || ''; | ||
// In case we ended up here w/ a relative path, | ||
@@ -67,0 +65,0 @@ // resolve it using the process's CWD |
@@ -18,2 +18,3 @@ module.exports = { | ||
example: 'lots of words, utf8 things you know', | ||
defaultsTo: '' | ||
}, | ||
@@ -28,3 +29,3 @@ | ||
force: { | ||
description: 'Whether to overwrite existing file(s) which might exist at the destination path.', | ||
description: 'Overwrite files or directories which might exist at or within the specified destination path?', | ||
example: false, | ||
@@ -39,2 +40,6 @@ defaultsTo: false | ||
success: { | ||
description: 'File written successfully.' | ||
}, | ||
alreadyExists: { | ||
@@ -44,6 +49,2 @@ description: 'Something already exists at the specified path (overwrite by enabling the `force` input)' | ||
success: { | ||
description: 'Filewritten successfully.' | ||
} | ||
}, | ||
@@ -53,10 +54,5 @@ | ||
fn: function (inputs, exits) { | ||
var path = require('path'); | ||
var fsx = require('fs-extra'); | ||
var _ = require('lodash'); | ||
var async = require('async'); | ||
// Coerce `string` input into an actual string | ||
inputs.string = inputs.string || ''; | ||
@@ -70,20 +66,21 @@ // In case we ended up here w/ a relative path, | ||
if (exists && !inputs.force) { | ||
return (exits.alreadyExists||exits.error)('Something else already exists at ::' + inputs.destination); | ||
return exits.alreadyExists(); | ||
} | ||
async.series([ | ||
function deleteExistingFileIfNecessary(exits) { | ||
if (!exists) return exits(); | ||
return fsx.remove(inputs.destination, exits); | ||
}, | ||
function writeToDisk(exits) { | ||
fsx.outputFile(inputs.destination, inputs.string, exits); | ||
// Delete existing files and/or directories if necessary. | ||
(function _deleteExistingFilesAndOrDirsIfNecessary(next) { | ||
if (!exists) { | ||
return next(); | ||
} | ||
], function (err){ | ||
if (err) return exits(err); | ||
return exits(); | ||
}); | ||
else { | ||
fsx.remove(inputs.destination, next); | ||
} | ||
})(function nowWriteFileToDisk(err){ | ||
if (err) { return exits(err); } | ||
}); | ||
// Now write the file to disk. | ||
fsx.outputFile(inputs.destination, inputs.string, exits); | ||
});//</after deleting existing file(s)/dir(s) if necessary> | ||
});//</fsx.exists()> | ||
} | ||
@@ -90,0 +87,0 @@ |
{ | ||
"name": "machinepack-fs", | ||
"version": "7.0.0", | ||
"version": "8.0.0", | ||
"description": "Work with the local filesystem; list files, write files, etc.", | ||
@@ -15,2 +15,11 @@ "scripts": { | ||
"license": "MIT", | ||
"dependencies": { | ||
"fs-extra": "0.26.5", | ||
"machine": "~12.1.0", | ||
"machinepack-json": "~2.0.0", | ||
"machinepack-strings": "~5.0.0", | ||
"machinepack-util": "^6.0.0", | ||
"rttc": "~9.3.0", | ||
"walker": "1.0.7" | ||
}, | ||
"devDependencies": { | ||
@@ -20,13 +29,2 @@ "mocha": "~1.19.0", | ||
}, | ||
"dependencies": { | ||
"async": "^0.9.0", | ||
"fs-extra": "~0.10.0", | ||
"lodash": "^2.4.1", | ||
"machine": "^11.0.3", | ||
"machinepack-json": "^1.0.0", | ||
"machinepack-strings": "^3.1.0", | ||
"machinepack-util": "^0.7.0", | ||
"rttc": "^9.3.0", | ||
"walker": "~1.0.6" | ||
}, | ||
"repository": { | ||
@@ -55,3 +53,4 @@ "type": "git", | ||
"read-sync", | ||
"read-stream" | ||
"read-stream", | ||
"write-stream" | ||
], | ||
@@ -58,0 +57,0 @@ "testsUrl": "https://travis-ci.org/mikermcneil/machinepack-fs" |
@@ -14,3 +14,3 @@ <h1> | ||
```sh | ||
$ npm install machinepack-fs | ||
$ npm install machinepack-fs --save --save-exact | ||
``` | ||
@@ -30,3 +30,3 @@ | ||
MIT © 2015 Mike McNeil and contributors | ||
MIT © 2015-2016 Mike McNeil and contributors | ||
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
41838
7
22
1025
+ Addedacorn@7.4.1(transitive)
+ Addedbrowserify-transform-machinepack@1.0.4(transitive)
+ Addedbrowserify-transform-tools@1.7.0(transitive)
+ Addedconvert-to-ecmascript-compatible-varname@0.1.4(transitive)
+ Addeddebug@2.2.03.1.0(transitive)
+ Addedfalafel@2.2.5(transitive)
+ Addedfs-extra@0.26.5(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedjsonfile@2.4.0(transitive)
+ Addedklaw@1.3.1(transitive)
+ Addedlodash@3.8.0(transitive)
+ Addedlodash.iserror@3.1.1(transitive)
+ Addedlodash.isfunction@3.0.8(transitive)
+ Addedlodash.isobject@3.0.2(transitive)
+ Addedlodash.isregexp@3.0.5(transitive)
+ Addedmachine@12.1.112.4.0(transitive)
+ Addedmachinepack-json@2.0.1(transitive)
+ Addedmachinepack-strings@5.0.0(transitive)
+ Addedmachinepack-util@6.1.2(transitive)
+ Addedms@0.7.1(transitive)
+ Addedobject-hash@0.5.0(transitive)
+ Addedrttc@9.3.4(transitive)
+ Addedswitchback@2.0.0(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedwalker@1.0.7(transitive)
- Removedasync@^0.9.0
- Removedlodash@^2.4.1
- Removedasync@0.9.2(transitive)
- Removedconvert-to-ecmascript-compatible-varname@0.1.5(transitive)
- Removeddebug@2.6.9(transitive)
- Removedfs-extra@0.10.0(transitive)
- Removedjsonfile@1.2.0(transitive)
- Removedmachine@11.0.32.0.64.1.1(transitive)
- Removedmachinepack-json@1.2.1(transitive)
- Removedmachinepack-strings@3.1.1(transitive)
- Removedmachinepack-util@0.7.24(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedncp@0.5.1(transitive)
- Removedrttc@1.0.28.1.7(transitive)
- Removedswitchback@1.1.32.0.5(transitive)
- Removedwalker@1.0.8(transitive)
Updatedfs-extra@0.26.5
Updatedmachine@~12.1.0
Updatedmachinepack-json@~2.0.0
Updatedmachinepack-strings@~5.0.0
Updatedmachinepack-util@^6.0.0
Updatedrttc@~9.3.0
Updatedwalker@1.0.7