UNPKG

laniakea

Version:

A renaming utility for classic ROMs

121 lines (94 loc) 3.26 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: utils.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: utils.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>const fs = require('fs'); const path = require('path'); const helpers = require('./helpers'); const glob = require('glob'); module.exports = { /** * Properly renames file and moves it to desired destination * @param {object} args * @param {string} args.sourceLocation - The location of the file to be moved * @param {boolean} args.sortIntoFolders - Whether you want sorted files namespaced into folders * @param {string} args.outputDestination - The directory where the saved file should go * @return {string} - The path that the ROM was moved to */ moveFile(args) { let konsole = helpers.getConsoleByExtension(args.sourceLocation); let game = helpers.getGameByFilepath(args.sourceLocation); let fileInfo = helpers.getFileInfo(args.sourceLocation); let dryrun = args.dryrun; if (args.sortIntoFolders) { newPath = path.join( args.outputDestination, konsole.folderName, `${game.title}.${fileInfo.extension}` ); } else { newPath = path.join( args.outputDestination, `${game.title}.${fileInfo.extension}` ); } if (!dryrun) { try { if (!fs.existsSync(path.dirname(newPath))) { fs.mkdirSync(path.dirname(newPath)); } fs.renameSync(args.sourceLocation, newPath); } catch (e) { throw new Error(`There was a generic error when moving the ROM. Error: ${e}`); } } return newPath; }, /** * Renames an individual file based on installed dictionaries * @param {string} sourceDirectory - The directory to be searched. Should be a fullpath. * @param {boolean} recursive - Whether subdirectories should be searched * @return {array} - A list of all files that have extenstions specified in the console dictionary */ listFiles(sourceDirectory, recursive = false) { let extensionList = helpers.getValidExtensions().join(); let globPattern; if (recursive) { globPattern = `${sourceDirectory}/**/*.{${extensionList}}`; } else { globPattern = `${sourceDirectory}/*.{${extensionList}}`; } return glob.sync(globPattern, { nocase: true }); } }; </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:36 GMT-0800 (PST) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>