@searchkings/gulp-gcs-upload
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Gulp Google Cloud Storage Upload

Upload files to Google Cloud Storage with Gulp

To generate GCS credentials:

$ gcloud auth application-default login --project <PROJECT_ID>

Install

npm install @searchkings/gulp-gcs-upload

Usage Example

import { Uploader } from '@searchkings/gulp-gcs-upload';

const bucketName: string = 'cdn-bucket';
const uploader = new Uploader({
  bucketName,
  cacheFilePath: path.resolve(homedir(), `.gcsupload-${bucketName}`),
  createOnly: true,
  uploadConcurrency: 20
});

return gulp
  .src(`${GLOBALS.CDN_COMMON_PATH}/**`)
  .pipe(uploader.upload())
  .pipe(uploader.report());

API

Uploader

constructor(pluginOptions: PluginOptions, storageOptions?: StorageOptions)

Create a new uploader with a set of plugin options and storage options.

Note: If you are not using Application Default Credentials (ADC), you must specify your preferred authentication method inside of the storage options.

interface PluginOptions {
  // Name of the bucket you wish to upload files to
  bucketName: string;

  // Local directory and file to store a cache of previously-uploaded files
  cacheFilePath?: string;

  // If true, files are considered immutable once uploaded, and will not be overwritten if a file with the same name exists. Default: false
  createOnly?: boolean;

  // Number of simultaneous file uploads. Default: 1
  uploadConcurrency?: number;
}

.upload(uploadOptions?: UploadOptions)

Uploads your stream of files to the GCS bucket with optional upload options you define.

.report(reportOptions?: ReportOptions)

Outputs a report with the state of each file that passed through the .upload() stream.

export type FileState = 'cache' | 'skip' | 'update' | 'create';

interface ReportOptions {
  // List of states you wish to see included in the output
  states?: FileState[];
}

Development

$ npm install
$ npm start

Package Sidebar

Install

npm i @searchkings/gulp-gcs-upload

Weekly Downloads

6

Version

1.0.5

License

MIT

Unpacked Size

18.9 kB

Total Files

10

Last publish

Collaborators

  • baileycassel
  • rosslavery
  • giansk
  • weizhong
  • glomlapay
  • usundara