Question: I have a question regarding a select mysql query. Lets say that we have 2 tables

users: [ id, username ]
logs [ id, user\_id, action ]

I want to selecr all users from table users with the count(`id`) of table logs based on user\_id

I tried to do the following:

```
SELECT t1.*,count(t2.`id`) 
FROM `users` t1
LEFT JOIN `logs` t2 
ON  t1.id = t2.user_id;

```

But that only prints the users who have count logs > 0. I want to select all the users with the count of the logs.

Answer: 
Here's a quick recipe I found:

gulpfile.js
-----------

```
var gulp   = require('gulp');

// npm install gulp yargs gulp-if gulp-uglify
var args   = require('yargs').argv;
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');

var isProduction = args.env === 'production';

gulp.task('scripts', function() {
  return gulp.src('**/*.js')
    .pipe(gulpif(isProduction, uglify())) // only minify if production
    .pipe(gulp.dest('dist'));
});

```

CLI
---

```
gulp scripts --env production

```

Original Ref (not available anymore): <https://github.com/gulpjs/gulp/blob/master/docs/recipes/pass-params-from-cli.md> 

Alternative with minimist
=========================

From Updated Ref: <https://github.com/gulpjs/gulp/blob/master/docs/recipes/pass-arguments-from-cli.md>

gulpfile.js
-----------

```
// npm install --save-dev gulp gulp-if gulp-uglify minimist

var gulp = require('gulp');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');

var minimist = require('minimist');

var knownOptions = {
  string: 'env',
  default: { env: process.env.NODE_ENV || 'production' }
};

var options = minimist(process.argv.slice(2), knownOptions);

gulp.task('scripts', function() {
  return gulp.src('**/*.js')
    .pipe(gulpif(options.env === 'production', uglify())) // only minify if production
    .pipe(gulp.dest('dist'));
});

```

CLI
---

```
gulp scripts --env production

```
And if you are using typescript (`gulpfile.ts`) then do this for `yargs` (building on @Caio Cunha's excellent answer <https://stackoverflow.com/a/23038290/1019307> and other comments above):

Install
-------

```
npm install --save-dev yargs

typings install dt~yargs --global --save

```

### `.ts` files

Add this to the .ts files:

```
import { argv } from 'yargs';

...

  let debug: boolean = argv.debug;

```

This has to be done in each .ts file individually (even the `tools/tasks/project` files that are imported into the `gulpfile.ts/js`).

Run
---

```
gulp build.dev --debug

```

Or under `npm` pass the arg through to gulp:

```
npm run build.dev -- --debug

```