Seek tutorial on hosting code on Github

77 views
Skip to first unread message

Bruce Axtens

unread,
Jun 1, 2022, 6:25:52 AM6/1/22
to Google Apps Script Community
I discovered today GasTap https://github.com/huan/gast which is TAP testing frame for Google Apps Script. Interestingly, the author makes it available, not as a library with a Id string, but as a link to a github file with the code evaluated inline as follows:

if ((typeof GasTap)==='undefined') { 
 eval(UrlFetchApp.fetch('https://raw.githubusercontent.com/huan/gast/master/src/gas-tap-lib.js').getContentText()) 
}

Is this still something that works and if so, is there somewhere where the process is discussed and the various ways of setting it up are described?

-- Bruce
Message has been deleted
Message has been deleted

dimud...@gmail.com

unread,
Jun 1, 2022, 8:33:25 AM6/1/22
to Google Apps Script Community
The `eval()` function is deprecated (and with good reason; see Never use eval()). So its best to avoid any code that relies on it.

MDN recommends using Function instead.

Bruce Axtens

unread,
Jun 1, 2022, 10:15:19 AM6/1/22
to google-apps-sc...@googlegroups.com

> The `eval()` function is deprecated (and with good reason; see Never use eval()). So its best to avoid any code that relies on it.

> But you have other options to choose from.

Yes, I know about the plethora of testing frameworks. I wasn’t asking about testing frameworks. I used that as an example of the technique of storing code on github and including it in a project. Is it now the case that everything needs to be in a Library and there’s no other technique available?

 

Related to that, can you use a Library in a Library? I suppose I should `clasp new standalone` and see.

 

--- Bruce

Clark Lind

unread,
Jun 2, 2022, 12:03:23 PM6/2/22
to Google Apps Script Community
This video has a small portion about hosting a css file on github. You can skip the first 13 minutes which talks about modifying Bootstrap with your own css file.

Jonathan Butler

unread,
Jun 2, 2022, 2:16:17 PM6/2/22
to google-apps-sc...@googlegroups.com
While I do agree eval should be used sparingly because of safety concerns, I think if you know the code you are evaluating beforehand it's alright. What I would warn you about this approach are permission concerns. If a user adds a library to a script, Google will check for keywords used and automatically add those permissions to the .json config file. However, the same can't be said for code evaluated at runtime. 

Libraries also help with potential naming conflicts. If the library you are loading has var var1 = "something" and you have var var1 = "other thing" the variable at runtime will change to whatever was declared last. This can be with local or global variables. However, libraries wrap all of their data in another object, so we type library.somefunction(). 

To host your files on Github I would recommend downloading the Github Assistant Chrome Extension. Once you push your files to a repo you can click on the file and get the raw link on the middle right of the page. (Seen in the bottom right of the photo).
Then eval it the same way gas tap did.

image.png

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/6107f982-f6e2-4676-a40f-fa13aed27ae3n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages