Search code examples
google-apps-script-editorgoogle-apps-script-apiclasp

How do I create and push new files client side?


Simply making files in the directory does not add them to the project. Is there a way to make sure they get pushed with the rest of the project, or am I doomed to creating them in the web editor and then pulling?


Solution

  • Any .js or .html files in the directory not excluded by the .claspignore file will be pushed to the associated Apps Script project. You can view these files with clasp status.

    Official Description:

    Push
    Force writes all local files to script.google.com.

    Ignores files:

    • That start with a .
    • That don't have an accepted file extension
    • That are ignored (filename matches a glob pattern in the .claspignore file)

    e.g.

    $ clasp create
     ...
    $ echo 'function foo() { console.log("This is a Stackdriver log"); }' > newFile.js
    $ clasp status
    Not ignored files:
    └─ appsscript.json
    └─ newFile.js
    
    Ignored files:
    └─ .clasp.json
    $ clasp push
    └─ appsscript.json
    └─ newFile.js
    Pushed 2 files.
    $ clasp open
    Opening script: https://script.google.com/d/..../edit
    

    In the Script Editor, you will observe the files that were pushed by clasp push. If you perform an immediate clasp pull, you will not observe differences in the files (well, perhaps other than LF/CRLF conversions).

    if so, the solution is to push a second time before opening the editor.

    $ clasp push && clasp push
      ...
    $ clasp open