Skip to content

Commit 7be2e54

Browse files
author
Matthew Rourke
committed
Initialize plugin
1 parent 89e3800 commit 7be2e54

6 files changed

Lines changed: 209 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
npm-debug.log
3+
tmp

.jshintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"curly": true,
3+
"eqeqeq": true,
4+
"immed": true,
5+
"latedef": true,
6+
"newcap": true,
7+
"noarg": true,
8+
"sub": true,
9+
"undef": true,
10+
"boss": true,
11+
"eqnull": true,
12+
"node": true
13+
}

Gruntfile.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* grunt-purifycss
3+
* https://github.com/purifycss/grunt-purify-css
4+
*
5+
* Copyright (c) 2015 Phoebe Li, Matthew Rourke, Kenny Tran
6+
* Licensed under the MIT license.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = function(grunt) {
12+
13+
// Project configuration.
14+
grunt.initConfig({
15+
jshint: {
16+
all: [
17+
'Gruntfile.js',
18+
'tasks/*.js',
19+
'<%= nodeunit.tests %>'
20+
],
21+
options: {
22+
jshintrc: '.jshintrc'
23+
}
24+
},
25+
26+
// Before generating any new files, remove any previously-created files.
27+
clean: {
28+
tests: ['tmp']
29+
},
30+
31+
// Configuration to be run (and then tested).
32+
purifycss: {
33+
default_options: {
34+
options: {
35+
},
36+
files: {
37+
'tmp/default_options': ['test/fixtures/testing', 'test/fixtures/123']
38+
}
39+
},
40+
custom_options: {
41+
options: {
42+
separator: ': ',
43+
punctuation: ' !!!'
44+
},
45+
files: {
46+
'tmp/custom_options': ['test/fixtures/testing', 'test/fixtures/123']
47+
},
48+
},
49+
test: {
50+
51+
src: ['test/fixtures/*.html'],
52+
css: ['test/fixtures/styles.css'],
53+
dest: 'tmp/purestyles.css',
54+
hello: 'hello world'
55+
}
56+
},
57+
58+
// Unit tests.grunt
59+
nodeunit: {
60+
tests: ['test/*_test.js']
61+
}
62+
63+
});
64+
65+
// Actually load this plugin's task(s).
66+
grunt.loadTasks('tasks');
67+
68+
// These plugins provide necessary tasks.
69+
grunt.loadNpmTasks('grunt-contrib-jshint');
70+
grunt.loadNpmTasks('grunt-contrib-clean');
71+
grunt.loadNpmTasks('grunt-contrib-nodeunit');
72+
73+
// Whenever the "test" task is run, first clean the "tmp" dir, then run this
74+
// plugin's task(s), then test the result.
75+
grunt.registerTask('test', ['clean', 'purifycss', 'nodeunit']);
76+
77+
// By default, lint and run all tests.
78+
grunt.registerTask('default', ['purifycss:test']);
79+
80+
};

LICENSE-MIT

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2015 Phoebe Li, Matthew Rourke, Kenny Tran
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

package.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "grunt-purifycss",
3+
"description": "Clean unnecessary CSS",
4+
"version": "0.1.0",
5+
"homepage": "https://github.com/purifycss/grunt-purify-css",
6+
"author": {
7+
"name": "Phoebe Li, Matthew Rourke, Kenny Tran"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/purifycss/grunt-purify-css.git"
12+
},
13+
"bugs": {
14+
"url": "https://github.com/purifycss/grunt-purify-css/issues"
15+
},
16+
"licenses": [
17+
{
18+
"type": "MIT",
19+
"url": "https://github.com/purifycss/grunt-purify-css/blob/master/LICENSE-MIT"
20+
}
21+
],
22+
"engines": {
23+
"node": ">= 0.8.0"
24+
},
25+
"scripts": {
26+
"test": "grunt test"
27+
},
28+
"devDependencies": {
29+
"grunt-contrib-jshint": "^0.9.2",
30+
"grunt-contrib-clean": "^0.5.0",
31+
"grunt-contrib-nodeunit": "^0.3.3",
32+
"grunt": "~0.4.5"
33+
},
34+
"peerDependencies": {
35+
"grunt": "~0.4.5"
36+
},
37+
"keywords": [
38+
"gruntplugin"
39+
],
40+
"dependencies": {
41+
"glob": "^5.0.10",
42+
"purify-css": "^1.0.3"
43+
}
44+
}

tasks/purifycss.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* grunt-purifycss
3+
* https://github.com/purifycss/grunt-purify-css
4+
*
5+
* Copyright (c) 2015 Phoebe Li, Matthew Rourke, Kenny Tran
6+
* Licensed under the MIT license.
7+
*/
8+
9+
'use strict';
10+
11+
var glob = require('glob');
12+
var purify = require('purify-css');
13+
14+
module.exports = function(grunt) {
15+
16+
// Please see the Grunt documentation for more information regarding task
17+
// creation: http://gruntjs.com/creating-tasks
18+
19+
grunt.registerMultiTask('purifycss', 'Clean unnecessary CSS', function() {
20+
// Merge task-specific and/or target-specific options with these defaults.
21+
var options = this.options({
22+
});
23+
24+
var src = [];
25+
this.data.src.forEach(function(pathPattern) {
26+
var files = glob.sync(pathPattern);
27+
console.log("glob files: ", files);
28+
src = src.concat(files);
29+
});
30+
31+
var styles = [];
32+
this.data.css.forEach(function(pathPattern) {
33+
var files = glob.sync(pathPattern);
34+
console.log("glob styles: ", files);
35+
styles = styles.concat(files);
36+
})
37+
38+
console.log(src);
39+
console.log(styles);
40+
41+
var pure = purify(src, styles, {write: false, info: true});
42+
43+
grunt.file.write(this.data.dest, pure);
44+
grunt.log.writeln('File "' + this.data.dest + '" created.');
45+
});
46+
47+
};

0 commit comments

Comments
 (0)