Problems when using CLASP to push client-side files from a local editor

856 views
Skip to first unread message

Faustino Rodriguez

unread,
Jun 11, 2019, 9:19:44 AM6/11/19
to Google Apps Script Community
May question:
+ Is there anyway to make clasp push, to only update client-side files, while leaving server-side files as they are in the GAS project?

Some notes on what I am trying ... (TL;DR)
I just installed CLASP this morning, so I hope my problems/questions are the newbie/trivial kind of

I feel comfortable using the GAS Editor for server side code, but it's a pain for client-side files
- So, I want to keep editing .gs files @GAS, while editing client-side files (.html, ...) in a local code editor (like VS Code)

When reading about the commands clasp push/pull, I thought they might be like GIT, that only deals with file changes
- But, clasp push/pull overwrites everything up and down

Then, I discovered .claspignore, that would ignore some files on a clasp push
- I included *.js (actual .gs in local) in .claspignore
- Then when calling clap push, it just removed all the *.gs from the GAS project

My question again,
+ Is there anyway to make clasp push, to only update client-side files, while leaving server-side files as they are in the GAS project?

Thanks in advance, Fausto

Martin Hawksey

unread,
Jun 12, 2019, 4:52:55 AM6/12/19
to google-apps-sc...@googlegroups.com
Definitely possible. One thing to keep in mind is clasp locally stores .gs files as .js so I don't think  ignoring by extension will work. 

