Skip to content
This repository has been archived by the owner on Dec 6, 2019. It is now read-only.

Directory resolve fix #48

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"scripts": {
"test": "grunt test",
"postinstall": "bower install"
"postinstall": "bower install --allow-root"
},
"devDependencies": {
"grunt": ">=0.4.5",
Expand All @@ -54,7 +54,8 @@
},
"peerDependencies": {
"phantomjs-prebuilt": "~2.1.3",
"grunt": ">=0.4.5"
"grunt": ">=0.4.5",
"casperjs": "^1.1.1"
},
"keywords": [
"gruntplugin",
Expand Down
33 changes: 31 additions & 2 deletions tasks/phantomcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,39 @@

var path = require('path');
var tmp = require('tmp');
var fs = require('fs');

function resolveDirectory(pathPart, maxLevel) {
var pathPrefix = __dirname + '/';
var resultPath;
for (var i = 0; i < maxLevel; ++i) {
var folderPath = path.resolve(pathPrefix + pathPart);

try {
var stats = fs.statSync(folderPath);
if (stats.isDirectory()) {
resultPath = folderPath;
break;
}
} catch(e) {
// just do nothing and try the next path
}

pathPrefix += '../';
}

if (!resultPath) {
throw new Error('Cannot find ' + pathPart);
}

return resultPath;
}


var phantomBinaryPath = require('phantomjs-prebuilt').path;
var runnerPath = path.join(__dirname, '..', 'phantomjs', 'runner.js');
var phantomCSSPath = path.join(__dirname, '..', 'node_modules', 'phantomcss');
var casperPath = path.join(__dirname, '..', 'node_modules', 'casperjs');
var phantomCSSPath = resolveDirectory('node_modules/phantomcss', 5);
var casperPath = resolveDirectory('node_modules/casperjs', 5);

module.exports = function(grunt) {
grunt.registerMultiTask('phantomcss', 'CSS Regression Testing', function() {
Expand Down