Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does asset-builder respect Gulp's cwd option? #51

Open
cibulka opened this issue Sep 19, 2015 · 4 comments
Open

Does asset-builder respect Gulp's cwd option? #51

cibulka opened this issue Sep 19, 2015 · 4 comments

Comments

@cibulka
Copy link

cibulka commented Sep 19, 2015

Hello!

I use Asset-builder with gulp-hub plugin, that allows to run tasks from multiple Gulpfiles specified at project's root.

This is a simplified version of my setup:

|-- project
|-- |-- gulpfile.js                       // Contains gulp-hub setup
|-- |-- /plugin-1
|-- |--  |-- /assets
|-- |--  |-- |-- manifest.json  // Sass task, containing asset-manifest
|-- |--  |-- /dist
|-- |--  |-- gulpfile.js
|-- |-- /plugin-2
|-- |--  |-- /assets
|-- |--  |-- |-- manifest.json  // Sass task, containing asset-manifest
|-- |--  |-- /dist
|-- |--  |-- gulpfile.js

This way, I can run ...

cd project
gulp sass

... to avoid manually CDing to each plugin folder and all the relevant files are watched by Gulp as they supposed to.

This setup works with asset manifest only if I hardcode absolute paths to manifest.json.

// This works
paths: {
  source: "/absolute/path/to/project/plugin-1/assets/",
  dist: "/absolute/path/to/project/plugin-1/dist/"
}

// I would prefer this though
paths: {
  source: "assets/",
  dist: "dist/"
}

I tried to make it work by specifying cwd option to my (e.g.) sass task like this ...

var merged = require('merge-stream'),
      manifest = require('assets-dev/manifest.json'),
      cwd = '/abs/path/to/plugin-1',
      dest = '/abs/path/to/plugin-dest';

     manifest.forEachDependency('css', function(dep) {
          $.gulp.src(dep.globs, { cwd: cwd })
                 .pipe(mySassTask())
                 .pipe(gulp.dest(dest));
     });

... but it doesn't seem to have any effect. Do I do something wrong or is there some another recommended setup for such case?

Thank you very much in advance!

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/26806181-does-asset-builder-respect-gulp-s-cwd-option?utm_campaign=plugin&utm_content=tracker%2F8853550&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F8853550&utm_medium=issues&utm_source=github).
@cibulka
Copy link
Author

cibulka commented Sep 19, 2015

OK, I have absolute path to plugin-1 etc. stored in another config variable, so for now, I prepend it manually to each dep.globs like this:

manifest.forEachDependency('css', function(dep) {
  for (var i=0; i < dep.globs.length; i++) {
    dep.globs[i] = config.base + dep.globs[i];
  }
  gulp.src(dep.globs).pipe() ... 
}

Still wondering if there is a better way though ...

@cibulka
Copy link
Author

cibulka commented Sep 21, 2015

Weirdly enough, I've just noticed, that the absolute path to my plugin-1 get prepended by Asset Builder for my Bower files, but not my main files.

console.log(dep.name)
// outputs
[
  /abs-path/to/plugin-1//abs-path/to/plugin-1/bower_components/object-fit/dist/polyfill.object-fit.css,
  /abs-path/to-plugin-1/assets/my-style.scss
]

So I ended up with:

for (var i=0; i < dep.globs.length; i++) {
    if (dep.globs[i].substring(0, config.base.length) != config.base) {
        dep.globs[i] = config.base + dep.globs[i];
    }
}

@austinpray
Copy link
Owner

Weirdly enough, I've just noticed, that the absolute path to my plugin-1 get prepended by Asset Builder for my Bower files, but not my main files.

So this behavior comes from https://github.com/ck86/main-bower-files. I definitely want to expose the option to either make all of the globs absolute or all of the globs relative.

You are bringing up an interesting point and I definitely want to support your usecase. Perhaps I should add a "cwd" option to the main entry function and the "make relative"/"make absolute" respect it? The default CWD could be whatever directory your gulpfile lives in.

@cibulka
Copy link
Author

cibulka commented Sep 21, 2015

Sounds cool! I will stay tuned - however my current "fix" works, so no pressure. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants