Yeoman generator composeWith - node.js

I am building a generator which uses another sub-generator, using composeWith.
I installed my generator using npm install -g generator-my-generator. When running the generator complains that I do not have my sub-generator installed.
My problem is that I don't want to install the sub-generator globally. I tried using it as a dependency / peerDependency (as suggested here), but it did not help.
Is it possible?

You need to provide the path in composeWith third argument:
this.composeWith('generator:name', {}, {
local: require.resolve('generator-foo/generators/name')
});
require.resolve is usually your best bet, but some generators (like generator-node) provide all the paths inside the main module so you don't have to know the package structure.

Related

How use openlayers3 in vuejs?

Through npm install openlayers(4.1.1), I can use openlayers normally in vuejs, but our company custom something base openlayers3.x, so how can I user this custom openlayers? I improt this ol's lib directly, when uses
goog.require("ol.Map")
it reports
goog undefined error!
so, is there any approach to use the custom ol in vuejs? thix.
You can install particular version of openlayers, by mentioning specific version in package.json, like following:
"dependencies": {
"openlayers": "3.x.x"
},
After that you remove earlier installed package and do npm install in the code directory, which will install the correct version you need.

Using an external node-installed JS library in Atom editor

I'm trying to figure out how to use external javascript libraries in the Atom editor. I used npm to install the momentjs library, since Atom uses node. However, I'm puzzled as to what to do now? I can't find a way to use the library in Atom.
I thought that I could go to the Atom init.coffee file and do a require "moment" (also tried require "momentjs") but nothing seems to work.
The whole reason behind this is so I can use some javascript libraries for formatting dates in a snippet (I have another SO question about that which I'll close if this solves it).
But this question is a general question about installing and running javascript libraries in Atom. I've looked through the Atom docs and Googled, but I can't find a good answer. I figured something like this would be pretty easy?
As Atom bundle its own node version (and thus is not using your global version(s)) it won't load globally installed modules through require.
However, the require method supporting absolute paths, you can still load any module if you know it's absolute path, which shouldn't be a problem in your specific case.
In your init script you can write:
momentjs = require('/path/to/momentjs')
But beware of modules that ships with binaries. Atom is using node 0.11.13 so if the module you're trying to require have been installed for a different version you'll get a Error: Module did not self-register.. In that case I'm afraid the only solution would be to install the module as a dependency of an Atom package (as suggested by #nwinkler).
You should be able to do the following when developing your own package:
Install moment using npm install --save moment - this will install the moment.js library as a dependency and register it in the package.json file
In your library, import it in your lib file:
moment = require 'moment';
myDate = moment().format();
Then you can use the moment object to format your timestamps.
All of this will only work if you're doing your own package, of course. Not sure if this will work with simple snippets as well.

Using localForage and angular-localForage with Browserify causing errors with require statements

I am attempting to install localForage into a node.js application (with Angular) and Browserify.
Here is a link to the localForage documentation
It appears that using localForage and angular-localForage causes a problem with browserify based around the use of 'require'
If I require the localforage.js file in the src file I get the following error:
Warning: module "promise" not found from "/Users/mgayhart/Sites/epson- receipts/bower_components/localforage/src/localforage.js" Use --force to continue.
If I require the localforage.js file in the dist file, I get the following error:
Warning: module "./drivers/indexeddb" not found from "/Users/mgayhart/Sites/epson- receipts/bower_components/localforage/dist/localforage.js" Use --force to continue.
Anyone know of a workaround to be able to move forward with these libraries?
There is an issue on github with this problem: https://github.com/ocombe/angular-localForage/issues/26
I'll be working on it soon, you can subscribe to the github notifs on this issue to know when it's fixed !
For me installing it through bower and using it with browserify-shim worked. So in package.json:
"browser": {
"localforage":"./src/lib/vendor/localforage/dist/localforage.min.js"
},
"browserify-shim": {
"localforage":"localforage"
}
And to expose it as an angular-service (if you don't want to use angular-localforage):
app.factory "localforage",-> require 'localforage'
I've just been having this issue myself tonight, but I think I found a fix.
Instead of trying to get the bower modules to work with browserify, why not just use npm like its made for?
npm install localforage
and then when you use require you don't have to give it the path
but it still didn't work for me until I copied the folder:
localforage/src/drivers TO localforage/dist/drivers
Then it found all the dependencies and worked like a champ!
Alternatively if you must use bower you could try to use the debowerify tranform w/ gulp:
https://github.com/eugeneware/debowerify

Register Yeoman Generator non-cli

I want to run a Yeoman generator without the cli (yo). I see the instructions in the Yeoman documentation about how to run a generator without the CLI environment.
If I run yo mygenerator:mysubgenerator it works (it's installed globally), but using env.run('mygenerator:mysubgenerator') from node does not work. It says that the generator is not installed.
I think this has to do with the //register/lookup generators step in the documentation above, but they don't include how to do this at all. How can I register my globally-installed generator?
There's a complete documentation here: http://yeoman.io/authoring/integrating-yeoman.html
The basic idea is you need to lookup installed generators before you can run them:
env.lookup(function () {
env.run('angular');
});
Why don't you try on this way:
env.register(require.resolve('generator-mygenerator'), 'mygenerator:mysubgenerator');

NPM alias node-postgres to node-postgres-pure

I'm building a nodejs application that needs to run on a Windows server. I've managed to get almost everything working, but I've ran into a problem with the postgresql driver. BrianC has a pure javascript implementation of the node-postgres that I would like to use to avoid having to build the postgres driver.
Is there a way for me to alias node-postgres(npm:pg) to node-postgres-pure(npm:pg.js) so that any dependent package that tries to install and resolve pg will install and resolve pg.js instead?
Thanks
Take a look at node-pg-pure-alias.
It's a bit of a hack, but the idea is to get a package that calls itself 'pg' installed into your node_modules folder. Then, that 'pg' library can export the "real" library.
See #it's not in npm! if you're concerned about depending on a package that's not in the official npm repository.
Disclaimer: I created node-pg-pure-alias. (All ten lines of the package.json, that is.)

Resources