How to download (export) an apps script add-on project? - google-apps-script

How will I download an apps-script Google Docs add-on project, which was opened from Tools > Script editor of Google Docs.
File > make a copy of the project do not seem to be any use. since it makes online copy itself. Any alternative ways to achieve?

Google launched clasp last year, an official tool to import and export apps scripts projects. It works great!

You should not develop you add-on directly in a document (I made this mistake too). Instead you need to have an independant script that you bound to a document with the options to test it as an addon (this way).
Doing so you'll have the capacity to export (and import) your script with the Google Drive rest api.To my knowledge there is two tools that you can use:
gapps writen in node
python-gas-cli, a python tool (never tested it)
You should also have a look at this post that explain quite well how it work

Related

Is there branching functionality on a Google Apps Script Project?

I am new to Google Apps Script projects, and have a Google Calendar add-on that I have been working on. My users recently came across some bugs, and I realized that I had no idea how to go back to the version they were on, and save the current updates I was working on at the same time, like a github branch.
I did some research and couldn't find anything out online, so just want to know if there are any other alternatives other than pulling down all code locally and uploading it to my personal GitHub.
To make your add-on go back to a previous version, just go to the Google Workspace Marketplace SDK and set the version number that you want to make available for your add-on users.
The Google Apps Script web editor it will always be showing the head deployment. You might use Google Apps Script API / CLASP to get access to any version. If you want to use the web editor, you should overwrite the files of with the version that you want to use.

Using external Web IDE in Google Appscript

I am creating an app for my company.
The thing is, I work on a governmental company and have several restrictions. I can use the google services including apps scripts and cloud services (the free services only) but ideally I can't install any IDE locally so I a web IDE would be the ideal solution.
But I am having a hard time to understand how can I export/import my scripts, I mean, I can't even find them on drive (I can find my project and that's it).
Some web based IDE's can be authorized, and some other will be blocked, this one: https://shiftedit.net/ seems to work.
I am just not understanding it?
Google Apps Script project files (.gs and .html) are not files that can be found in the Google Drive user interface. To export / download these files you could use Google Apps Script API, CLASP, Google Apps Script GitHub Assistant Chrome extension.
P.S. I just found https://github.com/dev-container/gas but have not tried yet... it' for working on Google Apps Script projects with VS Code and GitPod containers.
Related
How best to develop Google Sheets scripts and Git versioning
Is it possible to upload a .gs file to an apps script project of a copied google doc?

Is it possible to upload a .gs file to an apps script project of a copied google doc?

I copied a spreadsheet to be used by multiple people with script attached. My question is how do I modify script in the project without having to copy and paste each change to .gs files in the project?
This is the base document from which the other versions were copied:
Create a central script and then publish it as a library. Have your template linked to the library. Make sure that the template is using the "dev" version of the library so that any future changes will be reflected for everyone.
There ARE ways to manipulate the GS files using clasp but it is much less straightforward than using libraries and overkill for this use case.
https://developers.google.com/apps-script/guides/libraries
Yes, it's possible to "upload" a .gs file to an existing Google Apps Script project. To do this you might use CLASP, GAS GitHub Assistant (a Chrome extension) or directly the Google Apps Script API.
Please bear in mind that you also could alleviate these pains (having to update the bounded to spreadsheet GAS project copies) by taking a different approach. You could use libraries or to create a Workspace Editor add-on.
Libraries help by keeping a big part of your code in a single place but you might still have to update the copies i.e. if you are using simple triggers like onOpen and onEdit or if you change library function name, add a new function, etc.
Add-ons help by keeping all the code in a single place bu you have to publish the add-on to the Google Workspace Marketplace. If you have a Google Workspace account the add-on can be published for internal use.

Anyway to Execute Google App Script Code Hosted on GHE

I'm trying to find a way to run Google App Script code that's hosted on GHE. I found somewhere that you could get the script as a text string and use eval() to execute it as code, however I've read that it's a very unsecure way to do it and it shouldn't be done. Does anyone know any alternatives ways to run hosted code on Google App Script?
You could:
use this extension: https://chrome.google.com/webstore/detail/google-apps-script-github/lfjcgcmkmjjlieihflfhjopckgpelofo
use git and clasp CLI to push your code to your apps script project
From your specifications, I understand that you want to both host the script in GitHub Enterprise (GHE) and run it from there.
Even though Apps Script API offers a good range of functionalities such as executing functions from your App remotely it is not the best option for this scenario.
With clasp you can also write Apps Script functions remotely but eventually they have to be pushed to an Apps Script project.
So, after considering these limitations I think the best option you would have is to use the right Google API in your script (such as Gmail API for example). Its functional code can all be hosted and run from your application without the need of Apps Script projects and these APIs offer the same and extended functionalities than those offered by Apps Script.

