jsdoc issue: Full path to source file is displayed (unwantedly) - javascript

I'm using jsdoc3 for my project and everything compiles nicely.
But this I've been fiddling with for the last 2 days and I give up :(
When using the most basic call from MacOsX Terminal to run jsdoc I ALWAYS get the full path of my source file within the generated documentation.
Example:
./jsdoc ../projectname/js/jsfile.js
In the generated index file I can see a h1 with "index" and below it a h2 with the full path to the js file:
/Users/username/projects/path/projectname/js/jsfile.js
I don't like that it shows my complete local path...
After reading up I thought it would be relative to where I run jsdoc from.
But all this has the same exact result:
cd /Users/username/projects/path/projectname
../jsdoc-master/jsdoc js/jsfile.js
as well as
cd /Users/username/projects/path/projectname/js
../../jsdoc-master/jsdoc jsfile.js
The problem is, that this path is also used with the line number references and on the sourcecode page. And it's really not nice that my internal path is displayed...
The output I would want is projectname/js/jsfile.js or at least just jsfile.js, but I can not for the life of me get this to work.
I hope someone can tell me what I'm doing wrong.
regards,
Jan

#Louis helped me figure out it was a problem with the alpha version.
3.2.2 did not export the full path to the docs.
Unfortunately it had other problems, like the lacking of support for unordered lists.
So I decided to stick with 3.3.0 and make a shell script correcting the wrong output of jsdoc afterwards.
Contents of the shell file:
./jsdoc-master/jsdoc ./projectname/js/jsfile.js
ABSPATH=$(cd "$(dirname "$0")"; pwd)
perl -pi -e "s?$ABSPATH/projectname/js/??g" ./out/*.html
So this basically deletes the full path from the generated html files.
It's a bit dirty, but it works...
regards,
Jan

Related

Can I write the output of jasmine-spec-reporter to file?

I am currently using jasmine-spec-reporter to create a spec report for my Protractor test cases.
The output on the terminal looks great! Is there any way to save this output to file or somehow use protractor-jasmine2-screenshot-reporter to create a summary, but disable the screenshots?
I have tried looking online for solutions, but so far haven't been successful.
var SpecReporter = require('jasmine-spec-reporter');
jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: 'none'}));
https://github.com/jintoppy/protractor-html-screenshot-reporter
https://github.com/bcaudan/jasmine-spec-reporter
My current workaround is to use the protractor-jasmine2-screenshot-reporter to generate the report. This also generates screenshots (not very practical due to the volume being created).
If anyone has a solution to disabling the screenshots, or even not allowing the .png files to save, please share.
The output on the terminal looks great! Is there any way to save this output to file
This package is what you want https://www.npmjs.com/package/jasmine-reporters. It contains several different reporting options. If you want to parse the xml into an html file you can use https://www.npmjs.com/package/jasmine-xml2html-converter
It seems that this guy had the same need: https://github.com/Kenzitron/protractor-jasmine2-html-reporter
You can turn off screenshot if needed:
jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
takeScreenshots: false
}));

Requiring a .js file in Windows

I'm just starting to pick up javascript and casperjs for a project that I'm doing. I'm trying to create a project that uses babyparse in it.
Currently I have babyparse.js located at C:\js\babyparse.js.
I'm having trouble including babyparse, and I've tried a couple different ways of doing it.
1) eval('C:\js\babyparse.js') - I come up with a syntax error "Invalid Character \u0008". I found this on StackOverflow, but I was unable to find the unicode character in babyparase.js.
2) require('C:\js\babyparse.js') - this just doesn't even find the right path in windows. I'm assuming that's because of the backslash pathing of windows as opposed to the regular unix forwardslash.
3) require('C:\\js\\babyparse.js') - this gets the correct path in windows, but I get the error that CasperJS couldn't find the module C:\js\babyparse.js
I feel like I've looked a lot through stackoverflow, but maybe I'm just missing something obvious. Thanks in advance for the help!
Currently I have babyparse.js located in C:\js\babyparse
require('C:\js\babyparse.js')
You've got the path wrong it seems. The correct path would be
require('C:\\js\\babyparse\\babyparse.js')
Beware that babyparse is a node.js module. It may use some of node.js native modules wich are not present in PhantomJS javascript interpreter in which case your script will break.
If you want to use csv parsing while scraping, it's definitely better to use PapaParse which is specifically designed as general-flavour javascript without dependencies, "not even jQuery".
I managed to solve the problem!
The following snippet worked for me:
var fs = require('fs');
eval(fs.read('papaparse.js'));

npm dependencies not in package.json - due to missing comments?

I am wondering, if there is a way of using comments for my package.json dependencies.
Right now we have a bigger package.json file and we get more and more lost about the dependencies and there they come from. On other languages (not javascript) we can easily add comments. But since JSON is not supporting comments, this gets really tough for us.
Is there a optional file format for package.json to define our dependencies?
If not, how can we manage to create a package.json with comments?
Far more I am wondering, why node/NPM forces developers NOT to document, by choosing a fileformat which makes it impossible to document?!?
Hope someone can help us out of the dark...
I had the same problem earlier on this year.
I've just solved that problem with writing some basic script like this
#!/usr/local/bin/python
import os
os.rename("package.json", "package_M.json")
with open("package_M.json") as f:
with open("package.json", "a") as tmp_p:
for line in f:
if "//" not in line:
tmp_p.write(line)
os.system('npm install')
os.remove("package.json")
os.rename("package_M.json", "package.json")
I know it something like "Hacking" but it works for me :)
Hope it will help !
I did not understand your title, why would some dependencies would fail to get installed to package.json. The only explanation would be forgotten --save flag upon npm i.
Moving onwards,
Is there a optional file format for package.json to define our dependencies?
No.
If not, how can we manage to create a package.json with comments?
See the original question that this question duplicates: How do I add comments to package.json for npm install? there are some recipes there. Personally, I don't want to put comments in package.jsons, but I do use comments in my JSON's. I simply add dummy fields like "widt__comment___(value_below_is_capped_to_660_||_false_will_be_set_to_660_too)": false,. I omit the last letter and it appears on top when JSONs are sorted (next field would be width, so its comment starts with widt_).
why node/NPM forces developers NOT to document, by choosing a fileformat which makes it impossible to document?
package.json will have to be reliably parsed and rendered back, what limits the possible formats' choices. JSON is very reliable, old format, with very strict, known rules on its parsing and rendering. JSON is also covered by standards RFC 7159 and ECMA-404. TOML is not covered by any. YAML is not covered by any standards either. By the way, TOML is still on v0.x which is not even considered stable as per Semver.

Jekyll adding Null Characters to JavaScript

I'm trying to use this theme with Jekyll. However, my generated JavaScript has illegal characters appended to it, causing errors when the page is rendered.
In particular js/init.js seems to have two characters added to the end of it once rendered into _site. In Sublime Text they show as NUL, and in vi they show as ^#.
I'm running Jekyll from a Trusty Vagrant VM, and the source repo is a mapped volume to my Windows host. I've not edited any of the files at this point, so I can't see it being anything to do with line endings.
Any ideas?
(Following up to a super-old question, I know.)
TL;DR: Solution: apply frontmatter to the Javascript file.
I kept running into this issue, over the course of a few months, and turned up no solutions in search. Finally today, I think I've resolved my own case of it...
It turns out Jekyll is trying to process that file (at least it appears in my case) as a page document, so it looks for the frontmatter, and for some reason fails to render the file when it's missing.
After adding some frontmatter to my script, even though it breaks Javascript compatibility for the file on its own, Jekyll seems to play nice with it, and I'm no longer seeing the trailing ^# characters (etc).
Sample script with frontmatter
This tactic has a few ancillary features too...
---
some_variable: "yourvalue"
---
// access the value from the frontmatter within your script.
document.body.getElementById("mydiv").innerHTML = "{{some_variable}}";
Before adding front-matter (which fixed it for me, but breaks compatibility as noted by Samuel), try this first.
My JS file started out like this:
"use strict";
var filterView = {
Change it to this:
//A comment here helps Jekyll not get confused about file rendering
"use strict";
var filterView = {
In my case, I was only having problems with one of my JS files which was getting null characters added to it by Jekyll, and starting with "use strict" with nothing before it was the difference. I don't know if this will fix all causes of this problem but worth a shot.

How to get LanguageModel JS File?

I have been using PocketSphinx.js for speech recognition on my website. I have Downloaded language model file (.dmp). But their code uses JS file for Language model. I dont know where to get JS file. Help me out. Thanks.
As per documentation, you can convert dmp file to js and load it afterwards, see the section https://github.com/syl22-00/pocketsphinx.js/#i-embedding-the-files-into-one-large-javascript-file. Something like
$ cmake -DEMSCRIPTEN=1 -DCMAKE_TOOLCHAIN_FILE=path_to_emscripten/cmake/Modules/Platform/Emscripten.cmake -LM_BASE=/lm/dmp/folder/name -LM_FILES=model.dmp ..
Also check an alternative section https://github.com/syl22-00/pocketsphinx.js#ii-package-model-files-outside-the-main-javascript where you can do:
# python .../emscripten/tools/file_packager.py .../pocketsphinx.js/build/pocketsphinx.js --embed model.dmp --js-output=model.dmp.js
Overall, you need smaller models, big models from CMUSPHINX downloads are too large

Categories

Resources