How to debug/inspect hexo blog - javascript

I'd like to start a Nodejs debugger for my Hexo blog to understand how my theme works and possibly find a bug.

I needed 2 things to achieve this:
Install hexo-cli as a dev dependency rather than global. I used npm i hexo-cli --save-dev.
In package.json, under scripts, add a script called debug. I used this command: node --inspect=4300 ./node_modules/hexo-cli/bin/hexo server.
Then just use npm run debug and you're good to connect with a debugger to port 4300 (or whatever port you want to set in your command) and do line-to-line debugging etc.
One caveat is that with the --inspect setting, for some reason hexo is starting extremely slow (takes more than 2 minutes). I wonder what causes this.
Also, I haven't found a way to start hexo in a way that it generates pages dynamically. It would help with real time debugging.

Related

Changes to minio browser do not appear when running minio server

My goal is to modify the Minio browser for front end appearance in house. I'd like to add features too but can't seem to get either to work and feel like I'm missing something about how go accesses npm or the browser.
I have made changes to the Minio web browser (javascript) and can see them when running with npm (in ./browser 'npm run release;npm run dev'), but when I try to run minio server built with the same git clone (changes is browser subdir) and browse to localhost:9000 I don't see any of the changes.
It would also be nice to run the browser with npm and connect to the running server "./minio server ~/data", but they don't seem to talk and I'm unclear on how they're connected.
This seems to be a simple case of all the things I tried and in the right order.
Correct order:
cd browser; npm run release
cd ..; make
./minio server ~/minio-data
It seems I'd tried all of these separately but not in the obvious order. I'm assuming npm makes the ui-assets.go which gets included by the make

Why isn't Express using a JavaScript to bootstrap?

I am currently getting my feet wet using Express. To start out, I used express-generator to scaffold a simple app.
While examining the project, I noticed that the npm start command is mapped to a binary (bin/www). Upon further inspection I noticed that this file actually contains code to be executed in Node, hence the #!/usr/bin/env node pragma. For anyone having a deeper understanding of Express/Node the answer may be obvious, but still I am wondering: Why didn't they simply use a .js file to bootstrap the framework. That file could then be run using node www.js, I imagine.
There are probably a few reasons why the script was made an executable
npm scripts can be mapped to execute local JS files in the project or executables on the system.
By mapping npm start to bin/www it is effectively the same as running ./bin/www on the command line with the important distinction that by running it via a npm start, it will also work cross platform (e.g. on systems that ignore the hashbang statement, like Windows), otherwise you would need to run it as node bin/www on those systems.
There's a binary ready to add to startup scripts.

Can't generate webpack-assets.json with webpack-isomorphic-tools

I'm trying to learn React and the whole environment built around it. I do that by trying to construct my own dev-stack.
The problem I can't get across for a very long time is how to serve CSS/Images while not loosing a power of server rendering.
I've read a couple of tutorials and discovered webpack-isomorphic-tools
I've configured them and managed to get an images supported, sass (transformed to css) as well.
However, I came across an issue that my webpack-assets.json file is not generated, instead I see this output. ( I managed to get it generated on a 2nd run of npm start before this commit, but that was definitely not a way to go , but it showed that the plugin works when a file is present.)
$ npm start
> redux-universal-example#0.0.0 start /Users/janvorcak/learning2016
> node src/server/index.js
[webpack-isomorphic-tools] (waiting for the first Webpack build to finish)
[webpack-isomorphic-tools] (waiting for the first Webpack build to finish)
[webpack-isomorphic-tools] (waiting for the first Webpack build to finish)
[webpack-isomorphic-tools] (waiting for the first Webpack build to finish)
I understand the purpose of this file, but I can't really figure out why it's not generated at all.
Is there anything that I'm missing?
Here are the relevant files and a repository
https://github.com/jvorcak/universal-react-kit/tree/sass-loader
(sass-loader branch on my universal-react-kit repository)
configuration -
https://github.com/jvorcak/universal-react-kit/blob/sass-loader/webpack-isomorphic-tools-configuration.js
webpack.config.js -
https://github.com/jvorcak/universal-react-kit/blob/sass-loader/webpack.config.js
entry file when running a server https://github.com/jvorcak/universal-react-kit/blob/sass-loader/src/server/index.js
Could somebody please explain what is going on, I've read documentation, blogs, but I'm missing something here. Thank you.
The reason the assets file is not generated is because you have integrated webpack-dev-server into your server.js.
https://github.com/jvorcak/universal-react-kit/blob/master/src/server/server.js#L81
That's a wrong way to do it because in production you won't need webpack-dev-server and therefore its place is somewhere else.
In your case webpack-dev-server is meant to generate webpack-assets.json and this webpack-dev-server is being run after webpack-isomorphic-tools .server() method calls its callback, but it won't call its callback until it finds webpack-assets.json.
The answer is to run your webpack-dev-server in a separate process (you may want to refer to github.com/erikras/react-redux-universal-hot-example for an example of how to achieve that).
https://github.com/halt-hammerzeit/webpack-isomorphic-tools/issues/47
You may also like my very own boilerplate which can do all the fancy things
https://github.com/halt-hammerzeit/webapp

