This document provides a high-level overview of the @google/clasp project to guide AI-based development and maintenance.
clasp is a command-line tool for developing and managing Google Apps Script projects locally. It allows developers to write code in their preferred local environment, use version control (like Git), and then push the code to their Apps Script projects. It also supports managing deployments, versions, and executing functions remotely.
- Language: TypeScript
- Platform: Node.js
- CLI Framework: Commander.js
- Key Libraries:
googleapis: To interact with Google APIs (Apps Script, Drive, etc.).google-auth-library: For handling OAuth2 authentication.inquirer: For interactive command-line prompts.ora: For displaying spinners during long-running operations.
- Testing:
- Framework: Mocha
- Assertions: Chai
- Mocking: Nock (for HTTP requests) and
mock-fs(for filesystem).
- Linting & Formatting: Biome
.
βββ src/
β βββ commands/ # Definitions for each CLI command (e.g., push, pull, login).
β βββ core/ # Core logic for interacting with APIs and the filesystem.
β βββ auth/ # Authentication-related logic.
βββ test/
β βββ commands/ # Tests for the CLI commands.
β βββ core/ # Tests for the core logic.
β βββ fixtures/ # Mock data and file templates used in tests.
βββ build/ # Compiled JavaScript output from TypeScript.
βββ package.json # Project metadata, dependencies, and scripts.
βββ tsconfig.json # TypeScript compiler configuration.
βββ biome.json # Biome linter/formatter configuration.
βββ README.md # Project documentation.
- Install dependencies:
npm install
-
Compile TypeScript:
npm run compile
(This is equivalent to running
tspc, a patched version oftsc) -
Build the project (compiles and installs):
npm run build
-
Run tests:
npm test -
Check for linting and formatting issues:
npm run lint
(Uses
biome check) -
Fix linting and formatting issues:
npm run fix
(Uses
biome check --fix) -
Run the CLI locally for development:
npm run clasp -- <command> # Example: npm run clasp -- list-scripts
- Command/Core Separation: CLI command definitions in
src/commands/are kept separate from the underlying business logic insrc/core/. Commands primarily parse options and call methods from the core classes. - Class-based Core: The core logic is organized into classes like
Clasp,Project,Files, andServicesto encapsulate different areas of functionality. - Heavy Mocking in Tests: Tests rely heavily on
nockto mock all outgoing Google API calls andmock-fsto simulate the filesystem. This makes tests fast and deterministic. When adding new API interactions, corresponding mocks must be added intest/mocks.ts. - Asynchronous Code: The entire codebase is asynchronous, using
async/awaitextensively for all I/O and API operations. - Configuration: Project-specific settings are stored in a local
.clasp.jsonfile. Global user credentials are in~/.clasprc.json. - Internationalization (i18n): User-facing strings are managed through
@formatjs/intland are located insrc/messages/.