gulp-raml2html
gulp-raml2html copied to clipboard
Problems with Includes
Hi,
I just wanted to try this out and got some errors concerning missing files for includes.
Gulpfile:
gulp.task 'api_docs', ->
gulp.src('api/*.raml')
.pipe raml2html()
.pipe gulp.dest('public/api')
RAML file:
schemas:
- show: !include schemas-show.json
Error: /Users/pascal/Projekte/EF/public/api/ef-api.raml:27:11: Parse error while reading schemas-show.json: cannot read schemas-show.json (Error: ENOENT, open 'schemas-show.json')
at /Users/pascal/Projekte/EF/node_modules/gulp-raml2html/index.js:32:16
at process._tickCallback (node.js:419:13)
From what I can tell, this is because here the first action of the plugin is pushing the file object back into the stream. But when convertFile is later called, the file's path has been changed by gulp.dest(cf. this).
Long story short, I moved the this.push(file); line to the end of the function and it seems to work.
(Maybe I'll send a pull request later, I just wanted to write this down before I forget.)
Hehe, I just saw that there were some other (closed) issues/PRs concerning this. Just close this issue if it's no longer relevant.
I think it's relevant. Please send a PR with your fix and if you have extra time, write a test for it. Thank you for reporting it!
No problem. I'll try to look into it tomorrow.
I forked this and added the single-line change, but so far I didn't have time to write a test (it seems to me that I'll have to include vinyl-fs to replicate this…). Anyways, if you want to include the change, feel free to cherry-pick my commit. Otherwise I'll do some more work when I have some time.
@killercup That also fixes the problem where the .raml file gets copied to the gulp.dest folder when it's different from the src.
However, I think the this.push(file) isn't called always, because when one of the if-statements is true, there are early returns. This fork fixes that, and also mimics the example gulp plugin. I don't know gulp enough to know if that's a problem, but I think it can't do any harm either.
@nvh, yes, you are right. I should've seen those early returns ;) You should send this as a PR.
I'm still having issues with included schemas and resolving paths, any news on a fix?
I've already created this pull request, but it isn't merged yet
yep, I can confirm that includes don't work if dest dir != source dir, and also the dest dir is not created if it does not exist
used 3-step workaround for now:
apidoc-html- generate html in source dirapidoc-copy- copy html to dest dirapidoc- remove html in source dir
var del = require('del');
var path = require('path');
var gulp = require('gulp');
var rename = require('gulp-rename');
var raml2html = require('gulp-raml2html');
var RAML = '../api/api.raml';
var APIDOC = '../server/static/docs/api/index.html';
gulp.task('apidoc', ['apidoc-copy'], function(done) {
del(RAML.replace(/\.raml$/, '.html'), {force: true}, done);
});
gulp.task('apidoc-copy', ['apidoc-html'], function() {
return gulp.src(RAML.replace(/\.raml$/, '.html'))
.pipe(rename(path.basename(APIDOC)))
.pipe(gulp.dest(path.dirname(APIDOC)));
});
gulp.task('apidoc-html', function() {
return gulp.src(RAML)
.pipe(raml2html())
.pipe(gulp.dest(path.dirname(RAML)));
});
another workaround is to just use current raml2html directly: https://gist.github.com/iki/784ddd5ab33c1e1b726b ... which is the only workaround for #12 atm