krasimir / techy

A flat file CMS based on Gulp and AbsurdJS
http://krasimir.github.io/techy
MIT License
250 stars 23 forks source link

More Gulp-like? #6

Closed dangoor closed 10 years ago

dangoor commented 10 years ago

Despite being based on Gulp, Techy has a Grunt-like feel. You run "techy" and it reads a Techyfile for some configuration and then processes the files. I don't like the fact that Techy puts the resulting files next to the source files (I prefer that the generated files go into another directory that can be easily placed in .gitignore and rsync'ed to my server). But, since Techy is a command and not something that can process streams (in Gulp fashion), it's less than clear how I'd specify a destination.

It seems like what Techy is really offering is the merging of content with layouts. What if that could be done stream-style? Then, I could create a Gulpfile that processes my source files in any way I choose (any way that is supported by any of the Gulp plugins) and put the destination files anywhere I choose.

That may not at all be what you want Techy to be, and the authors of Gulp seemed to even support the notion that people will build Grunt-like tools on top of Gulp, but I thought I'd put forth the idea and see what you thought.

krasimir commented 10 years ago

Indeed, good points. The Grunt-like feel came because I wanted to provide options for the compilation. Passing them via the command line is not very flexible. And because there is not a central storage this was the only one solution that I came up with. But you are right, it's not good that Techy decides where to put the files in.

Techy could be used from within a Node.js script even now - http://krasimir.github.io/techy/docs/#using-techy-in-node-js-script So, at the moment Techy is using Gulp after its initial functionalities. What it does is to compile everything and starts listening for changes in the files. It simply fires the same compilation if some of the files is modified. Having this in mind I could say that most of the work is done.

What I'm going to do now is to make possible Techy acts as a Gulp plugin. Something like this:

var Techy = require('techy');
var techy = Techy('root/path/here', { globalSetting: '...'});
gulp.task('default', function() {
    gulp.src('./**/*.md')
    .pipe(techy.gulp)
    .pipe(gulp.dest('./public'));
});

The first parameter, the root's path is needed because that's how Techy knows about all the pages in the project. Otherwise some of the most important features will not work. Like for example, this will not be doable.

What you think?

dangoor commented 10 years ago

Seems reasonable. I haven't used Gulp much yet, but it doesn't seem out of line to create an object with project-level knowledge like that.

krasimir commented 10 years ago

It's done. Techy could be used as a Gulp plugin - http://krasimir.github.io/techy/examples/gulp-plugin/ Example:

var gulp = require('gulp');
var Techy = require('techy').gulp({
    root: __dirname,
    theme: 'default'
});

gulp.task('compile', function() {
    gulp.src('./src/**/*.md')
    .pipe(Techy())
    .pipe(gulp.dest('./dest'));
});

gulp.task('watchers', function() {
    gulp.watch(['src/**/*.md'], ['compile']);
});

gulp.task('default', ['compile', 'watchers']);

P.S. I made few small examples by using Techy as Gulp plugin and it works pretty nice. Actually even better then the original techy command. The separation of the files was really good idea. Thanks.

dangoor commented 10 years ago

Looks very nice! I'm going to give it a go now.