Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 6f78e3a4c5f4af8eeed1b7dbcd33fb82ae5aa6c2 @tkellen tkellen committed Oct 3, 2012
Showing with 341 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +82 −0 Gruntfile.js
  3. +22 −0 LICENSE-MIT
  4. +96 −0 README.md
  5. +38 −0 package.json
  6. +48 −0 tasks/concat.js
  7. +48 −0 test/concat_test.js
  8. +1 −0 test/expected/custom_options
  9. +1 −0 test/expected/default_options
  10. +1 −0 test/fixtures/file1
  11. +1 −0 test/fixtures/file2
@@ -0,0 +1,3 @@
+node_modules
+npm-debug.log
+tmp
@@ -0,0 +1,82 @@
+/*
+ * grunt-contrib-concat
+ * https://github.com/gruntjs/grunt-contrib-concat
+ *
+ * Copyright (c) 2012 "Cowboy" Ben Alman
+ * Licensed under the MIT license.
+ */
+
+'use strict';
+
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ jshint: {
+ all: [
+ 'Gruntfile.js',
+ 'tasks/*.js',
+ '<config:nodeunit.tests>'
+ ],
+ options: {
+ curly: true,
+ eqeqeq: true,
+ immed: true,
+ latedef: true,
+ newcap: true,
+ noarg: true,
+ sub: true,
+ undef: true,
+ boss: true,
+ eqnull: true,
+ node: true,
+ es5: true,
+ }
+ },
+
+ // Before generating any new files, remove any previously-created files.
+ clean: {
+ tests: ['tmp']
+ },
+
+ // Configuration to be run (and then tested).
+ concat: {
+ default_options: {
+ options: {
+ },
+ files: {
+ 'tmp/default_options': ['test/fixtures/file1', 'test/fixtures/file2']
+ }
+ },
+ custom_options: {
+ options: {
+ separator: ': ',
+ punctuation: ' !!!'
+ },
+ files: {
+ 'tmp/custom_options': ['test/fixtures/file1', 'test/fixtures/file2']
+ }
+ }
+ },
+
+ // Unit tests.
+ nodeunit: {
+ tests: ['test/*_test.js']
+ }
+
+ });
+
+ // Actually load this plugin's task(s).
+ grunt.loadTasks('tasks');
+
+ // The clean plugin helps in testing.
+ grunt.loadNpmTasks('grunt-contrib-clean');
+
+ // Whenever the "test" task is run, first clean the "tmp" dir, then run this
+ // plugin's task(s), then test the result.
+ grunt.registerTask('test', ['clean', 'concat', 'nodeunit']);
+
+ // By default, lint and run all tests.
+ grunt.registerTask('default', ['jshint', 'test']);
+
+};
@@ -0,0 +1,22 @@
+Copyright (c) 2012 "Cowboy" Ben Alman
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,96 @@
+# grunt-contrib-concat (not released)
+
+> Concatenate files.
+
+## Getting Started
+_If you haven't used [grunt][] before, be sure to check out the [Getting Started][] guide._
+
+Install this grunt plugin next to your project's [Gruntfile][Getting Started] with the following command. This will also add the plugin to your project's `package.json` file as a `devDependency`.
+
+```
+npm install grunt-contrib-concat --save-dev
+```
+
+Then add this line to your project's Gruntfile:
+
+```javascript
+grunt.loadNpmTasks('grunt-contrib-concat');
+```
+
+If the plugin was installed correctly, running `grunt --help` at the command line should list the newly-installed plugin's task(s) as a local Npm module task.
+
+[grunt]: http://gruntjs.com/
+[Getting Started]: https://github.com/gruntjs/grunt/blob/devel/docs/getting_started.md
+
+## Overview
+In your project's Gruntfile, add a section named `contrib_concat` to the data object passed into `grunt.initConfig()`.
+
+```js
+grunt.initConfig({
+ contrib_concat: {
+ options: {
+ // Task-specific options go here.
+ },
+ your_target: {
+ // Target-specific file lists and/or options go here.
+ },
+ },
+})
+```
+
+## Options
+
+### options.separator
+Type: `String`
+Default value: `', '`
+
+A string value that is used to do something with whatever.
+
+### options.punctuation
+Type: `String`
+Default value: `'.'`
+
+A string value that is used to do something else with whatever else.
+
+## Usage Examples
+
+### Default Options
+In this example, the default options are used to do something with whatever. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result would be `Testing, 1 2 3.`
+
+```js
+grunt.initConfig({
+ contrib_concat: {
+ options: {},
+ files: {
+ 'dest/default_options': ['src/testing', 'src/123'],
+ },
+ },
+})
+```
+
+### Custom Options
+In this example, custom options are used to do something else with whatever else. So if the `testing` file has the content `Testing` and the `123` file had the content `1 2 3`, the generated result in this case would be `Testing: 1 2 3 !!!`
+
+```js
+grunt.initConfig({
+ contrib_concat: {
+ options: {
+ separator: ': ',
+ punctuation: ' !!!',
+ },
+ files: {
+ 'dest/default_options': ['src/testing', 'src/123'],
+ },
+ },
+})
+```
+
+## Contributing
+In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt][].
+
+## Release History
+_(Nothing yet)_
+
+--
+
+Task submitted by ["Cowboy" Ben Alman](https://github.com/cowboy).
@@ -0,0 +1,38 @@
+{
+ "name": "grunt-contrib-concat",
+ "description": "Concatenate files.",
+ "version": "0.4.0",
+ "homepage": "https://github.com/gruntjs/grunt-contrib-concat",
+ "author": {
+ "name": "\"Cowboy\" Ben Alman",
+ "email": "cowboy@rj3.net",
+ "url": "http://gruntjs.com/"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/gruntjs/grunt-contrib-concat.git"
+ },
+ "bugs": {
+ "url": "https://github.com/gruntjs/grunt-contrib-concat/issues"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "https://github.com/gruntjs/grunt-contrib-concat/blob/master/LICENSE-MIT"
+ }
+ ],
+ "main": "Gruntfile.js",
+ "engines": {
+ "node": ">= 0.6.0"
+ },
+ "scripts": {
+ "test": "grunt test"
+ },
+ "devDependencies": {
+ "grunt-contrib-clean": "0.4.0a",
+ "grunt": "~0.4.0a"
+ },
+ "keywords": [
+ "gruntplugin"
+ ]
+}
@@ -0,0 +1,48 @@
+/*
+ * grunt-contrib-concat
+ * https://gruntjs.com/
+ *
+ * Copyright (c) 2012 "Cowboy" Ben Alman, contributors
+ * Licensed under the MIT license.
+ */
+
+'use strict';
+
+module.exports = function(grunt) {
+
+ grunt.registerMultiTask('concat', 'Concatenate files.', function() {
+ // Merge task-specific and/or target-specific options with these defaults.
+ var options = this.options({
+ punctuation: '.',
+ separator: ', '
+ });
+
+ // Iterate over all specified file groups.
+ this.files.forEach(function(fileObj) {
+ // The source files to be concatenated. The "nonull" option is used
+ // to retain invalid files/patterns so they can be warned about.
+ var files = grunt.file.expand({nonull: true}, fileObj.src);
+
+ // Concat specified files.
+ var src = files.map(function(filepath) {
+ // Warn if a source file/pattern was invalid.
+ if (!grunt.file.exists(filepath)) {
+ grunt.log.error('Source file "' + filepath + '" not found.');
+ return '';
+ }
+ // Read file source.
+ return grunt.file.read(filepath);
+ }).join(options.separator);
+
+ // Handle options.
+ src += options.punctuation;
+
+ // Write the destination file.
+ grunt.file.write(fileObj.dest, src);
+
+ // Print a success message.
+ grunt.log.writeln('File "' + fileObj.dest + '" created.');
+ });
+ });
+
+};
@@ -0,0 +1,48 @@
+'use strict';
+
+var grunt = require('grunt');
+
+/*
+ ======== A Handy Little Nodeunit Reference ========
+ https://github.com/caolan/nodeunit
+
+ Test methods:
+ test.expect(numAssertions)
+ test.done()
+ Test assertions:
+ test.ok(value, [message])
+ test.equal(actual, expected, [message])
+ test.notEqual(actual, expected, [message])
+ test.deepEqual(actual, expected, [message])
+ test.notDeepEqual(actual, expected, [message])
+ test.strictEqual(actual, expected, [message])
+ test.notStrictEqual(actual, expected, [message])
+ test.throws(block, [error], [message])
+ test.doesNotThrow(block, [error], [message])
+ test.ifError(value)
+*/
+
+exports.contrib_concat = {
+ setUp: function(done) {
+ // setup here if necessary
+ done();
+ },
+ default_options: function(test) {
+ test.expect(1);
+
+ var actual = grunt.file.read('tmp/default_options');
+ var expected = grunt.file.read('test/expected/default_options');
+ test.equal(actual, expected, 'should describe what the default behavior is.');
+
+ test.done();
+ },
+ custom_options: function(test) {
+ test.expect(1);
+
+ var actual = grunt.file.read('tmp/custom_options');
+ var expected = grunt.file.read('test/expected/custom_options');
+ test.equal(actual, expected, 'should describe what the custom option(s) behavior is.');
+
+ test.done();
+ },
+};
@@ -0,0 +1 @@
+file1: file2 !!!
@@ -0,0 +1 @@
+file1, file2.
@@ -0,0 +1 @@
+file1
@@ -0,0 +1 @@
+file2

0 comments on commit 6f78e3a

Please sign in to comment.