Profile
Back to NewsBack
GitHub Trending 19 min
Reader Mode
google/clasp: 🔗 Command Line Apps Script Projects

google/clasp: 🔗 Command Line Apps Script Projects

Clasp

Note: This is not an officially supported Google product.

!build status Coverage Status npm Version npm Downloads

Develop Apps Script projects locally using clasp (Command Line Apps Script Projects).
[!WARNING]
The default OAuth client for Clasp will be disabled on March 1st, 2027. Reauthorize clasp using your own project and Client ID — see Bring your own project/credentials.
> Until then, commands authorized with the default OAuth client will print a warning to stderr. You can suppress this warning by passing --skip-client-id-warning or setting the CLASP_SKIP_CLIENT_ID_WARNING environment variable.

!clasp

To get started, try out the codelab!

You can also try clasp in Gitpod, a one-click online IDE for GitHub:

Open in Gitpod</a>

Features

🗺️ Develop Locally: clasp allows you to develop your Apps Script projects locally. That means you can check-in your code into source control, collaborate with other developers, and use your favorite tools to develop Apps Script.

🔢 Manage Deployment Versions: Create, update, and view your multiple deployments of your project.

📁 Structure Code: clasp automatically converts your flat project on script.google.com into folders. For example:

  • _On script.google.com_:
- tests/slides.gs - tests/sheets.gs
  • _locally_:
- tests/ - slides.js - sheets.js

➡️ Run Apps Script: Execute your Apps Script from the command line. Features:

  • _Instant_ deployment.
  • Suggested functions Autocomplete (Fuzzy)
  • Easily add custom Google OAuth scopes
  • And more…

Install

First download clasp:

npm install -g @google/clasp

Then enable the Google Apps Script API: https://script.google.com/home/usersettings

!Enable Apps Script API

Installing as a Gemini CLI Extension

You can install clasp as an Gemini CLI extensions using the following command:

gemini extensions install https://github.com/google/clasp

This makes clasp available as an MCP server in Gemini CLI.

Make sure to enable the Google Apps Script API (as explained above) and perform a clasp login (with your specific login parameters) before you use the extension.

Installing as a Claude Code CLI Extension

You can use clasp with Claude Code CLI in one of two ways:

1. Install as a Plugin (Recommended)

Run the following command in Claude Code to install clasp as a plugin directly from the repository:

/plugin install @google/clasp

2. Manual Installation

You can manually add clasp as an MCP server using the provided configuration file or by running:

claude mcp add clasp -- npx -y @google/clasp mcp

Or by referencing the configuration file included in the repository:

claude mcp add-json clasp "$(cat claude-mcp.json)"

Commands

The following command provide basic Apps Script project management.

