NodeJS: gherkin-lint: How to make a binary from this node module? - node.js

I am currently working on a set of BDD tests using Gherkin and Python. In order to have standardized feature files I want to include a git hook for the repo.
I found a good linter, gherkin-lint, but it's all Node.js oriented and I don't want to have to install Node to use it. I tried to create a binary package out of it using the Node pkg module, but It is complaining about the bin entry on package.json.
# pkg . -o gherkin-lint
> pkg#5.8.0
> Error! Bin file does not exist (taken from package.json 'bin' property)
/app/gherkin-lint/dist/main.js
I'm not a Node.js developer and don't have much knowledge of it. Is there a way to achieve what I'm trying to do?
Also, I found a formatter (reformat-gherkin) that is pre-commit oriented, but it is not a linter. It only formats the feature files indentation and doesn't look for bad-practices in the code, like duplicated tags, so it doesn't fit for what I'm trying to achieve.

Related

How to build node js applciation?

it is generic question.
I know that if I have java project I can run mvn clean install and it will build the project and the artifacts will be jar or war in target folder
if U have node.js application How I can build it ? I know that I have package.json that could run with npm install and the artifices are node modules but I guess there is a way to build the result of the node application . what is the type of the result ?
How to build node js application?
You don't really "build" a regular node.js application. There is no compile step. There is no separate executable. Whatever your main entry Javascript file is, you would just run it with node main.js and everything else will be loaded from there as your Javascript files load other modules. The Javascript interpreter will compile your JS files on the fly as they are encountered. If there is a syntax error when the file is loaded, it will throw an exception at that time.
For the simplest possible hello world application, you'd just put this into a text file named main.js:
console.log("Hello World");
And, then type this at the command line:
node main.js
And, you would see your output in the console. No compile step. No build step.
There are transpilers and there are packagers that can do special things, but none of that is needed for a regular node.js app.
but if I write something wrong in the code.How i can check it for example like mvn
Javascript is an interpreted language (like PHP, Python, Perl, etc...), not like Java. You will likely get a run-time error when you run your app if you write something wrong in the code. Of course, there are all sorts of tools that will check things for you before you run your code (such as linters), but Javascript does not work like Java in that regard.
If you want a "typed" and "checked" language, then you can use TypeScript which is "compiled" into Javascript that node.js can run and the compile step for TypeScript will check your syntax for you, enforce data typing, etc...

NPM: edit es6 written plugin in node_modules dir without transpiling

I've got a plugin I wrote in es6, and I'm currently testing the plugin on a site that I'm building.
When there's an issue, I would like to quickly modify the plugin directly in the node_modules folder, however everytime I need to make a change, I need to rebuild the dist folder for that plugin using babel-cli.
Is there anyway to get around this? Is there a webpack solution for this?
Not sure if understand you correctly where do you execute this code, but any way if it is executed in node - node supports es, just use latest version. If it is browser - then again you have two options execute file without transcompiling it at all https://kangax.github.io/compat-table/es6/, or use babel directly in the browser: http://babeljs.io/docs/usage/browser/
Your problem derives from the use of a transpiler to transform your source code before loading it into the browser. You can avoid this by using an isomorphic module pattern like this example, with introductory article.
Another alternative that is webpack compatible is to use the webpack hot loader.

Download node module sources without installing them?

I would like to download node module packages (listed in a package.json file, in the present working directory) source code to a node_modules subdirectory of the present working directory, without compiling, or installing those modules. Now I have seen the related question download source from npm without npm install xxx but that question dealt with downloading the source code of individual modules specified to NPM directly (i.e., without using a package.json file). The reason why I want to do this is because I am working on developing an Atom package for the Open Build Service (OBS) of openSUSE and this seems like one of the necessary steps I need to go through in order to achieve this.
The source code is not shipped with the npm distributed code. The best you could do is read the package.json and look for the { repository: url { } } key if it exists and if it's a git repo (which most of them will be) clone it.
However be aware that the source code often requires a build step before it can be used, as in an npm prepublish step defined in the source code. In modern Javascript projects a common example of this is transpiling ES6 code to ES5 code for use in NodeJS and the browser.
I have not made an Atom package but I'm fairly certain you don't need to do any of this.

Distribution of node js module

I used the steps explained in this page: http://nodejs.org/api/addons.html and successfully created a addon.node file using the node-gyp tool. it works fine and it's a wrapper of a c++ static library.
Now I want to distribute this, I created the package.json file using:
npm init
and test it using "npm install . -g" but it tries to recompile the module which will be difficult to achieve because it will require the libraries that I'm embedding into the .node file, is it possible to distribute the .node file that I already compiled in my system?
How can I include the compiled .node file into the npm package and upload it to the npm registry. I'm sure I'm just one step to made it, but I dont know where to start.
I read about the dependencies, but seems that it's suited when your module depends on other modules, and not with your own .node file.
Thanks for your help.
ok, I finally did what I wanted to achieve, here're the options in case someone else needs this:
To avoid the compilation you could create a new folder and copy the package.json in there, along with the .node file, I didn't find this, just tried and it worked.
Provide the required libraries to allow the user his own compilation.
Although the first one worked well, I will need to create a package for windows, linux, mac, etc. Which looks very odd to say: "if you are in linux use: npm install xxx-linux", so I decided to adjust my library to allow the user the module compilation.
To do this I created a "client-dev" installer that has the required libraries precompiled, as long as the include headers required, then created the node module to be compiled using the preinstalled libraries and headers. I will need to add a help in my website to explain that, in order to install the module, the user will need to install the dependencies first using apt-get, windows installer, or mac pkg.
Although this works for me, I don't know if that will be maintainable in the long run, but I didn't find a better way to do this. (the only link that finally enlightened my goal was one saying: "if you're going to use node modules with precompiled libraries you will have nightmares", anyway... I prefer that instead of doing a full implementation in node js from scratch and maintain version for java, c#, nodejs, php, etc.

How to do a dojo build using nodejs?

I'm currently using the dojotoolkit and its build system.
I read the new build tutorial for 1.8 at http://dojotoolkit.org/documentation/tutorials/1.8/build/.
In the tutorial it mentions that you can speed up your build by using nodejs.
The build tool itself relies on Java (and, optionally, Node.js for even faster builds), so make sure that have you that installed as well.
But it fails to mention how to do this. Anyone know how this works?
I normally run it like this:
> node dojo/dojo.js load=build --profile myprofile.profile.js --release
This would build a release for the profile contained in myprofile.profile.js. It assumes you are in a directory, which contains both dojo and util as sub-directories. It also assumes that the path to node is set correctly.
If node is not configured in the path variable, you will need to use the full path to node:
> <path to node here> dojo/dojo.js load=build --profile myprofile.profile.js --release
On windows the path is normally C:\Program Files\nodejs\ but you might have to configure it as C:\PROGRA~1\nodejs\ to get it working.
Windows Notes:
The build scripts do not work with Node on Windows (except using Cygwin). If you are using Windows you can get it to work via the following patch:
Windows Patch
Use the attached node-win.patch file to edit the files: util/build/main.js and util/build/transforms/writeOptimized.js. The patch has worked for me 100% of the time and it a simple matter editing a few lines of code.
I've personally found the alternative to Node, using Rhino, useless. It always fails to detect the build paths correctly, no-matter what I set basePath to. I would strongly advise using Node over Rhino as it is more reliable and easier to setup.
The buildscript util/buildscripts/build.sh checks if node is in your path and if so uses it.
This is currently not working under Windows (http://bugs.dojotoolkit.org/ticket/15413).

Resources