Static web publishing CLI tool for deploying web applications to a CDN with a single command
npx @tessl/cli install tessl/npm-surge@0.24.0Surge is a command-line interface (CLI) tool for static web publishing that enables developers to deploy web applications to a CDN with a single command and no setup required. It provides a simple workflow for publishing static sites, single-page applications, and compiled web assets to the surge.sh hosted service.
npm install -g surge (global) or npm install surge (local)Library usage:
const surge = require('surge');With configuration:
const surge = require('surge')({
endpoint: 'https://surge.surge.sh',
platform: 'surge.sh',
name: 'surge',
default: 'publish'
});# Install globally
npm install -g surge
# Basic publishing (interactive)
surge
# Publish specific directory to domain
surge ./build example.surge.sh
# Login first
surge login
# List projects
surge list
# Teardown a project
surge teardown example.surge.shconst surge = require('surge')();
// Programmatic publishing
surge.publish({})(process.argv.slice(2));
// With hooks
surge.publish({
preAuth: (req, next) => {
console.log('Before authentication');
next();
},
postPublish: (req, next) => {
console.log('Deploy complete!');
next();
}
})(process.argv.slice(2));Surge is built around several key components:
Core authentication functionality for managing user credentials and account access. Essential for all publishing operations.
// Authentication commands
function login(hooks?: HookConfig): CommandFunction;
function logout(hooks?: HookConfig): CommandFunction;
function whoami(hooks?: HookConfig): CommandFunction;
function token(hooks?: HookConfig): CommandFunction;Primary publishing functionality for deploying static sites to the Surge CDN. Includes project detection, domain management, and file upload.
// Main publishing command
function publish(hooks?: HookConfig): CommandFunction;
// Project teardown
function teardown(hooks?: HookConfig): CommandFunction;
// Project listing
function list(hooks?: HookConfig): CommandFunction;
function files(hooks?: HookConfig): CommandFunction;Version control functionality for managing different revisions of deployed projects, enabling rollbacks and staged deployments.
// Revision commands
function rollback(hooks?: HookConfig): CommandFunction;
function rollfore(hooks?: HookConfig): CommandFunction;
function cutover(hooks?: HookConfig): CommandFunction;
function discard(hooks?: HookConfig): CommandFunction;
function select(hooks?: HookConfig): CommandFunction;SSL certificate management including Let's Encrypt integration and custom certificate upload for secure HTTPS deployments.
// SSL commands
function ssl(hooks?: HookConfig): CommandFunction;
function encrypt(hooks?: HookConfig): CommandFunction;
function certs(hooks?: HookConfig): CommandFunction;Comprehensive DNS management for custom domains, including zone management and record manipulation.
// DNS commands
function dns(hooks?: HookConfig): CommandFunction;
function zone(hooks?: HookConfig): CommandFunction;Analytics and monitoring capabilities for tracking traffic, performance, and usage metrics of deployed projects.
// Analytics commands
function analytics(hooks?: HookConfig): CommandFunction;
function traffic(hooks?: HookConfig): CommandFunction;
function load(hooks?: HookConfig): CommandFunction;
function audience(hooks?: HookConfig): CommandFunction;
function usage(hooks?: HookConfig): CommandFunction;
function audit(hooks?: HookConfig): CommandFunction;
function bust(hooks?: HookConfig): CommandFunction;Account and billing management including plan upgrades, payment methods, and account deletion.
// Account commands
function plan(hooks?: HookConfig): CommandFunction;
function card(hooks?: HookConfig): CommandFunction;
function plus(hooks?: HookConfig): CommandFunction;
function nuke(hooks?: HookConfig): CommandFunction;User collaboration features for managing project access and team permissions.
// Collaboration commands
function invite(hooks?: HookConfig): CommandFunction;
function revoke(hooks?: HookConfig): CommandFunction;Project and platform configuration management.
// Configuration command
function config(hooks?: HookConfig): CommandFunction;// Factory configuration options
interface SurgeConfiguration {
endpoint?: string; // API endpoint (default: 'https://surge.surge.sh')
platform?: string; // Platform domain (default: 'surge.sh')
name?: string; // CLI name (default: 'surge')
default?: string; // Default command (default: 'publish')
}
// Hook configuration for lifecycle customization
interface HookConfig {
preAuth?: MiddlewareFunction;
postAuth?: MiddlewareFunction;
preProject?: MiddlewareFunction;
postProject?: MiddlewareFunction;
preSize?: MiddlewareFunction;
postSize?: MiddlewareFunction;
preDomain?: MiddlewareFunction;
postDomain?: MiddlewareFunction;
prePublish?: MiddlewareFunction;
postPublish?: MiddlewareFunction;
}
// Middleware function signature
type MiddlewareFunction = (req: RequestObject, next: NextFunction, abort?: AbortFunction) => void;
type NextFunction = (error?: Error) => void;
type AbortFunction = (message?: string) => void;
// Command function signature
type CommandFunction = (argv: ParsedArguments) => void;
// Request object passed through middleware
interface RequestObject {
argv: ParsedArguments;
configuration: SurgeConfiguration;
endpoint: EndpointInfo;
creds: Credentials;
account: AccountInfo;
domain?: string;
project?: string;
fileCount?: number;
projectSize?: number;
}
// Parsed command line arguments
interface ParsedArguments {
_: string[]; // Positional arguments
project?: string; // -p, --project
domain?: string; // -d, --domain
endpoint?: string; // -e, --endpoint
add?: string; // -a, --add
remove?: string; // -r, --remove
stage?: boolean; // -s, --stage, --preview
message?: string; // -m, --message
[key: string]: any;
}