Skip to content

Commit ecbf3e5

Browse files
author
coder.se
committed
Initial Grunt plugin files
1 parent 671817e commit ecbf3e5

11 files changed

+251
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
npm-debug.log
3+
tmp

.jshintrc

+13
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

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* grunt-cdr-inject
3+
* https://github.com/coder-se/grunt-cdr-inject
4+
*
5+
* Copyright (c) 2014
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+
cdr_inject: {
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+
},
50+
51+
// Unit tests.
52+
nodeunit: {
53+
tests: ['test/*_test.js'],
54+
},
55+
56+
});
57+
58+
// Actually load this plugin's task(s).
59+
grunt.loadTasks('tasks');
60+
61+
// These plugins provide necessary tasks.
62+
grunt.loadNpmTasks('grunt-contrib-jshint');
63+
grunt.loadNpmTasks('grunt-contrib-clean');
64+
grunt.loadNpmTasks('grunt-contrib-nodeunit');
65+
66+
// Whenever the "test" task is run, first clean the "tmp" dir, then run this
67+
// plugin's task(s), then test the result.
68+
grunt.registerTask('test', ['clean', 'cdr_inject', 'nodeunit']);
69+
70+
// By default, lint and run all tests.
71+
grunt.registerTask('default', ['jshint', 'test']);
72+
73+
};

LICENSE-MIT

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2014
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

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "grunt-cdr-inject",
3+
"description": "The best Grunt plugin ever.",
4+
"version": "0.1.0",
5+
"homepage": "https://github.com/coder-se/grunt-cdr-inject",
6+
"author": {},
7+
"repository": {
8+
"type": "git",
9+
"url": "git://github.com/coder-se/grunt-cdr-inject.git"
10+
},
11+
"bugs": {
12+
"url": "https://github.com/coder-se/grunt-cdr-inject/issues"
13+
},
14+
"licenses": [
15+
{
16+
"type": "MIT",
17+
"url": "https://github.com/coder-se/grunt-cdr-inject/blob/master/LICENSE-MIT"
18+
}
19+
],
20+
"engines": {
21+
"node": ">= 0.8.0"
22+
},
23+
"scripts": {
24+
"test": "grunt test"
25+
},
26+
"devDependencies": {
27+
"grunt-contrib-jshint": "^0.9.2",
28+
"grunt-contrib-clean": "^0.5.0",
29+
"grunt-contrib-nodeunit": "^0.3.3",
30+
"grunt": "~0.4.4"
31+
},
32+
"peerDependencies": {
33+
"grunt": "~0.4.4"
34+
},
35+
"keywords": [
36+
"gruntplugin"
37+
]
38+
}

tasks/cdr_inject.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* grunt-cdr-inject
3+
* https://github.com/coder-se/grunt-cdr-inject
4+
*
5+
* Copyright (c) 2014
6+
* Licensed under the MIT license.
7+
*/
8+
9+
'use strict';
10+
11+
module.exports = function(grunt) {
12+
13+
// Please see the Grunt documentation for more information regarding task
14+
// creation: http://gruntjs.com/creating-tasks
15+
16+
grunt.registerMultiTask('cdr_inject', 'The best Grunt plugin ever.', function() {
17+
// Merge task-specific and/or target-specific options with these defaults.
18+
var options = this.options({
19+
punctuation: '.',
20+
separator: ', '
21+
});
22+
23+
// Iterate over all specified file groups.
24+
this.files.forEach(function(f) {
25+
// Concat specified files.
26+
var src = f.src.filter(function(filepath) {
27+
// Warn on and remove invalid source files (if nonull was set).
28+
if (!grunt.file.exists(filepath)) {
29+
grunt.log.warn('Source file "' + filepath + '" not found.');
30+
return false;
31+
} else {
32+
return true;
33+
}
34+
}).map(function(filepath) {
35+
// Read file source.
36+
return grunt.file.read(filepath);
37+
}).join(grunt.util.normalizelf(options.separator));
38+
39+
// Handle options.
40+
src += options.punctuation;
41+
42+
// Write the destination file.
43+
grunt.file.write(f.dest, src);
44+
45+
// Print a success message.
46+
grunt.log.writeln('File "' + f.dest + '" created.');
47+
});
48+
});
49+
50+
};

test/cdr_inject_test.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
3+
var grunt = require('grunt');
4+
5+
/*
6+
======== A Handy Little Nodeunit Reference ========
7+
https://github.com/caolan/nodeunit
8+
9+
Test methods:
10+
test.expect(numAssertions)
11+
test.done()
12+
Test assertions:
13+
test.ok(value, [message])
14+
test.equal(actual, expected, [message])
15+
test.notEqual(actual, expected, [message])
16+
test.deepEqual(actual, expected, [message])
17+
test.notDeepEqual(actual, expected, [message])
18+
test.strictEqual(actual, expected, [message])
19+
test.notStrictEqual(actual, expected, [message])
20+
test.throws(block, [error], [message])
21+
test.doesNotThrow(block, [error], [message])
22+
test.ifError(value)
23+
*/
24+
25+
exports.cdr_inject = {
26+
setUp: function(done) {
27+
// setup here if necessary
28+
done();
29+
},
30+
default_options: function(test) {
31+
test.expect(1);
32+
33+
var actual = grunt.file.read('tmp/default_options');
34+
var expected = grunt.file.read('test/expected/default_options');
35+
test.equal(actual, expected, 'should describe what the default behavior is.');
36+
37+
test.done();
38+
},
39+
custom_options: function(test) {
40+
test.expect(1);
41+
42+
var actual = grunt.file.read('tmp/custom_options');
43+
var expected = grunt.file.read('test/expected/custom_options');
44+
test.equal(actual, expected, 'should describe what the custom option(s) behavior is.');
45+
46+
test.done();
47+
},
48+
};

test/expected/custom_options

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Testing: 1 2 3 !!!

test/expected/default_options

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Testing, 1 2 3.

test/fixtures/123

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1 2 3

test/fixtures/testing

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Testing

0 commit comments

Comments
 (0)