If one of goals of The Console project is to make easy custom scripting then it’s logical that you need some way to manage your scripts. Putting all scripts in one file or even all scripts in one folder would be a mess. So, how to manage those files? How The Console deals with it?
So… a few questions have shown up.
1. How to track scripts?
Loading algorithm is quite straightforward:
- load file and remember it’s location
- watch for changes
Standard Java API makes it able to watch (monitor) folders for changes thanks to java.nio.file.WatchService. However, it doesn’t work for folder tree. That’s why I used custom modification of Philipp C. Heckel’s RecursiveWatcher.
As for changes, I’m only (currently) interested in script modification. I just want to reload it’s content. Although being able to freely move it between subfolders is useful (and works) I haven’t completely decided on edge case behaviour when file is moved into another folder because there’s a dilemma around it – what if other script is named alike? How to track scripts?
2. How to modify script?
Possible options are:
- built-in editor
- some built-in REPL CLI to manage scripts
- just a button or a quick command to open %APPDATA%\TheConsole\scripts folder (in File Explorer) and let user modify files using however he likes
Here’s how it goes:
- CLI is not hard to be made but I’d rather think of API to create custom CLI-s, e.g. for math just like you would use Octave in CLI. Having that, it would be actually quite simple to create CLI for script management. But that’s a topic for another post.
- little button on the top of window to open a folder will fit. Sublime Text, Notepad++ or Notepad? Edit your scritps as you want.
3. How to group scripts?
Group by folders, of course! But here comes very great dilemma!
Some scripts are about file computation (like calculating md5 of file), some take text/number arguments but other are very custom:
- Custom scripts to open websites? OK! Create websites folder and put those in there!
- Custom scripts to calculate something? OK! Create calc folder!
- Custom scripts to process text? No problem! Create text folder.
- whatever else to do whatever else? Sure! Create whatever folder!
Or encapsulate even more (in subfolders), I don’t care!
* So where’s the dilemma, you ask? Currently, I have some core scripts e.g. core/data/md5file.js , core/filesystem/cd.js , core/filesystem/pwd.js or core/filesystem/ls.js. For me these are core. For others my core scripts could be candidates for deletion.
(note: this dilemma will strike back within future post that will cover Script Sharing)
4. Finally, how to share script?
“Sharing is caring”, they say but it’s also about increasing usefulness of effort. Simply copying script files is easy but not efficient. Real sharing here is supposed to be about putting your work into some greater online library that more people have access to. Of course, if your heart is open sourced.
That’s why I have to design online library and I’m going to cover it in a future post.