Does Google Apps Script support external IDEs?

I am using Google Apps Script and was wondering if I could use any sort of editor outside of the one Google provides. (I purchased Sublime Text and would like to use that.)
The one Google provides is disgusting, with tiny text even though I have a giant screen and syntax colors that I find a bit difficult to distinguish on a white background with small text, and I don't have the beauties of Sublime like tons of custom keyboard shortcuts, all of my packages, etc.
As of today (May 2018), every scripts that you add on Google App Scripts (including scripts on Google Drive like spreadsheets) will get accessible through https://script.google.com and will have a specific id that you can get through the url by opening it.
By using clasp which handle a project (like git), you can do:
clasp clone {id}
to have your script in a local folder.
Then, after editing your file with your favorite text editor, upload it back with :
clasp push
Google has dropped support for Apps Script inside Eclipse but you can set up a local development environment inside VS Code using the Apps Script Starter kit and CLASP.
Here's a video tutorial to help you get started.
The eclipse plug-in is migrated now. You should install many
files. lastly it couldn't import my google script files.
nod-google-apps-script is depercated.
gdrive can't handle google scripts beyond exporting the project in single json file. issue issue
sublime-editor-plug-in has n't worked for me (I read the whole documents & issues)
The only working solution for me (ubuntu xenial) is clasp.
According to doc it can :
Develop Locally: clasp allows you to develop your Apps Script projects locally. That means you can check-in your code into source control, collaborate with other developers, and use your favorite tools to develop Apps Script.
Manage Deployment Versions: Create, update, and view your multiple deployments of your project.
Structure Code: clasp automatically converts your flat project on script.google.com into folders. For example:
On script.google.com:
tests/slides.gs
tests/sheets.gs
locally:
tests/
slides.js
sheets.js
N.B:. The fature of 'Manage Deployment Versions' isn't supported by eclipse plug in.
It give the following commands:
clasp login [--no-localhost]
clasp logout
clasp create [scriptTitle] [scriptParentId]
clasp clone <scriptId>
clasp pull
clasp push
clasp open
clasp deployments
clasp deploy [version] [description]
clasp redeploy <deploymentId> <version> <description>
clasp version [description]
clasp versions
By using it; you can use your favorite script editor; then push the changes.
Edit
GAS Editor Autocomplete
Thanks to #tehhowch comment.
Auto complete of google objects is almost exclusive for online GAS editor, If you use any external editor , you will only get auto complete for the functions & variables of your own script (I am not sure about eclipse).
But online editor provides autocomplete which reveals the global objects as well as methods and enums that are valid in the script's current context.
To show autocomplete suggestions, select the menu item Edit > Content assist or press Ctrl+Space. Autocomplete suggestions also appear automatically whenever you type a period after a global object, enum, or method call that returns an Apps Script class. For example:
If you click on a blank line in the script editor and activate autocomplete, you will see a list of the global objects.
If you type the full name of a global object or select one from autocomplete, then type . (a period), you will see all methods and enums for that class.
If you type a few characters and activate autocomplete, you will see all valid suggestions that begin with those characters.
You can use node-google-apps-script to edit scripts locally (described in this blog post from the google apps developer blog on 2015-12-17). This way you can use a more comfortable editor, version control and build scripts.
Caveats:
Like the eclipse plugin, node-google-apps-script requires that your add-on is a standalone script.
Debugging still requires google's script editor. With some additional setup you could run functions via the Execution API
It would be awesome if there was a Sublime Text plugin for code completion of google library methods, but I haven't found one (I don't think their default browser editor even offers this, though)
This is an answer for basic/beginner users of Intellij that are looking for code completion when writing Google App Scripts apps. Most of the answers above were helpful for getting me going, especially with Clasp. But none of them actually got Intellij to do the code complete. But this does:
Select File, Settings, Languages & Frameworks, JavaScript, Libraries.
Then on the right select Download, the scroll down to 'google-app-scripts'. (Lots of scrolling) Download and install and you're done. Almost so easy that it really shouldn't have been so hard to find.
Another option to contemplate: using "AppsScript Color" Google Chrome plugin and GAS editor shortcuts.
Here you have a list of most useful shortcuts:
https://opensourceseo.org/useful-tips-for-using-the-google-apps-script-editor/
You can just install a Google Drive command line client (e.g. https://github.com/prasmussen/gdrive) and edit .gs scripts directly.
There's also a way to edit Google Apps Scripts in Eclipse, which may be interesting. https://developers.google.com/eclipse/docs/apps_script