Typescript support for running and testing GAS projects locally.
npm install tgas-local
npm i -D tgas-local @types/google-apps-script
`
$3
`
pnpm i -D tgas-local @types/google-apps-script
`
$3
This plugin adds type checking for the return object from gasRequire()
`
pnpm i -D typescript-plugin-tgas-local
`
Then add this plugin information to "compilerOptions" in your tsconfig.json file.
`json
{
// rest of your compilerOptions
"plugins": [
{
"name": "typescript-plugin-tgas-local",
"apps-script-directory": "./RELATIVE_PATH_TO_YOUR_GAS_FILES"
}
]
}
`
Usage
`javascript
// import the gasRequire function
import { gasRequire } from 'tgas-local'
// Pass the relative path from your current working directory to the directory that includes your apps script files.
const gLib = gasRequire('./path-to-local-googleappsscript-directory')
// Call your apps script functions from the gLib object
gLib.yourAppsScriptFunction()
`
Mocking Google Services
`javascript
import { type IGlobalMocksObject, gasRequire } from 'tgas-local'
// Create an object that mocks the functions of an Apps Script Service
const mockServices: IGlobalMocksObject = {
UrlFetchApp: {
fetch: () => "fetch called!",
fetchAll: () => "fetchAll called!"
}
}
// pass it to gasRequire
const gLib = gasRequire('./appsscript-directory', mockServices)
gLib.UrlFetchApp.fetch() // returns the string "fetch called!"
`
Filtering
$3
`javascript
// Use the options object to pass a filter function that will filter any unwanted files
// Note: gasRequire is already setup to only read files with the extentions: .ts, .js, .gs
const options = {
filter: (filePath: string) => {
return filePath === "some-file-to-not-include.ts"
}
}
const gLib = gasRequire('./appscript-directory', mockServices, options)
`
$3
`javascript
// Accepts any valid parameter of the GlobOptions object from the node-glob library.
const options = {
globOptions: {
cwd: './some-other-dir',
absolute: true
// ...etc
}
}
``