Skip to content

Commit

Permalink
Check for existence of file, use @requires as default directive
Browse files Browse the repository at this point in the history
  • Loading branch information
backflip committed Feb 25, 2014
1 parent 3e017a5 commit 09b8b90
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var concat = require('gulp-concat');
gulp.task('js', function(){
gulp.src(['app/assets/js/main.js'])
.pipe(resolveDependencies({
pattern: /\* @depend (.*?\.js)/g
pattern: /\* @requires [\s-]*(.*?\.js)/g
})
.pipe(concat())
.pipe(gulp.dest('dest/assets/js/'));
Expand All @@ -29,8 +29,8 @@ And use the directives in your JS files (dependencies can be nested, they are ha
```javascript
/**
* @depend libs/jquery/jquery.js
* @depend ../modules/slideshow/slideshow.js
* @requires libs/jquery/jquery.js
* @requires ../modules/slideshow/slideshow.js
*/

(function(window, document, $, undefined) {
Expand All @@ -53,7 +53,7 @@ And use the directives in your JS files (dependencies can be nested, they are ha
#### options.pattern
Type: `RegExp`
The matching pattern (optional, defaults to ```/\* @depend (.*?\.js)/g``).
The matching pattern (optional, defaults to ```/\* @requires [\s-]*(.*?\.js)/g``).

#### options.log
Type: `Boolean`
Expand Down
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ function resolveDependencies(config) {
continue;
}

// Check existence
if (!fs.existsSync(filePath)) {
gutil.log('[' + gutil.colors.red(PLUGIN_NAME) + '] File not found: ', filePath);
continue;
}

// Create new file
file = new gutil.File({
base: targetFile.base,
Expand All @@ -60,7 +66,7 @@ function resolveDependencies(config) {

// Set default values
config = _.merge({
pattern: /\* @depend (.*?\.js)/g,
pattern: /\* @requires [\s-]*(.*?\.js)/g,
log: false
}, config);

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gulp-resolve-dependencies",
"version": "0.0.1",
"description": "Resolve dependency directives in assets (e.g. \"@depend\" or \"//= require\" in JavaScript)",
"version": "0.1.0",
"description": "Resolve dependency directives in assets (e.g. \"@requires\" or \"//= require\" in JavaScript)",
"license": "MIT",
"repository": "backflip/gulp-resolve-dependencies",
"author": "Thomas Jaggi",
Expand Down
4 changes: 2 additions & 2 deletions test/expected/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
console.log('lib.js');

/**
* @depend ../libs/lib.js
* @requires ../libs/lib.js
*/
console.log('test.js');

/**
* @depend test/test.js
* @requires test/test.js
*/
console.log('main.js');
2 changes: 1 addition & 1 deletion test/fixtures/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* @depend test/test.js
* @requires test/test.js
*/
console.log('main.js');
2 changes: 1 addition & 1 deletion test/fixtures/test/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* @depend ../libs/lib.js
* @requires ../libs/lib.js
*/
console.log('test.js');

0 comments on commit 09b8b90

Please sign in to comment.