Switch scripting .sscript inflating pre-commit hook

Post Reply
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Switch scripting .sscript inflating pre-commit hook

Post by gabrielp »

For anyone else finding it annoying that .sscript files are compressed and don't work well with version control applications (like Git), you might be manually unzipping your .sscript files and including them in your repositories.

An example of this would be: https://github.com/dominickp/SwitchAWS. You can see I have a Packed and Unpacked directory and if you browse through the commit history in an Unpacked file (https://github.com/dominickp/SwitchAWS/ ... ownload.js) you can see line by line changes, which is nice.

I've made a simple Git pre-commit "hook" which, once set up, will automatically scan through any .sscript files in your repo and unpack them whenever you make a new commit. It's pretty handy and can be found here: https://gist.github.com/dominickp/97496d6cb8921ddc9d4a
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
dkelly
TOP CONTRIBUTOR
Posts: 628
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Re: Switch scripting .sscript inflating pre-commit hook

Post by dkelly »

nice. Do you have to add and commit again to get the Unpacked in repository?
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: Switch scripting .sscript inflating pre-commit hook

Post by gabrielp »

dkelly wrote:nice. Do you have to add and commit again to get the Unpacked in repository?
Yeah, you do. So you commit once, then immediately do another. Not sure what hook I could use that would prevent needing to do that :?
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
bens
Member
Posts: 130
Joined: Thu Mar 03, 2011 10:13 am

Re: Switch scripting .sscript inflating pre-commit hook

Post by bens »

A little-known fact is that Switch Scripter can actually work with unpacked sscript files. When you unzip an sscript, you get a folder with, among others, another sscript (of 0 bytes) inside it. If you open this second sscript in Switch Scripter you can edit the script as normal, and when you save it will save the unpacked script, perfect for source control! When you are ready to use or test the script in Switch simply use File - Save as..., which will create a packed sscript. Be careful not to overwrite the 0 byte sscript of course.

The normal way of working with sourcecontrol is to regard the packed sscript as output, and not commit it to the repository. In git you can add it to the .gitignore file.
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: Switch scripting .sscript inflating pre-commit hook

Post by gabrielp »

bens wrote:A little-known fact is that Switch Scripter can actually work with unpacked sscript files. When you unzip an sscript, you get a folder with, among others, another sscript (of 0 bytes) inside it. If you open this second sscript in Switch Scripter you can edit the script as normal, and when you save it will save the unpacked script, perfect for source control! When you are ready to use or test the script in Switch simply use File - Save as..., which will create a packed sscript. Be careful not to overwrite the 0 byte sscript of course.

The normal way of working with sourcecontrol is to regard the packed sscript as output, and not commit it to the repository. In git you can add it to the .gitignore file.
That's really good to know. But the one benefit I've found with adding the packed sscript file to your repo is that you can very easily update the production machine to master. I'll make a few updates on my development machine, merge the branch to master, then walk over to my production server and run a git pull on the repo and I'm done. I can now go into each flow and "reload" the script package and I've just updated each script. Keeping the packed file in the repo also makes it easy for people who might not be familiar with SwitchScripter to use your code.
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: Switch scripting .sscript inflating pre-commit hook

Post by gabrielp »

Updated this so it now goes into subdirectories of a project: https://gist.github.com/dominickp/97496d6cb8921ddc9d4a
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: Switch scripting .sscript inflating pre-commit hook

Post by gabrielp »

If you have trouble getting the hook to execute, try running this command from the repository directory:

Code: Select all

chmod +x .git/hooks/pre-commit
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
tz8
Member
Posts: 84
Joined: Mon Aug 13, 2012 12:56 pm

Re: Switch scripting .sscript inflating pre-commit hook

Post by tz8 »

this is by the way amazing! Thank you for doing this!
tz8
Member
Posts: 84
Joined: Mon Aug 13, 2012 12:56 pm

Re: Switch scripting .sscript inflating pre-commit hook

Post by tz8 »

for the record: this stopped working in Switch 13 update 1, the unpacked scripts are now unreadable
User avatar
gabrielp
Advanced member
Posts: 577
Joined: Fri Aug 08, 2014 4:31 pm
Location: Boston
Contact:

Re: Switch scripting .sscript inflating pre-commit hook

Post by gabrielp »

tz8 wrote:for the record: this stopped working in Switch 13 update 1, the unpacked scripts are now unreadable
Yeah. It's a huge annoyance. I've been copying a pasting my source code out into other files with every script revision because of it.
Chat: open-automation @ gitter
Code: open-automation & dominickp @ GitHub
Tools: Switch, Pitstop, EPMS, Veracore, PageDNA, SmartStream, Metrix
tz8
Member
Posts: 84
Joined: Mon Aug 13, 2012 12:56 pm

Re: Switch scripting .sscript inflating pre-commit hook

Post by tz8 »

Solution according to Enfocus is to keep developing in an old SwitchScripter 13 version. They implemented the encryption because of the introduction of the appstore.

I disagree to that solution. Your hacky solution is working but it just stays... hacky. Adding another step to the hackiness of the solution to get Switch scripts into GIT is just messy. Enfocus should implement one of the below:
- 'save as... encrypted script package'
- 'save as... raw code package'
- a flag in the preferences to also save as raw code in a directory next to the script

And i personally prefer Option 3, in our GIT solution we could then just ignore the .sscript and .sficture files and voilà we'd all be happy...
Post Reply