-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 85af37e
Showing
16 changed files
with
440 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
npm-debug.log | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"sub": true, | ||
"undef": true, | ||
"boss": true, | ||
"eqnull": true, | ||
"node": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* grunt-importer | ||
* https://github.com/colinbowern/grunt-importer | ||
* | ||
* Copyright (c) 2013 Colin Bowern | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function (grunt) { | ||
|
||
// Project configuration. | ||
grunt.initConfig({ | ||
jshint: { | ||
all: [ | ||
'Gruntfile.js', | ||
'tasks/*.js', | ||
'<%= nodeunit.tests %>', | ||
], | ||
options: { | ||
jshintrc: '.jshintrc', | ||
}, | ||
}, | ||
|
||
// Before generating any new files, remove any previously-created files. | ||
clean: { | ||
tests: ['tmp'], | ||
}, | ||
|
||
// Setup for tests | ||
copy: { | ||
tests: { | ||
files: [{ | ||
expand: true, | ||
cwd: 'test/fixtures', | ||
src: ['**/*.*', '!**/*.template.js'], | ||
dest: 'tmp/replace_single_file' | ||
}, | ||
{ | ||
expand: true, | ||
cwd: 'test/fixtures', | ||
src: ['**/*.*', '!**/*.template.js'], | ||
dest: 'tmp/replace_multiple_files' | ||
}, | ||
{ | ||
expand: true, | ||
cwd: 'test/fixtures', | ||
src: ['**/*.*', '!foo.js'], | ||
dest: 'tmp/rename_file' | ||
}] | ||
} | ||
}, | ||
|
||
// Configurations to be tested | ||
importer: { | ||
replace_single_file: { | ||
files: [{ src: 'tmp/replace_single_file/foo.js' }] | ||
}, | ||
replace_multiple_files: { | ||
files: [{ src: 'tmp/replace_multiple_files/*.js' }] | ||
}, | ||
rename_file: { | ||
files: [{ | ||
expand: true, | ||
src: 'tmp/rename_file/foo.template.js', | ||
rename: function (dest, src) { | ||
return (dest || '') + src.replace('.template.js', '.js'); | ||
} | ||
}] | ||
}, | ||
different_output_folder: { | ||
files : [{ | ||
expand: true, | ||
flatten: true, | ||
src: 'test/fixtures/foo.js', | ||
dest: 'tmp/different_output_folder/' | ||
}] | ||
}, | ||
different_output_folder_and_rename: { | ||
files: [{ | ||
expand: true, | ||
flatten: true, | ||
src: 'test/fixtures/foo.template.js', | ||
dest: 'tmp/different_output_folder_and_rename/', | ||
rename: function (dest, src) { | ||
return (dest || '') + src.replace('.template.js', '.js'); | ||
} | ||
}] | ||
} | ||
}, | ||
|
||
// Unit tests | ||
nodeunit: { | ||
tests: ['test/*_test.js'], | ||
}, | ||
|
||
}); | ||
|
||
// Actually load this plugin's task(s). | ||
grunt.loadTasks('tasks'); | ||
|
||
// These plugins provide necessary tasks. | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-contrib-clean'); | ||
grunt.loadNpmTasks('grunt-contrib-nodeunit'); | ||
grunt.loadNpmTasks('grunt-contrib-copy'); | ||
|
||
// 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', 'copy', 'importer', 'nodeunit']); | ||
|
||
// By default, lint and run all tests. | ||
grunt.registerTask('default', ['jshint', 'test']); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2013 Colin Bowern | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# grunt-importer | ||
|
||
> Importer adds an #import statement to JavaScript based languages including CoffeeScript that works like #include in C-based languages. It concatenates them together in the places you've defined. | ||
## Getting Started | ||
This plugin requires Grunt `~0.4.1` | ||
|
||
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: | ||
|
||
```shell | ||
npm install grunt-importer --save-dev | ||
``` | ||
|
||
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: | ||
|
||
```js | ||
grunt.loadNpmTasks('grunt-importer'); | ||
``` | ||
|
||
## The "importer" task | ||
|
||
### Overview | ||
In your project's Gruntfile, add a section named `importer` to the data object passed into `grunt.initConfig()`. | ||
|
||
```js | ||
grunt.initConfig({ | ||
importer: { | ||
scripts: { | ||
files: [{ | ||
expand: true, | ||
src: 'scripts/layout.template.js', | ||
rename: function (dest, src) { | ||
return (dest || '') + src.replace('.template.js', '.js'); | ||
} | ||
}] | ||
}, | ||
}, | ||
}) | ||
``` | ||
|
||
### Usage Examples | ||
|
||
#### Replace a Single File | ||
In this example the script would be replaced in-place with any import statements substituted for their references. | ||
|
||
```js | ||
grunt.initConfig({ | ||
importer: { | ||
scripts: { | ||
files: [{ src: 'tmp/replace_single_file/foo.js' }] | ||
} | ||
}, | ||
}) | ||
``` | ||
|
||
#### Output to Different Folder and Rename | ||
In this example the dynamic file expanding object is used to output the results to a different folder using a different file name: | ||
|
||
```js | ||
grunt.initConfig({ | ||
importer: { | ||
scripts: { | ||
files: [{ | ||
expand: true, | ||
flatten: true, | ||
src: 'test/fixtures/foo.template.js', | ||
dest: 'tmp/different_output_folder_and_rename/', | ||
rename: function (dest, src) { | ||
return (dest || '') + src.replace('.template.js', '.js'); | ||
} | ||
}] | ||
}, | ||
}, | ||
}) | ||
``` | ||
|
||
## 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](http://gruntjs.com/). | ||
|
||
## Release History | ||
* 2013-10-04 v1.0.0 Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node --debug-brk $env:APPDATA\npm\node_modules\grunt-cli\bin\grunt --force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"name": "grunt-importer", | ||
"description": "Importer adds an #import statement to JavaScript based languages including CoffeeScript that works like #include in C-based languages. It compiles files into JavaScript, concatenates them together in the places you've defined, and generates source maps.", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/colinbowern/grunt-importer", | ||
"author": { | ||
"name": "Colin Bowern", | ||
"email": "colin@bowern.com", | ||
"url": "http://colinbowern.com" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/colinbowern/grunt-importer.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/colinbowern/grunt-importer/issues" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/colinbowern/grunt-importer/blob/master/LICENSE-MIT" | ||
} | ||
], | ||
"main": "Gruntfile.js", | ||
"engines": { | ||
"node": ">= 0.8.0" | ||
}, | ||
"scripts": { | ||
"test": "grunt test" | ||
}, | ||
"devDependencies": { | ||
"grunt-contrib-jshint": "~0.6.0", | ||
"grunt-contrib-clean": "~0.4.0", | ||
"grunt-contrib-nodeunit": "~0.2.0", | ||
"grunt": "~0.4.1", | ||
"grunt-contrib-copy": "~0.4.1" | ||
}, | ||
"peerDependencies": { | ||
"grunt": "~0.4.1" | ||
}, | ||
"keywords": [ | ||
"gruntplugin" | ||
], | ||
"dependencies": { | ||
"importer": "~0.7.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* grunt-importer | ||
* https://github.com/colinbowern/grunt-importer | ||
* | ||
* Copyright (c) 2013 Colin Bowern | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function (grunt) { | ||
|
||
var importer = require('importer'), | ||
path = require('path'), | ||
fs = require('fs'); | ||
|
||
grunt.registerMultiTask('importer', 'Importer adds an #import statement to JavaScript based languages including CoffeeScript that works like #include in C-based languages. It compiles files into JavaScript, concatenates them together in the places you have defined, and generates source maps.', function () { | ||
var done = this.async(); | ||
|
||
if (this.files.length < 1) { | ||
grunt.verbose.warn('No source files provided, nothing to do.'); | ||
} | ||
|
||
grunt.util.async.forEachSeries(this.files, function (f, nextFileObj) { | ||
var destination = f.dest; | ||
|
||
var files = f.src.filter(function (filepath) { | ||
if (!grunt.file.exists(filepath)) { | ||
grunt.log.warn('Source file "' + filepath + '" was not found.'); | ||
return false; | ||
} else { | ||
return true; | ||
} | ||
}); | ||
|
||
if (files.length === 0) { | ||
if (f.src.length < 1) { | ||
grunt.log.warn('No source files found, nothing to do.'); | ||
} | ||
return nextFileObj(); | ||
} | ||
|
||
grunt.util.async.concatSeries(files, function (file, next) { | ||
grunt.log.writeln(file); | ||
grunt.log.writeln(destination); | ||
var destinationFile = destination || file; | ||
|
||
var pkg = importer.createPackage(file); | ||
pkg.build(function(err, changed) { | ||
if (!err && changed) { | ||
var results = { | ||
sourceFile: file, | ||
destinationFile: destinationFile, | ||
destinationSourceMapFile: pkg.sourceMap, | ||
data: changed | ||
}; | ||
next(err, results); | ||
} else { | ||
nextFileObj(err); | ||
} | ||
}); | ||
}, function (err, results) { | ||
if (!results) { | ||
grunt.log.warn('Destination not written because results were empty.'); | ||
nextFileObj(); | ||
} | ||
for(var i = 0; i < results.length; i++) { | ||
var result = results[i]; | ||
|
||
grunt.file.write(result.destinationFile, result.data.code); | ||
grunt.log.writeln('File "' + result.destinationFile + '" created.'); | ||
} | ||
nextFileObj(); | ||
}); | ||
}, done); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(function() { | ||
//fizz | ||
})(); | ||
(function() { | ||
//buzz | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(function() { | ||
//fizz | ||
})(); | ||
(function() { | ||
//buzz | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(function() { | ||
//buzz | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(function() { | ||
//fizz | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
//import "bar/fizz.js" | ||
//import "bar/buzz.js" |
Oops, something went wrong.