How to override jhipster command to launch generator? - node.js

Suppose I would like to change the jhipster command to another name in order to launch the application generator, which source file(s) do I need to modify?

First, check where your npm global binaries (like jhipster command) are installed:
npm bin -g
In this folder, you'll find 2 files jhipster and jhipster.cmd, create a link to them with desired name or rename them and you're done.
Now, assuming you want to create your own distribution of jhipster while
respecting the terms of its Apache 2.0 licence, you should edit the package.json of generator-jhipster and change the bin section.
"bin": {
"jhipster": "./cli/jhipster.js",
"my_jhipster_copy": "./cli/jhipster.js"
},
npm install will create your my_jhipster_copy command

Related

How to generate JHipster application into a specific directory?

Suppose I modified the source code of generator-jhipster repo and I would like to generate my "custom" JHipster application into a specific directory, how would I accomplish this task?
After installing JHipster:
npm install -g generator-jhipster
I would be able to generate the application with:
jhipster
However, this command runs the application directly from the JHipster repository.
Since I modified the source code, I could generate the application locally by running:
node jhipster.js
in the ../cli directory.
The problem is, running this command in cli directory will generate the application in the same directory (cli) and this is not what I want.
I need to find a way to export the application into a specific directory.
Note: I strongly believe this has something to do with process.cwd(), because that generates the application in the local directory, but I'm not sure exactly
which source file to modify as I don't want to break anything.

How to modify an npm package built with TypeScript

I want to try and make some changes to a package published in npm? (I've suggest some changes as an issue but I think they are simple enough for me to attempt them).
https://www.npmjs.com/package/bt-presence#contributing--modifying
The author supplies some information on how to modify the package, but not really enough for someone doing it for the first time.
Where should I clone the GitHub repo to? The folder where the package is installed? I tried it in my home folder and that would not build (unmodified).
The command npm run build - where is this run from? The root folder of the package where the package.json is?
Will I need to modify the package.json?
In general what is the best way to develop something like this for npm? I've worked on packages before but they were simply Javascript.
If you want to work on the bt-presence package in isolation, you can put the cloned repository anywhere. If you want to use your modified version of bt-presence in combination with an application, my recommended approach is to register bt-presence as a dependency in the application's package.json file with the version set to a relative path to your bt-presence repository; then running npm install in the application will make a symlink from node_modules/bt-presence in the application to your bt-presence repository.
npm run build should indeed be run from the root folder that contains the package.json of bt-presence.
If you just want to change the code of bt-presence, you won't need to modify its package.json. You would only modify the package.json if you need to change any of the settings in there, e.g, if you need to add additional dependencies to your version of bt-presence.
None of the above is really specific to TypeScript. (Some JavaScript packages have build processes too if they need to transform or package the JavaScript files in some way.)

Liferay 7 Theme-Generator: Setting parent theme (baseTheme)

I have used the theme-generator to create a fresh theme.
Now I've created a second theme in the same directory and tried to set it's base/parent theme using gulp extend as explained on these pages:
https://github.com/liferay/liferay-theme-tasks
https://dev.liferay.com/de/develop/reference/-/knowledge_base/7-0/theme-gulp-tasks
After running the command and choosing option 1) to extend the Base Theme , I get the following options:
Styled
Unstyled
Search globally installed npm modules (development purposes only)
Search npm registry (published modules)
No matter if I choose 3) or 4) I cannot find the theme package.
Do I really have to publish the theme to npm to be able to find it?
Following this explanation I could achieve it using npm link:
npm link
Excerpt:
npm link: symbolic links to the rescue Fortunately npm provides a tool
to avoid this tedium. And it's easy to use. But there's a catch.
Here's how it's supposed to work:
cd to src/appy
Run "npm link". This creates a symbolic link from a global folder to the src/appy folder.
cd to src/mysite
Run "npm link appy". This links "node_modules/appy" in this particular project to the global folder, so that "require" calls
looking for appy wind up loading it from your development folder,
src/appy.
Mission accomplished... almost. If you installed Node in a typical
way, using MacPorts or Ubuntu's apt-get, then npm's "global" folders
are probably in a location shared system-wide, like /opt/local/npm or
/usr/lib/npm. And this is not good, because it means those "npm link"
commands are going to fail unless you run them as root.
EDIT: I was wrong to make a npm package out of it when you can also just require it locally. Even relative paths work. Example:
"dependencies": {
"my-liferay-theme": "file:../My-Liferay-theme",
}

Can I create an npm package that sets up another npm package?

I want to create an npm package that would be installed globally, with a binary to call. Calling that binary would set up the initial files for a new project, like your standard folders, standard license and layouts, a package.json with your common dependencies. Then you could call npm install to actually set up that project.
Like the Express application generator, or like rails new does in Ruby. The usage would be like
mkdir new_project
cd new_project
myCoolGenerator new
npm install
But I'm confused about how I'd implement this. The simple approach, which I'm doing now, is to create the standard vanilla folder, ship it with the generator package, and then just have the main binary use ncp to copy that folder into wherever the caller currently is.
My problem there is that I don't know how I can access the folder included in the globally-installed package to copy over. And additionally, npm lets you specify a files array in your package.json to specify files included with the package, but it's apparently hardwired to ignore package.json from that.
What's the recommended procedure for this sort of thing?

mean stack missing folders

Installing a mean stack:
$ sudo npm install -g meanio
$ mean init yourNewApp
Checking file structure:
$ ls
AUTHORS Procfile config packages
Gruntfile.js README.md karma.conf.js server.js
LICENSE bower.json package.json
I am missing the correct file structure even though the app "works". Everything should be installed correctly. Where is public and the server folder?
These folders are also missing if I clone any other mean stack project from github.
I had a same problem because I am beginner, but it seems that MEAN Stack file structure has been changed few weeks ago. Quote from Mean.io docs says:
'From v0.4.0 all the application code has been integrated into a number of packages. Each package uses MVC on the server and client. Below is the overall file structure as well as the package file structure'
Source: http://mean.io/#!/docs
This mean.io file structure is organised in packages and each package has own MVC for server/client sides folders. Also, please take a look on mean.io blog site where there is article about package types: http://blog.mean.io/2014/06/extending-mean-io/
If you are windows user and you try to follow mean.io website instructions, you probably will be confused how to install all the stuff in order to see the application lunched in your browser and probably you can't manage to have all the sources in your project. Follow their video from homepage or DO THIS:
Install Git from http://msysgit.github.io/ and then in then fallow
the instructions from here
http://www.computerhope.com/issues/ch000549.htm in order to add your
“git” var path;
Install node.js from http://nodejs.org/;
Install MongoDB from http://www.mongodb.org/. Create in your "C:\" the "data" directory and inside of "data" create "db" directory. Add like step one a new PATH var but this time for mongodb. For this you should find out your mongodb root in the window system (ex: C:\Program Files\MongoDB 2.6 Standard\bin).
Run in cmd: npm install -g meanio ;
Run in cmd: mean init myApp;
Go into myApp folder using cmd and there run: npm install;
Run in new cmd window in C:\ : mongod;
Run in new cmd window but this time in your myApp location: grunt. If you obtain an error saying that grunt is not recognized then run this comand line "npm install -g grunt-cli";
Go in browser and type http://localhost:3000/.
Hope this will be useful for someone new like me in this area.
In Mean.IO total project is divided into number of modules and these modules are known as package. these packages mostly independent from each other. and each package contains public and private folder separately. for more see the mean documentation.
Try installing meanjs. It's a fork from the mean.io. Many developers have shifted to meanjs as it's more stable and from the same guy Amos Haviv who started mean.io.

Resources