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

Cleanup files #5

Open
wants to merge 4 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
64 changes: 64 additions & 0 deletions .jscs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"disallowEmptyBlocks": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowQuotedKeysInObjects": true,
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpaceBeforeBinaryOperators": [
","
],
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"disallowYodaConditions": true,
"disallowKeywords": [ "with" ],
"disallowMultipleLineBreaks": true,
"disallowMultipleVarDecl": true,
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": true,
"requireBlocksOnNewline": 1,
"requireCommaBeforeLineBreak": true,
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceAfterBinaryOperators": true,
"requireCamelCaseOrUpperCaseIdentifiers": true,
"requireLineFeedAtFileEnd": true,
"requireCapitalizedConstructors": true,
"requireDotNotation": true,
"requireSpacesInForStatement": true,
"requireSpaceBetweenArguments": true,
"requireCurlyBraces": [
"do"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"case",
"return",
"try",
"catch",
"typeof"
],
"safeContextKeyword": "_this",
"validateLineBreaks": "LF",
"validateQuoteMarks": "'",
"validateIndentation": "\t"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Or add the following line to your `package.json`:
Then, once the plugin has been installed via `npm install`, it may be enabled inside your Gruntfile with this line of JavaScript:

```js
grunt.loadNpmTasks('grunt-phantomcss');
grunt.loadNpmTasks('@micahgodbolt/grunt-phantomcss');
```

## The "phantomcss" task
Expand Down
2 changes: 1 addition & 1 deletion phantomjs/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ phantomcss.init({
} else {
return name + '.png';
}
},
}
});

casper.start();
Expand Down
50 changes: 10 additions & 40 deletions tasks/phantomcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,52 +48,22 @@ module.exports = function(grunt) {
// Create a temporary file for message passing between the task and PhantomJS
var tempFile = new tmp.File();

var deleteDiffScreenshots = function(folderpath) {
var deleteScreenshots = function(pattern) {
// Find diff/fail files
var diffScreenshots = grunt.file.expand([
path.join(folderpath + '/' + options.screenshots, '*diff.png'),
path.join(folderpath + '/' + options.screenshots, '*fail.png'),
var screenshots = grunt.file.expand([
path.join(options.screenshots, pattern)
]);

// Delete all of 'em
diffScreenshots.forEach(function(filepath) {
grunt.file.delete(filepath);
});
};

var deleteDiffResults = function(folderpath) {
// Find diff/fail files
var diffScreenshots = grunt.file.expand([
path.join(folderpath, options.results),
]);

// Delete all of 'em
diffScreenshots.forEach(function(filepath) {
grunt.file.delete(filepath);
screenshots.forEach(function(filepath) {
grunt.file.delete(filepath, { force: true });
});
};

var cleanup = function(error) {
// Remove temporary file
tempFile.unlink();

options.testFolder.forEach(function(folderpath) {
// Create the output directory
grunt.file.mkdir(folderpath + '/' + options.results);

// Copy fixtures, diffs, and failure images to the results directory
var allScreenshots = grunt.file.expand(path.join(folderpath + '/' + options.screenshots, '**.png'));

allScreenshots.forEach(function(filepath) {
grunt.file.copy(filepath, path.join(
folderpath + '/' + options.results,
path.basename(filepath)
));
});

deleteDiffScreenshots(folderpath);
});

deleteScreenshots('*diff.png');
done(error || failureCount === 0);
};

Expand Down Expand Up @@ -180,8 +150,8 @@ module.exports = function(grunt) {
// Remove old diff screenshots

options.testFolder.forEach(function(folderpath) {
deleteDiffScreenshots(folderpath);
deleteDiffResults(folderpath);
deleteScreenshots('*diff.png');
deleteScreenshots('*fail.png');
});

// Start watching for messages
Expand All @@ -190,8 +160,8 @@ module.exports = function(grunt) {
grunt.util.spawn({
cmd: phantomBinaryPath,
args: [
runnerPath,
JSON.stringify(options),
runnerPath,
JSON.stringify(options)
],
opts: {
cwd: cwd,
Expand Down