How googlecodelabs/tools works
Project Type and Purpose
• This is a full-stack “authoring & publishing” toolkit for Google Codelabs.
• It comprises:
• A Go-based command-line tool (claat) that fetches Google Docs or Markdown, parses them into an AST, and renders to HTML/Markdown.
• A set of web components (codelab-elements) for interactive UIs.
• A static site generator (in site/) using Node/Gulp/Bower/Polymer to build landing pages and host codelabs.
High-Level File Structure
• Top-level: CI configs, Bazel/Make/Git files, README.md, FORMAT-GUIDE.md.
• claat/: Go modules—cmd/ (CLI commands), fetch/ (Google Docs API), parser/ (gdoc & markdown), nodes/ (AST nodes), render/ (template engine), types/, util/, main.go.
• codelab-elements/: Polymer/Bazel-built web components and demos.
• site/: front-end build pipeline—app/ (static SPA), tasks/ (Gulp tasks, helpers), gulpfile.js, package.json.
• sample/: example codelabs.
Key README Insights
• Input: Google Docs or Markdown (via claat export).
• Preview: claat serve spins up a local HTTP server.
• Output: static HTML/Markdown for any host (GitHub Pages, GCS, S3, etc.).
• Landing pages and custom views built by site/ pipeline.
• Uses Google Analytics, optional offline/offline formats, multiple output templates.
Main Components
a. CLI Layer (Go application)
• Fetch Module → Parser Module → AST (Nodes & Types) → Render Module → Output Artifacts (HTML/MD)
• Serve Module → Local HTTP Server → Browser (Preview UI)
b. Web Components Library (codelab-elements)
• Polymer components consumed by both the local preview and the static site.
c. Static Site Generator (site/)
• Gulp Tasks (generate landing pages, custom views)
• Front-end SPA (Polymer, HTML, CSS, JS)
• Deployment Helpers (GCS uploads, options parsing)
d. External Services
• Google Docs API (Drive auth & fetch)
• Google Analytics (usage tracking)
• Any static file host (GitHub Pages, App Engine, S3, etc.)
Relationships & Data Flow
1. User invokes claat export [docId|.md].
2. Fetch module calls Google Drive API, retrieves HTML.
3. Parser builds an AST of nodes & types.
4. Renderer applies Go templates to produce HTML/MD outputs.
5. Outputs dropped into a directory (ready to serve or check in).
6. User runs claat serve or copies outputs to static host.
7. Separately, Gulp tasks in site/ ingest codelab outputs + view definitions → build site/app (SPA + Polymer components) → deploy via GCS/other.
8. Browser loads static site or preview UI, pulling in codelab-elements components; user steps through codelab; analytics events fire to GA.
Architectural Patterns & Principles
• Layered/Modular CLI: separation of concerns (fetch, parse, render, serve).
• AST-driven rendering for flexible output formats.
• Component-based front-end (Polymer Web Components) for reusable UI building blocks.
• Static site generation pipeline via task runners (Gulp) for decoupled build & deploy.
• Build systems: Bazel for Go & JS libraries; Make/Gulp for site.
Technologies & Frameworks
• Go (CLI, Bazel build)
• Google Drive API & OAuth (fetching docs)
• Go text/templates (renderer)
• Node.js, Gulp, Bower, Polymer (front-end/site)
• HTML5, CSS3, Web Components
• Google Analytics for monitoring
• Static hosting (GCS, GitHub Pages, S3, App Engine)