Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial working version

  • Loading branch information...
commit 80acd2fe9748af99da40bd4f0f2250b317d4c175 1 parent 9e8f7b8
@aearly authored
View
27 README.md
@@ -1,4 +1,29 @@
grunt-gluejs
============
-Grunt wrapper for GlueJS
+
+Example Config:
+
+```javascript
+
+ grunt.initConfig({
+ gluejs: {
+ "dist/index.js": {
+ basepath: "lib",
+ includes: ["lib/*.js"],
+ excludes: ["lib/C.js"],
+ replace: {
+ "jQuery": "window.$"
+ },
+ npm: {
+ "lodash": "../../"
+ },
+ exportName: "A"
+ }
+ }
+ });
+
+ grunt.loadNpmTasks("grunt-gluejs");
+
+```
View
6 examples/test/grunt-basic.js
@@ -4,7 +4,11 @@ module.exports = function (grunt) {
grunt.initConfig({
gluejs: {
"dist/basic.js": {
- entries: ["lib/A.js"]
+ basepath: "lib",
+ includes: ["lib/*.js"],
+ excludes: ["lib/C.js"],
+ replace: [],
+ exportName: "A"
}
}
});
View
23 examples/test/grunt-npm.js
@@ -0,0 +1,23 @@
+module.exports = function (grunt) {
+ "use strict";
+
+ grunt.initConfig({
+ gluejs: {
+ "dist/npm.js": {
+ basepath: "lib",
+ includes: ["lib/C.js"],
+ excludes: [],
+ replace: {
+ "jQuery": "window.$"
+ },
+ npm: {
+ "lodash": "../../"
+ },
+ exportName: "C"
+ }
+ }
+ });
+
+ grunt.loadTasks("../../tasks/");
+ grunt.registerTask("default", "gluejs");
+};
View
5 examples/test/lib/C.js
@@ -0,0 +1,5 @@
+var _ = require("lodash");
+
+module.exports = _.map("asdf,asdf,asdf".split(), function (word, i) {
+ return i + word;
+});
View
3  grunt.js
@@ -41,5 +41,6 @@ module.exports = function (grunt) {
});
grunt.loadNpmTasks("grunt-simple-mocha");
- grunt.registerTask("default", "lint simplemocha");
+ grunt.registerTask("mocha", "simplemocha:all");
+ grunt.registerTask("default", "lint mocha");
};
View
3  package.json
@@ -26,6 +26,7 @@
"mocha": "~1.7.3"
},
"dependencies": {
- "gluejs": "~0.2.0"
+ "gluejs": "~0.2.0",
+ "lodash": "~1.0.0-rc.1"
}
}
View
35 tasks/gluejs.js
@@ -1,10 +1,41 @@
-var Glue = require("gluejs");
+var Glue = require("gluejs"),
+ _ = require("lodash");
module.exports = function (grunt) {
"use strict";
- grunt.registerMultiTask("gluejs", "Build CommonJS-style modules for the browser", function (grunt) {
+ grunt.registerMultiTask("gluejs", "Build CommonJS-style modules for the browser", function () {
+ var self = this,
+ glue = new Glue();
+ if (this.data.basepath) {
+ glue.basepath(this.data.basepath);
+ }
+
+ _.each(grunt.file.expandFiles(this.data.includes || []), function (entry) {
+ glue.include(entry);
+ });
+
+ _.each(grunt.file.expandFiles(this.data.excludes || []), function (entry) {
+ glue.exclude(entry);
+ });
+
+ _.each(this.data.replace || {}, function (path, name) {
+ glue.replace(name, path);
+ });
+
+ _.each(this.data.npm || {}, function (path, name) {
+ glue.npm(name, path);
+ });
+
+ if (this.data.exportName) {
+ glue["export"](this.data.exportName);
+ }
+
+ glue.render(function (err, txt) {
+ grunt.file.write(self.target, txt);
+ self.async();
+ });
});
};
View
14 test/all.test.js
@@ -5,9 +5,23 @@ var expect = require("expect.js"),
describe("Test project 1:", function () {
it("should build properly", function (done) {
+ fs.unlinkSync(__dirname + "/../examples/test/dist/basic.js");
exec("grunt --config " + __dirname + "/../examples/test/grunt-basic.js", function (err, stdout, stderr) {
console.log(stderr + stdout);
expect(err).to.equal(null);
+ expect(fs.existsSync(__dirname + "/../examples/test/dist/basic.js")).to.equal(true);
+ done();
+ });
+ });
+
+ it("should process NPM modules", function (done) {
+ try {
+ fs.unlinkSync(__dirname + "/../examples/test/dist/npm.js");
+ } catch (e) {}
+ exec("grunt --config " + __dirname + "/../examples/test/grunt-npm.js", function (err, stdout, stderr) {
+ console.log(stderr + stdout);
+ expect(err).to.equal(null);
+ expect(fs.existsSync(__dirname + "/../examples/test/dist/npm.js")).to.equal(true);
done();
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.