Code Monkey home page Code Monkey logo

gulp-gcloud-publish's Introduction

gulp-gcloud-publish

NPM Build Status Code Coverage Code Quality Dependencies Status

Upload files to Google Cloud Storage with Gulp

Install

npm install --save-dev gulp-gcloud-publish

Usage

First, you need to create your Google Cloud API credentials. Official Docs.

The plugin takes a configuration object with the following keys:

  • bucket String: Name of the bucket where we want to upload the file
  • gzip Boolean (optional): Let Google automatically gzip and mark metadata of your file. Regardless of this setting, already-gzipped files will have metadata properly set.
  • keyFilename String: Full path to the Google Cloud API keyfile (docs)
  • projectId String: Google Cloud Project ID (docs)
  • base String: base path to use in the bucket, default to /
  • public Boolean (optional): If set to true, marks the uploaded file as public
  • resumable Boolean (optional): Should be set to true for large files (>10Mb). Default is false.
  • transformDestination Function (optional): Manipulates the final destination of the file in the bucket.

Example

If you would like to gzip the files, the plugin works best with gulp-gzip.

var gulp = require('gulp');
var gcPub = require('gulp-gcloud-publish');
var gzip = require('gulp-gzip'); // optional

gulp.task('publish', function() {

  return gulp.src('public/css/example.css')
      .pipe(gzip()) // optional
      .pipe(gcPub({
        bucket: 'bucket-name',
        keyFilename: 'path/to/keyFile.json',
        projectId: 'my-project-id',
        base: '/css',
        public: true,
        transformDestination: function(path) {
          return path.toLowerCase();
        },
        metadata: {
            cacheControl: 'max-age=315360000, no-transform, public',
        }
      })); // => File will be uploaded to /bucket-name/css/example.css
});

gulp-gcloud-publish's People

Contributors

albertorestifo avatar bobvanluijt avatar dependabot[bot] avatar ruidfigueiredo avatar rusucosmin avatar scitech avatar sethvargo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gulp-gcloud-publish's Issues

metadata options

is the metadata options being honored. I tried to specify the metadata option and its not working. I even used your example for setting cachecontrol. Please advise

[22:53:56] TypeError: file.pipe is not a function

Uploading CSS/JS to GCP is simply not working and throwing this strange error.
TypeError: file.pipe is not a function

Here are my gulp dependencies that I am loading:

const autoprefixer = require("autoprefixer"); // v 9.5.1
const cssnano = require("cssnano"); // v 4.1.10
const { src, dest, watch, series, parallel } = require("gulp"); // v 4.0.1
const postcss = require("gulp-postcss"); // v 8.0.0"
const sass = require("gulp-sass"); // v 4.0.2
const uglify = require('gulp-uglify'); // v 3.0.2
const jshint = require('gulp-jshint'); // v 2.1.0
var gcPub = require('gulp-gcloud-publish'); // v 2.1.1
//var gzip = require('gulp-gzip'); // v 1.4.2
var log = require('fancy-log'); // v 1.3.3

Here are my file paths for my SCSS and JS files:

const files = {
  scssPath: './src/scss/**/*.scss',
  jsPath: 'src/js/**/*.js'
}

Here is my deploy task I have for compiling my SASS and uploading the compiled CSS file to my GCP bucket (I am passing the SCSS file path to the gulp src function):

function scssTaskGCP() {
  return src(files.scssPath)
    .pipe(sass())
    .pipe(postcss([ autoprefixer(), cssnano()]))
    .pipe(gcPub(
      {
        bucket: 'bucket-name',
        keyFilename: process.env.GCP_KEY_FILE,
        projectId: process.env.GCP_PROJECT_ID,
        base: '/assets/css',
        public: true,
        resumable: true,
        transformDestination: function(path) {
          return path.toLowerCase();
        },
        metadata: {
          cacheControl: 'max-age=315360000, no-transform, public',
        }
      }
    ));
}

When the scssTaskGCP() task is run via my CI/CD pipeline, I receive this error message:

+ gulp deploy
[22:32:36] Using gulpfile /opt/atlassian/pipelines/agent/project-folder/hca-craft/gulpfile.js
[22:32:36] Starting 'deploy'...
[22:32:36] Starting 'scssTaskGCP'...
[22:32:37] 'scssTaskGCP' errored after 846 ms
**[22:32:37] TypeError: file.pipe is not a function**
    **at DestroyableTransform._transform (/opt/atlassian/pipelines/agent/build/project-folder/node_modules/gulp-gcloud-publish/libs/index.js:113:10)**
   ...
[22:32:37] 'deploy' errored after 848 ms

I have been pulling my hair out trying to figure out what I'm doing wrong, and figured it could be a gulp 4 incompatibility issue. May you please be able to assist/investigate? Thanks!

DeprecationWarning

I'm now seeing this:

(node:19678) DeprecationWarning: Using Buffer without 'new' will soon stop working. Use 'new Buffer()', or preferably 'Buffer.from()', 'Buffer.allocUnsafe()' or 'Buffer.alloc()' instead.

This is happening with every asset uploaded.

A

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.