Monday, November 24, 2014

Running Grunt JS managed application behind a proxy

Unfortunately working in a corporate environment imposes certain constraints, mainly for security reasons, at least when it comes to internet access which is usually accomplished via a http(s) proxy server.
It is not unusual Grunt JS and Bower to be used in modern applications. Grunt JS uses npm to download any plugins, Bower on the other has its own mechanism to resolve and download dependencies.
It is also unfortunate, that none of them utilizes environment variables for proxy configuration; like http_proxy and https_proxy in a Linux environment. For Grunt JS you need to execute

npm config set proxy http://<proxy_host>:<proxy_port>
npm config set https-proxy http://<proxy_host>:<proxy_port>

for http and https proxy settings respectively. Note that no-prefix used the http type of proxy. These commands modify the npm config file; you should be able to verify the effect of the above using: 

npm config list

While Grunt JS settings are stored globally, for Bower, proxy settings are locally stored in the scope of the project. Typically in the root directory of a project there should be a .bowerrc file, you can modify the contents of this file to match the following:

{
    "directory": "app/bower_components",
    "proxy": "http://<proxy_host>:<proxy_port>",
    "https_proxy": "<proxy_host>:<proxy_port>"

}

You may now execute npm install and have all dependencies downloaded in your project.

Saturday, July 26, 2014

Install yo (yeoman) in Ubuntu 14.04

Yeoman is a really cool scaffolding tool that comes with lots of pre-built generators for a range of applications. I use it for initiating angularJS applications using yo's 'official' angularJS generator.

In Ubuntu 14.04 (actually starting from 13.10) versions 0.10.x of nodejs are present in the official repositories. So in order to install nodejs package manager just type:

sudo apt-get install npm nodejs-legacy

npm alone is not sufficient to install Yeoman, since the latter depends on 'node' legacy binary during installation, hence nodejs-legacy package is also required.

Install global npm packages as a regular user.

npm installs packages under a 'prefix' configuration variable, which defaults to /usr/lib in Ubuntu 14.04. In order to avoid using sudo for every npm-install command, you may configure 'prefix' variable to point into a user local directory.

sudo npm set prefix '$HOME/<user-space-local-npm-directory>' --global
i.e.
sudo npm set prefix '/home/andy/dev/npm' --global

Verify that setting has been set using; defaults to /usr/lib

sudo npm get prefix

Update your $PATH variable to include the location npm installs binaries,

echo "export PATH=$PATH:$HOME/dev/npm/bin" >> $HOME/.profile

and restart your terminal session.

Install Yeoman

Installing yeoman is dead simple; just invoke

npm install -g yo

as mentioned in the official site.

AngularJS scaffolding

Install angularJS generator

npm install -g generator-angular

Generate angularJS application

yo angular

Invoke grunt to build the application grunt serve (or python -m SimpleHTTPServer) to preview the application.