Skip to content

Commit

Permalink
catches errors when missing packages.
Browse files Browse the repository at this point in the history
fixes #112
  • Loading branch information
vincentmorneau committed Aug 8, 2016
1 parent 8995528 commit a4d25f4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
12 changes: 10 additions & 2 deletions docs/config.json.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
/*!
Expand Down
33 changes: 21 additions & 12 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// 1. LIBRARIES
try {
var gulp = require('gulp'),
plugins = require('gulp-load-plugins')(),
del = require('del'),
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a4d25f4

Please sign in to comment.