npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

snap-push

v6.1.1

Published

Deliver static website files to Amazon S3, Azure or Google Cloud.

Downloads

116

Readme

snap-push - Upload static website files to the cloud

Highlights

  • Upload with support for:
    • Amazon S3
    • Azure
    • Google Cloud Storage
    • MinIO
  • Automatically detect and set correct Content-Type for uploaded files.
  • Create gzip and br compressed versions of uploaded file and set the appropriate Content-Encoding.
  • Set custom Cache-Control.
  • Concurrent uploads.
  • Only upload changed files.
  • Remove files that were deleted locally.
  • Prioritise upload of new files first.
  • Dry Run / Pretend mode

Installation

For Amazon S3

yarn add snap-push @aws-sdk/client-s3 @aws-sdk/lib-storage

or use npm

npm install snap-push @aws-sdk/client-s3 @aws-sdk/lib-storage

For Azure Storage

yarn add snap-push @azure/storage-blob

For Google Cloud Storage

yarn add snap-push @google-cloud/storage

Basic Usage

snap-push can be used as a command line utility or as a library. For example, to push all the files in the dist folder to the root of the example-bucket S3 bucket and make them public:

Command line

$ cd dist && ../node_modules/.bin/snap-push './**/*' s3://example-bucket --public

Using the Library with S3

CommonJS require

const push = require('snap-push').default;
const s3FileProvider = require('snap-push/s3').default;

ES Modules import

import push from 'snap-push';
import s3FileProvider from 'snap-push/s3';

Code

const providerOptions = {
  bucket: 'example-bucket',
  region: 'ap-southeast-2',
};

(async () => {
  const result = await push({
    currentWorkingDirectory: 'directory-to-upload',
    files: './**/*',
    makePublic: true,
    provider: s3FileProvider(providerOptions),
  });

  console.log(result);
})();

Using the Library with Azure

CommonJS require

const push = require('snap-push').default;
const azureFileProvider = require('snap-push/azure').default;

ES Modules import

import push from 'snap-push';
import azureFileProvider from 'snap-push/azure';

Code

const providerOptions: AzureProviderOptions = {
  credential: new StorageSharedKeyCredential(
    'my-account-name',
    'my-account-key'
  ),
  serviceUrl: `https://myaccount.blob.core.windows.net/`,
  containerName: `my-test-container`,
};

(async () => {
  const result = await push({
    currentWorkingDirectory: 'directory-to-upload',
    files: './**/*',
    makePublic: true,
    provider: azureFileProvider(providerOptions),
  });

  console.log(result);
})();

Using the Library with Google Cloud Storage

CommonJS require

const push = require('snap-push').default;
const gcpFileProvider = require('snap-push/gcp').default;

ES Modules import

import push from 'snap-push';
import gcpFileProvider from 'snap-push/gcp';

Code

const providerOptions = {
  bucket: 'example-bucket'
};

(async () => {
  const result = await push({
    currentWorkingDirectory: 'directory-to-upload',
    files: './**/*',
    makePublic: true,
    provider: gcpFileProvider(providerOptions),
  });

  console.log(result);
})();

Using the Library with Cloudflare R2

CommonJS require

const push = require('snap-push').default;
const s3FileProvider = require('snap-push/s3').default;

ES Modules import

import push from 'snap-push';
import s3FileProvider from 'snap-push/s3';

Code

const providerOptions = {
  bucket: 'example-bucket',
  region: 'auto',
  endpoint: `https://my-region-endpoint.r2.cloudflarestorage.com`,
  credentials: {
    accessKeyId: 'my-account-key',
    secretAccessKey: 'my-secret-access-key',
  },
};

(async () => {
  const result = await push({
    currentWorkingDirectory: 'directory-to-upload',
    files: './**/*',
    makePublic: true,
    provider: s3FileProvider(providerOptions),
  });

  console.log(result);
})();

Auto compression

Files uploaded with specific fileExtensions or mimeTypes could be automatically compressed with br (Brotli) and/or gzip (GZip) using the encoding option. This is useful when used in conjuction with a CDN with rules to route requests with the appropriate Accept-Encoding to the compressed copy.

Examples

Encode files with .txt or .html file name extensions or mime/content-type containing text or xml, with raw (orginal, no encoding), br (brotli) and gz (gzip) encodings. raw will have the original file name. br will have a the original file name appended with .br, and gzip original appended with .gz.

const result = await push({
  currentWorkingDirectory: 'dist',
  files: './**/*',
  makePublic: true,
  encoding: {
    fileExtensions: ['txt', 'html'],
    mimeTypes: [/text/, /xml/],
    contentEncodings: ['raw', 'br', 'gzip'],
  },
  provider: s3FileProvider(providerOptions),
});

Encode files with gzip using the original file name.

const result = await push({
  currentWorkingDirectory: 'dist',
  files: './**/*',
  makePublic: true,
  encoding: (fileName) => {
    return [
      {
        destFileName: fileName,
        encoding: 'gzip',
      },
    ];
  },
  provider: s3FileProvider(providerOptions),
});