added logic to add script files to index

Although it works but i need to update how it works via a better mechanism or flow.