This document provides a comprehensive technical reference for the CoMapeo Category Set Spreadsheet Plugin architecture, including system design, data flow, and module organization.
Audience: Developers, AI assistants, and technical contributors For Users: See docs/index.md for end-user documentation
The CoMapeo Category Set Spreadsheet Plugin is a Google Apps Script application that allows users to create and manage configuration files for the CoMapeo mapping application directly from Google Spreadsheets. It streamlines the process of creating .comapeocat category files, which define the data collection schema for CoMapeo projects.
The project is organized into several key directories and files:
index.ts: The entry point of the application, which defines the menu structure and main functions that can be triggered from the Google Sheets UI.appsscript.json: Configuration file for the Google Apps Script project..clasp.json: Configuration file for the Clasp CLI tool, which is used for local development and deployment.
The src directory contains the main functionality of the plugin, organized into several modules:
generateCoMapeoConfig.ts: Contains the main function for generating CoMapeo configuration files from spreadsheet data.spreadsheetData.ts: Functions for retrieving and manipulating data from the spreadsheet.translation.ts: Handles translation of content between different languages.lint.ts: Provides validation and formatting for spreadsheet data. Includes functions to clean whitespace-only cells, check for duplicates, validate required fields, and ensure proper formatting.dialog.ts: Creates and manages UI dialogs for user interaction.driveService.ts: Manages interactions with Google Drive for saving and retrieving files.apiService.ts: Handles communication with external APIs for processing configuration files.
Current build flow uses the payload builder:
builders/payloadBuilder.ts: Builds the JSON payload sent to the/v2API.
Legacy (pre-v2) processors live under src/generateConfig and are no longer part of the main build path.
The src/generateIcons directory contains modules for generating and processing icons:
iconProcessor.ts: Processes icon data from the spreadsheet.iconApi.ts: Communicates with external icon APIs to generate SVG icons.
types.ts: TypeScript type definitions for the project.text/dialog.ts: Text content for dialogs in different languages.
The src/scripts directory contains shell scripts for deployment and management:
push-all.sh: Script for pushing code to multiple Google Apps Script projects.
The src/test directory contains test functions:
testBuildAndImport.ts: Tests JSON build flow and import integration.
The plugin uses the v2 API data model defined in types.ts:
BuildRequest: JSON payload sent to the/v2API.Metadata,Category,Field,Icon: Core schema objects for the build.TranslationsByLocale: Translation payload keyed by locale.
Legacy configuration types still exist for import/migration paths, but the build flow uses BuildRequest.
Entry Point: translateCoMapeoCategory() (Menu: "Manage Languages & Translate")
- Purpose: Standalone translation workflow (no build)
- Process: Language selection dialog → Translate empty cells → Update sheets
- Output: Updated translation sheets only
Entry Point: generateCoMapeoCategory() (Menu: "Generate CoMapeo Category")
- Purpose: Build a
.comapeocatfrom current spreadsheet data - Process: Validate + read sheets → Build JSON payload → POST to API
/v2 - Output:
.comapeocatZIP returned by API and saved to Google Drive
Debug mode note: The "Debug: Export Raw Files" menu entry runs the standard generator in v2; raw export is deprecated (see docs/how-to/export-and-share.md).
When the spreadsheet is opened, onOpen() creates a custom menu with the following options:
Main Menu (CoMapeo Tools / Herramientas CoMapeo):
- Manage Languages & Translate (
translateCoMapeoCategory)- Standalone translation workflow
- Generate Category Icons (
generateIcons)- Icon generation for categories only
- Separator
- Generate CoMapeo Category (
generateCoMapeoCategory)- Main production generation mode
- Import category file (
importCategoryFile)- Import existing
.comapeocator.mapeosettingsfiles
- Import existing
- Separator
- Lint Sheets (
lintAllSheets)- Validate all sheets for issues
- Reset Spreadsheet (
cleanAllSheets)- Clean sheets (remove translations, metadata, icons)
- Separator
- Debug: Export Raw Files (
generateCoMapeoCategoryDebug)- Runs the standard generator (v2); raw export is deprecated
- Help (
openHelpPage)- Opens help documentation
- About / Version (
showVersionInfo)- Display version information
Developer Menu (shown in development environment only):
- Test functions for format detection, translation extraction, category import, etc.
- Clear Language Cache - Reset cached language data
The v2 build flow is JSON-only and does not create local ZIPs:
- Validate & Lint: Check sheet structure, translation mismatches, and required fields.
- Read Spreadsheet Data: Build a
SheetDataobject from Categories/Details/Translations. - Build Payload: Create the JSON build payload (
createBuildPayload()). - API Build:
POST /v2with JSON and receive a.comapeocatZIP. - Save & Notify: Save the returned file to Drive and show the success dialog.
Translation creation and auto-translation are handled separately via Manage Languages & Translate.
When the user selects "Generate Category Icons":
- Data Collection: Reads Categories sheet
- Icon Processing: For each category:
- Check if Google Drive icon exists → Use existing
- Check if cell has image → Process via API
- Otherwise → Generate new icon from external API
- API Calls:
- Search:
https://icons.earthdefenderstoolkit.com/api/search - Generate:
https://icons.earthdefenderstoolkit.com/api/generate
- Search:
- Saving: Icons saved to Google Drive and URLs updated in spreadsheet
When the user selects "Manage Languages & Translate" (standalone mode):
- Language Detection: Reads primary language from cell A1 (supports both English and native names)
- Language Selection: Shows dialog with:
- Auto-translate checkboxes for 200+ languages
- Custom language input fields
- Common languages preset
- Custom Languages: Adds specified language columns to all translation sheets
- Auto-Translation: Translates empty cells using Google Translate API
- Bidirectional: Can translate both to and from target languages
- Output: Updated spreadsheet with translations (no config generation)
interface GenerationOptions {
skipDriveWrites?: boolean; // Skip Drive operations for in-memory mode
}- Stored in PropertiesService for async callback support
- Required because Google Apps Script doesn't preserve global variables across
google.script.runcontexts - Retrieved in
handleLanguageSelection()to determine workflow
- All user-facing strings are localized
- Supported locales: English (
en), Spanish (es) - Text definitions in
src/text/menu.ts
- Try-catch blocks at each major step
- Cleanup on failure (deleting Drive folders)
- Error logging via
getScopedLogger() - Icon errors stored separately for user-friendly reporting
- Graceful degradation where possible
- Modal processing dialog with 8 stages
- Progress callbacks:
updateProcessingDialogProgress(main, detail) - Real-time updates during long operations (Drive saves, API calls)
- Runs BEFORE processing to catch issues early
- Validates sheet structure, required columns, data integrity
- Shows summary of issues with option to continue or cancel
- Prevents wasted time on invalid configurations
The plugin can be deployed in several ways:
For local development, the plugin uses the Clasp CLI tool:
- Install Clasp:
npm install -g @google/clasp - Login to Google:
clasp login - Push changes:
clasp push - Open the project:
clasp open
The plugin supports deployment to multiple Google Apps Script projects using the .clasp.all.json file and the push-all.sh script.
The plugin includes a GitHub Actions workflow in .github/workflows/deploy.yml that automatically deploys the plugin when changes are pushed to the main branch or when a release is published.
The plugin interacts with several external APIs:
- Icon API: Used for searching and generating icons.
- CoMapeo API: Used for processing the final configuration file.
The plugin includes several security features:
- Project Key: A unique key can be generated for each project to ensure that configurations can only be synced with authorized projects.
- Metadata Validation: The plugin validates metadata to ensure that it meets the requirements for CoMapeo configurations.
The CoMapeo Category Set Spreadsheet Plugin provides a user-friendly interface for creating and managing CoMapeo configuration files directly from Google Spreadsheets. It streamlines the process of defining data collection schemas, generating icons, and translating content, making it easier for users to create and maintain CoMapeo projects.