laniakea
Version:
A renaming utility for classic ROMs
139 lines (111 loc) • 4.15 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: laniakea.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: laniakea.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const helpers = require('./library/helpers');
const utils = require('./library/utils');
const fs = require('fs');
module.exports = class Laniakea {
/**
* Renames an individual file based on installed dictionaries
* @param {string} sourceLocation - Where the file to be renamed is located. Should be a fullpath.
* @param {string} outputDirectory - Where you want the renamed files to be saved. Should be a fullpath.
* @param {object} options - A configuration object
* @param {boolean} options.sortIntoFolders - Whether to namespace into folders named after the console
* @param {boolean} options.dryrun - Whether to preform a dryrun without moving files
* @return {object} - An object containing the source and destination strings
*/
renameFile(sourceLocation, outputDirectory, options) {
let defaults = {
dryrun: false,
sortIntoFolders: false
};
let opts = Object.assign(defaults, options);
if (!fs.existsSync(sourceLocation)) {
throw new Error(`File: ${sourceLocation} not found`);
}
let result = utils.moveFile({
sourceLocation: sourceLocation,
sortIntoFolders: opts.sortIntoFolders,
outputDestination: outputDirectory,
dryrun: opts.dryrun
});
console.log(`${sourceLocation} -> ${result}`);
return {
source: sourceLocation,
destination: result
};
}
/**
* Renames an individual file based on installed dictionaries
* @param {string} sourceDirectory - Where the directory with files to be renamed is located. Should be a fullpath.
* @param {string} outputDirectory - Where you want the renamed files to be saved. Should be a fullpath.
* @param {object} options - A configuration object
* @param {boolean} options.sortIntoFolders - Whether to namespace into folders named after the console
* @param {boolean} options.recursive - Whether to recursively search directories
* @param {boolean} options.dryrun - Whether to preform a dryrun without moving files
* @return {array} - An array containing a list of source and dest ojects as well as any errors
*/
renameDirectory(sourceDirectory, outputDirectory,options) {
if (!fs.existsSync(sourceDirectory)) {
throw new Error(`Directory: ${sourceDirectory} not found`);
}
let defaults = {
recursive: false,
dryrun: false,
sortIntoFolders: false
};
let opts = Object.assign(defaults, options);
let fileList = utils.listFiles(sourceDirectory, outputDirectory,opts.recursive);
let destinationList = [];
let errorList = [];
fileList.forEach((file) => {
try {
let fileDest = this.renameFile(file, {
dryrun: opts.dryrun,
sortIntoFolders: opts.sortIntoFolders
});
destinationList.push(fileDest);
} catch (e) {
errorList.push({
file: file,
message: e.message
});
console.log(`Error processing ${file}: ${e.message}`);
}
});
return {
files: destinationList,
errors: errorList
};
}
};
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Tue Feb 28 2017 19:33:28 GMT-0800 (PST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>