Scripting in AR Studio might be difficult sometimes, having all the code in one file is not ideal, hard for collaboration and quite likely to be messy. Here is a simple guide to have a super simple web-like JavaScript build that allows you to have the all files and the structure you want.
Get the sample project from this page (Mug.zip), unzip it and go to the Mug Finished Effect
folder. Or, use your own project.