Reputation: 7839
Several Node.js packages have the following two steps as their starting point (just using Jasmine as an example):
npm install --save-dev jasmine
./node_modules/.bin/jasmine init
The first statement is straightforward, but I could not for the life of me figure out what the second statement does under the hood. The Jasmine docs only say that it initializes it (I am searching for something more technical).
./node_modules/.bin/jasmine looks like this:
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../jasmine/bin/jasmine.js" "$@"
ret=$?
else
node "$basedir/../jasmine/bin/jasmine.js" "$@"
ret=$?
fi
exit $ret
In case helpful, I did this to clone and install the package locally:
Any pointers/documentation explaining that init would be deeply appreciated.
Edit:
Just to clarify, I know what init does (clear from testing and the Jasmine documentation), I just do not understand how it does it. I am basically trying to find out why init is needed behind the script name when running it from the CLI, and where the init code is located.
Upvotes: 0
Views: 898
Reputation: 7839
I managed to finally solve this myself. If anyone comes across this in the future, the following is the explanation of ./node_modules/.bin/jasmine init
.
./node_modules/.bin/jasmine init
is executed from the command linejasmine
Unix script in ./node_modules/.bin/
(init
argument is not used yet)jasmine.js
(./node_modules/jasmine/bin/jasmine.js
) and runs itJasmine.js
contains this code: var Command = require('../lib/command.js')
Jasmine.js
creates a new instance of the Command
object (command
) and executes: command.run(jasmine, process.argv.slice(2));
slice(2)
equals init
run
function inside command.js
launches initJasmine
by having mapped init
to initJasmine
at the very topinitJasmine
makes the directory spec
and all its contentsHope that helps someone else in the future.
Upvotes: 1
Reputation: 904
jasmine init
initializes a basic folder structure for Jasmine by creating a spec directory and configuration json for you. You can look for more details here https://github.com/jasmine/jasmine-npm
Upvotes: 0