Skip to content

Commit 28751e8

Browse files
committed
grunt-init
1 parent 9eee200 commit 28751e8

12 files changed

+342
-3
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-jstransform
3+
* https://github.com/heftybyte/grunt-jstransform
4+
*
5+
* Copyright (c) 2014 Esco Obong
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+
jstransform: {
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', 'jstransform', '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 Esco Obong
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.

README.md

+88-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,89 @@
1-
grunt-jstransform
2-
=================
1+
# grunt-jstransform
32

4-
Grunt task for transpiling ES6 --> ES5 using [Facebook's jstransform](https://github.com/facebook/jstransform)
3+
> Grunt task for transpiling ES6 --> ES5 using [Facebook's jstransform](https://github.com/facebook/jstransform)
4+
5+
## Getting Started
6+
This plugin requires Grunt `~0.4.4`
7+
8+
If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
9+
10+
```shell
11+
npm install grunt-jstransform --save-dev
12+
```
13+
14+
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
15+
16+
```js
17+
grunt.loadNpmTasks('grunt-jstransform');
18+
```
19+
20+
## The "jstransform" task
21+
22+
### Overview
23+
In your project's Gruntfile, add a section named `jstransform` to the data object passed into `grunt.initConfig()`.
24+
25+
```js
26+
grunt.initConfig({
27+
jstransform: {
28+
options: {
29+
// Task-specific options go here.
30+
},
31+
your_target: {
32+
// Target-specific file lists and/or options go here.
33+
},
34+
},
35+
});
36+
```
37+
38+
### Options
39+
40+
#### options.separator
41+
Type: `String`
42+
Default value: `', '`
43+
44+
A string value that is used to do something with whatever.
45+
46+
#### options.punctuation
47+
Type: `String`
48+
Default value: `'.'`
49+
50+
A string value that is used to do something else with whatever else.
51+
52+
### Usage Examples
53+
54+
#### Default Options
55+
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.`
56+
57+
```js
58+
grunt.initConfig({
59+
jstransform: {
60+
options: {},
61+
files: {
62+
'dest/default_options': ['src/testing', 'src/123'],
63+
},
64+
},
65+
});
66+
```
67+
68+
#### Custom Options
69+
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 !!!`
70+
71+
```js
72+
grunt.initConfig({
73+
jstransform: {
74+
options: {
75+
separator: ': ',
76+
punctuation: ' !!!',
77+
},
78+
files: {
79+
'dest/default_options': ['src/testing', 'src/123'],
80+
},
81+
},
82+
});
83+
```
84+
85+
## Contributing
86+
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](http://gruntjs.com/).
87+
88+
## Release History
89+
_(Nothing yet)_

package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "grunt-jstransform",
3+
"description": "Grunt task for transpiling ES6 --> ES5 using Facebook's jstransform",
4+
"version": "0.0.1",
5+
"homepage": "https://github.com/heftybyte/grunt-jstransform",
6+
"author": {
7+
"name": "Esco Obong",
8+
"email": "[email protected]"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git://github.com/heftybyte/grunt-jstransform.git"
13+
},
14+
"bugs": {
15+
"url": "https://github.com/heftybyte/grunt-jstransform/issues"
16+
},
17+
"licenses": [
18+
{
19+
"type": "MIT",
20+
"url": "https://github.com/heftybyte/grunt-jstransform/blob/master/LICENSE-MIT"
21+
}
22+
],
23+
"engines": {
24+
"node": ">= 0.8.0"
25+
},
26+
"scripts": {
27+
"test": "grunt test"
28+
},
29+
"devDependencies": {
30+
"grunt-contrib-jshint": "~0.6.0",
31+
"grunt-contrib-clean": "~0.4.0",
32+
"grunt-contrib-nodeunit": "~0.2.0",
33+
"grunt": "~0.4.4"
34+
},
35+
"peerDependencies": {
36+
"grunt": "~0.4.4"
37+
},
38+
"keywords": [
39+
"gruntplugin"
40+
]
41+
}

tasks/jstransform.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* grunt-jstransform
3+
* https://github.com/heftybyte/grunt-jstransform
4+
*
5+
* Copyright (c) 2014 Esco Obong
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('jstransform', 'Grunt task for transpiling ES6 --> ES5 using Facebook's jstransform', 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/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

test/jstransform_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.jstransform = {
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+
};

0 commit comments

Comments
 (0)