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

@adamburgess/cloudflare-pages-direct-uploader

v1.7.1

Published

Directly create new Pages deploys using the Cloudflare API

Downloads

84

Readme

@adamburgess/cloudflare-pages-direct-uploader

Uploads a list of files or a directory directly to Cloudflare Pages using the Direct Upload Wrangler API.

npm version npm type definitions

Warning: Currently the API routes used are not documented/private. This could break at any time.

If you are using this on a version of Node <18, you must polyfill the global namespace with your own fetch, FormData, and Blob, e.g. with undici.

Usage (CLI):

CF_API_TOKEN=token CF_ACCOUNT_ID=id cloudflare-pages-direct-upload [--branch=BRANCH] PROJECT [DIRECTORY]
If directory is not specified, the current directory is used.

Usage (API):

import CFPagesUploader from '@adamburgess/cloudflare-pages-direct-uploader'

const uploader = new CFPagesUploader({
    // create an API Token with the "Account.Cloudflare Pages" permission, or use your global API key
    apiKey: 'XXXXXXXXX',
    // https://developers.cloudflare.com/fundamentals/get-started/basic-tasks/find-account-and-zone-ids/
    accountId: 'XXXXXXXXX',
    projectName: 'your-pages-name'
});

// all are optional. omit if you want.
const options = {
    branch: 'main',
    commitMessage: 'Deployment at ' + new Date().toString(),
    commitHash: 'abc123',
    headers: 'Contents of the _headers file',
    redirects: 'Contents of the _redirects file',
    worker: 'Contents of the _worker.js file',
    routes: 'Contents of the _routes.json file'
}
// note: when deploying a directory, the headers/redirects/worker files will be read from the disk.
//       they don't need to be specified.

// to upload a directory:
const deployment = await uploader.deployDirectory(directoryPath, options);

// to upload a list of files:
const files = [
    // normal usage, specify filename and content as a Buffer.
    { filename: 'index.html', content: Buffer.from('this is the index') },
    // optionally, specify a content-type:
    { filename: 'image.jxl', content: jxlBuffer, contentType: 'image/jxl' },
    // if the file is large, precompute and provide the hash for the file and set compute to an async function.
    // only if the file is necessary to upload will the function be called.
    // to precompute the hash, see the next section.
    { filename: 'large-file.zip', content: () => readFile('large-file.zip'), hash: 'XXXXXX' }
];
const deployment = await uploader.deployFiles(files, options);
/* deployment is: {
    url: link to the deployed page
    id: the unique id of this deployment
    hashes: a map of filename -> hash
}
*/
How to precompute the hash

If you don't know the hash for a file, just omit it, and then read the deployment object which has the hash.

Or:

import { computeHash } from '@adamburgess/cloudflare-pages-direct-uploader'
const hash = computeHash(content, filename);