grunt-glue-js
Advanced tools
Comparing version 0.0.4 to 0.0.5
Please see the [Contributing to grunt](http://gruntjs.com/contributing) guide for information on contributing to this project. |
@@ -36,12 +36,11 @@ /* | ||
directory: { | ||
options: { | ||
main: 'main.js' | ||
}, | ||
src: 'test/fixtures/package/*.js', | ||
dest: 'test/fixtures/index.js' | ||
}, | ||
ignore: { | ||
src: 'test/fixtures/package/*.js', | ||
dest: 'test/fixtures/index.js' | ||
}, | ||
export_and_basepath: { | ||
options: { | ||
export: 'App', | ||
export: 'MyApp', | ||
basepath: 'test/fixtures/package' | ||
@@ -48,0 +47,0 @@ }, |
{ | ||
"name": "grunt-glue-js", | ||
"description": "Grunt task to build CommonJS modules for the browser using gluejs.", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"homepage": "https://github.com/ngryman/grunt-glue-js", | ||
@@ -34,3 +34,3 @@ "author": { | ||
"dependencies": { | ||
"gluejs": "~0.2.2" | ||
"gluejs": "~2.3.7" | ||
}, | ||
@@ -37,0 +37,0 @@ "devDependencies": { |
@@ -52,3 +52,4 @@ # grunt-glue-js [![Build Status](https://travis-ci.org/ngryman/grunt-glue-js.png?branch=master)](https://travis-ci.org/ngryman/grunt-glue-js) | ||
options: { | ||
export: 'App' | ||
export: 'App', | ||
main: 'public/scripts/index.js' | ||
}, | ||
@@ -62,4 +63,30 @@ src: 'public/scripts/**/*.js', | ||
#### Advanced | ||
In this example, we use `coffeeify` to package our CoffeeScript app. We also showcase some more options. | ||
```javascript | ||
// Project configuration. | ||
grunt.initConfig({ | ||
gluejs: { | ||
app: { | ||
options: { | ||
export: 'App', | ||
report: true, | ||
debug: true, | ||
transform: 'coffeeify', | ||
replace: { | ||
jQuery: 'window.jQuery' | ||
}, | ||
main: 'public/scripts/index.coffee' | ||
}, | ||
src: 'public/scripts/**/*.coffee', | ||
dest: 'public/app.js' | ||
} | ||
} | ||
}); | ||
``` | ||
## Release History | ||
* 2014-04-07 v0.0.5 Switch to `gluejs` v2 (2.3.7). | ||
* 2013-12-10 v0.0.4 Set `gluejs` as an `npm` dep as requested fixes are now released. | ||
@@ -66,0 +93,0 @@ * 2013-05-24 v0.0.3 `basepath` and `main` options support. |
@@ -17,13 +17,20 @@ /* | ||
// merges task-specific and/or target-specific options with these defaults. | ||
var done = this.async(); | ||
var options = this.options({ | ||
stripBanners: false, | ||
process: false | ||
cache: false, | ||
require: false, | ||
report: false, | ||
debug: false | ||
}); | ||
// normalizes boolean options that accept options objects. | ||
if (options.stripBanners === true) { options.stripBanners = {}; } | ||
if (options.process === true) { options.process = {}; } | ||
var n_todo = 0; | ||
var n_done = 0; | ||
var n_err = 0; | ||
var n_files = this.files.length; | ||
// default options for glue | ||
Glue.defaults(options); | ||
if (!(options.main || ((n_files == 1) && (this.files[0].src.length == 1)))) { | ||
grunt.fail.fatal("The `main` option to gluejs is mandatory when there is more than one source file."); | ||
return; | ||
} | ||
@@ -36,26 +43,112 @@ // processes banner and footer. | ||
this.files.forEach(function(file) { | ||
n_todo = n_todo + 1; | ||
var glue = new Glue(); | ||
// export | ||
if (options.export) { glue.export(options.export); } | ||
if (options.debug) { | ||
grunt.log.writeln("processing file '" + file.src + "'"); | ||
} | ||
if (options.cache !== null) { | ||
glue.set('cache', options.cache); | ||
} | ||
if (options.require !== null) { | ||
glue.set('require', options.require); | ||
} | ||
if (options.report !== null) { | ||
glue.set('report', options.report); | ||
} | ||
//glue.set('cache', false).set('require', false).set('report', true); | ||
// command | ||
if (options.command) { | ||
glue.set('command', options.command); | ||
} | ||
// transform | ||
if (options.transform) { | ||
glue.options['transform'] = options.transform; | ||
} | ||
// basepath | ||
// TODO: should work with defaults | ||
if (options.basepath) { glue.basepath(options.basepath); } | ||
if (options.basepath) { | ||
// output paths are relative to this | ||
glue.basepath(options.basepath); | ||
} | ||
else { | ||
// output paths are relative to this | ||
glue.basepath(process.cwd()); | ||
} | ||
// includes source files - excludes the destination file if it is in the same directory of source(s) file(s) | ||
file.src.forEach(function(src) { | ||
var relpath = src; | ||
if (options.basepath) | ||
relpath = path.relative(options.basepath, relpath); | ||
if (options.debug) { | ||
grunt.log.writeln("including '" + src + "' as '" + relpath + "'"); | ||
} | ||
if (src !== file.dest) { | ||
glue.include(src); | ||
// includes all files in the dir | ||
glue.include(relpath); | ||
} | ||
}); | ||
// exclude | ||
if (options.exclude) { | ||
glue.exclude(options.exclude); | ||
} | ||
if (options.main) { | ||
// the file that's exported as the root of the package | ||
glue.main(options.main); | ||
} | ||
else if ((n_files == 1) && (file.src.length == 1)) { | ||
var relpath = file.src[0]; | ||
if (options.basepath) | ||
relpath = path.relative(options.basepath, relpath); | ||
glue.main(relpath); | ||
} | ||
// export | ||
if (options.export) { | ||
glue.export(options.export); | ||
} | ||
// replace | ||
if (options.replace) { | ||
var obj = options.replace; | ||
for (var key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
glue.replace(key, obj[key]); | ||
} | ||
} | ||
} | ||
if (options.debug) { | ||
grunt.log.writeln("going to render to '" + file.dest + "'"); | ||
console.log(glue); | ||
} | ||
glue.render(function(err, output) { | ||
output = banner + output + footer; | ||
grunt.file.write(file.dest, output); | ||
if (err) { | ||
grunt.log.writeln("error:", err); | ||
grunt.warn.writeln('File "' + file.dest + '" NOT created.'); | ||
grunt.log.writeln('File "' + file.dest + '" created.'); | ||
n_err++; | ||
} | ||
else { | ||
output = banner + output + footer; | ||
grunt.file.write(file.dest, output); | ||
grunt.log.writeln('File "' + file.dest + '" created.'); | ||
} | ||
n_done++; | ||
if (n_todo === n_done) { | ||
// All done! | ||
done((n_err === 0)); | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
198
100
11037
9
+ Addedamd-resolve@0.1.1(transitive)
+ Addedamdefine@1.0.1(transitive)
+ Addedamdetective@0.0.1(transitive)
+ Addedbrowser-resolve@1.2.4(transitive)
+ Addedbytes@0.2.1(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddebuglog@0.0.2(transitive)
+ Addeddetective@2.4.1(transitive)
+ Addedescodegen@1.1.0(transitive)
+ Addedestraverse@1.5.1(transitive)
+ Addedesutils@1.0.0(transitive)
+ Addedgluejs@2.3.9(transitive)
+ Addedmicroee@0.0.6(transitive)
+ Addedminilog@2.0.8(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedminiq@0.1.2(transitive)
+ Addedminitask@0.2.3(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedoptimist@0.5.2(transitive)
+ Addedprogress@1.1.8(transitive)
+ Addedreadable-stream@1.1.9(transitive)
+ Addedresolve@0.6.3(transitive)
+ Addedsource-map@0.1.43(transitive)
+ Addedwordwrap@0.0.3(transitive)
- Removedargsparser@0.0.6(transitive)
- Removedgluejs@0.2.2(transitive)
- Removedminilog@2.0.0(transitive)
- Removedpackage-json-resolver@0.0.1(transitive)
Updatedgluejs@~2.3.7