Skip to content

Instantly share code, notes, and snippets.

@vinceallenvince
Last active October 7, 2023 17:23
Show Gist options
  • Save vinceallenvince/f3d71c61887f0e2c4b4005e1f94b62d8 to your computer and use it in GitHub Desktop.
Save vinceallenvince/f3d71c61887f0e2c4b4005e1f94b62d8 to your computer and use it in GitHub Desktop.
Setting up for local Apps Script development

Follow these steps to get set up for local App Scripts development.

Initial Setup

  1. Install Node.js and npm: If you haven't already, you'll need Node.js and npm on your machine.

    # macOS or Linux
    brew install node
    
    # Windows
    choco install nodejs
  2. Install Clasp: Use npm to install the clasp CLI tool globally.

    npm install -g @google/clasp

Setting up the Project

  1. Initialize Clasp: Inside your project directory, initialize clasp to link it with your Google Apps Script project.

    clasp clone <scriptId> # if you're starting with an existing Apps Script project
    
    # OR
    
    clasp create "Your Project Name" # to create a new Apps Script project

Authentication

  1. Generate credentials.json: Visit the Google Cloud Console, create a new project, enable the Google Apps Script API, and download your credentials.json file.

  2. Clasp Login: Run the following command and point clasp to your credentials.json to log in.

    clasp login --creds ./path/to/credentials.json
  3. Set OAuth Scopes: In your appsscript.json file, define the OAuth scopes that your project needs.

    {
      "oauthScopes": [
        "https://www.googleapis.com/auth/spreadsheets",
        "https://www.googleapis.com/auth/drive"
        // ... other scopes
      ]
    }

Development and Execution

  1. Develop Locally: Write your Apps Script code (.gs files) using your preferred IDE, in this case, VS Code.

  2. Push Changes: Use clasp push to upload your local code to the Apps Script project.

    clasp push
  3. Run Function: Run your Apps Script function locally via the clasp CLI.

    clasp run "YourFunctionName"

Debugging

  1. View Logs: To check the output or any logs, you can use clasp logs, or navigate to the Logs section in the Google Apps Script Editor or Google Cloud Logging.

And that's the setlist! Now you're tuned up and ready to jam. Let me know if you hit any sour notes or if you're ready for the encore! 🎶

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment