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

Become require()-able by allowing to become a dependency #221

Closed
EvanLovely opened this issue Jan 4, 2016 · 18 comments
Closed

Become require()-able by allowing to become a dependency #221

EvanLovely opened this issue Jan 4, 2016 · 18 comments
Assignees
Milestone

Comments

@EvanLovely
Copy link
Member

It would be great to be able to use Pattern Lab Node as a dependency in another project (like a CMS theme build for a client - my use case). I would like my repo to contain the source code for the Pattern Lab Patterns, Data, Config, and Header/Footer template files, but not the compiled source – kinda like how we commit our *.scss but not our *.css. To do this we'd need to be able to do this at the top of a Gulp file:

var pl = require('patternlab-node')({
  "paths": {
    "source": {
      "root": "./source/",
      "patterns": "./source/_patterns/",
      "data": "./source/_data/"
    }
});

gulp.task('pl', function() {
  pl.build();
});

Basically pass in the config object (could just read a config.json in our repo and pass it in too) and then run the build command.

Is there any interest in the project moving in this direction? I could see the gulp and grunt "starter kits" you already provide getting ported to a yeoman generator for people who want all the stuff out of the box.

Thanks so much for your work and interest in the Pattern Lab world!! 🍻

@bmuenzenmeyer
Copy link
Member

hey @EvanLovely

I love the idea and the example syntax. For what it's worth this PR just landed in dev and I have plans to get it into 1.1.0 along with some example uses.

You'll also see that @geoffp included an example usage. It's not ready, but it's coming!

@EvanLovely
Copy link
Member Author

OK @bmuenzenmeyer - I've got the basics up in #223 !

@bmuenzenmeyer
Copy link
Member

Did the last commit of #223 address this issue in its entirety?

@EvanLovely
Copy link
Member Author

It's a huge step forward, but I think for this issue to be complete, we'd need it documented and any other steps ironed out. The PR #223 laid most of the groundwork (hence the "Basic" part of the title).

@bmuenzenmeyer
Copy link
Member

I am freed up, and will start testing and documenting using #223 (comment) as a starting point.

@bmuenzenmeyer
Copy link
Member

Documenting this has moved to https://github.com/pattern-lab/patternlab-node/wiki/Running-Pattern-Lab-Node-as-an-NPM-Dependency

Finishing #237 has helped simplify the styleguide steps quite a bit. When I pick this up again, I should be able to push through the remaining tasks and write up grunt docs too.

@bmuenzenmeyer
Copy link
Member

I got grunt working tonight - sans all the styleguide hoops to jump through, and updated the grunt documentation accordingly.

I will go through gulp at earliest opportunity too.

I've also created reference repositories that can house the final product configuration, which might help people understand what to do... or perhaps they might directly fork? Hmm.. https://github.com/bmuenzenmeyer/patternlab-node-grunt-dependency-example

. 🎉 🎈 🍻 🍰

@geoffp
Copy link
Contributor

geoffp commented Feb 4, 2016

Woohoo!
On Thu, Feb 4, 2016 at 12:48 AM Brian Muenzenmeyer notifications@github.com
wrote:

I got grunt working tonight - sans all the styleguide hoops to jump
through. [image: 🎉] [image: 🎈] [image: 🍻] [image:
🍰]


Reply to this email directly or view it on GitHub
#221 (comment)
.

@bmuenzenmeyer
Copy link
Member

Documentation complete!
Everything worked on the gulp side as you described.
https://github.com/pattern-lab/patternlab-node/wiki/Running-Pattern-Lab-Node-as-an-npm-Dependency

Also setup a reference repo for gulp here: https://github.com/bmuenzenmeyer/patternlab-node-gulp-dependency-example..

@EvanLovely @geoffp any objections to calling this guy resolved?!?

@geoffp
Copy link
Contributor

geoffp commented Feb 6, 2016

This is awesome! I'll sign off. 👍

@tbouron
Copy link

tbouron commented Feb 9, 2016

Hi Guys.

Thanks for tackling this, that's a huge improvement! But I think it can go even further to trully become a dependency of any other project. The current implementation involves copying Gruntfile.js or gulpfile.js which is very likely to be modified by any user to include its own custom tasks. Upon updates, it can (and will) become hard to merge patternlab changes into those files.

Now, grunt or gulp can require other Gruntfile.js or gulpfile.js files and use their tasks. I did some testing of this solution by requireing ./node_modules/patternlab-node/gulpfile.js and redefining the task patternlab => Works great except for the tasks that use path() because it's not injected. So what would be great is to create a simple node module that contains all grunt/gulp tasks and inject our configuration.

WDYT?

@tbouron
Copy link

tbouron commented Feb 9, 2016

I actually have a working example with gulp :)

I'll do more tests with grunt and push a PR once I have something that works

@bmuenzenmeyer
Copy link
Member

Hi @tbouron

I wasn't aware of the ability to require other grunt/gulp files. TIL. As with all contributions, I am eager to explore things that make consumption and developer workflow easier!

@geoffp
Copy link
Contributor

geoffp commented Feb 9, 2016

Me neither, that's great news to me -- I have at least a couple projects for which I'd love that functionality.

@tbouron
Copy link

tbouron commented Feb 9, 2016

@bmuenzenmeyer, @geoffp gruntfile.jsand gulpfile.js files are essentially classic javascript files which can be required as any other files. But for some reason, it is something not many people consider to do even though it creates even more modular applications!

I'll try to put something together tomorrow :)

@tbouron
Copy link

tbouron commented Feb 9, 2016

@bmuenzenmeyer, @geoffp I couldn't wait until tomorrow, so here you go: #244 :)

@EvanLovely
Copy link
Member Author

SO happy we got this in! I often use require() for grabbing other grunt/gulp files so I can split up my tasks. It's essentially just this:

In task.js:

var plugin = require('gulp-plugin');

module.exports = function (gulp, config) {

  gulp.task('task', function () {
    // cool stuff here
  });

};

In gulpfile.js:

var gulp = require('gulp');
var config = require('config.json');

require('./task.js')(gulp, config);

@bmuenzenmeyer
Copy link
Member

I meant to have this close with 1.1.0.
Conversation has moved to #244

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

4 participants