Sails.js 0.10 generators - javascript

The upcoming Sails.js 0.10 features custom generators. (at the time of writing it is currently # rc4)
There's a migration page on Sails github describing how wonderful generators are, but not so much how to go about installing them into your own application.
A few really interesting custom generators start to pop up:
sails-generate-auth
sails-generate-gulp-bower
The first one is available on npm. So it was a matter of npm install and generator was available in my app right away.
I wanted to try out the second one to replace Grunt with Gulp, but I couldn't install the generator.
Can anyone explain how to install custom generator and hook it up with Sails.js app?

You can install a sails-generator just like any other npm package:
npm install sails-generate-auth
The problem with sails-generate-gulp-bower is that it hasn't been released to npm yet.
You can trick npm by using the following url to install the latest version of it anyway.
npm install https://github.com/PaulAvery/sails-generate-gulp-bower/archive/master.tar.gz --save
But keep in mind that the author probably has his reason why he didn't release it.

I created generaters to use gulp with sails. https://github.com/Karnith/sails-generate-new-gulp
There are 4 in total that need to be used together with a .sailsrc file. They should be installed globally and then sails new can be used to create the app. Sails lift works also.

Related

How to develop client side library and npm library ?

I would like to develop a JS test library for client & node.
I need to develop for two different repo's?
Lets take for example QUnit:
for client side I will use:
https://code.jquery.com/qunit/qunit-2.3.0.js
But for node develop, I will use :
npm install qunitjs
Those are 2 different code repo's, aren't?
For the example, lets puts aside the testrunner, etc..
Thanks!
Originally the "npm" used to stand for the "Node Package Manager".
Currently, the npm Registry is a public collection of packages of open-source code for Node.js, front-end web apps, mobile apps, robots, routers, and countless other needs of the JavaScript community.
And npm is the command line client that allows developers to install and publish those packages.
See: https://www.npmjs.com/about
So you can use npm to package front-end code just like you can use npm to package Node code. Sometimes it makes sense to publish two packages - one for frontend and one for backend - but sometimes you can have just one.
For packaging frontend code there are more options like Bower: https://bower.io/
For packaging Node code the most popular choice is npm but you can install code directly from GitHub or other git repos.
As an example you can see my module tco that is on npm:
https://www.npmjs.com/package/tco
But also on GitHub:
https://github.com/rsp/node-tco
So you could install it with npm either from the npm Registry or from GitHub:
npm install tco # <-- from npm registry
npm install rsp/node-tco # <-- from github
Additionaly you can use it on the frontend from the CDN available for all code on GitHub:
<script src="https://cdn.rawgit.com/rsp/node-tco/v0.0.12/tco.min.js"></script>
If you want your code available on that CDN as well, see RawGit:
https://rawgit.com/

What is the step-by-step procedure for installing any npm module with Aurelia CLI?

I wanted to install jquery and found instructions here:
http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/contact-manager-tutorial/4
I then wanted to install "moment.js" and found instructions here ( I am not using typescript) :
How to import Moment-Timezone with Aurelia/Typescript
To install both of these with the Aurelia CLI the procedure is to install the respective npm module and then to manually modify aurelia.json in some way so the app recognizes it.
In the case of moments the instructions then say to place an import at the top of app.js , but this is not the case for JQuery.
First off , is there any way the changes to aurelia.json can be automated ( like a regular node.js package.json) so I don't need to manually do it and second, how do I know what modifications I am expected to make to aurelia.json ( or app.js or any other file) for the module I want to install?
With a basic node.js app its pretty simple , just npm install. With Aurelia its much more confusing.
Edit: There is also JSPM which I've read is used for front end libraries like the ones I mentioned above. However, the links with instructions for installation that I posted are not using JSPM.
Edit
I found some of the answers here:
http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/the-aurelia-cli/6
The CLI is still under development. I think the automatic adding of a package might some day be included in the CLI itself, for example with an install command.
The extra registration is required to register the package correctly for usage with RequireJS (http://requirejs.org/). And if the plugin exists of more than just 1 file, this registration is a bit more complex then just adding the name of the plugin.
There is an experimental CLI task here https://github.com/martonsagi/aurelia-cli-pacman that will do the automation for you.
Which can be installed by running:
npm install aurelia-cli-pacman -D
The above will install the package manager and register/ include itself in the tasks in your current project (be sure to run it with install, because npm won't run the post install script if you run it the i shorthand). Next, you can run the following command to install an extension:
npm i aurelia-interactjs -S
au pacman i aurelia-interactjs
The only downside for many might be that currently there aren't that many registry entries, but I think the author of the package would be very happy if you help him out by creating a pull to extend the registry. Would take you some time to figure out what would be the correct install/ import settings, but you will help out someone else and make them happy when they hit the same problem you experience :-).
JSPM has a same sort of issue around this, only is more matured/ the registry is bigger and/ or authors added specific information for JSPM installations to their package.json. For example: To install the above plugin with JSPM it will use the following highlighted section https://github.com/eriklieben/aurelia-interactjs/blob/master/package.json#L72,L86. The same is currently not possible with aurelia-cli, because the installation is done by NPM instead of through JSPM that redirects it to NPM.
If the author of the plugin didn't specify the JSPM section in the package.json, you would most likely and up with the same sort of issues. JSPM has a similar registry (https://github.com/jspm/registry/tree/master/package-overrides/npm) as aurelia-cli-pacman.

Why to use Bower.js if npm works fine?

In the projects prarent directory, if I do,
npm init
a file "package.json" is created,
Now if I want to install dependencies like let's say angular, jQuery and bootstrap I can do
npm install angular --save-dev
npm install jquery --save-dev
npm install bootstrap --save-dev
a folder "node_modules" get created, with the above mentioned dependencies.
and the same entries of dependencies in entered in "package.json" .
Now using any build tool like lets say gulp.js,
I can inject the "node_module" dependencies in my SPA's(Single page application) index.html.
So my question is, why to use Bower ?
Please let me know with some pointers
Short answer: Don't (use bower).
Bower started as a "clone" of npm for the client-side, but meanwhile literally everybody is using npm for this, too.
So there is no need to use bower any more, just rely on npm, and everything is fine. It makes your development workflow simpler, more unified, and you just end up with less friction and complexity (which is a good thing).
My biggest concern with bower is that it introduces unneeded overhead, such as another tool, another configuration file, another way of dealing with versions, another folder where modules go to, … I have hardly seen any benefit of bower that outweighs these drawbacks. Again: Just stick to npm and you're fine.
I myself thought of this just yesterday.
From my experience, you can be well off with just npm, provided the packages you need are registered.
This was not the case a few years ago, but now it nearly mirrors bower's repository.

npm dependency management best practices

I'm a relative newcomer to the node community. I recently got on board so that I could put together a build for a complex web application that's been under development for several years. The two key tools in my build are Grunt and Browserify, but the application uses jQuery, Backbone, d3 and a smattering of other libraries and plugins as well.
A problem that I've been running into is this: by default, when I install and save a package with npm, it sets up the package with a semver expression that captures all future releases of the package whenever you run npm update. Like this article explains well, that may seem like a good thing at first ("give me this package and all future upgrades"), but it exposes your own application to any non-backwards compatible updates the package maintainer makes... The article also provides some recommended best practices, but it was written almost 4 years ago to the day; I'm hoping there are other, newer ideas.
What sort of solutions do you use to resolve this issue? I can't keep wasting time updating my software every time a breaking change is made in a library I rely on. I want to update when I am good and ready, not whenever I run npm update.
Use npm shrinkwrap to save the tree of dependencies containing the exact versions, so when you npm install it'll use those exact versions.
The npm outdated command will tell you what packages are outdated.
Instead of npm update which updates all your packages, update specific packages with npm install <pkg>#<version> --save

How to update Yeoman dependencies?

Every yeoman generator has its package.json and bower.json that contain the dependencies.
When I initialize a new project with:
yo somegenerator
it starts to download and install the dependencies, according to the version saved in the files.
My question is: how can I update the dependencies when I initialize a new project?
I would that when I type "yo somegenerator", it download the latest dependencies and update the files (package.json and bower.json) with the current version.
Generators are designed with particular dependency version requirements intentionally. You are free to experiment with upgrading these dependencies, of course-- it's your app after all! Your question isn't really "how can Yeoman" update my dependencies, but "how can I update my dependencies?" Just wanted to clear that up.
Depending on what you want to upgrade-- jQuery? A grunt plugin? You will have to determine what it is you wish to upgrade, and run the update command for that dependency. See the Bower and npm docs for those commands.
If your generator hasn't been updated in a while, you are free to do so! Remember, generators are simply node modules, distributed via npm.
If you have yo 1.0rc1 or greater installed, you can also type just "yo" to see your installed generators, as well as select the "update your generators" option.
Hope this helps!
As yeoman generators are installed through npm does it not make sense to run
npm update somegenerator
Alternatively you could do npm unbuild somegenerator#version and reinstall.

Categories