Note: Most of them require you to clasp login and clasp create/clone before using the rest of the commands.
clasp
  • [clasp login [--no-localhost] [--creds ] [--use-project-scopes] [--include-clasp-scopes] [--extra-scopes ] [--redirect-port]](#login)
  • clasp logout
  • [clasp show-authorized-user [--json]](#show-authorized-user)
  • [clasp create-script [--title ] [--type <type>] [--rootDir <dir>] [--parentId <id>]</code>](#create)</li> <li>[<code>clasp clone-script <scriptId | scriptURL> [versionNumber] [--rootDir <dir>]</code>](#clone)</li> <li>[<code>clasp delete-script [--force]</code>](#delete)</li> <li>[<code>clasp pull [--versionNumber]</code>](#pull)</li> <li>[<code>clasp push [--watch] [--force]</code>](#push)</li> <li>[<code>clasp show-file-status [--json]</code>](#status)</li> <li><a href="#open" target="_blank" rel="noopener"><code>clasp open-script</code></a></li> <li><a href="#deployments" target="_blank" rel="noopener"><code>clasp list-deployments</code></a></li> <li>[<code>clasp create-deployment [--versionNumber <version>] [--description <description>] [--deploymentId <id>]</code>](#deploy)</li> <li>[<code>clasp delete-deployment [deploymentId] [--all]</code>](#undeploy)</li> <li>[<code>clasp create-version [description]</code>](#version)</li> <li><a href="#versions" target="_blank" rel="noopener"><code>clasp list-versions</code></a></li> <li><a href="#list" target="_blank" rel="noopener"><code>clasp list-scripts</code></a></li></ul> <h3>Advanced Commands</h3> <blockquote><strong>NOTE</strong>: These commands require you to add your <a href="#projectid-optional" target="_blank" rel="noopener">Project ID</a>.</blockquote> <ul><li>[<code>clasp tail-logs [--json] [--watch] [--simplified]</code>](#logs)</li> <li>[<code>clasp setup-logs [--json]</code>](#setup-logs)</li> <li><a href="#apis" target="_blank" rel="noopener"><code>clasp list-apis</code></a></li> <li><a href="#apis" target="_blank" rel="noopener"><code>clasp enable-api<api></code></a></li> <li><a href="#apis" target="_blank" rel="noopener"><code>clasp disable-api <api></code></a></li> <li>[<code>clasp run-function [function]</code>](#clasp-run)</li></ul> <h2>Guides</h2> <h3>Migrating from 2.x to 3.x</h3> <h4>Drop typescript support</h4> <p>Clasp no longer transpiles typescript code. For typescript projects, use typescript with a bundler like <a href="https://rollupjs.org/" target="_blank" rel="noopener">Rollup</a> to transform code prior to pushing with clasp. This has the advantage of offering more robust support for Typescript features along with ESM module and NPM package support.</p> <p>There are several template projects on GitHub that show how to transform Typescript code into Apps Script that are all excellent choices.</p> <ul><li>https://github.com/WildH0g/apps-script-engine-template</li> <li>https://github.com/tomoyanakano/clasp-typescript-template</li> <li>https://github.com/google/aside</li> <li>https://github.com/sqrrrl/apps-script-typescript-rollup-starter</li></ul> <h4>Command renames</h4> <p>Clasp 3.x introduces some breaking changes from 2.x. For common use cases these changes should not impact usage, but some lesser used commands have been restructured and renamed to improve consistency.</p> <p>| 2.x | 3.x | |----------------------------|----------------------------------------| |<code>open</code> | <code>open-script</code> | |<code>open --web</code> | <code>open-web-app</code> | |<code>open --addon</code> | <code>open-container</code> | |<code>open --creds</code> | <code>open-credentials-setup</code> | |<code>login --creds <file></code> | <code>login -u <name> --creds <file></code> | |<code>logs --open</code> | <code>open-logs</code> | |<code>logs --setup</code> | N/A | |<code>apis --open</code> | <code>open-api-console</code> | |<code>apis enable <api></code> | <code>enable-api <api></code> | |<code>apis disable <api></code> | <code>disable-api <api></code> | |<code>deploy -i <id></code> | <code>update-deployment <id></code> | |<code>settings</code> | N/A |</p> <p>Other commands have also been renamed but retain aliases for compatibility.</p> <h3>Authorization</h3> <p>Most command require user authorization. Run <code>clasp login</code> to authorize access to manage your scripts.</p> <h4>Multiple user support</h4> <p>Use the global <code>--user</code> option to switch between accounts. This supports both running clasp as different users as well as when invoking the <code>clasp run-function</code> command.</p> <p>Examples:</p> <pre><code class="sh">clasp login # Saves as default credentials clasp clone # User not specified, runs using default credentials clasp login --user testaccount # Authorized new named credentials clasp run-function --user testaccount myFunction # Runs function as test account</code></pre> <h3>Bring your own project/credentials</h3> <p>While clasp includes a default OAuth client, using your own project is recommend and can improve security and compliance in environments that limit which third party applications users may authorize. To set up your own project:</p> <ol><li><a href="https://cloud.google.com/resource-manager/docs/creating-managing-projects" target="_blank" rel="noopener">Create a new project</a> in the Google Cloud Developer Console.</li> <li><a href="https://support.google.com/cloud/answer/15549257?hl=en#:~:text=To%20create%20an%20OAuth%202.0,are%20yet%20to%20do%20so." target="_blank" rel="noopener">Create an OAuth client</a>. The client type must be <code>Desktop Application</code>. Download and save the generated client secrets file. This is required when authorizing using the<code>clasp login --creds <filename></code> command.</li> <li><a href="https://cloud.google.com/endpoints/docs/openapi/enable-api" target="_blank" rel="noopener">Enable services</a>. For full functionality, clasp requires the following:</li></ol> * Apps Script API - <code>script.googleapis.com</code> (required) * Service Usage API - <code>serviceusage.googleapis.com</code> (required to list/enable/disable APIs) * Google Drive API - <code>drive.googleapis.com</code> (required to list scripts, create container-bound scripts) - Cloud Logging API - <code>logging.googleapis.com</code> (required to read logs) <p>Note: If configuring the project for external use where OAuth scopes must be registered, include the following:</p> <pre><code class="">https://www.googleapis.com/auth/script.deployments https://www.googleapis.com/auth/script.projects https://www.googleapis.com/auth/script.webapp.deploy https://www.googleapis.com/auth/drive.metadata.readonly https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/service.management https://www.googleapis.com/auth/logging.read https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/cloud-platform</code></pre> <h3>Allow-list clasp</h3> <p>If your organization restricts authorization for third-party apps, you may either:</p> <ul><li>Request your admin allow-list clasp's client id <code>1072944905499-vm2v2i5dvn0a0d2o4ca36i1vge8cvbn0.apps.googleusercontent.com</code></li> <li>Set up an internal-only GCP project for clasp as described in the previous section.</li></ul> <h3>Service accounts (EXPERIMENTAL/NOT WORKING)</h3> <p>Use the <code>--adc</code> option on any command to read credentials from the environment using Google Cloud's <a href="https://cloud.google.com/docs/authentication/application-default-credentials" target="_blank" rel="noopener">application default credentials</a> mechanism.</p> <p>Note that if using a service account, service accounts can not own scripts. To use a service account to push or pull files from Apps Script, the scripts must be shared with the service account with the appropriate role (e.g. <code>Editor</code> in able to push.)</p> <h3>Ignore File (<code>.claspignore</code>)</h3> <p>Like <code>.gitignore</code>, <code>.claspignore</code> allows you to ignore files that you do not wish to upload on <code>clasp push</code>. Steps:</p> <ol><li>Create a file called <code>.claspignore</code> in your project's root directory.</li> <li>Add patterns to be excluded from <code>clasp push</code>. _Note_: The <code>.claspignore</code> patterns are applied by <a href="https://github.com/sindresorhus/multimatch" target="_blank" rel="noopener">multimatch</a>, which is different from <code>.gitignore</code>, especially for directories. To ignore a directory, use syntax like <code><strong>/node_modules/</strong></code>.</li></ol> A sample <code>.claspignore</code> ignoring everything except the manifest and <code>build/main.js</code>: <pre><code class="text"><strong>/</strong> !build/main.js !appsscript.json</code></pre> <p>_Note_: The <code>.claspignore</code> patterns are applied relative from the <code>rootDir</code>.</p> <p>If no <code>.claspignore</code> is specified, a default set of patterns is applied. This default set will only consider the <code>appsscript.json</code> manifest and any JavaScript, TypeScript and <code>.html</code> source files within the <code>rootDir</code> folder. Child folders other than <code>.git</code> and <code>node_modules</code> are processed.</p> <pre><code class="text"># ignore all files… <strong>/</strong> <h1>except the extensions…</h1> !appsscript.json !<em>*/</em>.gs !<em>*/</em>.js !<em>*/</em>.ts !<em>*/</em>.html <h1>ignore even valid files if in…</h1> .git/** node_modules/**</code></pre> <h2>Project Settings File (<code>.clasp.json</code>)</h2> <p>When running <code>clone</code> or <code>create</code>, a file named <code>.clasp.json</code> is created in the current directory to describe <code>clasp</code>'s configuration for the current project. Example <code>.clasp.json</code>:</p> <pre><code class="json">{ "scriptId": "", "rootDir": "build/", "projectId": "project-id-xxxxxxxxxxxxxxxxxxx", "fileExtension": "ts", "filePushOrder": ["file1.ts", "file2.ts"] }</code></pre> <p>The following configuration values can be used:</p> <h3><code>scriptId</code> (required)</h3> <p>Specifies the id of the Google Script project that clasp will target.</p> <ol><li>Open script url.</li> <li>File > Project properties > Script ID</li></ol> <h3><code>rootDir</code> (optional)</h3> <p>Specifies the <strong>local</strong> directory in which clasp will store your project files. If not specified, clasp will default to the current directory.</p> <h3><code>projectId</code> (optional)</h3> <p>Specifies the id of the Google Cloud Platform project that clasp will target. You must <a href="https://github.com/google/clasp/blob/master/docs/run.md#setup-instructions" target="_blank" rel="noopener">associate Google Script project with Google Cloud Platform</a> beforehand.</p> <ol><li>Run <code>clasp open</code>.</li> <li>Click <code>Resources > Cloud Platform project...</code>.</li> <li>Specify the project ID <code>project-id-xxxxxxxxxxxxxxxxxxx</code>.</li></ol> Even if you do not set this manually, clasp will ask this via a prompt to you at the required time. <h3><code>fileExtension</code> (deprecated, optional)</h3> <p>Specifies the file extension for <strong>local</strong> script files in your Apps Script project.</p> <h3><code>scriptExtensions</code> (optional)</h3> <p>Specifies the file extensions for <strong>local</strong> script files in your Apps Script project. May be a string or array of strings. Files matching the extension will be considered scripts files.</p> <p>When pulling files, the first extension listed is used to write files.</p> <p>Defaults to <code>[".js", ".gs"]</code></p> <h3><code>htmlExtensions</code> (optional)</h3> <p>Specifies the file extensions for <strong>local</strong> HTML files in your Apps Script project. May be a string or array of strings. Files matching the extension will be considered HTML files.</p> <p>When pulling files, the first extension listed is used to write files.</p> <p>Defaults to <code>[".html"]</code></p> <h3><code>filePushOrder</code> (optional)</h3> <p>Specifies the files that should be pushed first, useful for scripts that rely on order of execution. All other files are pushed after this list of files, sorted by name.</p> <p>Note that file paths are relative to directory containing .clasp.json. If <code>rootDir</code> is also set, any files listed should include that path as well.</p> <h3><code>skipSubdirectories</code> (optional)</h3> <p>For backwards compatibility with previous behavior where subdirectories are ignored if a <code>.claspignore</code> file is not present. Clasp provides default ignore rules, making the previous warning and behavior confusing. If you need to force clasp to ignore subdirectories and do not want to construct a <code>.claspignore</code> file, set this option to true.</p> <h2>Reference</h2> <h3>Global options</h3> <ul><li><code>--user <name></code>: Uses credentials stored under the named key. When omitted, the <code>default</code> user is used.</li> <li><code>--adc</code>: Uses application default credentials from the environment. Intended to support service accounts in CI workflows.</li> <li><code>--project <file></code>: Reads project settings from a file other than <code>.clasp.json</code>. Intended to support multiple deployment targets.</li> <li><code>--auth <file></code>: (<strong>DEPRECATED</strong>) Reads credentials from a file other than <code>.clasprc.json</code>. Use the <code>--user</code> option to maintain multiple authorized accounts.</li> <li><code>--ignore <file></code>: Reads ignore patterns from a file other than <code>.claspignore</code>.</li> <li><code>--json</code>: Show output in JSON format.</li> <li><code>--skip-client-id-warning</code>: Suppresses the deprecation warning when authorized with the default OAuth client ID. Can also be set via the <code>CLASP_SKIP_CLIENT_ID_WARNING</code> environment variable.</li></ul> <h3>Login</h3> <p>Logs the user in. Saves the client credentials to a <code>.clasprc.json</code> file in the user's home directory</p> <h4>Options</h4> <ul><li><code>--no-localhost</code>: Do not run a local server, manually enter code instead.</li> <li><code>--creds <file></code>: Use custom credentials used for <code>clasp run</code>. Saves a <code>.clasprc.json</code> file to current working directory. This file should be private!</li> <li><code>--use-project-scopes</code>: Use scopes from <code>appsscript.json</code> instead of default clasp scopes. Useful for <code>clasp run</code> when your script requires runtime scopes.</li> <li><code>--include-clasp-scopes</code>: Include default clasp scopes in addition to project scopes from <code>appsscript.json</code>. Can only be used with <code>--use-project-scopes</code>.</li> <li><code>--extra-scopes <scopes></code>: Include additional OAuth scopes as a comma-separated list (for example, <code>scopeA,scopeB</code>). Empty entries are rejected.</li> <li><code>--redirect-port <port></code>: Specify a custom port for the local redirect server during the login process. Useful for environments where a specific port is required.</li></ul> <h4>Examples</h4> <ul><li><code>clasp login</code></li> <li><code>clasp login --no-localhost</code></li> <li><code>clasp login --user test-user --creds client_secret.json</code></li> <li><code>clasp login --user test-user --use-project-scopes --creds client_secret.json</code></li> <li><code>clasp login --user test-user --use-project-scopes --include-clasp-scopes --creds client_secret.json</code></li> <li><code>clasp login --user test-user --extra-scopes https://www.googleapis.com/auth/spreadsheets.readonly,https://www.googleapis.com/auth/drive.readonly --creds client_secret.json</code></li> <li><code>clasp login --redirect-port 37473</code></li></ul> <h3>Logout</h3> <p>Logs out the user by deleting client credentials.</p> <h4>Examples</h4> <ul><li><code>clasp logout</code></li></ul> <h3>Show Authorized User</h3> <p>Shows the current authorization status. When logged in, the output includes the OAuth client ID and whether the client is <code>google-provided</code> (clasp default) or <code>user-provided</code> (custom credentials).</p> <h4>Options</h4> <ul><li><code>--json</code>: Output authorization details as JSON, including <code>clientId</code> and <code>clientType</code>.</li></ul> <h4>Examples</h4> <ul><li><code>clasp show-authorized-user</code></li> <li><code>clasp show-authorized-user --json</code></li></ul> <h3>Create</h3> <p>Creates a new script project. Prompts the user for the script type if not specified.</p> <h4>Options</h4> <ul><li><code>--type [docs/sheets/slides/forms]</code>: If specified, creates a new add-on attached to a Document, Spreadsheet, Presentation, or Form. If <code>--parentId</code> is specified, this value is ignored.</li> <li><code>--title <title></code>: A project title.</li> <li><code>--rootDir <dir></code>: Local directory in which clasp will store your project files. If not specified, clasp will default to the current directory.</li> <li><code>--parentId <id></code>: A project parent Id.</li></ul> - The Drive ID of a parent file that the created script project is bound to. This is usually the ID of a Google Doc, Google Sheet, Google Form, or Google Slides file. If not set, a standalone script project is created. - i.e. <code>https://docs.google.com/presentation/d/{id}/edit</code> <h4>Examples</h4> <ul><li><code>clasp create-script</code></li> <li><code>clasp create-script --type standalone</code> (default)</li> <li><code>clasp create-script --type docs</code></li> <li><code>clasp create-script --type sheets</code></li> <li><code>clasp create-script --type slides</code></li> <li><code>clasp create-script --type forms</code></li> <li><code>clasp create-script --type webapp</code></li> <li><code>clasp create-script --type api</code></li> <li><code>clasp create-script --title "My Script"</code></li> <li><code>clasp create-script --rootDir ./dist</code></li> <li><code>clasp create-script --parentId "1D_Gxyv<strong><em></strong><strong></em></strong><strong><em></strong><strong></em></strong><strong><em></strong></em><em>*</em>NXO7o"</code></li></ul> These options can be combined like so: <ul><li><code>clasp create-script --title "My Script" --parentId "1D_Gxyv<strong><em></strong><strong></em></strong><strong><em></strong><strong></em></strong><strong><em></strong></em><em>*</em>NXO7o" --rootDir ./dist</code></li></ul> <h3>Clone</h3> <p>Clones the script project from script.google.com.</p> <h4>Options</h4> <ul><li><code>scriptId | scriptURL</code>: The script ID _or_ script URL to clone.</li> <li><code>--versionNumber <number></code>: The version of the script to clone.</li> <li><code>--rootDir <dir></code>: Local directory in which clasp will store your project files. If not specified, clasp will default to the current directory.</li></ul> <h4>Examples</h4> <ul><li><code>clasp clone-script "15ImUCpyi1Jsd8yF8Z6wey_7cw793CymWTLxOqwMka3P1CzE5hQun6qiC"</code></li> <li><code>clasp clone-script "https://script.google.com/d/15ImUCpyi1Jsd8yF8Z6wey_7cw793CymWTLxOqwMka3P1CzE5hQun6qiC/edit"</code></li> <li><code>clasp clone-script "15ImUCpyi1Jsd8yF8Z6wey_7cw793CymWTLxOqwMka3P1CzE5hQun6qiC" --rootDir ./src</code></li></ul> <h3>Delete</h3> <p>Interactively deletes a script or a project and the <code>.clasp.json</code> file. Prompt the user for confirmation if the --force option is not specified.</p> <h4>Options</h4> <ul><li><code>-f</code> <code>--force</code>: Bypass any confirmation messages. It’s not a good idea to do this unless you want to run clasp from a script.</li></ul> <h4>Examples</h4> <ul><li><code>clasp delete-script</code></li> <li><code>clasp delete-script -f</code></li></ul> <h3>Pull</h3> <p>Fetches a project from either a provided or saved script ID. Updates local files with Apps Script project.</p> <h4>Options</h4> <ul><li><code>--versionNumber <number></code>: The version number of the project to retrieve.</li> <li><code>--deleteUnusedFiles</code>: Deletes local files that would have been pushed that were not returned by the server. Prompts for confirmation</li> <li><code>--force</code>: Used with <code>--deleteUnusedFiles</code> to automatically confirm. Use with caution.</li></ul> <h4>Examples</h4> <ul><li><code>clasp pull</code></li> <li><code>clasp pull --versionNumber 23</code></li></ul> <h3>Push</h3> <p>Force writes all local files to script.google.com.</p> <blockquote>Warning: Google <code>scripts</code> APIs do not currently support atomic nor per file operations. Thus the <code>push</code> command always <strong>replaces</strong> the whole content of the online project with the files being pushed.</blockquote> <p>Ignores files:</p> <ul><li>That start with a <code>.</code></li> <li>That don't have an accepted file extension</li> <li>That are ignored (filename matches a glob pattern in the <code>.claspignore</code> file)</li></ul> <h4>Options</h4> <ul><li><code>-f</code> <code>--force</code>: Forcibly overwrites the remote manifest.</li> <li><code>-w</code> <code>--watch</code>: Watches local file changes. Pushes files every few seconds.</li></ul> <h4>Examples</h4> <ul><li><code>clasp push</code></li> <li><code>clasp push -f</code></li> <li><code>clasp push --watch</code></li></ul> <h3>Status</h3> <p>Lists files that will be written to the server on <code>push</code>.</p> <p>Ignores files:</p> <ul><li>That start with a <code>.</code></li> <li>That don't have an accepted file extension</li> <li>That are ignored (filename matches a glob pattern in the ignore file)</li></ul> <h4>Options</h4> <ul><li><code>--json</code>: Show status in JSON form.</li></ul> <h4>Examples</h4> <ul><li><code>clasp show-file-status</code></li> <li><code>clasp show-file-status --json</code></li></ul> <h3>Open</h3> <p>Clasp offers several commands to opens the current directory's <code>clasp</code> project and related resources.</p> <h4>Examples</h4> <ul><li><code>clasp open-script</code></li> <li><code>clasp open-web-app</code></li> <li><code>clasp open-container</code></li> <li><code>clasp open-credentials-setup</code></li></ul> <h3>Deployments</h3> <p>List deployments of a script.</p> <h4>Examples</h4> <ul><li><code>clasp list-deployments</code>: List all deployments for the current project</li> <li><code>clasp list-deployments [scriptId]</code>: List all deployments for a script ID</li></ul> <h3>Deploy</h3> <p>Creates a version and deploys a script. The response gives the deployment ID and the version of the deployment.</p> <p>For web apps, each deployment has a unique URL. To update/redeploy an existing deployment, provide the deployment ID.</p> <h4>Options</h4> <ul><li><code>-V <version></code> <code>--versionNumber <version></code>: The project version to deploy at.</li> <li><code>-d <description></code> <code>--description <description></code>: The deployment description.</li> <li><code>-i <id></code> <code>--deploymentId <id></code>: The deployment ID to redeploy.</li></ul> <h4>Examples</h4> <ul><li><code>clasp create-deployment</code> (create new deployment and new version)</li> <li><code>clasp create-deployment --versionNumber 4</code> (create new deployment)</li> <li><code>clasp create-deployment --description "Updates sidebar logo."</code> (deploy with description)</li> <li><code>clasp create-deployment --deploymentId abcd1234</code> (redeploy and create new version)</li> <li><code>clasp create-deployment -V 7 -d "Updates sidebar logo." -i abdc1234</code></li></ul> <h3>Redeploy</h3> <p>Updates an existing deployment. Same as <code>create-deployment -i id</code>.</p> <h4>Options</h4> <ul><li><code>-V <version></code> <code>--versionNumber <version></code>: The project version to deploy at.</li> <li><code>-d <description></code> <code>--description <description></code>: The deployment description.</li></ul> <h4>Examples</h4> <ul><li><code>clasp update-deployment abcd1234</code> (redeploy and create new version)</li></ul> <h3>Undeploy</h3> <p>Undeploys a deployment of a script.</p> <h4>Options</h4> <ul><li><code>[deploymentId]</code>: An optional deployment ID.</li> <li><code>-a</code> <code>--all</code>: Undeploy all deployments.</li></ul> <h4>Examples</h4> <ul><li><code>clasp delete-deployment</code> (prompts for deployment or deletes if only one)</li> <li><code>clasp delete-deployment "123"</code></li> <li><code>clasp delete-deployment --all</code></li></ul> <h3>Version</h3> <p>Creates an immutable version of the script.</p> <h4>Options</h4> <ul><li><code>description</code>: description The description of the script version.</li></ul> <h4>Examples</h4> <ul><li><code>clasp create-version</code></li> <li><code>clasp create-version "Bump the version."</code></li></ul> <h3>Versions</h3> <p>List versions of a script.</p> <h4>Options</h4> <h4>Examples</h4> <ul><li><code>clasp list-versions</code>: List all versions for the current project</li> <li><code>clasp list-versions [scriptId]</code>: List all versions for a script ID</li></ul> <h3>List</h3> <p>Lists your most recent Apps Script projects.</p> <h4>Examples</h4> <ul><li><code>clasp list-scripts</code>: Prints <code>helloworld1 – xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...</code></li></ul> <h3>MCP (EXPERIMENTAL)</h3> <p>Runs clasp in MCP (model context protocol) mode for use with coding agents. Configure clasp as a local tool using STDIO transport. While running in MCP mode clasp uses the same credentials as normal when used as a CLI. Run <code>clasp login</code> ahead of time to authorize.</p> <p>When used in MCP mode clasp does not need to be started from the project directory. The project directoy is specified in the tool calls. Switching projects does not require a restart of the MCP server, while switching credentials does.</p> <p>This feature is experimental and currently offers a limited subset of tools for agents. Feedback is welcome.</p> <h4>Options</h4> <p>N/A</p> <h4>Examples</h4> <ul><li><code>clasp mcp</code></li></ul> <h2>Advanced Commands</h2> <blockquote><strong>NOTE</strong>: These commands require Project ID/credentials setup (<a href="#projectid-optional" target="_blank" rel="noopener">see below</a>).</blockquote> <h3>Setup Logs</h3> <p>Ensures your script is configured with a GCP project ID, which is required to view logs in Cloud Logging with <code>clasp logs</code>.</p> <h4>Options</h4> <ul><li><code>--json</code>: Output result in json format.</li></ul> <h4>Examples</h4> <ul><li><code>clasp setup-logs</code></li> <li><code>clasp setup-logs --json</code></li></ul> <h3>Logs</h3> <p>Prints out most recent the _Cloud Logging logs_. These are logs from <code>console.log</code>, not <code>Logger.log</code>.</p> <h4>Options</h4> <ul><li><code>--json</code>: Output logs in json format.</li> <li><code>--watch</code>: Retrieves the newest logs every 5 seconds.</li> <li><code>--simplified</code>: Removes timestamps from the logs.</li></ul> <h4>Examples</h4> <pre><code class="text">clasp logs ERROR Sat Apr 07 2019 10:58:31 GMT-0700 (PDT) myFunction my log error INFO Sat Apr 07 2019 10:58:31 GMT-0700 (PDT) myFunction info message</code></pre> <ul><li><code>clasp logs --json</code></li> <li><code>clasp logs --watch</code></li> <li><code>clasp logs --simplified</code></li></ul> <h3>Run</h3> <p>Remotely executes an Apps Script function.</p> <p>The complete step-by-step information on how to use <code>clasp run</code> is available here: <a href="/docs/run.md" target="_blank" rel="noopener">Run</a> Below is a short summary:</p> <ol><li>Log in with your credentials (<code>clasp login --creds creds.json</code>), see: <a href="/docs/run.md#prerequisites" target="_blank" rel="noopener">Run - Prerequisites</a></li> <li>Deploy the Script as an API executable (Easiest done via GUI at the moment).</li> <li>Enable any APIs that are used by the script, see: <a href="/docs/run.md#run-a-function-that-requires-scopes" target="_blank" rel="noopener">Run - Function with Scopes</a></li> <li>Have the following in your <code>appsscript.json</code>. Be sure it's pushed:</li></ol> <pre><code class="json">"executionApi": { "access": "ANYONE" }</code></pre> <h4>Options</h4> <ul><li><code><functionName></code>: The name of the function in the script that you want to run.</li> <li><code>--nondev</code>: If true, runs the function in non-devMode.</li> <li><code>-d <deploymentId></code> <code>--deployment-id <deploymentId></code>: The deployment ID to execute the function from.</li> <li><code>-p <paramString></code> <code>--params <paramString></code>: A JSON string array of parameters to pass to the function</li></ul> <h4>Examples</h4> <ul><li><code>clasp run-function 'sendEmail'</code></li> <li><code>clasp run-function 'addOptions' -p '["string", 123, {"test": "for"}, true]'</code></li> <li><code>clasp run-function 'sendEmail' --nondev --deployment-id <deploymentId></code></li></ul> <h3>List/Enable/Disable Google APIs</h3> <p>List available APIs. Enables and disables Google APIs.</p> <h4>List APIs</h4> <p>Lists Google APIs that can be enabled as <a href="https://developers.google.com/apps-script/guides/services/advanced" target="_blank" rel="noopener">Advanced Services</a>.</p> <ul><li><code>clasp list-apis</code></li> <li><code>clasp list-apis</code></li></ul> <h4>Enable/Disable APIs</h4> <p>Enables or disables APIs with the Google Cloud project. These APIs are used via services like GmailApp and Advanced Services like BigQuery.</p> <p>The API name can be found using <code>clasp apis list</code>.</p> <ul><li><code>clasp enable-api drive</code></li> <li><code>clasp disable-api drive</code></li></ul> <h4>Open APIs Console</h4> <p>Open the Google Cloud Console where you can view and manage API access.</p> <ul><li><code>clasp open-api-console</code></li></ul> <h3>Help</h3> <p>Displays the help function.</p> <h4>Examples</h4> <ul><li><code>clasp</code></li> <li><code>clasp help</code></li></ul> <h4>Clasp Run</h4> <blockquote><strong>NOTE</strong>: This command requires you to <a href="/docs/run.md" target="_blank" rel="noopener">bring your own Google API credentials</a>.</blockquote> <ul><li>[<code>clasp run-function [functionName] [--nondev] [--deployment-id <id>] [--params <StringArray>]</code>](#run)</li></ul> <h2>Troubleshooting</h2> <h3>NodeJS Version</h3> <p>The library requires <strong>NodeJS version >= 22.0.0</strong>.</p> <p>You can check your version of NodeJS with this command.</p> <pre><code class="sh">node -v</code></pre> <p>You can use these commands to upgrade NodeJS if necessary (<strong>not on Windows</strong>):</p> <pre><code class="sh">npm install -g npm # Update npm and npx npx n latest # use the n package to update node</code></pre> <h3>Debugging & filing issues</h3> <p>Clasp uses the <a href="https://www.npmjs.com/package/debug" target="_blank" rel="noopener">debug</a> library for internal logging. If you encounter an issue and want to file a bug report, please include a log with debugging enabled. Enable debugging by setting the envionment variable <code>DEBUG=clasp:*</code></p> <p>Example:</p> <pre><code class="sh">DEBUG=clasp:* clasp pull # Runs clasp with verbose debug output</code></pre> <h3>Using a Proxy</h3> <p>Clasp supports proxies via the Google APIs Node Module. See <a href="https://github.com/googleapis/google-api-nodejs-client#using-a-proxy" target="_blank" rel="noopener">"Using a Proxy"</a> and <a href="https://github.com/google/clasp/issues/8#issuecomment-427560737" target="_blank" rel="noopener">this discussion</a> for details on how to use the proxy. This requires using the environment variables <code>HTTP_PROXY</code> / <code>HTTPS_PROXY</code>.</p> <h2>README Badge</h2> <p>Using clasp for your project? Add a README badge to show it off: <a href="https://img.shields.io/badge/built%20with-clasp-4285f4.svg" target="_blank" rel="noopener"><img src="https://github.com/google/clasp" alt="clasp</a>" style="max-width:100%;"></p> <pre><code class="md"><a href="https://img.shields.io/badge/built%20with-clasp-4285f4.svg" target="_blank" rel="noopener"><img src="https://github.com/google/clasp" alt="clasp</a>" style="max-width:100%;"></code></pre> <h2>Develop clasp</h2> <p>See <a href="docs/develop.md" target="_blank" rel="noopener">the develop guide</a> for instructions on how to build <code>clasp</code>. It's not that hard!</p> <h2>Contributing</h2> <p>The main purpose of this tool is to enable local Apps Script development. If you have a core feature or use-case you'd like to see, find a GitHub issue or create a detailed proposal of the use-case. PRs are very welcome! See the <a href="https://github.com/google/clasp/issues" target="_blank" rel="noopener">issues</a> (especially <strong>good first issue</strong> and <strong>help wanted</strong>).</p> <p>⚡ Powered by the <a href="https://developers.google.com/apps-script/api/" target="_blank" rel="noopener">Apps Script API</a>.</p> </article> <!-- Article Completion Section --> <div class="reader-footer mt-5 pt-5"> <div class="reader-completion-box rounded-3 p-4 text-center"> <div class="reader-completion-icon mb-3"> <i class="fas fa-check-circle"></i> </div> <p class="reader-completion-text fw-semibold mb-1" style="font-size: 1rem;">You finished the article!</p> <p class="reader-completion-subtext small mb-4">Want to go deeper or explore more stories?</p> <div class="d-flex justify-content-center gap-3 flex-wrap"> <a href="https://github.com/google/clasp" target="_blank" rel="noopener noreferrer" class="btn btn-primary-custom btn-sm rounded-pill px-4"> <i class="fas fa-external-link-alt me-2"></i>Full Article on GitHub Trending </a> <a href="https://neshdevtech.com/news" class="reader-back-btn btn btn-sm rounded-pill px-4"> <i class="fas fa-newspaper me-2"></i>More Tech News </a> </div> </div> </div> <!-- Internal Linking CTA --> </div> </div> </div> <!-- Sidebar (desktop only) --> <div class="col-lg-4 col-xl-3 d-none d-lg-block"> <div class="sticky-top" style="top: 80px;"> <!-- Mini Controller Widget --> <div class="card border-0 shadow-sm mb-4 bg-surface"> <div class="card-body p-4"> <h6 class="fw-bold mb-3"><i class="fas fa-glasses me-2 text-primary-custom"></i>Reading Mode</h6> <p class="text-secondary-custom small mb-4">Adjust typography and theme to your preference.</p> <div class="mb-3"> <label class="text-muted-custom small d-block mb-2">Typography</label> <div class="d-flex gap-2"> <button class="btn btn-light btn-sm flex-grow-1 border-custom" id="sidebar-font-serif">Serif</button> <button class="btn btn-light btn-sm flex-grow-1 border-custom" id="sidebar-font-sans">Sans</button> </div> </div> <div class="mb-4"> <label class="text-muted-custom small d-block mb-2">Text Scale</label> <div class="d-flex gap-2"> <button class="btn btn-light btn-sm flex-grow-1 border-custom" id="sidebar-size-dec"><i class="fas fa-minus small"></i></button> <button class="btn btn-light btn-sm flex-grow-1 border-custom" id="sidebar-size-inc"><i class="fas fa-plus small"></i></button> </div> </div> <div class="border-top border-light-custom pt-3"> <a href="https://github.com/google/clasp" target="_blank" rel="noopener noreferrer" class="btn btn-outline-primary btn-sm w-100 rounded-pill"> View Original <i class="fas fa-external-link-alt ms-1"></i> </a> </div> </div> </div> <!-- Sidebar Related News --> <div class="card border-0 shadow-sm bg-surface"> <div class="card-header bg-transparent border-0 pt-4 pb-0 px-4"> <h5 class="card-title fw-bold mb-0" style="font-size: 1.05rem;"> <i class="fas fa-newspaper me-2 text-primary-custom"></i>Related Stories </h5> </div> <div class="card-body p-0"> <div class="list-group list-group-flush rounded-0 bg-transparent"> <a href="https://neshdevtech.com/news/intellectual-debt-after-generative-ai-heONb" class="list-group-item list-group-item-action border-0 px-4 py-3 bg-transparent border-bottom border-light-custom hover-bg-light"> <h6 class="mb-1 fw-semibold text-truncate-2" style="font-size: 0.875rem; line-height: 1.4;"> Intellectual Debt After Generative AI </h6> <div class="d-flex align-items-center justify-content-between text-muted-custom mt-1" style="font-size: 0.72rem;"> <span>Hacker News</span> <span>3 hours ago</span> </div> </a> <a href="https://neshdevtech.com/news/how-to-sell-a-mac-app-outside-the-app-store-2026-SFgmD" class="list-group-item list-group-item-action border-0 px-4 py-3 bg-transparent border-bottom border-light-custom hover-bg-light"> <h6 class="mb-1 fw-semibold text-truncate-2" style="font-size: 0.875rem; line-height: 1.4;"> How to Sell a Mac App Outside the App Store (2026) </h6> <div class="d-flex align-items-center justify-content-between text-muted-custom mt-1" style="font-size: 0.72rem;"> <span>Dev.to</span> <span>1 day ago</span> </div> </a> <a href="https://neshdevtech.com/news/masala-chai-episode-3-the-green-owl-that-became-everyones-nightmare-YxPjO" class="list-group-item list-group-item-action border-0 px-4 py-3 bg-transparent border-bottom border-light-custom hover-bg-light"> <h6 class="mb-1 fw-semibold text-truncate-2" style="font-size: 0.875rem; line-height: 1.4;"> Masala Chai – Episode 3 The Green Owl That Became Everyone's Nightmare </h6> <div class="d-flex align-items-center justify-content-between text-muted-custom mt-1" style="font-size: 0.72rem;"> <span>Dev.to</span> <span>1 day ago</span> </div> </a> <a href="https://neshdevtech.com/news/how-to-remove-image-backgrounds-without-uploading-or-installing-anything-apic-studio-7ebE1" class="list-group-item list-group-item-action border-0 px-4 py-3 bg-transparent border-bottom border-light-custom hover-bg-light"> <h6 class="mb-1 fw-semibold text-truncate-2" style="font-size: 0.875rem; line-height: 1.4;"> How to Remove Image Backgrounds Without Uploading or Installing Anything (APIC STUDIO) </h6> <div class="d-flex align-items-center justify-content-between text-muted-custom mt-1" style="font-size: 0.72rem;"> <span>Dev.to</span> <span>1 day ago</span> </div> </a> <a href="https://neshdevtech.com/news/anyone-can-be-a-founder-by-sunday-night-dtgWE" class="list-group-item list-group-item-action border-0 px-4 py-3 bg-transparent border-bottom border-light-custom hover-bg-light"> <h6 class="mb-1 fw-semibold text-truncate-2" style="font-size: 0.875rem; line-height: 1.4;"> Anyone can be a founder by Sunday night. </h6> <div class="d-flex align-items-center justify-content-between text-muted-custom mt-1" style="font-size: 0.72rem;"> <span>Dev.to</span> <span>1 day ago</span> </div> </a> </div> </div> </div> </div> </div> </div> <!-- Mobile: Related News horizontal scroll strip --> <div class="d-block d-lg-none mt-4"> <h6 class="fw-bold mb-3 px-1"> <i class="fas fa-newspaper me-2 text-primary-custom"></i>Related Stories </h6> <div class="related-scroll-strip"> <a href="https://neshdevtech.com/news/intellectual-debt-after-generative-ai-heONb" class="related-scroll-card"> <p class="related-scroll-title">Intellectual Debt After Generative AI</p> <div class="related-scroll-meta"> <span>Hacker News</span> <span>3 hours ago</span> </div> </a> <a href="https://neshdevtech.com/news/how-to-sell-a-mac-app-outside-the-app-store-2026-SFgmD" class="related-scroll-card"> <p class="related-scroll-title">How to Sell a Mac App Outside the App Store (2026)</p> <div class="related-scroll-meta"> <span>Dev.to</span> <span>1 day ago</span> </div> </a> <a href="https://neshdevtech.com/news/masala-chai-episode-3-the-green-owl-that-became-everyones-nightmare-YxPjO" class="related-scroll-card"> <p class="related-scroll-title">Masala Chai – Episode 3 The Green Owl That Became Everyone's Nightmare</p> <div class="related-scroll-meta"> <span>Dev.to</span> <span>1 day ago</span> </div> </a> <a href="https://neshdevtech.com/news/how-to-remove-image-backgrounds-without-uploading-or-installing-anything-apic-studio-7ebE1" class="related-scroll-card"> <p class="related-scroll-title">How to Remove Image Backgrounds Without Uploading or Installing Anythi...</p> <div class="related-scroll-meta"> <span>Dev.to</span> <span>1 day ago</span> </div> </a> <a href="https://neshdevtech.com/news/anyone-can-be-a-founder-by-sunday-night-dtgWE" class="related-scroll-card"> <p class="related-scroll-title">Anyone can be a founder by Sunday night.</p> <div class="related-scroll-meta"> <span>Dev.to</span> <span>1 day ago</span> </div> </a> </div> </div> </div> </section> </main> <!-- Footer --> <!-- Footer --> <footer class="py-5 mt-5 position-relative overflow-hidden" style="background: var(--surface); border-top: 1px solid var(--border); box-shadow: var(--shadow-lg);"> <!-- Decorative subtle background gradients --> <div class="position-absolute" style="top: -200px; right: -200px; width: 400px; height: 400px; background: rgba(var(--primary-rgb), 0.03); filter: blur(100px); border-radius: 50%; pointer-events: none;"></div> <div class="position-absolute" style="bottom: -200px; left: -200px; width: 400px; height: 400px; background: rgba(var(--accent-rgb), 0.03); filter: blur(100px); border-radius: 50%; pointer-events: none;"></div> <div class="container position-relative z-3"> <div class="row g-4"> <!-- Column 1: Brand & About --> <div class="col-lg-4 col-md-6"> <div class="d-flex align-items-center mb-3"> <span class="brand-mark me-2" style="width: 42px; height: 42px;" aria-hidden="true"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg> </span> <span class="fs-4 fw-extrabold text-primary-custom" style="letter-spacing: -0.05em; font-family: 'JetBrains Mono', monospace;">NeshDevTech</span> </div> <p class="text-secondary-custom mb-4 pe-lg-4" style="font-size: 0.95rem; line-height: 1.6;">NeshDevTech is a professional technology firm passionate about creating innovative, high-performance web and mobile solutions.</p> <div class="d-flex gap-2"> </div> </div> <!-- Column 2: Navigation Links --> <div class="col-lg-2 col-md-6 col-6"> <h6 class="text-primary-custom fw-bold text-uppercase mb-3" style="font-size: 0.85rem; letter-spacing: 0.05em;">Quick Navigation</h6> <ul class="list-unstyled mb-0"> <li class="mb-2"><a href="https://neshdevtech.com" class="footer-link text-secondary-custom text-decoration-none d-inline-block">Home</a></li> <li class="mb-2"><a href="https://neshdevtech.com/projects" class="footer-link text-secondary-custom text-decoration-none d-inline-block">Projects</a></li> <li class="mb-2"><a href="https://neshdevtech.com/blog" class="footer-link text-secondary-custom text-decoration-none d-inline-block">Tech Blog</a></li> <li class="mb-2"><a href="https://neshdevtech.com/pricing" class="footer-link text-secondary-custom text-decoration-none d-inline-block">Get Quote</a></li> <li class="mb-2"><a href="https://neshdevtech.com/contact" class="footer-link text-secondary-custom text-decoration-none d-inline-block">Contact Me</a></li> </ul> </div> <!-- Column 3: Tech Stack & Services --> <div class="col-lg-3 col-md-6 col-6"> <h6 class="text-primary-custom fw-bold text-uppercase mb-3" style="font-size: 0.85rem; letter-spacing: 0.05em;">Core Services</h6> <ul class="list-unstyled mb-0"> <li class="text-secondary-custom mb-2 small"><i class="bi bi-rocket-takeoff text-primary-custom me-2"></i>Custom Laravel Apps</li> <li class="text-secondary-custom mb-2 small"><i class="bi bi-laptop text-primary-custom me-2"></i>SPA (React & Vue.js)</li> <li class="text-secondary-custom mb-2 small"><i class="bi bi-phone-vibrate text-primary-custom me-2"></i>Flutter Mobile Apps</li> <li class="text-secondary-custom mb-2 small"><i class="bi bi-search text-primary-custom me-2"></i>SEO & Performance Opt</li> </ul> </div> <!-- Column 4: Contact & Availability --> <div class="col-lg-3 col-md-6"> <h6 class="text-primary-custom fw-bold text-uppercase mb-3" style="font-size: 0.85rem; letter-spacing: 0.05em;">Get in Touch</h6> <ul class="list-unstyled mb-3"> <li class="text-secondary-custom mb-2 small d-flex align-items-center"> <i class="bi bi-geo-alt text-primary-custom me-2 fs-6"></i>Nairobi, Kenya </li> <li class="text-secondary-custom mb-2 small d-flex align-items-center"> <i class="bi bi-envelope-at text-primary-custom me-2 fs-6"></i> <a href="mailto:info@neshdevtech.com" class="text-secondary-custom text-decoration-none footer-link">info@neshdevtech.com</a> </li> </ul> <div class="bg-primary-custom-light border border-primary-custom border-opacity-10 p-3 rounded-3" style="border-radius: 12px !important;"> <small class="d-block fw-semibold text-primary-custom mb-1"><i class="bi bi-patch-check-fill me-1"></i>Available for Projects</small> <p class="mb-0 text-secondary-custom small" style="font-size: 0.8rem; line-height: 1.4;">Need a high-performing system? Let's discuss your project.</p> </div> </div> </div> <hr style="border-color: var(--border); opacity: 0.8; margin: 2.5rem 0 2rem;"> <div class="row align-items-center"> <div class="col-md-6 text-center text-md-start mb-2 mb-md-0"> <p class="mb-0 text-secondary-custom small">© 2026 NeshDevTech. All rights reserved.</p> </div> <div class="col-md-6 text-center text-md-end"> <p class="mb-0 text-secondary-custom small">Built with <i class="bi bi-heart-fill text-danger"></i></p> </div> </div> </div> </footer> <!-- Bootstrap JS --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <!-- Custom JavaScript --> <script> // Theme Management System class ThemeManager { constructor() { this.themeToggle = document.getElementById('themeToggle'); this.themeIcon = document.getElementById('theme-icon'); this.mobileThemeToggle = document.getElementById('mobileThemeToggle'); this.mobileThemeIcon = document.getElementById('mobile-theme-icon'); this.init(); } init() { // Get current theme (already applied in head) const currentTheme = document.documentElement.getAttribute('data-theme') || 'light'; // Update icons to match current theme this.updateIcon(currentTheme); // Listen for desktop theme toggle clicks if (this.themeToggle) { this.themeToggle.addEventListener('click', (e) => { e.preventDefault(); this.toggleTheme(); }); } // Listen for mobile theme toggle clicks if (this.mobileThemeToggle) { this.mobileThemeToggle.addEventListener('click', (e) => { e.preventDefault(); this.toggleTheme(); }); } // Listen for system theme changes window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => { if (!localStorage.getItem('theme')) { this.setTheme(e.matches ? 'dark' : 'light'); } }); } setTheme(theme) { document.documentElement.setAttribute('data-theme', theme); document.documentElement.setAttribute('data-bs-theme', theme); if (theme === 'dark') { document.documentElement.classList.add('dark'); } else { document.documentElement.classList.remove('dark'); } localStorage.setItem('theme', theme); this.updateThemeColor(theme); this.updateIcon(theme); } updateThemeColor(theme) { document.querySelectorAll('meta[name="theme-color"]').forEach((meta) => { meta.setAttribute('content', theme === 'dark' ? '#1c2028' : '#e4e8f0'); }); } toggleTheme() { const currentTheme = document.documentElement.getAttribute('data-theme'); const newTheme = currentTheme === 'dark' ? 'light' : 'dark'; this.setTheme(newTheme); // Close mobile menu if open const navbarCollapse = document.querySelector('.navbar-collapse'); if (navbarCollapse && navbarCollapse.classList.contains('show') && window.innerWidth < 992) { setTimeout(() => { const bsCollapse = new bootstrap.Collapse(navbarCollapse, { toggle: false }); bsCollapse.hide(); }, 150); } } updateIcon(theme) { const iconClass = theme === 'dark' ? 'bi bi-sun-fill' : 'bi bi-moon-fill'; // Update desktop icon if (this.themeIcon) { this.themeIcon.className = iconClass; } // Update mobile icon if (this.mobileThemeIcon) { this.mobileThemeIcon.className = iconClass; } } } // Initialize theme manager when DOM is loaded document.addEventListener('DOMContentLoaded', () => { new ThemeManager(); // Initialize navbar live clock (function initNavClock(){ const clockEls = Array.from(document.querySelectorAll('[data-clock]')); if (!clockEls.length) return; const locale = navigator.language || 'en-US'; // Detect 12/24h by locale: use resolvedOptions hourCycle when available const dtf = new Intl.DateTimeFormat(locale, { hour: 'numeric' }); const uses12h = (dtf.resolvedOptions().hour12 === true); const fmt = new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: uses12h }); const update = () => { const now = new Date(); const text = fmt.format(now); clockEls.forEach(el => { el.textContent = text; }); }; update(); setInterval(update, 1000); })(); }); // Smooth scrolling for anchor links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); const target = document.querySelector(this.getAttribute('href')); if (target) { target.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }); }); // Navbar background on scroll window.addEventListener('scroll', () => { const navbar = document.querySelector('.navbar'); if (window.scrollY > 50) { navbar.style.backdropFilter = 'blur(20px)'; navbar.style.backgroundColor = 'rgba(var(--background-rgb), 0.8)'; } else { navbar.style.backdropFilter = 'blur(10px)'; navbar.style.backgroundColor = 'var(--background)'; } }); // Add fade-in animation to elements when they come into view const observerOptions = { threshold: 0.1, rootMargin: '0px 0px -50px 0px' }; const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('animate-fade-in-up'); } }); }, observerOptions); // Observe elements with animation class document.addEventListener('DOMContentLoaded', () => { document.querySelectorAll('.animate-on-scroll').forEach(el => { observer.observe(el); }); }); // Enhanced mobile menu functionality document.addEventListener('DOMContentLoaded', function() { const navbarToggler = document.querySelector('.navbar-toggler'); const navbarCollapse = document.querySelector('.navbar-collapse'); const navLinks = document.querySelectorAll('.navbar-nav .nav-link'); const socialLinks = document.querySelectorAll('.navbar-nav .d-flex a'); let isToggling = false; // Prevent rapid clicking // Enhanced menu close function function closeMenu() { if (navbarCollapse && navbarCollapse.classList.contains('show')) { // Use Bootstrap's collapse API for smooth transition const bsCollapse = new bootstrap.Collapse(navbarCollapse, { toggle: false }); bsCollapse.hide(); } // Reset hamburger animation and aria-expanded if (navbarToggler) { navbarToggler.classList.remove('active'); navbarToggler.setAttribute('aria-expanded', 'false'); } } // Enhanced hamburger toggle functionality if (navbarToggler) { navbarToggler.addEventListener('click', function(e) { e.preventDefault(); // Prevent rapid clicking if (isToggling) return; isToggling = true; const isMenuOpen = navbarCollapse.classList.contains('show'); if (isMenuOpen) { closeMenu(); } else { // Open menu const bsCollapse = new bootstrap.Collapse(navbarCollapse, { toggle: false }); bsCollapse.show(); navbarToggler.setAttribute('aria-expanded', 'true'); } // Reset toggle flag after animation setTimeout(() => { isToggling = false; }, 350); }); } // Close menu when clicking outside document.addEventListener('click', function(event) { const isClickInsideNav = navbarCollapse.contains(event.target); const isToggler = navbarToggler.contains(event.target); const isMenuOpen = navbarCollapse.classList.contains('show'); if (!isClickInsideNav && !isToggler && isMenuOpen && window.innerWidth < 992) { closeMenu(); } }); // Close menu when clicking on navigation links (mobile) navLinks.forEach(function(link) { link.addEventListener('click', function(e) { const isMenuOpen = navbarCollapse.classList.contains('show'); if (isMenuOpen && window.innerWidth < 992 && !this.classList.contains('dropdown-toggle')) { // Add a small delay to let the link navigation start setTimeout(() => { closeMenu(); }, 100); } }); }); // Close menu when clicking on social links (mobile) socialLinks.forEach(function(link) { link.addEventListener('click', function() { if (window.innerWidth < 992) { setTimeout(() => { closeMenu(); }, 100); } }); }); // Escape key closes menu document.addEventListener('keydown', function(event) { if (event.key === 'Escape' && window.innerWidth < 992) { closeMenu(); } }); // Handle window resize to close menu when switching to desktop window.addEventListener('resize', function() { if (window.innerWidth >= 992) { closeMenu(); } }); // Theme toggle functionality is handled by ThemeManager class // No separate event listener needed here // Prevent menu items from being too small on touch devices if ('ontouchstart' in window) { navLinks.forEach(function(link) { link.style.minHeight = '44px'; link.style.display = 'flex'; link.style.alignItems = 'center'; }); } // Add smooth scrolling for anchor links within pages navLinks.forEach(function(link) { const href = link.getAttribute('href'); if (href && href.startsWith('#')) { link.addEventListener('click', function(e) { e.preventDefault(); const target = document.querySelector(href); if (target) { target.scrollIntoView({ behavior: 'smooth', block: 'start' }); } closeMenu(); }); } }); }); </script> <script> // Sticky navbar scroll enhancement (desktop only) (function () { const navbar = document.querySelector('.navbar'); if (!navbar) return; let ticking = false; const SCROLL_THRESHOLD = 20; // px function updateNavbar() { if (window.innerWidth >= 992) { if (window.scrollY > SCROLL_THRESHOLD) { navbar.classList.add('scrolled'); } else { navbar.classList.remove('scrolled'); } } else { // Always remove on mobile so it doesn't affect mobile look navbar.classList.remove('scrolled'); } ticking = false; } window.addEventListener('scroll', function () { if (!ticking) { requestAnimationFrame(updateNavbar); ticking = true; } }, { passive: true }); window.addEventListener('resize', updateNavbar, { passive: true }); // Run once on page load in case page is already scrolled (e.g. back-navigation) updateNavbar(); })(); </script> <script> // Lightweight toast badge notifications (function(){ function ensureContainer(){ let c = document.getElementById('toast-badge-container'); if(!c){ c = document.createElement('div'); c.id = 'toast-badge-container'; c.setAttribute('aria-live','polite'); c.setAttribute('aria-atomic','true'); document.body.appendChild(c); } return c; } function iconFor(type){ switch(type){ case 'success': return '<i class="bi bi-check-circle"></i>'; case 'warning': return '<i class="bi bi-exclamation-triangle"></i>'; case 'error': return '<i class="bi bi-x-circle"></i>'; default: return '<i class="bi bi-info-circle"></i>'; } } window.notifyBadge = function(message, opts={}){ const { type = 'success', timeout = 2500 } = opts; const container = ensureContainer(); const el = document.createElement('div'); el.className = 'toast-badge ' + type; el.setAttribute('role','status'); el.innerHTML = '<span class="icon">'+iconFor(type)+'</span><span>'+message+'</span>'; container.appendChild(el); requestAnimationFrame(()=>{ el.classList.add('show'); }); const remove = () => { el.classList.remove('show'); setTimeout(()=> el.remove(), 200); }; setTimeout(remove, timeout); return { remove }; }; // Global copy helper used by inline buttons window.copyToClipboard = function(url){ try { navigator.clipboard.writeText(url).then(()=>{ // Update the clicked button, if available let btn = document.activeElement && document.activeElement.tagName === 'BUTTON' ? document.activeElement : (window.event && window.event.target && window.event.target.closest ? window.event.target.closest('button') : null); if (btn){ const original = btn.innerHTML; btn.innerHTML = '<i class="fas fa-check me-1"></i> Copied!'; btn.classList.remove('btn-outline-secondary'); btn.classList.add('btn-success'); setTimeout(()=>{ btn.innerHTML = original; btn.classList.remove('btn-success'); btn.classList.add('btn-outline-secondary'); }, 2000); } notifyBadge('Link copied to clipboard', { type: 'success' }); }).catch((err)=>{ console.error('Clipboard error:', err); notifyBadge('Could not copy link', { type: 'error' }); }); } catch (e) { console.error(e); notifyBadge('Copy not supported', { type: 'error' }); } }; })(); </script> <a href="https://wa.me/254768033943?text=Hi%2C+I+visited+your+website+and+would+like+to+inquire+about+your+services." class="whatsapp-btn-float" target="_blank" rel="noopener noreferrer" aria-label="Chat on WhatsApp"> <i class="fab fa-whatsapp"></i> <span class="whatsapp-tooltip">Chat with me</span> </a> <style> .whatsapp-btn-float { position: fixed; bottom: 24px; right: 24px; z-index: 1050; display: flex; align-items: center; justify-content: center; background-color: #25d366; color: #fff !important; width: 60px; height: 60px; border-radius: 50%; box-shadow: 0 4px 16px rgba(37, 211, 102, 0.45); text-decoration: none; transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); } .whatsapp-btn-float i { font-size: 32px; transition: transform 0.3s ease; } .whatsapp-btn-float:hover { background-color: #128c7e; transform: scale(1.1); box-shadow: 0 6px 20px rgba(18, 140, 126, 0.6); } .whatsapp-btn-float:hover i { transform: rotate(10deg); } /* Pulsing ring animation */ .whatsapp-btn-float::before { content: ''; position: absolute; width: 100%; height: 100%; border-radius: 50%; background-color: #25d366; opacity: 0.7; z-index: -1; animation: whatsapp-pulse 2s infinite; } @keyframes whatsapp-pulse { 0% { transform: scale(1); opacity: 0.7; } 100% { transform: scale(1.6); opacity: 0; } } /* Tooltip style utilizing site-wide theme colors */ .whatsapp-btn-float .whatsapp-tooltip { position: absolute; right: 76px; background-color: var(--surface); color: var(--text-primary); border: 1px solid var(--border); padding: 8px 14px; border-radius: 20px; font-size: 14px; font-weight: 600; white-space: nowrap; opacity: 0; visibility: hidden; transform: translateX(10px); transition: all 0.3s ease; box-shadow: var(--shadow); pointer-events: none; } .whatsapp-btn-float:hover .whatsapp-tooltip { opacity: 1; visibility: visible; transform: translateX(0); } /* Responsive Design */ @media (max-width: 768px) { .whatsapp-btn-float { bottom: 16px; right: 16px; width: 50px; height: 50px; } .whatsapp-btn-float i { font-size: 26px; } .whatsapp-btn-float .whatsapp-tooltip { display: none; /* Hide tooltip on small screens to prevent overlap issues */ } } </style> <!-- Mobile More Menu (Offcanvas Bottom Sheet) - Auth actions only --> <style> /* ══════════════════════════════════════════════════════════════ NEUMORPHISM REVAMP (front-end only) Soft-extruded UI: same-tone surfaces with dual light/dark shadows. This block sits at the end of the body so it layers over every page's own styles without touching page markup. ══════════════════════════════════════════════════════════════ */ /* ── Buttons: extruded, press-in on click ─────────────────────── */ .btn { box-shadow: var(--shadow) !important; transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important; } .btn:hover { transform: translateY(-2px) !important; box-shadow: var(--shadow-md) !important; } .btn:active:not(.btn-link), .btn.show { transform: translateY(1px) scale(0.99) !important; box-shadow: var(--shadow-inset) !important; } .btn-primary-custom, .btn-primary, .btn-success { background: var(--primary-color) !important; border-color: var(--primary-color) !important; color: #fff !important; box-shadow: var(--shadow) !important; } .btn-primary-custom:hover, .btn-primary:hover, .btn-success:hover { background: var(--primary-dark) !important; border-color: var(--primary-dark) !important; color: #fff !important; box-shadow: var(--shadow-md) !important; } .btn-outline-primary-custom, .btn-outline-primary, .btn-outline-success, .btn-outline-secondary, .btn-outline-danger, .btn-outline-dark, .btn-light { background-color: var(--surface) !important; border-color: transparent !important; color: var(--text-primary) !important; box-shadow: var(--shadow) !important; } .btn-outline-primary-custom:hover, .btn-outline-primary:hover { background-color: var(--primary-color) !important; border-color: var(--primary-color) !important; color: #fff !important; box-shadow: var(--shadow-md) !important; } .btn-outline-success:hover { background-color: var(--primary-color) !important; border-color: var(--primary-color) !important; color: #fff !important; box-shadow: var(--shadow-md) !important; } .btn-outline-secondary:hover { background-color: var(--text-secondary) !important; border-color: var(--text-secondary) !important; color: #fff !important; box-shadow: var(--shadow-md) !important; } .btn-outline-danger:hover { background-color: #ef4444 !important; border-color: #ef4444 !important; color: #fff !important; box-shadow: var(--shadow-md) !important; } .btn-outline-dark:hover, .btn-light:hover { background-color: var(--text-secondary) !important; border-color: var(--text-secondary) !important; color: var(--background) !important; box-shadow: var(--shadow-md) !important; } .btn-dark { background-color: var(--text-primary) !important; border-color: var(--text-primary) !important; color: var(--background) !important; box-shadow: var(--shadow) !important; } /* ── Forms: pressed-in surfaces ────────────────────────────────── */ .form-control, .form-select { background-color: var(--surface) !important; border: 1px solid transparent !important; color: var(--text-primary) !important; border-radius: 14px !important; box-shadow: var(--shadow-inset) !important; transition: box-shadow 0.3s ease, background-color 0.25s ease !important; } .form-control:focus, .form-select:focus { background-color: var(--surface) !important; border-color: transparent !important; color: var(--text-primary) !important; box-shadow: var(--shadow-inset), 0 0 0 4px rgba(var(--primary-rgb), 0.15) !important; } .form-control::placeholder { color: var(--text-muted) !important; } .input-group-text { background-color: var(--surface-alt) !important; border: 1px solid transparent !important; color: var(--text-secondary) !important; box-shadow: var(--shadow-inset-sm) !important; } /* ── Navbar: floating neumorphic pill (tablet & desktop) ──────── */ .navbar { background-color: rgba(var(--background-rgb), 0.9) !important; border-bottom: 1px solid transparent !important; backdrop-filter: blur(16px) !important; -webkit-backdrop-filter: blur(16px) !important; box-shadow: var(--shadow-md) !important; } [data-theme="dark"] .navbar { box-shadow: var(--shadow-md) !important; } @media (min-width: 768px) { .navbar { top: 14px !important; left: 18px !important; right: 18px !important; width: auto !important; border-radius: 20px !important; padding: 0.6rem 0 !important; box-shadow: var(--shadow-lg) !important; } [data-theme="dark"] .navbar { box-shadow: var(--shadow-lg) !important; } .navbar.scrolled { background-color: rgba(var(--background-rgb), 0.95) !important; border-bottom-color: transparent !important; padding: 0.5rem 0 !important; box-shadow: var(--shadow-lg) !important; } [data-theme="dark"] .navbar.scrolled { background-color: rgba(28, 32, 40, 0.95) !important; box-shadow: var(--shadow-lg) !important; } body { padding-top: 96px !important; } .reading-progress-container { top: 88px !important; } } /* ── Tablet refinements (768px - 991.98px) ────────────────────── */ @media (min-width: 768px) and (max-width: 991.98px) { /* Hamburger dropdown panel blends with the floating pill */ .navbar-collapse { border-radius: 20px !important; border-color: transparent !important; } body { padding-bottom: 0 !important; } .whatsapp-btn-float { bottom: 24px !important; } /* Hero: tighten the inline 80px top padding that assumed a full-height bar, so tablets don't get excessive empty space */ .hero-section-bg { padding-top: 40px !important; } } /* ── Neumorphic brand icon mark ────────────────────────────────── */ .brand-mark { width: 40px; height: 40px; flex-shrink: 0; border-radius: 13px; background-color: var(--surface) !important; color: var(--primary-color) !important; display: inline-flex; align-items: center; justify-content: center; box-shadow: var(--shadow) !important; transition: box-shadow 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1); } .brand-mark svg { width: 21px; height: 21px; } a:hover .brand-mark { box-shadow: var(--shadow-inset-sm) !important; transform: translateY(1px); } .mobile-logo .brand-mark { width: 34px; height: 34px; border-radius: 11px; } .mobile-logo .brand-mark svg { width: 17px; height: 17px; } /* ── Uploaded brand logo image ─────────────────────────────────── */ .brand-img { height: 38px; width: auto; max-width: 160px; object-fit: contain; flex-shrink: 0; } .brand-img-sm { height: 28px; max-width: 120px; } .brand-img-footer { height: 44px; max-width: 180px; } /* ── Mobile bars: floating neumorphic pills (phones) ──────────── */ @media (max-width: 767.98px) { .mobile-top-bar { top: 8px !important; left: 12px !important; right: 12px !important; height: 52px !important; border-radius: 16px !important; border-bottom: none !important; background-color: rgba(var(--surface-rgb), 0.92) !important; box-shadow: var(--shadow-md) !important; } .mobile-bottom-bar { left: 12px !important; right: 12px !important; bottom: 12px !important; height: 58px !important; border-radius: 18px !important; border-top: none !important; background-color: rgba(var(--surface-rgb), 0.92) !important; box-shadow: var(--shadow-md) !important; } body { padding-top: 74px !important; padding-bottom: 86px !important; } .whatsapp-btn-float { bottom: 88px !important; } .reading-progress-container { top: 70px !important; } } /* ── Nav pill widgets: pressed-in ──────────────────────────────── */ .theme-toggle, .mobile-theme-toggle, .nav-clock { background-color: var(--surface) !important; border-color: transparent !important; box-shadow: var(--shadow-inset-sm) !important; } /* ── Icon chips, markers & circles: extruded ───────────────────── */ .icon-wrap, .icon-wrapper, .expertise-card-icon, .timeline-marker, .mobile-more-icon-wrapper, .social-circle, .value-icon, .skill-icon-box { box-shadow: var(--shadow) !important; border-color: transparent !important; } /* ── Panels: extruded ──────────────────────────────────────────── */ .accordion-item { border-color: transparent !important; box-shadow: var(--shadow) !important; } .timeline-content { background: var(--surface) !important; border-radius: 12px !important; padding: 1rem 1.25rem !important; box-shadow: var(--shadow) !important; } .feature-item { background: var(--surface) !important; border-color: transparent !important; box-shadow: var(--shadow) !important; } .feature-item:hover { transform: translateY(-2px) !important; box-shadow: var(--shadow-md) !important; } .progress { background-color: var(--surface-alt) !important; box-shadow: var(--shadow-inset-sm) !important; } /* Card hover: consistent soft neu shadow */ .card-hover:hover, .project-card:hover, .blog-card:hover, .post-card:hover, .news-card:hover, .testimonial-card:hover, .hover-lift:hover, .stats-item:hover { box-shadow: var(--shadow-lg) !important; } </style> <script> document.addEventListener('DOMContentLoaded', function() { const readerCard = document.getElementById('reader-card'); if (!readerCard) return; // Settings Key constants const THEME_KEY = 'reader_mode_theme'; const FONT_KEY = 'reader_mode_font'; const SIZE_KEY = 'reader_mode_size'; // Available Options const themes = ['light', 'sepia', 'dark', 'oled']; const fonts = ['serif', 'sans']; const sizes = ['xs', 'sm', 'md', 'lg', 'xl']; // Default Configs const siteTheme = document.documentElement.getAttribute('data-theme') || 'light'; const defaultTheme = siteTheme === 'dark' ? 'dark' : 'light'; let currentTheme = localStorage.getItem(THEME_KEY) || defaultTheme; let currentFont = localStorage.getItem(FONT_KEY) || 'serif'; let currentSize = localStorage.getItem(SIZE_KEY) || 'md'; // Apply initial config applySettings(); // Register Action Listeners (Toolbar) document.getElementById('btn-font-serif').addEventListener('click', () => setFont('serif')); document.getElementById('btn-font-sans').addEventListener('click', () => setFont('sans')); document.getElementById('btn-size-decrease').addEventListener('click', () => adjustSize(-1)); document.getElementById('btn-size-increase').addEventListener('click', () => adjustSize(1)); document.getElementById('theme-light').addEventListener('click', () => setTheme('light')); document.getElementById('theme-sepia').addEventListener('click', () => setTheme('sepia')); document.getElementById('theme-dark').addEventListener('click', () => setTheme('dark')); document.getElementById('theme-oled').addEventListener('click', () => setTheme('oled')); // Register Action Listeners (Sidebar widgets, if present) const sidebarSerif = document.getElementById('sidebar-font-serif'); const sidebarSans = document.getElementById('sidebar-font-sans'); const sidebarSizeDec = document.getElementById('sidebar-size-dec'); const sidebarSizeInc = document.getElementById('sidebar-size-inc'); if (sidebarSerif) sidebarSerif.addEventListener('click', () => setFont('serif')); if (sidebarSans) sidebarSans.addEventListener('click', () => setFont('sans')); if (sidebarSizeDec) sidebarSizeDec.addEventListener('click', () => adjustSize(-1)); if (sidebarSizeInc) sidebarSizeInc.addEventListener('click', () => adjustSize(1)); // Action Core Functions function setTheme(theme) { currentTheme = theme; localStorage.setItem(THEME_KEY, theme); applySettings(); } function setFont(font) { currentFont = font; localStorage.setItem(FONT_KEY, font); applySettings(); } function adjustSize(delta) { let index = sizes.indexOf(currentSize); index = Math.max(0, Math.min(sizes.length - 1, index + delta)); currentSize = sizes[index]; localStorage.setItem(SIZE_KEY, currentSize); applySettings(); } function applySettings() { // 1. Reset theme classes and apply selected themes.forEach(t => readerCard.classList.remove('reader-theme-' + t)); readerCard.classList.add('reader-theme-' + currentTheme); // Update Theme circles highlight themes.forEach(t => { const circle = document.getElementById('theme-' + t); if (circle) { if (t === currentTheme) { circle.classList.add('active'); } else { circle.classList.remove('active'); } } }); // 2. Reset Font classes and apply selected fonts.forEach(f => readerCard.classList.remove('reader-font-' + f)); readerCard.classList.add('reader-font-' + currentFont); // Highlight Font buttons const serifBtns = [document.getElementById('btn-font-serif'), document.getElementById('sidebar-font-serif')]; const sansBtns = [document.getElementById('btn-font-sans'), document.getElementById('sidebar-font-sans')]; serifBtns.forEach(btn => { if (btn) { if (currentFont === 'serif') { btn.classList.add('btn-primary-custom'); btn.classList.remove('btn-light'); } else { btn.classList.add('btn-light'); btn.classList.remove('btn-primary-custom'); } } }); sansBtns.forEach(btn => { if (btn) { if (currentFont === 'sans') { btn.classList.add('btn-primary-custom'); btn.classList.remove('btn-light'); } else { btn.classList.add('btn-light'); btn.classList.remove('btn-primary-custom'); } } }); // 3. Reset Sizing classes and apply selected sizes.forEach(s => readerCard.classList.remove('reader-size-' + s)); readerCard.classList.add('reader-size-' + currentSize); } // Reading Scroll progress calculation const progressBar = document.getElementById('reading-progress-bar'); window.addEventListener('scroll', () => { const documentHeight = document.documentElement.scrollHeight - window.innerHeight; if (documentHeight > 0) { const scrollProgress = (window.pageYOffset / documentHeight) * 100; progressBar.style.width = scrollProgress + '%'; } }); }); </script> <script> // ══════════════════════════════════════════════════════════════ // PWA: Service Worker registration + install prompt // ══════════════════════════════════════════════════════════════ (function () { const PWA_VERSION = '20260805-1'; // ---- Service worker ------------------------------------ if ('serviceWorker' in navigator) { window.addEventListener('load', () => { navigator.serviceWorker.register('/sw.js?v=' + PWA_VERSION).then((reg) => { // Apply updates (new deploy) on the next load without disruption reg.addEventListener('updatefound', () => { const newWorker = reg.installing; if (!newWorker) return; newWorker.addEventListener('statechange', () => { if (newWorker.state === 'installed' && navigator.serviceWorker.controller) { newWorker.postMessage({ type: 'SKIP_WAITING' }); } }); }); }).catch(() => {}); }); } // ---- Install prompt -------------------------------------- let deferredPrompt = null; const bannerId = 'pwa-install-banner'; const DISMISS_KEY = 'nesh-install-dismissed'; function showInstallBanner() { if (localStorage.getItem(DISMISS_KEY) || document.getElementById(bannerId)) return; const banner = document.createElement('div'); banner.id = bannerId; banner.setAttribute('role', 'dialog'); banner.setAttribute('aria-label', 'Install app'); banner.innerHTML = '<div class="pwa-install-content">' + '<span class="pwa-install-icon">' + '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>' + '</span>' + '<div class="pwa-install-text">' + '<strong>Install NeshDevTech</strong>' + '<span>Get the app on your device</span>' + '</div>' + '<button type="button" class="pwa-install-btn" id="pwa-install-btn">Install</button>' + '<button type="button" class="pwa-install-close" id="pwa-install-close" aria-label="Dismiss">×</button>' + '</div>'; document.body.appendChild(banner); document.getElementById('pwa-install-btn').addEventListener('click', () => { if (!deferredPrompt) return; deferredPrompt.prompt(); deferredPrompt.userChoice.finally(() => { deferredPrompt = null; hideInstallBanner(); }); }); document.getElementById('pwa-install-close').addEventListener('click', () => { localStorage.setItem(DISMISS_KEY, '1'); hideInstallBanner(); }); requestAnimationFrame(() => banner.classList.add('show')); } function hideInstallBanner() { const banner = document.getElementById(bannerId); if (banner) { banner.classList.remove('show'); setTimeout(() => banner.remove(), 250); } } window.addEventListener('beforeinstallprompt', (e) => { e.preventDefault(); deferredPrompt = e; showInstallBanner(); }); window.addEventListener('appinstalled', () => { deferredPrompt = null; hideInstallBanner(); localStorage.setItem(DISMISS_KEY, '1'); }); })(); </script> <style> .pwa-install-content { display: flex; align-items: center; gap: 12px; padding: 14px 18px; } #pwa-install-banner { position: fixed; left: 50%; transform: translate(-50%, 20px); bottom: 84px; z-index: 1070; background: var(--surface); color: var(--text-primary); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .25s cubic-bezier(.16, 1, .3, 1), transform .25s cubic-bezier(.16, 1, .3, 1); width: min(420px, calc(100vw - 32px)); } #pwa-install-banner.show { opacity: 1; transform: translate(-50%, 0); } .pwa-install-icon { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; flex: 0 0 40px; border-radius: 12px; background: rgba(var(--primary-rgb), 0.1); border: 1px solid rgba(var(--primary-rgb), 0.2); color: var(--primary-color); } .pwa-install-icon svg { width: 20px; height: 20px; } .pwa-install-text { display: flex; flex-direction: column; flex: 1; min-width: 0; } .pwa-install-text strong { font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .pwa-install-text span { font-size: 0.78rem; color: var(--text-secondary); } .pwa-install-btn { background: var(--primary-color); border: none; color: #fff; font-weight: 600; font-size: 0.85rem; padding: 8px 18px; border-radius: 9999px; cursor: pointer; white-space: nowrap; box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.25); transition: all .2s ease; } .pwa-install-btn:hover { background: var(--primary-dark); transform: translateY(-1px); } .pwa-install-close { background: transparent; border: none; color: var(--text-muted); font-size: 1.4rem; line-height: 1; cursor: pointer; padding: 2px 6px; border-radius: 50%; transition: background-color .2s ease, color .2s ease; } .pwa-install-close:hover { background: var(--surface-alt); color: var(--text-primary); } @media (min-width: 992px) { #pwa-install-banner { bottom: 24px; } } </style> </div><!-- /.page-wrapper --> </body> </html>