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

Problems with Includes #6

Open
killercup opened this issue Aug 29, 2014 · 10 comments
Open

Problems with Includes #6

killercup opened this issue Aug 29, 2014 · 10 comments

Comments

@killercup
Copy link

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
Copy link
Author

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

@walling
Copy link
Owner

walling commented Aug 29, 2014

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!

@killercup
Copy link
Author

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

@killercup
Copy link
Author

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.

@nvh
Copy link
Contributor

nvh commented Sep 1, 2014

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

@killercup
Copy link
Author

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

@killercup killercup reopened this Sep 2, 2014
@rdohms
Copy link

rdohms commented Jan 7, 2015

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

@nvh
Copy link
Contributor

nvh commented Jan 7, 2015

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

@iki
Copy link
Collaborator

iki commented Jan 13, 2015

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
Copy link
Collaborator

iki commented Jan 22, 2015

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

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

No branches or pull requests

5 participants