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

Add configuration for gulp/gulpfile location #84

Open
therealklanni opened this issue Jul 22, 2016 · 11 comments
Open

Add configuration for gulp/gulpfile location #84

therealklanni opened this issue Jul 22, 2016 · 11 comments

Comments

@therealklanni
Copy link
Owner

There seems to be an increasing need for complex project structures where gulp and/or gulpfile.js are not in the project root.

Example use case:

.
├── .git
├── foo
│   ├── gulpfile.js
│   └── node_modules
└── bar

The goal would be to add a guppy entry in package.json with a property that sets an override for the gulpfile.js location or override the project path in such a way that guppy executes in the correct directory for gulp.

Suggestions for better/best approaches for this are welcomed.

@robfentress
Copy link

I think I have this issue. I am executing pre-commit from foo essentially and am getting an empty array for the changed files when I know they are there.

gulp.task('pre-commit', guppy.src('pre-commit', function (files) {
  console.log(files);
 }));

This results in [] being printed.

Executing the pre-commit task directly does return the changed files though. It also works if I move the gulpfile to the root of the project, but I don't want to do that.

Do you have a workaround?

@robfentress
Copy link

robfentress commented Aug 11, 2016

I submitted a pull request/s. Sorry for the multiple commits. I'm still trying to get the hang of this and realized some issues I had to fix. I tried to follow the guidelines in CONTRIBUTING.md--hope I did that right.

@robfentress
Copy link

Actually, looking at it now, I see there are significant problems with what I'm doing. I just quickly hacked something and it seemed to work in one limited case, but I didn't really test it out enough. If you've got any ideas, let me know.

@robfentress
Copy link

Okay, maybe now?

@robfentress
Copy link

Grr. . . nevermind.

@therealklanni
Copy link
Owner Author

Thanks for your efforts. Keep at it, I'm sure you'll get it! 👍

@ChrisMBarr
Copy link

ChrisMBarr commented Aug 30, 2016

After struggling with git-guppy for a bit I realized that this issue is why I can't get it working. We have a large & complex codebase with multiple projects, each one has its own gulpfile that does linting and runs unit tests

.
├── .git
├── source
│   ├── project-1
│   │   ├── gulpfile.js
│   │   └── node_modules
│   ├── project-2
│   │   ├── gulpfile.js
│   │   └── node_modules
│   ├── project-3
│   └── project-4
├── tools
└── docs

I'd love to use this project, but until I have the ability to define the location of the gulpfile(s) I can't.

@therealklanni
Copy link
Owner Author

@robfentress any luck finding a solution? :)

@robfentress
Copy link

Sorry. Been on vacation. For the moment, I've decided to just work around it in the gulpfiles themselves using the lodash, find-parent-dir, and path modules.

That looks something like this:

var _ = require('lodash');
var findParentDir = require('find-parent-dir');
var path = require('path');

var gitParent;

try {
  gitParent = findParentDir.sync(__dirname, '.git');
} catch(err) {
  console.error('error', err);
}

var gulpParent = path.resolve();
var gulpRelToGit = path.relative(gitParent, gulpParent);

gulp.task('pre-commit', guppy.src('pre-commit', function (files) {
      files = _.map(files, function(file) {
        var fileDir = path.resolve(path.dirname(file));
        var relFileDir = path.relative(gulpRelToGit, fileDir);

        return path.format({
          dir: relFileDir,
          base: path.basename(file)
        });
      });
      return gulp.src(files).pipe(doWhatever());
 }));

I had to edit what I actually had in my code a bit to make it clearer for this example. Hopefully, I didn't introduce any typos. Either way, this is the principle I used. Please let me know if I've overlooked anything.

@wheller
Copy link

wheller commented Dec 9, 2016

It seems to me since git will tell you where it's operating from, as well as where you need to "cd" to, to find the root... it could be as simple as this... #114

@arminrosu
Copy link

I don't know if it's the case for you as well, but I am running gulp (ie. gulp build) in /foo . In this case, you can edit the hookfile to cd into that directory first, since cwd will be /foo

E.g.:

  • Open .git/hooks/pre-commit
  • Change
var dir = execSync('npm bin gulp').toString().trim();

to

var dir = execSync(`cd ${cwd}; npm bin gulp`).toString().trim();

This should not affect projects which run gulp from the root, because cwd will be root.

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

No branches or pull requests

5 participants