From a4d25f4172828fb2b1fe56eeee68cdb0204eba1f Mon Sep 17 00:00:00 2001 From: Vincent Morneau Date: Mon, 8 Aug 2016 09:15:05 -0400 Subject: [PATCH] catches errors when missing packages. fixes #112 --- docs/config.json.md | 12 ++++++++++-- gulpfile.js | 33 +++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/docs/config.json.md b/docs/config.json.md index b3a3f31..77c1760 100644 --- a/docs/config.json.md +++ b/docs/config.json.md @@ -92,9 +92,17 @@ Name | Type | Default | Description Name | Type | Default | Description -- | -- | -- | -- `header.enabled` | boolean | `false` | Turns on and off the automatic header comment block feature. -`header.packageJsonPath` | string | | Represents the path to your project's `package.json` file. Only applies if `header.enabled` is `true`. +`header.packageJsonPath` | string | | Points to your project's `package.json` file. Only applies if `header.enabled` is `true`. -> Will output a standardized comment block at the start of `js` and `css` files. +> config.json example: +```json +"header": { + "enabled": true, + "packageJsonPath": "../project/package.json" +} +``` + +> Doing so will output a standardized comment block at the start of `js` and `css` files. > Example: ```js /*! diff --git a/gulpfile.js b/gulpfile.js index 6400f5a..e63f722 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,4 +1,5 @@ // 1. LIBRARIES +try { var gulp = require('gulp'), plugins = require('gulp-load-plugins')(), del = require('del'), @@ -15,9 +16,12 @@ var gulp = require('gulp'), validate = require('jsonschema').validate, schema = require('./lib/defaultSchema'), fs = require("fs"), - mkdirp = require('mkdirp'); - -const chalk = require('chalk'); + mkdirp = require('mkdirp'), + chalk = require('chalk'); +} catch (e) { + console.error('Your installation is missing dependencies. Please execute "npm install" again.'); + process.exit(); +} // 2. PREREQUISITES AND ERROR HANDLING @@ -68,15 +72,20 @@ if (config.sass.enabled && config.less.enabled) { // missing project header.packageJsonPath if (config.header.enabled) { - var pkg = require(config.header.packageJsonPath + "package.json"); - var banner = ['/*!', - ' * <%= pkg.name %> - <%= pkg.description %>', - ' * @author v<%= pkg.author %>', - ' * @version v<%= pkg.version %>', - ' * @link <%= pkg.homepage %>', - ' * @license <%= pkg.license %>', - ' */', - ''].join('\n'); + try { + var pkg = require(config.header.packageJsonPath); + var banner = ['/*!', + ' * <%= pkg.name %> - <%= pkg.description %>', + ' * @author v<%= pkg.author %>', + ' * @version v<%= pkg.version %>', + ' * @link <%= pkg.homepage %>', + ' * @license <%= pkg.license %>', + ' */', + ''].join('\n'); + } catch (e) { + console.log(chalk.red.bold("Your 'config.header.packageJsonPath' is invalid. It should point to your package.json file.")); + process.exit(); + } } // 3. SETTINGS VARIABLES