Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fileExists helper + symlinks #12

Merged
merged 2 commits into from

2 participants

@jbenet

This PR adds support for using symlinks (for compiler, builder, and depswriter), using stat.isFile() || stat.isSymboliclink().

Note commit message in 4b55786:

This commit de-duplicates code into a helper. Though helpers are
going away in grunt 0.4.0, this is a step forward. The function that
are currently helpers will need to be included some other way
jbenet added some commits
@jbenet jbenet helper: file exists
This commit de-duplicates code into a helper. Though helpers are
going away in grunt 0.4.0, this is a step forward. The function that
are currently helpers will need to be included some other way.
4b55786
@jbenet jbenet fileExists: allow symlinks 3f44167
@thanpolas thanpolas merged commit 187dc14 into thanpolas:master
@thanpolas
Owner

Looks good, thanks :)

v0.6.11 published

@jbenet

great! thanks for the speedy response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 7, 2012
  1. @jbenet

    helper: file exists

    jbenet authored
    This commit de-duplicates code into a helper. Though helpers are
    going away in grunt 0.4.0, this is a step forward. The function that
    are currently helpers will need to be included some other way.
  2. @jbenet

    fileExists: allow symlinks

    jbenet authored
This page is out of date. Refresh to see the latest.
View
18 tasks/closureBuilder.js
@@ -128,14 +128,7 @@ function validate(grunt, data)
// ---
// validate builder existence
// ---
- var fileExists = false;
- try {
- if (fs.lstatSync(builder).isFile()) {
- fileExists = true;
- }
- }
- catch (e) {}
- if (!fileExists) {
+ if (!grunt.helper('fileExists', builder)) {
grunt.log.error('ERROR'.red + ' :: builder file/path not valid: ' + builder.red);
return false;
}
@@ -197,14 +190,7 @@ function compileCommand(grunt, params, data)
// see if we have compiler set, will override any operation
if (data.compile) {
// we got something, check if file is there...
- var fileExists = false;
- try {
- if (fs.lstatSync(data.compiler).isFile()) {
- fileExists = true;
- }
- }
- catch (e) {}
- if (!fileExists) {
+ if (!grunt.helper('fileExists', data.compiler)) {
grunt.log.error('ERROR'.red + ' :: compiler .jar location not valid: ' + data.compiler.red);
return false;
}
View
9 tasks/closureCompiler.js
@@ -118,14 +118,7 @@ function validate(grunt, data)
//
// check compiler's existence
//
- var fileExists = false;
- try {
- if (fs.lstatSync(compiler).isFile()) {
- fileExists = true;
- }
- }
- catch (e) {}
- if (!fileExists) {
+ if (!grunt.helper('fileExists', compiler)) {
grunt.log.error('ERROR'.red + ' :: compiler filepath not valid: ' + compiler.red);
return false;
}
View
9 tasks/closureDepsWriter.js
@@ -108,14 +108,7 @@ function validate(grunt, data)
// ---
// check depswriter existence
// ---
- var fileExists = false;
- try {
- if (fs.lstatSync(depswriter).isFile()) {
- fileExists = true;
- }
- }
- catch (e) {}
- if (!fileExists) {
+ if (!grunt.helper('fileExists', depswriter)) {
grunt.log.error('ERROR'.red + ' :: depswriter file/path not valid: ' + depswriter);
return false;
}
View
13 tasks/helpers.js
@@ -100,4 +100,17 @@ module.exports = function(grunt) {
});
+ /**
+ * Checks existence of a file (allows symlinks)
+ *
+ * @param {string} filePath path to check
+ */
+ grunt.registerHelper('fileExists', function (filePath) {
+ try {
+ var stat = fs.lstatSync(filePath);
+ if (stat.isFile() || stat.isSymbolicLink())
+ return true;
+ } catch (e) {};
+ return false;
+ });
};
Something went wrong with that request. Please try again.