machinepack-fs
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -7,3 +7,3 @@ module.exports = { | ||
description: 'Ensures that the directory exists. If the directory structure does not exist, it is created.', | ||
description: 'Ensure that the directory exists. If the directory structure does not exist, it is created.', | ||
@@ -10,0 +10,0 @@ |
@@ -6,2 +6,3 @@ module.exports = { | ||
cacheable: true, | ||
idempotent: true, | ||
@@ -8,0 +9,0 @@ inputs: { |
module.exports = { | ||
friendlyName: 'Read file', | ||
description: 'Read file located at source path on disk into a string.', | ||
extendedDescription: 'Assumes file is encoded using utf8.', | ||
description: 'Read a file on disk as a string.', | ||
extendedDescription: 'Assumes file contents are encoded using utf8.', | ||
cacheable: true, | ||
idempotent: true, | ||
inputs: { | ||
source: { | ||
@@ -13,12 +26,12 @@ description: 'Absolute path to the source file (if relative path is provided, will resolve path from current working directory)', | ||
} | ||
}, | ||
defaultExit: 'success', | ||
catchallExit: 'error', | ||
exits: { | ||
error: {}, | ||
doesNotExist: { | ||
description: 'No file exists at the provided `source` path' | ||
}, | ||
success: { | ||
@@ -28,4 +41,6 @@ example: 'stuff in a file!', | ||
} | ||
}, | ||
fn: function (inputs, exits) { | ||
@@ -36,12 +51,14 @@ | ||
fs.readFile(inputs.source, 'utf8', function (err, contents) { | ||
if (err) { | ||
if (typeof err === 'object' && err.code === 'ENOENT') { | ||
return exits.doesNotExist(); | ||
} | ||
// Some unrecognized error | ||
return exits.error(err); | ||
// It worked! | ||
if (!err) { | ||
return exits.success(contents); | ||
} | ||
return exits.success(contents); | ||
// No need for `null` check here because we already know `err` is falsy | ||
if (typeof err === 'object' && err.code === 'ENOENT') { | ||
return exits.doesNotExist(); | ||
} | ||
// Some unrecognized error | ||
return exits.error(err); | ||
}); | ||
} | ||
}; |
{ | ||
"name": "machinepack-fs", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "Work with the local filesystem; list files, write files, etc.", | ||
@@ -47,3 +47,4 @@ "scripts": { | ||
"ensure-dir", | ||
"get-home-dirpath" | ||
"get-home-dirpath", | ||
"ensure-json" | ||
], | ||
@@ -50,0 +51,0 @@ "testsUrl": "https://travis-ci.org/mikermcneil/machinepack-fs" |
26710
19
713