Static web publishing CLI tool for deploying web applications to a CDN with a single command
—
Primary publishing functionality for deploying static sites to the Surge CDN. Handles project detection, domain management, file upload, and deployment lifecycle.
Main deployment command that publishes a local directory to the Surge CDN.
/**
* Publish static files to Surge CDN
* @param hooks - Optional lifecycle hooks
* @returns Command function
*/
function publish(hooks?: HookConfig): CommandFunction;CLI Usage:
# Interactive mode (prompts for path and domain)
surge
# Specify path and domain
surge ./build example.surge.sh
# With options
surge --project ./dist --domain mysite.surge.sh
# Preview mode (staging)
surge --stage
surge --previewCLI Options:
-p, --project: Project directory path-d, --domain: Target domain name-s, --stage, --preview: Deploy to preview/staging environmentLibrary Usage:
const surge = require('surge')();
// Basic publish
surge.publish({})(process.argv.slice(2));
// With hooks
surge.publish({
preAuth: (req, next) => {
console.log(`Publishing to ${req.domain}`);
next();
},
postPublish: (req, next) => {
console.log('Deploy successful!');
next();
}
})(process.argv.slice(2));Publishing Process:
Remove a published project from the Surge platform.
/**
* Remove published project from platform
* @param hooks - Optional lifecycle hooks
* @returns Command function
*/
function teardown(hooks?: HookConfig): CommandFunction;CLI Usage:
# Interactive domain selection
surge teardown
# Specify domain
surge teardown example.surge.shLibrary Usage:
surge.teardown({})(process.argv.slice(2));Permanently removes the project and all its files from the Surge CDN. The domain becomes available for reuse.
Display all published projects or revisions for a specific project.
/**
* List all projects or project revisions
* @param hooks - Optional lifecycle hooks
* @returns Command function
*/
function list(hooks?: HookConfig): CommandFunction;CLI Usage:
# List all projects
surge list
# List revisions for specific project
surge list example.surge.shDisplays projects in a formatted table with domain names, file counts, and deployment dates.
Library Usage:
surge.list({})(process.argv.slice(2));Display all files in a specific published project.
/**
* List all files in a published project
* @param hooks - Optional lifecycle hooks
* @returns Command function
*/
function files(hooks?: HookConfig): CommandFunction;CLI Usage:
# List files in project
surge files example.surge.shShows all files in the project with paths, sizes, and modification times.
Library Usage:
surge.files({})(process.argv.slice(2));Surge automatically discovers domains through several methods:
CNAME file in project rootSurge supports all static file types including:
CNAME: Domain configuration (not uploaded)200.html: SPA fallback for client-side routing404.html: Custom 404 error page.surgeignore: File ignore patterns (similar to .gitignore)Use 200.html file for single-page applications with client-side routing:
<!-- 200.html -->
<!DOCTYPE html>
<html>
<head>
<title>My SPA</title>
</head>
<body>
<div id="app"></div>
<script src="/app.js"></script>
</body>
</html># Travis CI example
script:
- npm run build
- surge --project ./build --domain $SURGE_DOMAIN// Gulp example
gulp.task('deploy', function() {
return surge({
project: './build',
domain: 'example.surge.sh'
});
});All publishing commands provide detailed error messages and suggested resolutions.
Install with Tessl CLI
npx tessl i tessl/npm-surge