CLASP

    New project setup πŸ”—

    • Create New Repo using Git GUI
    • Create Scripts project (On Google Scripts, Sheets, etc.)
    • Clone Scripts Project into repo folder using clasp
    clasp clone <scriptID>
    
    • Copy Hook and .gitignore from template folder repos/zTemplates/clasp/CopyContentsToProjectRoot/ or create folder to copy from using this zip file.

    Steps if using TypeScript (TS) πŸ”—

    Source: https://developers.google.com/apps-script/guides/typescript

    Source: https://github.com/google/clasp/blob/master/docs/typescript.md

    • Add Type definitions for Apps Script
    npm i -S @types/google-apps-script
    
    • Add ts_lib

      • Part of wykies
      git submodule add ../ts_lib.git
      
      • Outside of wykies
      git submodule add git@github.com:wykies/ts_lib.git
      
    • (Optional) Use the following command to push and watch the ts files. Watch is not required.

    clasp push --watch
    

    TypeScript Modules, exports and imports πŸ”—

    Source: https://github.com/google/clasp/blob/master/docs/typescript.md#the-namespace-statement-workaround

    Instead of normal imports use the following as import is not supported in GAS

    // module.ts
    namespace MyLib {
        export function foo() {
        }
    
        function bar() {
        }  // this function can only be addressed from within the `MyLib` namespace
    }
    
    // anyFiles.ts
    MyLib.foo();  // address a namespace's exported content directly
    

    Steps if using Javascript (JS) πŸ”—

    • Add js_lib
    git submodule add ../js_lib.git
    

    Converting an existing Javascript (JS) project to TypeScript (TS) πŸ”—

    Useful Commands πŸ”—

    Ignore files πŸ”—

    File location πŸ”—

    Source: https://github.com/google/clasp#ignore-file-claspignore

    Put a .claspignore in the root of the project’s directory. All paths are relative to root.

    Format πŸ”—

    Uses multimatch

    Glob Pattern:

    • * matches any number of characters, but not /
    • ? matches a single character, but not /
    • ** matches any number of characters, including /, as long as it’s the only thing in a path part
    • {} allows for a comma-separated list of β€œor” expressions
    • ! at the beginning of a pattern will negate the match

    Example πŸ”—

    js_lib/**
    

    Installation πŸ”—

    Source: https://developers.google.com/apps-script/guides/clasp#installation

    First install Install Node.js

    npm install @google/clasp -g