const fs = require('fs');
const path = require('path');

function getFileContents(filePath) {
  return fs.readFileSync(filePath, { encoding: 'utf-8' });
}

// Allows you to use short words for Roblox Script classes.
//
// This allows us to use short words to represent Roblox's Script classes. These
// words are commonly used in filenames to identify which file should be created
// as which class in-game.
function getScriptClassFromWord(word) {
  if (word === 'module') {
    return 'ModuleScript';
  } else if (word === 'local') {
    return 'LocalScript';
  } else {
    return 'Script';
  }
}

function luaFileToRobloxObject(filePath) {
  const baseName = path.basename(filePath);
  const parts = baseName.split('.');

  return {
    className: getScriptClassFromWord(parts[1]),
    source: getFileContents(filePath)
  };
}

function handleFile(filePath) {
  if (path.extname(filePath) === '.lua') {
    return luaFileToRobloxObject(filePath);
  };
}

function addChildrenToObjectTree(item, parentNode) {
  const children = fs.readdirSync(item);

  for (let child of children) {
    const fullPath = path.join(item, child);
    pathToRobloxObjectTree(fullPath, parentNode);
  };
}

function pathToRobloxObjectTree(item, parentNode=[]) {
  const stats = fs.statSync(item);
  const filename = path.basename(item);
  const nameParts = filename.split('.');

  var object = { name: nameParts[0] };

  if (stats.isDirectory()) {
    Object.assign(object, { children: [] });
    addChildrenToObjectTree(item, object.children);
  } else {
    Object.assign(object, handleFile(item));
  }

  if (object) parentNode.push(object);

  return parentNode;
}

function dirToRobloxObjectTree(dir) {
  const hierarchy = []

  addChildrenToObjectTree(dir, hierarchy)

  return hierarchy
}

module.exports = { dirToRobloxObjectTree }

@@ -149,16 +149,217 @@
  %7D);%0A%7D%0A%0A
+function getBaseNameParts(filePath) %7B%0A  const base = path.basename(filePath);%0A  const parts =  base.split('.');%0A%0A  return %7B%0A    name: parts%5B0%5D,%0A    className: parts%5B1%5D,%0A    extension: parts%5B2%5D%0A  %7D;%0A%7D%0A%0A
 // Allow
@@ -849,32 +849,32 @@
 nst 
-baseName = path.basen
+parts = getBaseN
 ame
+Parts
 (fil
@@ -884,45 +884,8 @@
 th);
-%0A  const parts = baseName.split('.');
 %0A%0A  
@@ -936,19 +936,26 @@
 rd(parts
-%5B1%5D
+.className
 ),%0A    s

Create a function for splitting filename parts