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

Synchronous CLI calls mix content #30

Closed
CodeLenny opened this issue Jan 12, 2017 · 9 comments · Fixed by #31
Closed

Synchronous CLI calls mix content #30

CodeLenny opened this issue Jan 12, 2017 · 9 comments · Fixed by #31

Comments

@CodeLenny
Copy link
Contributor

CodeLenny commented Jan 12, 2017

Hi,
I've been starting two Spectacle runs on different files at the same time in a build script, but some of the time (maybe one in four runs) one of the API pages is wrongly embedded in the other.

spectacle-embedded-obs

Censored as it's for a closed-source project (my apologies). Below "Documentation by Spectacle", the other document starts, with the title, schemes, and all routes.

I've paraphrased my Cakefile (CoffeeScript Make alternative).

{spawn, exec} = require "child-process-promise"
replace = require "replace-in-file"
chalk = require "chalk"

allSpectacle = (opts) ->
  spectacleDocs opts, "#{__dirname}/src1/api/api.yml", "#{__dirname}/doc/extra/src1/api"
  spectacleDocs opts, "#{__dirname}/src2/api/api.yml", "#{__dirname}/doc/extra/src2/api"

###
Build API docs via [spectacle](https://github.com/sourcey/spectacle)
@param [Object] opts the options passed to `cake`
@param [String] spec a path to the spec-file
@param [String] out a path to the output directory
###
spectacleDocs = (opts, spec, out) ->
  exec "$(npm bin)/spectacle #{spec} -t #{out}"
    .then ->
      replace
        files: "#{out}/index.html"
        replace: /(src|href)="\/\//g
        with: "$1=\"https://"
    .then ->
      replace
        files: "#{out}/index.html"
        replace: /(src|href)="\//g
        with: "$1=\""
    .then ->
      console.log chalk.green "Documented #{chalk.blue spec}"

I've changed my build file to run the two Spectacle compiles one after the other which may have fixed it (tested several of times), but it does slow the build down as Spectacle is one of the longer tasks.

@auscaster
Copy link
Member

auscaster commented Jan 13, 2017 via email

@CodeLenny
Copy link
Contributor Author

@auscaster Could the cache be changed so multiple files could be compiled at once? I've used tmp before to automatically create a clean directory, which could be used to keep runs separate from each other.

@auscaster
Copy link
Member

auscaster commented Jan 13, 2017 via email

@CodeLenny
Copy link
Contributor Author

@auscaster Sure, I can give it a go.

For my CLI usage, I could just change program.cacheDir = os.tmpdir() + '/.spectacle'; in bin/spectacle.js to use the tmp package.

Alternatively, the grunt file (index.js) could be altered to generate unique filenames inside .spectacle, or call tmp internally instead of being passed a temporary directory.

Is one of these an acceptable approach for you?

@auscaster
Copy link
Member

auscaster commented Jan 13, 2017 via email

@CodeLenny
Copy link
Contributor Author

@auscaster I've created a PR. It looks like the latest release wasn't pushed to GitHub, so you may want to do that before merging.

Thanks!

@auscaster
Copy link
Member

Thanks again, npm package updated

@CodeLenny
Copy link
Contributor Author

You're welcome, thanks for the quick merge! Looks like something might have broken in the testing, I didn't see the tests.

@CodeLenny
Copy link
Contributor Author

@auscaster Not just testing, it's failing an assertion. I'll take a look into it.

alvaromoo pushed a commit to etsfactory/spectacle-docs-etsfactory that referenced this issue Jul 26, 2017
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

Successfully merging a pull request may close this issue.

2 participants