How to add tab completion to a Nodejs CLI app

I want to add tab completion to a Nodejs CLI app (And preferably generate the tab completion dynamically).
I found a few npm modules but not sure how to really implement them:
https://github.com/hij1nx/complete
https://github.com/mklabs/node-tabtab
So what I am looking for is so I can have a nodejs file that is something like:
my-cmd create arg1 arg2
But then I might want to autocomplete like:
my-cmd cr<tab> -> create
Thanks!
Use omelette package that I built. If you have any questions, please contact me.
Edit - fast answer
After I answered, I kept reading tabtab source a bit and noticed that I can also run
pkgname completion install
to install the completion. since my environment was already dirty, I don't know if it actually did anything, but seems to me like it did..
Longer answer
#CameronLittle has given great documentation.
For the impatient, you can start by running
sudo bash -c 'pkgname completion > /etc/bash_completion.d/pkgname'
source /etc/bash_completion.d/pkgname
This will add completion to your current bash session.
As far as I know, new sessions will get the completion automatically.
To make the process seamless for user, you can use the install and postinstall hooks in package.json
https://docs.npmjs.com/misc/scripts
Make sure to not print anything by default. means running pkgname should result in no output, or otherwise it will not work.
important! install tabtab only from master
It seems tabtab has an annoying bug that was resolved in master but never got into a release..
The relevant commit to fix it is this:
https://github.com/mklabs/node-tabtab/commit/f8473555bf7278a300eae31cbe3377421e2eeb26
which handles completion for strings starting with --.
The commit if from february 2014, however the latest release as of (Jan. 2015) is 0.0.2 from Jan. 2014.. I assume there will not be more releases.
So if you want to get this fix, and you should(!), install tabtab only from master.
don't waste 2 hours figuring out what you did wrong like me :)
How did i reach this answer? TL;DR
While #CameronLittle's answer gives the explanation behind the scene, I would like to explain how to I reached the answer.
I tried using the package tabtab which has an explicit section about installing it. see https://www.npmjs.com/package/tabtab#completion-install
However, that didn't seem to work for me.
Looking at the code they instruct to add, I see the following process.argv.slice(2)[0] === 'completion' which made me run the command pkgname completion, which outputs something that starts with
###-begin-pkgname-completion-###
### credits to npm, this file is coming directly from isaacs/npm repo
#
# Just testing for now. (trying to learn this cool stuff)
#
# npm command completion script
#
# Installation: pkgname completion >> ~/.bashrc (or ~/.zshrc)
#
the words this file is coming directly from isaacs/npm repo made me wonder more. following the other answer here, I looked at /etc/bash_completion.d/npm - which showed the same exact content.. and so the comment.
I decided to run
pkgname completion > /etc/bash_completion.d/pkgname
however that requires sudo permissions and so becomes
sudo bash -c "pkgname completion > /etc/bash_completion.d/pkgname
and then, in order to apply it to current bash session I had to run
source /etc/bash_completion.d/pkgname
and voila! it works!
when I tried to open another terminal, it still worked, so I assume it will apply to all users. if not - you should add it to .bashrc or something..
I would just like to add that there is a
npm package yargs that enables bash-completion shortcuts for commands and options.
It has the option to output a .bashrc completion script. Bash completions are then enabled by sourcing the generated script.
It is currently an actively maintained package on npm with over a million downloads a month.

What do I need to do to get a JS3 environment (or at least couchdb) up and running?

I'm primarily a front-end coder but I'm not a stranger to server-side programming or the command line. Regardless I've still got a lot to learn about setting up servers and whatnot so I was wondering if anyone could help me put together some steps for setting up CouchDB on (preferably) ubuntu.
That's my main goal but I'd also like to get the 'JS3' environment going if possible. See this post for more info.
The things I struggle with most are knowing what packages I need to install and how to get it so I can work in my browser on localhost. Thanks for any pointers you can give me.
Packages are very dependant on the Operating System Flavor you use. On Freebsd you could go with
cd /usr/ports/www/helma ; make install clean
cd /usr/ports/databases/couchdb ; make install clean
and you have all the relevant software on your server. Then you need jQuery beeing hosted somewhere. Helma's Jetty Webserver can handle that for you.
For Ubuntu I read it now comes with a couchdb package sou you can just do
sudo apt-get install couchdb

Categories

Resources