As it probably makes sense to work with a folder structure you could just put all your server files in a folder named gs and ignore it with  **/gs/**

Dimu Designs

unread,
Jun 12, 2019, 7:37:20 AM6/12/19
to Google Apps Script Community

Edit your .clasp.json and set the  "fileExtension" property to "gs". That will prevent clasp from renaming your "gs" to "js". Then in your .clasp.ignore file you can specify the files and folders you want to ignore. 

Fausto

unread,
Jun 12, 2019, 11:28:22 AM6/12/19
to google-apps-sc...@googlegroups.com
Thanks Martin and Dimu
I believe I just did as you both suggested but I should be missing something else
- The .gs files keep disappearing from the GAS project after a clasp push
- see below, step by step what I did and the results on each step

At GAS project
image.png
- gs/Code.gs and dummy.html files

At VS Code
image.png
.claspignore:
**/gs/**
image.png
.clasp.json:
{
  "scriptId": "1fkrYvse9n84u9n384un384uv38",
  "fileExtension": "gs"
}

$ clasp pull
Cloned 3 files.
└─ gs/Code.gs
└─ appsscript.json
└─ dummy.html

$ clasp status
Not ignored files:
└─ appsscript.json
└─ dummy.html
Ignored files:
└─ **/gs/**
└─ .clasp.json
└─ .claspignore

$ clasp push
└─ appsscript.json
└─ dummy.html
Pushed 2 files.

Then, when going back to GAS project
- the gs/Code.gs is no longer there
- and a default empty Code.gs was added instead
image.png

On Wed, Jun 12, 2019 at 7:37 AM Dimu Designs <dimud...@gmail.com> wrote:

Edit your .clasp.json and set the  "fileExtension" property to "gs". That will prevent clasp from renaming your "gs" to "js". Then in your .clasp.ignore file you can specify the files and folders you want to ignore. 

--

Steven Bazyl

unread,
Jun 12, 2019, 3:23:54 PM6/12/19
to google-apps-sc...@googlegroups.com
The underlying API clasp uses doesn't allow partial overwrites of a project. What you're trying to do isn't currently possible.


Warning: The new content replaces all existing files in the script project. Files not updated by the request are removed.


You can sort of make it work but would need to be extremely careful about syncing in the correct direction whenever you make a change. That is, after every edit is apps script, do a clasp pull to update your local project. Likewise, after a local edit, do a clasp push. But it's dangerous and risks overwriting changes if not carefully done.

When using clasp you're best off having a single source of truth (typically your local environment, since that's the point of clasp :) rather than trying to edit in both places. Of course there are plenty of times I'll edit files in the Apps Script IDE while experimenting or debugging, but anything I plan to keep in those cases I'll reapply locally before pushing.



--
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.
Visit this group at https://groups.google.com/group/google-apps-script-community.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAK957HxdQuUanst_OatTdG0xK_oc1%3D9Ve9WQrGzm74c6k2STWA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Faustino Rodriguez

unread,
Jun 12, 2019, 3:53:39 PM6/12/19
to Google Apps Script Community
Thanks a lot Steven for your feedback, the link, the warning and the detailed explanations
You are right, it is quite risky to edit in both places, unless as an exception

Looking at that page, I was hoping that clasp would follow what it says right above that Warning (quote below, bold and [] are mine), but it's not the case unfortunately

Note: When updating script project content, common practice is to first issue a projects.getContent request to retrieve an array of the existing Files, make the desire [changes] to those objects, then use the Files as input for a projects.updateContent request.

I looked around at the code in GitHub, and it seems feasible to do a push/pull of only the changes in either way
Or at least do not remove the ignored files in a clasp push

Would that be a possibility in the future?

Thanks again

Reno Blair

unread,
Jun 12, 2019, 4:01:32 PM6/12/19
to google-apps-sc...@googlegroups.com
That looks to be on the todo list. From the push command source file:
* TODO: Only push the specific files that changed (rather than all files).

--
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.
Visit this group at https://groups.google.com/group/google-apps-script-community.

For more options, visit https://groups.google.com/d/optout.


--
Reno Blair
Educational Technology Services​

Faustino Rodriguez

unread,
Jun 12, 2019, 4:12:39 PM6/12/19
to Google Apps Script Community
Awesome, I missed that note
Thanks for pointing that out

There is hope then


On Wednesday, June 12, 2019 at 4:01:32 PM UTC-4, Reno Blair wrote:
That looks to be on the todo list. From the push command source file:
* TODO: Only push the specific files that changed (rather than all files).

On Wed, Jun 12, 2019 at 12:53 PM Faustino Rodriguez <fau...@thexs.ca> wrote:
Thanks a lot Steven for your feedback, the link, the warning and the detailed explanations
You are right, it is quite risky to edit in both places, unless as an exception

Looking at that page, I was hoping that clasp would follow what it says right above that Warning (quote below, bold and [] are mine), but it's not the case unfortunately

Note: When updating script project content, common practice is to first issue a projects.getContent request to retrieve an array of the existing Files, make the desire [changes] to those objects, then use the Files as input for a projects.updateContent request.

I looked around at the code in GitHub, and it seems feasible to do a push/pull of only the changes in either way
Or at least do not remove the ignored files in a clasp push

Would that be a possibility in the future?

Thanks again

On Wednesday, June 12, 2019 at 3:23:54 PM UTC-4, Steven Bazyl wrote:
The underlying API clasp uses doesn't allow partial overwrites of a project. What you're trying to do isn't currently possible.


Warning: The new content replaces all existing files in the script project. Files not updated by the request are removed.


You can sort of make it work but would need to be extremely careful about syncing in the correct direction whenever you make a change. That is, after every edit is apps script, do a clasp pull to update your local project. Likewise, after a local edit, do a clasp push. But it's dangerous and risks overwriting changes if not carefully done.

When using clasp you're best off having a single source of truth (typically your local environment, since that's the point of clasp :) rather than trying to edit in both places. Of course there are plenty of times I'll edit files in the Apps Script IDE while experimenting or debugging, but anything I plan to keep in those cases I'll reapply locally before pushing.


Eric Koleda

unread,
Jun 17, 2019, 11:37:25 AM6/17/19
to Google Apps Script Community
I think you could theoretically accomplish something like this by having:

- Your source code in /src/ folder.
- A local script that:
  - Did clasp pull into a /build/ folder.
  - Copied files from /src/ to /build/.
  - Did a clasp push from the /builder/ folder.

Essentially you merge your client-side and server side files locally before doing the clasp push.

- Eric

Faustino Rodriguez

unread,
Jun 17, 2019, 11:51:38 AM6/17/19
to Google Apps Script Community
thanks @Eric
- that sounds workable
- I will consider that path when I get back to clasp (in my second round)

For now,
- I am exploring the use of VS Code for GAS client-side code, integrated with GitHub
- It looks promising so far

My goal is 
- to code server-side at GAS editor
- and client-side at a better editor for this purpose like VS Code
- while waiting for a GAS editor upgrade

Thanks again, and not the last one
Reply all
Reply to author
Forward
0 new messages