gulp-raml2html icon indicating copy to clipboard operation
gulp-raml2html copied to clipboard

Problems with Includes

Open killercup opened this issue 11 years ago • 10 comments

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.)

killercup avatar Aug 29 '14 12:08 killercup

Hehe, I just saw that there were some other (closed) issues/PRs concerning this. Just close this issue if it's no longer relevant.

killercup avatar Aug 29 '14 12:08 killercup

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!

walling avatar Aug 29 '14 13:08 walling

No problem. I'll try to look into it tomorrow.

killercup avatar Aug 29 '14 14:08 killercup

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 avatar Aug 30 '14 19:08 killercup

@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 avatar Sep 01 '14 12:09 nvh

@nvh, yes, you are right. I should've seen those early returns ;) You should send this as a PR.

killercup avatar Sep 02 '14 11:09 killercup

I'm still having issues with included schemas and resolving paths, any news on a fix?

rdohms avatar Jan 07 '15 15:01 rdohms

I've already created this pull request, but it isn't merged yet

nvh avatar Jan 07 '15 23:01 nvh

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 dir
  • apidoc-copy - copy html to dest dir
  • apidoc - 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)));
});

iki avatar Jan 13 '15 21:01 iki

another workaround is to just use current raml2html directly: https://gist.github.com/iki/784ddd5ab33c1e1b726b ... which is the only workaround for #12 atm

iki avatar Jan 22 '15 12:01 iki