Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Defining useful additionalTasks is extremely confusing #478

Closed
toolness opened this issue Jul 14, 2017 · 6 comments
Closed

Defining useful additionalTasks is extremely confusing #478

toolness opened this issue Jul 14, 2017 · 6 comments

Comments

@toolness
Copy link

The additionalTasks documentation doesn't actually define any useful real-world tasks, such as simply copying files from one directory to another. I tried adding a task that does this to my initialize function, and then running it as part of my prebuild step:

  additionalTasks: {
    initialize(gulp, PATH_CONFIG, TASK_CONFIG) {
      gulp.task('copy-package-json', () => {
        return gulp.src('./package.json')
          .pipe(gulp.dest('./public/'));
      });
    },
    development: {
      prebuild: ['copy-package-json'],
      postbuild: [],
    },
    production: {
      prebuild: [],
      postbuild: [],
    }
  }

The copy-package-json task executes when I run blendid but it doesn't seem to copy the package.json file in the root directory of my project into the public directory. I thought perhaps this might be because my public directory is being wiped after the prebuild tasks execute, so I moved the task to postbuild, but then the task doesn't seem to get run at all (in fact, blendid only runs the default and clean tasks when I do this, whereas it runs a bunch of tasks when I put copy-package-json in prebuild).

I recommend modifying the documentation so that at least one useful task is defined, so that readers have a better mental model for how to leverage additionalTasks for their needs.

@dillonbailey
Copy link
Contributor

@toolness I set this GIST up with a useful(ish) additional task that copies a .liquid extended version of app.css over to assets for Shopify.

https://gist.github.com/dillonbailey/c06b1ee88ab1432435515c65840daf74

@codyellingham
Copy link

codyellingham commented Sep 22, 2018

@dillonbailey Thanks for that. I am having same problem as @toolness. The task is running but nothing is being outputted.

I would like to use https://yarnpkg.com/en/package/gulp-sitemap

  additionalTasks: {
    initialize(gulp, PATH_CONFIG, TASK_CONFIG) {

      gulp.task('sitemap', function () {
          gulp.src('./public/**/*.html', {
                  read: false
              })
              .pipe(sitemap({
                  siteUrl: 'http://example.com'
              }))
              .pipe(gulp.dest('./public'));
      });
    },
     development: {
      prebuild: null,
      postbuild: ['sitemap'],
    },
    production: {
      prebuild: null,
      postbuild: null,
    }
  }

@dillonbailey
Copy link
Contributor

@cbje-tokyo are you requiring gulp-sitemap at the top of the file? You may need to be more explicit with your gulp.src() and gulp.dest()declarations per the example gist

@codyellingham
Copy link

@dillonbailey Thank you, I have tried to update it:

const path = require('path');
const gulp = require('gulp');
const sitemap = require('gulp-sitemap');
const notify = require('gulp-notify');

module.exports = {
  html: true,
  images: true,
  fonts: true,
  static: true,
  svgSprite: true,
  media: true,
  ghPages: true,
  stylesheets: true,

  javascripts: {
    entry: {
      // files paths are relative to
      // javascripts.dest in path-config.json
      app: ["./app.js"]
    },
    provide: {
      $: "jquery",
      jQuery: "jquery",
      "window.jQuery": "jquery"
    }
  },

  browserSync: {
    server: {
      // should match `dest` in
      // path-config.json
      baseDir: 'public'
    }
  },

  production: {
    rev: false
  },

  additionalTasks: {
  initialize(gulp, PATH_CONFIG, TASK_CONFIG) {

      const paths = {
        src: path.dirname('/public'),
        dest: path.dirname('/public')
      }

      gulp.task('sitemap', function () {
       gulp.src(paths.src + '/*.html', {
               read: false
           })
           .pipe(sitemap({
               siteUrl: 'http://example.com'
           }))
           .pipe(gulp.dest(paths.dest))
           .pipe(notify('sitemap saved'));
         });
    },
    production: {
      postbuild: ['sitemap']
    }
  }

}

The task runs but nothing is outputted:
screen shot 2018-09-24 at 17 33 37

@dillonbailey
Copy link
Contributor

@cbje-tokyo couple of options I can think of.

  1. One of the best things to do is to run a test with the task outside of Blendid. So run a blendid build and then set up a completely separate gulp task for your sitemap and run it against the directory to see if it works. This can rule out any issues with the sitemap extension itself.
  2. Share your project repo with me and I'll take a look mate.

Cheers

@olets
Copy link
Contributor

olets commented May 28, 2019

The original issue appears to be an instance of #579. Closing in favor of that.

@cbje-tokyo feel free to open a new issue if you're having a different problem

@dillonbailey 🏆 thanks for the support

@olets olets closed this as completed May 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants